blob: 261b5a6b49c1943afc83dbcbbc4dbb53e4aad084 [file] [log] [blame]
Jason Samsa89371c2009-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.
29class Mesh : public ObjectBase
30{
31public:
Jason Samse514b452009-09-25 14:51:22 -070032 Mesh(Context *);
Jason Samsa89371c2009-06-30 14:13:04 -070033 ~Mesh();
34
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070035 // Contains vertex data
36 // Position, normal, texcoord, etc could either be strided in one allocation
37 // of provided separetely in multiple ones
38 ObjectBaseRef<Allocation> *mVertexBuffers;
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070039 uint32_t mVertexBufferCount;
Jason Samsa5597fc2009-07-08 18:01:53 -070040
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070041 // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference
42 // If both are null, mPrimitive only would be used to render the mesh
Jason Samsa89371c2009-06-30 14:13:04 -070043 struct Primitive_t
44 {
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070045 ObjectBaseRef<Allocation> mIndexBuffer;
Jason Samsa89371c2009-06-30 14:13:04 -070046
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070047 RsPrimitive mPrimitive;
48 uint32_t mGLPrimitive;
Jason Samsa89371c2009-06-30 14:13:04 -070049 };
50
Jason Samsa5597fc2009-07-08 18:01:53 -070051 Primitive_t ** mPrimitives;
52 uint32_t mPrimitivesCount;
53
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070054 void render(Context *) const;
55 void renderPrimitive(Context *, uint32_t primIndex) const;
56 void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
57 void uploadAll(Context *);
58 void updateGLPrimitives();
59
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070060 virtual void serialize(OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070061 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070062 static Mesh *createFromStream(Context *rsc, IStream *stream);
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070063
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -070064 // Bounding volumes
65 float mBBoxMin[3];
66 float mBBoxMax[3];
67 void computeBBox();
68
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -080069 void initVertexAttribs();
70
Jason Samsa89371c2009-06-30 14:13:04 -070071protected:
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -080072 bool isValidGLComponent(const Element *elem, uint32_t fieldIdx);
73 // Attribues that allow us to map to GL
74 VertexArray::Attrib *mAttribs;
75 // This allows us to figure out which allocation the attribute
76 // belongs to. In the event the allocation is uploaded to GL
77 // buffer, it lets us properly map it
78 uint32_t *mAttribAllocationIndex;
79 uint32_t mAttribCount;
Jason Samsa89371c2009-06-30 14:13:04 -070080};
81
82class MeshContext
83{
84public:
85 MeshContext();
86 ~MeshContext();
87
88};
89
90
91}
92}
93#endif //ANDROID_RS_TRIANGLE_MESH_H
94
95
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070096