Revision 375b3950
Added by Leszek Koltunski about 6 years ago
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
70 | 70 |
|
71 | 71 |
/// BLIT DEPTH PROGRAM /// |
72 | 72 |
private static DistortedProgram mBlitDepthProgram; |
73 |
private static int mBlitDepthTextureH; |
|
74 |
private static int mBlitDepthDepthTextureH; |
|
75 |
private static int mBlitDepthDepthH; |
|
76 |
private static int mBlitDepthTexCorrH; |
|
73 | 77 |
private static int mBlitDepthSizeH; |
78 |
private static int mBlitDepthNumRecordsH; |
|
74 | 79 |
|
75 | 80 |
private static int[] mLinkedListSSBO = new int[1]; |
76 | 81 |
private static int[] mAtomicCounter = new int[1]; |
... | ... | |
83 | 88 |
|
84 | 89 |
private static int mBufferSize=(0x1<<23); // 8 million entries |
85 | 90 |
|
86 |
private static IntBuffer mIntBuffer; |
|
87 |
|
|
88 |
private static ByteBuffer mBuf, mAtomicBuf; |
|
89 |
private static IntBuffer mIntBuf, mAtomicIntBuf; |
|
90 |
|
|
91 | 91 |
/// BLIT DEPTH RENDER PROGRAM /// |
92 | 92 |
private static DistortedProgram mBlitDepthRenderProgram; |
93 |
private static int mBlitDepthRenderDepthTextureH; |
|
94 |
private static int mBlitDepthRenderDepthH; |
|
95 |
private static int mBlitDepthRenderTexCorrH; |
|
93 | 96 |
private static int mBlitDepthRenderSizeH; |
94 | 97 |
|
95 | 98 |
/// NORMAL PROGRAM ///// |
... | ... | |
184 | 187 |
} |
185 | 188 |
|
186 | 189 |
int blitDepthProgramH = mBlitDepthProgram.getProgramHandle(); |
190 |
mBlitDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Texture"); |
|
191 |
mBlitDepthDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture"); |
|
192 |
mBlitDepthDepthH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Depth"); |
|
193 |
mBlitDepthTexCorrH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_TexCorr"); |
|
187 | 194 |
mBlitDepthSizeH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Size"); |
188 |
|
|
189 |
mIntBuffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
190 |
mIntBuffer.put(0,0); |
|
195 |
mBlitDepthNumRecordsH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_numRecords"); |
|
191 | 196 |
|
192 | 197 |
if( mLinkedListSSBO[0]<0 ) |
193 | 198 |
{ |
... | ... | |
203 | 208 |
GLES31.glGenBuffers(1,mAtomicCounter,0); |
204 | 209 |
GLES31.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[0]); |
205 | 210 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
206 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, mIntBuffer, GLES31.GL_DYNAMIC_DRAW);
|
|
211 |
GLES31.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES31.GL_DYNAMIC_DRAW);
|
|
207 | 212 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
208 | 213 |
} |
209 | 214 |
|
... | ... | |
222 | 227 |
} |
223 | 228 |
|
224 | 229 |
int blitDepthRenderProgramH = mBlitDepthRenderProgram.getProgramHandle(); |
230 |
mBlitDepthRenderDepthTextureH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_DepthTexture"); |
|
231 |
mBlitDepthRenderDepthH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_Depth"); |
|
232 |
mBlitDepthRenderTexCorrH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_TexCorr"); |
|
225 | 233 |
mBlitDepthRenderSizeH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_Size"); |
226 | 234 |
|
227 | 235 |
// NORMAL PROGRAM ////////////////////////////////////// |
... | ... | |
377 | 385 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
378 | 386 |
} |
379 | 387 |
|
388 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
389 |
// reset atomic counter to 0 |
|
390 |
|
|
391 |
static void zeroOutAtomic() |
|
392 |
{ |
|
393 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
|
394 |
|
|
395 |
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4, |
|
396 |
GLES31.GL_MAP_READ_BIT|GLES31.GL_MAP_WRITE_BIT); |
|
397 |
if( atomicBuf!=null ) |
|
398 |
{ |
|
399 |
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
400 |
|
|
401 |
int counter = atomicIntBuf.get(0); |
|
402 |
atomicIntBuf.put(0, 0); |
|
403 |
//android.util.Log.e("counter", "now = "+counter+" w="+surface.mWidth+" h="+surface.mHeight |
|
404 |
// +" diff="+(counter-surface.mWidth*surface.mHeight)); |
|
405 |
} |
|
406 |
else |
|
407 |
{ |
|
408 |
android.util.Log.e("counter", "failed to map buffer"); |
|
409 |
} |
|
410 |
|
|
411 |
GLES31.glUnmapBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER); |
|
412 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
|
413 |
} |
|
414 |
|
|
380 | 415 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
381 | 416 |
|
382 | 417 |
static void blitDepthPriv(DistortedOutputSurface surface, float corrW, float corrH) |
... | ... | |
384 | 419 |
mBlitDepthProgram.useProgram(); |
385 | 420 |
|
386 | 421 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
422 |
GLES31.glUniform1i(mBlitDepthTextureH, 0); |
|
423 |
GLES31.glUniform1i(mBlitDepthDepthTextureH, 1); |
|
424 |
GLES31.glUniform2f(mBlitDepthTexCorrH, corrW, corrH ); |
|
387 | 425 |
GLES31.glUniform2f(mBlitDepthSizeH, surface.mWidth, surface.mHeight); |
426 |
GLES31.glUniform1ui(mBlitDepthNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader |
|
427 |
GLES31.glUniform1f(mBlitDepthDepthH , 1.0f-surface.mNear); |
|
388 | 428 |
GLES31.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
389 | 429 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
390 | 430 |
} |
... | ... | |
400 | 440 |
//analyzeBuffer(surface.mWidth, surface.mHeight); |
401 | 441 |
|
402 | 442 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
443 |
GLES31.glUniform1i(mBlitDepthRenderDepthTextureH, 1); |
|
444 |
GLES31.glUniform2f(mBlitDepthRenderTexCorrH, corrW, corrH ); |
|
403 | 445 |
GLES31.glUniform2f(mBlitDepthRenderSizeH, surface.mWidth, surface.mHeight); |
446 |
GLES31.glUniform1f( mBlitDepthRenderDepthH , 1.0f-surface.mNear); |
|
404 | 447 |
GLES31.glVertexAttribPointer(mBlitDepthRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
405 | 448 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
406 |
|
|
407 |
// reset atomic counter to 0 |
|
408 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
|
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); |
|
427 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
|
428 | 449 |
} |
429 | 450 |
|
430 | 451 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
435 | 456 |
int errors = 0; |
436 | 457 |
|
437 | 458 |
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();
|
|
459 |
ByteBuffer buf = (ByteBuffer)GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, mBufferSize*4, GLES31.GL_MAP_READ_BIT);
|
|
460 |
IntBuffer intBuf = buf.order(ByteOrder.nativeOrder()).asIntBuffer();
|
|
440 | 461 |
|
441 | 462 |
for(int col=0; col<w; col++) |
442 | 463 |
for(int row=0; row<h; row++) |
443 | 464 |
{ |
444 | 465 |
index = col+row*w; |
445 |
ptr = mIntBuf.get(index);
|
|
466 |
ptr = intBuf.get(index);
|
|
446 | 467 |
|
447 | 468 |
if( ptr!=0 ) |
448 | 469 |
{ |
449 | 470 |
if( ptr>0 && ptr<mBufferSize ) |
450 | 471 |
{ |
451 |
ptr = mIntBuf.get(ptr);
|
|
472 |
ptr = intBuf.get(ptr);
|
|
452 | 473 |
if( ptr != index ) |
453 | 474 |
{ |
454 | 475 |
android.util.Log.d("surface", "col="+col+" row="+row+" val="+ptr+" expected: "+index); |
Also available in: Unified diff
OIT: something starts working ('Blur' and 'Multiblur' work, 'Triblur' and 'Transparency' do not)