commit cdd5e8277d693ac728f7d142c9633584bd3bb2c7
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Sat Jan 28 00:50:22 2017 +0000

    Some fixes for issues discovered by the Multiblur app.

diff --git a/src/main/java/org/distorted/library/DistortedEffects.java b/src/main/java/org/distorted/library/DistortedEffects.java
index cd6929f..edf738b 100644
--- a/src/main/java/org/distorted/library/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/DistortedEffects.java
@@ -77,7 +77,7 @@ public class DistortedEffects
   private static long mNextID =0;
   private long mID;
 
-  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1);
+  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1,true);
 
   private EffectQueueMatrix      mM;
   private EffectQueueFragment    mF;
diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index b110a07..005ae54 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -53,7 +53,7 @@ public class DistortedFramebuffer
   private int[] fboIds   = new int[1];
 
   private boolean mMarked;
-  private boolean mDepthWanted;
+  private boolean mDepthEnabled;
 
   private int mTexWidth, mTexHeight;
 
@@ -84,7 +84,7 @@ public class DistortedFramebuffer
 
       checkStatus("color");
       }
-    if( mDepthWanted && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
+    if( mDepthEnabled && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
       {
       GLES30.glGenTextures(1, depthIds, 0);
       GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, depthIds[0]);
@@ -99,7 +99,7 @@ public class DistortedFramebuffer
 
       checkStatus("depth");
       }
-    if( !mDepthWanted && depthIds[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment.
+    if( !mDepthEnabled && depthIds[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment.
       {
       GLES30.glDeleteTextures(1, depthIds, 0);
       depthIds[0]=NOT_CREATED_YET;
@@ -221,7 +221,7 @@ public class DistortedFramebuffer
     for( DistortedFramebuffer fbo : mList)
       {
       if( fbo.colorIds[0]!=DONT_CREATE ) fbo.colorIds[0] = NOT_CREATED_YET;
-      if( fbo.mDepthWanted             ) fbo.depthIds[0] = NOT_CREATED_YET;
+      if( fbo.mDepthEnabled) fbo.depthIds[0] = NOT_CREATED_YET;
       }
     }
 
@@ -279,6 +279,37 @@ public class DistortedFramebuffer
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Create a new offscreen Framebuffer.
+ *
+ * @param width Width of the COLOR attachment.
+ * @param height Height of the COLOR attachment.
+ * @param depthEnabled Add DEPTH attachment?
+ */
+  @SuppressWarnings("unused")
+  public DistortedFramebuffer(int width, int height, boolean depthEnabled)
+    {
+    mProjectionMatrix = new float[16];
+
+    mHeight      = height;
+    mWidth       = width;
+    mTexHeight   = height;
+    mTexWidth    = width;
+    mFOV         = 60.0f;
+    mX           = 0.0f;
+    mY           = 0.0f;
+    mMarked      = false;
+    mDepthEnabled= depthEnabled;
+
+    fboIds[0]  =-1;
+    colorIds[0]= NOT_CREATED_YET;
+    depthIds[0]= NOT_CREATED_YET;
+
+    createProjection();
+
+    mList.add(this);
+    }
+
 /**
  * Create a new offscreen Framebuffer.
  *
@@ -290,15 +321,15 @@ public class DistortedFramebuffer
     {
     mProjectionMatrix = new float[16];
 
-    mHeight     = height;
-    mWidth      = width;
-    mTexHeight  = height;
-    mTexWidth   = width;
-    mFOV        = 60.0f;
-    mX          = 0.0f;
-    mY          = 0.0f;
-    mMarked     = false;
-    mDepthWanted= false;
+    mHeight      = height;
+    mWidth       = width;
+    mTexHeight   = height;
+    mTexWidth    = width;
+    mFOV         = 60.0f;
+    mX           = 0.0f;
+    mY           = 0.0f;
+    mMarked      = false;
+    mDepthEnabled= false;
 
     fboIds[0]  =-1;
     colorIds[0]= NOT_CREATED_YET;
@@ -321,11 +352,11 @@ public class DistortedFramebuffer
     {
     mProjectionMatrix = new float[16];
 
-    mFOV        = 60.0f;
-    mX          = 0.0f;
-    mY          = 0.0f;
-    mMarked     = false;
-    mDepthWanted= true;
+    mFOV         = 60.0f;
+    mX           = 0.0f;
+    mY           = 0.0f;
+    mMarked      = false;
+    mDepthEnabled= true;
 
     fboIds[0]  = fbo;
     colorIds[0]= DONT_CREATE;
@@ -336,12 +367,12 @@ public class DistortedFramebuffer
 /**
  * Create a new DEPTH buffer and attach it or (param=false) detach an existing DEPTh attachment and destroy it.
  *
- * @param hasDepthAttachment <bold>true</bold> if we want to attach a new DEPTH buffer to the FBO.<br>
- *                           <bold>false</bold> if we want to detach the DEPTH attachment.
+ * @param enable <bold>true</bold> if we want to attach a new DEPTH buffer to the FBO.<br>
+ *               <bold>false</bold> if we want to detach the DEPTH attachment.
  */
-  public void setDepthAttachment(boolean hasDepthAttachment)
+  public void enableDepthAttachment(boolean enable)
     {
-    mDepthWanted = hasDepthAttachment;
+    mDepthEnabled = enable;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -492,6 +523,6 @@ public class DistortedFramebuffer
  */
   public boolean hasDepth()
     {
-    return mDepthWanted;
+    return mDepthEnabled;
     }
   }
diff --git a/src/main/java/org/distorted/library/EffectQueuePostprocess.java b/src/main/java/org/distorted/library/EffectQueuePostprocess.java
index 664bbb4..368113b 100644
--- a/src/main/java/org/distorted/library/EffectQueuePostprocess.java
+++ b/src/main/java/org/distorted/library/EffectQueuePostprocess.java
@@ -69,7 +69,8 @@ class EffectQueuePostprocess extends EffectQueue
     mQuadTextureInv.put(textureInv).position(0);
     }
 
-  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1);
+  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1,true);
+
   private static float[] mMVPMatrix = new float[16];
   private static float[] mTmpMatrix = new float[16];
 
@@ -246,6 +247,8 @@ class EffectQueuePostprocess extends EffectQueue
 
     mBufferFBO.resizeFast( (int)w, (int)h);
     mBufferFBO.setAsOutput();
+    GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+    GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
     GLES30.glViewport(0, 0, (int)w, (int)h);
 
     Matrix.setIdentityM(mTmpMatrix, 0);
