VirtualBox

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

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

crOpenGL: more gl state fixes

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

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