VirtualBox

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

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

crOpenGL: most changes to extend FBO support to ARB version

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