VirtualBox

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

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

crOpenGL: shared textures fix

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

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