1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// 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
|
// //
|
11
|
// This library is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14
|
// Lesser General Public License for more details. //
|
15
|
// //
|
16
|
// 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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20
|
|
21
|
package org.distorted.library.effectqueue;
|
22
|
|
23
|
import android.opengl.GLES30;
|
24
|
|
25
|
import org.distorted.library.helpers.MatrixHelper;
|
26
|
import org.distorted.library.effect.EffectType;
|
27
|
import org.distorted.library.effect.MatrixEffect;
|
28
|
import org.distorted.library.message.EffectMessageSender;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
|
32
|
class EffectQueueMatrix extends EffectQueue
|
33
|
{
|
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
|
private static final boolean USE_UBO = false;
|
37
|
private static final int INDEX = EffectType.MATRIX.ordinal();
|
38
|
|
39
|
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
|
|
43
|
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
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
EffectQueueMatrix()
|
50
|
{
|
51
|
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
|
52
|
}
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
EffectQueueMatrix(EffectQueueMatrix source)
|
57
|
{
|
58
|
super(source);
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
static void uniforms(int mProgramH, int variant)
|
64
|
{
|
65
|
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
66
|
mMVMatrixPH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixP");
|
67
|
mMVMatrixVH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixV");
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
void compute(long currTime, long step)
|
73
|
{
|
74
|
if( mNumEffects>0 )
|
75
|
{
|
76
|
float[] array = mUBF.getBackingArray();
|
77
|
|
78
|
for(int i=0; i<mNumEffects; i++)
|
79
|
{
|
80
|
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
81
|
{
|
82
|
EffectMessageSender.newMessage(mEffects[i]);
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
void send(float distance, float mipmap, float[] projection, int variant)
|
91
|
{
|
92
|
// i.e. setIdentity(); translate(0,0,-distance); scale(mipmap,mipmap,mipmap)
|
93
|
mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0] = mipmap;
|
94
|
mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1] = 0;
|
95
|
mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2] = 0;
|
96
|
mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3] = 0;
|
97
|
mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4] = 0;
|
98
|
mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5] = mipmap;
|
99
|
mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6] = 0;
|
100
|
mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7] = 0;
|
101
|
mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8] = 0;
|
102
|
mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9] = 0;
|
103
|
mModelViewMatrixV[10] = mModelViewMatrixP[10] = mipmap;
|
104
|
mModelViewMatrixV[11] = mModelViewMatrixP[11] = 0;
|
105
|
mModelViewMatrixV[12] = mModelViewMatrixP[12] = 0;
|
106
|
mModelViewMatrixV[13] = mModelViewMatrixP[13] = 0;
|
107
|
mModelViewMatrixV[14] = mModelViewMatrixP[14] = -distance;
|
108
|
mModelViewMatrixV[15] = mModelViewMatrixP[15] = 1;
|
109
|
|
110
|
float[] array = mUBF.getBackingArray();
|
111
|
|
112
|
// the 'Model' part of the MV matrix
|
113
|
for(int i=mNumEffects-1; i>=0; i--)
|
114
|
{
|
115
|
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,array,i);
|
116
|
}
|
117
|
|
118
|
// combined Model-View-Projection matrix
|
119
|
MatrixHelper.multiply(mMVPMatrix, projection, mModelViewMatrixP);
|
120
|
|
121
|
GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0);
|
122
|
GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0);
|
123
|
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
124
|
}
|
125
|
}
|