Project

General

Profile

« Previous | Next » 

Revision 9f9924f8

Added by Leszek Koltunski about 4 years ago

Remove the 'binding' parameter from the UBO in the vertex shader - this is not part of OpenGL ES 3.0, only introduced in 3.1, and we want to be compatible with 3.0.
Now we need to dynamically detect the UBO index and form a BlockBinding ourselves.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
143 143
      }
144 144

  
145 145
    mPreProgramH = mPreProgram.getProgramHandle();
146
    EffectQueueVertex.getUniforms( mPreProgramH,2 );
147
    EffectQueueMatrix.getUniforms( mPreProgramH,2 );
146
    EffectQueue.getUniforms( mPreProgramH,2 );
147
    MeshBase.getUniforms( mPreProgramH,2 );
148 148
    mPreColorH  = GLES30.glGetUniformLocation( mPreProgramH, "u_Color"  );
149 149
    mPreTextureH= GLES30.glGetUniformLocation( mPreProgramH, "u_Texture");
150 150
    }
......
183 183
    mPreProgram.useProgram();
184 184

  
185 185
    mesh.bindVertexAttribs(mPreProgram);
186
    mesh.send(mPreProgramH);
186
    mesh.send(mPreProgramH,2);
187 187

  
188 188
    EffectQueue[] queues = effects.getQueues();
189 189
    EffectQueueMatrix matrix = (EffectQueueMatrix)queues[0];
src/main/java/org/distorted/library/main/DistortedLibrary.java
264 264

  
265 265
    mMainProgramH = mMainProgram.getProgramHandle();
266 266
    EffectQueue.getUniforms(mMainProgramH,0);
267
    MeshBase.getUniforms(mMainProgramH,0);
267 268
    mMainTextureH= GLES30.glGetUniformLocation( mMainProgramH, "u_Texture");
268 269
    mTransformFeedbackH= GLES30.glGetUniformLocation( mMainProgramH, "u_TransformFeedback");
269 270

  
......
362 363

  
363 364
    mFullProgramH = mFullProgram.getProgramHandle();
364 365
    EffectQueue.getUniforms(mFullProgramH,3);
366
    MeshBase.getUniforms(mFullProgramH,3);
365 367
    }
366 368

  
367 369
///////////////////////////////////////////////////////////////////////////////////////////////////
......
396 398

  
397 399
    mMainOITProgramH = mMainOITProgram.getProgramHandle();
398 400
    EffectQueue.getUniforms(mMainOITProgramH,1);
401
    MeshBase.getUniforms(mMainOITProgramH,1);
399 402
    mMainOITTextureH    = GLES30.glGetUniformLocation( mMainOITProgramH, "u_Texture");
400 403
    mMainOITSizeH       = GLES30.glGetUniformLocation( mMainOITProgramH, "u_Size");
401 404
    mMainOITNumRecordsH = GLES30.glGetUniformLocation( mMainOITProgramH, "u_numRecords");
......
545 548
    mesh.bindVertexAttribs(mFullProgram);
546 549
    queue.compute(1);
547 550
    queue.send(0.0f,3);
548
    mesh.send(mFullProgramH);
551
    mesh.send(mFullProgramH,3);
549 552

  
550 553
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
551 554
    GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
......
573 576
      GLES30.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight);
574 577
      GLES30.glUniform1ui(mMainOITNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
575 578
      mesh.bindVertexAttribs(mMainOITProgram);
576
      mesh.send(mMainOITProgramH);
579
      mesh.send(mMainOITProgramH,1);
577 580

  
578 581
      float inflate     = mesh.getInflate();
579 582
      float distance    = surface.mDistance;
......
586 589
      if( mesh.getShowNormals() )
587 590
        {
588 591
        mMainProgram.useProgram();
589
        mesh.send(mMainProgramH);
592
        mesh.send(mMainProgramH,0);
590 593
        EffectQueue.send(queues, distance, mipmap, projection, inflate, 0 );
591 594
        displayNormals(projection,mesh);
592 595
        }
......
607 610
      mMainProgram.useProgram();
608 611
      GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0);
609 612
      mesh.bindVertexAttribs(DistortedLibrary.mMainProgram);
610
      mesh.send(mMainProgramH);
613
      mesh.send(mMainProgramH,0);
611 614

  
612 615
      float inflate     = mesh.getInflate();
613 616
      float distance    = surface.mDistance;
src/main/java/org/distorted/library/mesh/MeshBase.java
25 25

  
26 26
import org.distorted.library.effect.MatrixEffect;
27 27
import org.distorted.library.effect.VertexEffect;
28
import org.distorted.library.effectqueue.EffectQueue;
28 29
import org.distorted.library.main.InternalBuffer;
29 30
import org.distorted.library.program.DistortedProgram;
30 31
import org.distorted.library.type.Static4D;
......
87 88

  
88 89
   DeferredJobs.JobNode[] mJobNode;
89 90

  
91
   private static int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
92
   private static int[] mAssocBlockIndex  = new int[EffectQueue.MAIN_VARIANTS];
93

  
90 94
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
91 95

  
92 96
   private static class TexComponent
......
531 535
     return MAX_EFFECT_COMPONENTS;
532 536
     }
533 537

  
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

  
540
   public static void getUniforms(int programH, int variant)
541
     {
542
     mCenterBlockIndex[variant]= GLES30.glGetUniformBlockIndex(programH, "componentCenter");
543
     mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation");
544
     }
545

  
534 546
///////////////////////////////////////////////////////////////////////////////////////////////////
535 547
/**
536 548
 * Not part of public API, do not document (public only because has to be used from the main package)
......
676 688
 *
677 689
 * @y.exclude
678 690
 */
679
   public void send(int programH)
691
   public void send(int programH, int variant)
680 692
     {
681 693
     int indexA = mUBA.getIndex();
682 694
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA);
683
     GLES30.glUniformBlockBinding(programH, ASSOC_UBO_BINDING, indexA);
695
     GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING);
684 696

  
685 697
     int indexC = mUBC.getIndex();
686 698
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
687
     GLES30.glUniformBlockBinding(programH, CENTER_UBO_BINDING, indexC);
699
     GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING);
688 700
     }
689 701

  
690 702
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/raw/main_vertex_shader.glsl
39 39
uniform float u_Inflate;              // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
40 40
uniform int u_TransformFeedback;      // are we doing the transform feedback now?
41 41

  
42
layout (std140, binding=4) uniform componentCenter
42
layout (std140) uniform componentCenter
43 43
  {
44 44
  vec4 vComCenter[MAX_COMPON];        // centers of mesh components. 4 floats: (x,y,z,unused)
45 45
  };
......
56 56
                                      // The first vec4 is the Interpolated values,
57 57
                                      // second vec4: first float - cache, next 3: Center, the third -  the Region.
58 58

  
59
layout (std140, binding=3) uniform componentAssociation
59
layout (std140) uniform componentAssociation
60 60
  {
61 61
  ivec4 vComAssoc[MAX_COMPON];        // component Associations, 4 ints:
62 62
                                      // 1: component's AND association

Also available in: Unified diff