1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
dbdf8a73
|
Leszek Koltunski
|
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl //
|
3 |
d333eb6b
|
Leszek Koltunski
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
d333eb6b
|
Leszek Koltunski
|
// //
|
6 |
dbdf8a73
|
Leszek Koltunski
|
// This library is free software; you can redistribute it and/or //
|
7 |
|
|
// modify it under the terms of the GNU Lesser General Public //
|
8 |
|
|
// License as published by the Free Software Foundation; either //
|
9 |
|
|
// version 2.1 of the License, or (at your option) any later version. //
|
10 |
d333eb6b
|
Leszek Koltunski
|
// //
|
11 |
dbdf8a73
|
Leszek Koltunski
|
// This library 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 |
dbdf8a73
|
Leszek Koltunski
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14 |
|
|
// Lesser General Public License for more details. //
|
15 |
d333eb6b
|
Leszek Koltunski
|
// //
|
16 |
dbdf8a73
|
Leszek Koltunski
|
// You should have received a copy of the GNU Lesser General Public //
|
17 |
|
|
// License along with this library; if not, write to the Free Software //
|
18 |
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
809dcae3
|
Leszek Koltunski
|
package org.distorted.library.effectqueue;
|
22 |
6a06a912
|
Leszek Koltunski
|
|
23 |
b7074bc6
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
24 |
6a06a912
|
Leszek Koltunski
|
import android.opengl.Matrix;
|
25 |
|
|
|
26 |
da9b3f07
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectType;
|
27 |
fe82a979
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffect;
|
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 |
96e3b88a
|
Leszek Koltunski
|
{
|
34 |
|
|
private static final int NUM_FLOAT_UNIFORMS = MatrixEffect.NUM_FLOAT_UNIFORMS;
|
35 |
|
|
private static final int NUM_INT_UNIFORMS = MatrixEffect.NUM_INT_UNIFORMS;
|
36 |
2b7d2abb
|
Leszek Koltunski
|
private static final boolean USE_UBO = false;
|
37 |
da9b3f07
|
Leszek Koltunski
|
private static final int INDEX = EffectType.MATRIX.ordinal();
|
38 |
1a940548
|
Leszek Koltunski
|
|
39 |
de77a6c5
|
Leszek Koltunski
|
private static final float[] mMVPMatrix = new float[16];
|
40 |
|
|
private static final float[] mModelViewMatrixP= new float[16];
|
41 |
|
|
private static final float[] mModelViewMatrixV= new float[16];
|
42 |
1a940548
|
Leszek Koltunski
|
|
43 |
de77a6c5
|
Leszek Koltunski
|
private static final int[] mMVPMatrixH = new int[MAIN_VARIANTS];
|
44 |
|
|
private static final int[] mMVMatrixPH = new int[MAIN_VARIANTS];
|
45 |
|
|
private static final int[] mMVMatrixVH = new int[MAIN_VARIANTS];
|
46 |
bed13bea
|
leszek
|
|
47 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
|
49 |
20dbec0e
|
Leszek Koltunski
|
EffectQueueMatrix()
|
50 |
6a06a912
|
Leszek Koltunski
|
{
|
51 |
2b7d2abb
|
Leszek Koltunski
|
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
|
52 |
6a06a912
|
Leszek Koltunski
|
}
|
53 |
|
|
|
54 |
f046b159
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
EffectQueueMatrix(EffectQueueMatrix source)
|
57 |
|
|
{
|
58 |
|
|
super(source);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
809dcae3
|
Leszek Koltunski
|
static void uniforms(int mProgramH, int variant)
|
64 |
c1a38ba3
|
Leszek Koltunski
|
{
|
65 |
b7074bc6
|
Leszek Koltunski
|
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
66 |
62c869ad
|
Leszek Koltunski
|
mMVMatrixPH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixP");
|
67 |
|
|
mMVMatrixVH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixV");
|
68 |
c1a38ba3
|
Leszek Koltunski
|
}
|
69 |
|
|
|
70 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
835b197e
|
Leszek Koltunski
|
void compute(long currTime, long step)
|
73 |
02de77c9
|
Leszek Koltunski
|
{
|
74 |
835b197e
|
Leszek Koltunski
|
if( mNumEffects>0 )
|
75 |
02de77c9
|
Leszek Koltunski
|
{
|
76 |
835b197e
|
Leszek Koltunski
|
float[] array = mUBF.getBackingArray();
|
77 |
|
|
|
78 |
|
|
for(int i=0; i<mNumEffects; i++)
|
79 |
02de77c9
|
Leszek Koltunski
|
{
|
80 |
835b197e
|
Leszek Koltunski
|
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
81 |
|
|
{
|
82 |
|
|
EffectMessageSender.newMessage(mEffects[i]);
|
83 |
|
|
}
|
84 |
02de77c9
|
Leszek Koltunski
|
}
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
3fc9327a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
62c869ad
|
Leszek Koltunski
|
void send(float distance, float mipmap, float[] projection, int variant)
|
91 |
3fc9327a
|
Leszek Koltunski
|
{
|
92 |
62c869ad
|
Leszek Koltunski
|
Matrix.setIdentityM(mModelViewMatrixP, 0);
|
93 |
|
|
Matrix.translateM(mModelViewMatrixP, 0, 0,0, -distance);
|
94 |
02de77c9
|
Leszek Koltunski
|
|
95 |
62c869ad
|
Leszek Koltunski
|
if( mipmap!=1 )
|
96 |
|
|
{
|
97 |
|
|
Matrix.scaleM(mModelViewMatrixP, 0, mipmap, mipmap, mipmap);
|
98 |
|
|
}
|
99 |
3eb6f354
|
Leszek Koltunski
|
|
100 |
62c869ad
|
Leszek Koltunski
|
mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0];
|
101 |
|
|
mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1];
|
102 |
|
|
mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2];
|
103 |
|
|
mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3];
|
104 |
|
|
mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4];
|
105 |
|
|
mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5];
|
106 |
|
|
mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6];
|
107 |
|
|
mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7];
|
108 |
|
|
mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8];
|
109 |
|
|
mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9];
|
110 |
|
|
mModelViewMatrixV[10] = mModelViewMatrixP[10];
|
111 |
|
|
mModelViewMatrixV[11] = mModelViewMatrixP[11];
|
112 |
|
|
mModelViewMatrixV[12] = mModelViewMatrixP[12];
|
113 |
|
|
mModelViewMatrixV[13] = mModelViewMatrixP[13];
|
114 |
|
|
mModelViewMatrixV[14] = mModelViewMatrixP[14];
|
115 |
|
|
mModelViewMatrixV[15] = mModelViewMatrixP[15];
|
116 |
c1a38ba3
|
Leszek Koltunski
|
|
117 |
de77a6c5
|
Leszek Koltunski
|
float[] array = mUBF.getBackingArray();
|
118 |
|
|
|
119 |
7490d738
|
Leszek Koltunski
|
// the 'Model' part of the MV matrix
|
120 |
62c869ad
|
Leszek Koltunski
|
for(int i=mNumEffects-1; i>=0; i--)
|
121 |
|
|
{
|
122 |
de77a6c5
|
Leszek Koltunski
|
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,array,i);
|
123 |
62c869ad
|
Leszek Koltunski
|
}
|
124 |
7490d738
|
Leszek Koltunski
|
|
125 |
|
|
// combined Model-View-Projection matrix
|
126 |
62c869ad
|
Leszek Koltunski
|
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrixP, 0);
|
127 |
c1a38ba3
|
Leszek Koltunski
|
|
128 |
62c869ad
|
Leszek Koltunski
|
GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0);
|
129 |
|
|
GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0);
|
130 |
|
|
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
131 |
c1a38ba3
|
Leszek Koltunski
|
}
|
132 |
6a06a912
|
Leszek Koltunski
|
}
|