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