VirtualBox

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

Last change on this file since 47512 was 46607, checked in by vboxsync, 12 years ago

crOpenGL: remove false assertion

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

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