Project

General

Profile

« Previous | Next » 

Revision 4f81e0c8

Added by Leszek Koltunski almost 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
   }

Also available in: Unified diff