commit 4f81e0c8624d102236d1f405fd7b2b3bb0e2ba60
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun May 24 22:03:55 2020 +0100

    In library: allow a mixture of a deep and shallow copy of a Mesh ( mVertAttribs1 might be copied deeply or shallowly, mVertAttribs2 are always copied deeeply).
    Port RubikCube to the new library.

diff --git a/src/main/java/org/distorted/library/mesh/MeshBase.java b/src/main/java/org/distorted/library/mesh/MeshBase.java
index 882afb8..4c9ecb8 100644
--- a/src/main/java/org/distorted/library/mesh/MeshBase.java
+++ b/src/main/java/org/distorted/library/mesh/MeshBase.java
@@ -80,7 +80,7 @@ public abstract class MeshBase
    private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ
    private float[] mVertAttribs2;             // packed: TexS,TexT
    private float mInflate;
-   private boolean mNeedsAdjustment;
+   private boolean[] mNeedsAdjustment;
 
    private static class Component
      {
@@ -118,10 +118,12 @@ public abstract class MeshBase
 
    MeshBase()
      {
-     mShowNormals     = false;
-     mInflate         = 0.0f;
-     mNeedsAdjustment = false;
-     mComponent       = new ArrayList<>();
+     mShowNormals= false;
+     mInflate    = 0.0f;
+     mComponent  = new ArrayList<>();
+
+     mNeedsAdjustment = new boolean[1];
+     mNeedsAdjustment[0] = false;
 
      mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
      mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
@@ -131,11 +133,11 @@ public abstract class MeshBase
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // copy constructor
 
-   MeshBase(MeshBase original)
+   MeshBase(MeshBase original, boolean deep)
      {
      mShowNormals     = original.mShowNormals;
      mInflate         = original.mInflate;
-     mNeedsAdjustment = original.mNeedsAdjustment;
+     mNumVertices     = original.mNumVertices;
 
      int size = original.mComponent.size();
      mComponent = new ArrayList<>();
@@ -146,19 +148,29 @@ public abstract class MeshBase
        mComponent.add(comp);
        }
 
-     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
-     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
-     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
+     if( deep )
+       {
+       mNeedsAdjustment = new boolean[1];
+       mNeedsAdjustment[0] = original.mNeedsAdjustment[0];
 
-     mNumVertices = original.mNumVertices;
-     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
-     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
+       mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
+       mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
+       System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
+       mVBO1.invalidate();
+       }
+     else
+       {
+       mNeedsAdjustment = original.mNeedsAdjustment;
+       mVBO1            = original.mVBO1;
+       mVertAttribs1    = original.mVertAttribs1;
+       }
 
-     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
+     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
+     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
      System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
-
-     mVBO1.invalidate();
      mVBO2.invalidate();
+
+     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
      mTFO.invalidate();
      }
 
@@ -385,9 +397,9 @@ public abstract class MeshBase
  */
    public void bindVertexAttribs(DistortedProgram program)
      {
-     if( mNeedsAdjustment )
+     if( mNeedsAdjustment[0] )
        {
-       mNeedsAdjustment = false;
+       mNeedsAdjustment[0] = false;
        DistortedLibrary.adjustVertices(this);
        }
 
@@ -502,7 +514,7 @@ public abstract class MeshBase
        mComponent.get(i).mQueue.add(effect);
        }
 
-     mNeedsAdjustment = true;
+     mNeedsAdjustment[0] = true;
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -615,7 +627,11 @@ public abstract class MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Deep copy
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied)
  */
-   public abstract MeshBase deepCopy();
+   public abstract MeshBase copy(boolean deep);
    }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/mesh/MeshCubes.java b/src/main/java/org/distorted/library/mesh/MeshCubes.java
index f0d9fd8..0915b09 100644
--- a/src/main/java/org/distorted/library/mesh/MeshCubes.java
+++ b/src/main/java/org/distorted/library/mesh/MeshCubes.java
@@ -935,19 +935,23 @@ public class MeshCubes extends MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy constructor.
  */
- public MeshCubes(MeshCubes mesh)
+ public MeshCubes(MeshCubes mesh, boolean deep)
    {
-   super(mesh);
+   super(mesh,deep);
    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied).
  */
- public MeshCubes deepCopy()
+ public MeshCubes copy(boolean deep)
    {
-   return new MeshCubes(this);
+   return new MeshCubes(this,deep);
    }
  }
diff --git a/src/main/java/org/distorted/library/mesh/MeshJoined.java b/src/main/java/org/distorted/library/mesh/MeshJoined.java
index affe71a..922f64a 100644
--- a/src/main/java/org/distorted/library/mesh/MeshJoined.java
+++ b/src/main/java/org/distorted/library/mesh/MeshJoined.java
@@ -37,20 +37,24 @@ public class MeshJoined extends MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy constructor.
  */
-  public MeshJoined(MeshJoined mesh)
+  public MeshJoined(MeshJoined mesh, boolean deep)
    {
-   super(mesh);
+   super(mesh,deep);
    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied)
  */
-  public MeshJoined deepCopy()
+  public MeshJoined copy(boolean deep)
    {
-   return new MeshJoined(this);
+   return new MeshJoined(this,deep);
    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/mesh/MeshQuad.java b/src/main/java/org/distorted/library/mesh/MeshQuad.java
index 35f96a8..efefdf4 100644
--- a/src/main/java/org/distorted/library/mesh/MeshQuad.java
+++ b/src/main/java/org/distorted/library/mesh/MeshQuad.java
@@ -72,19 +72,23 @@ public class MeshQuad extends MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy constructor.
  */
-  public MeshQuad(MeshQuad mesh)
+  public MeshQuad(MeshQuad mesh, boolean deep)
     {
-    super(mesh);
+    super(mesh,deep);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied)
  */
-  public MeshQuad deepCopy()
+  public MeshQuad copy(boolean deep)
     {
-    return new MeshQuad(this);
+    return new MeshQuad(this,deep);
     }
   }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/mesh/MeshRectangles.java b/src/main/java/org/distorted/library/mesh/MeshRectangles.java
index 9c0acbe..ae33550 100644
--- a/src/main/java/org/distorted/library/mesh/MeshRectangles.java
+++ b/src/main/java/org/distorted/library/mesh/MeshRectangles.java
@@ -176,19 +176,23 @@ public class MeshRectangles extends MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy constructor.
  */
-  public MeshRectangles(MeshRectangles mesh)
+  public MeshRectangles(MeshRectangles mesh, boolean deep)
     {
-    super(mesh);
+    super(mesh,deep);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied)
  */
-  public MeshRectangles deepCopy()
+  public MeshRectangles copy(boolean deep)
     {
-    return new MeshRectangles(this);
+    return new MeshRectangles(this,deep);
     }
  }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/mesh/MeshSphere.java b/src/main/java/org/distorted/library/mesh/MeshSphere.java
index 9b4c1ee..57d3b0b 100644
--- a/src/main/java/org/distorted/library/mesh/MeshSphere.java
+++ b/src/main/java/org/distorted/library/mesh/MeshSphere.java
@@ -274,19 +274,23 @@ public class MeshSphere extends MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy cconstructor.
  */
-  public MeshSphere(MeshSphere mesh)
+  public MeshSphere(MeshSphere mesh, boolean deep)
     {
-    super(mesh);
+    super(mesh,deep);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied)
  */
-  public MeshSphere deepCopy()
+  public MeshSphere copy(boolean deep)
     {
-    return new MeshSphere(this);
+    return new MeshSphere(this,deep);
     }
   }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/mesh/MeshTriangles.java b/src/main/java/org/distorted/library/mesh/MeshTriangles.java
index 09823ac..76e8d8e 100644
--- a/src/main/java/org/distorted/library/mesh/MeshTriangles.java
+++ b/src/main/java/org/distorted/library/mesh/MeshTriangles.java
@@ -125,19 +125,23 @@ public class MeshTriangles extends MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy constructor.
  */
-  public MeshTriangles(MeshTriangles mesh)
+  public MeshTriangles(MeshTriangles mesh, boolean deep)
     {
-    super(mesh);
+    super(mesh,deep);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * deep copy.
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect assocciations, is always deep copied)
  */
-  public MeshTriangles deepCopy()
+  public MeshTriangles copy(boolean deep)
     {
-    return new MeshTriangles(this);
+    return new MeshTriangles(this,deep);
     }
   }
