commit c207da02518e0c97376aa842bd3cf20a957ea1ee
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue May 22 16:48:57 2018 +0100

    OIT: fixes. Everything looks correct now except for the curious return of the 'dancing lower-left corner' small glitch in the 'Transparency' app.

diff --git a/src/main/java/org/distorted/library/main/DistortedFramebuffer.java b/src/main/java/org/distorted/library/main/DistortedFramebuffer.java
index 0e00c90..c7614f1 100644
--- a/src/main/java/org/distorted/library/main/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/main/DistortedFramebuffer.java
@@ -197,20 +197,6 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
     super(width,height,NOT_CREATED_YET,numcolors,depthStencil,NOT_CREATED_YET,TYPE_USER);
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Create new offscreen Framebuffer with COLOR0 attachment only.
- *
- * @param width Width of the COLOR0 attachment.
- * @param height Height of the COLOR0 attachment.
- */
-  @SuppressWarnings("unused")
-  public DistortedFramebuffer(int width, int height)
-    {
-    super(width,height,NOT_CREATED_YET, 1, NO_DEPTH_NO_STENCIL,NOT_CREATED_YET,TYPE_USER);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Bind the underlying rectangle of pixels as a OpenGL Texture.
diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index ee4f939..7bdc82c 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -293,22 +293,22 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // two phases: 1. collapse the SSBO 2. blend the ssbo's color
 
-  private int oitRender(long currTime, DistortedOutputSurface buffer)
+  private int oitRender(long currTime)
     {
-    float corrW = buffer.getWidthCorrection();
-    float corrH = buffer.getHeightCorrection();
+    float corrW = getWidthCorrection();
+    float corrH = getHeightCorrection();
 
     GLES31.glViewport(0, 0, mWidth, mHeight);
-    setAsOutput(currTime);
+    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
     GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
-    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[0]);
+    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[0]);
 
     DistortedRenderState.switchOffColorDepthStencil();
     DistortedEffects.oitCollapse(this, corrW, corrH );
 
-    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
     GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
 
+    setAsOutput(currTime);
     DistortedRenderState.switchColorDepthOnStencilOff();
     DistortedEffects.oitRender(this, corrW, corrH);
     DistortedRenderState.restoreColorDepthStencil();
@@ -420,7 +420,7 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
           numRenders += currQueue.postprocess(mBuffer);
           numRenders += oitBuild(mBuffer[quality]);
           GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT);
-          numRenders += oitRender(time,this);  // merge the OIT linked list
+          numRenders += oitRender(time);  // merge the OIT linked list
           clearBuffer(mBuffer[quality]);
           }
         } // end else (postprocessed child)
diff --git a/src/main/res/raw/oit_collapse_fragment_shader.glsl b/src/main/res/raw/oit_collapse_fragment_shader.glsl
index 027c2b3..abbda53 100644
--- a/src/main/res/raw/oit_collapse_fragment_shader.glsl
+++ b/src/main/res/raw/oit_collapse_fragment_shader.glsl
@@ -50,18 +50,17 @@ void main()
     const float S= 2147483647.0;
     float depth = texture(u_DepthTexture, v_TexCoordinate).r;
     uint texdepth = uint(S*(1.0-depth)/2.0);
-    uint linkedlistdepth = u_Records[curr+1u];
 
-    while( curr != 0u && linkedlistdepth > texdepth )
+    while( curr != 0u )
       {
+      if( u_Records[curr+1u] <= texdepth )
+        {
+        u_Records[prev] = 0u;
+        break;
+        }
+
       prev = curr;
       curr = u_Records[curr];
-      linkedlistdepth = u_Records[curr+1u];
-      }
-
-    if( curr != 0u )
-      {
-      u_Records[prev] = 0u;
       }
     }
   else discard;
