blob: 59e3dd9991ce7cd92bf0055f41683665828a1e73 [file] [log] [blame]
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.renderscript;
18
19import java.util.Vector;
20
21import android.util.Config;
22import android.util.Log;
23
24/**
25 * @hide
26 *
27 **/
28public class Mesh extends BaseObj {
29
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080030 public enum Primitive {
31 POINT (0),
32 LINE (1),
33 LINE_STRIP (2),
34 TRIANGLE (3),
35 TRIANGLE_STRIP (4),
36 TRIANGLE_FAN (5);
37
38 int mID;
39 Primitive(int id) {
40 mID = id;
41 }
42 }
43
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070044 Allocation[] mVertexBuffers;
45 Allocation[] mIndexBuffers;
46 Primitive[] mPrimitives;
47
48 Mesh(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070049 super(id, rs);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070050 }
51
52 public int getVertexAllocationCount() {
53 if(mVertexBuffers == null) {
54 return 0;
55 }
56 return mVertexBuffers.length;
57 }
58 public Allocation getVertexAllocation(int slot) {
59 return mVertexBuffers[slot];
60 }
61
62 public int getPrimitiveCount() {
63 if(mIndexBuffers == null) {
64 return 0;
65 }
66 return mIndexBuffers.length;
67 }
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080068 public Allocation getIndexSetAllocation(int slot) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070069 return mIndexBuffers[slot];
70 }
71 public Primitive getPrimitive(int slot) {
72 return mPrimitives[slot];
73 }
74
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070075 @Override
76 void updateFromNative() {
Jason Sams06d69de2010-11-09 17:11:40 -080077 super.updateFromNative();
78 int vtxCount = mRS.nMeshGetVertexBufferCount(getID());
79 int idxCount = mRS.nMeshGetIndexCount(getID());
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070080
81 int[] vtxIDs = new int[vtxCount];
82 int[] idxIDs = new int[idxCount];
83 int[] primitives = new int[idxCount];
84
Jason Sams06d69de2010-11-09 17:11:40 -080085 mRS.nMeshGetVertices(getID(), vtxIDs, vtxCount);
86 mRS.nMeshGetIndices(getID(), idxIDs, primitives, idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070087
88 mVertexBuffers = new Allocation[vtxCount];
89 mIndexBuffers = new Allocation[idxCount];
90 mPrimitives = new Primitive[idxCount];
91
92 for(int i = 0; i < vtxCount; i ++) {
93 if(vtxIDs[i] != 0) {
Jason Samsd4b23b52010-12-13 15:32:35 -080094 mVertexBuffers[i] = new Allocation(vtxIDs[i], mRS, null, Allocation.USAGE_SCRIPT);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070095 mVertexBuffers[i].updateFromNative();
96 }
97 }
98
99 for(int i = 0; i < idxCount; i ++) {
100 if(idxIDs[i] != 0) {
Jason Samsd4b23b52010-12-13 15:32:35 -0800101 mIndexBuffers[i] = new Allocation(idxIDs[i], mRS, null, Allocation.USAGE_SCRIPT);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700102 mIndexBuffers[i].updateFromNative();
103 }
104 mPrimitives[i] = Primitive.values()[primitives[i]];
105 }
106 }
107
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700108 public static class Builder {
109 RenderScript mRS;
Jason Samsd1952402010-12-20 12:55:28 -0800110 int mUsage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700111
112 class Entry {
113 Type t;
114 Element e;
115 int size;
116 Primitive prim;
Jason Samsd1952402010-12-20 12:55:28 -0800117 int usage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700118 }
119
120 int mVertexTypeCount;
121 Entry[] mVertexTypes;
122 Vector mIndexTypes;
123
Jason Samsd1952402010-12-20 12:55:28 -0800124 public Builder(RenderScript rs, int usage) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700125 mRS = rs;
Jason Samsd1952402010-12-20 12:55:28 -0800126 mUsage = usage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700127 mVertexTypeCount = 0;
128 mVertexTypes = new Entry[16];
129 mIndexTypes = new Vector();
130 }
131
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800132 public int getCurrentVertexTypeIndex() {
133 return mVertexTypeCount - 1;
134 }
135
136 public int getCurrentIndexSetIndex() {
137 return mIndexTypes.size() - 1;
138 }
139
140 public Builder addVertexType(Type t) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700141 if (mVertexTypeCount >= mVertexTypes.length) {
142 throw new IllegalStateException("Max vertex types exceeded.");
143 }
144
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700145 mVertexTypes[mVertexTypeCount] = new Entry();
146 mVertexTypes[mVertexTypeCount].t = t;
147 mVertexTypes[mVertexTypeCount].e = null;
148 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800149 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700150 }
151
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800152 public Builder addVertexType(Element e, int size) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700153 if (mVertexTypeCount >= mVertexTypes.length) {
154 throw new IllegalStateException("Max vertex types exceeded.");
155 }
156
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700157 mVertexTypes[mVertexTypeCount] = new Entry();
158 mVertexTypes[mVertexTypeCount].t = null;
159 mVertexTypes[mVertexTypeCount].e = e;
160 mVertexTypes[mVertexTypeCount].size = size;
161 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800162 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700163 }
164
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800165 public Builder addIndexSetType(Type t, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700166 Entry indexType = new Entry();
167 indexType.t = t;
168 indexType.e = null;
169 indexType.size = 0;
170 indexType.prim = p;
171 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800172 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700173 }
174
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800175 public Builder addIndexSetType(Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700176 Entry indexType = new Entry();
177 indexType.t = null;
178 indexType.e = null;
179 indexType.size = 0;
180 indexType.prim = p;
181 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800182 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700183 }
184
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800185 public Builder addIndexSetType(Element e, int size, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700186 Entry indexType = new Entry();
187 indexType.t = null;
188 indexType.e = e;
189 indexType.size = size;
190 indexType.prim = p;
191 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800192 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700193 }
194
195 Type newType(Element e, int size) {
196 Type.Builder tb = new Type.Builder(mRS, e);
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800197 tb.setX(size);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700198 return tb.create();
199 }
200
201 static synchronized Mesh internalCreate(RenderScript rs, Builder b) {
202
203 int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
204 Mesh newMesh = new Mesh(id, rs);
205 newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
206 newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
207 newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
208
209 for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
210 Allocation alloc = null;
211 Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
212 if (entry.t != null) {
Jason Samsd1952402010-12-20 12:55:28 -0800213 alloc = Allocation.createTyped(rs, entry.t, b.mUsage);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700214 }
215 else if(entry.e != null) {
Jason Samsd1952402010-12-20 12:55:28 -0800216 alloc = Allocation.createSized(rs, entry.e, entry.size, b.mUsage);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700217 }
218 int allocID = (alloc == null) ? 0 : alloc.getID();
219 rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
220 newMesh.mIndexBuffers[ct] = alloc;
221 newMesh.mPrimitives[ct] = entry.prim;
222 }
223
224 for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
225 Allocation alloc = null;
226 Entry entry = b.mVertexTypes[ct];
227 if (entry.t != null) {
Jason Samsd1952402010-12-20 12:55:28 -0800228 alloc = Allocation.createTyped(rs, entry.t, b.mUsage);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700229 } else if(entry.e != null) {
Jason Samsd1952402010-12-20 12:55:28 -0800230 alloc = Allocation.createSized(rs, entry.e, entry.size, b.mUsage);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700231 }
232 rs.nMeshBindVertex(id, alloc.getID(), ct);
233 newMesh.mVertexBuffers[ct] = alloc;
234 }
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800235 rs.nMeshInitVertexAttribs(id);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700236
237 return newMesh;
238 }
239
240 public Mesh create() {
241 mRS.validate();
242 Mesh sm = internalCreate(mRS, this);
243 return sm;
244 }
245 }
246
247 public static class AllocationBuilder {
248 RenderScript mRS;
249
250 class Entry {
251 Allocation a;
252 Primitive prim;
253 }
254
255 int mVertexTypeCount;
256 Entry[] mVertexTypes;
257
258 Vector mIndexTypes;
259
260 public AllocationBuilder(RenderScript rs) {
261 mRS = rs;
262 mVertexTypeCount = 0;
263 mVertexTypes = new Entry[16];
264 mIndexTypes = new Vector();
265 }
266
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800267 public int getCurrentVertexTypeIndex() {
268 return mVertexTypeCount - 1;
269 }
270
271 public int getCurrentIndexSetIndex() {
272 return mIndexTypes.size() - 1;
273 }
274
275 public AllocationBuilder addVertexAllocation(Allocation a) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700276 if (mVertexTypeCount >= mVertexTypes.length) {
277 throw new IllegalStateException("Max vertex types exceeded.");
278 }
279
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700280 mVertexTypes[mVertexTypeCount] = new Entry();
281 mVertexTypes[mVertexTypeCount].a = a;
282 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800283 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700284 }
285
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800286 public AllocationBuilder addIndexSetAllocation(Allocation a, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700287 Entry indexType = new Entry();
288 indexType.a = a;
289 indexType.prim = p;
290 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800291 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700292 }
293
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800294 public AllocationBuilder addIndexSetType(Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700295 Entry indexType = new Entry();
296 indexType.a = null;
297 indexType.prim = p;
298 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800299 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700300 }
301
302 static synchronized Mesh internalCreate(RenderScript rs, AllocationBuilder b) {
303
304 int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
305 Mesh newMesh = new Mesh(id, rs);
306 newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
307 newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
308 newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
309
310 for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
311 Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
312 int allocID = (entry.a == null) ? 0 : entry.a.getID();
313 rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
314 newMesh.mIndexBuffers[ct] = entry.a;
315 newMesh.mPrimitives[ct] = entry.prim;
316 }
317
318 for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
319 Entry entry = b.mVertexTypes[ct];
Jason Sams06d69de2010-11-09 17:11:40 -0800320 rs.nMeshBindVertex(id, entry.a.getID(), ct);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700321 newMesh.mVertexBuffers[ct] = entry.a;
322 }
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800323 rs.nMeshInitVertexAttribs(id);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700324
325 return newMesh;
326 }
327
328 public Mesh create() {
329 mRS.validate();
330 Mesh sm = internalCreate(mRS, this);
331 return sm;
332 }
333 }
334
335
336 public static class TriangleMeshBuilder {
337 float mVtxData[];
338 int mVtxCount;
339 short mIndexData[];
340 int mIndexCount;
341 RenderScript mRS;
342 Element mElement;
343
344 float mNX = 0;
345 float mNY = 0;
346 float mNZ = -1;
347 float mS0 = 0;
348 float mT0 = 0;
349 float mR = 1;
350 float mG = 1;
351 float mB = 1;
352 float mA = 1;
353
354 int mVtxSize;
355 int mFlags;
356
357 public static final int COLOR = 0x0001;
358 public static final int NORMAL = 0x0002;
359 public static final int TEXTURE_0 = 0x0100;
360
361 public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
362 mRS = rs;
363 mVtxCount = 0;
364 mIndexCount = 0;
365 mVtxData = new float[128];
366 mIndexData = new short[128];
367 mVtxSize = vtxSize;
368 mFlags = flags;
369
370 if (vtxSize < 2 || vtxSize > 3) {
371 throw new IllegalArgumentException("Vertex size out of range.");
372 }
373 }
374
375 private void makeSpace(int count) {
376 if ((mVtxCount + count) >= mVtxData.length) {
377 float t[] = new float[mVtxData.length * 2];
378 System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
379 mVtxData = t;
380 }
381 }
382
383 private void latch() {
384 if ((mFlags & COLOR) != 0) {
385 makeSpace(4);
386 mVtxData[mVtxCount++] = mR;
387 mVtxData[mVtxCount++] = mG;
388 mVtxData[mVtxCount++] = mB;
389 mVtxData[mVtxCount++] = mA;
390 }
391 if ((mFlags & TEXTURE_0) != 0) {
392 makeSpace(2);
393 mVtxData[mVtxCount++] = mS0;
394 mVtxData[mVtxCount++] = mT0;
395 }
396 if ((mFlags & NORMAL) != 0) {
397 makeSpace(3);
398 mVtxData[mVtxCount++] = mNX;
399 mVtxData[mVtxCount++] = mNY;
400 mVtxData[mVtxCount++] = mNZ;
401 }
402 }
403
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800404 public TriangleMeshBuilder addVertex(float x, float y) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700405 if (mVtxSize != 2) {
406 throw new IllegalStateException("add mistmatch with declared components.");
407 }
408 makeSpace(2);
409 mVtxData[mVtxCount++] = x;
410 mVtxData[mVtxCount++] = y;
411 latch();
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800412 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700413 }
414
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800415 public TriangleMeshBuilder addVertex(float x, float y, float z) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700416 if (mVtxSize != 3) {
417 throw new IllegalStateException("add mistmatch with declared components.");
418 }
419 makeSpace(3);
420 mVtxData[mVtxCount++] = x;
421 mVtxData[mVtxCount++] = y;
422 mVtxData[mVtxCount++] = z;
423 latch();
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800424 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700425 }
426
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800427 public TriangleMeshBuilder setTexture(float s, float t) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700428 if ((mFlags & TEXTURE_0) == 0) {
429 throw new IllegalStateException("add mistmatch with declared components.");
430 }
431 mS0 = s;
432 mT0 = t;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800433 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700434 }
435
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800436 public TriangleMeshBuilder setNormal(float x, float y, float z) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700437 if ((mFlags & NORMAL) == 0) {
438 throw new IllegalStateException("add mistmatch with declared components.");
439 }
440 mNX = x;
441 mNY = y;
442 mNZ = z;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800443 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700444 }
445
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800446 public TriangleMeshBuilder setColor(float r, float g, float b, float a) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700447 if ((mFlags & COLOR) == 0) {
448 throw new IllegalStateException("add mistmatch with declared components.");
449 }
450 mR = r;
451 mG = g;
452 mB = b;
453 mA = a;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800454 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700455 }
456
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800457 public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700458 if((idx1 >= mVtxCount) || (idx1 < 0) ||
459 (idx2 >= mVtxCount) || (idx2 < 0) ||
460 (idx3 >= mVtxCount) || (idx3 < 0)) {
461 throw new IllegalStateException("Index provided greater than vertex count.");
462 }
463 if ((mIndexCount + 3) >= mIndexData.length) {
464 short t[] = new short[mIndexData.length * 2];
465 System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
466 mIndexData = t;
467 }
468 mIndexData[mIndexCount++] = (short)idx1;
469 mIndexData[mIndexCount++] = (short)idx2;
470 mIndexData[mIndexCount++] = (short)idx3;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800471 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700472 }
473
474 public Mesh create(boolean uploadToBufferObject) {
475 Element.Builder b = new Element.Builder(mRS);
476 int floatCount = mVtxSize;
477 b.add(Element.createVector(mRS,
478 Element.DataType.FLOAT_32,
479 mVtxSize), "position");
480 if ((mFlags & COLOR) != 0) {
481 floatCount += 4;
482 b.add(Element.F32_4(mRS), "color");
483 }
484 if ((mFlags & TEXTURE_0) != 0) {
485 floatCount += 2;
486 b.add(Element.F32_2(mRS), "texture0");
487 }
488 if ((mFlags & NORMAL) != 0) {
489 floatCount += 3;
490 b.add(Element.F32_3(mRS), "normal");
491 }
492 mElement = b.create();
493
Jason Samsd1952402010-12-20 12:55:28 -0800494 int usage = Allocation.USAGE_SCRIPT;
495 if (uploadToBufferObject) {
496 usage |= Allocation.USAGE_GRAPHICS_VERTEX;
497 }
498
499 Builder smb = new Builder(mRS, usage);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700500 smb.addVertexType(mElement, mVtxCount / floatCount);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800501 smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700502
503 Mesh sm = smb.create();
504
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800505 sm.getVertexAllocation(0).copyFrom(mVtxData);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700506 if(uploadToBufferObject) {
Jason Samsd1952402010-12-20 12:55:28 -0800507 if (uploadToBufferObject) {
508 sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
509 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700510 }
511
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800512 sm.getIndexSetAllocation(0).copyFrom(mIndexData);
Jason Samsd1952402010-12-20 12:55:28 -0800513 if (uploadToBufferObject) {
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800514 sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
Jason Samsd1952402010-12-20 12:55:28 -0800515 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700516
517 return sm;
518 }
519 }
520}
521