Jason Sams | 326e0dd | 2009-05-22 14:03:28 -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_STRUCTURED_TYPE_H |
| 18 | #define ANDROID_STRUCTURED_TYPE_H |
| 19 | |
| 20 | #include "rsElement.h" |
| 21 | |
| 22 | // --------------------------------------------------------------------------- |
| 23 | namespace android { |
| 24 | namespace renderscript { |
| 25 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 26 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | class Type : public ObjectBase |
| 28 | { |
| 29 | public: |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame^] | 30 | Type(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | virtual ~Type(); |
| 32 | |
| 33 | Type * createTex2D(const Element *, size_t w, size_t h, bool mip); |
| 34 | |
| 35 | |
| 36 | size_t getOffsetForFace(uint32_t face) const; |
| 37 | |
| 38 | size_t getSizeBytes() const {return mTotalSizeBytes;} |
| 39 | size_t getElementSizeBytes() const {return mElement->getSizeBytes();} |
| 40 | const Element * getElement() const {return mElement.get();} |
| 41 | |
| 42 | uint32_t getDimX() const {return mDimX;} |
| 43 | uint32_t getDimY() const {return mDimY;} |
| 44 | uint32_t getDimZ() const {return mDimZ;} |
| 45 | uint32_t getDimLOD() const {return mDimLOD;} |
| 46 | bool getDimFaces() const {return mFaces;} |
| 47 | |
| 48 | uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;} |
| 49 | uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;} |
| 50 | uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;} |
| 51 | uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;} |
| 52 | |
| 53 | uint32_t getLODOffset(uint32_t lod, uint32_t x) const; |
| 54 | uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const; |
| 55 | uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const; |
| 56 | |
| 57 | uint32_t getLODCount() const {return mLODCount;} |
| 58 | |
| 59 | |
| 60 | void setElement(const Element *e) {mElement.set(e);} |
| 61 | void setDimX(uint32_t v) {mDimX = v;} |
| 62 | void setDimY(uint32_t v) {mDimY = v;} |
| 63 | void setDimZ(uint32_t v) {mDimZ = v;} |
| 64 | void setDimFaces(bool v) {mFaces = v;} |
| 65 | void setDimLOD(bool v) {mDimLOD = v;} |
| 66 | |
| 67 | void clear(); |
| 68 | void compute(); |
| 69 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 70 | void enableGLVertexBuffer() const; |
| 71 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 72 | |
| 73 | protected: |
| 74 | struct LOD { |
| 75 | size_t mX; |
| 76 | size_t mY; |
| 77 | size_t mZ; |
| 78 | size_t mOffset; |
| 79 | }; |
| 80 | |
| 81 | void makeLODTable(); |
| 82 | |
| 83 | // Internal structure from most to least significant. |
| 84 | // * Array dimensions |
| 85 | // * Faces |
| 86 | // * Mipmaps |
| 87 | // * xyz |
| 88 | |
| 89 | ObjectBaseRef<const Element> mElement; |
| 90 | |
| 91 | // Size of the structure in the various dimensions. A missing Dimension is |
| 92 | // specified as a 0 and not a 1. |
| 93 | size_t mDimX; |
| 94 | size_t mDimY; |
| 95 | size_t mDimZ; |
| 96 | bool mDimLOD; |
| 97 | bool mFaces; |
| 98 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 99 | // A list of array dimensions. The count is the number of array dimensions and the |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 100 | // sizes is a per array size. |
| 101 | //Vector<size_t> mDimArraysSizes; |
| 102 | |
| 103 | // count of mipmap levels, 0 indicates no mipmapping |
| 104 | |
| 105 | size_t mMipChainSizeBytes; |
| 106 | size_t mTotalSizeBytes; |
| 107 | LOD *mLODs; |
| 108 | uint32_t mLODCount; |
| 109 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 110 | struct VertexComponent_t { |
| 111 | uint32_t offset; |
| 112 | uint32_t type; |
| 113 | uint32_t size; |
| 114 | uint32_t stride; |
| 115 | }; |
| 116 | struct GLState_t { |
| 117 | VertexComponent_t mVtx; |
| 118 | VertexComponent_t mNorm; |
| 119 | VertexComponent_t mColor; |
| 120 | VertexComponent_t mTex[RS_MAX_TEXTURE]; |
Jason Sams | e015841 | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 121 | VertexComponent_t mPointSize; |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 122 | }; |
| 123 | GLState_t mGL; |
| 124 | void makeGLComponents(); |
| 125 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 126 | private: |
| 127 | Type(const Type &); |
| 128 | }; |
| 129 | |
| 130 | |
| 131 | class TypeState { |
| 132 | public: |
| 133 | TypeState(); |
| 134 | ~TypeState(); |
| 135 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 136 | size_t mX; |
| 137 | size_t mY; |
| 138 | size_t mZ; |
| 139 | uint32_t mLOD; |
| 140 | bool mFaces; |
| 141 | ObjectBaseRef<const Element> mElement; |
| 142 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 143 | ObjectBaseRef<const Type> mIndexType; |
| 144 | ObjectBaseRef<const Type> mPrimitiveType; |
| 145 | ObjectBaseRef<const Type> *mVertexTypes; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 146 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 147 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | |
| 151 | } |
| 152 | } |
| 153 | #endif //ANDROID_STRUCTURED_TYPE |