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 android::renderscript::Mesh;
21 
rsaMeshGetVertexBufferCount(RsContext con,RsMesh mv,int32_t * numVtx)22 void rsaMeshGetVertexBufferCount(RsContext con, RsMesh mv, int32_t *numVtx) {
23     Mesh *sm = static_cast<Mesh *>(mv);
24     *numVtx = sm->mHal.state.vertexBuffersCount;
25 }
26 
rsaMeshGetIndexCount(RsContext con,RsMesh mv,int32_t * numIdx)27 void rsaMeshGetIndexCount(RsContext con, RsMesh mv, int32_t *numIdx) {
28     Mesh *sm = static_cast<Mesh *>(mv);
29     *numIdx = sm->mHal.state.primitivesCount;
30 }
31 
rsaMeshGetVertices(RsContext con,RsMesh mv,RsAllocation * vtxData,uint32_t vtxDataCount)32 void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_t vtxDataCount) {
33     Mesh *sm = static_cast<Mesh *>(mv);
34     rsAssert(vtxDataCount == sm->mHal.state.vertexBuffersCount);
35 
36     for (uint32_t ct = 0; ct < vtxDataCount; ct ++) {
37         vtxData[ct] = sm->mHal.state.vertexBuffers[ct];
38         sm->mHal.state.vertexBuffers[ct]->incUserRef();
39     }
40 }
41 
rsaMeshGetIndices(RsContext con,RsMesh mv,RsAllocation * va,uint32_t * primType,uint32_t idxDataCount)42 void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount) {
43     Mesh *sm = static_cast<Mesh *>(mv);
44     rsAssert(idxDataCount == sm->mHal.state.primitivesCount);
45 
46     for (uint32_t ct = 0; ct < idxDataCount; ct ++) {
47         va[ct] = sm->mHal.state.indexBuffers[ct];
48         primType[ct] = sm->mHal.state.primitives[ct];
49         if (sm->mHal.state.indexBuffers[ct]) {
50             sm->mHal.state.indexBuffers[ct]->incUserRef();
51         }
52     }
53 }
54