Revision acb44099
Added by Leszek Koltunski over 6 years ago
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
/////////////////////////////////////////////////////////////// |
88 |
// this has to be at least as big as the number of pixels in
|
|
89 |
// the screen, lest the oitClear() pass overwrite memory.
|
|
90 |
private static int mBufferSize=(0x1<<23); // 8 million entries
|
|
88 |
// meaning: allocate 1.0 screenful of places for transparent
|
|
89 |
// fragments in the SSBO backing up the OIT render method.
|
|
90 |
private static float mBufferSize=1.0f;
|
|
91 | 91 |
|
92 | 92 |
/// OIT CLEAR PROGRAM /// |
93 | 93 |
private static DistortedProgram mOITClearProgram; |
... | ... | |
311 | 311 |
mOITBuildSizeH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Size"); |
312 | 312 |
mOITBuildNumRecordsH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_numRecords"); |
313 | 313 |
|
314 |
if( mLinkedListSSBO[0]<0 ) |
|
315 |
{ |
|
316 |
GLES31.glGenBuffers(1,mLinkedListSSBO,0); |
|
317 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]); |
|
318 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW); |
|
319 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]); |
|
320 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0); |
|
321 |
} |
|
322 |
|
|
323 |
if( mAtomicCounter[0]<0 ) |
|
324 |
{ |
|
325 |
GLES31.glGenBuffers(1,mAtomicCounter,0); |
|
326 |
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[0]); |
|
327 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
|
328 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES31.GL_DYNAMIC_DRAW); |
|
329 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
|
330 |
} |
|
331 |
|
|
332 | 314 |
// OIT COLLAPSE PROGRAM /////////////////////////// |
333 | 315 |
final InputStream oitCollapseVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
334 | 316 |
final InputStream oitCollapseFragStream = resources.openRawResource(R.raw.oit_collapse_fragment_shader); |
... | ... | |
472 | 454 |
mMainOITProgram.useProgram(); |
473 | 455 |
GLES31.glUniform1i(mMainOITTextureH, 0); |
474 | 456 |
GLES31.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight); |
475 |
GLES31.glUniform1ui(mMainOITNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader
|
|
457 |
GLES31.glUniform1ui(mMainOITNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
|
|
476 | 458 |
|
477 | 459 |
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttVBO[0]); |
478 | 460 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0); |
... | ... | |
557 | 539 |
|
558 | 540 |
static void zeroOutAtomic() |
559 | 541 |
{ |
542 |
if( mAtomicCounter[0]<0 ) |
|
543 |
{ |
|
544 |
GLES31.glGenBuffers(1,mAtomicCounter,0); |
|
545 |
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[0]); |
|
546 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
|
547 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES31.GL_DYNAMIC_DRAW); |
|
548 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
|
549 |
} |
|
550 |
|
|
560 | 551 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
561 | 552 |
|
562 | 553 |
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4, |
... | ... | |
584 | 575 |
|
585 | 576 |
static void oitClear(DistortedOutputSurface surface) |
586 | 577 |
{ |
578 |
if( mLinkedListSSBO[0]<0 ) |
|
579 |
{ |
|
580 |
int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4); |
|
581 |
|
|
582 |
GLES31.glGenBuffers(1,mLinkedListSSBO,0); |
|
583 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]); |
|
584 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW); |
|
585 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]); |
|
586 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0); |
|
587 |
} |
|
588 |
|
|
587 | 589 |
mOITClearProgram.useProgram(); |
588 | 590 |
|
589 | 591 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
... | ... | |
606 | 608 |
GLES31.glUniform1i(mOITBuildDepthTextureH, 1); |
607 | 609 |
GLES31.glUniform2f(mOITBuildTexCorrH, corrW, corrH ); |
608 | 610 |
GLES31.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight); |
609 |
GLES31.glUniform1ui(mOITBuildNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader
|
|
611 |
GLES31.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
|
|
610 | 612 |
GLES31.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear); |
611 | 613 |
GLES31.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
612 | 614 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
Also available in: Unified diff
Make the OIT SSBO size independent of screen size.