commit 1f19fba854cf161baf2c3e46661ec3819be4e5ff
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Jun 28 00:51:02 2018 +0100

    Port the Mali flash fix to the OIT branch.

diff --git a/src/main/java/org/distorted/library/main/Distorted.java b/src/main/java/org/distorted/library/main/Distorted.java
index e44f451..b1a4283 100644
--- a/src/main/java/org/distorted/library/main/Distorted.java
+++ b/src/main/java/org/distorted/library/main/Distorted.java
@@ -28,7 +28,6 @@ import org.distorted.library.effect.Effect;
 import org.distorted.library.effect.FragmentEffect;
 import org.distorted.library.effect.PostprocessEffect;
 import org.distorted.library.effect.VertexEffect;
-import org.distorted.library.program.*;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -87,7 +86,7 @@ public class Distorted
    *
    * https://community.arm.com/graphics/f/discussions/10285/opengl-es-3-1-on-mali-t880-flashes
    */
-  public static final int FBO_QUEUE_SIZE = 3;
+  public static final int FBO_QUEUE_SIZE = 4;
 
   private static boolean mInitialized=false;
 
@@ -117,14 +116,8 @@ public class Distorted
  * Needs to be called from a thread holding the OpenGL context.
  *   
  * @param context Context of the App using the library - used to open up Resources and read Shader code.
- * @throws FragmentCompilationException Fragment Shader failed to compile
- * @throws VertexCompilationException   Vertex Shader failed to compile
- * @throws VertexUniformsException      Too many uniforms in the Vertex Shader
- * @throws FragmentUniformsException    Too many uniforms in the Fragment Shader
- * @throws LinkingException             Shader failed to link
  */
   public static void onCreate(final Context context)
-  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
     {
     final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 9154221..6a20bf5 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -299,7 +299,7 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // two phases: 1. collapse the SSBO 2. blend the ssbo's color
 
-  private int oitRender(long currTime)
+  private int oitRender(long currTime, int fbo)
     {
     float corrW = getWidthCorrection();
     float corrH = getHeightCorrection();
@@ -307,17 +307,17 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
     // Do the Collapse Pass only if we do have a Depth attachment.
     // Otherwise there's no point (in fact we then would create a feedback loop!)
 
-    if( mDepthStencilH[0] != 0 )
+    if( mDepthStencilH[fbo] != 0 )
       {
       GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
       GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
-      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[0]);
+      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[fbo]);
       DistortedRenderState.switchOffColorDepthStencil();
       DistortedEffects.oitCollapse(this, corrW, corrH);
       GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
       }
 
-    setAsOutput(currTime);
+    setAsOutputFBO(currTime,fbo);
     DistortedRenderState.switchColorDepthOnStencilOff();
     DistortedEffects.oitRender(this, corrW, corrH);
     DistortedRenderState.restoreColorDepthStencil();
@@ -341,12 +341,6 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
     GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
     GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo  ], 0);
     GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
-
-    for(int i=buffer.mNumColors-2; i>=0; i--)
-      {
-      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[i], 0);
-      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
-      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -430,7 +424,7 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
           numRenders += currQueue.postprocess(mBuffer,fbo);
           numRenders += oitBuild(time,mBuffer[quality],fbo);
           GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
-          numRenders += oitRender(time);  // merge the OIT linked list
+          numRenders += oitRender(time,fbo);  // merge the OIT linked list
           clearBuffer(mBuffer[quality],fbo);
           }
         } // end else (postprocessed child)
@@ -473,7 +467,7 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void setAsOutputFBO(long time, int fbo)
+  public void setAsOutputFBO(long time, int fbo)
     {
     if( fbo>=0 && fbo<mNumFBOs )
       {
@@ -609,7 +603,6 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
  * <p>
  * This version does not attempt to clear anything.
  */
-
   public void setAsOutput()
     {
     GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
