rsType.h revision e5ffb879ae535a899a486285a23bea05e912480f
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// --------------------------------------------------------------------------- 23namespace android { 24namespace renderscript { 25 26 27class Type : public ObjectBase 28{ 29public: 30 Type(); 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 70 void enableGLVertexBuffer() const; 71 72 73protected: 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 99 // A list of array dimensions. The count is the number of array dimensions and the 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 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]; 121 }; 122 GLState_t mGL; 123 void makeGLComponents(); 124 125private: 126 Type(const Type &); 127}; 128 129 130class TypeState { 131public: 132 TypeState(); 133 ~TypeState(); 134 135 size_t mX; 136 size_t mY; 137 size_t mZ; 138 uint32_t mLOD; 139 bool mFaces; 140 ObjectBaseRef<const Element> mElement; 141 142 ObjectBaseRef<const Type> mIndexType; 143 ObjectBaseRef<const Type> mPrimitiveType; 144 ObjectBaseRef<const Type> *mVertexTypes; 145 146 147}; 148 149 150} 151} 152#endif //ANDROID_STRUCTURED_TYPE 153