blob: f2fd5a92afe84fca6f6e41a968227d20fafd7ded [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 **/
Xusong Wang8b4548c2021-01-05 10:09:52 -080043@Deprecated
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070044public class Mesh extends BaseObj {
45
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070046 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070047 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -080048 * Describes the way mesh vertex data is interpreted when rendering
49 *
50 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080051 public enum Primitive {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070052 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070053 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080054 * Vertex data will be rendered as a series of points
55 */
Mathew Inwood15324472018-08-06 11:18:49 +010056 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080057 POINT (0),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070058 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070059 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080060 * Vertex pairs will be rendered as lines
61 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080062 LINE (1),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070063 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070064 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080065 * Vertex data will be rendered as a connected line strip
66 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080067 LINE_STRIP (2),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070068 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070069 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080070 * Vertices will be rendered as individual triangles
71 */
Mathew Inwood15324472018-08-06 11:18:49 +010072 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080073 TRIANGLE (3),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070074 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070075 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080076 * Vertices will be rendered as a connected triangle strip
77 * defined by the first three vertices with each additional
78 * triangle defined by a new vertex
79 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080080 TRIANGLE_STRIP (4),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070081 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070082 * @deprecated in API 16
Alex Sakhartchoukec0d3352011-01-17 15:23:22 -080083 * Vertices will be rendered as a sequence of triangles that all
84 * share first vertex as the origin
85 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080086 TRIANGLE_FAN (5);
87
88 int mID;
89 Primitive(int id) {
90 mID = id;
91 }
92 }
93
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070094 Allocation[] mVertexBuffers;
95 Allocation[] mIndexBuffers;
96 Primitive[] mPrimitives;
97
Tim Murray460a0492013-11-19 12:45:54 -080098 Mesh(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070099 super(id, rs);
Yang Nieb4dd082016-03-24 09:40:32 -0700100 guard.open("destroy");
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700101 }
102
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700103 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700104 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800105 * @return number of allocations containing vertex data
106 *
107 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700108 public int getVertexAllocationCount() {
109 if(mVertexBuffers == null) {
110 return 0;
111 }
112 return mVertexBuffers.length;
113 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700114 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700115 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800116 * @param slot index in the list of allocations to return
117 * @return vertex data allocation at the given index
118 *
119 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100120 @UnsupportedAppUsage
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700121 public Allocation getVertexAllocation(int slot) {
122 return mVertexBuffers[slot];
123 }
124
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700125 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700126 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800127 * @return number of primitives or index sets in the mesh
128 *
129 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700130 public int getPrimitiveCount() {
131 if(mIndexBuffers == null) {
132 return 0;
133 }
134 return mIndexBuffers.length;
135 }
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800136
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700137 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700138 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800139 * @param slot locaton within the list of index set allocation
140 * @return allocation containing primtive index data or null if
141 * the index data is not specified explicitly
142 *
143 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800144 public Allocation getIndexSetAllocation(int slot) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700145 return mIndexBuffers[slot];
146 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700147 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700148 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800149 * @param slot locaiton within the list of index set primitives
150 * @return index set primitive type
151 *
152 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700153 public Primitive getPrimitive(int slot) {
154 return mPrimitives[slot];
155 }
156
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700157 @Override
158 void updateFromNative() {
Jason Sams06d69de2010-11-09 17:11:40 -0800159 super.updateFromNative();
Jason Samse07694b2012-04-03 15:36:36 -0700160 int vtxCount = mRS.nMeshGetVertexBufferCount(getID(mRS));
161 int idxCount = mRS.nMeshGetIndexCount(getID(mRS));
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700162
Ashok Bhat98071552014-02-12 09:54:43 +0000163 long[] vtxIDs = new long[vtxCount];
164 long[] idxIDs = new long[idxCount];
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700165 int[] primitives = new int[idxCount];
166
Jason Samse07694b2012-04-03 15:36:36 -0700167 mRS.nMeshGetVertices(getID(mRS), vtxIDs, vtxCount);
168 mRS.nMeshGetIndices(getID(mRS), idxIDs, primitives, idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700169
170 mVertexBuffers = new Allocation[vtxCount];
171 mIndexBuffers = new Allocation[idxCount];
172 mPrimitives = new Primitive[idxCount];
173
174 for(int i = 0; i < vtxCount; i ++) {
175 if(vtxIDs[i] != 0) {
Jason Samsd4b23b52010-12-13 15:32:35 -0800176 mVertexBuffers[i] = new Allocation(vtxIDs[i], mRS, null, Allocation.USAGE_SCRIPT);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700177 mVertexBuffers[i].updateFromNative();
178 }
179 }
180
181 for(int i = 0; i < idxCount; i ++) {
182 if(idxIDs[i] != 0) {
Jason Samsd4b23b52010-12-13 15:32:35 -0800183 mIndexBuffers[i] = new Allocation(idxIDs[i], mRS, null, Allocation.USAGE_SCRIPT);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700184 mIndexBuffers[i].updateFromNative();
185 }
186 mPrimitives[i] = Primitive.values()[primitives[i]];
187 }
188 }
189
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700190 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700191 * @deprecated in API 16
Robert Ly11518ac2011-02-09 13:57:06 -0800192 * Mesh builder object. It starts empty and requires you to
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800193 * add the types necessary to create vertex and index
Robert Ly11518ac2011-02-09 13:57:06 -0800194 * allocations.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800195 *
196 */
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700197 public static class Builder {
198 RenderScript mRS;
Jason Samsd1952402010-12-20 12:55:28 -0800199 int mUsage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700200
201 class Entry {
202 Type t;
203 Element e;
204 int size;
205 Primitive prim;
Jason Samsd1952402010-12-20 12:55:28 -0800206 int usage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700207 }
208
209 int mVertexTypeCount;
210 Entry[] mVertexTypes;
211 Vector mIndexTypes;
212
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700213 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700214 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800215 * Creates builder object
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800216 * @param rs Context to which the mesh will belong.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800217 * @param usage specifies how the mesh allocations are to be
218 * handled, whether they need to be uploaded to a
219 * buffer on the gpu, maintain a cpu copy, etc
220 */
Jason Samsd1952402010-12-20 12:55:28 -0800221 public Builder(RenderScript rs, int usage) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700222 mRS = rs;
Jason Samsd1952402010-12-20 12:55:28 -0800223 mUsage = usage;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700224 mVertexTypeCount = 0;
225 mVertexTypes = new Entry[16];
226 mIndexTypes = new Vector();
227 }
228
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700229 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700230 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800231 * @return internal index of the last vertex buffer type added to
232 * builder
233 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800234 public int getCurrentVertexTypeIndex() {
235 return mVertexTypeCount - 1;
236 }
237
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700238 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700239 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800240 * @return internal index of the last index set added to the
241 * builder
242 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800243 public int getCurrentIndexSetIndex() {
244 return mIndexTypes.size() - 1;
245 }
246
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700247 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700248 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800249 * Adds a vertex data type to the builder object
250 *
Stephen Hinesb11e3d22011-01-11 19:30:58 -0800251 * @param t type of the vertex data allocation to be created
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800252 *
253 * @return this
254 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800255 public Builder addVertexType(Type t) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700256 if (mVertexTypeCount >= mVertexTypes.length) {
257 throw new IllegalStateException("Max vertex types exceeded.");
258 }
259
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700260 mVertexTypes[mVertexTypeCount] = new Entry();
261 mVertexTypes[mVertexTypeCount].t = t;
262 mVertexTypes[mVertexTypeCount].e = null;
263 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800264 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700265 }
266
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700267 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700268 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800269 * Adds a vertex data type to the builder object
270 *
271 * @param e element describing the vertex data layout
272 * @param size number of elements in the buffer
273 *
274 * @return this
275 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800276 public Builder addVertexType(Element e, int size) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700277 if (mVertexTypeCount >= mVertexTypes.length) {
278 throw new IllegalStateException("Max vertex types exceeded.");
279 }
280
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700281 mVertexTypes[mVertexTypeCount] = new Entry();
282 mVertexTypes[mVertexTypeCount].t = null;
283 mVertexTypes[mVertexTypeCount].e = e;
284 mVertexTypes[mVertexTypeCount].size = size;
285 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800286 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700287 }
288
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700289 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700290 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800291 * Adds an index set data type to the builder object
292 *
293 * @param t type of the index set data, could be null
294 * @param p primitive type
295 *
296 * @return this
297 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800298 public Builder addIndexSetType(Type t, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700299 Entry indexType = new Entry();
300 indexType.t = t;
301 indexType.e = null;
302 indexType.size = 0;
303 indexType.prim = p;
304 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800305 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700306 }
307
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700308 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700309 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800310 * Adds an index set primitive type to the builder object
311 *
312 * @param p primitive type
313 *
314 * @return this
315 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800316 public Builder addIndexSetType(Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700317 Entry indexType = new Entry();
318 indexType.t = null;
319 indexType.e = null;
320 indexType.size = 0;
321 indexType.prim = p;
322 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800323 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700324 }
325
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700326 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700327 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800328 * Adds an index set data type to the builder object
329 *
330 * @param e element describing the index set data layout
331 * @param size number of elements in the buffer
332 * @param p primitive type
333 *
334 * @return this
335 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800336 public Builder addIndexSetType(Element e, int size, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700337 Entry indexType = new Entry();
338 indexType.t = null;
339 indexType.e = e;
340 indexType.size = size;
341 indexType.prim = p;
342 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800343 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700344 }
345
346 Type newType(Element e, int size) {
347 Type.Builder tb = new Type.Builder(mRS, e);
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800348 tb.setX(size);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700349 return tb.create();
350 }
351
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700352 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700353 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800354 * Create a Mesh object from the current state of the builder
355 *
356 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700357 public Mesh create() {
358 mRS.validate();
Ashok Bhat98071552014-02-12 09:54:43 +0000359 long[] vtx = new long[mVertexTypeCount];
360 long[] idx = new long[mIndexTypes.size()];
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700361 int[] prim = new int[mIndexTypes.size()];
362
363 Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
364 Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
365 Primitive[] primitives = new Primitive[mIndexTypes.size()];
366
367 for(int ct = 0; ct < mVertexTypeCount; ct ++) {
368 Allocation alloc = null;
369 Entry entry = mVertexTypes[ct];
370 if (entry.t != null) {
371 alloc = Allocation.createTyped(mRS, entry.t, mUsage);
372 } else if(entry.e != null) {
373 alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
Jason Samsae5be382015-03-26 14:47:17 -0700374 } else {
375 // Should never happen because the builder will always set one
376 throw new IllegalStateException("Builder corrupt, no valid element in entry.");
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700377 }
378 vertexBuffers[ct] = alloc;
Ashok Bhat98071552014-02-12 09:54:43 +0000379 vtx[ct] = alloc.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700380 }
381
382 for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
383 Allocation alloc = null;
384 Entry entry = (Entry)mIndexTypes.elementAt(ct);
385 if (entry.t != null) {
386 alloc = Allocation.createTyped(mRS, entry.t, mUsage);
387 } else if(entry.e != null) {
388 alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
Jason Samsae5be382015-03-26 14:47:17 -0700389 } else {
390 // Should never happen because the builder will always set one
391 throw new IllegalStateException("Builder corrupt, no valid element in entry.");
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700392 }
Tim Murray460a0492013-11-19 12:45:54 -0800393 long allocID = (alloc == null) ? 0 : alloc.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700394 indexBuffers[ct] = alloc;
395 primitives[ct] = entry.prim;
396
Ashok Bhat98071552014-02-12 09:54:43 +0000397 idx[ct] = allocID;
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700398 prim[ct] = entry.prim.mID;
399 }
400
Tim Murray460a0492013-11-19 12:45:54 -0800401 long id = mRS.nMeshCreate(vtx, idx, prim);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700402 Mesh newMesh = new Mesh(id, mRS);
403 newMesh.mVertexBuffers = vertexBuffers;
404 newMesh.mIndexBuffers = indexBuffers;
405 newMesh.mPrimitives = primitives;
406
407 return newMesh;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700408 }
409 }
410
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700411 /**
Jason Samse619de62012-05-08 18:40:58 -0700412 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800413 * Mesh builder object. It starts empty and requires the user to
414 * add all the vertex and index allocations that comprise the
415 * mesh
416 *
417 */
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700418 public static class AllocationBuilder {
419 RenderScript mRS;
420
421 class Entry {
422 Allocation a;
423 Primitive prim;
424 }
425
426 int mVertexTypeCount;
427 Entry[] mVertexTypes;
428
429 Vector mIndexTypes;
430
Jason Samse619de62012-05-08 18:40:58 -0700431 /**
432 * @deprecated in API 16
433 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100434 @UnsupportedAppUsage
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700435 public AllocationBuilder(RenderScript rs) {
436 mRS = rs;
437 mVertexTypeCount = 0;
438 mVertexTypes = new Entry[16];
439 mIndexTypes = new Vector();
440 }
441
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700442 /**
Jason Samse619de62012-05-08 18:40:58 -0700443 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800444 * @return internal index of the last vertex buffer type added to
445 * builder
446 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800447 public int getCurrentVertexTypeIndex() {
448 return mVertexTypeCount - 1;
449 }
450
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700451 /**
Jason Samse619de62012-05-08 18:40:58 -0700452 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800453 * @return internal index of the last index set added to the
454 * builder
455 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800456 public int getCurrentIndexSetIndex() {
457 return mIndexTypes.size() - 1;
458 }
459
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700460 /**
Jason Samse619de62012-05-08 18:40:58 -0700461 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800462 * Adds an allocation containing vertex buffer data to the
463 * builder
464 *
465 * @param a vertex data allocation
466 *
467 * @return this
468 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100469 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800470 public AllocationBuilder addVertexAllocation(Allocation a) throws IllegalStateException {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700471 if (mVertexTypeCount >= mVertexTypes.length) {
472 throw new IllegalStateException("Max vertex types exceeded.");
473 }
474
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700475 mVertexTypes[mVertexTypeCount] = new Entry();
476 mVertexTypes[mVertexTypeCount].a = a;
477 mVertexTypeCount++;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800478 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700479 }
480
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700481 /**
Jason Samse619de62012-05-08 18:40:58 -0700482 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800483 * Adds an allocation containing index buffer data and index type
484 * to the builder
485 *
486 * @param a index set data allocation, could be null
487 * @param p index set primitive type
488 *
489 * @return this
490 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100491 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800492 public AllocationBuilder addIndexSetAllocation(Allocation a, Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700493 Entry indexType = new Entry();
494 indexType.a = a;
495 indexType.prim = p;
496 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800497 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700498 }
499
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700500 /**
Jason Samse619de62012-05-08 18:40:58 -0700501 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800502 * Adds an index set type to the builder
503 *
504 * @param p index set primitive type
505 *
506 * @return this
507 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100508 @UnsupportedAppUsage
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800509 public AllocationBuilder addIndexSetType(Primitive p) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700510 Entry indexType = new Entry();
511 indexType.a = null;
512 indexType.prim = p;
513 mIndexTypes.addElement(indexType);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800514 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700515 }
516
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700517 /**
Jason Samse619de62012-05-08 18:40:58 -0700518 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800519 * Create a Mesh object from the current state of the builder
520 *
521 **/
Mathew Inwood15324472018-08-06 11:18:49 +0100522 @UnsupportedAppUsage
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700523 public Mesh create() {
524 mRS.validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700525
Ashok Bhat98071552014-02-12 09:54:43 +0000526 long[] vtx = new long[mVertexTypeCount];
527 long[] idx = new long[mIndexTypes.size()];
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700528 int[] prim = new int[mIndexTypes.size()];
529
530 Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
531 Primitive[] primitives = new Primitive[mIndexTypes.size()];
532 Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
533
534 for(int ct = 0; ct < mVertexTypeCount; ct ++) {
535 Entry entry = mVertexTypes[ct];
536 vertexBuffers[ct] = entry.a;
Ashok Bhat98071552014-02-12 09:54:43 +0000537 vtx[ct] = entry.a.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700538 }
539
540 for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
541 Entry entry = (Entry)mIndexTypes.elementAt(ct);
Tim Murray460a0492013-11-19 12:45:54 -0800542 long allocID = (entry.a == null) ? 0 : entry.a.getID(mRS);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700543 indexBuffers[ct] = entry.a;
544 primitives[ct] = entry.prim;
545
Ashok Bhat98071552014-02-12 09:54:43 +0000546 idx[ct] = allocID;
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700547 prim[ct] = entry.prim.mID;
548 }
549
Tim Murray460a0492013-11-19 12:45:54 -0800550 long id = mRS.nMeshCreate(vtx, idx, prim);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700551 Mesh newMesh = new Mesh(id, mRS);
552 newMesh.mVertexBuffers = vertexBuffers;
553 newMesh.mIndexBuffers = indexBuffers;
554 newMesh.mPrimitives = primitives;
555
556 return newMesh;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700557 }
558 }
559
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700560 /**
Jason Samse619de62012-05-08 18:40:58 -0700561 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800562 * Builder that allows creation of a mesh object point by point
563 * and triangle by triangle
564 *
565 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700566 public static class TriangleMeshBuilder {
567 float mVtxData[];
568 int mVtxCount;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800569 int mMaxIndex;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700570 short mIndexData[];
571 int mIndexCount;
572 RenderScript mRS;
573 Element mElement;
574
575 float mNX = 0;
576 float mNY = 0;
577 float mNZ = -1;
578 float mS0 = 0;
579 float mT0 = 0;
580 float mR = 1;
581 float mG = 1;
582 float mB = 1;
583 float mA = 1;
584
585 int mVtxSize;
586 int mFlags;
587
Jason Samse619de62012-05-08 18:40:58 -0700588 /**
589 * @deprecated in API 16
590 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700591 public static final int COLOR = 0x0001;
Jason Samse619de62012-05-08 18:40:58 -0700592 /**
593 * @deprecated in API 16
594 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700595 public static final int NORMAL = 0x0002;
Jason Samse619de62012-05-08 18:40:58 -0700596 /**
597 * @deprecated in API 16
598 **/
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700599 public static final int TEXTURE_0 = 0x0100;
600
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700601 /**
Jason Samse619de62012-05-08 18:40:58 -0700602 * @deprecated in API 16
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800603 * @param rs Context to which the mesh will belong.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800604 * @param vtxSize specifies whether the vertex is a float2 or
605 * float3
606 * @param flags bitfield that is a combination of COLOR, NORMAL,
607 * and TEXTURE_0 that specifies what vertex data
608 * channels are present in the mesh
609 *
610 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000611 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700612 public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
613 mRS = rs;
614 mVtxCount = 0;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800615 mMaxIndex = 0;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700616 mIndexCount = 0;
617 mVtxData = new float[128];
618 mIndexData = new short[128];
619 mVtxSize = vtxSize;
620 mFlags = flags;
621
622 if (vtxSize < 2 || vtxSize > 3) {
623 throw new IllegalArgumentException("Vertex size out of range.");
624 }
625 }
626
627 private void makeSpace(int count) {
628 if ((mVtxCount + count) >= mVtxData.length) {
629 float t[] = new float[mVtxData.length * 2];
630 System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
631 mVtxData = t;
632 }
633 }
634
635 private void latch() {
636 if ((mFlags & COLOR) != 0) {
637 makeSpace(4);
638 mVtxData[mVtxCount++] = mR;
639 mVtxData[mVtxCount++] = mG;
640 mVtxData[mVtxCount++] = mB;
641 mVtxData[mVtxCount++] = mA;
642 }
643 if ((mFlags & TEXTURE_0) != 0) {
644 makeSpace(2);
645 mVtxData[mVtxCount++] = mS0;
646 mVtxData[mVtxCount++] = mT0;
647 }
648 if ((mFlags & NORMAL) != 0) {
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800649 makeSpace(4);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700650 mVtxData[mVtxCount++] = mNX;
651 mVtxData[mVtxCount++] = mNY;
652 mVtxData[mVtxCount++] = mNZ;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800653 mVtxData[mVtxCount++] = 0.0f;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700654 }
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800655 mMaxIndex ++;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700656 }
657
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700658 /**
Jason Samse619de62012-05-08 18:40:58 -0700659 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800660 * Adds a float2 vertex to the mesh
661 *
662 * @param x position x
663 * @param y position y
664 *
665 * @return this
666 *
667 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000668 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800669 public TriangleMeshBuilder addVertex(float x, float y) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700670 if (mVtxSize != 2) {
671 throw new IllegalStateException("add mistmatch with declared components.");
672 }
673 makeSpace(2);
674 mVtxData[mVtxCount++] = x;
675 mVtxData[mVtxCount++] = y;
676 latch();
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800677 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700678 }
679
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700680 /**
Jason Samse619de62012-05-08 18:40:58 -0700681 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800682 * Adds a float3 vertex to the mesh
683 *
684 * @param x position x
685 * @param y position y
686 * @param z position z
687 *
688 * @return this
689 *
690 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800691 public TriangleMeshBuilder addVertex(float x, float y, float z) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700692 if (mVtxSize != 3) {
693 throw new IllegalStateException("add mistmatch with declared components.");
694 }
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800695 makeSpace(4);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700696 mVtxData[mVtxCount++] = x;
697 mVtxData[mVtxCount++] = y;
698 mVtxData[mVtxCount++] = z;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800699 mVtxData[mVtxCount++] = 1.0f;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700700 latch();
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800701 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700702 }
703
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700704 /**
Jason Samse619de62012-05-08 18:40:58 -0700705 * @deprecated in API 16
Robert Lyf11ffc112012-02-22 10:59:12 -0800706 * Sets the texture coordinate for the vertices that are added after this method call.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800707 *
708 * @param s texture coordinate s
709 * @param t texture coordinate t
710 *
711 * @return this
712 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800713 public TriangleMeshBuilder setTexture(float s, float t) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700714 if ((mFlags & TEXTURE_0) == 0) {
715 throw new IllegalStateException("add mistmatch with declared components.");
716 }
717 mS0 = s;
718 mT0 = t;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800719 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700720 }
721
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700722 /**
Jason Samse619de62012-05-08 18:40:58 -0700723 * @deprecated in API 16
Robert Lyf11ffc112012-02-22 10:59:12 -0800724 * Sets the normal vector for the vertices that are added after this method call.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800725 *
726 * @param x normal vector x
727 * @param y normal vector y
728 * @param z normal vector z
729 *
730 * @return this
731 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800732 public TriangleMeshBuilder setNormal(float x, float y, float z) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700733 if ((mFlags & NORMAL) == 0) {
734 throw new IllegalStateException("add mistmatch with declared components.");
735 }
736 mNX = x;
737 mNY = y;
738 mNZ = z;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800739 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700740 }
741
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700742 /**
Jason Samse619de62012-05-08 18:40:58 -0700743 * @deprecated in API 16
Robert Lyf11ffc112012-02-22 10:59:12 -0800744 * Sets the color for the vertices that are added after this method call.
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800745 *
746 * @param r red component
747 * @param g green component
748 * @param b blue component
749 * @param a alpha component
750 *
751 * @return this
752 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800753 public TriangleMeshBuilder setColor(float r, float g, float b, float a) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700754 if ((mFlags & COLOR) == 0) {
755 throw new IllegalStateException("add mistmatch with declared components.");
756 }
757 mR = r;
758 mG = g;
759 mB = b;
760 mA = a;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800761 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700762 }
763
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700764 /**
Jason Samse619de62012-05-08 18:40:58 -0700765 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800766 * Adds a new triangle to the mesh builder
767 *
768 * @param idx1 index of the first vertex in the triangle
769 * @param idx2 index of the second vertex in the triangle
770 * @param idx3 index of the third vertex in the triangle
771 *
772 * @return this
773 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000774 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800775 public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) {
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800776 if((idx1 >= mMaxIndex) || (idx1 < 0) ||
777 (idx2 >= mMaxIndex) || (idx2 < 0) ||
778 (idx3 >= mMaxIndex) || (idx3 < 0)) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700779 throw new IllegalStateException("Index provided greater than vertex count.");
780 }
781 if ((mIndexCount + 3) >= mIndexData.length) {
782 short t[] = new short[mIndexData.length * 2];
783 System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
784 mIndexData = t;
785 }
786 mIndexData[mIndexCount++] = (short)idx1;
787 mIndexData[mIndexCount++] = (short)idx2;
788 mIndexData[mIndexCount++] = (short)idx3;
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800789 return this;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700790 }
791
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700792 /**
Jason Samse619de62012-05-08 18:40:58 -0700793 * @deprecated in API 16
Alex Sakhartchoukdf272022011-01-09 11:34:03 -0800794 * Creates the mesh object from the current state of the builder
795 *
796 * @param uploadToBufferObject specifies whether the vertex data
797 * is to be uploaded into the buffer
798 * object indicating that it's likely
799 * not going to be modified and
800 * rendered many times.
801 * Alternatively, it indicates the
802 * mesh data will be updated
803 * frequently and remain in script
804 * accessible memory
805 *
806 **/
Mathew Inwood8e742f92020-10-27 11:47:29 +0000807 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700808 public Mesh create(boolean uploadToBufferObject) {
809 Element.Builder b = new Element.Builder(mRS);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700810 b.add(Element.createVector(mRS,
811 Element.DataType.FLOAT_32,
812 mVtxSize), "position");
813 if ((mFlags & COLOR) != 0) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700814 b.add(Element.F32_4(mRS), "color");
815 }
816 if ((mFlags & TEXTURE_0) != 0) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700817 b.add(Element.F32_2(mRS), "texture0");
818 }
819 if ((mFlags & NORMAL) != 0) {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700820 b.add(Element.F32_3(mRS), "normal");
821 }
822 mElement = b.create();
823
Jason Samsd1952402010-12-20 12:55:28 -0800824 int usage = Allocation.USAGE_SCRIPT;
825 if (uploadToBufferObject) {
826 usage |= Allocation.USAGE_GRAPHICS_VERTEX;
827 }
828
829 Builder smb = new Builder(mRS, usage);
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800830 smb.addVertexType(mElement, mMaxIndex);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800831 smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700832
833 Mesh sm = smb.create();
834
Alex Sakhartchouke60149d2011-11-15 15:15:21 -0800835 sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mMaxIndex, mVtxData);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700836 if(uploadToBufferObject) {
Andreas Gampe16720c12015-03-17 19:10:14 -0700837 sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700838 }
839
Jason Samsb97b2512011-01-16 15:04:08 -0800840 sm.getIndexSetAllocation(0).copy1DRangeFromUnchecked(0, mIndexCount, mIndexData);
Jason Samsd1952402010-12-20 12:55:28 -0800841 if (uploadToBufferObject) {
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800842 sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
Jason Samsd1952402010-12-20 12:55:28 -0800843 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700844
845 return sm;
846 }
847 }
848}
849