54 |
54 |
private static final int NORMAL_DATA_SIZE = 3; // Main Program: size of the normal data in elements
|
55 |
55 |
private static final int TEX_DATA_SIZE = 2; // Main Program: size of the texture coordinate data in elements.
|
56 |
56 |
|
57 |
|
private static DistortedProgram mProgram;
|
|
57 |
/// MAIN PROGRAM ///
|
|
58 |
private static DistortedProgram mMainProgram;
|
|
59 |
private static int mMainTextureH;
|
58 |
60 |
private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
|
59 |
61 |
|
60 |
62 |
static
|
... | ... | |
67 |
69 |
}
|
68 |
70 |
}
|
69 |
71 |
|
70 |
|
/// DEBUG ONLY /////
|
71 |
|
private static DistortedProgram mDebugProgram;
|
|
72 |
/// BLIT PROGRAM ///
|
|
73 |
private static DistortedProgram mBlitProgram;
|
|
74 |
private static int mBlitTextureH;
|
|
75 |
private static int mBlitObjDH;
|
|
76 |
private static int mBlitMVPMatrixH;
|
72 |
77 |
private static final FloatBuffer mQuadPositions;
|
73 |
78 |
|
74 |
79 |
static
|
... | ... | |
78 |
83 |
mQuadPositions.put(positionData).position(0);
|
79 |
84 |
}
|
80 |
85 |
|
81 |
|
private static int mObjDH;
|
82 |
|
private static int mMVPMatrixH;
|
|
86 |
/// DEBUG ONLY /////
|
|
87 |
private static DistortedProgram mDebugProgram;
|
|
88 |
|
|
89 |
private static int mDebugObjDH;
|
|
90 |
private static int mDebugMVPMatrixH;
|
83 |
91 |
/// END DEBUG //////
|
84 |
92 |
|
85 |
93 |
private static float[] mMVPMatrix = new float[16];
|
... | ... | |
139 |
147 |
//android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
|
140 |
148 |
//android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
|
141 |
149 |
|
142 |
|
mProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader);
|
|
150 |
mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader);
|
143 |
151 |
|
144 |
|
int mainProgramH = mProgram.getProgramHandle();
|
|
152 |
int mainProgramH = mMainProgram.getProgramHandle();
|
145 |
153 |
EffectQueueFragment.getUniforms(mainProgramH);
|
146 |
154 |
EffectQueueVertex.getUniforms(mainProgramH);
|
147 |
155 |
EffectQueueMatrix.getUniforms(mainProgramH);
|
148 |
|
DistortedTexture.getUniforms(mainProgramH);
|
|
156 |
mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
|
|
157 |
|
|
158 |
// BLIT PROGRAM ////////////////////////////////////
|
|
159 |
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
|
|
160 |
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
|
|
161 |
|
|
162 |
String blitVertHeader= ("#version 100\n#define NUM_VERTEX 0\n" );
|
|
163 |
String blitFragHeader= ("#version 100\n#define NUM_FRAGMENT 0\n");
|
|
164 |
|
|
165 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader);
|
|
166 |
|
|
167 |
int blitProgramH = mBlitProgram.getProgramHandle();
|
|
168 |
mBlitTextureH = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
|
|
169 |
mBlitObjDH = GLES30.glGetUniformLocation( blitProgramH, "u_objD");
|
|
170 |
mBlitMVPMatrixH= GLES30.glGetUniformLocation( blitProgramH, "u_MVPMatrix");
|
149 |
171 |
|
150 |
172 |
// DEBUG ONLY //////////////////////////////////////
|
151 |
173 |
final InputStream debugVertexStream = resources.openRawResource(R.raw.test_vertex_shader);
|
... | ... | |
154 |
176 |
mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n");
|
155 |
177 |
|
156 |
178 |
int debugProgramH = mDebugProgram.getProgramHandle();
|
157 |
|
mObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
|
158 |
|
mMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
|
|
179 |
mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
|
|
180 |
mDebugMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
|
159 |
181 |
// END DEBUG //////////////////////////////////////
|
160 |
182 |
}
|
161 |
183 |
|
... | ... | |
254 |
276 |
Matrix.translateM ( mTmpMatrix, 0, halfX,-halfY, 0);
|
255 |
277 |
Matrix.multiplyMM ( mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
|
256 |
278 |
|
257 |
|
GLES30.glUniform2f( mObjDH , 2*halfX, 2*halfY);
|
258 |
|
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
|
279 |
GLES30.glUniform2f(mDebugObjDH, 2*halfX, 2*halfY);
|
|
280 |
GLES30.glUniformMatrix4fv(mDebugMVPMatrixH, 1, false, mMVPMatrix , 0);
|
259 |
281 |
|
260 |
282 |
GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
261 |
283 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
... | ... | |
263 |
285 |
|
264 |
286 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
265 |
287 |
|
266 |
|
void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
|
|
288 |
void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
|
267 |
289 |
{
|
268 |
290 |
mM.compute(currTime);
|
269 |
291 |
mV.compute(currTime);
|
270 |
292 |
mF.compute(currTime);
|
271 |
293 |
mP.compute(currTime);
|
272 |
294 |
|
273 |
|
float halfZ = halfInputW*mesh.zFactor;
|
|
295 |
float halfZ = halfW*mesh.zFactor;
|
274 |
296 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
|
275 |
297 |
|
276 |
298 |
if( mP.mNumEffects==0 )
|
277 |
299 |
{
|
278 |
|
mProgram.useProgram();
|
|
300 |
mMainProgram.useProgram();
|
|
301 |
GLES30.glUniform1i(mMainTextureH, 0);
|
279 |
302 |
surface.setAsOutput();
|
280 |
|
mM.send(surface,halfInputW,halfInputH,halfZ);
|
281 |
|
mV.send(halfInputW,halfInputH,halfZ);
|
282 |
|
mF.send(halfInputW,halfInputH);
|
283 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
284 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
285 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
|
303 |
mM.send(surface,halfW,halfH,halfZ);
|
|
304 |
mV.send(halfW,halfH,halfZ);
|
|
305 |
mF.send(halfW,halfH);
|
|
306 |
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
|
307 |
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
|
308 |
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
286 |
309 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
287 |
310 |
}
|
288 |
311 |
else
|
289 |
312 |
{
|
290 |
313 |
if( mV.mNumEffects==0 && mF.mNumEffects==0 && (mesh instanceof MeshFlat) && mM.canUseShortcut() )
|
291 |
314 |
{
|
292 |
|
mM.constructMatrices(surface,halfInputW,halfInputH);
|
293 |
|
mP.render(2*halfInputW, 2*halfInputH, mM.getMVP(), surface);
|
|
315 |
mM.constructMatrices(surface,halfW,halfH);
|
|
316 |
mP.render(2*halfW, 2*halfH, mM.getMVP(), surface);
|
294 |
317 |
}
|
295 |
318 |
else
|
296 |
319 |
{
|
297 |
|
mProgram.useProgram();
|
|
320 |
mMainProgram.useProgram();
|
|
321 |
GLES30.glUniform1i(mMainTextureH, 0);
|
298 |
322 |
mBufferFBO.resizeFast(surface.mWidth, surface.mHeight);
|
299 |
323 |
mBufferFBO.setAsOutput();
|
300 |
324 |
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
301 |
325 |
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
302 |
|
mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
|
303 |
|
mV.send(halfInputW,halfInputH,halfZ);
|
304 |
|
mF.send(halfInputW,halfInputH);
|
305 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
306 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
307 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
|
326 |
mM.send(mBufferFBO,halfW,halfH,halfZ);
|
|
327 |
mV.send(halfW,halfH,halfZ);
|
|
328 |
mF.send(halfW,halfH);
|
|
329 |
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
|
330 |
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
|
331 |
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
308 |
332 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
309 |
333 |
|
310 |
334 |
Matrix.setIdentityM(mTmpMatrix, 0);
|
... | ... | |
323 |
347 |
|
324 |
348 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
325 |
349 |
|
326 |
|
static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedOutputSurface projection)
|
|
350 |
static void blitPriv(DistortedOutputSurface projection)
|
327 |
351 |
{
|
328 |
352 |
GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
|
329 |
353 |
|
|
354 |
mBlitProgram.useProgram();
|
|
355 |
|
330 |
356 |
Matrix.setIdentityM(mTmpMatrix, 0);
|
331 |
357 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -projection.mDistance);
|
332 |
358 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0);
|
333 |
359 |
|
334 |
|
EffectQueueMatrix.sendZero(projection,halfInputW,halfInputH,halfInputW*mesh.zFactor);
|
335 |
|
EffectQueueVertex.sendZero();
|
336 |
|
EffectQueueFragment.sendZero();
|
337 |
|
|
338 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
|
339 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
|
340 |
|
GLES30.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
|
341 |
|
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
|
360 |
GLES30.glUniform1i(mBlitTextureH, 0);
|
|
361 |
GLES30.glUniform2f( mBlitObjDH , projection.mWidth/2, projection.mHeight/2);
|
|
362 |
GLES30.glUniformMatrix4fv(mBlitMVPMatrixH, 1, false, mMVPMatrix, 0);
|
|
363 |
GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
|
364 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
342 |
365 |
}
|
343 |
366 |
|
344 |
367 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Introduce Effects.blitPriv() (faster than previous drawNoEffectsPriv)