Project

General

Profile

« Previous | Next » 

Revision b7074bc6

Added by Leszek Koltunski about 4 years ago

Lower requirements - now only OpenGL ES 3.0 is required; if running on such platform, OIT part of the API ( which is the only one which actually requires 3.1) is switched off.

View differences:

src/main/java/org/distorted/library/main/InternalOutputSurface.java
19 19

  
20 20
package org.distorted.library.main;
21 21

  
22
import android.opengl.GLES30;
22 23
import android.opengl.GLES31;
23 24
import android.opengl.Matrix;
24 25

  
......
97 98

  
98 99
    mClearDepth = 1.0f;
99 100
    mClearStencil = 0;
100
    mClear = GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_COLOR_BUFFER_BIT;
101
    mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT;
101 102

  
102 103
    mMipmap = 1.0f;
103 104

  
......
167 168
    InternalObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
168 169

  
169 170
    InternalRenderState.colorDepthStencilOn();
170
    GLES31.glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
171
    GLES31.glClearDepthf(CLEAR_D);
172
    GLES31.glClearStencil(CLEAR_S);
171
    GLES30.glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
172
    GLES30.glClearDepthf(CLEAR_D);
173
    GLES30.glClearStencil(CLEAR_S);
173 174

  
174 175
    for(int k = 0; k< DistortedLibrary.FBO_QUEUE_SIZE; k++)
175 176
      {
176
      GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mBuffer[quality].mFBOH[k]);
177
      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k+1], 0);
178
      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT | GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_STENCIL_BUFFER_BIT);
179
      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k  ], 0);
180
      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
177
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mBuffer[quality].mFBOH[k]);
178
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k+1], 0);
179
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_STENCIL_BUFFER_BIT);
180
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k  ], 0);
181
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
181 182
      }
182 183

  
183 184
    InternalRenderState.colorDepthStencilRestore();
184 185

  
185
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
186
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
186 187
    }
187 188

  
188 189
///////////////////////////////////////////////////////////////////////////////////////////////////
......
236 237

  
237 238
  private int blitWithDepth(long currTime, InternalOutputSurface buffer, int fbo)
238 239
    {
239
    GLES31.glViewport(0, 0, mWidth, mHeight);
240
    GLES30.glViewport(0, 0, mWidth, mHeight);
240 241
    setAsOutput(currTime);
241
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
242
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
243
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
244
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
242
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
243
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
244
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
245
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
245 246

  
246
    GLES31.glDisable(GLES31.GL_STENCIL_TEST);
247
    GLES31.glStencilMask(0x00);
247
    GLES30.glDisable(GLES30.GL_STENCIL_TEST);
248
    GLES30.glStencilMask(0x00);
248 249

  
249 250
    DistortedLibrary.blitDepthPriv(this, buffer.getWidthCorrection(), buffer.getHeightCorrection() );
250
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
251
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
252
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
253
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
251
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
252
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
253
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
254
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
254 255

  
255 256
    // clear buffers
256
    GLES31.glStencilMask(0xff);
257
    GLES31.glDepthMask(true);
258
    GLES31.glColorMask(true,true,true,true);
259
    GLES31.glClearColor(buffer.mClearR,buffer.mClearG,buffer.mClearB,buffer.mClearA);
260
    GLES31.glClearDepthf(buffer.mClearDepth);
261
    GLES31.glClearStencil(buffer.mClearStencil);
257
    GLES30.glStencilMask(0xff);
258
    GLES30.glDepthMask(true);
259
    GLES30.glColorMask(true,true,true,true);
260
    GLES30.glClearColor(buffer.mClearR,buffer.mClearG,buffer.mClearB,buffer.mClearA);
261
    GLES30.glClearDepthf(buffer.mClearDepth);
262
    GLES30.glClearStencil(buffer.mClearStencil);
262 263

  
263 264
    buffer.setAsOutput();
264
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0);
265
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
266
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo  ], 0);
267
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
265
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0);
266
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
267
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo  ], 0);
268
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
268 269

  
269 270
    return 1;
270 271
    }
......
282 283

  
283 284
  private int oitBuild(long time, InternalOutputSurface buffer, int fbo)
284 285
    {
285
    GLES31.glViewport(0, 0, mWidth, mHeight);
286
    GLES30.glViewport(0, 0, mWidth, mHeight);
286 287
    setAsOutput(time);
287
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
288
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
289
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
290
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
288
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
289
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
290
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
291
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
291 292

  
292 293
    InternalRenderState.colorDepthStencilOn();
293 294
    InternalRenderState.enableDepthTest();
294 295

  
295 296
    DistortedLibrary.oitBuild(this, buffer.getWidthCorrection(), buffer.getHeightCorrection() );
296
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
297
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
298
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
299
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
297
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
298
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
299
    GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
300
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
300 301

  
301 302
    InternalRenderState.colorDepthStencilRestore();
302 303
    InternalRenderState.restoreDepthTest();
......
317 318

  
318 319
    if( mDepthStencilH[fbo] != 0 )
319 320
      {
320
      GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
321
      GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
322
      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[fbo]);
321
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
322
      GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
323
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthStencilH[fbo]);
323 324
      InternalRenderState.switchOffColorDepthStencil();
324 325
      DistortedLibrary.oitCollapse(this, corrW, corrH);
325
      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
326
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
326 327
      }
327 328

  
328 329
    setAsOutput(currTime);
......
338 339
  private void clear()
339 340
    {
340 341
    InternalRenderState.colorDepthStencilOn();
341
    GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA);
342
    GLES31.glClearDepthf(mClearDepth);
343
    GLES31.glClearStencil(mClearStencil);
344
    GLES31.glClear(mClear);
342
    GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA);
343
    GLES30.glClearDepthf(mClearDepth);
344
    GLES30.glClearStencil(mClearStencil);
345
    GLES30.glClear(mClear);
345 346
    InternalRenderState.colorDepthStencilRestore();
346 347
    }
347 348

  
......
533 534
    {
534 535
    InternalRenderState.colorDepthStencilOn();
535 536

  
536
    GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA);
537
    GLES31.glClearDepthf(mClearDepth);
538
    GLES31.glClearStencil(mClearStencil);
537
    GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA);
538
    GLES30.glClearDepthf(mClearDepth);
539
    GLES30.glClearStencil(mClearStencil);
539 540

  
540
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]);
541
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[2*fbo+1], 0);
542
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
543
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[2*fbo  ], 0);
544
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
541
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[fbo]);
542
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[2*fbo+1], 0);
543
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
544
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[2*fbo  ], 0);
545
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
545 546

  
546 547
    InternalRenderState.colorDepthStencilRestore();
547 548
    }
......
550 551

  
551 552
  void setAsOutput(long time)
552 553
    {
553
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
554
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
554 555

  
555 556
    if( mTime[mCurrFBO]!=time )
556 557
      {
......
617 618
 */
618 619
  public void setAsOutput()
619 620
    {
620
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
621
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[mCurrFBO]);
621 622
    }
622 623

  
623 624
///////////////////////////////////////////////////////////////////////////////////////////////////
......
811 812
/**
812 813
 * When rendering this Node, should we use the Order Independent Transparency render mode?
813 814
 * <p>
815
 * This feature requires OpenGL ES 3.1. If we are running on OpenGL 3.0, this will do nothing.
816
 * Also, if you are running on a buggy driver ( Imagination GE8100/8300 driver build 1.8@4490469 )
817
 * then do nothing.
818
 *
814 819
 * There are two modes of rendering: the fast 'normal' way, which however renders transparent
815 820
 * fragments in different ways depending on which fragments get rendered first, or the slower
816 821
 * 'oit' way, which renders transparent fragments correctly regardless of their order.
......
819 824
 */
820 825
  public void setOrderIndependentTransparency(boolean oit)
821 826
    {
822
    mRenderWayOIT = oit;
827
    if( DistortedLibrary.getGLSL()>=310 && DistortedLibrary.OITCompilationSuccessful() )
828
      {
829
      mRenderWayOIT = oit;
830
      }
823 831
    }
824 832

  
825 833
///////////////////////////////////////////////////////////////////////////////////////////////////
826 834
/**
827 835
 * When rendering this Node, should we use the Order Independent Transparency render mode?
828 836
 * <p>
837
 * This feature requires OpenGL ES 3.1. If we are running on OpenGL 3.0, this will do nothing.
838
 * Also, if you are running on a buggy driver ( Imagination GE8100/8300 driver build 1.8@4490469 )
839
 * then do nothing.
840
 *
829 841
 * There are two modes of rendering: the fast 'normal' way, which however renders transparent
830 842
 * fragments in different ways depending on which fragments get rendered first, or the slower
831 843
 * 'oit' way, which renders transparent fragments correctly regardless of their order.
......
840 852
 */
841 853
  public void setOrderIndependentTransparency(boolean oit, float initialSize)
842 854
    {
843
    mRenderWayOIT = oit;
844

  
845
    if( initialSize>0.0f && initialSize<10.0f )
855
    if( DistortedLibrary.getGLSL()>=310 && DistortedLibrary.OITCompilationSuccessful() )
846 856
      {
847
      DistortedLibrary.setSSBOSize(initialSize);
857
      mRenderWayOIT = oit;
858

  
859
      if( initialSize>0.0f && initialSize<10.0f )
860
        {
861
        DistortedLibrary.setSSBOSize(initialSize);
862
        }
848 863
      }
849 864
    }
850 865

  

Also available in: Unified diff