blob: 664f34370288ad10dad7e4bdd3486898136f7401 [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"
Jason Sams433eca32010-01-06 11:57:52 -080021#include "rsVertexArray.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070022
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
Jason Samse5ffb872009-08-09 17:01:55 -070027
Jason Sams326e0dd2009-05-22 14:03:28 -070028class Type : public ObjectBase
29{
30public:
Jason Samse514b452009-09-25 14:51:22 -070031 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070032 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;}
Jason Samsef21edc2010-02-22 15:37:51 -080059 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070060
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
Jason Samsef21edc2010-02-22 15:37:51 -080069
Jason Sams326e0dd2009-05-22 14:03:28 -070070 void clear();
71 void compute();
72
Jason Samsc460e552009-11-25 13:22:07 -080073 void enableGLVertexBuffer(class VertexArray *) const;
Jason Sams433eca32010-01-06 11:57:52 -080074 void enableGLVertexBuffer2(class VertexArray *) const;
Jason Samse5ffb872009-08-09 17:01:55 -070075
Jason Samse12c1c52009-09-27 17:50:38 -070076 void dumpLOGV(const char *prefix) const;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070077 virtual void serialize(OStream *stream) const;
78 virtual A3DClassID getClassId() const { return A3D_CLASS_ID_TYPE; }
79 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -070080
81protected:
82 struct LOD {
83 size_t mX;
84 size_t mY;
85 size_t mZ;
86 size_t mOffset;
87 };
88
89 void makeLODTable();
90
91 // Internal structure from most to least significant.
92 // * Array dimensions
93 // * Faces
94 // * Mipmaps
95 // * xyz
96
97 ObjectBaseRef<const Element> mElement;
98
99 // Size of the structure in the various dimensions. A missing Dimension is
100 // specified as a 0 and not a 1.
101 size_t mDimX;
102 size_t mDimY;
103 size_t mDimZ;
104 bool mDimLOD;
105 bool mFaces;
106
Jason Samse5ffb872009-08-09 17:01:55 -0700107 // A list of array dimensions. The count is the number of array dimensions and the
Jason Sams326e0dd2009-05-22 14:03:28 -0700108 // sizes is a per array size.
109 //Vector<size_t> mDimArraysSizes;
110
111 // count of mipmap levels, 0 indicates no mipmapping
112
113 size_t mMipChainSizeBytes;
114 size_t mTotalSizeBytes;
115 LOD *mLODs;
116 uint32_t mLODCount;
117
Jason Samse5ffb872009-08-09 17:01:55 -0700118 struct GLState_t {
Jason Sams433eca32010-01-06 11:57:52 -0800119 VertexArray::Attrib mUser[RS_MAX_ATTRIBS];
120 VertexArray::Attrib mVtx;
121 VertexArray::Attrib mNorm;
122 VertexArray::Attrib mColor;
123 VertexArray::Attrib mTex;
124 VertexArray::Attrib mPointSize;
Jason Samse5ffb872009-08-09 17:01:55 -0700125 };
126 GLState_t mGL;
127 void makeGLComponents();
128
Jason Sams326e0dd2009-05-22 14:03:28 -0700129private:
130 Type(const Type &);
131};
132
133
134class TypeState {
135public:
136 TypeState();
137 ~TypeState();
138
Jason Sams326e0dd2009-05-22 14:03:28 -0700139 size_t mX;
140 size_t mY;
141 size_t mZ;
142 uint32_t mLOD;
143 bool mFaces;
144 ObjectBaseRef<const Element> mElement;
Jason Sams81549542010-02-17 15:38:10 -0800145
146
147 // Cache of all existing types.
148 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700149};
150
151
152}
153}
154#endif //ANDROID_STRUCTURED_TYPE