blob: 3e080e2aabb9b1f89d0420c694e64841c78cd29c [file] [log] [blame]
Jason Sams7c878f32009-06-30 14:13:04 -07001/*
2 * Copyright (C) 2009 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 "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 Sakhartchouked9f2102010-11-09 17:00:54 -080029class Mesh : public ObjectBase {
Jason Sams7c878f32009-06-30 14:13:04 -070030public:
Jason Samsa9e7a052009-09-25 14:51:22 -070031 Mesh(Context *);
Jason Sams7c878f32009-06-30 14:13:04 -070032 ~Mesh();
33
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070034 // Contains vertex data
35 // Position, normal, texcoord, etc could either be strided in one allocation
36 // of provided separetely in multiple ones
37 ObjectBaseRef<Allocation> *mVertexBuffers;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070038 uint32_t mVertexBufferCount;
Jason Sams64676f32009-07-08 18:01:53 -070039
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070040 // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference
41 // If both are null, mPrimitive only would be used to render the mesh
Jason Sams7c878f32009-06-30 14:13:04 -070042 struct Primitive_t
43 {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070044 ObjectBaseRef<Allocation> mIndexBuffer;
Jason Sams7c878f32009-06-30 14:13:04 -070045
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070046 RsPrimitive mPrimitive;
47 uint32_t mGLPrimitive;
Jason Sams7c878f32009-06-30 14:13:04 -070048 };
49
Jason Sams64676f32009-07-08 18:01:53 -070050 Primitive_t ** mPrimitives;
51 uint32_t mPrimitivesCount;
52
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080053 virtual void serialize(OStream *stream) const;
54 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
55 static Mesh *createFromStream(Context *rsc, IStream *stream);
56
Alex Sakhartchoukd0f5bd12011-01-31 14:53:24 -080057#ifndef ANDROID_RS_SERIALIZE
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070058 void render(Context *) const;
59 void renderPrimitive(Context *, uint32_t primIndex) const;
60 void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
61 void uploadAll(Context *);
62 void updateGLPrimitives();
63
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080064
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -070065
Alex Sakhartchouka80145d2010-08-13 14:32:23 -070066 // Bounding volumes
67 float mBBoxMin[3];
68 float mBBoxMax[3];
69 void computeBBox();
70
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -080071 void initVertexAttribs();
72
Jason Sams7c878f32009-06-30 14:13:04 -070073protected:
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -080074 bool isValidGLComponent(const Element *elem, uint32_t fieldIdx);
75 // Attribues that allow us to map to GL
76 VertexArray::Attrib *mAttribs;
77 // This allows us to figure out which allocation the attribute
78 // belongs to. In the event the allocation is uploaded to GL
79 // buffer, it lets us properly map it
80 uint32_t *mAttribAllocationIndex;
81 uint32_t mAttribCount;
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080082#endif
Jason Sams7c878f32009-06-30 14:13:04 -070083};
84
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080085class MeshContext {
Jason Sams7c878f32009-06-30 14:13:04 -070086public:
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080087 MeshContext() {
88 }
89 ~MeshContext() {
90 }
Jason Sams7c878f32009-06-30 14:13:04 -070091};
92
Jason Sams7c878f32009-06-30 14:13:04 -070093}
94}
95#endif //ANDROID_RS_TRIANGLE_MESH_H
96
97
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070098