blob: 1a4d1fd5afbb1b4732a9c559f61030b6f415906f [file] [log] [blame]
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001/*
Jason Samse619de62012-05-08 18:40:58 -07002 * Copyright (C) 2008-2012 The Android Open Source Project
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07003 *
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
Artur Satayev2ebb31c2020-01-08 12:24:36 +000019import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwood8e742f92020-10-27 11:47:29 +000020import android.os.Build;
Artur Satayev2ebb31c2020-01-08 12:24:36 +000021
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070022import java.util.Vector;
23
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070024/**
Tim Murraya9084222013-04-05 22:06:43 +000025 * @hide
Jason Samsd4ca9912012-05-08 19:02:07 -070026 * @deprecated in API 16
Robert Ly11518ac2011-02-09 13:57:06 -080027 * <p>This class is a container for geometric data displayed with
Tim Murrayc11e25c2013-04-09 11:01:01 -070028 * RenderScript. Internally, a mesh is a collection of allocations that
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080029 * represent vertex data (positions, normals, texture
Robert Ly11518ac2011-02-09 13:57:06 -080030 * coordinates) and index data such as triangles and lines. </p>
31 * <p>
32 * Vertex data could either be interleaved within one
33 * allocation that is provided separately, as multiple allocation
34 * objects, or done as a combination of both. When a
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080035 * vertex channel name matches an input in the vertex program,
Tim Murrayc11e25c2013-04-09 11:01:01 -070036 * RenderScript automatically connects the two together.
Robert Ly11518ac2011-02-09 13:57:06 -080037 * </p>
38 * <p>
39 * Parts of the mesh can be rendered with either explicit
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080040 * index sets or primitive types.
Robert Ly11518ac2011-02-09 13:57:06 -080041 * </p>
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070042 **/
43public class Mesh extends BaseObj {
44
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070045 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070046 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080047 * Describes the way mesh vertex data is interpreted when rendering
48 *
49 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080050 public enum Primitive {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070051 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070052 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080053 * Vertex data will be rendered as a series of points
54 */
Mathew Inwood15324472018-08-06 11:18:49 +010055 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080056 POINT (0),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070057 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070058 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080059 * Vertex pairs will be rendered as lines
60 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080061 LINE (1),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070062 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070063 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080064 * Vertex data will be rendered as a connected line strip
65 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080066 LINE_STRIP (2),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070067 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070068 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080069 * Vertices will be rendered as individual triangles
70 */
Mathew Inwood15324472018-08-06 11:18:49 +010071 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080072 TRIANGLE (3),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070073 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070074 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080075 * Vertices will be rendered as a connected triangle strip
76 * defined by the first three vertices with each additional
77 * triangle defined by a new vertex
78 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080079 TRIANGLE_STRIP (4),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070080 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070081 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080082 * Vertices will be rendered as a sequence of triangles that all
83 * share first vertex as the origin
84 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080085 TRIANGLE_FAN (5);
86
87 int mID;
88 Primitive(int id) {
89 mID = id;
90 }
91 }
92
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070093 Allocation[] mVertexBuffers;
94 Allocation[] mIndexBuffers;
95 Primitive[] mPrimitives;
96
Tim Murray460a0492013-11-19 12:45:54 -080097 Mesh(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070098 super(id, rs);
Yang Nieb4dd082016-03-24 09:40:32 -070099 guard.open("destroy");
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700100 }
101
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700102 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700103 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800104 * @return number of allocations containing vertex data
105 *
106 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700107 public int getVertexAllocationCount() {
108 if(mVertexBuffers == null) {
109 return 0;
110 }
111 return mVertexBuffers.length;
112 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700113 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700114 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800115 * @param slot index in the list of allocations to return
116 * @return vertex data allocation at the given index
117 *
118 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100119 @UnsupportedAppUsage
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700120 public Allocation getVertexAllocation(int slot) {
121 return mVertexBuffers[slot];
122 }
123
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700124 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700125 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800126 * @return number of primitives or index sets in the mesh
127 *
128 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700129 public int getPrimitiveCount() {
130 if(mIndexBuffers == null) {
131 return 0;
132 }
133 return mIndexBuffers.length;
134 }
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800135
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700136 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700137 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800138 * @param slot locaton within the list of index set allocation
139 * @return allocation containing primtive index data or null if
140 * the index data is not specified explicitly
141 *
142 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800143 public Allocation getIndexSetAllocation(int slot) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700144 return mIndexBuffers[slot];
145 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700146 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700147 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800148 * @param slot locaiton within the list of index set primitives
149 * @return index set primitive type
150 *
151 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700152 public Primitive getPrimitive(int slot) {
153 return mPrimitives[slot];
154 }
155
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700156 @Override
157 void updateFromNative() {
Jason Sams06d69de2010-11-09 17:11:40 -0800158 super.updateFromNative();
Jason Samse07694b2012-04-03 15:36:36 -0700159 int vtxCount = mRS.nMeshGetVertexBufferCount(getID(mRS));
160 int idxCount = mRS.nMeshGetIndexCount(getID(mRS));
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700161
Ashok Bhat98071552014-02-12 09:54:43 +0000162 long[] vtxIDs = new long[vtxCount];
163 long[] idxIDs = new long[idxCount];
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700164 int[] primitives = new int[idxCount];
165
Jason Samse07694b2012-04-03 15:36:36 -0700166 mRS.nMeshGetVertices(getID(mRS), vtxIDs, vtxCount);
167 mRS.nMeshGetIndices(getID(mRS), idxIDs, primitives, idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700168
169 mVertexBuffers = new Allocation[vtxCount];
170 mIndexBuffers = new Allocation[idxCount];
171 mPrimitives = new Primitive[idxCount];
172
173 for(int i = 0; i < vtxCount; i ++) {
174 if(vtxIDs[i] != 0) {
Jason Samsd4b23b52010-12-13 15:32:35 -0800175 mVertexBuffers[i] = new Allocation(vtxIDs[i], mRS, null, Allocation.USAGE_SCRIPT);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700176 mVertexBuffers[i].updateFromNative();
177 }
178 }
179
180 for(int i = 0; i < idxCount; i ++) {
181 if(idxIDs[i] != 0) {
Jason Samsd4b23b52010-12-13 15:32:35 -0800182 mIndexBuffers[i] = new Allocation(idxIDs[i], mRS, null, Allocation.USAGE_SCRIPT);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700183 mIndexBuffers[i].updateFromNative();
184 }
185 mPrimitives[i] = Primitive.values()[primitives[i]];
186 }
187 }
188
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700189 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700190 * @deprecated in API 16
Robert Ly11518ac2011-02-09 13:57:06 -0800191 * Mesh builder object. It starts empty and requires you to
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800192 * add the types necessary to create vertex and index
Robert Ly11518ac2011-02-09 13:57:06 -0800193 * allocations.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800194 *
195 */
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700196 public static class Builder {
197 RenderScript mRS;
Jason Samsd1952402010-12-20 12:55:28 -0800198 int mUsage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700199
200 class Entry {
201 Type t;
202 Element e;
203 int size;
204 Primitive prim;
Jason Samsd1952402010-12-20 12:55:28 -0800205 int usage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700206 }
207
208 int mVertexTypeCount;
209 Entry[] mVertexTypes;
210 Vector mIndexTypes;
211
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700212 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700213 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800214 * Creates builder object
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800215 * @param rs Context to which the mesh will belong.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800216 * @param usage specifies how the mesh allocations are to be
217 * handled, whether they need to be uploaded to a
218 * buffer on the gpu, maintain a cpu copy, etc
219 */
Jason Samsd1952402010-12-20 12:55:28 -0800220 public Builder(RenderScript rs, int usage) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700221 mRS = rs;
Jason Samsd1952402010-12-20 12:55:28 -0800222 mUsage = usage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700223 mVertexTypeCount = 0;
224 mVertexTypes = new Entry[16];
225 mIndexTypes = new Vector();
226 }
227
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700228 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700229 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800230 * @return internal index of the last vertex buffer type added to
231 * builder
232 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800233 public int getCurrentVertexTypeIndex() {
234 return mVertexTypeCount - 1;
235 }
236
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700237 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700238 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800239 * @return internal index of the last index set added to the
240 * builder
241 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800242 public int getCurrentIndexSetIndex() {
243 return mIndexTypes.size() - 1;
244 }
245
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700246 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700247 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800248 * Adds a vertex data type to the builder object
249 *
Stephen Hinesb11e3d22011-01-11 19:30:58 -0800250 * @param t type of the vertex data allocation to be created
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800251 *
252 * @return this
253 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800254 public Builder addVertexType(Type t) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700255 if (mVertexTypeCount >= mVertexTypes.length) {
256 throw new IllegalStateException("Max vertex types exceeded.");
257 }
258
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700259 mVertexTypes[mVertexTypeCount] = new Entry();
260 mVertexTypes[mVertexTypeCount].t = t;
261 mVertexTypes[mVertexTypeCount].e = null;
262 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800263 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700264 }
265
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700266 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700267 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800268 * Adds a vertex data type to the builder object
269 *
270 * @param e element describing the vertex data layout
271 * @param size number of elements in the buffer
272 *
273 * @return this
274 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800275 public Builder addVertexType(Element e, int size) 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].t = null;
282 mVertexTypes[mVertexTypeCount].e = e;
283 mVertexTypes[mVertexTypeCount].size = size;
284 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800285 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700286 }
287
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700288 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700289 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800290 * Adds an index set data type to the builder object
291 *
292 * @param t type of the index set data, could be null
293 * @param p primitive type
294 *
295 * @return this
296 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800297 public Builder addIndexSetType(Type t, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700298 Entry indexType = new Entry();
299 indexType.t = t;
300 indexType.e = null;
301 indexType.size = 0;
302 indexType.prim = p;
303 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800304 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700305 }
306
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700307 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700308 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800309 * Adds an index set primitive type to the builder object
310 *
311 * @param p primitive type
312 *
313 * @return this
314 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800315 public Builder addIndexSetType(Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700316 Entry indexType = new Entry();
317 indexType.t = null;
318 indexType.e = null;
319 indexType.size = 0;
320 indexType.prim = p;
321 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800322 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700323 }
324
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700325 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700326 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800327 * Adds an index set data type to the builder object
328 *
329 * @param e element describing the index set data layout
330 * @param size number of elements in the buffer
331 * @param p primitive type
332 *
333 * @return this
334 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800335 public Builder addIndexSetType(Element e, int size, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700336 Entry indexType = new Entry();
337 indexType.t = null;
338 indexType.e = e;
339 indexType.size = size;
340 indexType.prim = p;
341 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800342 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700343 }
344
345 Type newType(Element e, int size) {
346 Type.Builder tb = new Type.Builder(mRS, e);
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800347 tb.setX(size);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700348 return tb.create();
349 }
350
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700351 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700352 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800353 * Create a Mesh object from the current state of the builder
354 *
355 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700356 public Mesh create() {
357 mRS.validate();
Ashok Bhat98071552014-02-12 09:54:43 +0000358 long[] vtx = new long[mVertexTypeCount];
359 long[] idx = new long[mIndexTypes.size()];
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700360 int[] prim = new int[mIndexTypes.size()];
361
362 Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
363 Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
364 Primitive[] primitives = new Primitive[mIndexTypes.size()];
365
366 for(int ct = 0; ct < mVertexTypeCount; ct ++) {
367 Allocation alloc = null;
368 Entry entry = mVertexTypes[ct];
369 if (entry.t != null) {
370 alloc = Allocation.createTyped(mRS, entry.t, mUsage);
371 } else if(entry.e != null) {
372 alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
Jason Samsae5be382015-03-26 14:47:17 -0700373 } else {
374 // Should never happen because the builder will always set one
375 throw new IllegalStateException("Builder corrupt, no valid element in entry.");
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700376 }
377 vertexBuffers[ct] = alloc;
Ashok Bhat98071552014-02-12 09:54:43 +0000378 vtx[ct] = alloc.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700379 }
380
381 for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
382 Allocation alloc = null;
383 Entry entry = (Entry)mIndexTypes.elementAt(ct);
384 if (entry.t != null) {
385 alloc = Allocation.createTyped(mRS, entry.t, mUsage);
386 } else if(entry.e != null) {
387 alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
Jason Samsae5be382015-03-26 14:47:17 -0700388 } else {
389 // Should never happen because the builder will always set one
390 throw new IllegalStateException("Builder corrupt, no valid element in entry.");
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700391 }
Tim Murray460a0492013-11-19 12:45:54 -0800392 long allocID = (alloc == null) ? 0 : alloc.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700393 indexBuffers[ct] = alloc;
394 primitives[ct] = entry.prim;
395
Ashok Bhat98071552014-02-12 09:54:43 +0000396 idx[ct] = allocID;
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700397 prim[ct] = entry.prim.mID;
398 }
399
Tim Murray460a0492013-11-19 12:45:54 -0800400 long id = mRS.nMeshCreate(vtx, idx, prim);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700401 Mesh newMesh = new Mesh(id, mRS);
402 newMesh.mVertexBuffers = vertexBuffers;
403 newMesh.mIndexBuffers = indexBuffers;
404 newMesh.mPrimitives = primitives;
405
406 return newMesh;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700407 }
408 }
409
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700410 /**
Jason Samse619de62012-05-08 18:40:58 -0700411 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800412 * Mesh builder object. It starts empty and requires the user to
413 * add all the vertex and index allocations that comprise the
414 * mesh
415 *
416 */
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700417 public static class AllocationBuilder {
418 RenderScript mRS;
419
420 class Entry {
421 Allocation a;
422 Primitive prim;
423 }
424
425 int mVertexTypeCount;
426 Entry[] mVertexTypes;
427
428 Vector mIndexTypes;
429
Jason Samse619de62012-05-08 18:40:58 -0700430 /**
431 * @deprecated in API 16
432 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100433 @UnsupportedAppUsage
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700434 public AllocationBuilder(RenderScript rs) {
435 mRS = rs;
436 mVertexTypeCount = 0;
437 mVertexTypes = new Entry[16];
438 mIndexTypes = new Vector();
439 }
440
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700441 /**
Jason Samse619de62012-05-08 18:40:58 -0700442 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800443 * @return internal index of the last vertex buffer type added to
444 * builder
445 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800446 public int getCurrentVertexTypeIndex() {
447 return mVertexTypeCount - 1;
448 }
449
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700450 /**
Jason Samse619de62012-05-08 18:40:58 -0700451 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800452 * @return internal index of the last index set added to the
453 * builder
454 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800455 public int getCurrentIndexSetIndex() {
456 return mIndexTypes.size() - 1;
457 }
458
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700459 /**
Jason Samse619de62012-05-08 18:40:58 -0700460 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800461 * Adds an allocation containing vertex buffer data to the
462 * builder
463 *
464 * @param a vertex data allocation
465 *
466 * @return this
467 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100468 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800469 public AllocationBuilder addVertexAllocation(Allocation a) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700470 if (mVertexTypeCount >= mVertexTypes.length) {
471 throw new IllegalStateException("Max vertex types exceeded.");
472 }
473
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700474 mVertexTypes[mVertexTypeCount] = new Entry();
475 mVertexTypes[mVertexTypeCount].a = a;
476 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800477 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700478 }
479
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700480 /**
Jason Samse619de62012-05-08 18:40:58 -0700481 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800482 * Adds an allocation containing index buffer data and index type
483 * to the builder
484 *
485 * @param a index set data allocation, could be null
486 * @param p index set primitive type
487 *
488 * @return this
489 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100490 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800491 public AllocationBuilder addIndexSetAllocation(Allocation a, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700492 Entry indexType = new Entry();
493 indexType.a = a;
494 indexType.prim = p;
495 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800496 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700497 }
498
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700499 /**
Jason Samse619de62012-05-08 18:40:58 -0700500 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800501 * Adds an index set type to the builder
502 *
503 * @param p index set primitive type
504 *
505 * @return this
506 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100507 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800508 public AllocationBuilder addIndexSetType(Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700509 Entry indexType = new Entry();
510 indexType.a = null;
511 indexType.prim = p;
512 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800513 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700514 }
515
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700516 /**
Jason Samse619de62012-05-08 18:40:58 -0700517 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800518 * Create a Mesh object from the current state of the builder
519 *
520 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100521 @UnsupportedAppUsage
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700522 public Mesh create() {
523 mRS.validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700524
Ashok Bhat98071552014-02-12 09:54:43 +0000525 long[] vtx = new long[mVertexTypeCount];
526 long[] idx = new long[mIndexTypes.size()];
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700527 int[] prim = new int[mIndexTypes.size()];
528
529 Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
530 Primitive[] primitives = new Primitive[mIndexTypes.size()];
531 Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
532
533 for(int ct = 0; ct < mVertexTypeCount; ct ++) {
534 Entry entry = mVertexTypes[ct];
535 vertexBuffers[ct] = entry.a;
Ashok Bhat98071552014-02-12 09:54:43 +0000536 vtx[ct] = entry.a.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700537 }
538
539 for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
540 Entry entry = (Entry)mIndexTypes.elementAt(ct);
Tim Murray460a0492013-11-19 12:45:54 -0800541 long allocID = (entry.a == null) ? 0 : entry.a.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700542 indexBuffers[ct] = entry.a;
543 primitives[ct] = entry.prim;
544
Ashok Bhat98071552014-02-12 09:54:43 +0000545 idx[ct] = allocID;
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700546 prim[ct] = entry.prim.mID;
547 }
548
Tim Murray460a0492013-11-19 12:45:54 -0800549 long id = mRS.nMeshCreate(vtx, idx, prim);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700550 Mesh newMesh = new Mesh(id, mRS);
551 newMesh.mVertexBuffers = vertexBuffers;
552 newMesh.mIndexBuffers = indexBuffers;
553 newMesh.mPrimitives = primitives;
554
555 return newMesh;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700556 }
557 }
558
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700559 /**
Jason Samse619de62012-05-08 18:40:58 -0700560 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800561 * Builder that allows creation of a mesh object point by point
562 * and triangle by triangle
563 *
564 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700565 public static class TriangleMeshBuilder {
566 float mVtxData[];
567 int mVtxCount;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800568 int mMaxIndex;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700569 short mIndexData[];
570 int mIndexCount;
571 RenderScript mRS;
572 Element mElement;
573
574 float mNX = 0;
575 float mNY = 0;
576 float mNZ = -1;
577 float mS0 = 0;
578 float mT0 = 0;
579 float mR = 1;
580 float mG = 1;
581 float mB = 1;
582 float mA = 1;
583
584 int mVtxSize;
585 int mFlags;
586
Jason Samse619de62012-05-08 18:40:58 -0700587 /**
588 * @deprecated in API 16
589 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700590 public static final int COLOR = 0x0001;
Jason Samse619de62012-05-08 18:40:58 -0700591 /**
592 * @deprecated in API 16
593 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700594 public static final int NORMAL = 0x0002;
Jason Samse619de62012-05-08 18:40:58 -0700595 /**
596 * @deprecated in API 16
597 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700598 public static final int TEXTURE_0 = 0x0100;
599
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700600 /**
Jason Samse619de62012-05-08 18:40:58 -0700601 * @deprecated in API 16
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800602 * @param rs Context to which the mesh will belong.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800603 * @param vtxSize specifies whether the vertex is a float2 or
604 * float3
605 * @param flags bitfield that is a combination of COLOR, NORMAL,
606 * and TEXTURE_0 that specifies what vertex data
607 * channels are present in the mesh
608 *
609 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000610 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700611 public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
612 mRS = rs;
613 mVtxCount = 0;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800614 mMaxIndex = 0;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700615 mIndexCount = 0;
616 mVtxData = new float[128];
617 mIndexData = new short[128];
618 mVtxSize = vtxSize;
619 mFlags = flags;
620
621 if (vtxSize < 2 || vtxSize > 3) {
622 throw new IllegalArgumentException("Vertex size out of range.");
623 }
624 }
625
626 private void makeSpace(int count) {
627 if ((mVtxCount + count) >= mVtxData.length) {
628 float t[] = new float[mVtxData.length * 2];
629 System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
630 mVtxData = t;
631 }
632 }
633
634 private void latch() {
635 if ((mFlags & COLOR) != 0) {
636 makeSpace(4);
637 mVtxData[mVtxCount++] = mR;
638 mVtxData[mVtxCount++] = mG;
639 mVtxData[mVtxCount++] = mB;
640 mVtxData[mVtxCount++] = mA;
641 }
642 if ((mFlags & TEXTURE_0) != 0) {
643 makeSpace(2);
644 mVtxData[mVtxCount++] = mS0;
645 mVtxData[mVtxCount++] = mT0;
646 }
647 if ((mFlags & NORMAL) != 0) {
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800648 makeSpace(4);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700649 mVtxData[mVtxCount++] = mNX;
650 mVtxData[mVtxCount++] = mNY;
651 mVtxData[mVtxCount++] = mNZ;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800652 mVtxData[mVtxCount++] = 0.0f;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700653 }
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800654 mMaxIndex ++;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700655 }
656
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700657 /**
Jason Samse619de62012-05-08 18:40:58 -0700658 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800659 * Adds a float2 vertex to the mesh
660 *
661 * @param x position x
662 * @param y position y
663 *
664 * @return this
665 *
666 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000667 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800668 public TriangleMeshBuilder addVertex(float x, float y) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700669 if (mVtxSize != 2) {
670 throw new IllegalStateException("add mistmatch with declared components.");
671 }
672 makeSpace(2);
673 mVtxData[mVtxCount++] = x;
674 mVtxData[mVtxCount++] = y;
675 latch();
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800676 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700677 }
678
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700679 /**
Jason Samse619de62012-05-08 18:40:58 -0700680 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800681 * Adds a float3 vertex to the mesh
682 *
683 * @param x position x
684 * @param y position y
685 * @param z position z
686 *
687 * @return this
688 *
689 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800690 public TriangleMeshBuilder addVertex(float x, float y, float z) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700691 if (mVtxSize != 3) {
692 throw new IllegalStateException("add mistmatch with declared components.");
693 }
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800694 makeSpace(4);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700695 mVtxData[mVtxCount++] = x;
696 mVtxData[mVtxCount++] = y;
697 mVtxData[mVtxCount++] = z;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800698 mVtxData[mVtxCount++] = 1.0f;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700699 latch();
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800700 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700701 }
702
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700703 /**
Jason Samse619de62012-05-08 18:40:58 -0700704 * @deprecated in API 16
Robert Lyf11ffc112012-02-22 10:59:12 -0800705 * Sets the texture coordinate for the vertices that are added after this method call.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800706 *
707 * @param s texture coordinate s
708 * @param t texture coordinate t
709 *
710 * @return this
711 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800712 public TriangleMeshBuilder setTexture(float s, float t) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700713 if ((mFlags & TEXTURE_0) == 0) {
714 throw new IllegalStateException("add mistmatch with declared components.");
715 }
716 mS0 = s;
717 mT0 = t;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800718 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700719 }
720
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700721 /**
Jason Samse619de62012-05-08 18:40:58 -0700722 * @deprecated in API 16
Robert Lyf11ffc112012-02-22 10:59:12 -0800723 * Sets the normal vector for the vertices that are added after this method call.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800724 *
725 * @param x normal vector x
726 * @param y normal vector y
727 * @param z normal vector z
728 *
729 * @return this
730 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800731 public TriangleMeshBuilder setNormal(float x, float y, float z) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700732 if ((mFlags & NORMAL) == 0) {
733 throw new IllegalStateException("add mistmatch with declared components.");
734 }
735 mNX = x;
736 mNY = y;
737 mNZ = z;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800738 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700739 }
740
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700741 /**
Jason Samse619de62012-05-08 18:40:58 -0700742 * @deprecated in API 16
Robert Lyf11ffc112012-02-22 10:59:12 -0800743 * Sets the color for the vertices that are added after this method call.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800744 *
745 * @param r red component
746 * @param g green component
747 * @param b blue component
748 * @param a alpha component
749 *
750 * @return this
751 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800752 public TriangleMeshBuilder setColor(float r, float g, float b, float a) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700753 if ((mFlags & COLOR) == 0) {
754 throw new IllegalStateException("add mistmatch with declared components.");
755 }
756 mR = r;
757 mG = g;
758 mB = b;
759 mA = a;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800760 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700761 }
762
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700763 /**
Jason Samse619de62012-05-08 18:40:58 -0700764 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800765 * Adds a new triangle to the mesh builder
766 *
767 * @param idx1 index of the first vertex in the triangle
768 * @param idx2 index of the second vertex in the triangle
769 * @param idx3 index of the third vertex in the triangle
770 *
771 * @return this
772 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000773 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800774 public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) {
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800775 if((idx1 >= mMaxIndex) || (idx1 < 0) ||
776 (idx2 >= mMaxIndex) || (idx2 < 0) ||
777 (idx3 >= mMaxIndex) || (idx3 < 0)) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700778 throw new IllegalStateException("Index provided greater than vertex count.");
779 }
780 if ((mIndexCount + 3) >= mIndexData.length) {
781 short t[] = new short[mIndexData.length * 2];
782 System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
783 mIndexData = t;
784 }
785 mIndexData[mIndexCount++] = (short)idx1;
786 mIndexData[mIndexCount++] = (short)idx2;
787 mIndexData[mIndexCount++] = (short)idx3;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800788 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700789 }
790
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700791 /**
Jason Samse619de62012-05-08 18:40:58 -0700792 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800793 * Creates the mesh object from the current state of the builder
794 *
795 * @param uploadToBufferObject specifies whether the vertex data
796 * is to be uploaded into the buffer
797 * object indicating that it's likely
798 * not going to be modified and
799 * rendered many times.
800 * Alternatively, it indicates the
801 * mesh data will be updated
802 * frequently and remain in script
803 * accessible memory
804 *
805 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000806 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700807 public Mesh create(boolean uploadToBufferObject) {
808 Element.Builder b = new Element.Builder(mRS);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700809 b.add(Element.createVector(mRS,
810 Element.DataType.FLOAT_32,
811 mVtxSize), "position");
812 if ((mFlags & COLOR) != 0) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700813 b.add(Element.F32_4(mRS), "color");
814 }
815 if ((mFlags & TEXTURE_0) != 0) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700816 b.add(Element.F32_2(mRS), "texture0");
817 }
818 if ((mFlags & NORMAL) != 0) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700819 b.add(Element.F32_3(mRS), "normal");
820 }
821 mElement = b.create();
822
Jason Samsd1952402010-12-20 12:55:28 -0800823 int usage = Allocation.USAGE_SCRIPT;
824 if (uploadToBufferObject) {
825 usage |= Allocation.USAGE_GRAPHICS_VERTEX;
826 }
827
828 Builder smb = new Builder(mRS, usage);
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800829 smb.addVertexType(mElement, mMaxIndex);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800830 smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700831
832 Mesh sm = smb.create();
833
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800834 sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mMaxIndex, mVtxData);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700835 if(uploadToBufferObject) {
Andreas Gampe16720c12015-03-17 19:10:14 -0700836 sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700837 }
838
Jason Samsb97b2512011-01-16 15:04:08 -0800839 sm.getIndexSetAllocation(0).copy1DRangeFromUnchecked(0, mIndexCount, mIndexData);
Jason Samsd1952402010-12-20 12:55:28 -0800840 if (uploadToBufferObject) {
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800841 sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
Jason Samsd1952402010-12-20 12:55:28 -0800842 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700843
844 return sm;
845 }
846 }
847}
848