Project

General

Profile

« Previous | Next » 

Revision 86c352e0

Added by Leszek Koltunski over 6 years ago

Some progress with not-postprocessed OIT.

View differences:

src/main/java/org/distorted/library/main/Distorted.java
88 88
   * https://community.arm.com/graphics/f/discussions/10285/opengl-es-3-1-on-mali-t880-flashes
89 89
   */
90 90
  public static final int FBO_QUEUE_SIZE = 4;
91
  /**
92
   * Number of Main program variants (ATM 2: main and main OIT)
93
   */
94
  public static final int MAIN_VARIANTS = 2;
91 95

  
92 96
  private static boolean mInitialized=false;
93 97

  
src/main/java/org/distorted/library/main/DistortedEffects.java
169 169
      }
170 170

  
171 171
    int mainProgramH = mMainProgram.getProgramHandle();
172
    EffectQueueFragment.getUniforms(mainProgramH);
173
    EffectQueueVertex.getUniforms(mainProgramH);
174
    EffectQueueMatrix.getUniforms(mainProgramH);
172
    EffectQueueFragment.getUniforms(mainProgramH,0);
173
    EffectQueueVertex.getUniforms(mainProgramH,0);
174
    EffectQueueMatrix.getUniforms(mainProgramH,0);
175 175
    mMainTextureH= GLES31.glGetUniformLocation( mainProgramH, "u_Texture");
176 176

  
177 177
    // BLIT PROGRAM ////////////////////////////////////
......
254 254
    try
255 255
      {
256 256
      mMainOITProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader,
257
          enabledEffectV, enabledEffectF, Distorted.GLSL, null);
257
                                             enabledEffectV, enabledEffectF, Distorted.GLSL, null);
258 258
      }
259 259
    catch(Exception e)
260 260
      {
......
263 263
      }
264 264

  
265 265
    int mainOITProgramH = mMainOITProgram.getProgramHandle();
266
    EffectQueueFragment.getUniformsOIT(mainOITProgramH);
267
    EffectQueueVertex.getUniformsOIT(mainOITProgramH);
268
    EffectQueueMatrix.getUniformsOIT(mainOITProgramH);
266
    EffectQueueFragment.getUniforms(mainOITProgramH,1);
267
    EffectQueueVertex.getUniforms(mainOITProgramH,1);
268
    EffectQueueMatrix.getUniforms(mainOITProgramH,1);
269 269
    mMainOITTextureH    = GLES31.glGetUniformLocation( mainOITProgramH, "u_Texture");
270 270
    mMainOITSizeH       = GLES31.glGetUniformLocation( mainOITProgramH, "u_Size");
271 271
    mMainOITNumRecordsH = GLES31.glGetUniformLocation( mainOITProgramH, "u_numRecords");
......
480 480
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
481 481
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
482 482

  
483
    mM.sendOIT(surface,halfW,halfH,halfZ,marginInPixels);
484
    mV.sendOIT();
485
    mF.sendOIT();
483
    mM.send(surface,halfW,halfH,halfZ,marginInPixels,1);
484
    mV.send(1);
485
    mF.send(1);
486 486

  
487 487
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
488 488

  
......
511 511
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
512 512
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
513 513

  
514
    mM.send(surface,halfW,halfH,halfZ,marginInPixels);
515
    mV.send();
516
    mF.send();
514
    mM.send(surface,halfW,halfH,halfZ,marginInPixels,0);
515
    mV.send(0);
516
    mF.send(0);
517 517

  
518 518
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
519 519

  
src/main/java/org/distorted/library/main/DistortedOutputSurface.java
388 388
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing
389 389
// to a whole buffer (lastQueue.postprocess) and merge it (this.oitBuild).
390 390

  
391
/*
392
int renderChildren1(long time, int numChildren, ArrayList<DistortedNode> children, int fbo, boolean oit)
393
  {
394
  oitClear(this);
395
  setAsOutputFBO(time,fbo);
396
  mChildren.get(0).drawOIT(time, this);
397
  GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT | GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
398
  oitRender(time, fbo);
399

  
400
  return 0;
401
  }
402
*/
403

  
391 404
  int renderChildren(long time, int numChildren, ArrayList<DistortedNode> children, int fbo, boolean oit)
392 405
    {
393 406
    int quality=0, internalQuality = 0, numRenders = 0, bucketChange = 0;
src/main/java/org/distorted/library/main/EffectQueueFragment.java
32 32
  private static final int NUM_UNIFORMS = FragmentEffect.NUM_UNIFORMS;
33 33
  private static final int INDEX = EffectType.FRAGMENT.ordinal();
34 34

  
35
  private static int mNumEffectsH;
36
  private static int mNameH;
37
  private static int mUniformsH;
38

  
39
  private static int mNumEffectsOITH;
40
  private static int mNameOITH;
41
  private static int mUniformsOITH;
35
  private static int[] mNumEffectsH = new int[Distorted.MAIN_VARIANTS];
36
  private static int[] mNameH       = new int[Distorted.MAIN_VARIANTS];
37
  private static int[] mUniformsH   = new int[Distorted.MAIN_VARIANTS];
42 38

  
43 39
///////////////////////////////////////////////////////////////////////////////////////////////////
44 40
   
......
49 45

  
50 46
///////////////////////////////////////////////////////////////////////////////////////////////////
51 47

  
52
  static void getUniforms(int mProgramH)
53
    {
54
    mNumEffectsH= GLES31.glGetUniformLocation( mProgramH, "fNumEffects");
55
    mNameH      = GLES31.glGetUniformLocation( mProgramH, "fName");
56
    mUniformsH  = GLES31.glGetUniformLocation( mProgramH, "fUniforms");
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
  static void getUniformsOIT(int mProgramH)
48
  static void getUniforms(int mProgramH, int variant)
62 49
    {
63
    mNumEffectsOITH= GLES31.glGetUniformLocation( mProgramH, "fNumEffects");
64
    mNameOITH      = GLES31.glGetUniformLocation( mProgramH, "fName");
65
    mUniformsOITH  = GLES31.glGetUniformLocation( mProgramH, "fUniforms");
50
    mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "fNumEffects");
51
    mNameH[variant]      = GLES31.glGetUniformLocation( mProgramH, "fName");
52
    mUniformsH[variant]  = GLES31.glGetUniformLocation( mProgramH, "fUniforms");
66 53
    }
67 54

  
68 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
99 86

  
100 87
///////////////////////////////////////////////////////////////////////////////////////////////////
101 88
  
102
  void send()
89
  void send(int variant)
103 90
    {
104
    GLES31.glUniform1i( mNumEffectsH, mNumEffects);
91
    GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
105 92

  
106 93
    if( mNumEffects>0 )
107 94
      {
108
      GLES31.glUniform1iv( mNameH    ,                 mNumEffects, mName    ,0);
109
      GLES31.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
95
      GLES31.glUniform1iv( mNameH[variant]    ,                 mNumEffects, mName    ,0);
96
      GLES31.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
110 97
      }  
111 98
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  void sendOIT()
116
    {
117
    GLES31.glUniform1i( mNumEffectsOITH, mNumEffects);
118

  
119
    if( mNumEffects>0 )
120
      {
121
      GLES31.glUniform1iv( mNameOITH    ,                 mNumEffects, mName    ,0);
122
      GLES31.glUniform4fv( mUniformsOITH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
123
      }
124
    }
125 99
  }
src/main/java/org/distorted/library/main/EffectQueueMatrix.java
43 43
  private static float mMiny;
44 44
  private static float mMaxy;
45 45

  
46
  private static int mObjDH;         // This is a handle to half a Object dimensions
47
  private static int mMVPMatrixH;    // the transformation matrix
48
  private static int mMVMatrixH;     // the modelview matrix.
49

  
50
  private static int mObjDOITH;      //
51
  private static int mMVPMatrixOITH; // Same like above, but in main OIT program.
52
  private static int mMVMatrixOITH;  //
46
  private static int[] mObjDH      = new int[Distorted.MAIN_VARIANTS];
47
  private static int[] mMVPMatrixH = new int[Distorted.MAIN_VARIANTS];
48
  private static int[] mMVMatrixH  = new int[Distorted.MAIN_VARIANTS];
53 49

  
54 50
///////////////////////////////////////////////////////////////////////////////////////////////////
55 51
   
......
105 101

  
106 102
///////////////////////////////////////////////////////////////////////////////////////////////////
107 103

  
108
  static void getUniforms(int mProgramH)
109
    {
110
    mObjDH     = GLES31.glGetUniformLocation(mProgramH, "u_objD");
111
    mMVPMatrixH= GLES31.glGetUniformLocation(mProgramH, "u_MVPMatrix");
112
    mMVMatrixH = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix"); 
113
    }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
  static void getUniformsOIT(int mProgramH)
104
  static void getUniforms(int mProgramH, int variant)
118 105
    {
119
    mObjDOITH     = GLES31.glGetUniformLocation(mProgramH, "u_objD");
120
    mMVPMatrixOITH= GLES31.glGetUniformLocation(mProgramH, "u_MVPMatrix");
121
    mMVMatrixOITH = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix");
106
    mObjDH[variant]     = GLES31.glGetUniformLocation(mProgramH, "u_objD");
107
    mMVPMatrixH[variant]= GLES31.glGetUniformLocation(mProgramH, "u_MVPMatrix");
108
    mMVMatrixH[variant] = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix");
122 109
    }
123 110

  
124 111
///////////////////////////////////////////////////////////////////////////////////////////////////
......
158 145

  
159 146
///////////////////////////////////////////////////////////////////////////////////////////////////
160 147

  
161
  void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
162
    {
163
    Matrix.setIdentityM(mViewMatrix, 0);
164
    Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance);
165
    float mipmap = projection.mMipmap;
166
    if( mipmap!=1 ) Matrix.scaleM(mViewMatrix, 0, mipmap, mipmap, mipmap);
167

  
168
    for(int i=0; i<mNumEffects; i++) ((MatrixEffect)mEffects[i]).apply(mViewMatrix,mUniforms,i);
169

  
170
    Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ);
171
    if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels);
172
    Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
173

  
174
    GLES31.glUniform3f( mObjDH , halfX, halfY, halfZ);
175
    GLES31.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0);
176
    GLES31.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
177
    }
178

  
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

  
181
  void sendOIT(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
148
  void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels, int variant)
182 149
    {
183 150
    Matrix.setIdentityM(mViewMatrix, 0);
184 151
    Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance);
......
191 158
    if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels);
192 159
    Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
193 160

  
194
    GLES31.glUniform3f( mObjDOITH , halfX, halfY, halfZ);
195
    GLES31.glUniformMatrix4fv(mMVMatrixOITH , 1, false, mViewMatrix, 0);
196
    GLES31.glUniformMatrix4fv(mMVPMatrixOITH, 1, false, mMVPMatrix , 0);
161
    GLES31.glUniform3f( mObjDH[variant] , halfX, halfY, halfZ);
162
    GLES31.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mViewMatrix, 0);
163
    GLES31.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0);
197 164
    }
198 165
  }
src/main/java/org/distorted/library/main/EffectQueueVertex.java
32 32
  private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS;
33 33
  private static final int INDEX = EffectType.VERTEX.ordinal();
34 34

  
35
  private static int mNumEffectsH;
36
  private static int mNameH;
37
  private static int mUniformsH;
38

  
39
  private static int mNumEffectsOITH;
40
  private static int mNameOITH;
41
  private static int mUniformsOITH;
35
  private static int[] mNumEffectsH = new int[Distorted.MAIN_VARIANTS];
36
  private static int[] mNameH       = new int[Distorted.MAIN_VARIANTS];
37
  private static int[] mUniformsH   = new int[Distorted.MAIN_VARIANTS];
42 38

  
43 39
///////////////////////////////////////////////////////////////////////////////////////////////////
44 40
   
......
49 45

  
50 46
///////////////////////////////////////////////////////////////////////////////////////////////////
51 47

  
52
  static void getUniforms(int mProgramH)
53
    {
54
    mNumEffectsH= GLES31.glGetUniformLocation( mProgramH, "vNumEffects");
55
    mNameH      = GLES31.glGetUniformLocation( mProgramH, "vName");
56
    mUniformsH  = GLES31.glGetUniformLocation( mProgramH, "vUniforms");
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
  static void getUniformsOIT(int mProgramH)
48
  static void getUniforms(int mProgramH, int variant)
62 49
    {
63
    mNumEffectsOITH= GLES31.glGetUniformLocation( mProgramH, "vNumEffects");
64
    mNameOITH      = GLES31.glGetUniformLocation( mProgramH, "vName");
65
    mUniformsOITH  = GLES31.glGetUniformLocation( mProgramH, "vUniforms");
50
    mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "vNumEffects");
51
    mNameH[variant]      = GLES31.glGetUniformLocation( mProgramH, "vName");
52
    mUniformsH[variant]  = GLES31.glGetUniformLocation( mProgramH, "vUniforms");
66 53
    }
67 54

  
68 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
100 87

  
101 88
///////////////////////////////////////////////////////////////////////////////////////////////////
102 89

  
103
  void send()
90
  void send(int variant)
104 91
    {
105
    GLES31.glUniform1i( mNumEffectsH, mNumEffects);
92
    GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
106 93
      
107 94
    if( mNumEffects>0 )
108 95
      {
109
      GLES31.glUniform1iv( mNameH    ,                 mNumEffects, mName    ,0);
110
      GLES31.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
111
      }
112
    }
113

  
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

  
116
  void sendOIT()
117
    {
118
    GLES31.glUniform1i( mNumEffectsOITH, mNumEffects);
119

  
120
    if( mNumEffects>0 )
121
      {
122
      GLES31.glUniform1iv( mNameOITH    ,                 mNumEffects, mName    ,0);
123
      GLES31.glUniform4fv( mUniformsOITH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
96
      GLES31.glUniform1iv( mNameH[variant]    ,                 mNumEffects, mName    ,0);
97
      GLES31.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
124 98
      }
125 99
    }
126 100
  }

Also available in: Unified diff