VirtualBox

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

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

crOpenGL: add GL_EXT_framebuffer_object support

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