commit 247d8225710ae0cabb62453ea9f8b0c44cb8bc97
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Jul 26 00:54:18 2018 +0100

    More progress with a more generic 'preprocess' stage of Postprocessing Effects.

diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffect.java b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
index cf55fa2..fef1b83 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffect.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
@@ -160,6 +160,17 @@ public abstract class PostprocessEffect extends Effect implements DistortedMaste
     return mQualityLevel;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+  /**
+   * Only for use by the library itself.
+   *
+   * @y.exclude
+   */
+  public int getWriteColor()
+    {
+    return 0;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * This is not really part of the public API. Has to be public only because it is a part of the
diff --git a/src/main/java/org/distorted/library/main/EffectQueuePostprocess.java b/src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
index ef7613f..8cf1638 100644
--- a/src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
+++ b/src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
@@ -41,8 +41,8 @@ class EffectQueuePostprocess extends EffectQueue
 
   private int mHalo;
 
-  static DistortedProgram mPreProgram;
-  static int mPreColorH;
+  private static DistortedProgram mPreProgram;
+  private static int mPreColorH;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -88,12 +88,8 @@ class EffectQueuePostprocess extends EffectQueue
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-  /**
-   * Only for use by the library itself.
-   *
-   * @y.exclude
-   */
-  public static void createPrograms(Resources resources)
+
+  static void createPrograms(Resources resources)
     {
     final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
     final InputStream mainFragStream = resources.openRawResource(R.raw.preprocess_fragment_shader);
@@ -125,9 +121,9 @@ class EffectQueuePostprocess extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // TODO
 
-  private boolean getWriteColor()
+  private int getWriteColor()
     {
-    return false;
+    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getWriteColor() : 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -165,15 +161,15 @@ class EffectQueuePostprocess extends EffectQueue
 
     if( input.setAsInput() )
       {
-      MeshObject    mesh = node.getMesh();
-      boolean writeColor = getWriteColor();
-      float       margin = getHalo()*surface.mMipmap;
+      MeshObject mesh = node.getMesh();
+      int  writeColor = getWriteColor();
+      float    margin = getHalo()*surface.mMipmap;
 
       float halfW = input.getWidth() / 2.0f;
       float halfH = input.getHeight()/ 2.0f;
       float halfZ = halfW*mesh.zFactor;
 
-      DistortedRenderState.setUpStencilMark(writeColor);
+      DistortedRenderState.setUpStencilMark(writeColor!=0);
 
       GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
 
@@ -187,6 +183,20 @@ class EffectQueuePostprocess extends EffectQueue
 
       node.getEffects().send(halfW, halfH, halfZ, margin, surface, 2);
 
+      float a = (writeColor&255);
+
+      if( a!=0.0f )
+        {
+        writeColor = (writeColor>>8);
+        float b = writeColor&255;
+        writeColor = (writeColor>>8);
+        float g = writeColor&255;
+        writeColor = (writeColor>>8);
+        float r = writeColor&255;
+
+        GLES31.glUniform4f(mPreColorH, r, g, b, a);
+        }
+
       GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
 
       DistortedRenderState.unsetUpStencilMark();
