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