Revision c731c612
Added by Leszek Koltunski about 6 years ago
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
85 | 85 |
|
86 | 86 |
private static IntBuffer mIntBuffer; |
87 | 87 |
|
88 |
private static ByteBuffer mBuf; |
|
89 |
private static IntBuffer mIntBuf; |
|
88 |
private static ByteBuffer mBuf, mAtomicBuf;
|
|
89 |
private static IntBuffer mIntBuf, mAtomicIntBuf;
|
|
90 | 90 |
|
91 | 91 |
/// BLIT DEPTH RENDER PROGRAM /// |
92 | 92 |
private static DistortedProgram mBlitDepthRenderProgram; |
... | ... | |
192 | 192 |
if( mLinkedListSSBO[0]<0 ) |
193 | 193 |
{ |
194 | 194 |
GLES31.glGenBuffers(1,mLinkedListSSBO,0); |
195 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]); |
|
195 | 196 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]); |
196 | 197 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW); |
197 |
|
|
198 |
mBuf = (ByteBuffer)GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, mBufferSize*4, GLES31.GL_MAP_READ_BIT); |
|
199 |
mIntBuf = mBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
200 |
|
|
201 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]); |
|
198 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0); |
|
202 | 199 |
} |
203 | 200 |
|
204 | 201 |
if( mAtomicCounter[0]<0 ) |
205 | 202 |
{ |
206 | 203 |
GLES31.glGenBuffers(1,mAtomicCounter,0); |
204 |
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[0]); |
|
207 | 205 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
208 | 206 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, mIntBuffer, GLES31.GL_DYNAMIC_DRAW); |
209 | 207 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
... | ... | |
408 | 406 |
|
409 | 407 |
// reset atomic counter to 0 |
410 | 408 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
411 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, mIntBuffer, GLES31.GL_DYNAMIC_DRAW); |
|
409 |
|
|
410 |
mAtomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4, |
|
411 |
GLES31.GL_MAP_READ_BIT|GLES31.GL_MAP_WRITE_BIT); |
|
412 |
if( mAtomicBuf!=null ) |
|
413 |
{ |
|
414 |
mAtomicIntBuf = mAtomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
415 |
|
|
416 |
int counter = mAtomicIntBuf.get(0); |
|
417 |
mAtomicIntBuf.put(0, 0); |
|
418 |
//android.util.Log.e("counter", "now = "+counter+" w="+surface.mWidth+" h="+surface.mHeight |
|
419 |
// +" diff="+(counter-surface.mWidth*surface.mHeight)); |
|
420 |
} |
|
421 |
else |
|
422 |
{ |
|
423 |
android.util.Log.e("counter", "failed to map buffer"); |
|
424 |
} |
|
425 |
|
|
426 |
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER); |
|
412 | 427 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
413 | 428 |
} |
414 | 429 |
|
415 | 430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
416 | 431 |
|
417 |
|
|
418 | 432 |
private static void analyzeBuffer(int w, int h) |
419 | 433 |
{ |
420 |
int ptr; |
|
421 |
final int GREEN = 1; |
|
422 |
final int RED = 2; |
|
434 |
int ptr, index; |
|
435 |
int errors = 0; |
|
423 | 436 |
|
424 |
int left1=0, left2=0;
|
|
425 |
int right1=0, right2=0;
|
|
426 |
int overflow = 0;
|
|
437 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
|
|
438 |
mBuf = (ByteBuffer)GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, mBufferSize*4, GLES31.GL_MAP_READ_BIT);
|
|
439 |
mIntBuf = mBuf.order(ByteOrder.nativeOrder()).asIntBuffer();
|
|
427 | 440 |
|
428 |
for(int row=0; row<h; row++)
|
|
429 |
for(int col=0; col<w; col++)
|
|
441 |
for(int col=0; col<w; col++)
|
|
442 |
for(int row=0; row<h; row++)
|
|
430 | 443 |
{ |
431 |
ptr = mIntBuf.get( col+row*w ); |
|
444 |
index = col+row*w; |
|
445 |
ptr = mIntBuf.get(index); |
|
432 | 446 |
|
433 | 447 |
if( ptr!=0 ) |
434 | 448 |
{ |
435 | 449 |
if( ptr>0 && ptr<mBufferSize ) |
436 | 450 |
{ |
437 | 451 |
ptr = mIntBuf.get(ptr); |
438 |
|
|
439 |
if ((2*col>w) && ptr != RED) |
|
440 |
{ |
|
441 |
if (ptr==GREEN) right1++; |
|
442 |
else right2++; |
|
443 |
} |
|
444 |
if ((2*col<=w) && ptr != GREEN) |
|
452 |
if( ptr != index ) |
|
445 | 453 |
{ |
446 |
if (ptr==RED) left1++;
|
|
447 |
else left2++;
|
|
454 |
android.util.Log.d("surface", "col="+col+" row="+row+" val="+ptr+" expected: "+index);
|
|
455 |
errors++;
|
|
448 | 456 |
} |
449 | 457 |
} |
450 | 458 |
else |
451 | 459 |
{ |
452 |
overflow++;
|
|
460 |
android.util.Log.d("surface", "overflow!");
|
|
453 | 461 |
} |
454 | 462 |
} |
455 | 463 |
} |
456 | 464 |
|
457 |
android.util.Log.e("surface", " left1: "+left1+" left2: "+left2+" right1: "+right1+" right2: "+right2+" overflow: "+overflow); |
|
465 |
GLES31.glUnmapBuffer(GLES31.GL_SHADER_STORAGE_BUFFER); |
|
466 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0); |
|
467 |
|
|
468 |
if( errors>0 ) android.util.Log.e("surface", "errors: "+errors); |
|
458 | 469 |
} |
459 | 470 |
|
460 | 471 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Fix the 'OIT' artefacts.