VirtualBox

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

最後變更 在這個檔案從25154是 25154,由 vboxsync 提交於 15 年 前

crOpenGL: fix various texture tracking issues

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

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