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