commit 8ca9f899c70d8be02f02401c8ac8ed368f4632dc
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Wed Feb 8 18:09:12 2017 +0000

    Introduce Renderable to the Tree.

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index 3b31a2c..c488fb9 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -44,7 +44,7 @@ public class Distorted
    * This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
    * apply different effects. Used in the copy constructor.
    */
-  public static final int CLONE_BITMAP  = 0x1;
+  public static final int CLONE_RENDERABLE = 0x1;
   /**
    * When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
    * <p>
diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index c620ad8..cbf693e 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -390,8 +390,8 @@ public class DistortedFramebuffer extends DistortedRenderable
     {
     if( mWidth!=width || mHeight!=height )
       {
-      mWidth    = width;
-      mHeight   = height;
+      mWidth = width;
+      mHeight= height;
       mSizeX = width;
       mSizeY = height;
 
diff --git a/src/main/java/org/distorted/library/DistortedRenderable.java b/src/main/java/org/distorted/library/DistortedRenderable.java
index 83987bf..15d6623 100644
--- a/src/main/java/org/distorted/library/DistortedRenderable.java
+++ b/src/main/java/org/distorted/library/DistortedRenderable.java
@@ -25,8 +25,12 @@ import java.util.Iterator;
 import java.util.LinkedList;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-
-abstract class DistortedRenderable
+/**
+ * Abstract class which represents a Renderable Object, i.e. something that we can take an skin our Mesh with.
+ * <p>
+ * Currently a DistortedTexture or a DistortedFramebuffer are Renderables.
+ */
+public abstract class DistortedRenderable
   {
   static final int FAILED_TO_CREATE = -1;
   static final int NOT_CREATED_YET  = -2;
diff --git a/src/main/java/org/distorted/library/DistortedTree.java b/src/main/java/org/distorted/library/DistortedTree.java
index 6e7ac32..47cf2f6 100644
--- a/src/main/java/org/distorted/library/DistortedTree.java
+++ b/src/main/java/org/distorted/library/DistortedTree.java
@@ -38,7 +38,7 @@ public class DistortedTree
 
   private MeshObject mMesh;
   private DistortedEffects mEffects;
-  private DistortedTexture mTexture;
+  private DistortedRenderable mRenderable;
   private NodeData mData;
 
   private DistortedTree mParent;
@@ -94,7 +94,7 @@ public class DistortedTree
     {
     ArrayList<Long> ret = new ArrayList<>();
      
-    ret.add( mTexture.getID() );
+    ret.add( mRenderable.getID() );
     DistortedTree node;
    
     for(int i=0; i<mNumChildren[0]; i++)
@@ -125,7 +125,7 @@ public class DistortedTree
       if( newList.size()>1 )
         {
         if( mData.mFBO ==null )
-          mData.mFBO = new DistortedFramebuffer(mTexture.getWidth(), mTexture.getHeight());
+          mData.mFBO = new DistortedFramebuffer(mRenderable.getWidth(), mRenderable.getHeight());
         }
       else
         {
@@ -200,13 +200,13 @@ public class DistortedTree
 
   void drawRecursive(long currTime, DistortedFramebuffer df)
     {
-    mTexture.create();
-    float halfX = mTexture.getWidth()/2.0f;
-    float halfY = mTexture.getHeight()/2.0f;
+    mRenderable.create();
+    float halfX = mRenderable.getWidth()/2.0f;
+    float halfY = mRenderable.getHeight()/2.0f;
 
     if( mNumChildren[0]<=0 )
       {
-      mTexture.setAsInput();
+      mRenderable.setAsInput();
       }
     else
       {
@@ -219,7 +219,7 @@ public class DistortedTree
         GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
         GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
 
-        if( mTexture.setAsInput() )
+        if( mRenderable.setAsInput() )
           DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
 
         synchronized(this)
@@ -245,22 +245,22 @@ public class DistortedTree
 /**
  * Constructs new Node of the Tree.
  *     
- * @param texture DistortedTexture to put into the new Node.
+ * @param renderable DistortedRenderable to put into the new Node.
  * @param effects DistortedEffects to put into the new Node.
  * @param mesh MeshObject to put into the new Node.
  */
-  public DistortedTree(DistortedTexture texture, DistortedEffects effects, MeshObject mesh)
+  public DistortedTree(DistortedRenderable renderable, DistortedEffects effects, MeshObject mesh)
     {
-    mTexture= texture;
-    mEffects= effects;
-    mMesh   = mesh;
-    mParent = null;
-    mChildren = null;
-    mNumChildren = new int[1];
-    mNumChildren[0] = 0;
+    mRenderable    = renderable;
+    mEffects       = effects;
+    mMesh          = mesh;
+    mParent        = null;
+    mChildren      = null;
+    mNumChildren   = new int[1];
+    mNumChildren[0]= 0;
    
     ArrayList<Long> list = new ArrayList<>();
-    list.add(mTexture.getID());
+    list.add(mRenderable.getID());
 
     mData = mMapNodeID.get(list);
    
@@ -281,9 +281,9 @@ public class DistortedTree
  *     
  * @param node The DistortedTree to copy data from.
  * @param flags bit field composed of a subset of the following:
- *        {@link Distorted#CLONE_BITMAP},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
+ *        {@link Distorted#CLONE_RENDERABLE},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
  *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
- *        For example flags = CLONE_BITMAP | CLONE_CHILDREN.
+ *        For example flags = CLONE_RENDERABLE | CLONE_CHILDREN.
  */
   public DistortedTree(DistortedTree node, int flags)
     {
@@ -291,13 +291,24 @@ public class DistortedTree
     mEffects= new DistortedEffects(node.mEffects,flags);
     mMesh = node.mMesh;
 
-    if( (flags & Distorted.CLONE_BITMAP) != 0 )
+    if( (flags & Distorted.CLONE_RENDERABLE) != 0 )
       {
-      mTexture = node.mTexture;
+      mRenderable = node.mRenderable;
       }
     else
       {
-      mTexture = new DistortedTexture(node.mTexture.getWidth(), node.mTexture.getHeight());
+      int w = node.mRenderable.getWidth();
+      int h = node.mRenderable.getHeight();
+
+      if( node.mRenderable instanceof DistortedTexture )
+        {
+        mRenderable = new DistortedTexture(w,h);
+        }
+      else if( node.mRenderable instanceof DistortedFramebuffer )
+        {
+        boolean hasDepth = ((DistortedFramebuffer) node.mRenderable).hasDepth();
+        mRenderable = new DistortedFramebuffer(w,h,hasDepth);
+        }
       }
     if( (flags & Distorted.CLONE_CHILDREN) != 0 )
       {
@@ -349,17 +360,17 @@ public class DistortedTree
 /**
  * Adds a new child to the last position in the list of our Node's children.
  * 
- * @param texture DistortedTexture to initialize our child Node with.
+ * @param renderable DistortedRenderable to initialize our child Node with.
  * @param effects DistortedEffects to initialize our child Node with.
  * @param mesh MeshObject to initialize our child Node with.
  * @return the newly constructed child Node, or null if we couldn't allocate resources.
  */
-  public synchronized DistortedTree attach(DistortedTexture texture, DistortedEffects effects, MeshObject mesh)
+  public synchronized DistortedTree attach(DistortedRenderable renderable, DistortedEffects effects, MeshObject mesh)
     {
     ArrayList<Long> prev = generateIDList(); 
       
     if( mChildren==null ) mChildren = new ArrayList<>(2);
-    DistortedTree node = new DistortedTree(texture,effects,mesh);
+    DistortedTree node = new DistortedTree(renderable,effects,mesh);
     node.mParent = this;
     mChildren.add(node);
     mNumChildren[0]++;
@@ -463,13 +474,13 @@ public class DistortedTree
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Returns the DistortedTexture object that's in the Node.
+ * Returns the DistortedRenderable object that's in the Node.
  *
- * @return The DistortedTexture contained in the Node.
+ * @return The DistortedRenderable contained in the Node.
  */
-  public DistortedTexture getTexture()
+  public DistortedRenderable getRenderable()
     {
-    return mTexture;
+    return mRenderable;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
