1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved.
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #ifndef CR_STATE_TEXTURE_H
|
---|
8 | #define CR_STATE_TEXTURE_H
|
---|
9 |
|
---|
10 | #include "cr_hash.h"
|
---|
11 | #include "state/cr_statetypes.h"
|
---|
12 | #include "state/cr_limits.h"
|
---|
13 |
|
---|
14 | #include <iprt/cdefs.h>
|
---|
15 |
|
---|
16 | #ifdef __cplusplus
|
---|
17 | extern "C" {
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | /* Tells state tracker to rely on diff_api to store/load texture images
|
---|
21 | * and avoid host memory allocation.
|
---|
22 | */
|
---|
23 | #define CR_STATE_NO_TEXTURE_IMAGE_STORE
|
---|
24 |
|
---|
25 | #if defined(CR_ARB_pixel_buffer_object) && !defined(CR_STATE_NO_TEXTURE_IMAGE_STORE)
|
---|
26 | #error CR_ARB_pixel_buffer_object not supported without CR_STATE_NO_TEXTURE_IMAGE_STORE
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #define CR_MAX_MIPMAP_LEVELS 20
|
---|
30 |
|
---|
31 | typedef struct {
|
---|
32 | GLubyte redbits;
|
---|
33 | GLubyte greenbits;
|
---|
34 | GLubyte bluebits;
|
---|
35 | GLubyte alphabits;
|
---|
36 | GLubyte luminancebits;
|
---|
37 | GLubyte intensitybits;
|
---|
38 | GLubyte indexbits;
|
---|
39 | } CRTextureFormat;
|
---|
40 |
|
---|
41 | typedef struct {
|
---|
42 | GLubyte *img;
|
---|
43 | int bytes;
|
---|
44 | GLint width; /* width, height, depth includes the border */
|
---|
45 | GLint height;
|
---|
46 | GLint depth;
|
---|
47 | GLint internalFormat;
|
---|
48 | GLint border;
|
---|
49 | GLenum format;
|
---|
50 | GLenum type;
|
---|
51 | int bytesPerPixel;
|
---|
52 | #if CR_ARB_texture_compression
|
---|
53 | GLboolean compressed;
|
---|
54 | #endif
|
---|
55 | GLboolean generateMipmap;
|
---|
56 | const CRTextureFormat *texFormat;
|
---|
57 |
|
---|
58 | CRbitvalue dirty[CR_MAX_BITARRAY];
|
---|
59 | } CRTextureLevel;
|
---|
60 |
|
---|
61 | typedef struct {
|
---|
62 | GLenum target;
|
---|
63 | GLuint id;
|
---|
64 | GLuint hwid;
|
---|
65 |
|
---|
66 | /* The mipmap levels */
|
---|
67 | CRTextureLevel *level[6]; /* 6 cube faces */
|
---|
68 |
|
---|
69 | GLcolorf borderColor;
|
---|
70 | GLenum minFilter, magFilter;
|
---|
71 | GLenum wrapS, wrapT;
|
---|
72 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
73 | GLenum wrapR;
|
---|
74 | GLfloat priority;
|
---|
75 | GLfloat minLod;
|
---|
76 | GLfloat maxLod;
|
---|
77 | GLint baseLevel;
|
---|
78 | GLint maxLevel;
|
---|
79 | #endif
|
---|
80 | #ifdef CR_EXT_texture_filter_anisotropic
|
---|
81 | GLfloat maxAnisotropy;
|
---|
82 | #endif
|
---|
83 | #ifdef CR_ARB_depth_texture
|
---|
84 | GLenum depthMode;
|
---|
85 | #endif
|
---|
86 | #ifdef CR_ARB_shadow
|
---|
87 | GLenum compareMode;
|
---|
88 | GLenum compareFunc;
|
---|
89 | #endif
|
---|
90 | #ifdef CR_ARB_shadow_ambient
|
---|
91 | GLfloat compareFailValue;
|
---|
92 | #endif
|
---|
93 | #ifdef CR_SGIS_generate_mipmap
|
---|
94 | GLboolean generateMipmap;
|
---|
95 | #endif
|
---|
96 | CRbitvalue dirty[CR_MAX_BITARRAY];
|
---|
97 | CRbitvalue imageBit[CR_MAX_BITARRAY];
|
---|
98 | CRbitvalue paramsBit[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
99 | } CRTextureObj;
|
---|
100 |
|
---|
101 | typedef struct {
|
---|
102 | CRbitvalue dirty[CR_MAX_BITARRAY];
|
---|
103 | CRbitvalue enable[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
104 | CRbitvalue current[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
105 | CRbitvalue objGen[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
106 | CRbitvalue eyeGen[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
107 | CRbitvalue genMode[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
108 | /* XXX someday create more bits for texture env state */
|
---|
109 | CRbitvalue envBit[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
|
---|
110 | } CRTextureBits;
|
---|
111 |
|
---|
112 | typedef struct {
|
---|
113 | /* Current texture objects (in terms of glBindTexture and glActiveTexture) */
|
---|
114 | CRTextureObj *currentTexture1D;
|
---|
115 | CRTextureObj *currentTexture2D;
|
---|
116 | CRTextureObj *currentTexture3D;
|
---|
117 | #ifdef CR_ARB_texture_cube_map
|
---|
118 | CRTextureObj *currentTextureCubeMap;
|
---|
119 | #endif
|
---|
120 | #ifdef CR_NV_texture_rectangle
|
---|
121 | CRTextureObj *currentTextureRect;
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | GLboolean enabled1D;
|
---|
125 | GLboolean enabled2D;
|
---|
126 | GLboolean enabled3D;
|
---|
127 | #ifdef CR_ARB_texture_cube_map
|
---|
128 | GLboolean enabledCubeMap;
|
---|
129 | #endif
|
---|
130 | #ifdef CR_NV_texture_rectangle
|
---|
131 | GLboolean enabledRect;
|
---|
132 | #endif
|
---|
133 | #ifdef CR_EXT_texture_lod_bias
|
---|
134 | GLfloat lodBias;
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | GLenum envMode;
|
---|
138 | GLcolorf envColor;
|
---|
139 |
|
---|
140 | /* GL_ARB_texture_env_combine */
|
---|
141 | GLenum combineModeRGB; /* GL_REPLACE, GL_DECAL, GL_ADD, etc. */
|
---|
142 | GLenum combineModeA; /* GL_REPLACE, GL_DECAL, GL_ADD, etc. */
|
---|
143 | GLenum combineSourceRGB[3]; /* GL_PRIMARY_COLOR, GL_TEXTURE, etc. */
|
---|
144 | GLenum combineSourceA[3]; /* GL_PRIMARY_COLOR, GL_TEXTURE, etc. */
|
---|
145 | GLenum combineOperandRGB[3]; /* SRC_COLOR, ONE_MINUS_SRC_COLOR, etc */
|
---|
146 | GLenum combineOperandA[3]; /* SRC_ALPHA, ONE_MINUS_SRC_ALPHA, etc */
|
---|
147 | GLfloat combineScaleRGB; /* 1 or 2 or 4 */
|
---|
148 | GLfloat combineScaleA; /* 1 or 2 or 4 */
|
---|
149 |
|
---|
150 | GLtexcoordb textureGen;
|
---|
151 | GLvectorf objSCoeff;
|
---|
152 | GLvectorf objTCoeff;
|
---|
153 | GLvectorf objRCoeff;
|
---|
154 | GLvectorf objQCoeff;
|
---|
155 | GLvectorf eyeSCoeff;
|
---|
156 | GLvectorf eyeTCoeff;
|
---|
157 | GLvectorf eyeRCoeff;
|
---|
158 | GLvectorf eyeQCoeff;
|
---|
159 | GLtexcoorde gen;
|
---|
160 |
|
---|
161 | /* These are only used for glPush/PopAttrib */
|
---|
162 | CRTextureObj Saved1D;
|
---|
163 | CRTextureObj Saved2D;
|
---|
164 | CRTextureObj Saved3D;
|
---|
165 | #ifdef CR_ARB_texture_cube_map
|
---|
166 | CRTextureObj SavedCubeMap;
|
---|
167 | #endif
|
---|
168 | #ifdef CR_NV_texture_rectangle
|
---|
169 | CRTextureObj SavedRect;
|
---|
170 | #endif
|
---|
171 | } CRTextureUnit;
|
---|
172 |
|
---|
173 | typedef struct {
|
---|
174 | /* Default texture objects (name = 0) */
|
---|
175 | CRTextureObj base1D;
|
---|
176 | CRTextureObj base2D;
|
---|
177 | CRTextureObj base3D;
|
---|
178 | #ifdef CR_ARB_texture_cube_map
|
---|
179 | CRTextureObj baseCubeMap;
|
---|
180 | #endif
|
---|
181 | #ifdef CR_NV_texture_rectangle
|
---|
182 | CRTextureObj baseRect;
|
---|
183 | #endif
|
---|
184 |
|
---|
185 | /* Proxy texture objects */
|
---|
186 | CRTextureObj proxy1D;
|
---|
187 | CRTextureObj proxy2D;
|
---|
188 | CRTextureObj proxy3D;
|
---|
189 | #ifdef CR_ARB_texture_cube_map
|
---|
190 | CRTextureObj proxyCubeMap;
|
---|
191 | #endif
|
---|
192 | #ifdef CR_NV_texture_rectangle
|
---|
193 | CRTextureObj proxyRect;
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | GLuint curTextureUnit; /* GL_ACTIVE_TEXTURE */
|
---|
197 |
|
---|
198 | GLint maxLevel; /* number of mipmap levels possible: [0..max] */
|
---|
199 | GLint max3DLevel;
|
---|
200 | GLint maxCubeMapLevel;
|
---|
201 | GLint maxRectLevel;
|
---|
202 |
|
---|
203 | GLboolean broadcastTextures; /*@todo what is it for?*/
|
---|
204 |
|
---|
205 | /* Indicates that we have to resend texture data to GPU on first glMakeCurrent call with owning context */
|
---|
206 | GLboolean bResyncNeeded;
|
---|
207 |
|
---|
208 | /* Per-texture unit state: */
|
---|
209 | CRTextureUnit unit[CR_MAX_TEXTURE_UNITS];
|
---|
210 | } CRTextureState;
|
---|
211 |
|
---|
212 | DECLEXPORT(void) crStateTextureInit(CRContext *ctx);
|
---|
213 | DECLEXPORT(void) crStateTextureDestroy(CRContext *ctx);
|
---|
214 | DECLEXPORT(void) crStateTextureFree(CRContext *ctx);
|
---|
215 |
|
---|
216 | DECLEXPORT(void) crStateTextureInitTexture(GLuint name);
|
---|
217 | DECLEXPORT(CRTextureObj *) crStateTextureAllocate(GLuint name);
|
---|
218 | /*void crStateTextureDelete(GLuint name);*/
|
---|
219 | DECLEXPORT(CRTextureObj *) crStateTextureGet(GLenum target, GLuint textureid);
|
---|
220 | DECLEXPORT(int) crStateTextureGetSize(GLenum target, GLenum level);
|
---|
221 | DECLEXPORT(const GLvoid *) crStateTextureGetData(GLenum target, GLenum level);
|
---|
222 |
|
---|
223 | DECLEXPORT(int) crStateTextureCheckDirtyImages(CRContext *from, CRContext *to, GLenum target, int textureUnit);
|
---|
224 |
|
---|
225 | DECLEXPORT(void) crStateTextureDiff(CRTextureBits *t, CRbitvalue *bitID,
|
---|
226 | CRContext *fromCtx, CRContext *toCtx);
|
---|
227 | DECLEXPORT(void) crStateTextureSwitch(CRTextureBits *t, CRbitvalue *bitID,
|
---|
228 | CRContext *fromCtx, CRContext *toCtx);
|
---|
229 |
|
---|
230 | DECLEXPORT(void) crStateTextureObjectDiff(CRContext *fromCtx,
|
---|
231 | const CRbitvalue *bitID,
|
---|
232 | const CRbitvalue *nbitID,
|
---|
233 | CRTextureObj *tobj, GLboolean alwaysDirty);
|
---|
234 |
|
---|
235 | DECLEXPORT(void) crStateDiffAllTextureObjects( CRContext *g, CRbitvalue *bitID, GLboolean bForceUpdate );
|
---|
236 |
|
---|
237 | DECLEXPORT(void) crStateDeleteTextureObjectData(CRTextureObj *tobj);
|
---|
238 | DECLEXPORT(void) crStateDeleteTextureObject(CRTextureObj *tobj);
|
---|
239 |
|
---|
240 | DECLEXPORT(GLuint) STATE_APIENTRY crStateTextureHWIDtoID(GLuint hwid);
|
---|
241 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureHWID(GLuint id);
|
---|
242 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureObjHWID(CRTextureObj *tobj);
|
---|
243 |
|
---|
244 | #ifdef __cplusplus
|
---|
245 | }
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | #endif /* CR_STATE_TEXTURE_H */
|
---|