1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
d333eb6b
|
Leszek Koltunski
|
// //
|
6 |
46b572b5
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
d333eb6b
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
46b572b5
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
d333eb6b
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
46b572b5
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
809dcae3
|
Leszek Koltunski
|
package org.distorted.library.effectqueue;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
b7074bc6
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
23 |
6a06a912
|
Leszek Koltunski
|
import android.opengl.Matrix;
|
24 |
|
|
|
25 |
da9b3f07
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectType;
|
26 |
fe82a979
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffect;
|
27 |
23b733db
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
28 |
ed06301f
|
Leszek Koltunski
|
import org.distorted.library.message.EffectMessageSender;
|
29 |
a4835695
|
Leszek Koltunski
|
|
30 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31 |
|
|
|
32 |
d07f2950
|
Leszek Koltunski
|
class EffectQueueMatrix extends EffectQueue
|
33 |
6a06a912
|
Leszek Koltunski
|
{
|
34 |
15aa7d94
|
Leszek Koltunski
|
private static final int NUM_UNIFORMS = MatrixEffect.NUM_UNIFORMS;
|
35 |
da9b3f07
|
Leszek Koltunski
|
private static final int INDEX = EffectType.MATRIX.ordinal();
|
36 |
1a940548
|
Leszek Koltunski
|
|
37 |
7490d738
|
Leszek Koltunski
|
private static float[] mMVPMatrix = new float[16];
|
38 |
|
|
private static float[] mModelViewMatrix = new float[16];
|
39 |
1a940548
|
Leszek Koltunski
|
|
40 |
809dcae3
|
Leszek Koltunski
|
private static int[] mMVPMatrixH = new int[MAIN_VARIANTS];
|
41 |
|
|
private static int[] mMVMatrixH = new int[MAIN_VARIANTS];
|
42 |
bed13bea
|
leszek
|
|
43 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
|
45 |
20dbec0e
|
Leszek Koltunski
|
EffectQueueMatrix()
|
46 |
6a06a912
|
Leszek Koltunski
|
{
|
47 |
20dbec0e
|
Leszek Koltunski
|
super(NUM_UNIFORMS,INDEX );
|
48 |
6a06a912
|
Leszek Koltunski
|
}
|
49 |
|
|
|
50 |
f046b159
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
EffectQueueMatrix(EffectQueueMatrix source)
|
53 |
|
|
{
|
54 |
|
|
super(source);
|
55 |
|
|
}
|
56 |
|
|
|
57 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
809dcae3
|
Leszek Koltunski
|
static void uniforms(int mProgramH, int variant)
|
60 |
c1a38ba3
|
Leszek Koltunski
|
{
|
61 |
b7074bc6
|
Leszek Koltunski
|
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
62 |
|
|
mMVMatrixH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix");
|
63 |
c1a38ba3
|
Leszek Koltunski
|
}
|
64 |
|
|
|
65 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
|
|
|
67 |
735a8757
|
Leszek Koltunski
|
void compute(long currTime)
|
68 |
02de77c9
|
Leszek Koltunski
|
{
|
69 |
|
|
if( currTime==mTime ) return;
|
70 |
|
|
if( mTime==0 ) mTime = currTime;
|
71 |
|
|
long step = (currTime-mTime);
|
72 |
15aa7d94
|
Leszek Koltunski
|
|
73 |
02de77c9
|
Leszek Koltunski
|
for(int i=0; i<mNumEffects; i++)
|
74 |
|
|
{
|
75 |
3a70bd6d
|
leszek
|
mCurrentDuration[i] += step;
|
76 |
|
|
|
77 |
15aa7d94
|
Leszek Koltunski
|
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) )
|
78 |
02de77c9
|
Leszek Koltunski
|
{
|
79 |
20dbec0e
|
Leszek Koltunski
|
EffectMessageSender.newMessage(mEffects[i]);
|
80 |
02de77c9
|
Leszek Koltunski
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
mTime = currTime;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
3fc9327a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87 |
|
|
|
88 |
|
|
float[] getMVP()
|
89 |
|
|
{
|
90 |
|
|
return mMVPMatrix;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
|
95 |
23b733db
|
Leszek Koltunski
|
void send(float distance, float mipmap, float[] projection, MeshBase mesh, int variant)
|
96 |
c1a38ba3
|
Leszek Koltunski
|
{
|
97 |
7490d738
|
Leszek Koltunski
|
Matrix.setIdentityM(mModelViewMatrix, 0);
|
98 |
3eb6f354
|
Leszek Koltunski
|
|
99 |
7490d738
|
Leszek Koltunski
|
// The 'View' part of the MV matrix
|
100 |
|
|
Matrix.translateM(mModelViewMatrix, 0, 0,0, -distance);
|
101 |
|
|
if( mipmap!=1 ) Matrix.scaleM(mModelViewMatrix, 0, mipmap, mipmap, mipmap);
|
102 |
c1a38ba3
|
Leszek Koltunski
|
|
103 |
7490d738
|
Leszek Koltunski
|
// the 'Model' part of the MV matrix
|
104 |
|
|
for(int i=mNumEffects-1; i>=0; i--) ((MatrixEffect)mEffects[i]).apply(mModelViewMatrix,mUniforms,i);
|
105 |
|
|
|
106 |
|
|
// combined Model-View-Projection matrix
|
107 |
|
|
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrix, 0);
|
108 |
c1a38ba3
|
Leszek Koltunski
|
|
109 |
b7074bc6
|
Leszek Koltunski
|
GLES30.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0);
|
110 |
|
|
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
111 |
c1a38ba3
|
Leszek Koltunski
|
}
|
112 |
6a06a912
|
Leszek Koltunski
|
}
|