Project

General

Profile

« Previous | Next » 

Revision 4f81e0c8

Added by Leszek Koltunski over 4 years ago

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.

View differences:

src/main/java/org/distorted/library/mesh/MeshBase.java
80 80
   private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ
81 81
   private float[] mVertAttribs2;             // packed: TexS,TexT
82 82
   private float mInflate;
83
   private boolean mNeedsAdjustment;
83
   private boolean[] mNeedsAdjustment;
84 84

  
85 85
   private static class Component
86 86
     {
......
118 118

  
119 119
   MeshBase()
120 120
     {
121
     mShowNormals     = false;
122
     mInflate         = 0.0f;
123
     mNeedsAdjustment = false;
124
     mComponent       = new ArrayList<>();
121
     mShowNormals= false;
122
     mInflate    = 0.0f;
123
     mComponent  = new ArrayList<>();
124

  
125
     mNeedsAdjustment = new boolean[1];
126
     mNeedsAdjustment[0] = false;
125 127

  
126 128
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
127 129
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
......
131 133
///////////////////////////////////////////////////////////////////////////////////////////////////
132 134
// copy constructor
133 135

  
134
   MeshBase(MeshBase original)
136
   MeshBase(MeshBase original, boolean deep)
135 137
     {
136 138
     mShowNormals     = original.mShowNormals;
137 139
     mInflate         = original.mInflate;
138
     mNeedsAdjustment = original.mNeedsAdjustment;
140
     mNumVertices     = original.mNumVertices;
139 141

  
140 142
     int size = original.mComponent.size();
141 143
     mComponent = new ArrayList<>();
......
146 148
       mComponent.add(comp);
147 149
       }
148 150

  
149
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
150
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
151
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
151
     if( deep )
152
       {
153
       mNeedsAdjustment = new boolean[1];
154
       mNeedsAdjustment[0] = original.mNeedsAdjustment[0];
152 155

  
153
     mNumVertices = original.mNumVertices;
154
     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
155
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
156
       mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
157
       mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
158
       System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
159
       mVBO1.invalidate();
160
       }
161
     else
162
       {
163
       mNeedsAdjustment = original.mNeedsAdjustment;
164
       mVBO1            = original.mVBO1;
165
       mVertAttribs1    = original.mVertAttribs1;
166
       }
156 167

  
157
     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
168
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
169
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
158 170
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
159

  
160
     mVBO1.invalidate();
161 171
     mVBO2.invalidate();
172

  
173
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
162 174
     mTFO.invalidate();
163 175
     }
164 176

  
......
385 397
 */
386 398
   public void bindVertexAttribs(DistortedProgram program)
387 399
     {
388
     if( mNeedsAdjustment )
400
     if( mNeedsAdjustment[0] )
389 401
       {
390
       mNeedsAdjustment = false;
402
       mNeedsAdjustment[0] = false;
391 403
       DistortedLibrary.adjustVertices(this);
392 404
       }
393 405

  
......
502 514
       mComponent.get(i).mQueue.add(effect);
503 515
       }
504 516

  
505
     mNeedsAdjustment = true;
517
     mNeedsAdjustment[0] = true;
506 518
     }
507 519

  
508 520
///////////////////////////////////////////////////////////////////////////////////////////////////
......
615 627

  
616 628
///////////////////////////////////////////////////////////////////////////////////////////////////
617 629
/**
618
 * Deep copy
630
 * Copy the Mesh.
631
 *
632
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
633
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
634
 *             coordinates and effect assocciations, is always deep copied)
619 635
 */
620
   public abstract MeshBase deepCopy();
636
   public abstract MeshBase copy(boolean deep);
621 637
   }
src/main/java/org/distorted/library/mesh/MeshCubes.java
935 935

  
936 936
///////////////////////////////////////////////////////////////////////////////////////////////////
937 937
/**
938
 * deep copy.
938
 * Copy constructor.
939 939
 */
940
 public MeshCubes(MeshCubes mesh)
940
 public MeshCubes(MeshCubes mesh, boolean deep)
941 941
   {
942
   super(mesh);
942
   super(mesh,deep);
943 943
   }
944 944

  
945 945
///////////////////////////////////////////////////////////////////////////////////////////////////
946 946
/**
947
 * deep copy.
947
 * Copy the Mesh.
948
 *
949
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
950
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
951
 *             coordinates and effect assocciations, is always deep copied).
948 952
 */
949
 public MeshCubes deepCopy()
953
 public MeshCubes copy(boolean deep)
950 954
   {
951
   return new MeshCubes(this);
955
   return new MeshCubes(this,deep);
952 956
   }
953 957
 }
src/main/java/org/distorted/library/mesh/MeshJoined.java
37 37

  
38 38
///////////////////////////////////////////////////////////////////////////////////////////////////
39 39
/**
40
 * deep copy.
40
 * Copy constructor.
41 41
 */
42
  public MeshJoined(MeshJoined mesh)
42
  public MeshJoined(MeshJoined mesh, boolean deep)
43 43
   {
44
   super(mesh);
44
   super(mesh,deep);
45 45
   }
46 46

  
47 47
///////////////////////////////////////////////////////////////////////////////////////////////////
48 48
/**
49
 * deep copy.
49
 * Copy the Mesh.
50
 *
51
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
52
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
53
 *             coordinates and effect assocciations, is always deep copied)
50 54
 */
51
  public MeshJoined deepCopy()
55
  public MeshJoined copy(boolean deep)
52 56
   {
53
   return new MeshJoined(this);
57
   return new MeshJoined(this,deep);
54 58
   }
55 59

  
56 60
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/mesh/MeshQuad.java
72 72

  
73 73
///////////////////////////////////////////////////////////////////////////////////////////////////
74 74
/**
75
 * deep copy.
75
 * Copy constructor.
76 76
 */
77
  public MeshQuad(MeshQuad mesh)
77
  public MeshQuad(MeshQuad mesh, boolean deep)
78 78
    {
79
    super(mesh);
79
    super(mesh,deep);
80 80
    }
81 81

  
82 82
///////////////////////////////////////////////////////////////////////////////////////////////////
83 83
/**
84
 * deep copy.
84
 * Copy the Mesh.
85
 *
86
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
87
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
88
 *             coordinates and effect assocciations, is always deep copied)
85 89
 */
86
  public MeshQuad deepCopy()
90
  public MeshQuad copy(boolean deep)
87 91
    {
88
    return new MeshQuad(this);
92
    return new MeshQuad(this,deep);
89 93
    }
90 94
  }
src/main/java/org/distorted/library/mesh/MeshRectangles.java
176 176

  
177 177
///////////////////////////////////////////////////////////////////////////////////////////////////
178 178
/**
179
 * deep copy.
179
 * Copy constructor.
180 180
 */
181
  public MeshRectangles(MeshRectangles mesh)
181
  public MeshRectangles(MeshRectangles mesh, boolean deep)
182 182
    {
183
    super(mesh);
183
    super(mesh,deep);
184 184
    }
185 185

  
186 186
///////////////////////////////////////////////////////////////////////////////////////////////////
187 187
/**
188
 * deep copy.
188
 * Copy the Mesh.
189
 *
190
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
191
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
192
 *             coordinates and effect assocciations, is always deep copied)
189 193
 */
190
  public MeshRectangles deepCopy()
194
  public MeshRectangles copy(boolean deep)
191 195
    {
192
    return new MeshRectangles(this);
196
    return new MeshRectangles(this,deep);
193 197
    }
194 198
 }
src/main/java/org/distorted/library/mesh/MeshSphere.java
274 274

  
275 275
///////////////////////////////////////////////////////////////////////////////////////////////////
276 276
/**
277
 * deep copy.
277
 * Copy cconstructor.
278 278
 */
279
  public MeshSphere(MeshSphere mesh)
279
  public MeshSphere(MeshSphere mesh, boolean deep)
280 280
    {
281
    super(mesh);
281
    super(mesh,deep);
282 282
    }
283 283

  
284 284
///////////////////////////////////////////////////////////////////////////////////////////////////
285 285
/**
286
 * deep copy.
286
 * Copy the Mesh.
287
 *
288
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
289
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
290
 *             coordinates and effect assocciations, is always deep copied)
287 291
 */
288
  public MeshSphere deepCopy()
292
  public MeshSphere copy(boolean deep)
289 293
    {
290
    return new MeshSphere(this);
294
    return new MeshSphere(this,deep);
291 295
    }
292 296
  }
src/main/java/org/distorted/library/mesh/MeshTriangles.java
125 125

  
126 126
///////////////////////////////////////////////////////////////////////////////////////////////////
127 127
/**
128
 * deep copy.
128
 * Copy constructor.
129 129
 */
130
  public MeshTriangles(MeshTriangles mesh)
130
  public MeshTriangles(MeshTriangles mesh, boolean deep)
131 131
    {
132
    super(mesh);
132
    super(mesh,deep);
133 133
    }
134 134

  
135 135
///////////////////////////////////////////////////////////////////////////////////////////////////
136 136
/**
137
 * deep copy.
137
 * Copy the Mesh.
138
 *
139
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
140
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
141
 *             coordinates and effect assocciations, is always deep copied)
138 142
 */
139
  public MeshTriangles deepCopy()
143
  public MeshTriangles copy(boolean deep)
140 144
    {
141
    return new MeshTriangles(this);
145
    return new MeshTriangles(this,deep);
142 146
    }
143 147
  }

Also available in: Unified diff