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;
|
21
|
|
22
|
import android.opengl.GLES20;
|
23
|
import android.opengl.Matrix;
|
24
|
|
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
|
private static int mMVPMatrixH;
|
46
|
|
47
|
private static float[] mMVPMatrix = new float[16];
|
48
|
private static float[] mTmpMatrix = new float[16];
|
49
|
|
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
|
mMVPMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
|
66
|
}
|
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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
|
118
|
synchronized void send(DistortedFramebuffer df)
|
119
|
{
|
120
|
Matrix.setIdentityM(mTmpMatrix, 0);
|
121
|
Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
|
122
|
Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
|
123
|
|
124
|
GLES20.glUniform1i( mNumEffectsH, mNumEffects);
|
125
|
GLES20.glUniform2f( mObjDH , df.mWidth, df.mHeight);
|
126
|
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
127
|
|
128
|
if( mNumEffects>0 )
|
129
|
{
|
130
|
GLES20.glUniform1iv( mTypeH , mNumEffects, mName ,0);
|
131
|
GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
|
132
|
}
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
synchronized static void sendZero(DistortedFramebuffer df)
|
138
|
{
|
139
|
Matrix.setIdentityM(mTmpMatrix, 0);
|
140
|
Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
|
141
|
Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
|
142
|
|
143
|
GLES20.glUniform1i( mNumEffectsH, 0);
|
144
|
GLES20.glUniform2f( mObjDH , df.mWidth, df.mHeight);
|
145
|
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
// blur
|
150
|
|
151
|
synchronized long add(EffectNames eln, Data1D degree, Data2D center)
|
152
|
{
|
153
|
if( mMax[INDEX]>mNumEffects )
|
154
|
{
|
155
|
if( degree instanceof Dynamic1D)
|
156
|
{
|
157
|
mInter[0][mNumEffects] = (Dynamic1D)degree;
|
158
|
}
|
159
|
else if( degree instanceof Static1D)
|
160
|
{
|
161
|
mInter[0][mNumEffects] = null;
|
162
|
mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)degree).getX();
|
163
|
}
|
164
|
else return -1;
|
165
|
|
166
|
if( center instanceof Dynamic2D)
|
167
|
{
|
168
|
mInter[1][mNumEffects] = (Dynamic2D)center;
|
169
|
}
|
170
|
else if( center instanceof Static2D)
|
171
|
{
|
172
|
mInter[1][mNumEffects] = null;
|
173
|
mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)center).getX();
|
174
|
mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static2D)center).getY();
|
175
|
}
|
176
|
else return -1;
|
177
|
|
178
|
return addBase(eln);
|
179
|
}
|
180
|
|
181
|
return -1;
|
182
|
}
|
183
|
}
|