1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "rsContext.h"
18 #include "rsMesh.h"
19 
20 using namespace android;
21 using namespace android::renderscript;
22 
rsaMeshGetVertexBufferCount(RsContext con,RsMesh mv,int32_t * numVtx)23 void rsaMeshGetVertexBufferCount(RsContext con, RsMesh mv, int32_t *numVtx) {
24     Mesh *sm = static_cast<Mesh *>(mv);
25     *numVtx = sm->mHal.state.vertexBuffersCount;
26 }
27 
rsaMeshGetIndexCount(RsContext con,RsMesh mv,int32_t * numIdx)28 void rsaMeshGetIndexCount(RsContext con, RsMesh mv, int32_t *numIdx) {
29     Mesh *sm = static_cast<Mesh *>(mv);
30     *numIdx = sm->mHal.state.primitivesCount;
31 }
32 
rsaMeshGetVertices(RsContext con,RsMesh mv,RsAllocation * vtxData,uint32_t vtxDataCount)33 void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_t vtxDataCount) {
34     Mesh *sm = static_cast<Mesh *>(mv);
35     rsAssert(vtxDataCount == sm->mHal.state.vertexBuffersCount);
36 
37     for (uint32_t ct = 0; ct < vtxDataCount; ct ++) {
38         vtxData[ct] = sm->mHal.state.vertexBuffers[ct];
39         sm->mHal.state.vertexBuffers[ct]->incUserRef();
40     }
41 }
42 
rsaMeshGetIndices(RsContext con,RsMesh mv,RsAllocation * va,uint32_t * primType,uint32_t idxDataCount)43 void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount) {
44     Mesh *sm = static_cast<Mesh *>(mv);
45     rsAssert(idxDataCount == sm->mHal.state.primitivesCount);
46 
47     for (uint32_t ct = 0; ct < idxDataCount; ct ++) {
48         va[ct] = sm->mHal.state.indexBuffers[ct];
49         primType[ct] = sm->mHal.state.primitives[ct];
50         if (sm->mHal.state.indexBuffers[ct]) {
51             sm->mHal.state.indexBuffers[ct]->incUserRef();
52         }
53     }
54 }
55