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
|
|
24
|
import org.distorted.library.message.EffectMessage;
|
25
|
import org.distorted.library.type.Data1D;
|
26
|
import org.distorted.library.type.Data2D;
|
27
|
import org.distorted.library.type.Dynamic1D;
|
28
|
import org.distorted.library.type.Dynamic2D;
|
29
|
import org.distorted.library.type.Static1D;
|
30
|
import org.distorted.library.type.Static2D;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
class EffectQueuePostprocess extends EffectQueue
|
35
|
{
|
36
|
private static final int NUM_UNIFORMS = 3;
|
37
|
private static final int NUM_CACHE = 0;
|
38
|
private static final int INDEX = EffectTypes.POSTPROCESS.ordinal();
|
39
|
|
40
|
private static int mNumEffectsH;
|
41
|
private static int mTypeH;
|
42
|
private static int mUniformsH;
|
43
|
private static int mObjDH;
|
44
|
|
45
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46
|
|
47
|
EffectQueuePostprocess(long id)
|
48
|
{
|
49
|
super(id,NUM_UNIFORMS,NUM_CACHE,INDEX );
|
50
|
}
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
static void getUniforms(int mProgramH)
|
55
|
{
|
56
|
mNumEffectsH= GLES20.glGetUniformLocation( mProgramH, "pNumEffects");
|
57
|
mTypeH = GLES20.glGetUniformLocation( mProgramH, "pType");
|
58
|
mUniformsH = GLES20.glGetUniformLocation( mProgramH, "pUniforms");
|
59
|
mObjDH = GLES20.glGetUniformLocation( mProgramH, "u_objD");
|
60
|
}
|
61
|
|
62
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
|
64
|
synchronized void compute(long currTime)
|
65
|
{
|
66
|
if( currTime==mTime ) return;
|
67
|
if( mTime==0 ) mTime = currTime;
|
68
|
long step = (currTime-mTime);
|
69
|
|
70
|
for(int i=0; i<mNumEffects; i++)
|
71
|
{
|
72
|
if( mInter[0][i]!=null && mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )
|
73
|
{
|
74
|
for(int j=0; j<mNumListeners; j++)
|
75
|
EffectMessageSender.newMessage( mListeners.elementAt(j),
|
76
|
EffectMessage.EFFECT_FINISHED,
|
77
|
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.POSTPROCESS.type,
|
78
|
mName[i],
|
79
|
mObjectID);
|
80
|
|
81
|
if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
|
82
|
{
|
83
|
remove(i);
|
84
|
i--;
|
85
|
continue;
|
86
|
}
|
87
|
else mInter[0][i] = null;
|
88
|
}
|
89
|
|
90
|
if( mInter[1][i]!=null )
|
91
|
{
|
92
|
mInter[1][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+1, mCurrentDuration[i], step);
|
93
|
}
|
94
|
|
95
|
mCurrentDuration[i] += step;
|
96
|
}
|
97
|
|
98
|
mTime = currTime;
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
protected void moveEffect(int index)
|
104
|
{
|
105
|
mUniforms[NUM_UNIFORMS*index ] = mUniforms[NUM_UNIFORMS*(index+1) ];
|
106
|
mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
|
107
|
mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
|
108
|
}
|
109
|
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
synchronized void send(float objX, float objY)
|
113
|
{
|
114
|
GLES20.glUniform1i( mNumEffectsH, mNumEffects);
|
115
|
GLES20.glUniform2f( mObjDH , objX, objY);
|
116
|
|
117
|
if( mNumEffects>0 )
|
118
|
{
|
119
|
GLES20.glUniform1iv( mTypeH , mNumEffects, mName ,0);
|
120
|
GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
|
121
|
}
|
122
|
}
|
123
|
|
124
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125
|
// blur
|
126
|
|
127
|
synchronized long add(EffectNames eln, Data1D degree, Data2D center)
|
128
|
{
|
129
|
if( mMax[INDEX]>mNumEffects )
|
130
|
{
|
131
|
if( degree instanceof Dynamic1D)
|
132
|
{
|
133
|
mInter[0][mNumEffects] = (Dynamic1D)degree;
|
134
|
}
|
135
|
else if( degree instanceof Static1D)
|
136
|
{
|
137
|
mInter[0][mNumEffects] = null;
|
138
|
mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)degree).getX();
|
139
|
}
|
140
|
else return -1;
|
141
|
|
142
|
if( center instanceof Dynamic2D)
|
143
|
{
|
144
|
mInter[1][mNumEffects] = (Dynamic2D)center;
|
145
|
}
|
146
|
else if( center instanceof Static2D)
|
147
|
{
|
148
|
mInter[1][mNumEffects] = null;
|
149
|
mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)center).getX();
|
150
|
mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static2D)center).getY();
|
151
|
}
|
152
|
else return -1;
|
153
|
|
154
|
return addBase(eln);
|
155
|
}
|
156
|
|
157
|
return -1;
|
158
|
}
|
159
|
}
|