Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 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 | |
| 17 | #include "rsContext.h" |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 19 | using namespace android; |
| 20 | using namespace android::renderscript; |
| 21 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 22 | Mesh::Mesh(Context *rsc) : ObjectBase(rsc) { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 23 | mHal.drv = NULL; |
| 24 | mHal.state.primitives = NULL; |
| 25 | mHal.state.primitivesCount = 0; |
| 26 | mHal.state.vertexBuffers = NULL; |
| 27 | mHal.state.vertexBuffersCount = 0; |
| 28 | mInitialized = false; |
| 29 | } |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 30 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 31 | Mesh::Mesh(Context *rsc, |
| 32 | uint32_t vertexBuffersCount, |
| 33 | uint32_t primitivesCount) : ObjectBase(rsc) { |
| 34 | mHal.drv = NULL; |
| 35 | mHal.state.primitivesCount = primitivesCount; |
| 36 | mHal.state.primitives = new Primitive_t *[mHal.state.primitivesCount]; |
| 37 | for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) { |
| 38 | mHal.state.primitives[i] = new Primitive_t; |
| 39 | } |
| 40 | mHal.state.vertexBuffersCount = vertexBuffersCount; |
| 41 | mHal.state.vertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount]; |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 44 | Mesh::~Mesh() { |
Alex Sakhartchouk | d0f5bd1 | 2011-01-31 14:53:24 -0800 | [diff] [blame] | 45 | #ifndef ANDROID_RS_SERIALIZE |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 46 | mRSC->mHal.funcs.mesh.destroy(mRSC, this); |
| 47 | #endif |
| 48 | |
| 49 | if (mHal.state.vertexBuffers) { |
| 50 | delete[] mHal.state.vertexBuffers; |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 51 | } |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 52 | |
| 53 | if (mHal.state.primitives) { |
| 54 | for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) { |
| 55 | mHal.state.primitives[i]->mIndexBuffer.clear(); |
| 56 | delete mHal.state.primitives[i]; |
| 57 | } |
| 58 | delete[] mHal.state.primitives; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void Mesh::init() { |
| 63 | #ifndef ANDROID_RS_SERIALIZE |
| 64 | mRSC->mHal.funcs.mesh.init(mRSC, this); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 65 | #endif |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 68 | void Mesh::serialize(OStream *stream) const { |
| 69 | // Need to identify ourselves |
| 70 | stream->addU32((uint32_t)getClassId()); |
| 71 | |
| 72 | String8 name(getName()); |
| 73 | stream->addString(&name); |
| 74 | |
| 75 | // Store number of vertex streams |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 76 | stream->addU32(mHal.state.vertexBuffersCount); |
| 77 | for (uint32_t vCount = 0; vCount < mHal.state.vertexBuffersCount; vCount ++) { |
| 78 | mHal.state.vertexBuffers[vCount]->serialize(stream); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 81 | stream->addU32(mHal.state.primitivesCount); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 82 | // Store the primitives |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 83 | for (uint32_t pCount = 0; pCount < mHal.state.primitivesCount; pCount ++) { |
| 84 | Primitive_t * prim = mHal.state.primitives[pCount]; |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 85 | |
| 86 | stream->addU8((uint8_t)prim->mPrimitive); |
| 87 | |
| 88 | if (prim->mIndexBuffer.get()) { |
| 89 | stream->addU32(1); |
| 90 | prim->mIndexBuffer->serialize(stream); |
| 91 | } else { |
| 92 | stream->addU32(0); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | Mesh *Mesh::createFromStream(Context *rsc, IStream *stream) { |
| 98 | // First make sure we are reading the correct object |
| 99 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
| 100 | if (classID != RS_A3D_CLASS_ID_MESH) { |
| 101 | LOGE("mesh loading skipped due to invalid class id"); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 105 | String8 name; |
| 106 | stream->loadString(&name); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 107 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 108 | uint32_t vertexBuffersCount = stream->loadU32(); |
| 109 | ObjectBaseRef<Allocation> *vertexBuffers = NULL; |
| 110 | if (vertexBuffersCount) { |
| 111 | vertexBuffers = new ObjectBaseRef<Allocation>[vertexBuffersCount]; |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 112 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 113 | for (uint32_t vCount = 0; vCount < vertexBuffersCount; vCount ++) { |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 114 | Allocation *vertexAlloc = Allocation::createFromStream(rsc, stream); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 115 | vertexBuffers[vCount].set(vertexAlloc); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 119 | uint32_t primitivesCount = stream->loadU32(); |
| 120 | ObjectBaseRef<Allocation> *indexBuffers = NULL; |
| 121 | RsPrimitive *primitives = NULL; |
| 122 | if (primitivesCount) { |
| 123 | indexBuffers = new ObjectBaseRef<Allocation>[primitivesCount]; |
| 124 | primitives = new RsPrimitive[primitivesCount]; |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 125 | |
| 126 | // load all primitives |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 127 | for (uint32_t pCount = 0; pCount < primitivesCount; pCount ++) { |
| 128 | primitives[pCount] = (RsPrimitive)stream->loadU8(); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 129 | |
| 130 | // Check to see if the index buffer was stored |
| 131 | uint32_t isIndexPresent = stream->loadU32(); |
| 132 | if (isIndexPresent) { |
| 133 | Allocation *indexAlloc = Allocation::createFromStream(rsc, stream); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 134 | indexBuffers[pCount].set(indexAlloc); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 139 | Mesh *mesh = new Mesh(rsc, vertexBuffersCount, primitivesCount); |
| 140 | mesh->setName(name.string(), name.size()); |
| 141 | for (uint32_t vCount = 0; vCount < vertexBuffersCount; vCount ++) { |
| 142 | mesh->setVertexBuffer(vertexBuffers[vCount].get(), vCount); |
| 143 | } |
| 144 | for (uint32_t pCount = 0; pCount < primitivesCount; pCount ++) { |
| 145 | mesh->setPrimitive(indexBuffers[pCount].get(), primitives[pCount], pCount); |
| 146 | } |
| 147 | |
| 148 | // Cleanup |
| 149 | if (vertexBuffersCount) { |
| 150 | delete[] vertexBuffers; |
| 151 | } |
| 152 | if (primitivesCount) { |
| 153 | delete[] indexBuffers; |
| 154 | delete[] primitives; |
| 155 | } |
| 156 | |
Alex Sakhartchouk | d0f5bd1 | 2011-01-31 14:53:24 -0800 | [diff] [blame] | 157 | #ifndef ANDROID_RS_SERIALIZE |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 158 | mesh->init(); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 159 | mesh->uploadAll(rsc); |
| 160 | #endif |
| 161 | return mesh; |
| 162 | } |
| 163 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 164 | void Mesh::render(Context *rsc) const { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 165 | for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) { |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 166 | renderPrimitive(rsc, ct); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | void Mesh::renderPrimitive(Context *rsc, uint32_t primIndex) const { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 171 | if (primIndex >= mHal.state.primitivesCount) { |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 172 | LOGE("Invalid primitive index"); |
| 173 | return; |
| 174 | } |
| 175 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 176 | Primitive_t *prim = mHal.state.primitives[primIndex]; |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 177 | |
| 178 | if (prim->mIndexBuffer.get()) { |
| 179 | renderPrimitiveRange(rsc, primIndex, 0, prim->mIndexBuffer->getType()->getDimX()); |
| 180 | return; |
| 181 | } |
| 182 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 183 | renderPrimitiveRange(rsc, primIndex, 0, mHal.state.vertexBuffers[0]->getType()->getDimX()); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 186 | void Mesh::renderPrimitiveRange(Context *rsc, uint32_t primIndex, uint32_t start, uint32_t len) const { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 187 | if (len < 1 || primIndex >= mHal.state.primitivesCount) { |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 188 | LOGE("Invalid mesh or parameters"); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 189 | return; |
| 190 | } |
| 191 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 192 | mRSC->mHal.funcs.mesh.draw(mRSC, this, primIndex, start, len); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 195 | void Mesh::uploadAll(Context *rsc) { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 196 | for (uint32_t ct = 0; ct < mHal.state.vertexBuffersCount; ct ++) { |
| 197 | if (mHal.state.vertexBuffers[ct].get()) { |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 198 | rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct].get()); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 202 | for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) { |
| 203 | if (mHal.state.primitives[ct]->mIndexBuffer.get()) { |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 204 | rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.primitives[ct]->mIndexBuffer.get()); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 209 | void Mesh::computeBBox() { |
| 210 | float *posPtr = NULL; |
| 211 | uint32_t vectorSize = 0; |
| 212 | uint32_t stride = 0; |
| 213 | uint32_t numVerts = 0; |
| 214 | // First we need to find the position ptr and stride |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 215 | for (uint32_t ct=0; ct < mHal.state.vertexBuffersCount; ct++) { |
| 216 | const Type *bufferType = mHal.state.vertexBuffers[ct]->getType(); |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 217 | const Element *bufferElem = bufferType->getElement(); |
| 218 | |
| 219 | for (uint32_t ct=0; ct < bufferElem->getFieldCount(); ct++) { |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 220 | if (strcmp(bufferElem->getFieldName(ct), "position") == 0) { |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 221 | vectorSize = bufferElem->getField(ct)->getComponent().getVectorSize(); |
| 222 | stride = bufferElem->getSizeBytes() / sizeof(float); |
| 223 | uint32_t offset = bufferElem->getFieldOffsetBytes(ct); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 224 | posPtr = (float*)((uint8_t*)mHal.state.vertexBuffers[ct]->getPtr() + offset); |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 225 | numVerts = bufferType->getDimX(); |
| 226 | break; |
| 227 | } |
| 228 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 229 | if (posPtr) { |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | mBBoxMin[0] = mBBoxMin[1] = mBBoxMin[2] = 1e6; |
| 235 | mBBoxMax[0] = mBBoxMax[1] = mBBoxMax[2] = -1e6; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 236 | if (!posPtr) { |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 237 | LOGE("Unable to compute bounding box"); |
| 238 | mBBoxMin[0] = mBBoxMin[1] = mBBoxMin[2] = 0.0f; |
| 239 | mBBoxMax[0] = mBBoxMax[1] = mBBoxMax[2] = 0.0f; |
| 240 | return; |
| 241 | } |
| 242 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 243 | for (uint32_t i = 0; i < numVerts; i ++) { |
| 244 | for (uint32_t v = 0; v < vectorSize; v ++) { |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 245 | mBBoxMin[v] = rsMin(mBBoxMin[v], posPtr[v]); |
| 246 | mBBoxMax[v] = rsMax(mBBoxMax[v], posPtr[v]); |
| 247 | } |
| 248 | posPtr += stride; |
| 249 | } |
| 250 | } |
| 251 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 252 | namespace android { |
| 253 | namespace renderscript { |
| 254 | |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 255 | RsMesh rsi_MeshCreate(Context *rsc, |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 256 | RsAllocation * vtx, size_t vtxCount, |
| 257 | RsAllocation * idx, size_t idxCount, |
| 258 | uint32_t * primType, size_t primTypeCount) { |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 259 | rsAssert(idxCount == primTypeCount); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 260 | Mesh *sm = new Mesh(rsc, vtxCount, idxCount); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 261 | sm->incUserRef(); |
| 262 | |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 263 | for (uint32_t i = 0; i < vtxCount; i ++) { |
| 264 | sm->setVertexBuffer((Allocation*)vtx[i], i); |
| 265 | } |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 266 | |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 267 | for (uint32_t i = 0; i < idxCount; i ++) { |
| 268 | sm->setPrimitive((Allocation*)idx[i], (RsPrimitive)primType[i], i); |
| 269 | } |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 270 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 271 | sm->init(); |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 272 | |
| 273 | return sm; |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 276 | }} |
| 277 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 278 | void rsaMeshGetVertexBufferCount(RsContext con, RsMesh mv, int32_t *numVtx) { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 279 | Mesh *sm = static_cast<Mesh *>(mv); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 280 | *numVtx = sm->mHal.state.vertexBuffersCount; |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 283 | void rsaMeshGetIndexCount(RsContext con, RsMesh mv, int32_t *numIdx) { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 284 | Mesh *sm = static_cast<Mesh *>(mv); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 285 | *numIdx = sm->mHal.state.primitivesCount; |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 288 | void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_t vtxDataCount) { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 289 | Mesh *sm = static_cast<Mesh *>(mv); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 290 | rsAssert(vtxDataCount == sm->mHal.state.vertexBuffersCount); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 291 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 292 | for (uint32_t ct = 0; ct < vtxDataCount; ct ++) { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 293 | vtxData[ct] = sm->mHal.state.vertexBuffers[ct].get(); |
| 294 | sm->mHal.state.vertexBuffers[ct]->incUserRef(); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 298 | void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount) { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 299 | Mesh *sm = static_cast<Mesh *>(mv); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 300 | rsAssert(idxDataCount == sm->mHal.state.primitivesCount); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 301 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 302 | for (uint32_t ct = 0; ct < idxDataCount; ct ++) { |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 303 | va[ct] = sm->mHal.state.primitives[ct]->mIndexBuffer.get(); |
| 304 | primType[ct] = sm->mHal.state.primitives[ct]->mPrimitive; |
| 305 | if (sm->mHal.state.primitives[ct]->mIndexBuffer.get()) { |
| 306 | sm->mHal.state.primitives[ct]->mIndexBuffer->incUserRef(); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 309 | } |