Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 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 *); |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 32 | ~Mesh(); |
| 33 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 34 | // Contains vertex data |
| 35 | // Position, normal, texcoord, etc could either be strided in one allocation |
| 36 | // of provided separetely in multiple ones |
| 37 | ObjectBaseRef<Allocation> *mVertexBuffers; |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 38 | uint32_t mVertexBufferCount; |
Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 39 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 40 | // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference |
| 41 | // If both are null, mPrimitive only would be used to render the mesh |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 42 | struct Primitive_t |
| 43 | { |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 44 | ObjectBaseRef<Allocation> mIndexBuffer; |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 45 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 46 | RsPrimitive mPrimitive; |
| 47 | uint32_t mGLPrimitive; |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 50 | Primitive_t ** mPrimitives; |
| 51 | uint32_t mPrimitivesCount; |
| 52 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 53 | void render(Context *) const; |
| 54 | void renderPrimitive(Context *, uint32_t primIndex) const; |
| 55 | void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const; |
| 56 | void uploadAll(Context *); |
| 57 | void updateGLPrimitives(); |
| 58 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 59 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 60 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 61 | static Mesh *createFromStream(Context *rsc, IStream *stream); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 62 | |
Alex Sakhartchouk | a80145d | 2010-08-13 14:32:23 -0700 | [diff] [blame] | 63 | // Bounding volumes |
| 64 | float mBBoxMin[3]; |
| 65 | float mBBoxMax[3]; |
| 66 | void computeBBox(); |
| 67 | |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 68 | void initVertexAttribs(); |
| 69 | |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 70 | protected: |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 71 | bool isValidGLComponent(const Element *elem, uint32_t fieldIdx); |
| 72 | // Attribues that allow us to map to GL |
| 73 | VertexArray::Attrib *mAttribs; |
| 74 | // This allows us to figure out which allocation the attribute |
| 75 | // belongs to. In the event the allocation is uploaded to GL |
| 76 | // buffer, it lets us properly map it |
| 77 | uint32_t *mAttribAllocationIndex; |
| 78 | uint32_t mAttribCount; |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame^] | 81 | class MeshContext { |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 82 | public: |
| 83 | MeshContext(); |
| 84 | ~MeshContext(); |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | #endif //ANDROID_RS_TRIANGLE_MESH_H |
| 90 | |
| 91 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 92 | |