blob: 2c43405122ba0dc75bf312bc77e1832fbdb4958b [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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
Jason Samse5ffb872009-08-09 17:01:55 -070026
Jason Sams326e0dd2009-05-22 14:03:28 -070027class Type : public ObjectBase
28{
29public:
Jason Samse514b452009-09-25 14:51:22 -070030 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070031 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 Samse5ffb872009-08-09 17:01:55 -070070 void enableGLVertexBuffer() const;
71
Jason Samse12c1c52009-09-27 17:50:38 -070072 void dumpLOGV(const char *prefix) const;
Jason Sams326e0dd2009-05-22 14:03:28 -070073
74protected:
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
Jason Samse5ffb872009-08-09 17:01:55 -0700100 // A list of array dimensions. The count is the number of array dimensions and the
Jason Sams326e0dd2009-05-22 14:03:28 -0700101 // 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
Jason Samse5ffb872009-08-09 17:01:55 -0700111 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];
Jason Samse0158412009-08-20 16:10:36 -0700122 VertexComponent_t mPointSize;
Jason Samse5ffb872009-08-09 17:01:55 -0700123 };
124 GLState_t mGL;
125 void makeGLComponents();
126
Jason Sams326e0dd2009-05-22 14:03:28 -0700127private:
128 Type(const Type &);
129};
130
131
132class TypeState {
133public:
134 TypeState();
135 ~TypeState();
136
Jason Sams326e0dd2009-05-22 14:03:28 -0700137 size_t mX;
138 size_t mY;
139 size_t mZ;
140 uint32_t mLOD;
141 bool mFaces;
142 ObjectBaseRef<const Element> mElement;
Jason Sams326e0dd2009-05-22 14:03:28 -0700143};
144
145
146}
147}
148#endif //ANDROID_STRUCTURED_TYPE