commit e7a207026741ad6310020b7f19f713b9a21fcc02
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Mon Dec 19 21:59:14 2016 +0000

    Simplify DistortedTexture.

diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index 0616d3a..8bbda64 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -273,9 +273,9 @@ public class DistortedFramebuffer
   public void renderTo(DistortedTexture tex, GridObject grid, DistortedEffects effects, long time)
     {
     tex.createTexture();
+    tex.setAsInput();
     createFBO();
     GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
-    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
     effects.drawPriv(tex.mHalfX, tex.mHalfY, grid, this, time);
     DistortedFramebuffer.deleteAllMarked();
     DistortedTexture.deleteAllMarked();
diff --git a/src/main/java/org/distorted/library/DistortedTexture.java b/src/main/java/org/distorted/library/DistortedTexture.java
index 22a6d3b..8521678 100644
--- a/src/main/java/org/distorted/library/DistortedTexture.java
+++ b/src/main/java/org/distorted/library/DistortedTexture.java
@@ -51,9 +51,9 @@ public class DistortedTexture
   private long mID;
   private boolean mMarked;
 
-  private Bitmap[] mBmp= null; //
-  int[] mTextureDataH;         // have to be shared among all the cloned Objects
-  boolean[] mBitmapSet;        //
+  private Bitmap mBmp= null;
+  private int[] mTextureDataH;
+  private boolean mBitmapSet;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // We have to flip vertically every single Bitmap that we get fed with.
@@ -78,7 +78,7 @@ public class DistortedTexture
 
   void createTexture()
     {
-    if( mBmp[0]!=null && mTextureDataH!=null )
+    if( mBmp!=null && mTextureDataH!=null )
       {
       //android.util.Log.e("Texture", "creating "+mID);
 
@@ -90,8 +90,8 @@ public class DistortedTexture
       GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
       GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
 
-      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp[0]), 0);
-      mBmp[0] = null;
+      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0);
+      mBmp = null;
       }
     }
 
@@ -107,7 +107,7 @@ public class DistortedTexture
       GLES20.glDeleteTextures(1, mTextureDataH, 0);
 
       mTextureDataH[0] = 0;
-      mBitmapSet[0] = false;
+      mBitmapSet= false;
       }
 
     mMarked = false;
@@ -120,6 +120,19 @@ public class DistortedTexture
     return mID;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  boolean setAsInput()
+    {
+    if( mBitmapSet )
+      {
+      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
+      return true;
+      }
+
+    return false;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   static void getUniforms(int mProgramH)
@@ -176,56 +189,14 @@ public class DistortedTexture
 
     mTextureDataH   = new int[1];
     mTextureDataH[0]= 0;
-    mBmp            = new Bitmap[1];
-    mBmp[0]         = null;
-    mBitmapSet      = new boolean[1];
-    mBitmapSet[0]   = false;
+    mBmp            = null;
+    mBitmapSet      = false;
     mID             = 0;
     mMarked         = false;
 
     mList.add(this);
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Copy constructor.
- * <p>
- * Whatever we do not clone gets created just like in the default constructor.
- *
- * @param dt    Source object to create our object from
- * @param flags A bitmask of values specifying what to copy.
- *              Only possibilities: CLONE_BITMAP or CLONE_NOTHING.
- */
-
-  public DistortedTexture(DistortedTexture dt, int flags)
-    {
-    mSizeX= dt.mSizeX ; mHalfX = mSizeX/2.0f;
-    mSizeY= dt.mSizeY ; mHalfY = mSizeY/2.0f;
-
-    if( (flags & Distorted.CLONE_BITMAP) != 0 )
-      {
-      mTextureDataH = dt.mTextureDataH;
-      mBmp          = dt.mBmp;
-      mBitmapSet    = dt.mBitmapSet;
-      mID           = dt.getID();
-      }
-    else
-      {
-      mTextureDataH   = new int[1];
-      mTextureDataH[0]= 0;
-      mBitmapSet      = new boolean[1];
-      mBitmapSet[0]   = false;
-      mBmp            = new Bitmap[1];
-      mBmp[0]         = null;
-      mID             = 0;
-      }
-
-    mMarked = false;
-
-    mList.add(this);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
@@ -250,9 +221,9 @@ public class DistortedTexture
 
   public void setTexture(Bitmap bmp)
     {
-    mBitmapSet[0] = true;
-    mBmp[0]       = bmp;
-    mID           = bmp.hashCode();
+    mBitmapSet = true;
+    mBmp       = bmp;
+    mID        = bmp.hashCode();
 
     //android.util.Log.e("Texture", "setting new bitmap "+mID);
     }
diff --git a/src/main/java/org/distorted/library/DistortedTree.java b/src/main/java/org/distorted/library/DistortedTree.java
index 17d419d..c1ad09a 100644
--- a/src/main/java/org/distorted/library/DistortedTree.java
+++ b/src/main/java/org/distorted/library/DistortedTree.java
@@ -208,7 +208,7 @@ public class DistortedTree
 
     if( mNumChildren[0]<=0 )
       {
-      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture.mTextureDataH[0]);
+      mTexture.setAsInput();
       }
     else
       {
@@ -221,11 +221,8 @@ public class DistortedTree
         GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
         GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
 
-        if( mTexture.mBitmapSet[0] )
-          {
-          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture.mTextureDataH[0]);
+        if( mTexture.setAsInput() )
           mEffects.drawNoEffectsPriv(mTexture.mHalfX, mTexture.mHalfY, mGrid, mData.mDF);
-          }
 
         synchronized(this)
           {
@@ -295,10 +292,17 @@ public class DistortedTree
   public DistortedTree(DistortedTree node, int flags)
     {
     mParent = null;
-    mTexture= new DistortedTexture(node.mTexture,flags);
     mEffects= new DistortedEffects(node.mEffects,flags);
     mGrid   = node.mGrid;
 
+    if( (flags & Distorted.CLONE_BITMAP) != 0 )
+      {
+      mTexture = node.mTexture;
+      }
+    else
+      {
+      mTexture = new DistortedTexture(node.mTexture.getWidth(), node.mTexture.getHeight());
+      }
     if( (flags & Distorted.CLONE_CHILDREN) != 0 )
       {
       mChildren = node.mChildren;
