VirtualBox

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

最後變更 在這個檔案從44326是 44125,由 vboxsync 提交於 12 年 前

crOpenGL: fix guest state bits

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

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