commit 2ab60f72f69bc613595a12f3dd295aaf728b2fa3
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Mar 28 14:58:33 2018 +0100

    SSBO: something is working already, although we still get the 4 bytes back from the shader in reverse order ( so '17'=0x00000011 written by the shader becomes '285212672 = 0x11000000' )

diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 3e4ccd5..c48e5fc 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -162,6 +162,18 @@ public static final int DEBUG_FPS = 1;
     createProjection();
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void error(String msg)
+    {
+    int err = GLES31.glGetError();
+
+    if( err != GLES31.GL_NO_ERROR )
+      {
+      android.util.Log.e("surface", msg+" error: "+err);
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Must be called from a thread holding OpenGL Context
 
@@ -173,9 +185,13 @@ public static final int DEBUG_FPS = 1;
 
       // here bind the new SSBO and map it
       GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
+      error("pre1");
       GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
-      mSSBOBuffer = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_WRITE_BIT | GLES31.GL_MAP_WRITE_BIT );
-      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,1, mSSBO[0]);
+      error("pre2");
+      mSSBOBuffer = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT );
+      error("pre3");
+      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]);
+      error("pre4");
       }
 
     mSurfaceID = mSurfaceCounter.returnNext();
diff --git a/src/main/java/org/distorted/library/main/DistortedScreen.java b/src/main/java/org/distorted/library/main/DistortedScreen.java
index efd73f5..530d3d5 100644
--- a/src/main/java/org/distorted/library/main/DistortedScreen.java
+++ b/src/main/java/org/distorted/library/main/DistortedScreen.java
@@ -137,9 +137,8 @@ public class DistortedScreen extends DistortedOutputSurface
  */
   public DistortedScreen()
     {
-    // set color to 'DONT_CREATE' so that Screens will not get added to the Surface lists
-    // set depth to 'CREATED' so that depth will be, by default, on.
-    super(0,0,DONT_CREATE,1,DEPTH_NO_STENCIL,0,TYPE_USER);
+    // Screen also has to be created (3rd arg 'NOT_CREATED_YET') because of the SSBO inside OutputSurface.
+    super(0,0,NOT_CREATED_YET,1,DEPTH_NO_STENCIL,0,TYPE_USER);
 
     mInitialized = false;
     }
diff --git a/src/main/res/raw/main_fragment_shader.glsl b/src/main/res/raw/main_fragment_shader.glsl
index 27b78c6..6fa42a8 100644
--- a/src/main/res/raw/main_fragment_shader.glsl
+++ b/src/main/res/raw/main_fragment_shader.glsl
@@ -43,9 +43,9 @@ uniform vec4 fUniforms[2*NUM_FRAGMENT]; // i-th effect is 2 consecutive vec4's:
                                         // next describes the Region, i.e. area over which the effect is active.
 #endif    // NUM_FRAGMENT>0
 
-layout (std140,binding=1) buffer SSBO   // PER-SURFACE count of transparent fragments.
+layout (std140,binding=0) buffer SSBO   // PER-SURFACE count of transparent fragments.
   {                                     // Can be buffered, i.e. if we are for example
-  int count[];                          // triple-buffered, then surfaceID=N uses 3
+  int ssbocount[];                      // triple-buffered, then surfaceID=N uses 3
   };                                    // consecutive counts (N,N+1,N+2) during 3
                                         // consecutive frames.
 uniform int u_currentIndex;             // Index into the count[] array we are supposed to be using
@@ -73,7 +73,7 @@ void main()
     }
 #endif
 
-  count[0]=17;
+  ssbocount[0]=17;
 
   FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
   }
\ No newline at end of file
