VirtualBox

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

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

crOpenGL: resource sharing between contexts

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