1 /*
2  * Copyright (C) 2011 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 #ifndef ANDROID_RS_MESH_H
18 #define ANDROID_RS_MESH_H
19 
20 
21 #include "rsObjectBase.h"
22 
23 // ---------------------------------------------------------------------------
24 namespace android {
25 namespace renderscript {
26 /*****************************************************************************
27  * CAUTION
28  *
29  * Any layout changes for this class may require a corresponding change to be
30  * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
31  * a partial copy of the information below.
32  *
33  *****************************************************************************/
34 
35 // An element is a group of Components that occupies one cell in a structure.
36 class Mesh : public ObjectBase {
37 public:
38     struct Hal {
39         mutable void *drv;
40 
41         struct State {
42             // Contains vertex data
43             // Position, normal, texcoord, etc could either be strided in one allocation
44             // of provided separetely in multiple ones
45             Allocation **vertexBuffers;
46             uint32_t vertexBuffersCount;
47 
48             // indexBuffers[i] could be nullptr, in which case only primitives[i] is used
49             Allocation **indexBuffers;
50             uint32_t indexBuffersCount;
51             RsPrimitive *primitives;
52             uint32_t primitivesCount;
53         };
54         State state;
55     };
56     Hal mHal;
57 
58     explicit Mesh(Context *);
59     Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
60     ~Mesh();
61 
62     virtual void serialize(Context *rsc, OStream *stream) const;
getClassId()63     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
64     static Mesh *createFromStream(Context *rsc, IStream *stream);
65     void init();
66 
setVertexBuffer(Allocation * vb,uint32_t index)67     void setVertexBuffer(Allocation *vb, uint32_t index) {
68         mVertexBuffers[index].set(vb);
69         mHal.state.vertexBuffers[index] = vb;
70     }
71 
setPrimitive(Allocation * idx,RsPrimitive prim,uint32_t index)72     void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
73         mIndexBuffers[index].set(idx);
74         mHal.state.indexBuffers[index] = idx;
75         mHal.state.primitives[index] = prim;
76     }
77 
78     void render(Context *) const;
79     void renderPrimitive(Context *, uint32_t primIndex) const;
80     void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
81     void uploadAll(Context *);
82 
83     // Bounding volumes
84     float mBBoxMin[3];
85     float mBBoxMax[3];
86     void computeBBox(Context *rsc);
87 protected:
88     ObjectBaseRef<Allocation> *mVertexBuffers;
89     ObjectBaseRef<Allocation> *mIndexBuffers;
90     bool mInitialized;
91 };
92 
93 class MeshContext {
94 public:
MeshContext()95     MeshContext() {
96     }
~MeshContext()97     ~MeshContext() {
98     }
99 };
100 
101 } // namespace renderscript
102 } // namespace android
103 #endif //ANDROID_RS_MESH_H
104 
105 
106 
107