commit 2aef1f4db70c7247c164aeecfa7209d5903999d0
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu May 31 13:29:37 2018 +0100

    OIT: fixes for Mali: fix a broken loop in the oitRender fragment shader that resulted in flashing.

diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 6a47301..a3f7a98 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -214,7 +214,7 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // The postprocessing buffers mBuffer[] are generally speaking too large (there's just one static
-// set of them) so before we use them for output, we need to adjust the Vieport as if they were
+// set of them) so before we use them for output, we need to adjust the Viewport as if they were
 // smaller. That takes care of outputting pixels to them. When we use them as input, we have to
 // adjust the texture coords - see the get{Width|Height}Correction functions.
 
@@ -367,8 +367,6 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
     EffectQueuePostprocess lastQueue=null, currQueue;
     long lastBucket=0, currBucket;
 
-    oitClear(this);
-
     for(int i=0; i<numChildren; i++)
       {
       child1 = children.get(i);
@@ -389,6 +387,7 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
           if( lastBucket==0 )
             {
             clonePostprocessingViewport(this);
+            oitClear(this);
             }
           else
             {
diff --git a/src/main/res/raw/oit_render_fragment_shader.glsl b/src/main/res/raw/oit_render_fragment_shader.glsl
index 3415c7f..1df11f6 100644
--- a/src/main/res/raw/oit_render_fragment_shader.glsl
+++ b/src/main/res/raw/oit_render_fragment_shader.glsl
@@ -67,11 +67,12 @@ void main()
     const float S= 2147483647.0;
     gl_FragDepth = 1.0 - 2.0*float(u_Records[curr+1u])/S;
     vec4 color   = convert(u_Records[curr+2u]);
+    curr = u_Records[curr];
 
     while (curr != 0u)
       {
-      curr = u_Records[curr];
       color = blend( color , convert(u_Records[curr+2u]) );
+      curr = u_Records[curr];
       }
 
     fragColor = color;
