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 | #include "state.h"
|
---|
8 | #include "state/cr_statetypes.h"
|
---|
9 | #include "state/cr_texture.h"
|
---|
10 | #include "cr_hash.h"
|
---|
11 | #include "cr_string.h"
|
---|
12 | #include "cr_mem.h"
|
---|
13 | #include "cr_version.h"
|
---|
14 | #include "state_internals.h"
|
---|
15 |
|
---|
16 | #ifdef DEBUG_misha
|
---|
17 | #include <iprt/assert.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #define UNUSED(x) ((void) (x))
|
---|
21 |
|
---|
22 | #define GET_TOBJ(tobj, state, id) \
|
---|
23 | tobj = (CRTextureObj *) crHashtableSearch(g->shared->textureTable, id);
|
---|
24 |
|
---|
25 |
|
---|
26 | void crStateTextureDestroy(CRContext *ctx)
|
---|
27 | {
|
---|
28 | crStateDeleteTextureObjectData(&ctx->texture.base1D);
|
---|
29 | crStateDeleteTextureObjectData(&ctx->texture.proxy1D);
|
---|
30 | crStateDeleteTextureObjectData(&ctx->texture.base2D);
|
---|
31 | crStateDeleteTextureObjectData(&ctx->texture.proxy2D);
|
---|
32 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
33 | crStateDeleteTextureObjectData(&ctx->texture.base3D);
|
---|
34 | crStateDeleteTextureObjectData(&ctx->texture.proxy3D);
|
---|
35 | #endif
|
---|
36 | #ifdef CR_ARB_texture_cube_map
|
---|
37 | crStateDeleteTextureObjectData(&ctx->texture.baseCubeMap);
|
---|
38 | crStateDeleteTextureObjectData(&ctx->texture.proxyCubeMap);
|
---|
39 | #endif
|
---|
40 | #ifdef CR_NV_texture_rectangle
|
---|
41 | crStateDeleteTextureObjectData(&ctx->texture.baseRect);
|
---|
42 | crStateDeleteTextureObjectData(&ctx->texture.proxyRect);
|
---|
43 | #endif
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | void crStateTextureInit(CRContext *ctx)
|
---|
48 | {
|
---|
49 | CRLimitsState *limits = &ctx->limits;
|
---|
50 | CRTextureState *t = &ctx->texture;
|
---|
51 | CRStateBits *sb = GetCurrentBits();
|
---|
52 | CRTextureBits *tb = &(sb->texture);
|
---|
53 | unsigned int i;
|
---|
54 | unsigned int a;
|
---|
55 | GLvectorf zero_vector = {0.0f, 0.0f, 0.0f, 0.0f};
|
---|
56 | GLcolorf zero_color = {0.0f, 0.0f, 0.0f, 0.0f};
|
---|
57 | GLvectorf x_vector = {1.0f, 0.0f, 0.0f, 0.0f};
|
---|
58 | GLvectorf y_vector = {0.0f, 1.0f, 0.0f, 0.0f};
|
---|
59 |
|
---|
60 | /* compute max levels from max sizes */
|
---|
61 | for (i=0, a=limits->maxTextureSize; a; i++, a=a>>1);
|
---|
62 | t->maxLevel = i-1;
|
---|
63 | for (i=0, a=limits->max3DTextureSize; a; i++, a=a>>1);
|
---|
64 | t->max3DLevel = i-1;
|
---|
65 | #ifdef CR_ARB_texture_cube_map
|
---|
66 | for (i=0, a=limits->maxCubeMapTextureSize; a; i++, a=a>>1);
|
---|
67 | t->maxCubeMapLevel = i-1;
|
---|
68 | #endif
|
---|
69 | #ifdef CR_NV_texture_rectangle
|
---|
70 | for (i=0, a=limits->maxRectTextureSize; a; i++, a=a>>1);
|
---|
71 | t->maxRectLevel = i-1;
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | crStateTextureInitTextureObj(ctx, &(t->base1D), 0, GL_TEXTURE_1D);
|
---|
75 | crStateTextureInitTextureObj(ctx, &(t->base2D), 0, GL_TEXTURE_2D);
|
---|
76 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
77 | crStateTextureInitTextureObj(ctx, &(t->base3D), 0, GL_TEXTURE_3D);
|
---|
78 | #endif
|
---|
79 | #ifdef CR_ARB_texture_cube_map
|
---|
80 | crStateTextureInitTextureObj(ctx, &(t->baseCubeMap), 0,
|
---|
81 | GL_TEXTURE_CUBE_MAP_ARB);
|
---|
82 | #endif
|
---|
83 | #ifdef CR_NV_texture_rectangle
|
---|
84 | crStateTextureInitTextureObj(ctx, &(t->baseRect), 0,
|
---|
85 | GL_TEXTURE_RECTANGLE_NV);
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | crStateTextureInitTextureObj(ctx, &(t->proxy1D), 0, GL_TEXTURE_1D);
|
---|
89 | crStateTextureInitTextureObj(ctx, &(t->proxy2D), 0, GL_TEXTURE_2D);
|
---|
90 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
91 | crStateTextureInitTextureObj(ctx, &(t->proxy3D), 0, GL_TEXTURE_3D);
|
---|
92 | #endif
|
---|
93 | #ifdef CR_ARB_texture_cube_map
|
---|
94 | crStateTextureInitTextureObj(ctx, &(t->proxyCubeMap), 0,
|
---|
95 | GL_TEXTURE_CUBE_MAP_ARB);
|
---|
96 | #endif
|
---|
97 | #ifdef CR_NV_texture_rectangle
|
---|
98 | crStateTextureInitTextureObj(ctx, &(t->proxyRect), 0,
|
---|
99 | GL_TEXTURE_RECTANGLE_NV);
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | t->curTextureUnit = 0;
|
---|
103 |
|
---|
104 | /* Per-unit initialization */
|
---|
105 | for (i = 0; i < limits->maxTextureUnits; i++)
|
---|
106 | {
|
---|
107 | t->unit[i].currentTexture1D = &(t->base1D);
|
---|
108 | t->unit[i].currentTexture2D = &(t->base2D);
|
---|
109 | t->unit[i].currentTexture3D = &(t->base3D);
|
---|
110 | #ifdef CR_ARB_texture_cube_map
|
---|
111 | t->unit[i].currentTextureCubeMap = &(t->baseCubeMap);
|
---|
112 | #endif
|
---|
113 | #ifdef CR_NV_texture_rectangle
|
---|
114 | t->unit[i].currentTextureRect = &(t->baseRect);
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | t->unit[i].enabled1D = GL_FALSE;
|
---|
118 | t->unit[i].enabled2D = GL_FALSE;
|
---|
119 | t->unit[i].enabled3D = GL_FALSE;
|
---|
120 | t->unit[i].enabledCubeMap = GL_FALSE;
|
---|
121 | #ifdef CR_NV_texture_rectangle
|
---|
122 | t->unit[i].enabledRect = GL_FALSE;
|
---|
123 | #endif
|
---|
124 | t->unit[i].textureGen.s = GL_FALSE;
|
---|
125 | t->unit[i].textureGen.t = GL_FALSE;
|
---|
126 | t->unit[i].textureGen.r = GL_FALSE;
|
---|
127 | t->unit[i].textureGen.q = GL_FALSE;
|
---|
128 |
|
---|
129 | t->unit[i].gen.s = GL_EYE_LINEAR;
|
---|
130 | t->unit[i].gen.t = GL_EYE_LINEAR;
|
---|
131 | t->unit[i].gen.r = GL_EYE_LINEAR;
|
---|
132 | t->unit[i].gen.q = GL_EYE_LINEAR;
|
---|
133 |
|
---|
134 | t->unit[i].objSCoeff = x_vector;
|
---|
135 | t->unit[i].objTCoeff = y_vector;
|
---|
136 | t->unit[i].objRCoeff = zero_vector;
|
---|
137 | t->unit[i].objQCoeff = zero_vector;
|
---|
138 |
|
---|
139 | t->unit[i].eyeSCoeff = x_vector;
|
---|
140 | t->unit[i].eyeTCoeff = y_vector;
|
---|
141 | t->unit[i].eyeRCoeff = zero_vector;
|
---|
142 | t->unit[i].eyeQCoeff = zero_vector;
|
---|
143 | t->unit[i].envMode = GL_MODULATE;
|
---|
144 | t->unit[i].envColor = zero_color;
|
---|
145 |
|
---|
146 | t->unit[i].combineModeRGB = GL_MODULATE;
|
---|
147 | t->unit[i].combineModeA = GL_MODULATE;
|
---|
148 | t->unit[i].combineSourceRGB[0] = GL_TEXTURE;
|
---|
149 | t->unit[i].combineSourceRGB[1] = GL_PREVIOUS_EXT;
|
---|
150 | t->unit[i].combineSourceRGB[2] = GL_CONSTANT_EXT;
|
---|
151 | t->unit[i].combineSourceA[0] = GL_TEXTURE;
|
---|
152 | t->unit[i].combineSourceA[1] = GL_PREVIOUS_EXT;
|
---|
153 | t->unit[i].combineSourceA[2] = GL_CONSTANT_EXT;
|
---|
154 | t->unit[i].combineOperandRGB[0] = GL_SRC_COLOR;
|
---|
155 | t->unit[i].combineOperandRGB[1] = GL_SRC_COLOR;
|
---|
156 | t->unit[i].combineOperandRGB[2] = GL_SRC_ALPHA;
|
---|
157 | t->unit[i].combineOperandA[0] = GL_SRC_ALPHA;
|
---|
158 | t->unit[i].combineOperandA[1] = GL_SRC_ALPHA;
|
---|
159 | t->unit[i].combineOperandA[2] = GL_SRC_ALPHA;
|
---|
160 | t->unit[i].combineScaleRGB = 1.0F;
|
---|
161 | t->unit[i].combineScaleA = 1.0F;
|
---|
162 | #ifdef CR_EXT_texture_lod_bias
|
---|
163 | t->unit[i].lodBias = 0.0F;
|
---|
164 | #endif
|
---|
165 | RESET(tb->enable[i], ctx->bitid);
|
---|
166 | RESET(tb->current[i], ctx->bitid);
|
---|
167 | RESET(tb->objGen[i], ctx->bitid);
|
---|
168 | RESET(tb->eyeGen[i], ctx->bitid);
|
---|
169 | RESET(tb->genMode[i], ctx->bitid);
|
---|
170 | RESET(tb->envBit[i], ctx->bitid);
|
---|
171 | }
|
---|
172 | RESET(tb->dirty, ctx->bitid);
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | void
|
---|
177 | crStateTextureInitTextureObj(CRContext *ctx, CRTextureObj *tobj,
|
---|
178 | GLuint name, GLenum target)
|
---|
179 | {
|
---|
180 | const CRTextureState *t = &(ctx->texture);
|
---|
181 | int i, face;
|
---|
182 |
|
---|
183 | tobj->borderColor.r = 0.0f;
|
---|
184 | tobj->borderColor.g = 0.0f;
|
---|
185 | tobj->borderColor.b = 0.0f;
|
---|
186 | tobj->borderColor.a = 0.0f;
|
---|
187 | tobj->minFilter = GL_NEAREST_MIPMAP_LINEAR;
|
---|
188 | tobj->magFilter = GL_LINEAR;
|
---|
189 | tobj->wrapS = GL_REPEAT;
|
---|
190 | tobj->wrapT = GL_REPEAT;
|
---|
191 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
192 | tobj->wrapR = GL_REPEAT;
|
---|
193 | tobj->priority = 1.0f;
|
---|
194 | tobj->minLod = -1000.0;
|
---|
195 | tobj->maxLod = 1000.0;
|
---|
196 | tobj->baseLevel = 0;
|
---|
197 | tobj->maxLevel = t->maxLevel;
|
---|
198 | #endif
|
---|
199 | tobj->target = target;
|
---|
200 | tobj->id = name;
|
---|
201 | tobj->hwid = 0;
|
---|
202 |
|
---|
203 | #ifndef IN_GUEST
|
---|
204 | crStateGetTextureObjHWID(tobj);
|
---|
205 | #endif
|
---|
206 |
|
---|
207 | CRASSERT(t->maxLevel);
|
---|
208 |
|
---|
209 | /* XXX don't always need all six faces */
|
---|
210 | for (face = 0; face < 6; face++) {
|
---|
211 | /* allocate array of mipmap levels */
|
---|
212 | CRASSERT(t->maxLevel < CR_MAX_MIPMAP_LEVELS);
|
---|
213 | tobj->level[face] = (CRTextureLevel *)
|
---|
214 | crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS);
|
---|
215 |
|
---|
216 | if (!tobj->level[face])
|
---|
217 | return; /* out of memory */
|
---|
218 |
|
---|
219 | /* init non-zero fields */
|
---|
220 | for (i = 0; i <= t->maxLevel; i++) {
|
---|
221 | CRTextureLevel *tl = &(tobj->level[face][i]);
|
---|
222 | tl->internalFormat = GL_ONE;
|
---|
223 | tl->format = GL_RGBA;
|
---|
224 | tl->type = GL_UNSIGNED_BYTE;
|
---|
225 | crStateTextureInitTextureFormat( tl, tl->internalFormat );
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | #ifdef CR_EXT_texture_filter_anisotropic
|
---|
230 | tobj->maxAnisotropy = 1.0f;
|
---|
231 | #endif
|
---|
232 |
|
---|
233 | #ifdef CR_ARB_depth_texture
|
---|
234 | tobj->depthMode = GL_LUMINANCE;
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | #ifdef CR_ARB_shadow
|
---|
238 | tobj->compareMode = GL_NONE;
|
---|
239 | tobj->compareFunc = GL_LEQUAL;
|
---|
240 | #endif
|
---|
241 |
|
---|
242 | #ifdef CR_ARB_shadow_ambient
|
---|
243 | tobj->compareFailValue = 0.0;
|
---|
244 | #endif
|
---|
245 |
|
---|
246 | RESET(tobj->dirty, ctx->bitid);
|
---|
247 | RESET(tobj->imageBit, ctx->bitid);
|
---|
248 | for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++)
|
---|
249 | {
|
---|
250 | RESET(tobj->paramsBit[i], ctx->bitid);
|
---|
251 | }
|
---|
252 |
|
---|
253 | CR_STATE_SHAREDOBJ_USAGE_INIT(tobj);
|
---|
254 | CR_STATE_SHAREDOBJ_USAGE_SET(tobj, ctx);
|
---|
255 | }
|
---|
256 |
|
---|
257 |
|
---|
258 | /* ================================================================
|
---|
259 | * Texture internal formats:
|
---|
260 | */
|
---|
261 |
|
---|
262 | const CRTextureFormat _texformat_rgba8888 = {
|
---|
263 | 8, /* RedBits */
|
---|
264 | 8, /* GreenBits */
|
---|
265 | 8, /* BlueBits */
|
---|
266 | 8, /* AlphaBits */
|
---|
267 | 0, /* LuminanceBits */
|
---|
268 | 0, /* IntensityBits */
|
---|
269 | 0, /* IndexBits */
|
---|
270 | };
|
---|
271 |
|
---|
272 | const CRTextureFormat _texformat_argb8888 = {
|
---|
273 | 8, /* RedBits */
|
---|
274 | 8, /* GreenBits */
|
---|
275 | 8, /* BlueBits */
|
---|
276 | 8, /* AlphaBits */
|
---|
277 | 0, /* LuminanceBits */
|
---|
278 | 0, /* IntensityBits */
|
---|
279 | 0, /* IndexBits */
|
---|
280 | };
|
---|
281 |
|
---|
282 | const CRTextureFormat _texformat_rgb888 = {
|
---|
283 | 8, /* RedBits */
|
---|
284 | 8, /* GreenBits */
|
---|
285 | 8, /* BlueBits */
|
---|
286 | 0, /* AlphaBits */
|
---|
287 | 0, /* LuminanceBits */
|
---|
288 | 0, /* IntensityBits */
|
---|
289 | 0, /* IndexBits */
|
---|
290 | };
|
---|
291 |
|
---|
292 | const CRTextureFormat _texformat_rgb565 = {
|
---|
293 | 5, /* RedBits */
|
---|
294 | 6, /* GreenBits */
|
---|
295 | 5, /* BlueBits */
|
---|
296 | 0, /* AlphaBits */
|
---|
297 | 0, /* LuminanceBits */
|
---|
298 | 0, /* IntensityBits */
|
---|
299 | 0, /* IndexBits */
|
---|
300 | };
|
---|
301 |
|
---|
302 | const CRTextureFormat _texformat_argb4444 = {
|
---|
303 | 4, /* RedBits */
|
---|
304 | 4, /* GreenBits */
|
---|
305 | 4, /* BlueBits */
|
---|
306 | 4, /* AlphaBits */
|
---|
307 | 0, /* LuminanceBits */
|
---|
308 | 0, /* IntensityBits */
|
---|
309 | 0, /* IndexBits */
|
---|
310 | };
|
---|
311 |
|
---|
312 | const CRTextureFormat _texformat_argb1555 = {
|
---|
313 | 5, /* RedBits */
|
---|
314 | 5, /* GreenBits */
|
---|
315 | 5, /* BlueBits */
|
---|
316 | 1, /* AlphaBits */
|
---|
317 | 0, /* LuminanceBits */
|
---|
318 | 0, /* IntensityBits */
|
---|
319 | 0, /* IndexBits */
|
---|
320 | };
|
---|
321 |
|
---|
322 | const CRTextureFormat _texformat_al88 = {
|
---|
323 | 0, /* RedBits */
|
---|
324 | 0, /* GreenBits */
|
---|
325 | 0, /* BlueBits */
|
---|
326 | 8, /* AlphaBits */
|
---|
327 | 8, /* LuminanceBits */
|
---|
328 | 0, /* IntensityBits */
|
---|
329 | 0, /* IndexBits */
|
---|
330 | };
|
---|
331 |
|
---|
332 | const CRTextureFormat _texformat_rgb332 = {
|
---|
333 | 3, /* RedBits */
|
---|
334 | 3, /* GreenBits */
|
---|
335 | 2, /* BlueBits */
|
---|
336 | 0, /* AlphaBits */
|
---|
337 | 0, /* LuminanceBits */
|
---|
338 | 0, /* IntensityBits */
|
---|
339 | 0, /* IndexBits */
|
---|
340 | };
|
---|
341 |
|
---|
342 | const CRTextureFormat _texformat_a8 = {
|
---|
343 | 0, /* RedBits */
|
---|
344 | 0, /* GreenBits */
|
---|
345 | 0, /* BlueBits */
|
---|
346 | 8, /* AlphaBits */
|
---|
347 | 0, /* LuminanceBits */
|
---|
348 | 0, /* IntensityBits */
|
---|
349 | 0, /* IndexBits */
|
---|
350 | };
|
---|
351 |
|
---|
352 | const CRTextureFormat _texformat_l8 = {
|
---|
353 | 0, /* RedBits */
|
---|
354 | 0, /* GreenBits */
|
---|
355 | 0, /* BlueBits */
|
---|
356 | 0, /* AlphaBits */
|
---|
357 | 8, /* LuminanceBits */
|
---|
358 | 0, /* IntensityBits */
|
---|
359 | 0, /* IndexBits */
|
---|
360 | };
|
---|
361 |
|
---|
362 | const CRTextureFormat _texformat_i8 = {
|
---|
363 | 0, /* RedBits */
|
---|
364 | 0, /* GreenBits */
|
---|
365 | 0, /* BlueBits */
|
---|
366 | 0, /* AlphaBits */
|
---|
367 | 0, /* LuminanceBits */
|
---|
368 | 8, /* IntensityBits */
|
---|
369 | 0, /* IndexBits */
|
---|
370 | };
|
---|
371 |
|
---|
372 | const CRTextureFormat _texformat_ci8 = {
|
---|
373 | 0, /* RedBits */
|
---|
374 | 0, /* GreenBits */
|
---|
375 | 0, /* BlueBits */
|
---|
376 | 0, /* AlphaBits */
|
---|
377 | 0, /* LuminanceBits */
|
---|
378 | 0, /* IntensityBits */
|
---|
379 | 8, /* IndexBits */
|
---|
380 | };
|
---|
381 |
|
---|
382 |
|
---|
383 | /**
|
---|
384 | * Given an internal texture format enum or 1, 2, 3, 4 initialize the
|
---|
385 | * texture levels texture format. This basically just indicates the
|
---|
386 | * number of red, green, blue, alpha, luminance, etc. bits are used to
|
---|
387 | * store the image.
|
---|
388 | */
|
---|
389 | void
|
---|
390 | crStateTextureInitTextureFormat( CRTextureLevel *tl, GLenum internalFormat )
|
---|
391 | {
|
---|
392 | switch (internalFormat) {
|
---|
393 | case 4:
|
---|
394 | case GL_RGBA:
|
---|
395 | case GL_COMPRESSED_RGBA_ARB:
|
---|
396 | #ifdef CR_EXT_texture_sRGB
|
---|
397 | case GL_SRGB_ALPHA_EXT:
|
---|
398 | case GL_SRGB8_ALPHA8_EXT:
|
---|
399 | case GL_COMPRESSED_SRGB_ALPHA_EXT:
|
---|
400 | #endif
|
---|
401 | tl->texFormat = &_texformat_rgba8888;
|
---|
402 | break;
|
---|
403 |
|
---|
404 | case 3:
|
---|
405 | case GL_RGB:
|
---|
406 | case GL_COMPRESSED_RGB_ARB:
|
---|
407 | #ifdef CR_EXT_texture_sRGB
|
---|
408 | case GL_SRGB_EXT:
|
---|
409 | case GL_SRGB8_EXT:
|
---|
410 | case GL_COMPRESSED_SRGB_EXT:
|
---|
411 | #endif
|
---|
412 | tl->texFormat = &_texformat_rgb888;
|
---|
413 | break;
|
---|
414 |
|
---|
415 | case GL_RGBA2:
|
---|
416 | case GL_RGBA4:
|
---|
417 | case GL_RGB5_A1:
|
---|
418 | case GL_RGBA8:
|
---|
419 | case GL_RGB10_A2:
|
---|
420 | case GL_RGBA12:
|
---|
421 | case GL_RGBA16:
|
---|
422 | tl->texFormat = &_texformat_rgba8888;
|
---|
423 | break;
|
---|
424 |
|
---|
425 | case GL_R3_G3_B2:
|
---|
426 | tl->texFormat = &_texformat_rgb332;
|
---|
427 | break;
|
---|
428 | case GL_RGB4:
|
---|
429 | case GL_RGB5:
|
---|
430 | case GL_RGB8:
|
---|
431 | case GL_RGB10:
|
---|
432 | case GL_RGB12:
|
---|
433 | case GL_RGB16:
|
---|
434 | tl->texFormat = &_texformat_rgb888;
|
---|
435 | break;
|
---|
436 |
|
---|
437 | case GL_ALPHA:
|
---|
438 | case GL_ALPHA4:
|
---|
439 | case GL_ALPHA8:
|
---|
440 | case GL_ALPHA12:
|
---|
441 | case GL_ALPHA16:
|
---|
442 | case GL_COMPRESSED_ALPHA_ARB:
|
---|
443 | tl->texFormat = &_texformat_a8;
|
---|
444 | break;
|
---|
445 |
|
---|
446 | case 1:
|
---|
447 | case GL_LUMINANCE:
|
---|
448 | case GL_LUMINANCE4:
|
---|
449 | case GL_LUMINANCE8:
|
---|
450 | case GL_LUMINANCE12:
|
---|
451 | case GL_LUMINANCE16:
|
---|
452 | case GL_COMPRESSED_LUMINANCE_ARB:
|
---|
453 | #ifdef CR_EXT_texture_sRGB
|
---|
454 | case GL_SLUMINANCE_EXT:
|
---|
455 | case GL_SLUMINANCE8_EXT:
|
---|
456 | case GL_COMPRESSED_SLUMINANCE_EXT:
|
---|
457 | #endif
|
---|
458 | tl->texFormat = &_texformat_l8;
|
---|
459 | break;
|
---|
460 |
|
---|
461 | case 2:
|
---|
462 | case GL_LUMINANCE_ALPHA:
|
---|
463 | case GL_LUMINANCE4_ALPHA4:
|
---|
464 | case GL_LUMINANCE6_ALPHA2:
|
---|
465 | case GL_LUMINANCE8_ALPHA8:
|
---|
466 | case GL_LUMINANCE12_ALPHA4:
|
---|
467 | case GL_LUMINANCE12_ALPHA12:
|
---|
468 | case GL_LUMINANCE16_ALPHA16:
|
---|
469 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
|
---|
470 | #ifdef CR_EXT_texture_sRGB
|
---|
471 | case GL_SLUMINANCE_ALPHA_EXT:
|
---|
472 | case GL_SLUMINANCE8_ALPHA8_EXT:
|
---|
473 | case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
|
---|
474 | #endif
|
---|
475 | tl->texFormat = &_texformat_al88;
|
---|
476 | break;
|
---|
477 |
|
---|
478 | case GL_INTENSITY:
|
---|
479 | case GL_INTENSITY4:
|
---|
480 | case GL_INTENSITY8:
|
---|
481 | case GL_INTENSITY12:
|
---|
482 | case GL_INTENSITY16:
|
---|
483 | case GL_COMPRESSED_INTENSITY_ARB:
|
---|
484 | tl->texFormat = &_texformat_i8;
|
---|
485 | break;
|
---|
486 |
|
---|
487 | case GL_COLOR_INDEX:
|
---|
488 | case GL_COLOR_INDEX1_EXT:
|
---|
489 | case GL_COLOR_INDEX2_EXT:
|
---|
490 | case GL_COLOR_INDEX4_EXT:
|
---|
491 | case GL_COLOR_INDEX8_EXT:
|
---|
492 | case GL_COLOR_INDEX12_EXT:
|
---|
493 | case GL_COLOR_INDEX16_EXT:
|
---|
494 | tl->texFormat = &_texformat_ci8;
|
---|
495 | break;
|
---|
496 |
|
---|
497 | default:
|
---|
498 | return;
|
---|
499 | }
|
---|
500 | }
|
---|
501 |
|
---|
502 | #if 0
|
---|
503 | void crStateTextureInitTexture (GLuint name)
|
---|
504 | {
|
---|
505 | CRContext *g = GetCurrentContext();
|
---|
506 | CRTextureState *t = &(g->texture);
|
---|
507 | CRTextureObj *tobj;
|
---|
508 |
|
---|
509 | GET_TOBJ(tobj, name);
|
---|
510 | if (!tobj) return;
|
---|
511 |
|
---|
512 | crStateTextureInitTextureObj(g, tobj, name, GL_NONE);
|
---|
513 | }
|
---|
514 | #endif
|
---|
515 |
|
---|
516 |
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * Return the texture object corresponding to the given target and ID.
|
---|
520 | */
|
---|
521 | CRTextureObj *
|
---|
522 | crStateTextureGet(GLenum target, GLuint name)
|
---|
523 | {
|
---|
524 | CRContext *g = GetCurrentContext();
|
---|
525 | CRTextureState *t = &(g->texture);
|
---|
526 | CRTextureObj *tobj;
|
---|
527 |
|
---|
528 | if (name == 0)
|
---|
529 | {
|
---|
530 | switch (target) {
|
---|
531 | case GL_TEXTURE_1D:
|
---|
532 | return &t->base1D;
|
---|
533 | case GL_TEXTURE_2D:
|
---|
534 | return &t->base2D;
|
---|
535 | case GL_TEXTURE_3D:
|
---|
536 | return &t->base3D;
|
---|
537 | #ifdef CR_ARB_texture_cube_map
|
---|
538 | case GL_TEXTURE_CUBE_MAP_ARB:
|
---|
539 | return &t->baseCubeMap;
|
---|
540 | #endif
|
---|
541 | #ifdef CR_NV_texture_rectangle
|
---|
542 | case GL_TEXTURE_RECTANGLE_NV:
|
---|
543 | return &t->baseRect;
|
---|
544 | #endif
|
---|
545 | default:
|
---|
546 | return NULL;
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | GET_TOBJ(tobj, g, name);
|
---|
551 |
|
---|
552 | return tobj;
|
---|
553 | }
|
---|
554 |
|
---|
555 |
|
---|
556 | /*
|
---|
557 | * Allocate a new texture object with the given name.
|
---|
558 | * Also insert into hash table.
|
---|
559 | */
|
---|
560 | static CRTextureObj *
|
---|
561 | crStateTextureAllocate_t(CRContext *ctx, GLuint name)
|
---|
562 | {
|
---|
563 | CRTextureObj *tobj;
|
---|
564 |
|
---|
565 | if (!name)
|
---|
566 | return NULL;
|
---|
567 |
|
---|
568 | tobj = crCalloc(sizeof(CRTextureObj));
|
---|
569 | if (!tobj)
|
---|
570 | return NULL;
|
---|
571 |
|
---|
572 | crHashtableAdd( ctx->shared->textureTable, name, (void *) tobj );
|
---|
573 |
|
---|
574 | crStateTextureInitTextureObj(ctx, tobj, name, GL_NONE);
|
---|
575 |
|
---|
576 | return tobj;
|
---|
577 | }
|
---|
578 |
|
---|
579 |
|
---|
580 | /**
|
---|
581 | * Delete all the data that hangs off a CRTextureObj, but don't
|
---|
582 | * delete the texture object itself, since it may not have been
|
---|
583 | * dynamically allocated.
|
---|
584 | */
|
---|
585 | void
|
---|
586 | crStateDeleteTextureObjectData(CRTextureObj *tobj)
|
---|
587 | {
|
---|
588 | int k;
|
---|
589 | int face;
|
---|
590 |
|
---|
591 | CRASSERT(tobj);
|
---|
592 |
|
---|
593 | /* Free the texture images */
|
---|
594 | for (face = 0; face < 6; face++) {
|
---|
595 | CRTextureLevel *levels = NULL;
|
---|
596 | levels = tobj->level[face];
|
---|
597 | if (levels) {
|
---|
598 | /* free all mipmap levels for this face */
|
---|
599 | for (k = 0; k < CR_MAX_MIPMAP_LEVELS; k++) {
|
---|
600 | CRTextureLevel *tl = levels + k;
|
---|
601 | if (tl->img) {
|
---|
602 | crFree(tl->img);
|
---|
603 | tl->img = NULL;
|
---|
604 | tl->bytes = 0;
|
---|
605 | }
|
---|
606 | }
|
---|
607 | crFree(levels);
|
---|
608 | }
|
---|
609 | tobj->level[face] = NULL;
|
---|
610 | }
|
---|
611 | }
|
---|
612 |
|
---|
613 |
|
---|
614 | void
|
---|
615 | crStateDeleteTextureObject(CRTextureObj *tobj)
|
---|
616 | {
|
---|
617 | crStateDeleteTextureObjectData(tobj);
|
---|
618 | crFree(tobj);
|
---|
619 | }
|
---|
620 |
|
---|
621 | void crStateRegNames(CRContext *g, CRHashTable *table, GLsizei n, GLuint *names)
|
---|
622 | {
|
---|
623 | GLint i;
|
---|
624 | (void)g;
|
---|
625 | for (i = 0; i < n; i++)
|
---|
626 | {
|
---|
627 | if (names[i])
|
---|
628 | {
|
---|
629 | GLboolean isNewKey = crHashtableAllocRegisterKey(table, names[i]);
|
---|
630 | CRASSERT(isNewKey);
|
---|
631 | }
|
---|
632 | else
|
---|
633 | crWarning("RegNames: requested to register a null name");
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 | void crStateRegTextures(GLsizei n, GLuint *names)
|
---|
638 | {
|
---|
639 | CRContext *g = GetCurrentContext();
|
---|
640 | crStateRegNames(g, g->shared->textureTable, n, names);
|
---|
641 | }
|
---|
642 |
|
---|
643 | void crStateGenNames(CRContext *g, CRHashTable *table, GLsizei n, GLuint *names)
|
---|
644 | {
|
---|
645 | GLint start;
|
---|
646 |
|
---|
647 | FLUSH();
|
---|
648 |
|
---|
649 | if (g->current.inBeginEnd)
|
---|
650 | {
|
---|
651 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
652 | "crStateGenNames called in Begin/End");
|
---|
653 | return;
|
---|
654 | }
|
---|
655 |
|
---|
656 | if (n < 0)
|
---|
657 | {
|
---|
658 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
659 | "Negative n passed to crStateGenNames: %d", n);
|
---|
660 | return;
|
---|
661 | }
|
---|
662 |
|
---|
663 | start = crHashtableAllocKeys(table, n);
|
---|
664 | if (start)
|
---|
665 | {
|
---|
666 | GLint i;
|
---|
667 | for (i = 0; i < n; i++)
|
---|
668 | names[i] = (GLuint) (start + i);
|
---|
669 | }
|
---|
670 | else
|
---|
671 | {
|
---|
672 | crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenTextures");
|
---|
673 | }
|
---|
674 | }
|
---|
675 |
|
---|
676 | void STATE_APIENTRY crStateGenTextures(GLsizei n, GLuint *textures)
|
---|
677 | {
|
---|
678 | CRContext *g = GetCurrentContext();
|
---|
679 | crStateGenNames(g, g->shared->textureTable, n, textures);
|
---|
680 | }
|
---|
681 |
|
---|
682 | static void crStateTextureCheckFBOAPs(GLenum target, GLuint texture)
|
---|
683 | {
|
---|
684 | GLuint u;
|
---|
685 | CRFBOAttachmentPoint *ap;
|
---|
686 | CRContext *g = GetCurrentContext();
|
---|
687 | CRFramebufferObjectState *fbo = &g->framebufferobject;
|
---|
688 | CRFramebufferObject *pFBO;
|
---|
689 |
|
---|
690 | pFBO = GL_READ_FRAMEBUFFER==target ? fbo->readFB : fbo->drawFB;
|
---|
691 | if (!pFBO) return;
|
---|
692 |
|
---|
693 | for (u=0; u<CR_MAX_COLOR_ATTACHMENTS; ++u)
|
---|
694 | {
|
---|
695 | ap = &pFBO->color[u];
|
---|
696 | if (ap->type==GL_TEXTURE && ap->name==texture)
|
---|
697 | {
|
---|
698 | crStateFramebufferTexture1DEXT(target, u+GL_COLOR_ATTACHMENT0_EXT, 0, 0, 0);
|
---|
699 | }
|
---|
700 | }
|
---|
701 |
|
---|
702 | ap = &pFBO->depth;
|
---|
703 | if (ap->type==GL_TEXTURE && ap->name==texture)
|
---|
704 | {
|
---|
705 | crStateFramebufferTexture1DEXT(target, GL_DEPTH_ATTACHMENT_EXT, 0, 0, 0);
|
---|
706 | }
|
---|
707 |
|
---|
708 | ap = &pFBO->stencil;
|
---|
709 | if (ap->type==GL_TEXTURE && ap->name==texture)
|
---|
710 | {
|
---|
711 | crStateFramebufferTexture1DEXT(target, GL_STENCIL_ATTACHMENT_EXT, 0, 0, 0);
|
---|
712 | }
|
---|
713 | }
|
---|
714 |
|
---|
715 | static void crStateCleanupTextureRefs(CRContext *g, CRTextureObj *tObj)
|
---|
716 | {
|
---|
717 | CRTextureState *t = &(g->texture);
|
---|
718 | GLuint u;
|
---|
719 |
|
---|
720 | /*
|
---|
721 | ** reset back to the base texture.
|
---|
722 | */
|
---|
723 | for (u = 0; u < g->limits.maxTextureUnits; u++)
|
---|
724 | {
|
---|
725 | if (tObj == t->unit[u].currentTexture1D)
|
---|
726 | {
|
---|
727 | t->unit[u].currentTexture1D = &(t->base1D);
|
---|
728 | }
|
---|
729 | if (tObj == t->unit[u].currentTexture2D)
|
---|
730 | {
|
---|
731 | t->unit[u].currentTexture2D = &(t->base2D);
|
---|
732 | }
|
---|
733 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
734 | if (tObj == t->unit[u].currentTexture3D)
|
---|
735 | {
|
---|
736 | t->unit[u].currentTexture3D = &(t->base3D);
|
---|
737 | }
|
---|
738 | #endif
|
---|
739 | #ifdef CR_ARB_texture_cube_map
|
---|
740 | if (tObj == t->unit[u].currentTextureCubeMap)
|
---|
741 | {
|
---|
742 | t->unit[u].currentTextureCubeMap = &(t->baseCubeMap);
|
---|
743 | }
|
---|
744 | #endif
|
---|
745 | #ifdef CR_NV_texture_rectangle
|
---|
746 | if (tObj == t->unit[u].currentTextureRect)
|
---|
747 | {
|
---|
748 | t->unit[u].currentTextureRect = &(t->baseRect);
|
---|
749 | }
|
---|
750 | #endif
|
---|
751 |
|
---|
752 | #ifdef CR_EXT_framebuffer_object
|
---|
753 | crStateTextureCheckFBOAPs(GL_DRAW_FRAMEBUFFER, tObj->id);
|
---|
754 | crStateTextureCheckFBOAPs(GL_READ_FRAMEBUFFER, tObj->id);
|
---|
755 | #endif
|
---|
756 | }
|
---|
757 | }
|
---|
758 |
|
---|
759 | void STATE_APIENTRY crStateDeleteTextures(GLsizei n, const GLuint *textures)
|
---|
760 | {
|
---|
761 | CRContext *g = GetCurrentContext();
|
---|
762 | CRTextureState *t = &(g->texture);
|
---|
763 | CRStateBits *sb = GetCurrentBits();
|
---|
764 | CRTextureBits *tb = &(sb->texture);
|
---|
765 | int i;
|
---|
766 |
|
---|
767 | FLUSH();
|
---|
768 |
|
---|
769 | if (g->current.inBeginEnd)
|
---|
770 | {
|
---|
771 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
772 | "glDeleteTextures called in Begin/End");
|
---|
773 | return;
|
---|
774 | }
|
---|
775 |
|
---|
776 | if (n < 0)
|
---|
777 | {
|
---|
778 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
779 | "Negative n passed to glDeleteTextures: %d", n);
|
---|
780 | return;
|
---|
781 | }
|
---|
782 |
|
---|
783 | for (i=0; i<n; i++)
|
---|
784 | {
|
---|
785 | GLuint name = textures[i];
|
---|
786 | CRTextureObj *tObj;
|
---|
787 | if (!name)
|
---|
788 | continue;
|
---|
789 |
|
---|
790 | GET_TOBJ(tObj, g, name);
|
---|
791 | if (tObj)
|
---|
792 | {
|
---|
793 | GLuint j;
|
---|
794 |
|
---|
795 | crStateCleanupTextureRefs(g, tObj);
|
---|
796 |
|
---|
797 | CR_STATE_SHAREDOBJ_USAGE_CLEAR(tObj, g);
|
---|
798 |
|
---|
799 | CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(tObj, j)
|
---|
800 | {
|
---|
801 | /* saved state version <= SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS does not have usage bits info,
|
---|
802 | * so on restore, we set mark bits as used.
|
---|
803 | * This is why g_pAvailableContexts[j] could be NULL
|
---|
804 | * also g_pAvailableContexts[0] will hold default context, which we should discard */
|
---|
805 | CRContext *ctx = g_pAvailableContexts[j];
|
---|
806 | if (j && ctx)
|
---|
807 | {
|
---|
808 | crStateCleanupTextureRefs(ctx, tObj);
|
---|
809 | CR_STATE_SHAREDOBJ_USAGE_CLEAR(tObj, g);
|
---|
810 | }
|
---|
811 | else
|
---|
812 | CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX(tObj, j);
|
---|
813 | }
|
---|
814 |
|
---|
815 | /* on the host side, ogl texture object is deleted by a separate cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
|
---|
816 | * in crServerDispatchDeleteTextures, we just delete a state object here, which crStateDeleteTextureObject does */
|
---|
817 | crHashtableDelete(g->shared->textureTable, name, (CRHashtableCallback)crStateDeleteTextureObject);
|
---|
818 | }
|
---|
819 | else
|
---|
820 | {
|
---|
821 | /* call crHashtableDelete in any way, to ensure the allocated key is freed */
|
---|
822 | Assert(crHashtableIsKeyUsed(g->shared->textureTable, name));
|
---|
823 | crHashtableDelete(g->shared->textureTable, name, NULL);
|
---|
824 | }
|
---|
825 | }
|
---|
826 |
|
---|
827 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
828 | DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
|
---|
829 | }
|
---|
830 |
|
---|
831 |
|
---|
832 |
|
---|
833 | void STATE_APIENTRY crStateClientActiveTextureARB( GLenum texture )
|
---|
834 | {
|
---|
835 | CRContext *g = GetCurrentContext();
|
---|
836 | CRClientState *c = &(g->client);
|
---|
837 |
|
---|
838 | FLUSH();
|
---|
839 |
|
---|
840 | if (!g->extensions.ARB_multitexture) {
|
---|
841 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
842 | "glClientActiveTextureARB not available");
|
---|
843 | return;
|
---|
844 | }
|
---|
845 |
|
---|
846 | if (g->current.inBeginEnd)
|
---|
847 | {
|
---|
848 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
849 | "glClientActiveTextureARB called in Begin/End");
|
---|
850 | return;
|
---|
851 | }
|
---|
852 |
|
---|
853 | if ( texture < GL_TEXTURE0_ARB ||
|
---|
854 | texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
|
---|
855 | {
|
---|
856 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
857 | "crStateClientActiveTexture: unit = %d (max is %d)",
|
---|
858 | texture, g->limits.maxTextureUnits );
|
---|
859 | return;
|
---|
860 | }
|
---|
861 |
|
---|
862 | c->curClientTextureUnit = texture - GL_TEXTURE0_ARB;
|
---|
863 |
|
---|
864 | DIRTY(GetCurrentBits()->client.dirty, g->neg_bitid);
|
---|
865 | }
|
---|
866 |
|
---|
867 | void STATE_APIENTRY crStateActiveTextureARB( GLenum texture )
|
---|
868 | {
|
---|
869 | CRContext *g = GetCurrentContext();
|
---|
870 | CRTextureState *t = &(g->texture);
|
---|
871 |
|
---|
872 | FLUSH();
|
---|
873 |
|
---|
874 | if (!g->extensions.ARB_multitexture) {
|
---|
875 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
876 | "glActiveTextureARB not available");
|
---|
877 | return;
|
---|
878 | }
|
---|
879 |
|
---|
880 | if (g->current.inBeginEnd)
|
---|
881 | {
|
---|
882 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glActiveTextureARB called in Begin/End");
|
---|
883 | return;
|
---|
884 | }
|
---|
885 |
|
---|
886 | if ( texture < GL_TEXTURE0_ARB || texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
|
---|
887 | {
|
---|
888 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Bad texture unit passed to crStateActiveTexture: %d (max is %d)", texture, g->limits.maxTextureUnits );
|
---|
889 | return;
|
---|
890 | }
|
---|
891 |
|
---|
892 | t->curTextureUnit = texture - GL_TEXTURE0_ARB;
|
---|
893 |
|
---|
894 | /* update the current matrix pointer, etc. */
|
---|
895 | if (g->transform.matrixMode == GL_TEXTURE) {
|
---|
896 | crStateMatrixMode(GL_TEXTURE);
|
---|
897 | }
|
---|
898 | }
|
---|
899 |
|
---|
900 | #ifndef IN_GUEST
|
---|
901 | # ifdef DEBUG
|
---|
902 | static uint32_t gDbgNumPinned = 0;
|
---|
903 | # endif
|
---|
904 |
|
---|
905 | DECLEXPORT(void) crStatePinTexture(GLuint texture, GLboolean pin)
|
---|
906 | {
|
---|
907 | CRTextureObj * pTobj;
|
---|
908 | CRSharedState *pShared = crStateGlobalSharedAcquire();
|
---|
909 | if (pShared)
|
---|
910 | {
|
---|
911 | pTobj = (CRTextureObj*)crHashtableSearch(pShared->textureTable, texture);
|
---|
912 |
|
---|
913 | if (pTobj)
|
---|
914 | {
|
---|
915 | # ifdef DEBUG
|
---|
916 | if (!pTobj->pinned != !pin)
|
---|
917 | {
|
---|
918 | if (pin)
|
---|
919 | ++gDbgNumPinned;
|
---|
920 | else
|
---|
921 | {
|
---|
922 | Assert(gDbgNumPinned);
|
---|
923 | --gDbgNumPinned;
|
---|
924 | }
|
---|
925 | }
|
---|
926 | # endif
|
---|
927 | pTobj->pinned = !!pin;
|
---|
928 | if (!pin)
|
---|
929 | {
|
---|
930 | if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pTobj))
|
---|
931 | crStateOnTextureUsageRelease(pShared, pTobj);
|
---|
932 | }
|
---|
933 | }
|
---|
934 | else
|
---|
935 | WARN(("texture %d not defined", texture));
|
---|
936 |
|
---|
937 | crStateGlobalSharedRelease();
|
---|
938 | }
|
---|
939 | else
|
---|
940 | WARN(("no global shared"));
|
---|
941 | }
|
---|
942 | #endif
|
---|
943 |
|
---|
944 | DECLEXPORT(void) crStateSetTextureUsed(GLuint texture, GLboolean used)
|
---|
945 | {
|
---|
946 | CRContext *g = GetCurrentContext();
|
---|
947 | CRTextureObj *tobj;
|
---|
948 |
|
---|
949 | if (!texture)
|
---|
950 | {
|
---|
951 | crWarning("crStateSetTextureUsed: null texture name specified!");
|
---|
952 | return;
|
---|
953 | }
|
---|
954 |
|
---|
955 | GET_TOBJ(tobj, g, texture);
|
---|
956 | if (!tobj)
|
---|
957 | {
|
---|
958 | #ifdef IN_GUEST
|
---|
959 | if (used)
|
---|
960 | {
|
---|
961 | tobj = crStateTextureAllocate_t(g, texture);
|
---|
962 | }
|
---|
963 | else
|
---|
964 | #endif
|
---|
965 | {
|
---|
966 | WARN(("crStateSetTextureUsed: failed to fined a HW name for texture(%d)!", texture));
|
---|
967 | return;
|
---|
968 | }
|
---|
969 | }
|
---|
970 |
|
---|
971 | if (used)
|
---|
972 | CR_STATE_SHAREDOBJ_USAGE_SET(tobj, g);
|
---|
973 | else
|
---|
974 | {
|
---|
975 | CRStateBits *sb = GetCurrentBits();
|
---|
976 | CRTextureBits *tb = &(sb->texture);
|
---|
977 | CRTextureState *t = &(g->texture);
|
---|
978 |
|
---|
979 | crStateCleanupTextureRefs(g, tobj);
|
---|
980 |
|
---|
981 | crStateReleaseTexture(g, tobj);
|
---|
982 |
|
---|
983 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
984 | DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
|
---|
985 | }
|
---|
986 | }
|
---|
987 |
|
---|
988 | void STATE_APIENTRY crStateBindTexture(GLenum target, GLuint texture)
|
---|
989 | {
|
---|
990 | CRContext *g = GetCurrentContext();
|
---|
991 | CRTextureState *t = &(g->texture);
|
---|
992 | CRTextureObj *tobj;
|
---|
993 | CRStateBits *sb = GetCurrentBits();
|
---|
994 | CRTextureBits *tb = &(sb->texture);
|
---|
995 |
|
---|
996 | FLUSH();
|
---|
997 |
|
---|
998 | if (g->current.inBeginEnd)
|
---|
999 | {
|
---|
1000 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBindTexture called in Begin/End");
|
---|
1001 | return;
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | /* Special Case name = 0 */
|
---|
1005 | if (!texture)
|
---|
1006 | {
|
---|
1007 | switch (target)
|
---|
1008 | {
|
---|
1009 | case GL_TEXTURE_1D:
|
---|
1010 | t->unit[t->curTextureUnit].currentTexture1D = &(t->base1D);
|
---|
1011 | break;
|
---|
1012 | case GL_TEXTURE_2D:
|
---|
1013 | t->unit[t->curTextureUnit].currentTexture2D = &(t->base2D);
|
---|
1014 | break;
|
---|
1015 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1016 | case GL_TEXTURE_3D:
|
---|
1017 | t->unit[t->curTextureUnit].currentTexture3D = &(t->base3D);
|
---|
1018 | break;
|
---|
1019 | #endif
|
---|
1020 | #ifdef CR_ARB_texture_cube_map
|
---|
1021 | case GL_TEXTURE_CUBE_MAP_ARB:
|
---|
1022 | if (!g->extensions.ARB_texture_cube_map) {
|
---|
1023 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1024 | "Invalid target passed to glBindTexture: %d", target);
|
---|
1025 | return;
|
---|
1026 | }
|
---|
1027 | t->unit[t->curTextureUnit].currentTextureCubeMap = &(t->baseCubeMap);
|
---|
1028 | break;
|
---|
1029 | #endif
|
---|
1030 | #ifdef CR_NV_texture_rectangle
|
---|
1031 | case GL_TEXTURE_RECTANGLE_NV:
|
---|
1032 | if (!g->extensions.NV_texture_rectangle) {
|
---|
1033 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1034 | "Invalid target passed to glBindTexture: %d", target);
|
---|
1035 | return;
|
---|
1036 | }
|
---|
1037 | t->unit[t->curTextureUnit].currentTextureRect = &(t->baseRect);
|
---|
1038 | break;
|
---|
1039 | #endif
|
---|
1040 | default:
|
---|
1041 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid target passed to glBindTexture: %d", target);
|
---|
1042 | return;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
1046 | DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
|
---|
1047 | return;
|
---|
1048 | }
|
---|
1049 |
|
---|
1050 | /* texture != 0 */
|
---|
1051 | /* Get the texture */
|
---|
1052 | GET_TOBJ(tobj, g, texture);
|
---|
1053 | if (!tobj)
|
---|
1054 | {
|
---|
1055 | Assert(crHashtableIsKeyUsed(g->shared->textureTable, texture));
|
---|
1056 | tobj = crStateTextureAllocate_t(g, texture);
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | CR_STATE_SHAREDOBJ_USAGE_SET(tobj, g);
|
---|
1060 |
|
---|
1061 | /* Check the targets */
|
---|
1062 | if (tobj->target == GL_NONE)
|
---|
1063 | {
|
---|
1064 | /* Target isn't set so set it now.*/
|
---|
1065 | tobj->target = target;
|
---|
1066 | }
|
---|
1067 | else if ((tobj->target != target)
|
---|
1068 | && !((target==GL_TEXTURE_RECTANGLE_NV && tobj->target==GL_TEXTURE_2D)
|
---|
1069 | ||(target==GL_TEXTURE_2D && tobj->target==GL_TEXTURE_RECTANGLE_NV)))
|
---|
1070 | {
|
---|
1071 | crWarning( "You called glBindTexture with a target of 0x%x, but the texture you wanted was target 0x%x [1D: %x 2D: %x 3D: %x cube: %x]", (int) target, (int) tobj->target, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP );
|
---|
1072 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Attempt to bind a texture of different dimensions");
|
---|
1073 | return;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | /* Set the current texture */
|
---|
1077 | switch (target)
|
---|
1078 | {
|
---|
1079 | case GL_TEXTURE_1D:
|
---|
1080 | t->unit[t->curTextureUnit].currentTexture1D = tobj;
|
---|
1081 | break;
|
---|
1082 | case GL_TEXTURE_2D:
|
---|
1083 | t->unit[t->curTextureUnit].currentTexture2D = tobj;
|
---|
1084 | break;
|
---|
1085 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1086 | case GL_TEXTURE_3D:
|
---|
1087 | t->unit[t->curTextureUnit].currentTexture3D = tobj;
|
---|
1088 | break;
|
---|
1089 | #endif
|
---|
1090 | #ifdef CR_ARB_texture_cube_map
|
---|
1091 | case GL_TEXTURE_CUBE_MAP_ARB:
|
---|
1092 | t->unit[t->curTextureUnit].currentTextureCubeMap = tobj;
|
---|
1093 | break;
|
---|
1094 | #endif
|
---|
1095 | #ifdef CR_NV_texture_rectangle
|
---|
1096 | case GL_TEXTURE_RECTANGLE_NV:
|
---|
1097 | t->unit[t->curTextureUnit].currentTextureRect = tobj;
|
---|
1098 | break;
|
---|
1099 | #endif
|
---|
1100 | default:
|
---|
1101 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1102 | "Invalid target passed to glBindTexture: %d", target);
|
---|
1103 | return;
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
1107 | DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 |
|
---|
1111 | void STATE_APIENTRY
|
---|
1112 | crStateTexParameterfv(GLenum target, GLenum pname, const GLfloat *param)
|
---|
1113 | {
|
---|
1114 | CRContext *g = GetCurrentContext();
|
---|
1115 | CRTextureObj *tobj = NULL;
|
---|
1116 | CRTextureLevel *tl = NULL;
|
---|
1117 | GLenum e = (GLenum) *param;
|
---|
1118 | CRStateBits *sb = GetCurrentBits();
|
---|
1119 | CRTextureBits *tb = &(sb->texture);
|
---|
1120 | unsigned int i;
|
---|
1121 |
|
---|
1122 | FLUSH();
|
---|
1123 |
|
---|
1124 | if (g->current.inBeginEnd)
|
---|
1125 | {
|
---|
1126 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1127 | "TexParameterfv called in Begin/End");
|
---|
1128 | return;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
|
---|
1132 | if (!tobj) {
|
---|
1133 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1134 | "TexParamterfv(invalid target=0x%x)", target);
|
---|
1135 | return;
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | switch (pname)
|
---|
1139 | {
|
---|
1140 | case GL_TEXTURE_MIN_FILTER:
|
---|
1141 | if (e != GL_NEAREST &&
|
---|
1142 | e != GL_LINEAR &&
|
---|
1143 | e != GL_NEAREST_MIPMAP_NEAREST &&
|
---|
1144 | e != GL_LINEAR_MIPMAP_NEAREST &&
|
---|
1145 | e != GL_NEAREST_MIPMAP_LINEAR &&
|
---|
1146 | e != GL_LINEAR_MIPMAP_LINEAR)
|
---|
1147 | {
|
---|
1148 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1149 | "TexParamterfv: GL_TEXTURE_MIN_FILTER invalid param: %d", e);
|
---|
1150 | return;
|
---|
1151 | }
|
---|
1152 | tobj->minFilter = e;
|
---|
1153 | break;
|
---|
1154 | case GL_TEXTURE_MAG_FILTER:
|
---|
1155 | if (e != GL_NEAREST && e != GL_LINEAR)
|
---|
1156 | {
|
---|
1157 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1158 | "TexParamterfv: GL_TEXTURE_MAG_FILTER invalid param: %d", e);
|
---|
1159 | return;
|
---|
1160 | }
|
---|
1161 | tobj->magFilter = e;
|
---|
1162 | break;
|
---|
1163 | case GL_TEXTURE_WRAP_S:
|
---|
1164 | if (e == GL_CLAMP || e == GL_REPEAT) {
|
---|
1165 | tobj->wrapS = e;
|
---|
1166 | }
|
---|
1167 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1168 | else if (e == GL_CLAMP_TO_EDGE) {
|
---|
1169 | tobj->wrapS = e;
|
---|
1170 | }
|
---|
1171 | #endif
|
---|
1172 | #ifdef GL_CLAMP_TO_EDGE_EXT
|
---|
1173 | else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
|
---|
1174 | tobj->wrapS = e;
|
---|
1175 | }
|
---|
1176 | #endif
|
---|
1177 | #ifdef CR_ARB_texture_border_clamp
|
---|
1178 | else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
|
---|
1179 | tobj->wrapS = e;
|
---|
1180 | }
|
---|
1181 | #endif
|
---|
1182 | #ifdef CR_ARB_texture_mirrored_repeat
|
---|
1183 | else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
|
---|
1184 | tobj->wrapS = e;
|
---|
1185 | }
|
---|
1186 | #endif
|
---|
1187 | #ifdef CR_ATI_texture_mirror_once
|
---|
1188 | else if ((e == GL_MIRROR_CLAMP_ATI || e == GL_MIRROR_CLAMP_TO_EDGE_ATI) && g->extensions.ATI_texture_mirror_once) {
|
---|
1189 | tobj->wrapS = e;
|
---|
1190 | }
|
---|
1191 | #endif
|
---|
1192 | else {
|
---|
1193 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1194 | "TexParameterfv: GL_TEXTURE_WRAP_S invalid param: 0x%x", e);
|
---|
1195 | return;
|
---|
1196 | }
|
---|
1197 | break;
|
---|
1198 | case GL_TEXTURE_WRAP_T:
|
---|
1199 | if (e == GL_CLAMP || e == GL_REPEAT) {
|
---|
1200 | tobj->wrapT = e;
|
---|
1201 | }
|
---|
1202 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1203 | else if (e == GL_CLAMP_TO_EDGE) {
|
---|
1204 | tobj->wrapT = e;
|
---|
1205 | }
|
---|
1206 | #endif
|
---|
1207 | #ifdef GL_CLAMP_TO_EDGE_EXT
|
---|
1208 | else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
|
---|
1209 | tobj->wrapT = e;
|
---|
1210 | }
|
---|
1211 | #endif
|
---|
1212 | #ifdef CR_ARB_texture_border_clamp
|
---|
1213 | else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
|
---|
1214 | tobj->wrapT = e;
|
---|
1215 | }
|
---|
1216 | #endif
|
---|
1217 | #ifdef CR_ARB_texture_mirrored_repeat
|
---|
1218 | else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
|
---|
1219 | tobj->wrapT = e;
|
---|
1220 | }
|
---|
1221 | #endif
|
---|
1222 | #ifdef CR_ATI_texture_mirror_once
|
---|
1223 | else if ((e == GL_MIRROR_CLAMP_ATI || e == GL_MIRROR_CLAMP_TO_EDGE_ATI) && g->extensions.ATI_texture_mirror_once) {
|
---|
1224 | tobj->wrapT = e;
|
---|
1225 | }
|
---|
1226 | #endif
|
---|
1227 | else {
|
---|
1228 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1229 | "TexParameterfv: GL_TEXTURE_WRAP_T invalid param: 0x%x", e);
|
---|
1230 | return;
|
---|
1231 | }
|
---|
1232 | break;
|
---|
1233 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1234 | case GL_TEXTURE_WRAP_R:
|
---|
1235 | if (e == GL_CLAMP || e == GL_REPEAT) {
|
---|
1236 | tobj->wrapR = e;
|
---|
1237 | }
|
---|
1238 | else if (e == GL_CLAMP_TO_EDGE) {
|
---|
1239 | tobj->wrapR = e;
|
---|
1240 | }
|
---|
1241 | #ifdef GL_CLAMP_TO_EDGE_EXT
|
---|
1242 | else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
|
---|
1243 | tobj->wrapR = e;
|
---|
1244 | }
|
---|
1245 | #endif
|
---|
1246 | #ifdef CR_ARB_texture_border_clamp
|
---|
1247 | else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
|
---|
1248 | tobj->wrapR = e;
|
---|
1249 | }
|
---|
1250 | #endif
|
---|
1251 | #ifdef CR_ARB_texture_mirrored_repeat
|
---|
1252 | else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
|
---|
1253 | tobj->wrapR = e;
|
---|
1254 | }
|
---|
1255 | #endif
|
---|
1256 | #ifdef CR_ATI_texture_mirror_once
|
---|
1257 | else if ((e == GL_MIRROR_CLAMP_ATI || e == GL_MIRROR_CLAMP_TO_EDGE_ATI) && g->extensions.ATI_texture_mirror_once) {
|
---|
1258 | tobj->wrapR = e;
|
---|
1259 | }
|
---|
1260 | #endif
|
---|
1261 | else {
|
---|
1262 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1263 | "TexParameterfv: GL_TEXTURE_WRAP_R invalid param: 0x%x", e);
|
---|
1264 | return;
|
---|
1265 | }
|
---|
1266 | break;
|
---|
1267 | case GL_TEXTURE_PRIORITY:
|
---|
1268 | tobj->priority = param[0];
|
---|
1269 | break;
|
---|
1270 | case GL_TEXTURE_MIN_LOD:
|
---|
1271 | tobj->minLod = param[0];
|
---|
1272 | break;
|
---|
1273 | case GL_TEXTURE_MAX_LOD:
|
---|
1274 | tobj->maxLod = param[0];
|
---|
1275 | break;
|
---|
1276 | case GL_TEXTURE_BASE_LEVEL:
|
---|
1277 | if (e < 0.0f)
|
---|
1278 | {
|
---|
1279 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1280 | "TexParameterfv: GL_TEXTURE_BASE_LEVEL invalid param: 0x%x", e);
|
---|
1281 | return;
|
---|
1282 | }
|
---|
1283 | tobj->baseLevel = e;
|
---|
1284 | break;
|
---|
1285 | case GL_TEXTURE_MAX_LEVEL:
|
---|
1286 | if (e < 0.0f)
|
---|
1287 | {
|
---|
1288 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1289 | "TexParameterfv: GL_TEXTURE_MAX_LEVEL invalid param: 0x%x", e);
|
---|
1290 | return;
|
---|
1291 | }
|
---|
1292 | tobj->maxLevel = e;
|
---|
1293 | break;
|
---|
1294 | #endif
|
---|
1295 | case GL_TEXTURE_BORDER_COLOR:
|
---|
1296 | tobj->borderColor.r = param[0];
|
---|
1297 | tobj->borderColor.g = param[1];
|
---|
1298 | tobj->borderColor.b = param[2];
|
---|
1299 | tobj->borderColor.a = param[3];
|
---|
1300 | break;
|
---|
1301 | #ifdef CR_EXT_texture_filter_anisotropic
|
---|
1302 | case GL_TEXTURE_MAX_ANISOTROPY_EXT:
|
---|
1303 | if (g->extensions.EXT_texture_filter_anisotropic) {
|
---|
1304 | if (param[0] < 1.0f)
|
---|
1305 | {
|
---|
1306 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
1307 | "TexParameterfv: GL_TEXTURE_MAX_ANISOTROPY_EXT called with parameter less than 1: %f", param[0]);
|
---|
1308 | return;
|
---|
1309 | }
|
---|
1310 | tobj->maxAnisotropy = param[0];
|
---|
1311 | if (tobj->maxAnisotropy > g->limits.maxTextureAnisotropy)
|
---|
1312 | {
|
---|
1313 | tobj->maxAnisotropy = g->limits.maxTextureAnisotropy;
|
---|
1314 | }
|
---|
1315 | }
|
---|
1316 | break;
|
---|
1317 | #endif
|
---|
1318 | #ifdef CR_ARB_depth_texture
|
---|
1319 | case GL_DEPTH_TEXTURE_MODE_ARB:
|
---|
1320 | if (g->extensions.ARB_depth_texture) {
|
---|
1321 | if (param[0] == GL_LUMINANCE ||
|
---|
1322 | param[0] == GL_INTENSITY ||
|
---|
1323 | param[0] == GL_ALPHA) {
|
---|
1324 | tobj->depthMode = (GLenum) param[0];
|
---|
1325 | }
|
---|
1326 | else
|
---|
1327 | {
|
---|
1328 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
1329 | "TexParameterfv: GL_DEPTH_TEXTURE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
|
---|
1330 | return;
|
---|
1331 | }
|
---|
1332 | }
|
---|
1333 | break;
|
---|
1334 | #endif
|
---|
1335 | #ifdef CR_ARB_shadow
|
---|
1336 | case GL_TEXTURE_COMPARE_MODE_ARB:
|
---|
1337 | if (g->extensions.ARB_shadow) {
|
---|
1338 | if (param[0] == GL_NONE ||
|
---|
1339 | param[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
|
---|
1340 | tobj->compareMode = (GLenum) param[0];
|
---|
1341 | }
|
---|
1342 | else
|
---|
1343 | {
|
---|
1344 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
1345 | "TexParameterfv: GL_TEXTURE_COMPARE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
|
---|
1346 | return;
|
---|
1347 | }
|
---|
1348 | }
|
---|
1349 | break;
|
---|
1350 | case GL_TEXTURE_COMPARE_FUNC_ARB:
|
---|
1351 | if (g->extensions.ARB_shadow) {
|
---|
1352 | if (param[0] == GL_LEQUAL ||
|
---|
1353 | param[0] == GL_GEQUAL) {
|
---|
1354 | tobj->compareFunc = (GLenum) param[0];
|
---|
1355 | }
|
---|
1356 | }
|
---|
1357 | #ifdef CR_EXT_shadow_funcs
|
---|
1358 | else if (g->extensions.EXT_shadow_funcs) {
|
---|
1359 | if (param[0] == GL_LEQUAL ||
|
---|
1360 | param[0] == GL_GEQUAL ||
|
---|
1361 | param[0] == GL_LESS ||
|
---|
1362 | param[0] == GL_GREATER ||
|
---|
1363 | param[0] == GL_ALWAYS ||
|
---|
1364 | param[0] == GL_NEVER ) {
|
---|
1365 | tobj->compareFunc = (GLenum) param[0];
|
---|
1366 | }
|
---|
1367 | }
|
---|
1368 | #endif
|
---|
1369 | else {
|
---|
1370 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
1371 | "TexParameterfv: GL_TEXTURE_COMPARE_FUNC_ARB called with invalid parameter: 0x%x", param[0]);
|
---|
1372 | return;
|
---|
1373 | }
|
---|
1374 | break;
|
---|
1375 | #endif
|
---|
1376 | #ifdef CR_ARB_shadow_ambient
|
---|
1377 | case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
|
---|
1378 | if (g->extensions.ARB_shadow_ambient) {
|
---|
1379 | tobj->compareFailValue = param[0];
|
---|
1380 | }
|
---|
1381 | break;
|
---|
1382 | #endif
|
---|
1383 | #ifdef CR_SGIS_generate_mipmap
|
---|
1384 | case GL_GENERATE_MIPMAP_SGIS:
|
---|
1385 | if (g->extensions.SGIS_generate_mipmap) {
|
---|
1386 | tobj->generateMipmap = param[0] ? GL_TRUE : GL_FALSE;
|
---|
1387 | }
|
---|
1388 | break;
|
---|
1389 | #endif
|
---|
1390 | default:
|
---|
1391 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1392 | "TexParamterfv: Invalid pname: %d", pname);
|
---|
1393 | return;
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | DIRTY(tobj->dirty, g->neg_bitid);
|
---|
1397 | for (i = 0; i < g->limits.maxTextureUnits; i++)
|
---|
1398 | {
|
---|
1399 | DIRTY(tobj->paramsBit[i], g->neg_bitid);
|
---|
1400 | }
|
---|
1401 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 |
|
---|
1405 | void STATE_APIENTRY
|
---|
1406 | crStateTexParameteriv(GLenum target, GLenum pname, const GLint *param)
|
---|
1407 | {
|
---|
1408 | GLfloat f_param;
|
---|
1409 | GLcolor f_color;
|
---|
1410 | switch (pname)
|
---|
1411 | {
|
---|
1412 | case GL_TEXTURE_MIN_FILTER:
|
---|
1413 | case GL_TEXTURE_MAG_FILTER:
|
---|
1414 | case GL_TEXTURE_WRAP_S:
|
---|
1415 | case GL_TEXTURE_WRAP_T:
|
---|
1416 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1417 | case GL_TEXTURE_WRAP_R:
|
---|
1418 | case GL_TEXTURE_PRIORITY:
|
---|
1419 | case GL_TEXTURE_MIN_LOD:
|
---|
1420 | case GL_TEXTURE_MAX_LOD:
|
---|
1421 | case GL_TEXTURE_BASE_LEVEL:
|
---|
1422 | case GL_TEXTURE_MAX_LEVEL:
|
---|
1423 | #endif
|
---|
1424 | #ifdef CR_EXT_texture_filter_anisotropic
|
---|
1425 | case GL_TEXTURE_MAX_ANISOTROPY_EXT:
|
---|
1426 | #endif
|
---|
1427 | #ifdef CR_ARB_depth_texture
|
---|
1428 | case GL_DEPTH_TEXTURE_MODE_ARB:
|
---|
1429 | #endif
|
---|
1430 | #ifdef CR_ARB_shadow
|
---|
1431 | case GL_TEXTURE_COMPARE_MODE_ARB:
|
---|
1432 | case GL_TEXTURE_COMPARE_FUNC_ARB:
|
---|
1433 | #endif
|
---|
1434 | #ifdef CR_ARB_shadow_ambinet
|
---|
1435 | case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
|
---|
1436 | #endif
|
---|
1437 | #ifdef CR_SGIS_generate_mipmap
|
---|
1438 | case GL_GENERATE_MIPMAP_SGIS:
|
---|
1439 | #endif
|
---|
1440 | f_param = (GLfloat) (*param);
|
---|
1441 | crStateTexParameterfv( target, pname, &(f_param) );
|
---|
1442 | break;
|
---|
1443 | case GL_TEXTURE_BORDER_COLOR:
|
---|
1444 | f_color.r = ((GLfloat) param[0])/CR_MAXINT;
|
---|
1445 | f_color.g = ((GLfloat) param[1])/CR_MAXINT;
|
---|
1446 | f_color.b = ((GLfloat) param[2])/CR_MAXINT;
|
---|
1447 | f_color.a = ((GLfloat) param[3])/CR_MAXINT;
|
---|
1448 | crStateTexParameterfv( target, pname, (const GLfloat *) &(f_color) );
|
---|
1449 | break;
|
---|
1450 | default:
|
---|
1451 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1452 | "TexParamteriv: Invalid pname: %d", pname);
|
---|
1453 | return;
|
---|
1454 | }
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 |
|
---|
1458 | void STATE_APIENTRY
|
---|
1459 | crStateTexParameterf(GLenum target, GLenum pname, GLfloat param)
|
---|
1460 | {
|
---|
1461 | crStateTexParameterfv( target, pname, ¶m );
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 |
|
---|
1465 | void STATE_APIENTRY
|
---|
1466 | crStateTexParameteri(GLenum target, GLenum pname, GLint param) {
|
---|
1467 | GLfloat f_param = (GLfloat) param;
|
---|
1468 | crStateTexParameterfv( target, pname, &f_param );
|
---|
1469 | }
|
---|
1470 |
|
---|
1471 |
|
---|
1472 | void STATE_APIENTRY
|
---|
1473 | crStateTexEnvfv(GLenum target, GLenum pname, const GLfloat *param)
|
---|
1474 | {
|
---|
1475 | CRContext *g = GetCurrentContext();
|
---|
1476 | CRTextureState *t = &(g->texture);
|
---|
1477 | CRStateBits *sb = GetCurrentBits();
|
---|
1478 | CRTextureBits *tb = &(sb->texture);
|
---|
1479 | GLenum e;
|
---|
1480 | GLcolorf c;
|
---|
1481 | GLuint stage = 0;
|
---|
1482 |
|
---|
1483 | (void) stage;
|
---|
1484 |
|
---|
1485 | FLUSH();
|
---|
1486 |
|
---|
1487 | if (g->current.inBeginEnd)
|
---|
1488 | {
|
---|
1489 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1490 | "glTexEnvfv called in begin/end");
|
---|
1491 | return;
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 | #if CR_EXT_texture_lod_bias
|
---|
1495 | if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
|
---|
1496 | if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
|
---|
1497 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
|
---|
1498 | }
|
---|
1499 | else {
|
---|
1500 | t->unit[t->curTextureUnit].lodBias = *param;
|
---|
1501 | DIRTY(tb->envBit[t->curTextureUnit], g->neg_bitid);
|
---|
1502 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
1503 | }
|
---|
1504 | return;
|
---|
1505 | }
|
---|
1506 | else
|
---|
1507 | #endif
|
---|
1508 | #if CR_ARB_point_sprite
|
---|
1509 | if (target == GL_POINT_SPRITE_ARB) {
|
---|
1510 | if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
|
---|
1511 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
|
---|
1512 | }
|
---|
1513 | else {
|
---|
1514 | CRPointBits *pb = &(sb->point);
|
---|
1515 | g->point.coordReplacement[t->curTextureUnit] = *param ? GL_TRUE : GL_FALSE;
|
---|
1516 | DIRTY(pb->coordReplacement[t->curTextureUnit], g->neg_bitid);
|
---|
1517 | DIRTY(pb->dirty, g->neg_bitid);
|
---|
1518 | }
|
---|
1519 | return;
|
---|
1520 | }
|
---|
1521 | else
|
---|
1522 | #endif
|
---|
1523 | if (target != GL_TEXTURE_ENV)
|
---|
1524 | {
|
---|
1525 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1526 | "glTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
|
---|
1527 | return;
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | switch (pname)
|
---|
1531 | {
|
---|
1532 | case GL_TEXTURE_ENV_MODE:
|
---|
1533 | e = (GLenum) *param;
|
---|
1534 | if (e != GL_MODULATE &&
|
---|
1535 | e != GL_DECAL &&
|
---|
1536 | e != GL_BLEND &&
|
---|
1537 | e != GL_ADD &&
|
---|
1538 | e != GL_REPLACE &&
|
---|
1539 | e != GL_COMBINE_ARB)
|
---|
1540 | {
|
---|
1541 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1542 | "glTexEnvfv: invalid param: %f", *param);
|
---|
1543 | return;
|
---|
1544 | }
|
---|
1545 | t->unit[t->curTextureUnit].envMode = e;
|
---|
1546 | break;
|
---|
1547 | case GL_TEXTURE_ENV_COLOR:
|
---|
1548 | c.r = param[0];
|
---|
1549 | c.g = param[1];
|
---|
1550 | c.b = param[2];
|
---|
1551 | c.a = param[3];
|
---|
1552 | if (c.r > 1.0f) c.r = 1.0f;
|
---|
1553 | if (c.g > 1.0f) c.g = 1.0f;
|
---|
1554 | if (c.b > 1.0f) c.b = 1.0f;
|
---|
1555 | if (c.a > 1.0f) c.a = 1.0f;
|
---|
1556 | if (c.r < 0.0f) c.r = 0.0f;
|
---|
1557 | if (c.g < 0.0f) c.g = 0.0f;
|
---|
1558 | if (c.b < 0.0f) c.b = 0.0f;
|
---|
1559 | if (c.a < 0.0f) c.a = 0.0f;
|
---|
1560 | t->unit[t->curTextureUnit].envColor = c;
|
---|
1561 | break;
|
---|
1562 |
|
---|
1563 | #ifdef CR_ARB_texture_env_combine
|
---|
1564 | case GL_COMBINE_RGB_ARB:
|
---|
1565 | e = (GLenum) (GLint) *param;
|
---|
1566 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1567 | (e == GL_REPLACE ||
|
---|
1568 | e == GL_MODULATE ||
|
---|
1569 | e == GL_ADD ||
|
---|
1570 | e == GL_ADD_SIGNED_ARB ||
|
---|
1571 | e == GL_INTERPOLATE_ARB ||
|
---|
1572 | e == GL_SUBTRACT_ARB)) {
|
---|
1573 | t->unit[t->curTextureUnit].combineModeRGB = e;
|
---|
1574 | }
|
---|
1575 | #ifdef CR_ARB_texture_env_dot3
|
---|
1576 | else if (g->extensions.ARB_texture_env_dot3 &&
|
---|
1577 | (e == GL_DOT3_RGB_ARB ||
|
---|
1578 | e == GL_DOT3_RGBA_ARB ||
|
---|
1579 | e == GL_DOT3_RGB_EXT ||
|
---|
1580 | e == GL_DOT3_RGBA_EXT)) {
|
---|
1581 | t->unit[t->curTextureUnit].combineModeRGB = e;
|
---|
1582 | }
|
---|
1583 | #endif
|
---|
1584 | else {
|
---|
1585 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x", e);
|
---|
1586 | return;
|
---|
1587 | }
|
---|
1588 | break;
|
---|
1589 | case GL_COMBINE_ALPHA_EXT:
|
---|
1590 | e = (GLenum) *param;
|
---|
1591 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1592 | (e == GL_REPLACE ||
|
---|
1593 | e == GL_MODULATE ||
|
---|
1594 | e == GL_ADD ||
|
---|
1595 | e == GL_ADD_SIGNED_ARB ||
|
---|
1596 | e == GL_INTERPOLATE_ARB ||
|
---|
1597 | e == GL_SUBTRACT_ARB)) {
|
---|
1598 | t->unit[t->curTextureUnit].combineModeA = e;
|
---|
1599 | }
|
---|
1600 | else {
|
---|
1601 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
|
---|
1602 | return;
|
---|
1603 | }
|
---|
1604 | break;
|
---|
1605 | case GL_SOURCE0_RGB_ARB:
|
---|
1606 | case GL_SOURCE1_RGB_ARB:
|
---|
1607 | case GL_SOURCE2_RGB_ARB:
|
---|
1608 | e = (GLenum) *param;
|
---|
1609 | stage = pname - GL_SOURCE0_RGB_ARB;
|
---|
1610 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1611 | (e == GL_TEXTURE ||
|
---|
1612 | e == GL_CONSTANT_ARB ||
|
---|
1613 | e == GL_PRIMARY_COLOR_ARB ||
|
---|
1614 | e == GL_PREVIOUS_ARB)) {
|
---|
1615 | t->unit[t->curTextureUnit].combineSourceRGB[stage] = e;
|
---|
1616 | }
|
---|
1617 | else if (g->extensions.ARB_texture_env_crossbar &&
|
---|
1618 | e >= GL_TEXTURE0_ARB &&
|
---|
1619 | e < GL_TEXTURE0_ARB + g->limits.maxTextureUnits) {
|
---|
1620 | t->unit[t->curTextureUnit].combineSourceRGB[stage] = e;
|
---|
1621 | }
|
---|
1622 | else {
|
---|
1623 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
|
---|
1624 | return;
|
---|
1625 | }
|
---|
1626 | break;
|
---|
1627 | case GL_SOURCE0_ALPHA_ARB:
|
---|
1628 | case GL_SOURCE1_ALPHA_ARB:
|
---|
1629 | case GL_SOURCE2_ALPHA_ARB:
|
---|
1630 | e = (GLenum) *param;
|
---|
1631 | stage = pname - GL_SOURCE0_ALPHA_ARB;
|
---|
1632 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1633 | (e == GL_TEXTURE ||
|
---|
1634 | e == GL_CONSTANT_ARB ||
|
---|
1635 | e == GL_PRIMARY_COLOR_ARB ||
|
---|
1636 | e == GL_PREVIOUS_ARB)) {
|
---|
1637 | t->unit[t->curTextureUnit].combineSourceA[stage] = e;
|
---|
1638 | }
|
---|
1639 | else if (g->extensions.ARB_texture_env_crossbar &&
|
---|
1640 | e >= GL_TEXTURE0_ARB &&
|
---|
1641 | e < GL_TEXTURE0_ARB + g->limits.maxTextureUnits) {
|
---|
1642 | t->unit[t->curTextureUnit].combineSourceA[stage] = e;
|
---|
1643 | }
|
---|
1644 | else {
|
---|
1645 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
|
---|
1646 | return;
|
---|
1647 | }
|
---|
1648 | break;
|
---|
1649 | case GL_OPERAND0_RGB_ARB:
|
---|
1650 | case GL_OPERAND1_RGB_ARB:
|
---|
1651 | case GL_OPERAND2_RGB_ARB:
|
---|
1652 | e = (GLenum) *param;
|
---|
1653 | stage = pname - GL_OPERAND0_RGB_ARB;
|
---|
1654 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1655 | (e == GL_SRC_COLOR ||
|
---|
1656 | e == GL_ONE_MINUS_SRC_COLOR ||
|
---|
1657 | e == GL_SRC_ALPHA ||
|
---|
1658 | e == GL_ONE_MINUS_SRC_ALPHA)) {
|
---|
1659 | t->unit[t->curTextureUnit].combineOperandRGB[stage] = e;
|
---|
1660 | }
|
---|
1661 | else {
|
---|
1662 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
|
---|
1663 | return;
|
---|
1664 | }
|
---|
1665 | break;
|
---|
1666 | case GL_OPERAND0_ALPHA_ARB:
|
---|
1667 | case GL_OPERAND1_ALPHA_ARB:
|
---|
1668 | case GL_OPERAND2_ALPHA_ARB:
|
---|
1669 | e = (GLenum) *param;
|
---|
1670 | stage = pname - GL_OPERAND0_ALPHA_ARB;
|
---|
1671 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1672 | (e == GL_SRC_ALPHA ||
|
---|
1673 | e == GL_ONE_MINUS_SRC_ALPHA)) {
|
---|
1674 | t->unit[t->curTextureUnit].combineOperandA[stage] = e;
|
---|
1675 | }
|
---|
1676 | else {
|
---|
1677 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x)", e);
|
---|
1678 | return;
|
---|
1679 | }
|
---|
1680 | break;
|
---|
1681 | case GL_RGB_SCALE_ARB:
|
---|
1682 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1683 | (*param == 1.0 ||
|
---|
1684 | *param == 2.0 ||
|
---|
1685 | *param == 4.0)) {
|
---|
1686 | t->unit[t->curTextureUnit].combineScaleRGB = *param;
|
---|
1687 | }
|
---|
1688 | else {
|
---|
1689 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
|
---|
1690 | return;
|
---|
1691 | }
|
---|
1692 | break;
|
---|
1693 | case GL_ALPHA_SCALE:
|
---|
1694 | if (g->extensions.ARB_texture_env_combine &&
|
---|
1695 | (*param == 1.0 ||
|
---|
1696 | *param == 2.0 ||
|
---|
1697 | *param == 4.0)) {
|
---|
1698 | t->unit[t->curTextureUnit].combineScaleA = *param;
|
---|
1699 | }
|
---|
1700 | else {
|
---|
1701 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
|
---|
1702 | return;
|
---|
1703 | }
|
---|
1704 | break;
|
---|
1705 | #endif /* CR_ARB_texture_env_combine */
|
---|
1706 |
|
---|
1707 | default:
|
---|
1708 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1709 | "glTexEnvfv: invalid pname: %d", pname);
|
---|
1710 | return;
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 | DIRTY(tb->envBit[t->curTextureUnit], g->neg_bitid);
|
---|
1714 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
1715 | }
|
---|
1716 |
|
---|
1717 |
|
---|
1718 | void STATE_APIENTRY
|
---|
1719 | crStateTexEnviv(GLenum target, GLenum pname, const GLint *param)
|
---|
1720 | {
|
---|
1721 | GLfloat f_param;
|
---|
1722 | GLcolor f_color;
|
---|
1723 |
|
---|
1724 | switch (pname) {
|
---|
1725 | case GL_TEXTURE_ENV_MODE:
|
---|
1726 | f_param = (GLfloat) (*param);
|
---|
1727 | crStateTexEnvfv( target, pname, &f_param );
|
---|
1728 | break;
|
---|
1729 | case GL_TEXTURE_ENV_COLOR:
|
---|
1730 | f_color.r = ((GLfloat) param[0]) / CR_MAXINT;
|
---|
1731 | f_color.g = ((GLfloat) param[1]) / CR_MAXINT;
|
---|
1732 | f_color.b = ((GLfloat) param[2]) / CR_MAXINT;
|
---|
1733 | f_color.a = ((GLfloat) param[3]) / CR_MAXINT;
|
---|
1734 | crStateTexEnvfv( target, pname, (const GLfloat *) &f_color );
|
---|
1735 | break;
|
---|
1736 | #ifdef CR_ARB_texture_env_combine
|
---|
1737 | case GL_COMBINE_RGB_ARB:
|
---|
1738 | case GL_COMBINE_ALPHA_EXT:
|
---|
1739 | case GL_SOURCE0_RGB_ARB:
|
---|
1740 | case GL_SOURCE1_RGB_ARB:
|
---|
1741 | case GL_SOURCE2_RGB_ARB:
|
---|
1742 | case GL_SOURCE0_ALPHA_ARB:
|
---|
1743 | case GL_SOURCE1_ALPHA_ARB:
|
---|
1744 | case GL_SOURCE2_ALPHA_ARB:
|
---|
1745 | case GL_OPERAND0_RGB_ARB:
|
---|
1746 | case GL_OPERAND1_RGB_ARB:
|
---|
1747 | case GL_OPERAND2_RGB_ARB:
|
---|
1748 | case GL_OPERAND0_ALPHA_ARB:
|
---|
1749 | case GL_OPERAND1_ALPHA_ARB:
|
---|
1750 | case GL_OPERAND2_ALPHA_ARB:
|
---|
1751 | case GL_RGB_SCALE_ARB:
|
---|
1752 | case GL_ALPHA_SCALE:
|
---|
1753 | f_param = (GLfloat) (*param);
|
---|
1754 | crStateTexEnvfv( target, pname, &f_param );
|
---|
1755 | break;
|
---|
1756 | #endif
|
---|
1757 | #ifdef CR_EXT_texture_lod_bias
|
---|
1758 | case GL_TEXTURE_LOD_BIAS_EXT:
|
---|
1759 | f_param = (GLfloat) (*param);
|
---|
1760 | crStateTexEnvfv( target, pname, &f_param);
|
---|
1761 | break;
|
---|
1762 | #endif
|
---|
1763 | #ifdef CR_ARB_point_sprite
|
---|
1764 | case GL_COORD_REPLACE_ARB:
|
---|
1765 | f_param = (GLfloat) *param;
|
---|
1766 | crStateTexEnvfv( target, pname, &f_param);
|
---|
1767 | break;
|
---|
1768 | #endif
|
---|
1769 |
|
---|
1770 | default:
|
---|
1771 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1772 | "glTexEnvfv: invalid pname: %d", pname);
|
---|
1773 | return;
|
---|
1774 | }
|
---|
1775 | }
|
---|
1776 |
|
---|
1777 |
|
---|
1778 | void STATE_APIENTRY
|
---|
1779 | crStateTexEnvf(GLenum target, GLenum pname, GLfloat param)
|
---|
1780 | {
|
---|
1781 | crStateTexEnvfv( target, pname, ¶m );
|
---|
1782 | }
|
---|
1783 |
|
---|
1784 |
|
---|
1785 | void STATE_APIENTRY
|
---|
1786 | crStateTexEnvi(GLenum target, GLenum pname, GLint param)
|
---|
1787 | {
|
---|
1788 | GLfloat f_param = (GLfloat) param;
|
---|
1789 | crStateTexEnvfv( target, pname, &f_param );
|
---|
1790 | }
|
---|
1791 |
|
---|
1792 |
|
---|
1793 | void STATE_APIENTRY
|
---|
1794 | crStateGetTexEnvfv(GLenum target, GLenum pname, GLfloat *param)
|
---|
1795 | {
|
---|
1796 | CRContext *g = GetCurrentContext();
|
---|
1797 | CRTextureState *t = &(g->texture);
|
---|
1798 |
|
---|
1799 | if (g->current.inBeginEnd)
|
---|
1800 | {
|
---|
1801 | crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
|
---|
1802 | "glGetTexEnvfv called in begin/end");
|
---|
1803 | return;
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | #if CR_EXT_texture_lod_bias
|
---|
1807 | if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
|
---|
1808 | if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
|
---|
1809 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
|
---|
1810 | }
|
---|
1811 | else {
|
---|
1812 | *param = t->unit[t->curTextureUnit].lodBias;
|
---|
1813 | }
|
---|
1814 | return;
|
---|
1815 | }
|
---|
1816 | else
|
---|
1817 | #endif
|
---|
1818 | #if CR_ARB_point_sprite
|
---|
1819 | if (target == GL_POINT_SPRITE_ARB) {
|
---|
1820 | if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
|
---|
1821 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
|
---|
1822 | }
|
---|
1823 | else {
|
---|
1824 | *param = (GLfloat) g->point.coordReplacement[t->curTextureUnit];
|
---|
1825 | }
|
---|
1826 | return;
|
---|
1827 | }
|
---|
1828 | else
|
---|
1829 | #endif
|
---|
1830 | if (target != GL_TEXTURE_ENV)
|
---|
1831 | {
|
---|
1832 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1833 | "glGetTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
|
---|
1834 | return;
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 | switch (pname) {
|
---|
1838 | case GL_TEXTURE_ENV_MODE:
|
---|
1839 | *param = (GLfloat) t->unit[t->curTextureUnit].envMode;
|
---|
1840 | break;
|
---|
1841 | case GL_TEXTURE_ENV_COLOR:
|
---|
1842 | param[0] = t->unit[t->curTextureUnit].envColor.r;
|
---|
1843 | param[1] = t->unit[t->curTextureUnit].envColor.g;
|
---|
1844 | param[2] = t->unit[t->curTextureUnit].envColor.b;
|
---|
1845 | param[3] = t->unit[t->curTextureUnit].envColor.a;
|
---|
1846 | break;
|
---|
1847 | case GL_COMBINE_RGB_ARB:
|
---|
1848 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1849 | *param = (GLfloat) t->unit[t->curTextureUnit].combineModeRGB;
|
---|
1850 | }
|
---|
1851 | else {
|
---|
1852 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1853 | return;
|
---|
1854 | }
|
---|
1855 | break;
|
---|
1856 | case GL_COMBINE_ALPHA_ARB:
|
---|
1857 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1858 | *param = (GLfloat) t->unit[t->curTextureUnit].combineModeA;
|
---|
1859 | }
|
---|
1860 | else {
|
---|
1861 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1862 | return;
|
---|
1863 | }
|
---|
1864 | break;
|
---|
1865 | case GL_SOURCE0_RGB_ARB:
|
---|
1866 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1867 | *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[0];
|
---|
1868 | }
|
---|
1869 | else {
|
---|
1870 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1871 | return;
|
---|
1872 | }
|
---|
1873 | break;
|
---|
1874 | case GL_SOURCE1_RGB_ARB:
|
---|
1875 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1876 | *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[1];
|
---|
1877 | }
|
---|
1878 | else {
|
---|
1879 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1880 | return;
|
---|
1881 | }
|
---|
1882 | break;
|
---|
1883 | case GL_SOURCE2_RGB_ARB:
|
---|
1884 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1885 | *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[2];
|
---|
1886 | }
|
---|
1887 | else {
|
---|
1888 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1889 | return;
|
---|
1890 | }
|
---|
1891 | break;
|
---|
1892 | case GL_SOURCE0_ALPHA_ARB:
|
---|
1893 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1894 | *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[0];
|
---|
1895 | }
|
---|
1896 | else {
|
---|
1897 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1898 | return;
|
---|
1899 | }
|
---|
1900 | break;
|
---|
1901 | case GL_SOURCE1_ALPHA_ARB:
|
---|
1902 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1903 | *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[1];
|
---|
1904 | }
|
---|
1905 | else {
|
---|
1906 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1907 | return;
|
---|
1908 | }
|
---|
1909 | break;
|
---|
1910 | case GL_SOURCE2_ALPHA_ARB:
|
---|
1911 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1912 | *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[2];
|
---|
1913 | }
|
---|
1914 | else {
|
---|
1915 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1916 | return;
|
---|
1917 | }
|
---|
1918 | break;
|
---|
1919 | case GL_OPERAND0_RGB_ARB:
|
---|
1920 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1921 | *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[0];
|
---|
1922 | }
|
---|
1923 | else {
|
---|
1924 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1925 | return;
|
---|
1926 | }
|
---|
1927 | break;
|
---|
1928 | case GL_OPERAND1_RGB_ARB:
|
---|
1929 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1930 | *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[1];
|
---|
1931 | }
|
---|
1932 | else {
|
---|
1933 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1934 | return;
|
---|
1935 | }
|
---|
1936 | break;
|
---|
1937 | case GL_OPERAND2_RGB_ARB:
|
---|
1938 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1939 | *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[2];
|
---|
1940 | }
|
---|
1941 | else {
|
---|
1942 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1943 | return;
|
---|
1944 | }
|
---|
1945 | break;
|
---|
1946 | case GL_OPERAND0_ALPHA_ARB:
|
---|
1947 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1948 | *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[0];
|
---|
1949 | }
|
---|
1950 | else {
|
---|
1951 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1952 | return;
|
---|
1953 | }
|
---|
1954 | break;
|
---|
1955 | case GL_OPERAND1_ALPHA_ARB:
|
---|
1956 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1957 | *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[1];
|
---|
1958 | }
|
---|
1959 | else {
|
---|
1960 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1961 | return;
|
---|
1962 | }
|
---|
1963 | break;
|
---|
1964 | case GL_OPERAND2_ALPHA_ARB:
|
---|
1965 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1966 | *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[2];
|
---|
1967 | }
|
---|
1968 | else {
|
---|
1969 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1970 | return;
|
---|
1971 | }
|
---|
1972 | break;
|
---|
1973 | case GL_RGB_SCALE_ARB:
|
---|
1974 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1975 | *param = t->unit[t->curTextureUnit].combineScaleRGB;
|
---|
1976 | }
|
---|
1977 | else {
|
---|
1978 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1979 | return;
|
---|
1980 | }
|
---|
1981 | break;
|
---|
1982 | case GL_ALPHA_SCALE:
|
---|
1983 | if (g->extensions.ARB_texture_env_combine) {
|
---|
1984 | *param = t->unit[t->curTextureUnit].combineScaleA;
|
---|
1985 | }
|
---|
1986 | else {
|
---|
1987 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
|
---|
1988 | return;
|
---|
1989 | }
|
---|
1990 | break;
|
---|
1991 | default:
|
---|
1992 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1993 | "glGetTexEnvfv: invalid pname: %d", pname);
|
---|
1994 | return;
|
---|
1995 | }
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 |
|
---|
1999 | void STATE_APIENTRY
|
---|
2000 | crStateGetTexEnviv(GLenum target, GLenum pname, GLint *param)
|
---|
2001 | {
|
---|
2002 | CRContext *g = GetCurrentContext();
|
---|
2003 | CRTextureState *t = &(g->texture);
|
---|
2004 |
|
---|
2005 | if (g->current.inBeginEnd)
|
---|
2006 | {
|
---|
2007 | crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
|
---|
2008 | "glGetTexEnviv called in begin/end");
|
---|
2009 | return;
|
---|
2010 | }
|
---|
2011 |
|
---|
2012 | #if CR_EXT_texture_lod_bias
|
---|
2013 | if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
|
---|
2014 | if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
|
---|
2015 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
|
---|
2016 | }
|
---|
2017 | else {
|
---|
2018 | *param = (GLint) t->unit[t->curTextureUnit].lodBias;
|
---|
2019 | }
|
---|
2020 | return;
|
---|
2021 | }
|
---|
2022 | else
|
---|
2023 | #endif
|
---|
2024 | #if CR_ARB_point_sprite
|
---|
2025 | if (target == GL_POINT_SPRITE_ARB) {
|
---|
2026 | if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
|
---|
2027 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
|
---|
2028 | }
|
---|
2029 | else {
|
---|
2030 | *param = (GLint) g->point.coordReplacement[t->curTextureUnit];
|
---|
2031 | }
|
---|
2032 | return;
|
---|
2033 | }
|
---|
2034 | else
|
---|
2035 | #endif
|
---|
2036 | if (target != GL_TEXTURE_ENV)
|
---|
2037 | {
|
---|
2038 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2039 | "glGetTexEnviv: target != GL_TEXTURE_ENV: %d", target);
|
---|
2040 | return;
|
---|
2041 | }
|
---|
2042 |
|
---|
2043 | switch (pname) {
|
---|
2044 | case GL_TEXTURE_ENV_MODE:
|
---|
2045 | *param = (GLint) t->unit[t->curTextureUnit].envMode;
|
---|
2046 | break;
|
---|
2047 | case GL_TEXTURE_ENV_COLOR:
|
---|
2048 | param[0] = (GLint) (t->unit[t->curTextureUnit].envColor.r * CR_MAXINT);
|
---|
2049 | param[1] = (GLint) (t->unit[t->curTextureUnit].envColor.g * CR_MAXINT);
|
---|
2050 | param[2] = (GLint) (t->unit[t->curTextureUnit].envColor.b * CR_MAXINT);
|
---|
2051 | param[3] = (GLint) (t->unit[t->curTextureUnit].envColor.a * CR_MAXINT);
|
---|
2052 | break;
|
---|
2053 | case GL_COMBINE_RGB_ARB:
|
---|
2054 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2055 | *param = (GLint) t->unit[t->curTextureUnit].combineModeRGB;
|
---|
2056 | }
|
---|
2057 | else {
|
---|
2058 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2059 | return;
|
---|
2060 | }
|
---|
2061 | break;
|
---|
2062 | case GL_COMBINE_ALPHA_ARB:
|
---|
2063 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2064 | *param = (GLint) t->unit[t->curTextureUnit].combineModeA;
|
---|
2065 | }
|
---|
2066 | else {
|
---|
2067 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2068 | return;
|
---|
2069 | }
|
---|
2070 | break;
|
---|
2071 | case GL_SOURCE0_RGB_ARB:
|
---|
2072 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2073 | *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[0];
|
---|
2074 | }
|
---|
2075 | else {
|
---|
2076 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2077 | return;
|
---|
2078 | }
|
---|
2079 | break;
|
---|
2080 | case GL_SOURCE1_RGB_ARB:
|
---|
2081 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2082 | *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[1];
|
---|
2083 | }
|
---|
2084 | else {
|
---|
2085 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2086 | return;
|
---|
2087 | }
|
---|
2088 | break;
|
---|
2089 | case GL_SOURCE2_RGB_ARB:
|
---|
2090 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2091 | *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[2];
|
---|
2092 | }
|
---|
2093 | else {
|
---|
2094 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2095 | return;
|
---|
2096 | }
|
---|
2097 | break;
|
---|
2098 | case GL_SOURCE0_ALPHA_ARB:
|
---|
2099 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2100 | *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[0];
|
---|
2101 | }
|
---|
2102 | else {
|
---|
2103 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2104 | return;
|
---|
2105 | }
|
---|
2106 | break;
|
---|
2107 | case GL_SOURCE1_ALPHA_ARB:
|
---|
2108 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2109 | *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[1];
|
---|
2110 | }
|
---|
2111 | else {
|
---|
2112 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2113 | return;
|
---|
2114 | }
|
---|
2115 | break;
|
---|
2116 | case GL_SOURCE2_ALPHA_ARB:
|
---|
2117 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2118 | *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[2];
|
---|
2119 | }
|
---|
2120 | else {
|
---|
2121 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2122 | return;
|
---|
2123 | }
|
---|
2124 | break;
|
---|
2125 | case GL_OPERAND0_RGB_ARB:
|
---|
2126 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2127 | *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[0];
|
---|
2128 | }
|
---|
2129 | else {
|
---|
2130 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2131 | return;
|
---|
2132 | }
|
---|
2133 | break;
|
---|
2134 | case GL_OPERAND1_RGB_ARB:
|
---|
2135 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2136 | *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[1];
|
---|
2137 | }
|
---|
2138 | else {
|
---|
2139 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2140 | return;
|
---|
2141 | }
|
---|
2142 | break;
|
---|
2143 | case GL_OPERAND2_RGB_ARB:
|
---|
2144 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2145 | *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[2];
|
---|
2146 | }
|
---|
2147 | else {
|
---|
2148 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2149 | return;
|
---|
2150 | }
|
---|
2151 | break;
|
---|
2152 | case GL_OPERAND0_ALPHA_ARB:
|
---|
2153 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2154 | *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[0];
|
---|
2155 | }
|
---|
2156 | else {
|
---|
2157 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2158 | return;
|
---|
2159 | }
|
---|
2160 | break;
|
---|
2161 | case GL_OPERAND1_ALPHA_ARB:
|
---|
2162 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2163 | *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[1];
|
---|
2164 | }
|
---|
2165 | else {
|
---|
2166 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2167 | return;
|
---|
2168 | }
|
---|
2169 | break;
|
---|
2170 | case GL_OPERAND2_ALPHA_ARB:
|
---|
2171 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2172 | *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[2];
|
---|
2173 | }
|
---|
2174 | else {
|
---|
2175 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2176 | return;
|
---|
2177 | }
|
---|
2178 | break;
|
---|
2179 | case GL_RGB_SCALE_ARB:
|
---|
2180 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2181 | *param = (GLint) t->unit[t->curTextureUnit].combineScaleRGB;
|
---|
2182 | }
|
---|
2183 | else {
|
---|
2184 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2185 | return;
|
---|
2186 | }
|
---|
2187 | break;
|
---|
2188 | case GL_ALPHA_SCALE:
|
---|
2189 | if (g->extensions.ARB_texture_env_combine) {
|
---|
2190 | *param = (GLint) t->unit[t->curTextureUnit].combineScaleA;
|
---|
2191 | }
|
---|
2192 | else {
|
---|
2193 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
|
---|
2194 | return;
|
---|
2195 | }
|
---|
2196 | break;
|
---|
2197 | default:
|
---|
2198 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2199 | "glGetTexEnviv: invalid pname: %d", pname);
|
---|
2200 | return;
|
---|
2201 | }
|
---|
2202 | }
|
---|
2203 |
|
---|
2204 |
|
---|
2205 | void STATE_APIENTRY
|
---|
2206 | crStateTexGendv(GLenum coord, GLenum pname, const GLdouble *param)
|
---|
2207 | {
|
---|
2208 | CRContext *g = GetCurrentContext();
|
---|
2209 | CRTextureState *t = &(g->texture);
|
---|
2210 | CRTransformState *trans = &(g->transform);
|
---|
2211 | GLvectorf v;
|
---|
2212 | GLenum e;
|
---|
2213 | CRmatrix inv;
|
---|
2214 | CRStateBits *sb = GetCurrentBits();
|
---|
2215 | CRTextureBits *tb = &(sb->texture);
|
---|
2216 |
|
---|
2217 | FLUSH();
|
---|
2218 |
|
---|
2219 | if (g->current.inBeginEnd)
|
---|
2220 | {
|
---|
2221 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
2222 | "glTexGen called in begin/end");
|
---|
2223 | return;
|
---|
2224 | }
|
---|
2225 |
|
---|
2226 | switch (coord)
|
---|
2227 | {
|
---|
2228 | case GL_S:
|
---|
2229 | switch (pname)
|
---|
2230 | {
|
---|
2231 | case GL_TEXTURE_GEN_MODE:
|
---|
2232 | e = (GLenum) *param;
|
---|
2233 | if (e == GL_OBJECT_LINEAR ||
|
---|
2234 | e == GL_EYE_LINEAR ||
|
---|
2235 | e == GL_SPHERE_MAP
|
---|
2236 | #if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
|
---|
2237 | || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
|
---|
2238 | && g->extensions.ARB_texture_cube_map)
|
---|
2239 | #endif
|
---|
2240 | ) {
|
---|
2241 | t->unit[t->curTextureUnit].gen.s = e;
|
---|
2242 | DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
|
---|
2243 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2244 | }
|
---|
2245 | else {
|
---|
2246 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2247 | "glTexGendv called with bad param: %lf", *param);
|
---|
2248 | return;
|
---|
2249 | }
|
---|
2250 | break;
|
---|
2251 | case GL_OBJECT_PLANE:
|
---|
2252 | v.x = (GLfloat) param[0];
|
---|
2253 | v.y = (GLfloat) param[1];
|
---|
2254 | v.z = (GLfloat) param[2];
|
---|
2255 | v.w = (GLfloat) param[3];
|
---|
2256 | t->unit[t->curTextureUnit].objSCoeff = v;
|
---|
2257 | DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
|
---|
2258 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2259 | break;
|
---|
2260 | case GL_EYE_PLANE:
|
---|
2261 | v.x = (GLfloat) param[0];
|
---|
2262 | v.y = (GLfloat) param[1];
|
---|
2263 | v.z = (GLfloat) param[2];
|
---|
2264 | v.w = (GLfloat) param[3];
|
---|
2265 | crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
|
---|
2266 | crStateTransformXformPointMatrixf(&inv, &v);
|
---|
2267 | t->unit[t->curTextureUnit].eyeSCoeff = v;
|
---|
2268 | DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
|
---|
2269 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2270 | break;
|
---|
2271 | default:
|
---|
2272 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2273 | "glTexGendv called with bogus pname: %d", pname);
|
---|
2274 | return;
|
---|
2275 | }
|
---|
2276 | break;
|
---|
2277 | case GL_T:
|
---|
2278 | switch (pname) {
|
---|
2279 | case GL_TEXTURE_GEN_MODE:
|
---|
2280 | e = (GLenum) *param;
|
---|
2281 | if (e == GL_OBJECT_LINEAR ||
|
---|
2282 | e == GL_EYE_LINEAR ||
|
---|
2283 | e == GL_SPHERE_MAP
|
---|
2284 | #if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
|
---|
2285 | || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
|
---|
2286 | && g->extensions.ARB_texture_cube_map)
|
---|
2287 | #endif
|
---|
2288 | ) {
|
---|
2289 | t->unit[t->curTextureUnit].gen.t = e;
|
---|
2290 | DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
|
---|
2291 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2292 | }
|
---|
2293 | else {
|
---|
2294 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2295 | "glTexGendv called with bad param: %lf", *param);
|
---|
2296 | return;
|
---|
2297 | }
|
---|
2298 | break;
|
---|
2299 | case GL_OBJECT_PLANE:
|
---|
2300 | v.x = (GLfloat) param[0];
|
---|
2301 | v.y = (GLfloat) param[1];
|
---|
2302 | v.z = (GLfloat) param[2];
|
---|
2303 | v.w = (GLfloat) param[3];
|
---|
2304 | t->unit[t->curTextureUnit].objTCoeff = v;
|
---|
2305 | DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
|
---|
2306 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2307 | break;
|
---|
2308 | case GL_EYE_PLANE:
|
---|
2309 | v.x = (GLfloat) param[0];
|
---|
2310 | v.y = (GLfloat) param[1];
|
---|
2311 | v.z = (GLfloat) param[2];
|
---|
2312 | v.w = (GLfloat) param[3];
|
---|
2313 | crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
|
---|
2314 | crStateTransformXformPointMatrixf(&inv, &v);
|
---|
2315 | t->unit[t->curTextureUnit].eyeTCoeff = v;
|
---|
2316 | DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
|
---|
2317 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2318 | break;
|
---|
2319 | default:
|
---|
2320 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2321 | "glTexGen called with bogus pname: %d", pname);
|
---|
2322 | return;
|
---|
2323 | }
|
---|
2324 | break;
|
---|
2325 | case GL_R:
|
---|
2326 | switch (pname) {
|
---|
2327 | case GL_TEXTURE_GEN_MODE:
|
---|
2328 | e = (GLenum) *param;
|
---|
2329 | if (e == GL_OBJECT_LINEAR ||
|
---|
2330 | e == GL_EYE_LINEAR ||
|
---|
2331 | e == GL_SPHERE_MAP
|
---|
2332 | #if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
|
---|
2333 | || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
|
---|
2334 | && g->extensions.ARB_texture_cube_map)
|
---|
2335 | #endif
|
---|
2336 | ) {
|
---|
2337 | t->unit[t->curTextureUnit].gen.r = e;
|
---|
2338 | DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
|
---|
2339 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2340 | }
|
---|
2341 | else {
|
---|
2342 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2343 | "glTexGen called with bad param: %lf", *param);
|
---|
2344 | return;
|
---|
2345 | }
|
---|
2346 | break;
|
---|
2347 | case GL_OBJECT_PLANE:
|
---|
2348 | v.x = (GLfloat) param[0];
|
---|
2349 | v.y = (GLfloat) param[1];
|
---|
2350 | v.z = (GLfloat) param[2];
|
---|
2351 | v.w = (GLfloat) param[3];
|
---|
2352 | t->unit[t->curTextureUnit].objRCoeff = v;
|
---|
2353 | DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
|
---|
2354 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2355 | break;
|
---|
2356 | case GL_EYE_PLANE:
|
---|
2357 | v.x = (GLfloat) param[0];
|
---|
2358 | v.y = (GLfloat) param[1];
|
---|
2359 | v.z = (GLfloat) param[2];
|
---|
2360 | v.w = (GLfloat) param[3];
|
---|
2361 | crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
|
---|
2362 | crStateTransformXformPointMatrixf(&inv, &v);
|
---|
2363 | t->unit[t->curTextureUnit].eyeRCoeff = v;
|
---|
2364 | DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
|
---|
2365 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2366 | break;
|
---|
2367 | default:
|
---|
2368 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2369 | "glTexGen called with bogus pname: %d", pname);
|
---|
2370 | return;
|
---|
2371 | }
|
---|
2372 | break;
|
---|
2373 | case GL_Q:
|
---|
2374 | switch (pname) {
|
---|
2375 | case GL_TEXTURE_GEN_MODE:
|
---|
2376 | e = (GLenum) *param;
|
---|
2377 | if (e == GL_OBJECT_LINEAR ||
|
---|
2378 | e == GL_EYE_LINEAR ||
|
---|
2379 | e == GL_SPHERE_MAP
|
---|
2380 | #if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
|
---|
2381 | || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
|
---|
2382 | && g->extensions.ARB_texture_cube_map)
|
---|
2383 | #endif
|
---|
2384 | ) {
|
---|
2385 | t->unit[t->curTextureUnit].gen.q = e;
|
---|
2386 | DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
|
---|
2387 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2388 | }
|
---|
2389 | else {
|
---|
2390 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2391 | "glTexGen called with bad param: %lf", *param);
|
---|
2392 | return;
|
---|
2393 | }
|
---|
2394 | break;
|
---|
2395 | case GL_OBJECT_PLANE:
|
---|
2396 | v.x = (GLfloat) param[0];
|
---|
2397 | v.y = (GLfloat) param[1];
|
---|
2398 | v.z = (GLfloat) param[2];
|
---|
2399 | v.w = (GLfloat) param[3];
|
---|
2400 | t->unit[t->curTextureUnit].objQCoeff = v;
|
---|
2401 | DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
|
---|
2402 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2403 | break;
|
---|
2404 | case GL_EYE_PLANE:
|
---|
2405 | v.x = (GLfloat) param[0];
|
---|
2406 | v.y = (GLfloat) param[1];
|
---|
2407 | v.z = (GLfloat) param[2];
|
---|
2408 | v.w = (GLfloat) param[3];
|
---|
2409 | crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
|
---|
2410 | crStateTransformXformPointMatrixf(&inv, &v);
|
---|
2411 | t->unit[t->curTextureUnit].eyeQCoeff = v;
|
---|
2412 | DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
|
---|
2413 | DIRTY(tb->dirty, g->neg_bitid);
|
---|
2414 | break;
|
---|
2415 | default:
|
---|
2416 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2417 | "glTexGen called with bogus pname: %d", pname);
|
---|
2418 | return;
|
---|
2419 | }
|
---|
2420 | break;
|
---|
2421 | default:
|
---|
2422 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2423 | "glTexGen called with bogus coord: %d", coord);
|
---|
2424 | return;
|
---|
2425 | }
|
---|
2426 | }
|
---|
2427 |
|
---|
2428 |
|
---|
2429 | void STATE_APIENTRY
|
---|
2430 | crStateTexGenfv(GLenum coord, GLenum pname, const GLfloat *param)
|
---|
2431 | {
|
---|
2432 | GLdouble d_param;
|
---|
2433 | GLvectord d_vector;
|
---|
2434 | switch (pname)
|
---|
2435 | {
|
---|
2436 | case GL_TEXTURE_GEN_MODE:
|
---|
2437 | d_param = (GLdouble) *param;
|
---|
2438 | crStateTexGendv( coord, pname, &d_param );
|
---|
2439 | break;
|
---|
2440 | case GL_OBJECT_PLANE:
|
---|
2441 | case GL_EYE_PLANE:
|
---|
2442 | d_vector.x = (GLdouble) param[0];
|
---|
2443 | d_vector.y = (GLdouble) param[1];
|
---|
2444 | d_vector.z = (GLdouble) param[2];
|
---|
2445 | d_vector.w = (GLdouble) param[3];
|
---|
2446 | crStateTexGendv( coord, pname, (const double *) &d_vector );
|
---|
2447 | break;
|
---|
2448 | default:
|
---|
2449 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2450 | "glTexGen called with bogus pname: %d", pname);
|
---|
2451 | return;
|
---|
2452 | }
|
---|
2453 | }
|
---|
2454 |
|
---|
2455 |
|
---|
2456 | void STATE_APIENTRY
|
---|
2457 | crStateTexGeniv(GLenum coord, GLenum pname, const GLint *param)
|
---|
2458 | {
|
---|
2459 | GLdouble d_param;
|
---|
2460 | GLvectord d_vector;
|
---|
2461 | switch (pname)
|
---|
2462 | {
|
---|
2463 | case GL_TEXTURE_GEN_MODE:
|
---|
2464 | d_param = (GLdouble) *param;
|
---|
2465 | crStateTexGendv( coord, pname, &d_param );
|
---|
2466 | break;
|
---|
2467 | case GL_OBJECT_PLANE:
|
---|
2468 | case GL_EYE_PLANE:
|
---|
2469 | d_vector.x = (GLdouble) param[0];
|
---|
2470 | d_vector.y = (GLdouble) param[1];
|
---|
2471 | d_vector.z = (GLdouble) param[2];
|
---|
2472 | d_vector.w = (GLdouble) param[3];
|
---|
2473 | crStateTexGendv( coord, pname, (const double *) &d_vector );
|
---|
2474 | break;
|
---|
2475 | default:
|
---|
2476 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2477 | "glTexGen called with bogus pname: %d", pname);
|
---|
2478 | return;
|
---|
2479 | }
|
---|
2480 | }
|
---|
2481 |
|
---|
2482 |
|
---|
2483 | void STATE_APIENTRY
|
---|
2484 | crStateTexGend (GLenum coord, GLenum pname, GLdouble param)
|
---|
2485 | {
|
---|
2486 | crStateTexGendv( coord, pname, ¶m );
|
---|
2487 | }
|
---|
2488 |
|
---|
2489 |
|
---|
2490 | void STATE_APIENTRY
|
---|
2491 | crStateTexGenf(GLenum coord, GLenum pname, GLfloat param)
|
---|
2492 | {
|
---|
2493 | GLdouble d_param = (GLdouble) param;
|
---|
2494 | crStateTexGendv( coord, pname, &d_param );
|
---|
2495 | }
|
---|
2496 |
|
---|
2497 |
|
---|
2498 | void STATE_APIENTRY
|
---|
2499 | crStateTexGeni(GLenum coord, GLenum pname, GLint param)
|
---|
2500 | {
|
---|
2501 | GLdouble d_param = (GLdouble) param;
|
---|
2502 | crStateTexGendv( coord, pname, &d_param );
|
---|
2503 | }
|
---|
2504 |
|
---|
2505 |
|
---|
2506 | void STATE_APIENTRY
|
---|
2507 | crStateGetTexGendv(GLenum coord, GLenum pname, GLdouble *param)
|
---|
2508 | {
|
---|
2509 | CRContext *g = GetCurrentContext();
|
---|
2510 | CRTextureState *t = &(g->texture);
|
---|
2511 |
|
---|
2512 | if (g->current.inBeginEnd)
|
---|
2513 | {
|
---|
2514 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
2515 | "glGetTexGen called in begin/end");
|
---|
2516 | return;
|
---|
2517 | }
|
---|
2518 |
|
---|
2519 | switch (pname) {
|
---|
2520 | case GL_TEXTURE_GEN_MODE:
|
---|
2521 | switch (coord) {
|
---|
2522 | case GL_S:
|
---|
2523 | *param = (GLdouble) t->unit[t->curTextureUnit].gen.s;
|
---|
2524 | break;
|
---|
2525 | case GL_T:
|
---|
2526 | *param = (GLdouble) t->unit[t->curTextureUnit].gen.t;
|
---|
2527 | break;
|
---|
2528 | case GL_R:
|
---|
2529 | *param = (GLdouble) t->unit[t->curTextureUnit].gen.r;
|
---|
2530 | break;
|
---|
2531 | case GL_Q:
|
---|
2532 | *param = (GLdouble) t->unit[t->curTextureUnit].gen.q;
|
---|
2533 | break;
|
---|
2534 | default:
|
---|
2535 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2536 | "glGetTexGen called with bogus coord: %d", coord);
|
---|
2537 | return;
|
---|
2538 | }
|
---|
2539 | break;
|
---|
2540 | case GL_OBJECT_PLANE:
|
---|
2541 | switch (coord) {
|
---|
2542 | case GL_S:
|
---|
2543 | param[0] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.x;
|
---|
2544 | param[1] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.y;
|
---|
2545 | param[2] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.z;
|
---|
2546 | param[3] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.w;
|
---|
2547 | break;
|
---|
2548 | case GL_T:
|
---|
2549 | param[0] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.x;
|
---|
2550 | param[1] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.y;
|
---|
2551 | param[2] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.z;
|
---|
2552 | param[3] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.w;
|
---|
2553 | break;
|
---|
2554 | case GL_R:
|
---|
2555 | param[0] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.x;
|
---|
2556 | param[1] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.y;
|
---|
2557 | param[2] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.z;
|
---|
2558 | param[3] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.w;
|
---|
2559 | break;
|
---|
2560 | case GL_Q:
|
---|
2561 | param[0] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.x;
|
---|
2562 | param[1] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.y;
|
---|
2563 | param[2] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.z;
|
---|
2564 | param[3] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.w;
|
---|
2565 | break;
|
---|
2566 | default:
|
---|
2567 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2568 | "glGetTexGen called with bogus coord: %d", coord);
|
---|
2569 | return;
|
---|
2570 | }
|
---|
2571 | break;
|
---|
2572 | case GL_EYE_PLANE:
|
---|
2573 | switch (coord) {
|
---|
2574 | case GL_S:
|
---|
2575 | param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.x;
|
---|
2576 | param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.y;
|
---|
2577 | param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.z;
|
---|
2578 | param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.w;
|
---|
2579 | break;
|
---|
2580 | case GL_T:
|
---|
2581 | param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.x;
|
---|
2582 | param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.y;
|
---|
2583 | param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.z;
|
---|
2584 | param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.w;
|
---|
2585 | break;
|
---|
2586 | case GL_R:
|
---|
2587 | param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.x;
|
---|
2588 | param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.y;
|
---|
2589 | param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.z;
|
---|
2590 | param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.w;
|
---|
2591 | break;
|
---|
2592 | case GL_Q:
|
---|
2593 | param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.x;
|
---|
2594 | param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.y;
|
---|
2595 | param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.z;
|
---|
2596 | param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.w;
|
---|
2597 | break;
|
---|
2598 | default:
|
---|
2599 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2600 | "glGetTexGen called with bogus coord: %d", coord);
|
---|
2601 | return;
|
---|
2602 | }
|
---|
2603 | break;
|
---|
2604 | default:
|
---|
2605 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2606 | "glGetTexGen called with bogus pname: %d", pname);
|
---|
2607 | return;
|
---|
2608 | }
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 |
|
---|
2612 | void STATE_APIENTRY
|
---|
2613 | crStateGetTexGenfv(GLenum coord, GLenum pname, GLfloat *param)
|
---|
2614 | {
|
---|
2615 | CRContext *g = GetCurrentContext();
|
---|
2616 | CRTextureState *t = &(g->texture);
|
---|
2617 |
|
---|
2618 | if (g->current.inBeginEnd)
|
---|
2619 | {
|
---|
2620 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
2621 | "glGetTexGenfv called in begin/end");
|
---|
2622 | return;
|
---|
2623 | }
|
---|
2624 |
|
---|
2625 | switch (pname) {
|
---|
2626 | case GL_TEXTURE_GEN_MODE:
|
---|
2627 | switch (coord) {
|
---|
2628 | case GL_S:
|
---|
2629 | *param = (GLfloat) t->unit[t->curTextureUnit].gen.s;
|
---|
2630 | break;
|
---|
2631 | case GL_T:
|
---|
2632 | *param = (GLfloat) t->unit[t->curTextureUnit].gen.t;
|
---|
2633 | break;
|
---|
2634 | case GL_R:
|
---|
2635 | *param = (GLfloat) t->unit[t->curTextureUnit].gen.r;
|
---|
2636 | break;
|
---|
2637 | case GL_Q:
|
---|
2638 | *param = (GLfloat) t->unit[t->curTextureUnit].gen.q;
|
---|
2639 | break;
|
---|
2640 | default:
|
---|
2641 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2642 | "glGetTexGenfv called with bogus coord: %d", coord);
|
---|
2643 | return;
|
---|
2644 | }
|
---|
2645 | break;
|
---|
2646 | case GL_OBJECT_PLANE:
|
---|
2647 | switch (coord) {
|
---|
2648 | case GL_S:
|
---|
2649 | param[0] = t->unit[t->curTextureUnit].objSCoeff.x;
|
---|
2650 | param[1] = t->unit[t->curTextureUnit].objSCoeff.y;
|
---|
2651 | param[2] = t->unit[t->curTextureUnit].objSCoeff.z;
|
---|
2652 | param[3] = t->unit[t->curTextureUnit].objSCoeff.w;
|
---|
2653 | break;
|
---|
2654 | case GL_T:
|
---|
2655 | param[0] = t->unit[t->curTextureUnit].objTCoeff.x;
|
---|
2656 | param[1] = t->unit[t->curTextureUnit].objTCoeff.y;
|
---|
2657 | param[2] = t->unit[t->curTextureUnit].objTCoeff.z;
|
---|
2658 | param[3] = t->unit[t->curTextureUnit].objTCoeff.w;
|
---|
2659 | break;
|
---|
2660 | case GL_R:
|
---|
2661 | param[0] = t->unit[t->curTextureUnit].objRCoeff.x;
|
---|
2662 | param[1] = t->unit[t->curTextureUnit].objRCoeff.y;
|
---|
2663 | param[2] = t->unit[t->curTextureUnit].objRCoeff.z;
|
---|
2664 | param[3] = t->unit[t->curTextureUnit].objRCoeff.w;
|
---|
2665 | break;
|
---|
2666 | case GL_Q:
|
---|
2667 | param[0] = t->unit[t->curTextureUnit].objQCoeff.x;
|
---|
2668 | param[1] = t->unit[t->curTextureUnit].objQCoeff.y;
|
---|
2669 | param[2] = t->unit[t->curTextureUnit].objQCoeff.z;
|
---|
2670 | param[3] = t->unit[t->curTextureUnit].objQCoeff.w;
|
---|
2671 | break;
|
---|
2672 | default:
|
---|
2673 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2674 | "glGetTexGenfv called with bogus coord: %d", coord);
|
---|
2675 | return;
|
---|
2676 | }
|
---|
2677 | break;
|
---|
2678 | case GL_EYE_PLANE:
|
---|
2679 | switch (coord) {
|
---|
2680 | case GL_S:
|
---|
2681 | param[0] = t->unit[t->curTextureUnit].eyeSCoeff.x;
|
---|
2682 | param[1] = t->unit[t->curTextureUnit].eyeSCoeff.y;
|
---|
2683 | param[2] = t->unit[t->curTextureUnit].eyeSCoeff.z;
|
---|
2684 | param[3] = t->unit[t->curTextureUnit].eyeSCoeff.w;
|
---|
2685 | break;
|
---|
2686 | case GL_T:
|
---|
2687 | param[0] = t->unit[t->curTextureUnit].eyeTCoeff.x;
|
---|
2688 | param[1] = t->unit[t->curTextureUnit].eyeTCoeff.y;
|
---|
2689 | param[2] = t->unit[t->curTextureUnit].eyeTCoeff.z;
|
---|
2690 | param[3] = t->unit[t->curTextureUnit].eyeTCoeff.w;
|
---|
2691 | break;
|
---|
2692 | case GL_R:
|
---|
2693 | param[0] = t->unit[t->curTextureUnit].eyeRCoeff.x;
|
---|
2694 | param[1] = t->unit[t->curTextureUnit].eyeRCoeff.y;
|
---|
2695 | param[2] = t->unit[t->curTextureUnit].eyeRCoeff.z;
|
---|
2696 | param[3] = t->unit[t->curTextureUnit].eyeRCoeff.w;
|
---|
2697 | break;
|
---|
2698 | case GL_Q:
|
---|
2699 | param[0] = t->unit[t->curTextureUnit].eyeQCoeff.x;
|
---|
2700 | param[1] = t->unit[t->curTextureUnit].eyeQCoeff.y;
|
---|
2701 | param[2] = t->unit[t->curTextureUnit].eyeQCoeff.z;
|
---|
2702 | param[3] = t->unit[t->curTextureUnit].eyeQCoeff.w;
|
---|
2703 | break;
|
---|
2704 | default:
|
---|
2705 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2706 | "glGetTexGenfv called with bogus coord: %d", coord);
|
---|
2707 | return;
|
---|
2708 | }
|
---|
2709 | break;
|
---|
2710 | default:
|
---|
2711 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2712 | "glGetTexGenfv called with bogus pname: %d", pname);
|
---|
2713 | return;
|
---|
2714 | }
|
---|
2715 | }
|
---|
2716 |
|
---|
2717 |
|
---|
2718 | void STATE_APIENTRY
|
---|
2719 | crStateGetTexGeniv(GLenum coord, GLenum pname, GLint *param)
|
---|
2720 | {
|
---|
2721 | CRContext *g = GetCurrentContext();
|
---|
2722 | CRTextureState *t = &(g->texture);
|
---|
2723 |
|
---|
2724 | if (g->current.inBeginEnd)
|
---|
2725 | {
|
---|
2726 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
2727 | "glGetTexGeniv called in begin/end");
|
---|
2728 | return;
|
---|
2729 | }
|
---|
2730 |
|
---|
2731 | switch (pname) {
|
---|
2732 | case GL_TEXTURE_GEN_MODE:
|
---|
2733 | switch (coord) {
|
---|
2734 | case GL_S:
|
---|
2735 | *param = (GLint) t->unit[t->curTextureUnit].gen.s;
|
---|
2736 | break;
|
---|
2737 | case GL_T:
|
---|
2738 | *param = (GLint) t->unit[t->curTextureUnit].gen.t;
|
---|
2739 | break;
|
---|
2740 | case GL_R:
|
---|
2741 | *param = (GLint) t->unit[t->curTextureUnit].gen.r;
|
---|
2742 | break;
|
---|
2743 | case GL_Q:
|
---|
2744 | *param = (GLint) t->unit[t->curTextureUnit].gen.q;
|
---|
2745 | break;
|
---|
2746 | default:
|
---|
2747 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2748 | "glGetTexGeniv called with bogus coord: %d", coord);
|
---|
2749 | return;
|
---|
2750 | }
|
---|
2751 | break;
|
---|
2752 | case GL_OBJECT_PLANE:
|
---|
2753 | switch (coord) {
|
---|
2754 | case GL_S:
|
---|
2755 | param[0] = (GLint) t->unit[t->curTextureUnit].objSCoeff.x;
|
---|
2756 | param[1] = (GLint) t->unit[t->curTextureUnit].objSCoeff.y;
|
---|
2757 | param[2] = (GLint) t->unit[t->curTextureUnit].objSCoeff.z;
|
---|
2758 | param[3] = (GLint) t->unit[t->curTextureUnit].objSCoeff.w;
|
---|
2759 | break;
|
---|
2760 | case GL_T:
|
---|
2761 | param[0] = (GLint) t->unit[t->curTextureUnit].objTCoeff.x;
|
---|
2762 | param[1] = (GLint) t->unit[t->curTextureUnit].objTCoeff.y;
|
---|
2763 | param[2] = (GLint) t->unit[t->curTextureUnit].objTCoeff.z;
|
---|
2764 | param[3] = (GLint) t->unit[t->curTextureUnit].objTCoeff.w;
|
---|
2765 | break;
|
---|
2766 | case GL_R:
|
---|
2767 | param[0] = (GLint) t->unit[t->curTextureUnit].objRCoeff.x;
|
---|
2768 | param[1] = (GLint) t->unit[t->curTextureUnit].objRCoeff.y;
|
---|
2769 | param[2] = (GLint) t->unit[t->curTextureUnit].objRCoeff.z;
|
---|
2770 | param[3] = (GLint) t->unit[t->curTextureUnit].objRCoeff.w;
|
---|
2771 | break;
|
---|
2772 | case GL_Q:
|
---|
2773 | param[0] = (GLint) t->unit[t->curTextureUnit].objQCoeff.x;
|
---|
2774 | param[1] = (GLint) t->unit[t->curTextureUnit].objQCoeff.y;
|
---|
2775 | param[2] = (GLint) t->unit[t->curTextureUnit].objQCoeff.z;
|
---|
2776 | param[3] = (GLint) t->unit[t->curTextureUnit].objQCoeff.w;
|
---|
2777 | break;
|
---|
2778 | default:
|
---|
2779 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2780 | "glGetTexGeniv called with bogus coord: %d", coord);
|
---|
2781 | return;
|
---|
2782 | }
|
---|
2783 | break;
|
---|
2784 | case GL_EYE_PLANE:
|
---|
2785 | switch (coord) {
|
---|
2786 | case GL_S:
|
---|
2787 | param[0] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.x;
|
---|
2788 | param[1] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.y;
|
---|
2789 | param[2] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.z;
|
---|
2790 | param[3] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.w;
|
---|
2791 | break;
|
---|
2792 | case GL_T:
|
---|
2793 | param[0] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.x;
|
---|
2794 | param[1] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.y;
|
---|
2795 | param[2] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.z;
|
---|
2796 | param[3] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.w;
|
---|
2797 | break;
|
---|
2798 | case GL_R:
|
---|
2799 | param[0] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.x;
|
---|
2800 | param[1] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.y;
|
---|
2801 | param[2] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.z;
|
---|
2802 | param[3] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.w;
|
---|
2803 | break;
|
---|
2804 | case GL_Q:
|
---|
2805 | param[0] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.x;
|
---|
2806 | param[1] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.y;
|
---|
2807 | param[2] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.z;
|
---|
2808 | param[3] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.w;
|
---|
2809 | break;
|
---|
2810 | default:
|
---|
2811 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2812 | "glGetTexGeniv called with bogus coord: %d", coord);
|
---|
2813 | return;
|
---|
2814 | }
|
---|
2815 | break;
|
---|
2816 | default:
|
---|
2817 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2818 | "glGetTexGen called with bogus pname: %d", pname);
|
---|
2819 | return;
|
---|
2820 | }
|
---|
2821 | }
|
---|
2822 |
|
---|
2823 |
|
---|
2824 | void STATE_APIENTRY
|
---|
2825 | crStateGetTexLevelParameterfv(GLenum target, GLint level,
|
---|
2826 | GLenum pname, GLfloat *params)
|
---|
2827 | {
|
---|
2828 | CRContext *g = GetCurrentContext();
|
---|
2829 | CRTextureState *t = &(g->texture);
|
---|
2830 | CRTextureObj *tobj;
|
---|
2831 | CRTextureLevel *timg;
|
---|
2832 |
|
---|
2833 | if (g->current.inBeginEnd)
|
---|
2834 | {
|
---|
2835 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
2836 | "glGetTexLevelParameterfv called in begin/end");
|
---|
2837 | return;
|
---|
2838 | }
|
---|
2839 |
|
---|
2840 | if (level < 0 || level > t->maxLevel)
|
---|
2841 | {
|
---|
2842 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
2843 | "glGetTexLevelParameterfv: Invalid level: %d", level);
|
---|
2844 | return;
|
---|
2845 | }
|
---|
2846 |
|
---|
2847 | crStateGetTextureObjectAndImage(g, target, level, &tobj, &timg);
|
---|
2848 | if (!timg)
|
---|
2849 | {
|
---|
2850 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2851 | "GetTexLevelParameterfv: invalid target: 0x%x or level %d",
|
---|
2852 | target, level);
|
---|
2853 | return;
|
---|
2854 | }
|
---|
2855 |
|
---|
2856 | switch (pname)
|
---|
2857 | {
|
---|
2858 | case GL_TEXTURE_WIDTH:
|
---|
2859 | *params = (GLfloat) timg->width;
|
---|
2860 | break;
|
---|
2861 | case GL_TEXTURE_HEIGHT:
|
---|
2862 | *params = (GLfloat) timg->height;
|
---|
2863 | break;
|
---|
2864 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
2865 | case GL_TEXTURE_DEPTH:
|
---|
2866 | *params = (GLfloat) timg->depth;
|
---|
2867 | break;
|
---|
2868 | #endif
|
---|
2869 | case GL_TEXTURE_INTERNAL_FORMAT:
|
---|
2870 | *params = (GLfloat) timg->internalFormat;
|
---|
2871 | break;
|
---|
2872 | case GL_TEXTURE_BORDER:
|
---|
2873 | *params = (GLfloat) timg->border;
|
---|
2874 | break;
|
---|
2875 | case GL_TEXTURE_RED_SIZE:
|
---|
2876 | *params = (GLfloat) timg->texFormat->redbits;
|
---|
2877 | break;
|
---|
2878 | case GL_TEXTURE_GREEN_SIZE:
|
---|
2879 | *params = (GLfloat) timg->texFormat->greenbits;
|
---|
2880 | break;
|
---|
2881 | case GL_TEXTURE_BLUE_SIZE:
|
---|
2882 | *params = (GLfloat) timg->texFormat->bluebits;
|
---|
2883 | break;
|
---|
2884 | case GL_TEXTURE_ALPHA_SIZE:
|
---|
2885 | *params = (GLfloat) timg->texFormat->alphabits;
|
---|
2886 | break;
|
---|
2887 | case GL_TEXTURE_INTENSITY_SIZE:
|
---|
2888 | *params = (GLfloat) timg->texFormat->intensitybits;
|
---|
2889 | break;
|
---|
2890 | case GL_TEXTURE_LUMINANCE_SIZE:
|
---|
2891 | *params = (GLfloat) timg->texFormat->luminancebits;
|
---|
2892 | break;
|
---|
2893 | #if CR_ARB_texture_compression
|
---|
2894 | case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
|
---|
2895 | *params = (GLfloat) timg->bytes;
|
---|
2896 | break;
|
---|
2897 | case GL_TEXTURE_COMPRESSED_ARB:
|
---|
2898 | *params = (GLfloat) timg->compressed;
|
---|
2899 | break;
|
---|
2900 | #endif
|
---|
2901 | default:
|
---|
2902 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2903 | "GetTexLevelParameterfv: invalid pname: 0x%x",
|
---|
2904 | pname);
|
---|
2905 | return;
|
---|
2906 | }
|
---|
2907 | }
|
---|
2908 |
|
---|
2909 |
|
---|
2910 | void STATE_APIENTRY
|
---|
2911 | crStateGetTexLevelParameteriv(GLenum target, GLint level,
|
---|
2912 | GLenum pname, GLint *params)
|
---|
2913 | {
|
---|
2914 | CRContext *g = GetCurrentContext();
|
---|
2915 | CRTextureState *t = &(g->texture);
|
---|
2916 | CRTextureObj *tobj;
|
---|
2917 | CRTextureLevel *timg;
|
---|
2918 |
|
---|
2919 | if (g->current.inBeginEnd)
|
---|
2920 | {
|
---|
2921 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
2922 | "glGetTexLevelParameteriv called in begin/end");
|
---|
2923 | return;
|
---|
2924 | }
|
---|
2925 |
|
---|
2926 | if (level < 0 || level > t->maxLevel)
|
---|
2927 | {
|
---|
2928 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
2929 | "glGetTexLevelParameteriv: Invalid level: %d", level);
|
---|
2930 | return;
|
---|
2931 | }
|
---|
2932 |
|
---|
2933 | crStateGetTextureObjectAndImage(g, target, level, &tobj, &timg);
|
---|
2934 | if (!timg)
|
---|
2935 | {
|
---|
2936 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2937 | "GetTexLevelParameteriv: invalid target: 0x%x",
|
---|
2938 | target);
|
---|
2939 | return;
|
---|
2940 | }
|
---|
2941 |
|
---|
2942 | switch (pname)
|
---|
2943 | {
|
---|
2944 | case GL_TEXTURE_WIDTH:
|
---|
2945 | *params = (GLint) timg->width;
|
---|
2946 | break;
|
---|
2947 | case GL_TEXTURE_HEIGHT:
|
---|
2948 | *params = (GLint) timg->height;
|
---|
2949 | break;
|
---|
2950 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
2951 | case GL_TEXTURE_DEPTH:
|
---|
2952 | *params = (GLint) timg->depth;
|
---|
2953 | break;
|
---|
2954 | #endif
|
---|
2955 | case GL_TEXTURE_INTERNAL_FORMAT:
|
---|
2956 | *params = (GLint) timg->internalFormat;
|
---|
2957 | break;
|
---|
2958 | case GL_TEXTURE_BORDER:
|
---|
2959 | *params = (GLint) timg->border;
|
---|
2960 | break;
|
---|
2961 | case GL_TEXTURE_RED_SIZE:
|
---|
2962 | *params = (GLint) timg->texFormat->redbits;
|
---|
2963 | break;
|
---|
2964 | case GL_TEXTURE_GREEN_SIZE:
|
---|
2965 | *params = (GLint) timg->texFormat->greenbits;
|
---|
2966 | break;
|
---|
2967 | case GL_TEXTURE_BLUE_SIZE:
|
---|
2968 | *params = (GLint) timg->texFormat->bluebits;
|
---|
2969 | break;
|
---|
2970 | case GL_TEXTURE_ALPHA_SIZE:
|
---|
2971 | *params = (GLint) timg->texFormat->alphabits;
|
---|
2972 | break;
|
---|
2973 | case GL_TEXTURE_INTENSITY_SIZE:
|
---|
2974 | *params = (GLint) timg->texFormat->intensitybits;
|
---|
2975 | break;
|
---|
2976 | case GL_TEXTURE_LUMINANCE_SIZE:
|
---|
2977 | *params = (GLint) timg->texFormat->luminancebits;
|
---|
2978 | break;
|
---|
2979 |
|
---|
2980 | #if 0
|
---|
2981 | /* XXX TODO */
|
---|
2982 | case GL_TEXTURE_DEPTH_SIZE:
|
---|
2983 | *params = (GLint) timg->texFormat->depthSize;
|
---|
2984 | break;
|
---|
2985 | #endif
|
---|
2986 | #if CR_ARB_texture_compression
|
---|
2987 | case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
|
---|
2988 | *params = (GLint) timg->bytes;
|
---|
2989 | break;
|
---|
2990 | case GL_TEXTURE_COMPRESSED_ARB:
|
---|
2991 | *params = (GLint) timg->compressed;
|
---|
2992 | break;
|
---|
2993 | #endif
|
---|
2994 | default:
|
---|
2995 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
2996 | "GetTexLevelParameteriv: invalid pname: 0x%x",
|
---|
2997 | pname);
|
---|
2998 | return;
|
---|
2999 | }
|
---|
3000 | }
|
---|
3001 |
|
---|
3002 |
|
---|
3003 | void STATE_APIENTRY
|
---|
3004 | crStateGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
|
---|
3005 | {
|
---|
3006 | CRContext *g = GetCurrentContext();
|
---|
3007 | CRTextureObj *tobj;
|
---|
3008 | CRTextureLevel *tl;
|
---|
3009 |
|
---|
3010 | if (g->current.inBeginEnd)
|
---|
3011 | {
|
---|
3012 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
3013 | "glGetTexParameterfv called in begin/end");
|
---|
3014 | return;
|
---|
3015 | }
|
---|
3016 |
|
---|
3017 | crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
|
---|
3018 | if (!tobj)
|
---|
3019 | {
|
---|
3020 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3021 | "glGetTexParameterfv: invalid target: 0x%x", target);
|
---|
3022 | return;
|
---|
3023 | }
|
---|
3024 |
|
---|
3025 | switch (pname)
|
---|
3026 | {
|
---|
3027 | case GL_TEXTURE_MAG_FILTER:
|
---|
3028 | *params = (GLfloat) tobj->magFilter;
|
---|
3029 | break;
|
---|
3030 | case GL_TEXTURE_MIN_FILTER:
|
---|
3031 | *params = (GLfloat) tobj->minFilter;
|
---|
3032 | break;
|
---|
3033 | case GL_TEXTURE_WRAP_S:
|
---|
3034 | *params = (GLfloat) tobj->wrapS;
|
---|
3035 | break;
|
---|
3036 | case GL_TEXTURE_WRAP_T:
|
---|
3037 | *params = (GLfloat) tobj->wrapT;
|
---|
3038 | break;
|
---|
3039 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
3040 | case GL_TEXTURE_WRAP_R:
|
---|
3041 | *params = (GLfloat) tobj->wrapR;
|
---|
3042 | break;
|
---|
3043 | case GL_TEXTURE_PRIORITY:
|
---|
3044 | *params = (GLfloat) tobj->priority;
|
---|
3045 | break;
|
---|
3046 | #endif
|
---|
3047 | case GL_TEXTURE_BORDER_COLOR:
|
---|
3048 | params[0] = tobj->borderColor.r;
|
---|
3049 | params[1] = tobj->borderColor.g;
|
---|
3050 | params[2] = tobj->borderColor.b;
|
---|
3051 | params[3] = tobj->borderColor.a;
|
---|
3052 | break;
|
---|
3053 | #ifdef CR_EXT_texture_filter_anisotropic
|
---|
3054 | case GL_TEXTURE_MAX_ANISOTROPY_EXT:
|
---|
3055 | if (g->extensions.EXT_texture_filter_anisotropic) {
|
---|
3056 | *params = (GLfloat) tobj->maxAnisotropy;
|
---|
3057 | }
|
---|
3058 | else {
|
---|
3059 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3060 | "glGetTexParameterfv: invalid pname: 0x%x", pname);
|
---|
3061 | return;
|
---|
3062 | }
|
---|
3063 | break;
|
---|
3064 | #endif
|
---|
3065 | #ifdef CR_ARB_depth_texture
|
---|
3066 | case GL_DEPTH_TEXTURE_MODE_ARB:
|
---|
3067 | if (g->extensions.ARB_depth_texture) {
|
---|
3068 | *params = (GLfloat) tobj->depthMode;
|
---|
3069 | }
|
---|
3070 | else {
|
---|
3071 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3072 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3073 | return;
|
---|
3074 | }
|
---|
3075 | break;
|
---|
3076 | #endif
|
---|
3077 | #ifdef CR_ARB_shadow
|
---|
3078 | case GL_TEXTURE_COMPARE_MODE_ARB:
|
---|
3079 | if (g->extensions.ARB_shadow) {
|
---|
3080 | *params = (GLfloat) tobj->compareMode;
|
---|
3081 | }
|
---|
3082 | else {
|
---|
3083 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3084 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3085 | return;
|
---|
3086 | }
|
---|
3087 | break;
|
---|
3088 | case GL_TEXTURE_COMPARE_FUNC_ARB:
|
---|
3089 | if (g->extensions.ARB_shadow) {
|
---|
3090 | *params = (GLfloat) tobj->compareFunc;
|
---|
3091 | }
|
---|
3092 | else {
|
---|
3093 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3094 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3095 | return;
|
---|
3096 | }
|
---|
3097 | break;
|
---|
3098 | #endif
|
---|
3099 | #ifdef CR_ARB_shadow_ambient
|
---|
3100 | case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
|
---|
3101 | if (g->extensions.ARB_shadow_ambient) {
|
---|
3102 | *params = (GLfloat) tobj->compareFailValue;
|
---|
3103 | }
|
---|
3104 | else {
|
---|
3105 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3106 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3107 | return;
|
---|
3108 | }
|
---|
3109 | break;
|
---|
3110 | #endif
|
---|
3111 | #ifdef CR_SGIS_generate_mipmap
|
---|
3112 | case GL_GENERATE_MIPMAP_SGIS:
|
---|
3113 | if (g->extensions.SGIS_generate_mipmap) {
|
---|
3114 | *params = (GLfloat) tobj->generateMipmap;
|
---|
3115 | }
|
---|
3116 | else {
|
---|
3117 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3118 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3119 | return;
|
---|
3120 | }
|
---|
3121 | break;
|
---|
3122 | #endif
|
---|
3123 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
3124 | case GL_TEXTURE_MIN_LOD:
|
---|
3125 | *params = (GLfloat) tobj->minLod;
|
---|
3126 | break;
|
---|
3127 | case GL_TEXTURE_MAX_LOD:
|
---|
3128 | *params = (GLfloat) tobj->maxLod;
|
---|
3129 | break;
|
---|
3130 | case GL_TEXTURE_BASE_LEVEL:
|
---|
3131 | *params = (GLfloat) tobj->baseLevel;
|
---|
3132 | break;
|
---|
3133 | case GL_TEXTURE_MAX_LEVEL:
|
---|
3134 | *params = (GLfloat) tobj->maxLevel;
|
---|
3135 | break;
|
---|
3136 | #endif
|
---|
3137 | #if 0
|
---|
3138 | case GL_TEXTURE_LOD_BIAS_EXT:
|
---|
3139 | /* XXX todo */
|
---|
3140 | *params = (GLfloat) tobj->lodBias;
|
---|
3141 | break;
|
---|
3142 | #endif
|
---|
3143 | case GL_TEXTURE_RESIDENT:
|
---|
3144 | /* XXX todo */
|
---|
3145 | crWarning("glGetTexParameterfv GL_TEXTURE_RESIDENT is unimplemented");
|
---|
3146 | break;
|
---|
3147 | default:
|
---|
3148 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3149 | "glGetTexParameterfv: invalid pname: %d", pname);
|
---|
3150 | return;
|
---|
3151 | }
|
---|
3152 | }
|
---|
3153 |
|
---|
3154 |
|
---|
3155 | void STATE_APIENTRY
|
---|
3156 | crStateGetTexParameteriv(GLenum target, GLenum pname, GLint *params)
|
---|
3157 | {
|
---|
3158 | CRContext *g = GetCurrentContext();
|
---|
3159 | CRTextureObj *tobj;
|
---|
3160 | CRTextureLevel *tl;
|
---|
3161 |
|
---|
3162 | if (g->current.inBeginEnd)
|
---|
3163 | {
|
---|
3164 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
3165 | "glGetTexParameter called in begin/end");
|
---|
3166 | return;
|
---|
3167 | }
|
---|
3168 |
|
---|
3169 | crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
|
---|
3170 | if (!tobj)
|
---|
3171 | {
|
---|
3172 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3173 | "glGetTexParameteriv: invalid target: 0x%x", target);
|
---|
3174 | return;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | switch (pname)
|
---|
3178 | {
|
---|
3179 | case GL_TEXTURE_MAG_FILTER:
|
---|
3180 | *params = (GLint) tobj->magFilter;
|
---|
3181 | break;
|
---|
3182 | case GL_TEXTURE_MIN_FILTER:
|
---|
3183 | *params = (GLint) tobj->minFilter;
|
---|
3184 | break;
|
---|
3185 | case GL_TEXTURE_WRAP_S:
|
---|
3186 | *params = (GLint) tobj->wrapS;
|
---|
3187 | break;
|
---|
3188 | case GL_TEXTURE_WRAP_T:
|
---|
3189 | *params = (GLint) tobj->wrapT;
|
---|
3190 | break;
|
---|
3191 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
3192 | case GL_TEXTURE_WRAP_R:
|
---|
3193 | *params = (GLint) tobj->wrapR;
|
---|
3194 | break;
|
---|
3195 | case GL_TEXTURE_PRIORITY:
|
---|
3196 | *params = (GLint) tobj->priority;
|
---|
3197 | break;
|
---|
3198 | #endif
|
---|
3199 | case GL_TEXTURE_BORDER_COLOR:
|
---|
3200 | params[0] = (GLint) (tobj->borderColor.r * CR_MAXINT);
|
---|
3201 | params[1] = (GLint) (tobj->borderColor.g * CR_MAXINT);
|
---|
3202 | params[2] = (GLint) (tobj->borderColor.b * CR_MAXINT);
|
---|
3203 | params[3] = (GLint) (tobj->borderColor.a * CR_MAXINT);
|
---|
3204 | break;
|
---|
3205 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
3206 | case GL_TEXTURE_MIN_LOD:
|
---|
3207 | *params = (GLint) tobj->minLod;
|
---|
3208 | break;
|
---|
3209 | case GL_TEXTURE_MAX_LOD:
|
---|
3210 | *params = (GLint) tobj->maxLod;
|
---|
3211 | break;
|
---|
3212 | case GL_TEXTURE_BASE_LEVEL:
|
---|
3213 | *params = (GLint) tobj->baseLevel;
|
---|
3214 | break;
|
---|
3215 | case GL_TEXTURE_MAX_LEVEL:
|
---|
3216 | *params = (GLint) tobj->maxLevel;
|
---|
3217 | break;
|
---|
3218 | #endif
|
---|
3219 | #ifdef CR_EXT_texture_filter_anisotropic
|
---|
3220 | case GL_TEXTURE_MAX_ANISOTROPY_EXT:
|
---|
3221 | if (g->extensions.EXT_texture_filter_anisotropic) {
|
---|
3222 | *params = (GLint) tobj->maxAnisotropy;
|
---|
3223 | }
|
---|
3224 | else {
|
---|
3225 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3226 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3227 | return;
|
---|
3228 | }
|
---|
3229 | break;
|
---|
3230 | #endif
|
---|
3231 | #ifdef CR_ARB_depth_texture
|
---|
3232 | case GL_DEPTH_TEXTURE_MODE_ARB:
|
---|
3233 | if (g->extensions.ARB_depth_texture) {
|
---|
3234 | *params = (GLint) tobj->depthMode;
|
---|
3235 | }
|
---|
3236 | else {
|
---|
3237 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3238 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3239 | return;
|
---|
3240 | }
|
---|
3241 | break;
|
---|
3242 | #endif
|
---|
3243 | #ifdef CR_ARB_shadow
|
---|
3244 | case GL_TEXTURE_COMPARE_MODE_ARB:
|
---|
3245 | if (g->extensions.ARB_shadow) {
|
---|
3246 | *params = (GLint) tobj->compareMode;
|
---|
3247 | }
|
---|
3248 | else {
|
---|
3249 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3250 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3251 | return;
|
---|
3252 | }
|
---|
3253 | break;
|
---|
3254 | case GL_TEXTURE_COMPARE_FUNC_ARB:
|
---|
3255 | if (g->extensions.ARB_shadow) {
|
---|
3256 | *params = (GLint) tobj->compareFunc;
|
---|
3257 | }
|
---|
3258 | else {
|
---|
3259 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3260 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3261 | return;
|
---|
3262 | }
|
---|
3263 | break;
|
---|
3264 | #endif
|
---|
3265 | #ifdef CR_ARB_shadow_ambient
|
---|
3266 | case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
|
---|
3267 | if (g->extensions.ARB_shadow_ambient) {
|
---|
3268 | *params = (GLint) tobj->compareFailValue;
|
---|
3269 | }
|
---|
3270 | else {
|
---|
3271 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3272 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3273 | return;
|
---|
3274 | }
|
---|
3275 | break;
|
---|
3276 | #endif
|
---|
3277 | #ifdef CR_SGIS_generate_mipmap
|
---|
3278 | case GL_GENERATE_MIPMAP_SGIS:
|
---|
3279 | if (g->extensions.SGIS_generate_mipmap) {
|
---|
3280 | *params = (GLint) tobj->generateMipmap;
|
---|
3281 | }
|
---|
3282 | else {
|
---|
3283 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3284 | "glGetTexParameter: invalid pname: 0x%x", pname);
|
---|
3285 | return;
|
---|
3286 | }
|
---|
3287 | break;
|
---|
3288 | #endif
|
---|
3289 | case GL_TEXTURE_RESIDENT:
|
---|
3290 | /* XXX todo */
|
---|
3291 | crWarning("glGetTexParameteriv GL_TEXTURE_RESIDENT is unimplemented");
|
---|
3292 | break;
|
---|
3293 | default:
|
---|
3294 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
3295 | "glGetTexParameter: invalid pname: %d", pname);
|
---|
3296 | return;
|
---|
3297 | }
|
---|
3298 | }
|
---|
3299 |
|
---|
3300 |
|
---|
3301 | void STATE_APIENTRY
|
---|
3302 | crStatePrioritizeTextures(GLsizei n, const GLuint *textures,
|
---|
3303 | const GLclampf *priorities)
|
---|
3304 | {
|
---|
3305 | CRContext *g = GetCurrentContext();
|
---|
3306 | CRTextureObj *tobj;
|
---|
3307 | GLsizei i;
|
---|
3308 | UNUSED(priorities);
|
---|
3309 |
|
---|
3310 | for (i = 0; i < n; ++i)
|
---|
3311 | {
|
---|
3312 | GLuint tex = textures[i];
|
---|
3313 | GET_TOBJ(tobj, g, tex);
|
---|
3314 | if (!tobj)
|
---|
3315 | {
|
---|
3316 | Assert(crHashtableIsKeyUsed(g->shared->textureTable, tex));
|
---|
3317 | tobj = crStateTextureAllocate_t(g, tex);
|
---|
3318 | }
|
---|
3319 |
|
---|
3320 | /* so far the code just ensures the tex object is created to make
|
---|
3321 | * the crserverlib code be able to pass it to host ogl */
|
---|
3322 |
|
---|
3323 | /** @todo store texture priorities in the state data to be able to restore it properly
|
---|
3324 | * on save state load */
|
---|
3325 | }
|
---|
3326 |
|
---|
3327 | return;
|
---|
3328 | }
|
---|
3329 |
|
---|
3330 |
|
---|
3331 | GLboolean STATE_APIENTRY
|
---|
3332 | crStateAreTexturesResident(GLsizei n, const GLuint *textures,
|
---|
3333 | GLboolean *residences)
|
---|
3334 | {
|
---|
3335 | UNUSED(n);
|
---|
3336 | UNUSED(textures);
|
---|
3337 | UNUSED(residences);
|
---|
3338 | /** @todo */
|
---|
3339 | return GL_TRUE;
|
---|
3340 | }
|
---|
3341 |
|
---|
3342 |
|
---|
3343 | GLboolean STATE_APIENTRY
|
---|
3344 | crStateIsTexture(GLuint texture)
|
---|
3345 | {
|
---|
3346 | CRContext *g = GetCurrentContext();
|
---|
3347 | CRTextureObj *tobj;
|
---|
3348 |
|
---|
3349 | GET_TOBJ(tobj, g, texture);
|
---|
3350 | return tobj != NULL;
|
---|
3351 | }
|
---|
3352 |
|
---|
3353 | static void crStateCheckTextureHWIDCB(unsigned long key, void *data1, void *data2)
|
---|
3354 | {
|
---|
3355 | CRTextureObj *pTex = (CRTextureObj *) data1;
|
---|
3356 | crCheckIDHWID_t *pParms = (crCheckIDHWID_t*) data2;
|
---|
3357 | (void) key;
|
---|
3358 |
|
---|
3359 | if (crStateGetTextureObjHWID(pTex)==pParms->hwid)
|
---|
3360 | pParms->id = pTex->id;
|
---|
3361 | }
|
---|
3362 |
|
---|
3363 | DECLEXPORT(GLuint) STATE_APIENTRY crStateTextureHWIDtoID(GLuint hwid)
|
---|
3364 | {
|
---|
3365 | CRContext *g = GetCurrentContext();
|
---|
3366 | crCheckIDHWID_t parms;
|
---|
3367 |
|
---|
3368 | parms.id = hwid;
|
---|
3369 | parms.hwid = hwid;
|
---|
3370 |
|
---|
3371 | crHashtableWalk(g->shared->textureTable, crStateCheckTextureHWIDCB, &parms);
|
---|
3372 | return parms.id;
|
---|
3373 | }
|
---|
3374 |
|
---|
3375 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureHWID(GLuint id)
|
---|
3376 | {
|
---|
3377 | CRContext *g = GetCurrentContext();
|
---|
3378 | CRTextureObj *tobj;
|
---|
3379 |
|
---|
3380 | GET_TOBJ(tobj, g, id);
|
---|
3381 |
|
---|
3382 | #ifdef DEBUG_misha
|
---|
3383 | if (id)
|
---|
3384 | {
|
---|
3385 | Assert(tobj);
|
---|
3386 | }
|
---|
3387 | else
|
---|
3388 | {
|
---|
3389 | Assert(!tobj);
|
---|
3390 | }
|
---|
3391 | if (tobj)
|
---|
3392 | {
|
---|
3393 | /* crDebug("tex id(%d), hwid(%d)", tobj->id, tobj->hwid);*/
|
---|
3394 | }
|
---|
3395 | #endif
|
---|
3396 |
|
---|
3397 |
|
---|
3398 | return tobj ? crStateGetTextureObjHWID(tobj) : 0;
|
---|
3399 | }
|
---|
3400 |
|
---|
3401 | DECLEXPORT(GLuint) STATE_APIENTRY crStateGetTextureObjHWID(CRTextureObj *tobj)
|
---|
3402 | {
|
---|
3403 | CRASSERT(tobj);
|
---|
3404 |
|
---|
3405 | #ifndef IN_GUEST
|
---|
3406 | if (tobj->id && !tobj->hwid)
|
---|
3407 | {
|
---|
3408 | CRASSERT(diff_api.GenTextures);
|
---|
3409 | diff_api.GenTextures(1, &tobj->hwid);
|
---|
3410 | #if 0 /*def DEBUG_misha*/
|
---|
3411 | crDebug("tex id(%d), hwid(%d)", tobj->id, tobj->hwid);
|
---|
3412 | #endif
|
---|
3413 | CRASSERT(tobj->hwid);
|
---|
3414 | }
|
---|
3415 | #endif
|
---|
3416 |
|
---|
3417 | return tobj->hwid;
|
---|
3418 | }
|
---|