commit 51a3cbab6ec0950b8ffaa12930c52e949522dd63
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Mar 28 23:33:05 2018 +0100

    SSBO: handle the fact that we might run out of space in our SSBO if we keep creating new Surfaces.

diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 6ca8bb9..0dc0fcd 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -183,8 +183,23 @@ public static final int DEBUG_FPS = 1;
 
     if( mSurfaceID>=mBufferSize )
       {
-      // increase the size of mSSBOBuffer, copy over old values, remap.
-      // TODO (don't need this if there are never more than mBufferSize=10 Surfaces)
+      // increase size of the Buffer, copy over old values, remap.
+      int[] tmp = new int[BUFFERING*mBufferSize];
+      for(int i=0;i<BUFFERING*mBufferSize;i++) tmp[i] = mIntBuffer.get(i);
+
+      mBufferSize*= 2;
+
+      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, 0);
+      GLES31.glUnmapBuffer(GLES31.GL_SHADER_STORAGE_BUFFER);
+      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER,0);
+
+      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
+      GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
+      ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT );
+      mIntBuffer = buf.order(ByteOrder.nativeOrder()).asIntBuffer();
+      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]);
+
+      for(int i=0;i<tmp.length;i++) mIntBuffer.put(i,tmp[i]);
       }
 
     createSurface();
diff --git a/src/main/res/raw/main_fragment_shader.glsl b/src/main/res/raw/main_fragment_shader.glsl
index 15638d5..b9c92c7 100644
--- a/src/main/res/raw/main_fragment_shader.glsl
+++ b/src/main/res/raw/main_fragment_shader.glsl
@@ -73,7 +73,7 @@ void main()
     }
 #endif
 
-  if( color.a < 1.0 ) ssbocount[u_currentIndex]++;
+  if( color.a < 1.0 && color.a > 0.0 ) ssbocount[u_currentIndex]++;
 
   FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
   }
\ No newline at end of file
