blob: 1e279f4d13201e07970851c554f3e3e805e53752 [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:
Jason Samse514b452009-09-25 14:51:22 -070031 Mesh(Context *);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070032 Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
Jason Samsa89371c2009-06-30 14:13:04 -070033 ~Mesh();
34
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070035 // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference
36 // If both are null, mPrimitive only would be used to render the mesh
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070037 struct Primitive_t {
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070038 ObjectBaseRef<Allocation> mIndexBuffer;
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070039 RsPrimitive mPrimitive;
Jason Samsa89371c2009-06-30 14:13:04 -070040 };
41
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070042 // compatibility to not break the build
43 ObjectBaseRef<Allocation> *mVertexBuffers;
44 uint32_t mVertexBufferCount;
Jason Samsa5597fc2009-07-08 18:01:53 -070045 Primitive_t ** mPrimitives;
46 uint32_t mPrimitivesCount;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070047 // end compatibility
Jason Samsa5597fc2009-07-08 18:01:53 -070048
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -080049 virtual void serialize(OStream *stream) const;
50 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
51 static Mesh *createFromStream(Context *rsc, IStream *stream);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070052 void init();
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -080053
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070054 struct Hal {
55 mutable void *drv;
56
57 struct State {
58 // Contains vertex data
59 // Position, normal, texcoord, etc could either be strided in one allocation
60 // of provided separetely in multiple ones
61 ObjectBaseRef<Allocation> *vertexBuffers;
62 uint32_t vertexBuffersCount;
63
64 Primitive_t ** primitives;
65 uint32_t primitivesCount;
66 };
67 State state;
68 };
69 Hal mHal;
70
71 void setVertexBuffer(Allocation *vb, uint32_t index) {
72 mHal.state.vertexBuffers[index].set(vb);
73 }
74
75 void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
76 mHal.state.primitives[index]->mIndexBuffer.set(idx);
77 mHal.state.primitives[index]->mPrimitive = prim;
78 }
79
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070080 void render(Context *) const;
81 void renderPrimitive(Context *, uint32_t primIndex) const;
82 void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
83 void uploadAll(Context *);
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070084
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -070085 // Bounding volumes
86 float mBBoxMin[3];
87 float mBBoxMax[3];
88 void computeBBox();
Jason Samsa89371c2009-06-30 14:13:04 -070089protected:
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070090 bool mInitialized;
Jason Samsa89371c2009-06-30 14:13:04 -070091};
92
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080093class MeshContext {
Jason Samsa89371c2009-06-30 14:13:04 -070094public:
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -080095 MeshContext() {
96 }
97 ~MeshContext() {
98 }
Jason Samsa89371c2009-06-30 14:13:04 -070099};
100
Jason Samsa89371c2009-06-30 14:13:04 -0700101}
102}
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700103#endif //ANDROID_RS_MESH_H
Jason Samsa89371c2009-06-30 14:13:04 -0700104
105
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700106