Revision c1a38ba3
Added by Leszek Koltunski almost 6 years ago
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
70 | 70 |
private static int mBlitDepthDepthH; |
71 | 71 |
private static int mBlitDepthTexCorrH; |
72 | 72 |
|
73 |
/// NORMAL PROGRAM ///// |
|
74 |
private static DistortedProgram mNormalProgram; |
|
75 |
private static int mNormalMVPMatrixH; |
|
76 |
|
|
73 | 77 |
/// OIT SSBO BUFFER /// |
74 | 78 |
private static int[] mLinkedListSSBO = new int[1]; |
75 | 79 |
private static int[] mAtomicCounter = new int[1]; |
... | ... | |
113 | 117 |
private static int mOITRenderTexCorrH; |
114 | 118 |
private static int mOITRenderSizeH; |
115 | 119 |
|
116 |
/// NORMAL PROGRAM ///// |
|
117 |
private static DistortedProgram mNormalProgram; |
|
118 |
private static int mNormalMVPMatrixH; |
|
120 |
/// MAIN OIT PROGRAM /// |
|
121 |
private static DistortedProgram mMainOITProgram; |
|
122 |
private static int mMainOITTextureH; |
|
123 |
private static int mMainOITSizeH; |
|
124 |
private static int mMainOITNumRecordsH; |
|
119 | 125 |
/// END PROGRAMS ////// |
120 | 126 |
|
121 | 127 |
private static long mNextID =0; |
... | ... | |
228 | 234 |
|
229 | 235 |
static void createProgramsOIT(Resources resources) |
230 | 236 |
{ |
237 |
// MAIN OIT PROGRAM //////////////////////////////// |
|
238 |
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader); |
|
239 |
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader); |
|
240 |
|
|
241 |
int numF = FragmentEffect.getNumEnabled(); |
|
242 |
int numV = VertexEffect.getNumEnabled(); |
|
243 |
|
|
244 |
String mainVertHeader= Distorted.GLSL_VERSION + |
|
245 |
("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n") + |
|
246 |
("#define OIT\n"); |
|
247 |
String mainFragHeader= Distorted.GLSL_VERSION + |
|
248 |
("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + |
|
249 |
("#define OIT\n"); |
|
250 |
|
|
251 |
String enabledEffectV= VertexEffect.getGLSL(); |
|
252 |
String enabledEffectF= FragmentEffect.getGLSL(); |
|
253 |
|
|
254 |
try |
|
255 |
{ |
|
256 |
mMainOITProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
|
257 |
enabledEffectV, enabledEffectF, Distorted.GLSL, null); |
|
258 |
} |
|
259 |
catch(Exception e) |
|
260 |
{ |
|
261 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN OIT program: "+e.getMessage()); |
|
262 |
throw new RuntimeException(e.getMessage()); |
|
263 |
} |
|
264 |
|
|
265 |
int mainOITProgramH = mMainOITProgram.getProgramHandle(); |
|
266 |
EffectQueueFragment.getUniformsOIT(mainOITProgramH); |
|
267 |
EffectQueueVertex.getUniformsOIT(mainOITProgramH); |
|
268 |
EffectQueueMatrix.getUniformsOIT(mainOITProgramH); |
|
269 |
mMainOITTextureH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Texture"); |
|
270 |
mMainOITSizeH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Size"); |
|
271 |
mMainOITNumRecordsH = GLES31.glGetUniformLocation( mainOITProgramH, "u_numRecords"); |
|
272 |
|
|
231 | 273 |
// OIT CLEAR PROGRAM //////////////////////////////////// |
232 | 274 |
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
233 | 275 |
final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader); |
... | ... | |
414 | 456 |
GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*mesh.numVertices); |
415 | 457 |
} |
416 | 458 |
|
459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
460 |
|
|
461 |
void drawPrivOIT(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels) |
|
462 |
{ |
|
463 |
float halfZ = halfW*mesh.zFactor; |
|
464 |
|
|
465 |
mM.compute(currTime); |
|
466 |
mV.compute(currTime,halfW,halfH,halfZ); |
|
467 |
mF.compute(currTime,halfW,halfH); |
|
468 |
mP.compute(currTime); |
|
469 |
|
|
470 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
|
471 |
|
|
472 |
mMainOITProgram.useProgram(); |
|
473 |
GLES31.glUniform1i(mMainOITTextureH, 0); |
|
474 |
GLES31.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight); |
|
475 |
GLES31.glUniform1ui(mMainOITNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader |
|
476 |
|
|
477 |
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttVBO[0]); |
|
478 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0); |
|
479 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1); |
|
480 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2); |
|
481 |
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0); |
|
482 |
|
|
483 |
mM.sendOIT(surface,halfW,halfH,halfZ,marginInPixels); |
|
484 |
mV.sendOIT(); |
|
485 |
mF.sendOIT(); |
|
486 |
|
|
487 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices); |
|
488 |
|
|
489 |
if( mesh.mShowNormals ) displayNormals(mesh); |
|
490 |
} |
|
491 |
|
|
417 | 492 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
418 | 493 |
|
419 | 494 |
void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels) |
Also available in: Unified diff
Progress with non-postprocessed OIT.
Status: compiles, but fails to work on both Adreno and Mali. Crashes the app (Adreno) or the whole system (Mali)