commit 70b6a155a15f11ba611af634c9ba23cecc18167f
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Jul 14 17:37:26 2017 +0100

    Internal API change around postprocessing.

diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffect.java b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
index 214b2f0..28ebd7c 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffect.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
@@ -19,8 +19,8 @@
 
 package org.distorted.library.effect;
 
-import org.distorted.library.main.DistortedFramebuffer;
 import org.distorted.library.main.DistortedMaster;
+import org.distorted.library.main.DistortedOutputSurface;
 import org.distorted.library.program.DistortedProgram;
 
 import java.nio.ByteBuffer;
@@ -139,7 +139,7 @@ public abstract class PostprocessEffect extends Effect implements DistortedMaste
  *
  * @y.exclude
  */
-  public abstract int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers);
+  public abstract int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers);
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java b/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
index 68d4857..63c7757 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
@@ -22,6 +22,7 @@ package org.distorted.library.effect;
 import android.opengl.GLES30;
 
 import org.distorted.library.main.DistortedFramebuffer;
+import org.distorted.library.main.DistortedOutputSurface;
 import org.distorted.library.main.DistortedRenderState;
 import org.distorted.library.program.DistortedProgram;
 import org.distorted.library.type.Data1D;
@@ -139,7 +140,7 @@ public class PostprocessEffectBlur extends PostprocessEffect
  *
  * @y.exclude
  */
-  public int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers)
+  public int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers)
     {
     if( mProgram1 ==null)
       {
@@ -149,7 +150,7 @@ public class PostprocessEffectBlur extends PostprocessEffect
 
     DistortedRenderState.useStencilMark();
 
-    DistortedFramebuffer buffer = buffers[mQualityLevel];
+    DistortedFramebuffer buffer = (DistortedFramebuffer)buffers[mQualityLevel];
 
     buffer.setAsOutput();
 
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java b/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
index ffcb85c..6257c32 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
@@ -23,6 +23,7 @@ import android.opengl.GLES30;
 
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedFramebuffer;
+import org.distorted.library.main.DistortedOutputSurface;
 import org.distorted.library.main.DistortedRenderState;
 import org.distorted.library.program.DistortedProgram;
 import org.distorted.library.type.Data1D;
@@ -143,7 +144,7 @@ public class PostprocessEffectGlow extends PostprocessEffect
  *
  * @y.exclude
  */
-  public int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers)
+  public int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers)
     {
     if( mProgram1 ==null)
       {
@@ -153,8 +154,8 @@ public class PostprocessEffectGlow extends PostprocessEffect
 
     DistortedRenderState.useStencilMark();
 
-    DistortedFramebuffer  inBuffer = buffers[0];
-    DistortedFramebuffer outBuffer = buffers[mQualityLevel];
+    DistortedFramebuffer  inBuffer = (DistortedFramebuffer)buffers[0];
+    DistortedFramebuffer outBuffer = (DistortedFramebuffer)buffers[mQualityLevel];
 
     float w= outBuffer.getWidth();
     float h= outBuffer.getHeight();
diff --git a/src/main/java/org/distorted/library/main/DistortedEffects.java b/src/main/java/org/distorted/library/main/DistortedEffects.java
index 167e6c9..fbe2dc7 100644
--- a/src/main/java/org/distorted/library/main/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/main/DistortedEffects.java
@@ -25,7 +25,6 @@ import android.opengl.GLES30;
 import org.distorted.library.R;
 import org.distorted.library.effect.Effect;
 import org.distorted.library.effect.EffectName;
-import org.distorted.library.effect.EffectQuality;
 import org.distorted.library.effect.EffectType;
 import org.distorted.library.effect.FragmentEffect;
 import org.distorted.library.effect.VertexEffect;
@@ -41,7 +40,6 @@ import java.io.InputStream;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.FloatBuffer;
-import java.util.ArrayList;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -231,37 +229,9 @@ public class DistortedEffects
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  int postprocess(DistortedOutputSurface surface)
+  EffectQueuePostprocess getPostprocess()
     {
-    return mP.postprocess(surface);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  long getBucket()
-    {
-    return mP.getID();
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  int getQuality()
-    {
-    return mP.getQuality();
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  int getInternalQuality()
-    {
-    return mP.getInternalQuality();
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  int getHalo()
-    {
-    return mP.getHalo();
+    return mP;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/main/DistortedMaster.java b/src/main/java/org/distorted/library/main/DistortedMaster.java
index 65c561e..2305b37 100644
--- a/src/main/java/org/distorted/library/main/DistortedMaster.java
+++ b/src/main/java/org/distorted/library/main/DistortedMaster.java
@@ -100,26 +100,17 @@ public class DistortedMaster
 
   static void addSorted(ArrayList<DistortedNode> mChildren, DistortedNode newChild)
     {
-    DistortedNode child;
-    DistortedEffects effects;
     int i,num = mChildren.size();
-    long bucket, newBucket;
-
-    effects = newChild.getEffects();
-    newBucket = effects.getBucket();
+    long bucket = newChild.getPostprocessQueue().getID();
 
     for(i=0; i<num; i++)
       {
-      child  = mChildren.get(i);
-      effects= child.getEffects();
-      bucket = effects.getBucket();
-
-      if( bucket>newBucket ) break;
+      if( mChildren.get(i).getPostprocessQueue().getID() > bucket ) break;
       }
 
     mChildren.add(i,newChild);
 
-    //android.util.Log.e("newChild", "newBucket="+newBucket+" new child at "+i+" total num ="+num);
+    //android.util.Log.e("newChild", "newBucket="+bucket+" new child at "+i+" total num ="+num);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/main/DistortedNode.java b/src/main/java/org/distorted/library/main/DistortedNode.java
index 5436670..de9f421 100644
--- a/src/main/java/org/distorted/library/main/DistortedNode.java
+++ b/src/main/java/org/distorted/library/main/DistortedNode.java
@@ -256,7 +256,7 @@ public class DistortedNode implements DistortedMaster.Slave
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  int markStencilAndDepth(long currTime, DistortedOutputSurface surface, DistortedEffects effects)
+  int markStencilAndDepth(long currTime, DistortedOutputSurface surface, EffectQueuePostprocess queue)
     {
     DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
 
@@ -264,7 +264,7 @@ public class DistortedNode implements DistortedMaster.Slave
       {
       surface.setAsOutput();
       DistortedRenderState.setUpStencilMark();
-      mEffects.drawPriv(mSurface.getWidth() /2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, effects.getHalo()*surface.mMipmap);
+      mEffects.drawPriv(mSurface.getWidth() /2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, queue.getHalo()*surface.mMipmap);
       DistortedRenderState.unsetUpStencilMark();
 
       return 1;
@@ -352,6 +352,17 @@ public class DistortedNode implements DistortedMaster.Slave
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Not part of the Public API.
+ *
+ * @y.exclude
+ */
+  public EffectQueuePostprocess getPostprocessQueue()
+    {
+    return mEffects.getPostprocess();
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 78adf3f..b4b160e 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -27,8 +27,12 @@ import org.distorted.library.effect.EffectQuality;
 import java.util.ArrayList;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-
-abstract class DistortedOutputSurface extends DistortedSurface implements DistortedMaster.Slave
+/**
+ * This is not really part of the public API.
+ *
+ * @y.exclude
+ */
+public abstract class DistortedOutputSurface extends DistortedSurface implements DistortedMaster.Slave
 {
 //////////// DEBUG FLAGS /////////////////////////////////////////////
 /**
@@ -72,7 +76,7 @@ public static final int DEBUG_FPS = 1;
 
   private ArrayList<Job> mJobs = new ArrayList<>();
 
-  DistortedFramebuffer[] mBuffer;
+  DistortedOutputSurface[] mBuffer;
 
   private long mTime;
   private float mFOV;
@@ -128,7 +132,7 @@ private String sLast="", sCurr="";
     mClearStencil = 0;
     mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT;
 
-    mBuffer = new DistortedFramebuffer[EffectQuality.LENGTH];
+    mBuffer = new DistortedOutputSurface[1+EffectQuality.LENGTH];
 
     mMipmap = 1.0f;
 
@@ -188,6 +192,8 @@ private String sLast="", sCurr="";
       mipmap *= EffectQuality.MULTIPLIER;
       }
 
+    mBuffer[EffectQuality.LENGTH] = this;
+
     DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
 
     GLES30.glStencilMask(0xff);
@@ -209,7 +215,7 @@ private String sLast="", sCurr="";
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int blitWithDepth(long currTime, DistortedFramebuffer buffer)
+  private int blitWithDepth(long currTime, DistortedOutputSurface buffer)
     {
     GLES30.glViewport(0, 0, mWidth, mHeight);
     setAsOutput(currTime);
@@ -253,7 +259,7 @@ private String sLast="", sCurr="";
     {
     int quality=0, internalQuality = 0, numRenders = 0, bucketChange = 0;
     DistortedNode child1, child2;
-    DistortedEffects lastEffects=null, currEffects;
+    EffectQueuePostprocess lastQueue=null, currQueue;
     long lastBucket=0, currBucket;
 
 sCurr = "";
@@ -261,8 +267,8 @@ sCurr = "";
     for(int i=0; i<numChildren; i++)
       {
       child1 = children.get(i);
-      currEffects = child1.getEffects();
-      currBucket  = currEffects.getBucket();
+      currQueue = child1.getPostprocessQueue();
+      currBucket= currQueue.getID();
 
 sCurr += (" "+currBucket);
 
@@ -278,35 +284,36 @@ sCurr += (" "+currBucket);
             for(int j=bucketChange; j<i; j++)
               {
               child2 = children.get(j);
-              numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastEffects);
+              numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastQueue);
               }
 
-            numRenders += lastEffects.postprocess(this);
+            numRenders += lastQueue.postprocess(this);
             numRenders += blitWithDepth(time, mBuffer[quality]);
             }
 
-          internalQuality = currEffects.getInternalQuality();
-          quality = currEffects.getQuality();
-          bucketChange = i;
+          internalQuality = currQueue.getInternalQuality();
+          quality         = currQueue.getQuality();
+          bucketChange    = i;
           }
 
-        numRenders += child1.draw(time,mBuffer[quality]);
+        child1.draw(time,mBuffer[quality]);
+        //numRenders += currQueue.draw(child1,time,mBuffer);
 
         if( i==numChildren-1 )
           {
           for(int j=bucketChange; j<numChildren; j++)
             {
             child2 = children.get(j);
-            numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currEffects);
+            numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currQueue);
             }
 
-          numRenders += currEffects.postprocess(this);
+          numRenders += currQueue.postprocess(this);
           numRenders += blitWithDepth(time, mBuffer[quality]);
           }
         }
 
-      lastEffects = currEffects;
-      lastBucket  = currBucket;
+      lastQueue = currQueue;
+      lastBucket= currBucket;
       }
 
 if( !sLast.equals(sCurr) ) android.util.Log.e("surface", "rendering: "+sCurr);
