VirtualBox

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

Last change on this file since 50460 was 50041, checked in by vboxsync, 11 years ago

crOpenGL: crOpenGL: 1. workaround point sprite driver bugs; 2. workaround multi-string shader source driver bug; 3. proper GLhandle for OSX; 4. extended dumping; 5. misc fixes

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