VirtualBox

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

Last change on this file since 37650 was 37613, checked in by vboxsync, 14 years ago

wddm/3d: fix snapshots with aero

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