VirtualBox

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

Last change on this file since 55043 was 52641, checked in by vboxsync, 10 years ago

crOpenGL: disable some verbose logging

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