rsType.h revision 383e5b1f68c321a77bfd7466fa1171a9bfab4a6f
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#include "rsVertexArray.h" 22 23// --------------------------------------------------------------------------- 24namespace android { 25namespace renderscript { 26 27 28class Type : public ObjectBase 29{ 30public: 31 Type(Context *); 32 virtual ~Type(); 33 34 Type * createTex2D(const Element *, size_t w, size_t h, bool mip); 35 36 37 size_t getOffsetForFace(uint32_t face) const; 38 39 size_t getSizeBytes() const {return mTotalSizeBytes;} 40 size_t getElementSizeBytes() const {return mElement->getSizeBytes();} 41 const Element * getElement() const {return mElement.get();} 42 43 uint32_t getDimX() const {return mDimX;} 44 uint32_t getDimY() const {return mDimY;} 45 uint32_t getDimZ() const {return mDimZ;} 46 uint32_t getDimLOD() const {return mDimLOD;} 47 bool getDimFaces() const {return mFaces;} 48 49 uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;} 50 uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;} 51 uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;} 52 uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;} 53 54 uint32_t getLODOffset(uint32_t lod, uint32_t x) const; 55 uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const; 56 uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const; 57 58 uint32_t getLODCount() const {return mLODCount;} 59 bool getIsNp2() const; 60 61 62 void setElement(const Element *e) {mElement.set(e);} 63 void setDimX(uint32_t v) {mDimX = v;} 64 void setDimY(uint32_t v) {mDimY = v;} 65 void setDimZ(uint32_t v) {mDimZ = v;} 66 void setDimFaces(bool v) {mFaces = v;} 67 void setDimLOD(bool v) {mDimLOD = v;} 68 69 70 void clear(); 71 void compute(); 72 73 void enableGLVertexBuffer(class VertexArray *) const; 74 75 void dumpLOGV(const char *prefix) const; 76 virtual void serialize(OStream *stream) const; 77 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; } 78 static Type *createFromStream(Context *rsc, IStream *stream); 79 80 bool isEqual(const Type *other) const; 81 82protected: 83 struct LOD { 84 size_t mX; 85 size_t mY; 86 size_t mZ; 87 size_t mOffset; 88 }; 89 90 void makeLODTable(); 91 92 // Internal structure from most to least significant. 93 // * Array dimensions 94 // * Faces 95 // * Mipmaps 96 // * xyz 97 98 ObjectBaseRef<const Element> mElement; 99 100 // Size of the structure in the various dimensions. A missing Dimension is 101 // specified as a 0 and not a 1. 102 size_t mDimX; 103 size_t mDimY; 104 size_t mDimZ; 105 bool mDimLOD; 106 bool mFaces; 107 108 // A list of array dimensions. The count is the number of array dimensions and the 109 // sizes is a per array size. 110 //Vector<size_t> mDimArraysSizes; 111 112 // count of mipmap levels, 0 indicates no mipmapping 113 114 size_t mMipChainSizeBytes; 115 size_t mTotalSizeBytes; 116 LOD *mLODs; 117 uint32_t mLODCount; 118 119 VertexArray::Attrib mAttribs[RS_MAX_ATTRIBS]; 120 void makeGLComponents(); 121 122private: 123 Type(const Type &); 124}; 125 126 127class TypeState { 128public: 129 TypeState(); 130 ~TypeState(); 131 132 size_t mX; 133 size_t mY; 134 size_t mZ; 135 uint32_t mLOD; 136 bool mFaces; 137 ObjectBaseRef<const Element> mElement; 138 139 140 // Cache of all existing types. 141 Vector<Type *> mTypes; 142}; 143 144 145} 146} 147#endif //ANDROID_STRUCTURED_TYPE 148