VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c@ 27396

Last change on this file since 27396 was 27396, checked in by vboxsync, 15 years ago

crOpenGL: opengl 2.1 support

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette