Revision e54bfada
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
52 | 52 |
static final int POS_ATTRIB = 0; |
53 | 53 |
static final int NOR_ATTRIB = POS_DATA_SIZE; |
54 | 54 |
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE; |
55 |
static final int TEX_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; |
|
56 |
static final int VERT_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE + TEX_DATA_SIZE; // number of attributes of a 'normal' vertex |
|
57 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + POS_DATA_SIZE; // number of attributes of a transform feedback vertex |
|
55 |
static final int TEX_ATTRIB = 0; |
|
56 |
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply) |
|
57 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part) |
|
58 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex |
|
58 | 59 |
|
59 | 60 |
private static final int BYTES_PER_FLOAT = 4; |
60 | 61 |
|
... | ... | |
63 | 64 |
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT; |
64 | 65 |
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT; |
65 | 66 |
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT; |
66 |
private static final int VERT_SIZE = VERT_ATTRIBS*BYTES_PER_FLOAT; |
|
67 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
|
68 |
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT; |
|
67 | 69 |
|
68 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors? |
|
69 |
private InternalBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer |
|
70 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors?
|
|
71 |
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
|
|
70 | 72 |
private int mNumVertices; |
71 |
private float[] mVertAttribs; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT |
|
73 |
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ |
|
74 |
private float[] mVertAttribs2; // packed: TexS,TexT |
|
72 | 75 |
private float mInflate; |
73 | 76 |
private boolean mNeedsAdjustment; |
74 | 77 |
|
... | ... | |
113 | 116 |
mNeedsAdjustment = false; |
114 | 117 |
mComponent = new ArrayList<>(); |
115 | 118 |
|
116 |
mVBO = new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
119 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
120 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
117 | 121 |
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ); |
118 | 122 |
} |
119 | 123 |
|
... | ... | |
134 | 138 |
mComponent.add(comp); |
135 | 139 |
} |
136 | 140 |
|
137 |
mVBO = new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
141 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
142 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
138 | 143 |
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ); |
139 | 144 |
|
140 | 145 |
mNumVertices = original.mNumVertices; |
141 |
mVertAttribs = new float[mNumVertices*VERT_ATTRIBS];
|
|
142 |
System.arraycopy(original.mVertAttribs,0,mVertAttribs,0,mNumVertices*VERT_ATTRIBS);
|
|
146 |
mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
|
|
147 |
mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
|
|
143 | 148 |
|
144 |
mVBO.invalidate(); |
|
149 |
System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS); |
|
150 |
System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS); |
|
151 |
|
|
152 |
mVBO1.invalidate(); |
|
153 |
mVBO2.invalidate(); |
|
145 | 154 |
mTFO.invalidate(); |
146 | 155 |
} |
147 | 156 |
|
... | ... | |
155 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
156 | 165 |
// when a derived class is done computing its mesh, it has to call this method. |
157 | 166 |
|
158 |
void setAttribs(float[] vertexAttribs)
|
|
167 |
void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
|
|
159 | 168 |
{ |
160 |
mNumVertices = vertexAttribs.length/VERT_ATTRIBS; |
|
161 |
mVertAttribs = vertexAttribs; |
|
169 |
mNumVertices = vert1Attribs.length/VERT1_ATTRIBS; |
|
170 |
mVertAttribs1= vert1Attribs; |
|
171 |
mVertAttribs2= vert2Attribs; |
|
162 | 172 |
|
163 | 173 |
mComponent.add(new Component(mNumVertices)); |
164 | 174 |
|
165 |
mVBO.invalidate(); |
|
166 |
mTFO.invalidate();
|
|
175 |
mVBO1.invalidate();
|
|
176 |
mVBO2.invalidate();
|
|
167 | 177 |
} |
168 | 178 |
|
169 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
211 | 221 |
} |
212 | 222 |
|
213 | 223 |
// allocate new attrib array |
214 |
float[] newAttribs = new float[VERT_ATTRIBS*mNumVertices]; |
|
224 |
float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices]; |
|
225 |
float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices]; |
|
215 | 226 |
numVertices = origVertices; |
216 | 227 |
|
217 | 228 |
if( origVertices>0 ) |
218 | 229 |
{ |
219 |
System.arraycopy(mVertAttribs, 0, newAttribs, 0, VERT_ATTRIBS*numVertices); |
|
220 |
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS ); |
|
230 |
System.arraycopy(mVertAttribs1, 0, newAttribs1, 0, VERT1_ATTRIBS*numVertices); |
|
231 |
System.arraycopy(mVertAttribs2, 0, newAttribs2, 0, VERT2_ATTRIBS*numVertices); |
|
232 |
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS ); |
|
233 |
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS ); |
|
221 | 234 |
origVertices++; |
222 | 235 |
|
223 | 236 |
if( numVertices%2==1 ) |
224 | 237 |
{ |
225 |
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
238 |
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS); |
|
239 |
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS); |
|
226 | 240 |
origVertices++; |
227 | 241 |
} |
228 | 242 |
} |
... | ... | |
234 | 248 |
|
235 | 249 |
if( origVertices>0 ) |
236 | 250 |
{ |
237 |
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS ); |
|
251 |
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS ); |
|
252 |
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS ); |
|
238 | 253 |
origVertices++; |
239 | 254 |
} |
240 |
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS*numVertices); |
|
255 |
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices); |
|
256 |
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices); |
|
241 | 257 |
origVertices+=numVertices; |
242 | 258 |
|
243 | 259 |
if( i<numMeshes-1 ) |
244 | 260 |
{ |
245 |
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(numVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
261 |
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS); |
|
262 |
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS); |
|
246 | 263 |
origVertices++; |
247 | 264 |
|
248 | 265 |
if( numVertices%2==1 ) |
249 | 266 |
{ |
250 |
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(numVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
267 |
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS); |
|
268 |
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS); |
|
251 | 269 |
origVertices++; |
252 | 270 |
} |
253 | 271 |
} |
... | ... | |
258 | 276 |
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices); |
259 | 277 |
} |
260 | 278 |
|
261 |
mVertAttribs = newAttribs; |
|
279 |
mVertAttribs1 = newAttribs1; |
|
280 |
mVertAttribs2 = newAttribs2; |
|
262 | 281 |
|
263 |
mVBO.invalidate(); |
|
282 |
mVBO1.invalidate(); |
|
283 |
mVBO2.invalidate(); |
|
264 | 284 |
} |
265 | 285 |
|
266 | 286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
271 | 291 |
*/ |
272 | 292 |
public void copyTransformToVertex() |
273 | 293 |
{ |
274 |
float posX, posY, posZ, norX, norY, norZ; |
|
275 |
FloatBuffer feedback=null; |
|
276 |
|
|
277 |
ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, TRAN_SIZE*mNumVertices, |
|
278 |
GLES30.GL_MAP_READ_BIT); |
|
294 |
ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, |
|
295 |
TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT); |
|
279 | 296 |
if( buffer!=null ) |
280 | 297 |
{ |
281 |
feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
298 |
FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
299 |
feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices); |
|
300 |
mVBO1.update(mVertAttribs1); |
|
282 | 301 |
} |
283 | 302 |
else |
284 | 303 |
{ |
... | ... | |
286 | 305 |
Log.e("mesh", "failed to map tf buffer, error="+error); |
287 | 306 |
} |
288 | 307 |
|
289 |
if( feedback!=null ) |
|
290 |
{ |
|
291 |
for(int vertex=0; vertex<mNumVertices; vertex++) |
|
292 |
{ |
|
293 |
mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB ] = feedback.get(6*vertex ); |
|
294 |
mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 1 ] = feedback.get(6*vertex+1); |
|
295 |
mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 2 ] = feedback.get(6*vertex+2); |
|
296 |
mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB ] = feedback.get(6*vertex+3); |
|
297 |
mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 1 ] = feedback.get(6*vertex+4); |
|
298 |
mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 2 ] = feedback.get(6*vertex+5); |
|
299 |
} |
|
300 |
|
|
301 |
mVBO.update(mVertAttribs); |
|
302 |
} |
|
303 |
|
|
304 | 308 |
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK); |
305 | 309 |
|
306 | 310 |
int numComp = mComponent.size(); |
... | ... | |
379 | 383 |
DistortedLibrary.adjustVertices(this); |
380 | 384 |
} |
381 | 385 |
|
382 |
int index = mVBO.createImmediately(mNumVertices*VERT_SIZE, mVertAttribs); |
|
386 |
int index1 = mVBO1.createImmediately(mNumVertices*VERT1_SIZE, mVertAttribs1); |
|
387 |
int index2 = mVBO2.createImmediately(mNumVertices*VERT2_SIZE, mVertAttribs2); |
|
383 | 388 |
|
384 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index ); |
|
385 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_POS); |
|
386 |
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_NOR); |
|
387 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_INF); |
|
388 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_TEX); |
|
389 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 ); |
|
390 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS); |
|
391 |
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR); |
|
392 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF); |
|
393 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 ); |
|
394 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX); |
|
389 | 395 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
390 | 396 |
} |
391 | 397 |
|
... | ... | |
458 | 464 |
*/ |
459 | 465 |
public void markForDeletion() |
460 | 466 |
{ |
461 |
mVertAttribs = null; |
|
467 |
mVertAttribs1 = null; |
|
468 |
mVertAttribs2 = null; |
|
462 | 469 |
|
463 |
mVBO.markForDeletion(); |
|
470 |
mVBO1.markForDeletion(); |
|
471 |
mVBO2.markForDeletion(); |
|
464 | 472 |
mTFO.markForDeletion(); |
465 | 473 |
} |
466 | 474 |
|
... | ... | |
538 | 546 |
movX = newMap.get0() - ratW*oldMap.get0(); |
539 | 547 |
movY = newMap.get1() - ratH*oldMap.get1(); |
540 | 548 |
|
541 |
for( int index=vertex*VERT_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT_ATTRIBS)
|
|
549 |
for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
|
|
542 | 550 |
{ |
543 |
mVertAttribs[index ] = ratW*mVertAttribs[index ] + movX;
|
|
544 |
mVertAttribs[index+1] = ratH*mVertAttribs[index+1] + movY;
|
|
551 |
mVertAttribs2[index ] = ratW*mVertAttribs2[index ] + movX;
|
|
552 |
mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
|
|
545 | 553 |
} |
546 | 554 |
comp.setMap(newMap); |
547 | 555 |
} |
... | ... | |
550 | 558 |
vertex= comp.mEndIndex+1; |
551 | 559 |
} |
552 | 560 |
|
553 |
mVBO.invalidate(); |
|
561 |
mVBO2.invalidate();
|
|
554 | 562 |
} |
555 | 563 |
|
556 | 564 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Have VERTEX_QUATERNION, VERTEX_ROTATE and VERTEX_SHEAR modify inflate vectors.
Split Vertex attribute array into two (the one modified by preapply effects and the one not)