22 |
22 |
import android.opengl.GLES20;
|
23 |
23 |
|
24 |
24 |
import org.distorted.library.message.EffectListener;
|
|
25 |
import org.distorted.library.program.DistortedProgram;
|
25 |
26 |
import org.distorted.library.type.Data1D;
|
26 |
27 |
import org.distorted.library.type.Data2D;
|
27 |
28 |
import org.distorted.library.type.Data3D;
|
... | ... | |
42 |
43 |
public class DistortedEffects
|
43 |
44 |
{
|
44 |
45 |
private static final int BYTES_PER_FLOAT = 4; //
|
45 |
|
private static final int POSITION_DATA_SIZE= 2; // Size of the position data in elements
|
46 |
|
private static final int TEX_DATA_SIZE = 2; // Size of the texture coordinate data in elements.
|
|
46 |
private static final int MAIN_POSITION_DATA_SIZE= 3; // Size of the position data in elements
|
|
47 |
private static final int MAIN_NORMAL_DATA_SIZE = 3; // Size of the position data in elements
|
|
48 |
private static final int MAIN_TEX_DATA_SIZE = 2; // Size of the texture coordinate data in elements.
|
|
49 |
private static final int POST_POSITION_DATA_SIZE= 2; // Size of the position data in elements
|
|
50 |
private static final int POST_TEX_DATA_SIZE = 2; // Size of the texture coordinate data in elements.
|
|
51 |
|
47 |
52 |
private static final FloatBuffer mQuadPositions, mQuadTexture;
|
|
53 |
private static DistortedProgram mMainProgram, mPostProgram;
|
48 |
54 |
|
49 |
55 |
private static long mNextID =0;
|
50 |
56 |
private long mID;
|
... | ... | |
65 |
71 |
float[] positionData= { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f };
|
66 |
72 |
float[] textureData = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f };
|
67 |
73 |
|
68 |
|
mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
74 |
mQuadPositions = ByteBuffer.allocateDirect(POST_POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
69 |
75 |
mQuadPositions.put(positionData).position(0);
|
70 |
|
mQuadTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
76 |
mQuadTexture = ByteBuffer.allocateDirect(POST_TEX_DATA_SIZE *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
71 |
77 |
mQuadTexture.put(textureData).position(0);
|
72 |
78 |
|
73 |
79 |
mBufferFBO = new DistortedFramebuffer(1,1);
|
74 |
80 |
}
|
75 |
81 |
|
76 |
82 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
83 |
|
|
84 |
static void setPrograms(DistortedProgram main, DistortedProgram post)
|
|
85 |
{
|
|
86 |
mMainProgram = main;
|
|
87 |
mPostProgram = post;
|
|
88 |
}
|
|
89 |
|
|
90 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
91 |
|
78 |
92 |
private void initializeEffectLists(DistortedEffects d, int flags)
|
79 |
93 |
{
|
80 |
94 |
if( (flags & Distorted.CLONE_MATRIX) != 0 )
|
... | ... | |
132 |
146 |
mP.compute(currTime);
|
133 |
147 |
|
134 |
148 |
float halfZ = halfInputW*mesh.zFactor;
|
|
149 |
GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
|
135 |
150 |
|
136 |
151 |
if( mP.mNumEffects==0 )
|
137 |
152 |
{
|
138 |
|
Distorted.mMainProgram.useProgram();
|
139 |
|
GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
|
140 |
|
|
|
153 |
mMainProgram.useProgram();
|
141 |
154 |
mM.send(df,halfInputW,halfInputH,halfZ);
|
142 |
155 |
mV.send(halfInputW,halfInputH,halfZ);
|
143 |
156 |
mF.send(halfInputW,halfInputH);
|
144 |
|
|
145 |
|
mesh.draw();
|
|
157 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[0], MAIN_POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
|
158 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[1], MAIN_NORMAL_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
|
159 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[2], MAIN_TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
|
160 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
146 |
161 |
}
|
147 |
162 |
else
|
148 |
163 |
{
|
149 |
164 |
if( mV.mNumEffects>0 || mF.mNumEffects>0 )
|
150 |
165 |
{
|
151 |
|
Distorted.mMainProgram.useProgram();
|
152 |
|
GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
|
153 |
|
|
|
166 |
mMainProgram.useProgram();
|
154 |
167 |
mBufferFBO.resizeFast(df.mWidth, df.mHeight);
|
155 |
168 |
mBufferFBO.setAsOutput();
|
156 |
|
|
157 |
169 |
mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
|
158 |
170 |
mV.send(halfInputW,halfInputH,halfZ);
|
159 |
171 |
mF.send(halfInputW,halfInputH);
|
|
172 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[0], MAIN_POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
|
173 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[1], MAIN_NORMAL_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
|
174 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[2], MAIN_TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
|
175 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
160 |
176 |
|
161 |
|
mesh.draw();
|
162 |
|
|
163 |
|
Distorted.mPostProgram.useProgram();
|
|
177 |
mPostProgram.useProgram();
|
164 |
178 |
mBufferFBO.setAsInput();
|
165 |
179 |
df.setAsOutput();
|
166 |
180 |
mP.send(df);
|
167 |
|
|
168 |
|
GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
|
169 |
|
GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[1], TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture);
|
|
181 |
GLES20.glVertexAttribPointer(mPostProgram.mAttribute[0], POST_POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
|
|
182 |
GLES20.glVertexAttribPointer(mPostProgram.mAttribute[1], POST_TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture);
|
170 |
183 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
|
171 |
184 |
}
|
172 |
185 |
else
|
173 |
186 |
{
|
174 |
|
Distorted.mPostProgram.useProgram();
|
175 |
|
GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
|
176 |
|
|
|
187 |
mPostProgram.useProgram();
|
177 |
188 |
mM.constructMatrices(df,halfInputW,halfInputH);
|
178 |
189 |
mP.send(2*halfInputW,2*halfInputH, mM.getMVP() );
|
179 |
|
|
180 |
|
GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
|
181 |
|
GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[1], TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture);
|
|
190 |
GLES20.glVertexAttribPointer(mPostProgram.mAttribute[0], POST_POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
|
|
191 |
GLES20.glVertexAttribPointer(mPostProgram.mAttribute[1], POST_TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture);
|
182 |
192 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
|
183 |
193 |
}
|
184 |
194 |
}
|
... | ... | |
195 |
205 |
EffectQueueFragment.sendZero();
|
196 |
206 |
EffectQueuePostprocess.sendZero(df);
|
197 |
207 |
|
198 |
|
mesh.draw();
|
|
208 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[0], MAIN_POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
|
209 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[1], MAIN_NORMAL_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
|
210 |
GLES20.glVertexAttribPointer(mMainProgram.mAttribute[2], MAIN_TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
|
211 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
199 |
212 |
}
|
200 |
213 |
|
201 |
214 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Minor reorganization.