blob: 84a57ca50f7aff08b1fee9ff60bbeacea42d4420 [file] [log] [blame]
Jason Samsa89371c2009-06-30 14:13:04 -07001/*
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Samsa89371c2009-06-30 14:13:04 -07003 *
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 "RenderScript.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27
28// An element is a group of Components that occupies one cell in a structure.
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080029class Mesh : public ObjectBase {
Jason Samsa89371c2009-06-30 14:13:04 -070030public:
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070031 struct Hal {
32 mutable void *drv;
33
34 struct State {
35 // Contains vertex data
36 // Position, normal, texcoord, etc could either be strided in one allocation
37 // of provided separetely in multiple ones
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070038 Allocation **vertexBuffers;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070039 uint32_t vertexBuffersCount;
40
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070041 // indexBuffers[i] could be NULL, in which case only primitives[i] is used
42 Allocation **indexBuffers;
43 uint32_t indexBuffersCount;
44 RsPrimitive *primitives;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070045 uint32_t primitivesCount;
46 };
47 State state;
48 };
49 Hal mHal;
50
Alex Sakhartchouk253325d2011-12-15 09:56:10 -080051 Mesh(Context *);
52 Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
53 ~Mesh();
54
55 virtual void serialize(OStream *stream) const;
56 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
57 static Mesh *createFromStream(Context *rsc, IStream *stream);
58 void init();
59
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070060 void setVertexBuffer(Allocation *vb, uint32_t index) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070061 mVertexBuffers[index].set(vb);
62 mHal.state.vertexBuffers[index] = vb;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070063 }
64
65 void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070066 mIndexBuffers[index].set(idx);
67 mHal.state.indexBuffers[index] = idx;
68 mHal.state.primitives[index] = prim;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070069 }
70
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070071 void render(Context *) const;
72 void renderPrimitive(Context *, uint32_t primIndex) const;
73 void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
74 void uploadAll(Context *);
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070075
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -070076 // Bounding volumes
77 float mBBoxMin[3];
78 float mBBoxMax[3];
79 void computeBBox();
Jason Samsa89371c2009-06-30 14:13:04 -070080protected:
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070081 ObjectBaseRef<Allocation> *mVertexBuffers;
82 ObjectBaseRef<Allocation> *mIndexBuffers;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070083 bool mInitialized;
Jason Samsa89371c2009-06-30 14:13:04 -070084};
85
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080086class MeshContext {
Jason Samsa89371c2009-06-30 14:13:04 -070087public:
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -080088 MeshContext() {
89 }
90 ~MeshContext() {
91 }
Jason Samsa89371c2009-06-30 14:13:04 -070092};
93
Jason Samsa89371c2009-06-30 14:13:04 -070094}
95}
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070096#endif //ANDROID_RS_MESH_H
Jason Samsa89371c2009-06-30 14:13:04 -070097
98
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070099