commit 133cbb2bb1b6315c038d5c1d213338d7f81b763f
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Wed Feb 8 12:44:47 2017 +0000

    Introduce DistortedRenderable, a base class for Texture and Framebuffer

diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index 005ae54..bbe1fe4 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -39,24 +39,17 @@ import java.util.LinkedList;
  * framework where one is able to mark for deletion at any time and actual deletion takes place
  * on the next render).
  */
-public class DistortedFramebuffer
+public class DistortedFramebuffer extends DistortedRenderable
   {
-  private static final int FAILED_TO_CREATE = -1;
-  private static final int NOT_CREATED_YET  = -2;
-  private static final int DONT_CREATE      = -3;
-
   private static boolean mListMarked = false;
   private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
 
-  private int[] colorIds = new int[1];
-  private int[] depthIds = new int[1];
-  private int[] fboIds   = new int[1];
+  private int[] mDepthH = new int[1];
+  private int[] mFBOH   = new int[1];
 
   private boolean mMarked;
   private boolean mDepthEnabled;
 
-  private int mTexWidth, mTexHeight;
-
   // Projection stuff
   private float mX, mY, mFOV;
   int mWidth,mHeight,mDepth;
@@ -66,43 +59,43 @@ public class DistortedFramebuffer
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Must be called from a thread holding OpenGL Context
 
-  void createFBO()
+  void create()
     {
-    if( colorIds[0]==NOT_CREATED_YET )
+    if( mColorH[0]==NOT_CREATED_YET )
       {
-      GLES30.glGenTextures(1, colorIds, 0);
-      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, colorIds[0]);
+      GLES30.glGenTextures(1, mColorH, 0);
+      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
       GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
       GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
       GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
       GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
-      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mTexWidth, mTexHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
+      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mSizeX, mSizeY, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
 
-      GLES30.glGenFramebuffers(1, fboIds, 0);
-      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
-      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, colorIds[0], 0);
+      GLES30.glGenFramebuffers(1, mFBOH, 0);
+      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
+      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[0], 0);
 
       checkStatus("color");
       }
-    if( mDepthEnabled && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
+    if( mDepthEnabled && mDepthH[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]);
+      GLES30.glGenTextures(1, mDepthH, 0);
+      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthH[0]);
       GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
       GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
       GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
       GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
-      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mTexWidth, mTexHeight, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_SHORT, null);
+      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mSizeX, mSizeY, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_SHORT, null);
 
-      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
-      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, depthIds[0], 0);
+      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
+      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthH[0], 0);
 
       checkStatus("depth");
       }
-    if( !mDepthEnabled && depthIds[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment.
+    if( !mDepthEnabled && mDepthH[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment.
       {
-      GLES30.glDeleteTextures(1, depthIds, 0);
-      depthIds[0]=NOT_CREATED_YET;
+      GLES30.glDeleteTextures(1, mDepthH, 0);
+      mDepthH[0]=NOT_CREATED_YET;
       }
     }
 
@@ -116,12 +109,12 @@ public class DistortedFramebuffer
       {
       android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status);
 
-      GLES30.glDeleteTextures(1, colorIds, 0);
-      GLES30.glDeleteTextures(1, depthIds, 0);
-      GLES30.glDeleteFramebuffers(1, fboIds, 0);
-      fboIds[0]   = 0;
-      colorIds[0] = FAILED_TO_CREATE;
-      depthIds[0] = FAILED_TO_CREATE;
+      GLES30.glDeleteTextures(1, mColorH, 0);
+      GLES30.glDeleteTextures(1, mDepthH, 0);
+      GLES30.glDeleteFramebuffers(1, mFBOH, 0);
+      mFBOH[0]   = 0;
+      mColorH[0] = FAILED_TO_CREATE;
+      mDepthH[0] = FAILED_TO_CREATE;
 
       return false;
       }
@@ -132,23 +125,21 @@ public class DistortedFramebuffer
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Must be called from a thread holding OpenGL Context
 
-  private void deleteFBO()
+  private void delete()
     {
-    if( colorIds[0]>=0 )
+    if( mColorH[0]>=0 )
       {
-      //android.util.Log.e("FBO", "deleting ("+mWidth+","+mHeight+") "+fboIds[0]);
-
-      if( depthIds[0]>=0 )
+      if( mDepthH[0]>=0 )
         {
-        GLES30.glDeleteTextures(1, depthIds, 0);
-        depthIds[0]=NOT_CREATED_YET;
+        GLES30.glDeleteTextures(1, mDepthH, 0);
+        mDepthH[0]=NOT_CREATED_YET;
         }
 
-      GLES30.glDeleteTextures(1, colorIds, 0);
-      colorIds[0] = NOT_CREATED_YET;
+      GLES30.glDeleteTextures(1, mColorH, 0);
+      mColorH[0] = NOT_CREATED_YET;
 
-      GLES30.glDeleteFramebuffers(1, fboIds, 0);
-      fboIds[0] = 0;
+      GLES30.glDeleteFramebuffers(1, mFBOH, 0);
+      mFBOH[0] = 0;
       }
 
     mMarked = false;
@@ -158,9 +149,9 @@ public class DistortedFramebuffer
 
   void setAsOutput()
     {
-    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
+    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
 
-    if( depthIds[0]!=NOT_CREATED_YET )
+    if( mDepthH[0]!=NOT_CREATED_YET )
       {
       GLES30.glEnable(GLES30.GL_DEPTH_TEST);
       GLES30.glDepthMask(true);
@@ -172,13 +163,6 @@ public class DistortedFramebuffer
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  void setAsInput()
-    {
-    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, colorIds[0]);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void createProjection()
@@ -220,8 +204,8 @@ public class DistortedFramebuffer
     {
     for( DistortedFramebuffer fbo : mList)
       {
-      if( fbo.colorIds[0]!=DONT_CREATE ) fbo.colorIds[0] = NOT_CREATED_YET;
-      if( fbo.mDepthEnabled) fbo.depthIds[0] = NOT_CREATED_YET;
+      if( fbo.mColorH[0]!=DONT_CREATE ) fbo.mColorH[0] = NOT_CREATED_YET;
+      if( fbo.mDepthEnabled           ) fbo.mDepthH[0] = NOT_CREATED_YET;
       }
     }
 
@@ -241,7 +225,7 @@ public class DistortedFramebuffer
 
         if( tmp.mMarked )
           {
-          tmp.deleteFBO();
+          tmp.delete();
           iterator.remove();
           }
         }
@@ -265,15 +249,15 @@ public class DistortedFramebuffer
 
       createProjection();
 
-      if( mWidth>mTexWidth || mHeight>mTexHeight )
+      if( mWidth> mSizeX || mHeight> mSizeY)
         {
-        mTexWidth = mWidth;
-        mTexHeight= mHeight;
-        deleteFBO();
+        mSizeX = mWidth;
+        mSizeY = mHeight;
+        delete();
         }
       }
 
-    createFBO();
+    create();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -293,23 +277,25 @@ public class DistortedFramebuffer
 
     mHeight      = height;
     mWidth       = width;
-    mTexHeight   = height;
-    mTexWidth    = width;
+    mSizeY       = height;
+    mSizeX       = 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;
+    mFBOH[0]  =-1;
+    mColorH[0]= NOT_CREATED_YET;
+    mDepthH[0]= NOT_CREATED_YET;
 
     createProjection();
 
     mList.add(this);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
 /**
  * Create a new offscreen Framebuffer.
  *
@@ -323,17 +309,17 @@ public class DistortedFramebuffer
 
     mHeight      = height;
     mWidth       = width;
-    mTexHeight   = height;
-    mTexWidth    = width;
+    mSizeY       = height;
+    mSizeX       = width;
     mFOV         = 60.0f;
     mX           = 0.0f;
     mY           = 0.0f;
     mMarked      = false;
     mDepthEnabled= false;
 
-    fboIds[0]  =-1;
-    colorIds[0]= NOT_CREATED_YET;
-    depthIds[0]= NOT_CREATED_YET;
+    mFBOH[0]  =-1;
+    mColorH[0]= NOT_CREATED_YET;
+    mDepthH[0]= NOT_CREATED_YET;
 
     createProjection();
 
@@ -358,9 +344,9 @@ public class DistortedFramebuffer
     mMarked      = false;
     mDepthEnabled= true;
 
-    fboIds[0]  = fbo;
-    colorIds[0]= DONT_CREATE;
-    depthIds[0]= DONT_CREATE;
+    mFBOH[0]  = fbo;
+    mColorH[0]= DONT_CREATE;
+    mDepthH[0]= DONT_CREATE;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -389,12 +375,15 @@ public class DistortedFramebuffer
  */
   public void renderTo(DistortedTexture tex, MeshObject mesh, DistortedEffects effects, long time)
     {
-    tex.createTexture();
-    DistortedFramebuffer.deleteAllMarked();
-    DistortedTexture.deleteAllMarked();
-    createFBO();
-    tex.setAsInput();
-    effects.drawPriv(tex.mHalfX, tex.mHalfY, mesh, this, time);
+    tex.create();
+
+    if( tex.setAsInput() )
+      {
+      DistortedFramebuffer.deleteAllMarked();
+      DistortedTexture.deleteAllMarked();
+      create();
+      effects.drawPriv(tex.getWidth()/2.0f, tex.getHeight()/2.0f, mesh, this, time);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -412,15 +401,14 @@ public class DistortedFramebuffer
  */
   public void renderTo(DistortedFramebuffer fbo, MeshObject mesh, DistortedEffects effects, long time)
     {
-    fbo.createFBO();
+    fbo.create();
 
-    if( fbo.colorIds[0]>0 )    // fbo created with the first constructor
+    if( fbo.setAsInput() )
       {
       DistortedFramebuffer.deleteAllMarked();
       DistortedTexture.deleteAllMarked();
-      createFBO();
-      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, fbo.colorIds[0]);
-      effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, mesh, this, time);
+      create();
+      effects.drawPriv(fbo.getWidth()/2.0f, fbo.getHeight()/2.0f, mesh, this, time);
       }
     }
 
@@ -437,7 +425,7 @@ public class DistortedFramebuffer
     {
     DistortedFramebuffer.deleteAllMarked();
     DistortedTexture.deleteAllMarked();
-    createFBO();
+    create();
     dt.drawRecursive(time,this);
     }
 
@@ -447,7 +435,7 @@ public class DistortedFramebuffer
  */
   public void markForDeletion()
     {
-    //android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+fboIds[0]);
+    //android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+mFBOH[0]);
 
     mListMarked = true;
     mMarked     = true;
@@ -490,12 +478,12 @@ public class DistortedFramebuffer
       {
       mWidth    = width;
       mHeight   = height;
-      mTexWidth = width;
-      mTexHeight= height;
+      mSizeX = width;
+      mSizeY = height;
 
       createProjection();
 
-      if( colorIds[0]>0 ) markForDeletion();
+      if( mColorH[0]>0 ) markForDeletion();
       }
     }
 
@@ -512,7 +500,7 @@ public class DistortedFramebuffer
  */
   public int getTextureID()
     {
-    return colorIds[0];
+    return mColorH[0];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedRenderable.java b/src/main/java/org/distorted/library/DistortedRenderable.java
new file mode 100644
index 0000000..19aeee0
--- /dev/null
+++ b/src/main/java/org/distorted/library/DistortedRenderable.java
@@ -0,0 +1,93 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library;
+
+import android.opengl.GLES30;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+abstract class DistortedRenderable
+  {
+  static final int FAILED_TO_CREATE = -1;
+  static final int NOT_CREATED_YET  = -2;
+  static final int DONT_CREATE      = -3;
+
+  int[] mColorH = new int[1];
+  int mSizeX, mSizeY;  // in screen space
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  long getID()
+    {
+    return mColorH[0];
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  boolean setAsInput()
+    {
+    if( mColorH[0]>0 )
+      {
+      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
+      return true;
+      }
+
+    return false;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Returns the height of the Renderable.
+ *
+ * @return height of the object, in pixels.
+ */
+  public int getWidth()
+    {
+    return mSizeX;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Returns the width of the Renderable.
+ *
+ * @return width of the Object, in pixels.
+ */
+  public int getHeight()
+    {
+    return mSizeY;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Returns the depth of the Renderable.
+ * <p>
+ * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
+ * 'depth' of a Renderable (bitmap really!) when rendered based only on the texture itself, that depends
+ * on the Mesh it is rendered with.
+ *
+ * @return depth of the Object, in pixels.
+ */
+  public int getDepth(MeshObject mesh)
+    {
+    return mesh==null ? 0 : (int)(mSizeX*mesh.zFactor);
+    }
+  }
diff --git a/src/main/java/org/distorted/library/DistortedTexture.java b/src/main/java/org/distorted/library/DistortedTexture.java
index 47c5570..331fc37 100644
--- a/src/main/java/org/distorted/library/DistortedTexture.java
+++ b/src/main/java/org/distorted/library/DistortedTexture.java
@@ -39,20 +39,15 @@ import java.util.LinkedList;
  * framework where one is able to mark for deletion at any time and actual deletion takes place
  * on the next render).
  */
-public class DistortedTexture
+public class DistortedTexture extends DistortedRenderable
   {
   private static boolean mListMarked = false;
   private static LinkedList<DistortedTexture> mList = new LinkedList<>();
 
   private static int mTextureH;
 
-  private int mSizeX, mSizeY;  // in screen space
-  float mHalfX, mHalfY;        // halves of the above
-  private long mID;
   private boolean mMarked;
-
   private Bitmap mBmp= null;
-  private int[] mTextureDataH;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // We have to flip vertically every single Bitmap that we get fed with.
@@ -75,16 +70,14 @@ public class DistortedTexture
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // must be called from a thread holding OpenGL Context
 
-  void createTexture()
+  void create()
     {
-    if( mBmp!=null && mTextureDataH!=null )
+    if( mBmp!=null && mColorH !=null )
       {
-      //android.util.Log.e("Texture", "creating "+mID);
-
-      if( mTextureDataH[0]==0 )
+      if( mColorH[0]==0 )
         {
-        GLES30.glGenTextures(1, mTextureDataH, 0);
-        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
+        GLES30.glGenTextures(1, mColorH, 0);
+        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
         GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR );
         GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR );
         GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE );
@@ -93,7 +86,7 @@ public class DistortedTexture
         }
       else
         {
-        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
+        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
         GLUtils.texSubImage2D(GLES30.GL_TEXTURE_2D, 0,0,0,flipBitmap(mBmp));
         }
 
@@ -104,41 +97,17 @@ public class DistortedTexture
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // must be called from a thread holding OpenGL Context
 
-  private void deleteTexture()
+  private void delete()
     {
-    if( mTextureDataH!=null && mTextureDataH[0]>0 )
+    if( mColorH !=null && mColorH[0]>0 )
       {
-      //android.util.Log.e("Texture", "deleting "+mID);
-
-      GLES30.glDeleteTextures(1, mTextureDataH, 0);
-
-      mTextureDataH[0] = 0;
-      mID              = 0;
+      GLES30.glDeleteTextures(1, mColorH, 0);
+      mColorH[0] = 0;
       }
 
     mMarked = false;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  long getID()
-    {
-    return mID;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  boolean setAsInput()
-    {
-    if( mID!=0 )
-      {
-      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
-      return true;
-      }
-
-    return false;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   static void getUniforms(int mProgramH)
@@ -173,7 +142,7 @@ public class DistortedTexture
 
         if( tmp.mMarked )
           {
-          tmp.deleteTexture();
+          tmp.delete();
           iterator.remove();
           }
         }
@@ -190,14 +159,11 @@ public class DistortedTexture
  */
   public DistortedTexture(int width, int height)
     {
-    mSizeX= width ; mHalfX = mSizeX/2.0f;
-    mSizeY= height; mHalfY = mSizeY/2.0f;
-
-    mTextureDataH   = new int[1];
-    mTextureDataH[0]= 0;
-    mBmp            = null;
-    mID             = 0;
-    mMarked         = false;
+    mSizeX    = width ;
+    mSizeY    = height;
+    mColorH[0]= 0;
+    mBmp      = null;
+    mMarked   = false;
 
     mList.add(this);
     }
@@ -208,8 +174,6 @@ public class DistortedTexture
  */
   public void markForDeletion()
     {
-    //android.util.Log.e("Texture", "marking for deletion "+mID);
-
     mListMarked = true;
     mMarked     = true;
     }
@@ -227,45 +191,5 @@ public class DistortedTexture
   public void setTexture(Bitmap bmp)
     {
     mBmp= bmp;
-    mID = bmp.hashCode();
-
-    //android.util.Log.e("Texture", "setting new bitmap "+mID);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Returns the height of the Texture.
- *
- * @return height of the object, in pixels.
- */
-  public int getWidth()
-    {
-    return mSizeX;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Returns the width of the Texture.
- *
- * @return width of the Object, in pixels.
- */
-  public int getHeight()
-    {
-    return mSizeY;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Returns the depth of the Texture.
- * <p>
- * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
- * 'depth' of a texture when rendered based only on the texture itself, that depends on the Mesh it is
- * rendered with.
- *
- * @return depth of the Object, in pixels.
- */
-  public int getDepth(MeshObject mesh)
-    {
-    return mesh==null ? 0 : (int)(mSizeX*mesh.zFactor);
     }
   }
diff --git a/src/main/java/org/distorted/library/DistortedTree.java b/src/main/java/org/distorted/library/DistortedTree.java
index d5953eb..6e7ac32 100644
--- a/src/main/java/org/distorted/library/DistortedTree.java
+++ b/src/main/java/org/distorted/library/DistortedTree.java
@@ -200,7 +200,9 @@ public class DistortedTree
 
   void drawRecursive(long currTime, DistortedFramebuffer df)
     {
-    mTexture.createTexture();
+    mTexture.create();
+    float halfX = mTexture.getWidth()/2.0f;
+    float halfY = mTexture.getHeight()/2.0f;
 
     if( mNumChildren[0]<=0 )
       {
@@ -208,7 +210,7 @@ public class DistortedTree
       }
     else
       {
-      mData.mFBO.createFBO();
+      mData.mFBO.create();
 
       if( mData.numRendered==0 )
         {
@@ -218,7 +220,7 @@ public class DistortedTree
         GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
 
         if( mTexture.setAsInput() )
-          DistortedEffects.drawNoEffectsPriv(mTexture.mHalfX, mTexture.mHalfY, mMesh, mData.mFBO);
+          DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
 
         synchronized(this)
           {
@@ -234,7 +236,7 @@ public class DistortedTree
       mData.mFBO.setAsInput();
       }
 
-    mEffects.drawPriv(mTexture.mHalfX, mTexture.mHalfY, mMesh, df, currTime);
+    mEffects.drawPriv(halfX, halfY, mMesh, df, currTime);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
