Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | 7c878f3 | 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 | |
| 21 | #include "RenderScript.h" |
| 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | |
| 28 | // An element is a group of Components that occupies one cell in a structure. |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 29 | class Mesh : public ObjectBase { |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 30 | public: |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 31 | Mesh(Context *); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 32 | Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount); |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 33 | ~Mesh(); |
| 34 | |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 35 | virtual void serialize(OStream *stream) const; |
| 36 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; } |
| 37 | static Mesh *createFromStream(Context *rsc, IStream *stream); |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 38 | void init(); |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 39 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 40 | struct Hal { |
| 41 | mutable void *drv; |
| 42 | |
| 43 | struct State { |
| 44 | // Contains vertex data |
| 45 | // Position, normal, texcoord, etc could either be strided in one allocation |
| 46 | // of provided separetely in multiple ones |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 47 | Allocation **vertexBuffers; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 48 | uint32_t vertexBuffersCount; |
| 49 | |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 50 | // indexBuffers[i] could be NULL, in which case only primitives[i] is used |
| 51 | Allocation **indexBuffers; |
| 52 | uint32_t indexBuffersCount; |
| 53 | RsPrimitive *primitives; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 54 | uint32_t primitivesCount; |
| 55 | }; |
| 56 | State state; |
| 57 | }; |
| 58 | Hal mHal; |
| 59 | |
| 60 | void setVertexBuffer(Allocation *vb, uint32_t index) { |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 61 | mVertexBuffers[index].set(vb); |
| 62 | mHal.state.vertexBuffers[index] = vb; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) { |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 66 | mIndexBuffers[index].set(idx); |
| 67 | mHal.state.indexBuffers[index] = idx; |
| 68 | mHal.state.primitives[index] = prim; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 71 | void render(Context *) const; |
| 72 | void renderPrimitive(Context *, uint32_t primIndex) const; |
| 73 | void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const; |
| 74 | void uploadAll(Context *); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 75 | |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 76 | // Bounding volumes |
| 77 | float mBBoxMin[3]; |
| 78 | float mBBoxMax[3]; |
| 79 | void computeBBox(); |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 80 | protected: |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 81 | ObjectBaseRef<Allocation> *mVertexBuffers; |
| 82 | ObjectBaseRef<Allocation> *mIndexBuffers; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 83 | bool mInitialized; |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 86 | class MeshContext { |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 87 | public: |
Alex Sakhartchouk | a3b5960 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 88 | MeshContext() { |
| 89 | } |
| 90 | ~MeshContext() { |
| 91 | } |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 96 | #endif //ANDROID_RS_MESH_H |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 97 | |
| 98 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 99 | |