Project

General

Profile

« Previous | Next » 

Revision f482efa3

Added by Leszek Koltunski over 4 years ago

Do not crash if we failed to compile some programs.

View differences:

src/main/java/org/distorted/library/main/DistortedLibrary.java
460 460

  
461 461
  static void drawPriv(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
462 462
    {
463
    EffectQueue[] queues = effects.getQueues();
463
    if( mMainOITProgram!=null )
464
      {
465
      EffectQueue[] queues = effects.getQueues();
464 466

  
465
    EffectQueue.compute(queues, currTime);
466
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
467
      EffectQueue.compute(queues, currTime);
468
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
467 469

  
468
    DistortedLibrary.mMainProgram.useProgram();
469
    GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0);
470
    mesh.bindVertexAttribs(DistortedLibrary.mMainProgram);
470
      mMainProgram.useProgram();
471
      GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0);
472
      mesh.bindVertexAttribs(DistortedLibrary.mMainProgram);
471 473

  
472
    float inflate     = mesh.getInflate();
473
    float distance    = surface.mDistance;
474
    float mipmap      = surface.mMipmap;
475
    float[] projection= surface.mProjectionMatrix;
474
      float inflate     = mesh.getInflate();
475
      float distance    = surface.mDistance;
476
      float mipmap      = surface.mMipmap;
477
      float[] projection= surface.mProjectionMatrix;
476 478

  
477
    EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 0 );
478
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
479
      EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 0 );
480
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
479 481

  
480
    if( mesh.getShowNormals() ) displayNormals(queues,mesh);
482
      if( mesh.getShowNormals() ) displayNormals(queues,mesh);
483
      }
481 484
    }
482 485

  
483 486
///////////////////////////////////////////////////////////////////////////////////////////////////
484 487

  
485 488
  static void blitPriv(InternalOutputSurface surface)
486 489
    {
487
    mBlitProgram.useProgram();
490
    if( mBlitProgram!=null )
491
      {
492
      mBlitProgram.useProgram();
488 493

  
489
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
490
    GLES30.glUniform1i(mBlitTextureH, 0);
491
    GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
492
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
493
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
494
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
495
      GLES30.glUniform1i(mBlitTextureH, 0);
496
      GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
497
      GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
498
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
499
      }
494 500
    }
495 501

  
496 502
///////////////////////////////////////////////////////////////////////////////////////////////////
497 503

  
498 504
  static void blitDepthPriv(InternalOutputSurface surface, float corrW, float corrH)
499 505
    {
500
    mBlitDepthProgram.useProgram();
506
    if( mBlitDepthProgram!=null )
507
      {
508
      mBlitDepthProgram.useProgram();
501 509

  
502
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
503
    GLES30.glUniform1i(mBlitDepthTextureH, 0);
504
    GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
505
    GLES30.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
506
    GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
507
    GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
508
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
510
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
511
      GLES30.glUniform1i(mBlitDepthTextureH, 0);
512
      GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
513
      GLES30.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
514
      GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
515
      GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
516
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
517
      }
509 518
    }
510 519

  
511 520
///////////////////////////////////////////////////////////////////////////////////////////////////
......
591 600

  
592 601
  static void oitClear(InternalOutputSurface surface, int counter)
593 602
    {
594
    if( mLinkedListSSBO[0]<0 )
603
    if( mOITClearProgram!=null )
595 604
      {
596
      GLES30.glGenBuffers(1,mLinkedListSSBO,0);
597

  
598
      int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
599
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
600
      GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
601
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
605
      if( mLinkedListSSBO[0]<0 )
606
        {
607
        GLES30.glGenBuffers(1,mLinkedListSSBO,0);
602 608

  
603
      GLES30.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
604
      }
609
        int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
610
        GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
611
        GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
612
        GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
605 613

  
606
    // See if we have overflown the SSBO in one of the previous frames.
607
    // If yes, assume we need to make the SSBO larger.
608
    float overflow = counter/(mBufferSize*surface.mWidth*surface.mHeight);
614
        GLES30.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
615
        }
609 616

  
610
    if( overflow>1.0f )
611
      {
612
      //android.util.Log.e("effects", "previous frame rendered "+counter+
613
      //                   " fragments, but there was only "+(mBufferSize*surface.mWidth*surface.mHeight)+" space");
617
      // See if we have overflown the SSBO in one of the previous frames.
618
      // If yes, assume we need to make the SSBO larger.
619
      float overflow = counter/(mBufferSize*surface.mWidth*surface.mHeight);
614 620

  
615
      mBufferSize *= (int)(overflow+1.0f);
616
      int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
617
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
618
      GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
619
      GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
620
      }
621
      if( overflow>1.0f )
622
        {
623
        //android.util.Log.e("effects", "previous frame rendered "+counter+
624
        //                   " fragments, but there was only "+(mBufferSize*surface.mWidth*surface.mHeight)+" space");
625

  
626
        mBufferSize *= (int)(overflow+1.0f);
627
        int size = (int)(surface.mWidth*surface.mHeight*(3*mBufferSize+1)*4);
628
        GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
629
        GLES30.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, size, null, GLES30.GL_DYNAMIC_READ|GLES30.GL_DYNAMIC_DRAW);
630
        GLES30.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
631
        }
621 632

  
622
    mOITClearProgram.useProgram();
633
      mOITClearProgram.useProgram();
623 634

  
624
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
625
    GLES30.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f );   // corrections do not really matter here - only present because of common vertex shader.
626
    GLES30.glUniform1f( mOITClearDepthH , 1.0f);          // likewise depth
627
    GLES30.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
628
    GLES30.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
629
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
635
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
636
      GLES30.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f );   // corrections do not really matter here - only present because of common vertex shader.
637
      GLES30.glUniform1f( mOITClearDepthH , 1.0f);          // likewise depth
638
      GLES30.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
639
      GLES30.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
640
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
641
      }
630 642
    }
631 643

  
632 644
///////////////////////////////////////////////////////////////////////////////////////////////////
......
634 646

  
635 647
  static void oitBuild(InternalOutputSurface surface, float corrW, float corrH)
636 648
    {
637
    mOITBuildProgram.useProgram();
649
    if( mOITBuildProgram!=null )
650
      {
651
      mOITBuildProgram.useProgram();
638 652

  
639
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
640
    GLES30.glUniform1i(mOITBuildTextureH, 0);
641
    GLES30.glUniform1i(mOITBuildDepthTextureH, 1);
642
    GLES30.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
643
    GLES30.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
644
    GLES30.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
645
    GLES30.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
646
    GLES30.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
647
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
653
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
654
      GLES30.glUniform1i(mOITBuildTextureH, 0);
655
      GLES30.glUniform1i(mOITBuildDepthTextureH, 1);
656
      GLES30.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
657
      GLES30.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
658
      GLES30.glUniform1ui(mOITBuildNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
659
      GLES30.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
660
      GLES30.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
661
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
662
      }
648 663
    }
649 664

  
650 665
///////////////////////////////////////////////////////////////////////////////////////////////////
......
652 667

  
653 668
  static void oitCollapse(InternalOutputSurface surface, float corrW, float corrH)
654 669
    {
655
    mOITCollapseProgram.useProgram();
670
    if( mOITCollapseProgram!=null )
671
      {
672
      mOITCollapseProgram.useProgram();
656 673

  
657
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
658
    GLES30.glUniform1i(mOITCollapseDepthTextureH, 1);
659
    GLES30.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
660
    GLES30.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
661
    GLES30.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
662
    GLES30.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
663
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
674
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
675
      GLES30.glUniform1i(mOITCollapseDepthTextureH, 1);
676
      GLES30.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
677
      GLES30.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
678
      GLES30.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
679
      GLES30.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
680
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
681
      }
664 682
    }
665 683

  
666 684
///////////////////////////////////////////////////////////////////////////////////////////////////
......
668 686

  
669 687
  static void oitRender(InternalOutputSurface surface, float corrW, float corrH)
670 688
    {
671
    mOITRenderProgram.useProgram();
689
    if( mOITRenderProgram!=null )
690
      {
691
      mOITRenderProgram.useProgram();
672 692

  
673
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
674
    GLES30.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
675
    GLES30.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
676
    GLES30.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
677
    GLES30.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
678
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
693
      GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
694
      GLES30.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
695
      GLES30.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
696
      GLES30.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
697
      GLES30.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
698
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
699
      }
679 700
    }
680 701

  
681 702
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff