VirtualBox

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

Last change on this file since 37771 was 37771, checked in by vboxsync, 13 years ago

crOpenGL: fix warning

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