Revision b11171e8
Added by Leszek Koltunski almost 3 years ago
src/main/java/org/distorted/library/effect/PostprocessEffectBlurred.java | ||
---|---|---|
186 | 186 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
187 | 187 |
GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
188 | 188 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
189 |
mProgram1.stopUsingProgram(); |
|
189 | 190 |
|
190 | 191 |
// vertical blur |
191 | 192 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH; |
... | ... | |
208 | 209 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
209 | 210 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
210 | 211 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
212 |
mProgram1.stopUsingProgram(); |
|
211 | 213 |
|
212 | 214 |
InternalRenderState.unuseStencilMark(); |
213 | 215 |
|
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
---|---|---|
202 | 202 |
} |
203 | 203 |
|
204 | 204 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() ); |
205 |
mPreProgram.stopUsingProgram(); |
|
205 | 206 |
|
206 | 207 |
InternalRenderState.restoreBlending(); |
207 | 208 |
InternalRenderState.unsetUpStencilMark(); |
src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
---|---|---|
529 | 529 |
mesh.bindTransformAttribs(mNormalProgram); |
530 | 530 |
GLES30.glLineWidth(8.0f); |
531 | 531 |
GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*num); |
532 |
mNormalProgram.stopUsingProgram(); |
|
532 | 533 |
} |
533 | 534 |
|
534 | 535 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
569 | 570 |
GLES30.glEndTransformFeedback(); |
570 | 571 |
mesh.copyTransformToVertex(); |
571 | 572 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0); |
573 |
mFullProgram.stopUsingProgram(); |
|
572 | 574 |
} |
573 | 575 |
|
574 | 576 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
596 | 598 |
|
597 | 599 |
EffectQueue.send(queues, mMainOITProgramH, distance, mipmap, projection, inflate, 1 ); |
598 | 600 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() ); |
601 |
mMainOITProgram.stopUsingProgram(); |
|
599 | 602 |
|
600 |
if( mesh.getShowNormals() ) |
|
601 |
{ |
|
602 |
mMainProgram.useProgram(); |
|
603 |
mesh.send(mMainProgramH,0); |
|
604 |
EffectQueue.send(queues, mMainProgramH, distance, mipmap, projection, inflate, 0 ); |
|
605 |
displayNormals(projection,mesh); |
|
606 |
} |
|
603 |
if( mesh.getShowNormals() ) displayNormals(projection,mesh); |
|
607 | 604 |
} |
608 | 605 |
} |
609 | 606 |
|
... | ... | |
630 | 627 |
|
631 | 628 |
EffectQueue.send(queues, mMainProgramH, distance, mipmap, projection, inflate, 0 ); |
632 | 629 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() ); |
630 |
mMainProgram.stopUsingProgram(); |
|
633 | 631 |
|
634 | 632 |
if( mesh.getShowNormals() ) displayNormals(projection,mesh); |
635 | 633 |
} |
... | ... | |
642 | 640 |
if( mBlitProgram!=null ) |
643 | 641 |
{ |
644 | 642 |
mBlitProgram.useProgram(); |
645 |
|
|
646 | 643 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
647 | 644 |
GLES30.glUniform1i(mBlitTextureH, 0); |
648 | 645 |
GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear); |
649 | 646 |
GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
650 | 647 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
648 |
mBlitProgram.stopUsingProgram(); |
|
651 | 649 |
} |
652 | 650 |
} |
653 | 651 |
|
... | ... | |
658 | 656 |
if( mBlitDepthProgram!=null ) |
659 | 657 |
{ |
660 | 658 |
mBlitDepthProgram.useProgram(); |
661 |
|
|
662 | 659 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
663 | 660 |
GLES30.glUniform1i(mBlitDepthTextureH, 0); |
664 | 661 |
GLES30.glUniform1i(mBlitDepthDepthTextureH, 1); |
665 | 662 |
GLES30.glUniform2f(mBlitDepthTexCorrH, corrW, corrH ); |
666 | 663 |
GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
667 | 664 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
665 |
mBlitDepthProgram.stopUsingProgram(); |
|
668 | 666 |
} |
669 | 667 |
} |
670 | 668 |
|
... | ... | |
801 | 799 |
} |
802 | 800 |
|
803 | 801 |
mOITClearProgram.useProgram(); |
804 |
|
|
805 | 802 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
806 | 803 |
GLES30.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f ); // corrections do not really matter here - only present because of common vertex shader. |
807 | 804 |
GLES30.glUniform1f( mOITClearDepthH , 1.0f); // likewise depth |
808 | 805 |
GLES30.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight); |
809 | 806 |
GLES30.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
810 | 807 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
808 |
mOITClearProgram.stopUsingProgram(); |
|
811 | 809 |
} |
812 | 810 |
|
813 | 811 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
818 | 816 |
if( mOITBuildProgram!=null ) |
819 | 817 |
{ |
820 | 818 |
mOITBuildProgram.useProgram(); |
821 |
|
|
822 | 819 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
823 | 820 |
GLES30.glUniform1i(mOITBuildTextureH, 0); |
824 | 821 |
GLES30.glUniform1i(mOITBuildDepthTextureH, 1); |
... | ... | |
828 | 825 |
GLES30.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear); |
829 | 826 |
GLES30.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
830 | 827 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
828 |
mOITBuildProgram.stopUsingProgram(); |
|
831 | 829 |
} |
832 | 830 |
} |
833 | 831 |
|
... | ... | |
839 | 837 |
if( mOITCollapseProgram!=null ) |
840 | 838 |
{ |
841 | 839 |
mOITCollapseProgram.useProgram(); |
842 |
|
|
843 | 840 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
844 | 841 |
GLES30.glUniform1i(mOITCollapseDepthTextureH, 1); |
845 | 842 |
GLES30.glUniform2f(mOITCollapseTexCorrH, corrW, corrH ); |
... | ... | |
847 | 844 |
GLES30.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear); |
848 | 845 |
GLES30.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
849 | 846 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
847 |
mOITCollapseProgram.stopUsingProgram(); |
|
850 | 848 |
} |
851 | 849 |
} |
852 | 850 |
|
... | ... | |
858 | 856 |
if( mOITRenderProgram!=null ) |
859 | 857 |
{ |
860 | 858 |
mOITRenderProgram.useProgram(); |
861 |
|
|
862 | 859 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
863 | 860 |
GLES30.glUniform2f(mOITRenderTexCorrH, corrW, corrH ); |
864 | 861 |
GLES30.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight); |
865 | 862 |
GLES30.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear); |
866 | 863 |
GLES30.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
867 | 864 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
865 |
mOITRenderProgram.stopUsingProgram(); |
|
868 | 866 |
} |
869 | 867 |
} |
870 | 868 |
|
src/main/java/org/distorted/library/program/DistortedProgram.java | ||
---|---|---|
43 | 43 |
/** |
44 | 44 |
* List of Attributes (OpenGL ES 3.0: 'in' variables), in the same order as declared in the shader source. |
45 | 45 |
*/ |
46 |
public final int[] mAttribute;
|
|
46 |
public int[] mAttribute; |
|
47 | 47 |
/** |
48 | 48 |
* List of Uniforms, in the same order as declared in the shader source. |
49 | 49 |
*/ |
50 |
public final int[] mUniform;
|
|
50 |
public int[] mUniform; |
|
51 | 51 |
|
52 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
53 | 53 |
|
... | ... | |
330 | 330 |
} |
331 | 331 |
|
332 | 332 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
333 |
/** |
|
334 |
* Only for use by the library itself. |
|
335 |
* |
|
336 |
* @y.exclude |
|
337 |
*/ |
|
338 |
public DistortedProgram(final InputStream vert, final InputStream frag, final String vertHeader, final String fragHeader, |
|
339 |
int glslVersion, final String[] feedback ) |
|
340 |
throws FragmentCompilationException,VertexCompilationException,LinkingException |
|
341 |
{ |
|
342 |
init(glslVersion); |
|
343 |
|
|
344 |
final String vertShader = readTextFileFromRawResource(vert, true ); |
|
345 |
final String fragShader = readTextFileFromRawResource(frag, false); |
|
346 |
|
|
347 |
final int vertShaderHandle = compileShader(GLES30.GL_VERTEX_SHADER , vertHeader + vertShader); |
|
348 |
final int fragShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragHeader + fragShader); |
|
349 |
|
|
350 |
mProgramHandle = createAndLinkProgram(vertShaderHandle, fragShaderHandle, mAttributeName, glslVersion>= 300 ? feedback:null ); |
|
351 | 333 |
|
334 |
private void setUpAttributes() |
|
335 |
{ |
|
352 | 336 |
mAttribute = new int[mNumAttributes]; |
353 | 337 |
|
354 | 338 |
for(int i=0; i<mNumAttributes; i++) |
... | ... | |
356 | 340 |
mAttribute[i] = GLES30.glGetAttribLocation( mProgramHandle, mAttributeName[i]); |
357 | 341 |
} |
358 | 342 |
|
343 |
int emptyAttrs = 0; |
|
344 |
|
|
345 |
for(int i=0; i<mNumAttributes; i++) |
|
346 |
{ |
|
347 |
if( mAttribute[i] < 0 ) |
|
348 |
{ |
|
349 |
emptyAttrs++; |
|
350 |
|
|
351 |
for(int j=i; j<mNumAttributes-1; j++) |
|
352 |
{ |
|
353 |
mAttribute[j] = mAttribute[j+1]; |
|
354 |
mAttributeName[j] = mAttributeName[j+1]; |
|
355 |
} |
|
356 |
} |
|
357 |
} |
|
358 |
|
|
359 |
mNumAttributes -= emptyAttrs; |
|
360 |
} |
|
361 |
|
|
362 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 |
|
|
364 |
private void setUpUniforms() |
|
365 |
{ |
|
359 | 366 |
if( mNumUniforms>0 ) |
360 | 367 |
{ |
361 | 368 |
mUniform = new int[mNumUniforms]; |
... | ... | |
369 | 376 |
else mUniform = null; |
370 | 377 |
} |
371 | 378 |
|
379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
380 |
/** |
|
381 |
* Only for use by the library itself. |
|
382 |
* |
|
383 |
* @y.exclude |
|
384 |
*/ |
|
385 |
public DistortedProgram(final InputStream vert, final InputStream frag, final String vertHeader, final String fragHeader, |
|
386 |
int glslVersion, final String[] feedback ) |
|
387 |
throws FragmentCompilationException,VertexCompilationException,LinkingException |
|
388 |
{ |
|
389 |
init(glslVersion); |
|
390 |
|
|
391 |
final String vertShader = readTextFileFromRawResource(vert, true ); |
|
392 |
final String fragShader = readTextFileFromRawResource(frag, false); |
|
393 |
|
|
394 |
final int vertShaderHandle = compileShader(GLES30.GL_VERTEX_SHADER , vertHeader + vertShader); |
|
395 |
final int fragShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragHeader + fragShader); |
|
396 |
|
|
397 |
mProgramHandle = createAndLinkProgram(vertShaderHandle, fragShaderHandle, mAttributeName, glslVersion>= 300 ? feedback:null ); |
|
398 |
|
|
399 |
setUpAttributes(); |
|
400 |
setUpUniforms(); |
|
401 |
} |
|
402 |
|
|
372 | 403 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
373 | 404 |
/** |
374 | 405 |
* Only for use by the library itself. |
... | ... | |
392 | 423 |
|
393 | 424 |
mProgramHandle = createAndLinkProgram(vertShaderHandle, fragShaderHandle, mAttributeName, glslVersion>= 300 ? feedback:null ); |
394 | 425 |
|
395 |
mAttribute = new int[mNumAttributes]; |
|
396 |
|
|
397 |
for(int i=0; i<mNumAttributes; i++) |
|
398 |
{ |
|
399 |
mAttribute[i] = GLES30.glGetAttribLocation( mProgramHandle, mAttributeName[i]); |
|
400 |
} |
|
401 |
|
|
402 |
if( mNumUniforms>0 ) |
|
403 |
{ |
|
404 |
mUniform = new int[mNumUniforms]; |
|
405 |
mUniformName = mUniList.split(" "); |
|
406 |
|
|
407 |
for(int i=0; i<mNumUniforms; i++) |
|
408 |
{ |
|
409 |
mUniform[i] = GLES30.glGetUniformLocation( mProgramHandle, mUniformName[i]); |
|
410 |
} |
|
411 |
} |
|
412 |
else mUniform = null; |
|
426 |
setUpAttributes(); |
|
427 |
setUpUniforms(); |
|
413 | 428 |
} |
414 | 429 |
|
415 | 430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
434 | 449 |
* |
435 | 450 |
* @param vertex Vertex shader code. |
436 | 451 |
* @param fragment Fragment shader code. |
437 |
* @throws FragmentCompilationException |
|
438 |
* @throws VertexCompilationException |
|
439 |
* @throws LinkingException |
|
452 |
* @throws FragmentCompilationException fragment shader failed to compile
|
|
453 |
* @throws VertexCompilationException vertex shader failed to compile
|
|
454 |
* @throws LinkingException shaders failed to link
|
|
440 | 455 |
*/ |
441 | 456 |
public DistortedProgram(final String vertex, final String fragment) |
442 | 457 |
throws FragmentCompilationException,VertexCompilationException,LinkingException |
... | ... | |
451 | 466 |
|
452 | 467 |
mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, null ); |
453 | 468 |
|
454 |
mAttribute = new int[mNumAttributes]; |
|
455 |
|
|
456 |
for(int i=0; i<mNumAttributes; i++) |
|
457 |
{ |
|
458 |
mAttribute[i] = GLES30.glGetAttribLocation( mProgramHandle, mAttributeName[i]); |
|
459 |
} |
|
460 |
|
|
461 |
if( mNumUniforms>0 ) |
|
462 |
{ |
|
463 |
mUniform = new int[mNumUniforms]; |
|
464 |
mUniformName = mUniList.split(" "); |
|
465 |
|
|
466 |
for(int i=0; i<mNumUniforms; i++) |
|
467 |
{ |
|
468 |
mUniform[i] = GLES30.glGetUniformLocation( mProgramHandle, mUniformName[i]); |
|
469 |
} |
|
470 |
} |
|
471 |
else mUniform = null; |
|
469 |
setUpAttributes(); |
|
470 |
setUpUniforms(); |
|
472 | 471 |
} |
473 | 472 |
|
474 | 473 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
491 | 490 |
GLES30.glUseProgram(mProgramHandle); |
492 | 491 |
|
493 | 492 |
for(int i=0; i<mNumAttributes; i++) |
493 |
{ |
|
494 | 494 |
GLES30.glEnableVertexAttribArray(mAttribute[i]); |
495 |
} |
|
496 |
} |
|
497 |
|
|
498 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
499 |
/** |
|
500 |
* Disable all vertex attribute arrays. |
|
501 |
* |
|
502 |
* Needs to be called from a thread holding the OpenGL context. |
|
503 |
*/ |
|
504 |
public void stopUsingProgram() |
|
505 |
{ |
|
506 |
GLES30.glUseProgram(0); |
|
507 |
|
|
508 |
for(int i=0; i<mNumAttributes; i++) |
|
509 |
{ |
|
510 |
GLES30.glDisableVertexAttribArray(mAttribute[i]); |
|
511 |
} |
|
495 | 512 |
} |
496 | 513 |
} |
497 | 514 |
|
Also available in: Unified diff
Add DistortedProgram.stopUsingProgram()