commit a436ccc58e0cc056c9583123354005faf9cb666e
Author: leszek <leszek@koltunski.pl>
Date:   Tue Feb 14 16:51:57 2017 +0000

    1. Make it possible to enable/disable DEPTH test when rendering to a Screen
    2. Using this, remove the 'Root' Node from StarWars.

diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index a992491..d893e77 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -30,9 +30,6 @@ import android.opengl.GLES30;
  */
 public class DistortedFramebuffer extends DistortedOutputSurface implements DistortedInputSurface
   {
-  private int[] mDepthH = new int[1];
-  private int[] mFBOH   = new int[1];
-  private boolean mDepthEnabled;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Must be called from a thread holding OpenGL Context
@@ -160,12 +157,9 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
 // create 'system' Framebuffers, i.e. those that are used internally by the library.
 // Those do not get removed in onDestroy();
 
-  public DistortedFramebuffer(boolean depthEnabled, int width, int height)
+  DistortedFramebuffer(boolean depthEnabled, int width, int height)
     {
-    super(width,height,NOT_CREATED_YET,true);
-    mDepthEnabled= depthEnabled;
-    mFBOH[0]     = NOT_CREATED_YET;
-    mDepthH[0]   = NOT_CREATED_YET;
+    super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,true, depthEnabled);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -181,10 +175,7 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
   @SuppressWarnings("unused")
   public DistortedFramebuffer(int width, int height, boolean depthEnabled)
     {
-    super(width,height,NOT_CREATED_YET,false);
-    mDepthEnabled= depthEnabled;
-    mFBOH[0]     = NOT_CREATED_YET;
-    mDepthH[0]   = NOT_CREATED_YET;
+    super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false, depthEnabled);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -198,17 +189,14 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
   @SuppressWarnings("unused")
   public DistortedFramebuffer(int width, int height)
     {
-    super(width,height,NOT_CREATED_YET,false);
-    mDepthEnabled= false;
-    mFBOH[0]     = NOT_CREATED_YET;
-    mDepthH[0]   = NOT_CREATED_YET;
+    super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false,false);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Bind the underlying rectangle of pixels as a OpenGL Texture.
  *
- * @returns <code>true</code> if successful.
+ * @return <code>true</code> if successful.
  */
   public boolean setAsInput()
     {
@@ -221,42 +209,6 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
     return false;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Bind this Surface as a Framebuffer we can render to.
- */
-  public void setAsOutput()
-    {
-    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
-
-    if( mDepthH[0]!=NOT_CREATED_YET )
-      {
-      GLES30.glEnable(GLES30.GL_DEPTH_TEST);
-      GLES30.glDepthMask(true);
-      }
-    else
-      {
-      GLES30.glDisable(GLES30.GL_DEPTH_TEST);
-      GLES30.glDepthMask(false);
-      }
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Create a new DEPTH buffer and attach it or (param=false) detach an existing DEPTh attachment and recreate it.
- *
- * @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 enableDepthAttachment(boolean enable)
-    {
-    if( mDepthEnabled!=enable )
-      {
-      mDepthEnabled = enable;
-      moveToToDo();
-      }
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Return the ID of the Texture (COLOR attachment 0) that's backing this FBO.
@@ -272,15 +224,4 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
     {
     return mColorH[0];
     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Return true if the FBO contains a DEPTH attachment.
- *
- * @return <bold>true</bold> if the FBO contains a DEPTH attachment.
- */
-  public boolean hasDepth()
-    {
-    return mDepthEnabled;
-    }
   }
diff --git a/src/main/java/org/distorted/library/DistortedOutputSurface.java b/src/main/java/org/distorted/library/DistortedOutputSurface.java
index 0d7d433..960d04f 100644
--- a/src/main/java/org/distorted/library/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/DistortedOutputSurface.java
@@ -19,6 +19,7 @@
 
 package org.distorted.library;
 
+import android.opengl.GLES30;
 import android.opengl.Matrix;
 import java.util.ArrayList;
 
@@ -34,9 +35,13 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
   float mDistance;
   float[] mProjectionMatrix;
 
+  boolean mDepthEnabled;
+  int[] mDepthH = new int[1];
+  int[] mFBOH   = new int[1];
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  DistortedOutputSurface(int width, int height, int color, boolean system)
+  DistortedOutputSurface(int width, int height, int color, int fbo, boolean system, boolean depth)
     {
     super(width,height,color,system);
 
@@ -49,6 +54,10 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
     mX   =  0.0f;
     mY   =  0.0f;
 
+    mDepthEnabled= depth;
+    mFBOH[0]     = fbo;
+    mDepthH[0]   = color;
+
     createProjection();
     }
 
@@ -136,7 +145,21 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
 /**
  * Bind this Surface as a Framebuffer we can render to.
  */
-  public abstract void setAsOutput();
+  public void setAsOutput()
+    {
+    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
+
+    if( mDepthEnabled && mDepthH[0]!=NOT_CREATED_YET )
+      {
+      GLES30.glEnable(GLES30.GL_DEPTH_TEST);
+      GLES30.glDepthMask(true);
+      }
+    else
+      {
+      GLES30.glDisable(GLES30.GL_DEPTH_TEST);
+      GLES30.glDepthMask(false);
+      }
+    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -181,6 +204,33 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Create a new DEPTH buffer and attach it or (param=false) detach an existing DEPTH attachment and recreate it.
+ *
+ * @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 enableDepth(boolean enable)
+    {
+    if( mDepthEnabled!=enable )
+      {
+      mDepthEnabled = enable;
+      moveToToDo();
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Return true if the Surface contains a DEPTH attachment.
+ *
+ * @return <bold>true</bold> if the FBO contains a DEPTH attachment.
+ */
+  public boolean hasDepth()
+    {
+    return mDepthEnabled;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Adds a new child to the last position in the list of our Surface's children.
diff --git a/src/main/java/org/distorted/library/DistortedScreen.java b/src/main/java/org/distorted/library/DistortedScreen.java
index 9101c0b..d3c2f4e 100644
--- a/src/main/java/org/distorted/library/DistortedScreen.java
+++ b/src/main/java/org/distorted/library/DistortedScreen.java
@@ -19,8 +19,6 @@
 
 package org.distorted.library;
 
-import android.opengl.GLES30;
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Class which represents the Screen.
@@ -32,8 +30,8 @@ public class DistortedScreen extends DistortedOutputSurface
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // here we don't manage underlying OpenGL assets ourselves
 
-  void create()  {}
-  void delete()  {}
+  void create()   {}
+  void delete()   {}
   void recreate() {}
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -46,17 +44,6 @@ public class DistortedScreen extends DistortedOutputSurface
  */
   public DistortedScreen()
     {
-    super(0,0,DONT_CREATE,false);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Bind this Surface as a Framebuffer we can render to.
- */
-  public void setAsOutput()
-    {
-    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
-    GLES30.glEnable(GLES30.GL_DEPTH_TEST);
-    GLES30.glDepthMask(true);
+    super(0,0,DONT_CREATE,0,false,true);
     }
   }
