1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted is free software: you can redistribute it and/or modify //
|
7
|
// 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
|
// Distorted 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 //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.library.effectqueue;
|
21
|
|
22
|
import android.opengl.GLES30;
|
23
|
import android.opengl.Matrix;
|
24
|
|
25
|
import org.distorted.library.effect.EffectType;
|
26
|
import org.distorted.library.effect.MatrixEffect;
|
27
|
import org.distorted.library.message.EffectMessageSender;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
class EffectQueueMatrix extends EffectQueue
|
32
|
{
|
33
|
private static final int NUM_UNIFORMS = MatrixEffect.NUM_UNIFORMS;
|
34
|
private static final int INDEX = EffectType.MATRIX.ordinal();
|
35
|
|
36
|
private static float[] mMVPMatrix = new float[16];
|
37
|
private static float[] mModelViewMatrixP= new float[16];
|
38
|
private static float[] mModelViewMatrixV= new float[16];
|
39
|
|
40
|
private static int[] mMVPMatrixH = new int[MAIN_VARIANTS];
|
41
|
private static int[] mMVMatrixPH = new int[MAIN_VARIANTS];
|
42
|
private static int[] mMVMatrixVH = new int[MAIN_VARIANTS];
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
EffectQueueMatrix()
|
47
|
{
|
48
|
super(NUM_UNIFORMS,INDEX );
|
49
|
}
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
EffectQueueMatrix(EffectQueueMatrix source)
|
54
|
{
|
55
|
super(source);
|
56
|
}
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
static void uniforms(int mProgramH, int variant)
|
61
|
{
|
62
|
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
63
|
mMVMatrixPH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixP");
|
64
|
mMVMatrixVH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixV");
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
void compute(long currTime)
|
70
|
{
|
71
|
if( currTime==mTime ) return;
|
72
|
if( mTime==0 ) mTime = currTime;
|
73
|
long step = (currTime-mTime);
|
74
|
|
75
|
for(int i=0; i<mNumEffects; i++)
|
76
|
{
|
77
|
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, currTime, step) )
|
78
|
{
|
79
|
EffectMessageSender.newMessage(mEffects[i]);
|
80
|
}
|
81
|
}
|
82
|
|
83
|
mTime = currTime;
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
void send(float distance, float mipmap, float[] projection, int variant)
|
89
|
{
|
90
|
Matrix.setIdentityM(mModelViewMatrixP, 0);
|
91
|
Matrix.translateM(mModelViewMatrixP, 0, 0,0, -distance);
|
92
|
|
93
|
if( mipmap!=1 )
|
94
|
{
|
95
|
Matrix.scaleM(mModelViewMatrixP, 0, mipmap, mipmap, mipmap);
|
96
|
}
|
97
|
|
98
|
mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0];
|
99
|
mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1];
|
100
|
mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2];
|
101
|
mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3];
|
102
|
mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4];
|
103
|
mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5];
|
104
|
mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6];
|
105
|
mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7];
|
106
|
mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8];
|
107
|
mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9];
|
108
|
mModelViewMatrixV[10] = mModelViewMatrixP[10];
|
109
|
mModelViewMatrixV[11] = mModelViewMatrixP[11];
|
110
|
mModelViewMatrixV[12] = mModelViewMatrixP[12];
|
111
|
mModelViewMatrixV[13] = mModelViewMatrixP[13];
|
112
|
mModelViewMatrixV[14] = mModelViewMatrixP[14];
|
113
|
mModelViewMatrixV[15] = mModelViewMatrixP[15];
|
114
|
|
115
|
// the 'Model' part of the MV matrix
|
116
|
for(int i=mNumEffects-1; i>=0; i--)
|
117
|
{
|
118
|
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,mUniforms,i);
|
119
|
}
|
120
|
|
121
|
// combined Model-View-Projection matrix
|
122
|
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrixP, 0);
|
123
|
|
124
|
GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0);
|
125
|
GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0);
|
126
|
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
|
127
|
}
|
128
|
}
|