VirtualBox

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

Last change on this file since 41109 was 41109, checked in by vboxsync, 13 years ago

crOpenGL,wined3d,wddm: second part of fixing resource leakage, basics for cr commands submission from r0 miniport driver (for r0 visible region reporting, WPF 3D rendering fixes w/o Aero, etc.)

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

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