commit 47511918fa59178b2f52451d9016231a68a2c0f9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Apr 25 15:17:24 2018 +0100

    Order Independent Transparency: some progress

diff --git a/src/main/java/org/distorted/library/main/Distorted.java b/src/main/java/org/distorted/library/main/Distorted.java
index 70be620..6afde6d 100644
--- a/src/main/java/org/distorted/library/main/Distorted.java
+++ b/src/main/java/org/distorted/library/main/Distorted.java
@@ -119,8 +119,8 @@ public class Distorted
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
     android.util.Log.e("DISTORTED", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
 
-    GLSL = ( (configurationInfo.reqGlEsVersion>>16)>=3 ? 300 : 100 );
-    GLSL_VERSION= (GLSL==100 ? "#version 100\n" : "#version 300 es\n");
+    GLSL = ( (configurationInfo.reqGlEsVersion>>16)>=3 ? 310 : 100 );
+    GLSL_VERSION= (GLSL==100 ? "#version 100\n" : "#version 310 es\n");
 
     EffectMessageSender.startSending();
 
diff --git a/src/main/java/org/distorted/library/program/DistortedProgram.java b/src/main/java/org/distorted/library/program/DistortedProgram.java
index 505f808..67214b4 100644
--- a/src/main/java/org/distorted/library/program/DistortedProgram.java
+++ b/src/main/java/org/distorted/library/program/DistortedProgram.java
@@ -292,24 +292,20 @@ public class DistortedProgram
       final int[] compileStatus = new int[1];
       GLES31.glGetShaderiv(shaderHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0);
 
-      if (compileStatus[0] != GLES31.GL_TRUE )
+      if (compileStatus[0] != GLES31.GL_TRUE)
         {
-        GLES31.glDeleteShader(shaderHandle);
-        shaderHandle = 0;
-        }
-      }
+        String error = GLES31.glGetShaderInfoLog(shaderHandle);
 
-    if (shaderHandle == 0)
-      {
-      String error = GLES31.glGetShaderInfoLog(shaderHandle);
+        //android.util.Log.e("Program", "error compiling :" + error);
 
-      //android.util.Log.e("Program", "error compiling :"+error);
+        GLES31.glDeleteShader(shaderHandle);
 
-      switch(shaderType)
-        {
-        case GLES31.GL_VERTEX_SHADER  : throw new VertexCompilationException(error);
-        case GLES31.GL_FRAGMENT_SHADER: throw new FragmentCompilationException(error);
-        default                       : throw new RuntimeException(error);
+        switch (shaderType)
+          {
+          case GLES31.GL_VERTEX_SHADER:   throw new VertexCompilationException(error);
+          case GLES31.GL_FRAGMENT_SHADER: throw new FragmentCompilationException(error);
+          default:                        throw new RuntimeException(error);
+          }
         }
       }
 
@@ -447,7 +443,6 @@ android.util.Log.d("Program", end.substring(0,40));
  * Create a new Shader Program from two source strings.
  * <p>
  * Needs to be called from a thread holding the OpenGL context.
- * Assumed to hold GLSL 'version 300 es' source.
  *
  * @param vertex   Vertex shader code.
  * @param fragment Fragment shader code.
diff --git a/src/main/res/raw/blit_depth_fragment_shader.glsl b/src/main/res/raw/blit_depth_fragment_shader.glsl
index 01a9ba3..2e39264 100644
--- a/src/main/res/raw/blit_depth_fragment_shader.glsl
+++ b/src/main/res/raw/blit_depth_fragment_shader.glsl
@@ -18,7 +18,7 @@
 //////////////////////////////////////////////////////////////////////////////////////////////
 
 precision highp float;
-precision highp uint;
+precision highp int;
 
 #if __VERSION__ != 100
 out vec4 fragColor;           // The output color
@@ -56,26 +56,36 @@ layout (std430,binding=1) buffer linkedlist  // first (u_Size.x*u_Size.y) uints
 // This arranges fragments by decreasing 'depth', so one would think - from back to front, but
 // in main() below the depth is mapped with S*(1-depth)/2, so it is really front to back.
 
-void insert( vec2 ij, uint depth, uint rgba )
+void insert2( vec2 ij, uint depth, uint rgba )
   {
-  uint ptr = atomicCounterIncrement(u_Counter)-1u;
+/*
+  uint index = uint(ij.x + ij.y * float(u_Size.x));
+  u_Records[index] = (255u<<24u)+ uint( (int(255*int(ij.y)/u_Size.y))<<16u ) + (255u);
+  discard;
+*/
+
+  uint ptr = atomicCounterIncrement(u_Counter);
 
   if( ptr<u_numRecords )
-    {/*
-    uint color;
-    vec2 c = vec2(0.0,1.0);
+    {
+    ptr = ptr /*uint(ij.x + ij.y * float(u_Size.x))*/ + uint(u_Size.x*u_Size.y);
 
-    uint rgb = ((uint(255.0*c.x))<<16u) + uint(255.0*c.y);
+    u_Records[ptr   ] = (255u<<( (4*int(ij.x) > u_Size.x) ? 24u:16u)) + (255u);
+    //u_Records[ptr+1u] = depth;
+    //u_Records[ptr+2u] = rgba;
 
-         if(  rgb       ==  0u ) color = (255u<<24u) + (255u<<16u) + 255u;
-    else if( (rgb&255u) ==  0u ) color = (255u<<24u) + 255u;
-    else if( (rgb&255u) <= 50u ) color = (255u<<16u) + 255u;
-    else if( (rgb&255u) == 255u) color = (255u<<16u) + (255u<< 8u) + 255u;
-    else                         color = (255u<< 8u) + 255u;
-*/
-vec4 c= vec4(1.0,1.0,0.0,1.0);
-uint color = ((uint(255.0*c.r))<<24u) + ((uint(255.0*c.g))<<16u) + ((uint(255.0*c.b))<<8u) + uint(255.0*c.a);
+    uint index = uint(ij.x + ij.y * float(u_Size.x));
+    u_Records[index] = ptr;
+    discard;
+    }
+  }
+
+void insert( vec2 ij, uint depth, uint rgba )
+  {
+  uint ptr = atomicCounterIncrement(u_Counter);
 
+  if( ptr<u_numRecords )
+    {
     ptr = 3u*ptr + uint(u_Size.x*u_Size.y);
 
     u_Records[ptr   ] = 0u;
@@ -138,16 +148,15 @@ void main()
   {
   vec4 frag  = TEXTURE(u_Texture     , v_TexCoordinate);
   float depth= TEXTURE(u_DepthTexture, v_TexCoordinate).r;
-
+/*
   if( frag.a > 0.95 )
     {
     gl_FragDepth = depth;
     FRAG_COLOR   = frag;
     }
   else if( frag.a > 0.0 )
-    {
+    {*/
     const float S= 2147483647.0; // max signed int. Could probably be max unsigned int but this is enough.
-    insert(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );
-    discard;
-    }
+    insert2(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );
+    //}
   }
\ No newline at end of file
diff --git a/src/main/res/raw/blit_depth_render_fragment_shader.glsl b/src/main/res/raw/blit_depth_render_fragment_shader.glsl
index 1f05532..b44426f 100644
--- a/src/main/res/raw/blit_depth_render_fragment_shader.glsl
+++ b/src/main/res/raw/blit_depth_render_fragment_shader.glsl
@@ -18,7 +18,7 @@
 //////////////////////////////////////////////////////////////////////////////////////////////
 
 precision highp float;
-precision highp uint;
+precision highp int;
 
 #if __VERSION__ != 100
 out vec4 fragColor;           // The output color
@@ -66,16 +66,21 @@ vec4 blend(vec4 clr,vec4 srf)
 void main()                    		
   {
   uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));
+  uint ptr = u_Records[index];
 
-  if( u_Records[index] == 0u ) discard;
+  if( ptr == 0u ) discard;
   else
     {
-    index = u_Records[index];
-    FRAG_COLOR = convert(u_Records[index+2u]);
+    u_Records[index] = 0u;
+    vec4 color = convert(u_Records[ptr]);
+
+         if( (4*int(v_Pixel.x) > u_Size.x) && color.r==1.0 ) FRAG_COLOR = color;
+    else if( (4*int(v_Pixel.x) <=u_Size.x) && color.g==1.0 ) FRAG_COLOR = color;
+    else FRAG_COLOR = vec4(0.0,0.0,1.0,1.0);
+    //FRAG_COLOR = convert(u_Records[index]);
+    //u_Records[index] = 0u;
     }
 
-  u_Records[index] = 0u;
-
   /*
   uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));
   uint curr = u_Records[index];
diff --git a/src/main/res/raw/blit_depth_vertex_shader.glsl b/src/main/res/raw/blit_depth_vertex_shader.glsl
index d8ecabe..f1f5d57 100644
--- a/src/main/res/raw/blit_depth_vertex_shader.glsl
+++ b/src/main/res/raw/blit_depth_vertex_shader.glsl
@@ -17,8 +17,8 @@
 // along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
 //////////////////////////////////////////////////////////////////////////////////////////////
 
-precision lowp float;
-precision highp uint;
+precision highp float;
+precision highp int;
 
 #if __VERSION__ != 100
 in vec2 a_Position;           // Per-vertex position.
