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" |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 21 | #include "rsVertexArray.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 27 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | class Type : public ObjectBase |
| 29 | { |
| 30 | public: |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | Type * createTex2D(const Element *, size_t w, size_t h, bool mip); |
| 32 | |
| 33 | |
| 34 | size_t getOffsetForFace(uint32_t face) const; |
| 35 | |
| 36 | size_t getSizeBytes() const {return mTotalSizeBytes;} |
| 37 | size_t getElementSizeBytes() const {return mElement->getSizeBytes();} |
| 38 | const Element * getElement() const {return mElement.get();} |
| 39 | |
| 40 | uint32_t getDimX() const {return mDimX;} |
| 41 | uint32_t getDimY() const {return mDimY;} |
| 42 | uint32_t getDimZ() const {return mDimZ;} |
| 43 | uint32_t getDimLOD() const {return mDimLOD;} |
| 44 | bool getDimFaces() const {return mFaces;} |
| 45 | |
| 46 | uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;} |
| 47 | uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;} |
| 48 | uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;} |
| 49 | uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;} |
| 50 | |
| 51 | uint32_t getLODOffset(uint32_t lod, uint32_t x) const; |
| 52 | uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const; |
| 53 | uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const; |
| 54 | |
| 55 | uint32_t getLODCount() const {return mLODCount;} |
Jason Sams | ef21edc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 56 | bool getIsNp2() const; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 57 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | void clear(); |
| 59 | void compute(); |
| 60 | |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 61 | void enableGLVertexBuffer(class VertexArray *) const; |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 62 | |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 63 | void dumpLOGV(const char *prefix) const; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 64 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 65 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 66 | static Type *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 67 | |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 68 | bool isEqual(const Type *other) const; |
| 69 | |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 70 | Type * cloneAndResize1D(Context *rsc, uint32_t dimX) const; |
| 71 | Type * cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const; |
| 72 | |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 73 | static Type * getType(Context *rsc, const Element *e, |
| 74 | uint32_t dimX, uint32_t dimY, uint32_t dimZ, |
| 75 | bool dimLOD, bool dimFaces); |
| 76 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | protected: |
| 78 | struct LOD { |
| 79 | size_t mX; |
| 80 | size_t mY; |
| 81 | size_t mZ; |
| 82 | size_t mOffset; |
| 83 | }; |
| 84 | |
| 85 | void makeLODTable(); |
| 86 | |
| 87 | // Internal structure from most to least significant. |
| 88 | // * Array dimensions |
| 89 | // * Faces |
| 90 | // * Mipmaps |
| 91 | // * xyz |
| 92 | |
| 93 | ObjectBaseRef<const Element> mElement; |
| 94 | |
| 95 | // Size of the structure in the various dimensions. A missing Dimension is |
| 96 | // specified as a 0 and not a 1. |
| 97 | size_t mDimX; |
| 98 | size_t mDimY; |
| 99 | size_t mDimZ; |
| 100 | bool mDimLOD; |
| 101 | bool mFaces; |
| 102 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 103 | // 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] | 104 | // sizes is a per array size. |
| 105 | //Vector<size_t> mDimArraysSizes; |
| 106 | |
| 107 | // count of mipmap levels, 0 indicates no mipmapping |
| 108 | |
| 109 | size_t mMipChainSizeBytes; |
| 110 | size_t mTotalSizeBytes; |
| 111 | LOD *mLODs; |
| 112 | uint32_t mLODCount; |
| 113 | |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 114 | VertexArray::Attrib *mAttribs; |
| 115 | uint32_t mAttribsSize; |
Alex Sakhartchouk | 39f2ef6 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 116 | bool isValidGLComponent(uint32_t fieldIdx); |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 117 | void makeGLComponents(); |
| 118 | |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 119 | |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 120 | protected: |
| 121 | virtual void preDestroy(); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 122 | virtual ~Type(); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 123 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 124 | private: |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 125 | Type(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 126 | Type(const Type &); |
| 127 | }; |
| 128 | |
| 129 | |
| 130 | class TypeState { |
| 131 | public: |
| 132 | TypeState(); |
| 133 | ~TypeState(); |
| 134 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 135 | // Cache of all existing types. |
| 136 | Vector<Type *> mTypes; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | |
| 140 | } |
| 141 | } |
| 142 | #endif //ANDROID_STRUCTURED_TYPE |