VirtualBox

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

Last change on this file since 78402 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

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

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