Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 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 | |
Alex Sakhartchouk | e23d239 | 2012-03-09 09:24:39 -0800 | [diff] [blame] | 21 | #include "rsObjectBase.h" |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 26 | /***************************************************************************** |
| 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 Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 34 | |
| 35 | // An element is a group of Components that occupies one cell in a structure. |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 36 | class Mesh : public ObjectBase { |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 37 | public: |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 38 | 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 Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 45 | Allocation **vertexBuffers; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 46 | uint32_t vertexBuffersCount; |
| 47 | |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 48 | // indexBuffers[i] could be nullptr, in which case only primitives[i] is used |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 49 | Allocation **indexBuffers; |
| 50 | uint32_t indexBuffersCount; |
| 51 | RsPrimitive *primitives; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 52 | uint32_t primitivesCount; |
| 53 | }; |
| 54 | State state; |
| 55 | }; |
| 56 | Hal mHal; |
| 57 | |
Alex Sakhartchouk | 253325d | 2011-12-15 09:56:10 -0800 | [diff] [blame] | 58 | Mesh(Context *); |
| 59 | Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount); |
| 60 | ~Mesh(); |
| 61 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 62 | virtual void serialize(Context *rsc, OStream *stream) const; |
Alex Sakhartchouk | 253325d | 2011-12-15 09:56:10 -0800 | [diff] [blame] | 63 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; } |
| 64 | static Mesh *createFromStream(Context *rsc, IStream *stream); |
| 65 | void init(); |
| 66 | |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 67 | void setVertexBuffer(Allocation *vb, uint32_t index) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 68 | mVertexBuffers[index].set(vb); |
| 69 | mHal.state.vertexBuffers[index] = vb; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 73 | mIndexBuffers[index].set(idx); |
| 74 | mHal.state.indexBuffers[index] = idx; |
| 75 | mHal.state.primitives[index] = prim; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Alex Sakhartchouk | 4e9a7a8 | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 78 | 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 Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 82 | |
Alex Sakhartchouk | ba4aa5c | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 83 | // Bounding volumes |
| 84 | float mBBoxMin[3]; |
| 85 | float mBBoxMax[3]; |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 86 | void computeBBox(Context *rsc); |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 87 | protected: |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 88 | ObjectBaseRef<Allocation> *mVertexBuffers; |
| 89 | ObjectBaseRef<Allocation> *mIndexBuffers; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 90 | bool mInitialized; |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 93 | class MeshContext { |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 94 | public: |
Alex Sakhartchouk | 099d7d3 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 95 | MeshContext() { |
| 96 | } |
| 97 | ~MeshContext() { |
| 98 | } |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 103 | #endif //ANDROID_RS_MESH_H |
Jason Sams | a89371c | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 104 | |
| 105 | |
Alex Sakhartchouk | 4e9a7a8 | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 106 | |