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 |
ed06301f
|
Leszek Koltunski
|
import org.distorted.library.message.EffectMessageSender;
|
28 |
a4835695
|
Leszek Koltunski
|
|
29 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
d07f2950
|
Leszek Koltunski
|
class EffectQueueMatrix extends EffectQueue
|
32 |
96e3b88a
|
Leszek Koltunski
|
{
|
33 |
|
|
private static final int NUM_FLOAT_UNIFORMS = MatrixEffect.NUM_FLOAT_UNIFORMS;
|
34 |
|
|
private static final int NUM_INT_UNIFORMS = MatrixEffect.NUM_INT_UNIFORMS;
|
35 |
2b7d2abb
|
Leszek Koltunski
|
private static final boolean USE_UBO = false;
|
36 |
da9b3f07
|
Leszek Koltunski
|
private static final int INDEX = EffectType.MATRIX.ordinal();
|
37 |
1a940548
|
Leszek Koltunski
|
|
38 |
de77a6c5
|
Leszek Koltunski
|
private static final float[] mMVPMatrix = new float[16];
|
39 |
|
|
private static final float[] mModelViewMatrixP= new float[16];
|
40 |
|
|
private static final float[] mModelViewMatrixV= new float[16];
|
41 |
1a940548
|
Leszek Koltunski
|
|
42 |
de77a6c5
|
Leszek Koltunski
|
private static final int[] mMVPMatrixH = new int[MAIN_VARIANTS];
|
43 |
|
|
private static final int[] mMVMatrixPH = new int[MAIN_VARIANTS];
|
44 |
|
|
private static final int[] mMVMatrixVH = new int[MAIN_VARIANTS];
|
45 |
bed13bea
|
leszek
|
|
46 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
20dbec0e
|
Leszek Koltunski
|
EffectQueueMatrix()
|
49 |
6a06a912
|
Leszek Koltunski
|
{
|
50 |
2b7d2abb
|
Leszek Koltunski
|
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
|
51 |
6a06a912
|
Leszek Koltunski
|
}
|
52 |
|
|
|
53 |
f046b159
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
|
|
EffectQueueMatrix(EffectQueueMatrix source)
|
56 |
|
|
{
|
57 |
|
|
super(source);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61 |
|
|
|
62 |
809dcae3
|
Leszek Koltunski
|
static void uniforms(int mProgramH, int variant)
|
63 |
c1a38ba3
|
Leszek Koltunski
|
{
|
64 |
b7074bc6
|
Leszek Koltunski
|
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
65 |
62c869ad
|
Leszek Koltunski
|
mMVMatrixPH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixP");
|
66 |
|
|
mMVMatrixVH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixV");
|
67 |
c1a38ba3
|
Leszek Koltunski
|
}
|
68 |
|
|
|
69 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
835b197e
|
Leszek Koltunski
|
void compute(long currTime, long step)
|
72 |
02de77c9
|
Leszek Koltunski
|
{
|
73 |
835b197e
|
Leszek Koltunski
|
if( mNumEffects>0 )
|
74 |
02de77c9
|
Leszek Koltunski
|
{
|
75 |
835b197e
|
Leszek Koltunski
|
float[] array = mUBF.getBackingArray();
|
76 |
|
|
|
77 |
|
|
for(int i=0; i<mNumEffects; i++)
|
78 |
02de77c9
|
Leszek Koltunski
|
{
|
79 |
835b197e
|
Leszek Koltunski
|
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
80 |
|
|
{
|
81 |
|
|
EffectMessageSender.newMessage(mEffects[i]);
|
82 |
|
|
}
|
83 |
02de77c9
|
Leszek Koltunski
|
}
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
3fc9327a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
62c869ad
|
Leszek Koltunski
|
void send(float distance, float mipmap, float[] projection, int variant)
|
90 |
3fc9327a
|
Leszek Koltunski
|
{
|
91 |
62c869ad
|
Leszek Koltunski
|
Matrix.setIdentityM(mModelViewMatrixP, 0);
|
92 |
|
|
Matrix.translateM(mModelViewMatrixP, 0, 0,0, -distance);
|
93 |
02de77c9
|
Leszek Koltunski
|
|
94 |
62c869ad
|
Leszek Koltunski
|
if( mipmap!=1 )
|
95 |
|
|
{
|
96 |
|
|
Matrix.scaleM(mModelViewMatrixP, 0, mipmap, mipmap, mipmap);
|
97 |
|
|
}
|
98 |
3eb6f354
|
Leszek Koltunski
|
|
99 |
62c869ad
|
Leszek Koltunski
|
mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0];
|
100 |
|
|
mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1];
|
101 |
|
|
mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2];
|
102 |
|
|
mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3];
|
103 |
|
|
mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4];
|
104 |
|
|
mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5];
|
105 |
|
|
mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6];
|
106 |
|
|
mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7];
|
107 |
|
|
mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8];
|
108 |
|
|
mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9];
|
109 |
|
|
mModelViewMatrixV[10] = mModelViewMatrixP[10];
|
110 |
|
|
mModelViewMatrixV[11] = mModelViewMatrixP[11];
|
111 |
|
|
mModelViewMatrixV[12] = mModelViewMatrixP[12];
|
112 |
|
|
mModelViewMatrixV[13] = mModelViewMatrixP[13];
|
113 |
|
|
mModelViewMatrixV[14] = mModelViewMatrixP[14];
|
114 |
|
|
mModelViewMatrixV[15] = mModelViewMatrixP[15];
|
115 |
c1a38ba3
|
Leszek Koltunski
|
|
116 |
de77a6c5
|
Leszek Koltunski
|
float[] array = mUBF.getBackingArray();
|
117 |
|
|
|
118 |
7490d738
|
Leszek Koltunski
|
// the 'Model' part of the MV matrix
|
119 |
62c869ad
|
Leszek Koltunski
|
for(int i=mNumEffects-1; i>=0; i--)
|
120 |
|
|
{
|
121 |
de77a6c5
|
Leszek Koltunski
|
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,array,i);
|
122 |
62c869ad
|
Leszek Koltunski
|
}
|
123 |
7490d738
|
Leszek Koltunski
|
|
124 |
|
|
// combined Model-View-Projection matrix
|
125 |
62c869ad
|
Leszek Koltunski
|
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrixP, 0);
|
126 |
c1a38ba3
|
Leszek Koltunski
|
|
127 |
62c869ad
|
Leszek Koltunski
|
GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0);
|
128 |
|
|
GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0);
|
129 |
|
|
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
130 |
c1a38ba3
|
Leszek Koltunski
|
}
|
131 |
6a06a912
|
Leszek Koltunski
|
}
|