commit 3ef3364d576ee004145bcc56214a2df90f766697
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Wed Dec 14 00:10:29 2016 +0000

    Hide the 'depth' of a DistortedTexture inside the library, so users do not get exposed to this weirdness.

diff --git a/src/main/java/org/distorted/library/DistortedEffectQueues.java b/src/main/java/org/distorted/library/DistortedEffectQueues.java
index b22afda..d4904e0 100644
--- a/src/main/java/org/distorted/library/DistortedEffectQueues.java
+++ b/src/main/java/org/distorted/library/DistortedEffectQueues.java
@@ -92,11 +92,13 @@ public class DistortedEffectQueues
 
     GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
 
+    float halfZ = tex.mHalfX*grid.zFactor;
+
     mM.compute(currTime);
-    mM.send(df,tex.mHalfX,tex.mHalfY,tex.mHalfZ);
+    mM.send(df,tex.mHalfX,tex.mHalfY,halfZ);
       
     mV.compute(currTime);
-    mV.send(tex.mHalfX,tex.mHalfY,tex.mHalfZ);
+    mV.send(tex.mHalfX,tex.mHalfY,halfZ);
         
     mF.compute(currTime);
     mF.send(tex.mHalfX,tex.mHalfY);
@@ -110,7 +112,7 @@ public class DistortedEffectQueues
     {
     GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
 
-    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfZ);
+    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfX*grid.zFactor);
     mV.sendZero();
     mF.sendZero();
 
@@ -751,7 +753,7 @@ public class DistortedEffectQueues
 /**
  * Directional, sinusoidal wave effect.
  *
- * @param wave   see {@link DistortedObject#wave(Data5D,Data3D)}
+ * @param wave   see {@link DistortedEffectQueues#wave(Data5D,Data3D)}
  * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
diff --git a/src/main/java/org/distorted/library/DistortedTexture.java b/src/main/java/org/distorted/library/DistortedTexture.java
index 28d9f08..8a3c912 100644
--- a/src/main/java/org/distorted/library/DistortedTexture.java
+++ b/src/main/java/org/distorted/library/DistortedTexture.java
@@ -34,8 +34,8 @@ public class DistortedTexture
   private static long mNextID =0;
   private static HashMap<Long,DistortedTexture> mTextures = new HashMap<>();
 
-  private int mSizeX, mSizeY, mSizeZ;   // in screen space
-  float mHalfX, mHalfY, mHalfZ;         // halves of the above
+  private int mSizeX, mSizeY;  // in screen space
+  float mHalfX, mHalfY;        // halves of the above
 
   private long mID;
   private long mBitmapID=0;
@@ -138,15 +138,14 @@ public class DistortedTexture
 /**
  * Create empty texture of given dimensions.
  */
-  public DistortedTexture(int width, int height, int depth)
+  public DistortedTexture(int width, int height)
     {
-    mSizeX= width ; mHalfX = mSizeX/2.0f;
-    mSizeY= height; mHalfY = mSizeY/2.0f;
-    mSizeZ= depth ; mHalfZ = mSizeZ/2.0f;
-
     mID = mNextID++;
     mTextures.put(mID,this);
 
+    mSizeX= width ; mHalfX = mSizeX/2.0f;
+    mSizeY= height; mHalfY = mSizeY/2.0f;
+
     mTextureDataH   = new int[1];
     mTextureDataH[0]= 0;
     mBmp            = new Bitmap[1];
@@ -174,12 +173,8 @@ public class DistortedTexture
     mID = mNextID++;
     mTextures.put(mID,this);
 
-    mSizeX = dt.mSizeX;
-    mSizeY = dt.mSizeY;
-    mSizeZ = dt.mSizeZ;
-    mHalfX = dt.mHalfX;
-    mHalfY = dt.mHalfY;
-    mHalfZ = dt.mHalfZ;
+    mSizeX= dt.mSizeX ; mHalfX = mSizeX/2.0f;
+    mSizeY= dt.mSizeY ; mHalfY = mSizeY/2.0f;
 
     if( (flags & Distorted.CLONE_BITMAP) != 0 )
       {
@@ -261,12 +256,15 @@ public class DistortedTexture
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Returns the depth of the DistortedObject.
+ * <p>
+ * Admittedly quite a strange method. Why do we need to pass a Grid to it? Because one cannot determine
+ * 'depth' of a texture when rendered based only on the texture itself, that depends on the Grid it is
+ * rendered with.
  *
  * @return depth of the Object, in pixels.
  */
-  public int getDepth()
+  public int getDepth(GridObject grid)
       {
-      return mSizeZ;
+      return grid==null ? 0 : (int)(mSizeX*grid.zFactor);
       }
-
   }
diff --git a/src/main/java/org/distorted/library/GridCubes.java b/src/main/java/org/distorted/library/GridCubes.java
index e0ebd4c..4555312 100644
--- a/src/main/java/org/distorted/library/GridCubes.java
+++ b/src/main/java/org/distorted/library/GridCubes.java
@@ -766,6 +766,7 @@ public class GridCubes extends GridObject
  */
    public GridCubes(int cols, String desc, boolean frontOnly)
       {
+      super(frontOnly ? 0.0f:1.0f/cols);
       prepareDataStructures(cols,desc,frontOnly);
       build(frontOnly);
       }
@@ -780,6 +781,7 @@ public class GridCubes extends GridObject
  */
    public GridCubes(int cols, int rows, boolean frontOnly)
       {
+      super(frontOnly ? 0.0f:1.0f/cols);
       prepareDataStructures(cols,rows,frontOnly);
       build(frontOnly);
       }
diff --git a/src/main/java/org/distorted/library/GridFlat.java b/src/main/java/org/distorted/library/GridFlat.java
index f46caf8..51a6c95 100644
--- a/src/main/java/org/distorted/library/GridFlat.java
+++ b/src/main/java/org/distorted/library/GridFlat.java
@@ -163,6 +163,7 @@ public class GridFlat extends GridObject
  */
    public GridFlat(int cols, int rows)
       {
+      super(0.0f);
       computeNumberOfVertices(cols,rows);
 
       float[] positionData= new float[POSITION_DATA_SIZE*dataLength];
diff --git a/src/main/java/org/distorted/library/GridObject.java b/src/main/java/org/distorted/library/GridObject.java
index 4f99b48..4561e62 100644
--- a/src/main/java/org/distorted/library/GridObject.java
+++ b/src/main/java/org/distorted/library/GridObject.java
@@ -34,9 +34,19 @@ public abstract class GridObject
 
    protected int dataLength;
    protected FloatBuffer mGridPositions,mGridNormals,mGridTexture;
- 
+
+   final float zFactor; // strange workaround the fact that we need to somehow store the 'depth'
+                        // of the Grid. Used in DistortedEffectQueues. See DistortedTexture.getDepth().
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-   
+
+   GridObject(float factor)
+     {
+     zFactor = factor;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
    void draw()
      { 
      GLES20.glVertexAttribPointer(Distorted.mPositionH    , POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mGridPositions);          
