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 26 27 class Type : public ObjectBase 28 { 29 public: 30 Type(Context *); 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 getSizeBytes()38 size_t getSizeBytes() const {return mTotalSizeBytes;} getElementSizeBytes()39 size_t getElementSizeBytes() const {return mElement->getSizeBytes();} getElement()40 const Element * getElement() const {return mElement.get();} 41 getDimX()42 uint32_t getDimX() const {return mDimX;} getDimY()43 uint32_t getDimY() const {return mDimY;} getDimZ()44 uint32_t getDimZ() const {return mDimZ;} getDimLOD()45 uint32_t getDimLOD() const {return mDimLOD;} getDimFaces()46 bool getDimFaces() const {return mFaces;} 47 getLODDimX(uint32_t lod)48 uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;} getLODDimY(uint32_t lod)49 uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;} getLODDimZ(uint32_t lod)50 uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;} getLODOffset(uint32_t lod)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 getLODCount()57 uint32_t getLODCount() const {return mLODCount;} 58 59 setElement(const Element * e)60 void setElement(const Element *e) {mElement.set(e);} setDimX(uint32_t v)61 void setDimX(uint32_t v) {mDimX = v;} setDimY(uint32_t v)62 void setDimY(uint32_t v) {mDimY = v;} setDimZ(uint32_t v)63 void setDimZ(uint32_t v) {mDimZ = v;} setDimFaces(bool v)64 void setDimFaces(bool v) {mFaces = v;} setDimLOD(bool v)65 void setDimLOD(bool v) {mDimLOD = v;} 66 67 void clear(); 68 void compute(); 69 70 void enableGLVertexBuffer() const; 71 72 void dumpLOGV(const char *prefix) const; 73 74 protected: 75 struct LOD { 76 size_t mX; 77 size_t mY; 78 size_t mZ; 79 size_t mOffset; 80 }; 81 82 void makeLODTable(); 83 84 // Internal structure from most to least significant. 85 // * Array dimensions 86 // * Faces 87 // * Mipmaps 88 // * xyz 89 90 ObjectBaseRef<const Element> mElement; 91 92 // Size of the structure in the various dimensions. A missing Dimension is 93 // specified as a 0 and not a 1. 94 size_t mDimX; 95 size_t mDimY; 96 size_t mDimZ; 97 bool mDimLOD; 98 bool mFaces; 99 100 // A list of array dimensions. The count is the number of array dimensions and the 101 // sizes is a per array size. 102 //Vector<size_t> mDimArraysSizes; 103 104 // count of mipmap levels, 0 indicates no mipmapping 105 106 size_t mMipChainSizeBytes; 107 size_t mTotalSizeBytes; 108 LOD *mLODs; 109 uint32_t mLODCount; 110 111 struct VertexComponent_t { 112 uint32_t offset; 113 uint32_t type; 114 uint32_t size; 115 uint32_t stride; 116 }; 117 struct GLState_t { 118 VertexComponent_t mVtx; 119 VertexComponent_t mNorm; 120 VertexComponent_t mColor; 121 VertexComponent_t mTex[RS_MAX_TEXTURE]; 122 VertexComponent_t mPointSize; 123 }; 124 GLState_t mGL; 125 void makeGLComponents(); 126 127 private: 128 Type(const Type &); 129 }; 130 131 132 class TypeState { 133 public: 134 TypeState(); 135 ~TypeState(); 136 137 size_t mX; 138 size_t mY; 139 size_t mZ; 140 uint32_t mLOD; 141 bool mFaces; 142 ObjectBaseRef<const Element> mElement; 143 }; 144 145 146 } 147 } 148 #endif //ANDROID_STRUCTURED_TYPE 149