blob: ed1e93d6395459f44d4c7513aea77065da7d182a [file] [log] [blame]
Jason Sams7c878f32009-06-30 14:13:04 -07001/*
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Sams7c878f32009-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 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 *);
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -070032 Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
Jason Sams7c878f32009-06-30 14:13:04 -070033 ~Mesh();
34
Alex Sakhartchouk164aaed2010-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 Sakhartchouk4a36b452011-04-29 16:49:08 -070037 struct Primitive_t {
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070038 ObjectBaseRef<Allocation> mIndexBuffer;
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070039 RsPrimitive mPrimitive;
Jason Sams7c878f32009-06-30 14:13:04 -070040 };
41
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080042 virtual void serialize(OStream *stream) const;
43 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
44 static Mesh *createFromStream(Context *rsc, IStream *stream);
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -070045 void init();
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080046
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -070047 struct Hal {
48 mutable void *drv;
49
50 struct State {
51 // Contains vertex data
52 // Position, normal, texcoord, etc could either be strided in one allocation
53 // of provided separetely in multiple ones
54 ObjectBaseRef<Allocation> *vertexBuffers;
55 uint32_t vertexBuffersCount;
56
57 Primitive_t ** primitives;
58 uint32_t primitivesCount;
59 };
60 State state;
61 };
62 Hal mHal;
63
64 void setVertexBuffer(Allocation *vb, uint32_t index) {
65 mHal.state.vertexBuffers[index].set(vb);
66 }
67
68 void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
69 mHal.state.primitives[index]->mIndexBuffer.set(idx);
70 mHal.state.primitives[index]->mPrimitive = prim;
71 }
72
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070073 void render(Context *) const;
74 void renderPrimitive(Context *, uint32_t primIndex) const;
75 void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
76 void uploadAll(Context *);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -070077
Alex Sakhartchouka80145d2010-08-13 14:32:23 -070078 // Bounding volumes
79 float mBBoxMin[3];
80 float mBBoxMax[3];
81 void computeBBox();
Jason Sams7c878f32009-06-30 14:13:04 -070082protected:
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -070083 bool mInitialized;
Jason Sams7c878f32009-06-30 14:13:04 -070084};
85
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080086class MeshContext {
Jason Sams7c878f32009-06-30 14:13:04 -070087public:
Alex Sakhartchouka3b59602011-01-28 09:31:47 -080088 MeshContext() {
89 }
90 ~MeshContext() {
91 }
Jason Sams7c878f32009-06-30 14:13:04 -070092};
93
Jason Sams7c878f32009-06-30 14:13:04 -070094}
95}
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -070096#endif //ANDROID_RS_MESH_H
Jason Sams7c878f32009-06-30 14:13:04 -070097
98
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -070099