1 |
4c1dd6e9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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;
|
21 |
|
|
|
22 |
|
|
import android.opengl.GLES20;
|
23 |
bfe2c61b
|
Leszek Koltunski
|
import android.opengl.Matrix;
|
24 |
4c1dd6e9
|
Leszek Koltunski
|
|
25 |
|
|
import org.distorted.library.message.EffectMessage;
|
26 |
|
|
import org.distorted.library.type.Data1D;
|
27 |
|
|
import org.distorted.library.type.Data2D;
|
28 |
|
|
import org.distorted.library.type.Dynamic1D;
|
29 |
|
|
import org.distorted.library.type.Dynamic2D;
|
30 |
|
|
import org.distorted.library.type.Static1D;
|
31 |
|
|
import org.distorted.library.type.Static2D;
|
32 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
class EffectQueuePostprocess extends EffectQueue
|
36 |
|
|
{
|
37 |
|
|
private static final int NUM_UNIFORMS = 3;
|
38 |
|
|
private static final int NUM_CACHE = 0;
|
39 |
|
|
private static final int INDEX = EffectTypes.POSTPROCESS.ordinal();
|
40 |
|
|
|
41 |
|
|
private static int mNumEffectsH;
|
42 |
|
|
private static int mTypeH;
|
43 |
|
|
private static int mUniformsH;
|
44 |
|
|
private static int mObjDH;
|
45 |
bfe2c61b
|
Leszek Koltunski
|
private static int mMVPMatrixH;
|
46 |
|
|
|
47 |
|
|
private static float[] mMVPMatrix = new float[16];
|
48 |
|
|
private static float[] mTmpMatrix = new float[16];
|
49 |
4c1dd6e9
|
Leszek Koltunski
|
|
50 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
EffectQueuePostprocess(long id)
|
53 |
|
|
{
|
54 |
|
|
super(id,NUM_UNIFORMS,NUM_CACHE,INDEX );
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
|
|
static void getUniforms(int mProgramH)
|
60 |
|
|
{
|
61 |
|
|
mNumEffectsH= GLES20.glGetUniformLocation( mProgramH, "pNumEffects");
|
62 |
|
|
mTypeH = GLES20.glGetUniformLocation( mProgramH, "pType");
|
63 |
|
|
mUniformsH = GLES20.glGetUniformLocation( mProgramH, "pUniforms");
|
64 |
|
|
mObjDH = GLES20.glGetUniformLocation( mProgramH, "u_objD");
|
65 |
bfe2c61b
|
Leszek Koltunski
|
mMVPMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
66 |
4c1dd6e9
|
Leszek Koltunski
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
|
|
synchronized void compute(long currTime)
|
71 |
|
|
{
|
72 |
|
|
if( currTime==mTime ) return;
|
73 |
|
|
if( mTime==0 ) mTime = currTime;
|
74 |
|
|
long step = (currTime-mTime);
|
75 |
|
|
|
76 |
|
|
for(int i=0; i<mNumEffects; i++)
|
77 |
|
|
{
|
78 |
|
|
if( mInter[0][i]!=null && mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )
|
79 |
|
|
{
|
80 |
|
|
for(int j=0; j<mNumListeners; j++)
|
81 |
|
|
EffectMessageSender.newMessage( mListeners.elementAt(j),
|
82 |
|
|
EffectMessage.EFFECT_FINISHED,
|
83 |
|
|
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.POSTPROCESS.type,
|
84 |
|
|
mName[i],
|
85 |
|
|
mObjectID);
|
86 |
|
|
|
87 |
|
|
if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
|
88 |
|
|
{
|
89 |
|
|
remove(i);
|
90 |
|
|
i--;
|
91 |
|
|
continue;
|
92 |
|
|
}
|
93 |
|
|
else mInter[0][i] = null;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
if( mInter[1][i]!=null )
|
97 |
|
|
{
|
98 |
|
|
mInter[1][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+1, mCurrentDuration[i], step);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
mCurrentDuration[i] += step;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
mTime = currTime;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
protected void moveEffect(int index)
|
110 |
|
|
{
|
111 |
|
|
mUniforms[NUM_UNIFORMS*index ] = mUniforms[NUM_UNIFORMS*(index+1) ];
|
112 |
|
|
mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
|
113 |
|
|
mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
|
114 |
|
|
}
|
115 |
|
|
|
116 |
02de77c9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
synchronized void send(float w, float h, float[] mvp)
|
119 |
|
|
{
|
120 |
|
|
GLES20.glUniform1i( mNumEffectsH, mNumEffects);
|
121 |
|
|
GLES20.glUniform2f( mObjDH , w, h );
|
122 |
|
|
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
|
123 |
|
|
|
124 |
|
|
if( mNumEffects>0 )
|
125 |
|
|
{
|
126 |
|
|
GLES20.glUniform1iv( mTypeH , mNumEffects, mName ,0);
|
127 |
|
|
GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
4c1dd6e9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
|
|
|
133 |
2b942cd0
|
Leszek Koltunski
|
synchronized void send(DistortedFramebuffer df)
|
134 |
4c1dd6e9
|
Leszek Koltunski
|
{
|
135 |
bfe2c61b
|
Leszek Koltunski
|
Matrix.setIdentityM(mTmpMatrix, 0);
|
136 |
2b942cd0
|
Leszek Koltunski
|
Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
|
137 |
bfe2c61b
|
Leszek Koltunski
|
Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
|
138 |
|
|
|
139 |
4c1dd6e9
|
Leszek Koltunski
|
GLES20.glUniform1i( mNumEffectsH, mNumEffects);
|
140 |
2b942cd0
|
Leszek Koltunski
|
GLES20.glUniform2f( mObjDH , df.mWidth, df.mHeight);
|
141 |
bfe2c61b
|
Leszek Koltunski
|
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
142 |
4c1dd6e9
|
Leszek Koltunski
|
|
143 |
|
|
if( mNumEffects>0 )
|
144 |
|
|
{
|
145 |
|
|
GLES20.glUniform1iv( mTypeH , mNumEffects, mName ,0);
|
146 |
|
|
GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
|
150 |
d6e94c84
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
|
152 |
2b942cd0
|
Leszek Koltunski
|
synchronized static void sendZero(DistortedFramebuffer df)
|
153 |
d6e94c84
|
Leszek Koltunski
|
{
|
154 |
bfe2c61b
|
Leszek Koltunski
|
Matrix.setIdentityM(mTmpMatrix, 0);
|
155 |
2b942cd0
|
Leszek Koltunski
|
Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
|
156 |
bfe2c61b
|
Leszek Koltunski
|
Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
|
157 |
|
|
|
158 |
d6e94c84
|
Leszek Koltunski
|
GLES20.glUniform1i( mNumEffectsH, 0);
|
159 |
2b942cd0
|
Leszek Koltunski
|
GLES20.glUniform2f( mObjDH , df.mWidth, df.mHeight);
|
160 |
bfe2c61b
|
Leszek Koltunski
|
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
161 |
d6e94c84
|
Leszek Koltunski
|
}
|
162 |
|
|
|
163 |
4c1dd6e9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164 |
|
|
// blur
|
165 |
|
|
|
166 |
|
|
synchronized long add(EffectNames eln, Data1D degree, Data2D center)
|
167 |
|
|
{
|
168 |
|
|
if( mMax[INDEX]>mNumEffects )
|
169 |
|
|
{
|
170 |
|
|
if( degree instanceof Dynamic1D)
|
171 |
|
|
{
|
172 |
|
|
mInter[0][mNumEffects] = (Dynamic1D)degree;
|
173 |
|
|
}
|
174 |
|
|
else if( degree instanceof Static1D)
|
175 |
|
|
{
|
176 |
|
|
mInter[0][mNumEffects] = null;
|
177 |
|
|
mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)degree).getX();
|
178 |
|
|
}
|
179 |
|
|
else return -1;
|
180 |
|
|
|
181 |
|
|
if( center instanceof Dynamic2D)
|
182 |
|
|
{
|
183 |
|
|
mInter[1][mNumEffects] = (Dynamic2D)center;
|
184 |
|
|
}
|
185 |
|
|
else if( center instanceof Static2D)
|
186 |
|
|
{
|
187 |
|
|
mInter[1][mNumEffects] = null;
|
188 |
|
|
mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)center).getX();
|
189 |
|
|
mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static2D)center).getY();
|
190 |
|
|
}
|
191 |
|
|
else return -1;
|
192 |
|
|
|
193 |
|
|
return addBase(eln);
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
return -1;
|
197 |
|
|
}
|
198 |
|
|
}
|