commit c9a24bfb83991030e3345f87685ffd5f20384a2e
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri May 26 12:52:54 2017 +0100

    Bugfix in renderChildren (postprocess):
    
    for each bucket, first render all the bucket members , only then render all of their Stencils+Depths (avoids this 'black ring' effect)

diff --git a/src/main/java/org/distorted/library/DistortedNode.java b/src/main/java/org/distorted/library/DistortedNode.java
index f796948..fe141e4 100644
--- a/src/main/java/org/distorted/library/DistortedNode.java
+++ b/src/main/java/org/distorted/library/DistortedNode.java
@@ -259,25 +259,15 @@ public class DistortedNode implements DistortedSlave
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  int markStencilAndDraw(long currTime, DistortedOutputSurface surface, DistortedEffectsPostprocess effects)
+  int markStencilAndDepth(long currTime, DistortedOutputSurface surface, DistortedEffectsPostprocess effects)
     {
     DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
 
     if( input.setAsInput() )
       {
-      int quality = effects.getQuality();
-      DistortedFramebuffer buffer = surface.mBuffer[quality];
-      float w = mSurface.getWidth() /2.0f;
-      float h = mSurface.getHeight()/2.0f;
-      buffer.setAsOutput();
-
-      // Draw the color buffer of the object.
-      mState.apply();
-      mEffects.drawPriv(w, h, mMesh, buffer, currTime, 0);
-
-      // Draw stencil + depth buffers of the object enlarged by HALO pixels around.
+      surface.setAsOutput();
       DistortedRenderState.setUpStencilMark();
-      mEffects.drawPriv(w, h, mMesh, buffer, currTime, effects.getHalo()*buffer.mMipmap);
+      mEffects.drawPriv(mSurface.getWidth() /2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, effects.getHalo()*surface.mMipmap);
       DistortedRenderState.unsetUpStencilMark();
 
       return 1;
diff --git a/src/main/java/org/distorted/library/DistortedOutputSurface.java b/src/main/java/org/distorted/library/DistortedOutputSurface.java
index 0445aca..4e11295 100644
--- a/src/main/java/org/distorted/library/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/DistortedOutputSurface.java
@@ -237,34 +237,54 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
     DistortedNode child;
     DistortedEffectsPostprocess lastP=null, currP;
     long lastB=0, currB;
-    int quality;
+    int bucketChange=0;
+    int lastQ=0, currQ;
 
     for(int i=0; i<num; i++)
       {
       child = children.get(i);
       currP = child.getEffectsPostprocess();
       currB = currP==null ? 0 : currP.getBucket();
-
-      if( lastB!=currB && lastB!=0 )
-        {
-        quality = lastP.getQuality();
-        numRenders += lastP.postprocess(time, this);
-        numRenders += blitWithDepth(quality,time);
-        }
+      currQ = currP==null ? 0 : currP.getQuality();
 
       if( currB==0 ) numRenders += child.draw(time,this);
       else
         {
         if( mBuffer[0]==null ) createBuffers();
-        numRenders += child.markStencilAndDraw(time,this,currP);
+
+        if( lastB!=currB )
+          {
+          if( lastB!=0 )
+            {
+            for(int j=bucketChange; j<i; j++)
+              {
+              child = children.get(j);
+              numRenders += child.markStencilAndDepth(time,mBuffer[lastQ],lastP);
+              }
+
+            numRenders += lastP.postprocess(time, this);
+            numRenders += blitWithDepth(lastQ,time);
+            }
+
+          bucketChange = i;
+          }
+
+        numRenders += child.draw(time,mBuffer[currQ]);
+
         if( i==num-1 )
           {
-          quality = currP.getQuality();
+          for(int j=bucketChange; j<num; j++)
+            {
+            child = children.get(j);
+            numRenders += child.markStencilAndDepth(time,mBuffer[currQ],currP);
+            }
+
           numRenders += currP.postprocess(time,this);
-          numRenders += blitWithDepth(quality,time);
+          numRenders += blitWithDepth(currQ,time);
           }
         }
 
+      lastQ = currQ;
       lastP = currP;
       lastB = currB;
       }
