blob: e0ce062e1c07e1bb058fc81115625ded4cebd4a3 [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
Alex Sakhartchouke23d2392012-03-09 09:24:39 -080021#include "rsObjectBase.h"
Jason Samsa89371c2009-06-30 14:13:04 -070022
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
Alex Sakhartchouk4a43e3e2011-12-28 13:47:05 -080026/*****************************************************************************
27 * CAUTION
28 *
29 * Any layout changes for this class may require a corresponding change to be
30 * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
31 * a partial copy of the information below.
32 *
33 *****************************************************************************/
Jason Samsa89371c2009-06-30 14:13:04 -070034
35// An element is a group of Components that occupies one cell in a structure.
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080036class Mesh : public ObjectBase {
Jason Samsa89371c2009-06-30 14:13:04 -070037public:
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070038 struct Hal {
39 mutable void *drv;
40
41 struct State {
42 // Contains vertex data
43 // Position, normal, texcoord, etc could either be strided in one allocation
44 // of provided separetely in multiple ones
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070045 Allocation **vertexBuffers;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070046 uint32_t vertexBuffersCount;
47
Chris Wailes44bef6f2014-08-12 13:51:10 -070048 // indexBuffers[i] could be nullptr, in which case only primitives[i] is used
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070049 Allocation **indexBuffers;
50 uint32_t indexBuffersCount;
51 RsPrimitive *primitives;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070052 uint32_t primitivesCount;
53 };
54 State state;
55 };
56 Hal mHal;
57
Chih-Hung Hsieh10ab8bb2016-07-01 12:20:20 -070058 explicit Mesh(Context *);
Alex Sakhartchouk253325d2011-12-15 09:56:10 -080059 Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
60 ~Mesh();
61
Jason Samse3150cf2012-07-24 18:10:20 -070062 virtual void serialize(Context *rsc, OStream *stream) const;
Alex Sakhartchouk253325d2011-12-15 09:56:10 -080063 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
64 static Mesh *createFromStream(Context *rsc, IStream *stream);
65 void init();
66
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070067 void setVertexBuffer(Allocation *vb, uint32_t index) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070068 mVertexBuffers[index].set(vb);
69 mHal.state.vertexBuffers[index] = vb;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070070 }
71
72 void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070073 mIndexBuffers[index].set(idx);
74 mHal.state.indexBuffers[index] = idx;
75 mHal.state.primitives[index] = prim;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070076 }
77
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -070078 void render(Context *) const;
79 void renderPrimitive(Context *, uint32_t primIndex) const;
80 void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
81 void uploadAll(Context *);
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070082
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -070083 // Bounding volumes
84 float mBBoxMin[3];
85 float mBBoxMax[3];
Jason Samse3150cf2012-07-24 18:10:20 -070086 void computeBBox(Context *rsc);
Jason Samsa89371c2009-06-30 14:13:04 -070087protected:
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070088 ObjectBaseRef<Allocation> *mVertexBuffers;
89 ObjectBaseRef<Allocation> *mIndexBuffers;
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
Rahul Chaudhry7974fc02017-02-09 12:33:28 -0800101} // namespace renderscript
102} // namespace android
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