commit 8b7b2398e516cef4b8f92a092b4b1474ed06611d
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Dec 13 22:35:54 2018 +0000

    Fix the bug where the postprocessed halo would not work for the first few frames of each quality level (before this commit the bug was visible in the 'GLOW' app).

diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 9c276d2..10dff23 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -182,6 +182,13 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
 
   private static void createPostprocessingBuffers(int width, int height, float near)
     {
+    final float CLEAR_R = 1.0f;
+    final float CLEAR_G = 1.0f;
+    final float CLEAR_B = 1.0f;
+    final float CLEAR_A = 0.0f;
+    final float CLEAR_D = 1.0f;
+    final int   CLEAR_S = 0;
+
     mBuffer = new DistortedFramebuffer[EffectQuality.LENGTH];
     float mipmap=1.0f;
 
@@ -190,19 +197,17 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
       mBuffer[j] = new DistortedFramebuffer(Distorted.FBO_QUEUE_SIZE,2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
       mBuffer[j].mMipmap = mipmap;
       mBuffer[j].mNear = near;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
-      mBuffer[j].glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+      mBuffer[j].glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
 
       mipmap *= EffectQuality.MULTIPLIER;
       }
 
     DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
 
-    GLES31.glStencilMask(0xff);
-    GLES31.glDepthMask(true);
-    GLES31.glColorMask(true, true, true, true);
-    GLES31.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
-    GLES31.glClearDepthf(1.0f);
-    GLES31.glClearStencil(0);
+    DistortedRenderState.colorDepthStencilOn();
+    GLES31.glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
+    GLES31.glClearDepthf(CLEAR_D);
+    GLES31.glClearStencil(CLEAR_S);
 
     for (int j=0; j<EffectQuality.LENGTH; j++)
       {
@@ -216,6 +221,8 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
         }
       }
 
+    DistortedRenderState.colorDepthStencilRestore();
+
     GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
     }
 
@@ -300,9 +307,9 @@ public abstract class DistortedOutputSurface extends DistortedSurface implements
     GLES31.glStencilMask(0xff);
     GLES31.glDepthMask(true);
     GLES31.glColorMask(true,true,true,true);
-    GLES31.glClearColor(0.0f,0.0f,0.0f,0.0f);
-    GLES31.glClearDepthf(1.0f);
-    GLES31.glClearStencil(0);
+    GLES31.glClearColor(buffer.mClearR,buffer.mClearG,buffer.mClearB,buffer.mClearA);
+    GLES31.glClearDepthf(buffer.mClearDepth);
+    GLES31.glClearStencil(buffer.mClearStencil);
 
     buffer.setAsOutput();
     GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0);
