1 /* $Id: texstate.c,v 1.9 2000/03/07 17:54:58 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 #include "extensions.h"
47 /* Needed for an Amiga compiler */
48 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
49 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
51 /* all other compilers */
52 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
53 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
59 /**********************************************************************/
60 /* Texture Environment */
61 /**********************************************************************/
65 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
67 GET_CURRENT_CONTEXT(ctx
);
68 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
70 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexEnv");
72 if (target
==GL_TEXTURE_ENV
) {
74 if (pname
==GL_TEXTURE_ENV_MODE
) {
75 GLenum mode
= (GLenum
) (GLint
) *param
;
78 if (!ctx
->Extensions
.HaveTextureEnvAdd
) {
79 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
87 /* A small optimization for drivers */
88 if (texUnit
->EnvMode
== mode
)
91 if (MESA_VERBOSE
& (VERBOSE_STATE
|VERBOSE_TEXTURE
))
92 fprintf(stderr
, "glTexEnv: old mode %s, new mode %s\n",
93 gl_lookup_enum_by_nr(texUnit
->EnvMode
),
94 gl_lookup_enum_by_nr(mode
));
96 texUnit
->EnvMode
= mode
;
97 ctx
->NewState
|= NEW_TEXTURE_ENV
;
100 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
104 else if (pname
==GL_TEXTURE_ENV_COLOR
) {
105 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
106 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
107 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
108 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
111 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
116 else if (target
==GL_TEXTURE_FILTER_CONTROL_EXT
) {
118 if (!ctx
->Extensions
.HaveTextureLodBias
) {
119 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
123 if (pname
==GL_TEXTURE_LOD_BIAS_EXT
) {
124 texUnit
->LodBias
= param
[0];
127 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
133 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
137 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
138 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
139 gl_lookup_enum_by_nr(target
),
140 gl_lookup_enum_by_nr(pname
),
142 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
144 /* Tell device driver about the new texture environment */
145 if (ctx
->Driver
.TexEnv
) {
146 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
153 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
155 _mesa_TexEnvfv( target
, pname
, ¶m
);
161 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
164 p
[0] = (GLfloat
) param
;
165 p
[1] = p
[2] = p
[3] = 0.0;
166 _mesa_TexEnvfv( target
, pname
, p
);
171 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
174 p
[0] = INT_TO_FLOAT( param
[0] );
175 p
[1] = INT_TO_FLOAT( param
[1] );
176 p
[2] = INT_TO_FLOAT( param
[2] );
177 p
[3] = INT_TO_FLOAT( param
[3] );
178 _mesa_TexEnvfv( target
, pname
, p
);
183 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
185 GET_CURRENT_CONTEXT(ctx
);
186 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
188 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexEnvfv");
190 if (target
!=GL_TEXTURE_ENV
) {
191 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
195 case GL_TEXTURE_ENV_MODE
:
196 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
198 case GL_TEXTURE_ENV_COLOR
:
199 COPY_4FV( params
, texUnit
->EnvColor
);
202 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
208 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
210 GET_CURRENT_CONTEXT(ctx
);
211 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
213 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexEnviv");
215 if (target
!=GL_TEXTURE_ENV
) {
216 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
220 case GL_TEXTURE_ENV_MODE
:
221 *params
= (GLint
) texUnit
->EnvMode
;
223 case GL_TEXTURE_ENV_COLOR
:
224 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
225 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
226 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
227 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
230 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
237 /**********************************************************************/
238 /* Texture Parameters */
239 /**********************************************************************/
243 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
245 _mesa_TexParameterfv(target
, pname
, ¶m
);
250 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
252 GET_CURRENT_CONTEXT(ctx
);
253 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
254 GLenum eparam
= (GLenum
) (GLint
) params
[0];
255 struct gl_texture_object
*texObj
;
257 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexParameterfv");
259 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
260 fprintf(stderr
, "texPARAM %s %s %d...\n",
261 gl_lookup_enum_by_nr(target
),
262 gl_lookup_enum_by_nr(pname
),
268 texObj
= texUnit
->CurrentD
[1];
271 texObj
= texUnit
->CurrentD
[2];
273 case GL_TEXTURE_3D_EXT
:
274 texObj
= texUnit
->CurrentD
[3];
277 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
282 case GL_TEXTURE_MIN_FILTER
:
283 /* A small optimization */
284 if (texObj
->MinFilter
== eparam
)
287 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
288 || eparam
==GL_NEAREST_MIPMAP_NEAREST
289 || eparam
==GL_LINEAR_MIPMAP_NEAREST
290 || eparam
==GL_NEAREST_MIPMAP_LINEAR
291 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
292 texObj
->MinFilter
= eparam
;
293 ctx
->NewState
|= NEW_TEXTURING
;
296 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
300 case GL_TEXTURE_MAG_FILTER
:
301 /* A small optimization */
302 if (texObj
->MagFilter
== eparam
)
305 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
306 texObj
->MagFilter
= eparam
;
307 ctx
->NewState
|= NEW_TEXTURING
;
310 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
314 case GL_TEXTURE_WRAP_S
:
315 if (texObj
->WrapS
== eparam
)
318 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
319 texObj
->WrapS
= eparam
;
320 ctx
->NewState
|= NEW_TEXTURING
;
323 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
327 case GL_TEXTURE_WRAP_T
:
328 if (texObj
->WrapT
== eparam
)
331 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
332 texObj
->WrapT
= eparam
;
333 ctx
->NewState
|= NEW_TEXTURING
;
336 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
340 case GL_TEXTURE_WRAP_R_EXT
:
341 if (texObj
->WrapR
== eparam
)
344 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
345 texObj
->WrapR
= eparam
;
346 ctx
->NewState
|= NEW_TEXTURING
;
349 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
352 case GL_TEXTURE_BORDER_COLOR
:
353 texObj
->BorderColor
[0] = (GLubyte
) CLAMP((GLint
)(params
[0]*255.0), 0, 255);
354 texObj
->BorderColor
[1] = (GLubyte
) CLAMP((GLint
)(params
[1]*255.0), 0, 255);
355 texObj
->BorderColor
[2] = (GLubyte
) CLAMP((GLint
)(params
[2]*255.0), 0, 255);
356 texObj
->BorderColor
[3] = (GLubyte
) CLAMP((GLint
)(params
[3]*255.0), 0, 255);
358 case GL_TEXTURE_MIN_LOD
:
359 texObj
->MinLod
= params
[0];
360 ctx
->NewState
|= NEW_TEXTURING
;
362 case GL_TEXTURE_MAX_LOD
:
363 texObj
->MaxLod
= params
[0];
364 ctx
->NewState
|= NEW_TEXTURING
;
366 case GL_TEXTURE_BASE_LEVEL
:
367 if (params
[0] < 0.0) {
368 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
371 texObj
->BaseLevel
= (GLint
) params
[0];
372 ctx
->NewState
|= NEW_TEXTURING
;
374 case GL_TEXTURE_MAX_LEVEL
:
375 if (params
[0] < 0.0) {
376 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
379 texObj
->MaxLevel
= (GLint
) params
[0];
380 ctx
->NewState
|= NEW_TEXTURING
;
382 case GL_TEXTURE_PRIORITY
:
383 /* (keithh@netcomuk.co.uk) */
384 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
387 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
391 gl_put_texobj_on_dirty_list( ctx
, texObj
);
393 if (ctx
->Driver
.TexParameter
) {
394 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
400 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
403 fparam
[0] = (GLfloat
) param
;
404 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
405 _mesa_TexParameterfv(target
, pname
, fparam
);
409 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
412 fparam
[0] = (GLfloat
) params
[0];
413 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
414 _mesa_TexParameterfv(target
, pname
, fparam
);
419 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
420 GLenum pname
, GLfloat
*params
)
423 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
424 *params
= (GLfloat
) iparam
;
430 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
431 GLenum pname
, GLint
*params
)
433 GET_CURRENT_CONTEXT(ctx
);
434 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
435 const struct gl_texture_image
*img
= NULL
;
438 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexLevelParameter");
440 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
441 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
447 img
= texUnit
->CurrentD
[1]->Image
[level
];
451 img
= texUnit
->CurrentD
[2]->Image
[level
];
455 img
= texUnit
->CurrentD
[3]->Image
[level
];
458 case GL_PROXY_TEXTURE_1D
:
459 img
= ctx
->Texture
.Proxy1D
->Image
[level
];
462 case GL_PROXY_TEXTURE_2D
:
463 img
= ctx
->Texture
.Proxy2D
->Image
[level
];
466 case GL_PROXY_TEXTURE_3D
:
467 img
= ctx
->Texture
.Proxy3D
->Image
[level
];
471 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
476 if (pname
== GL_TEXTURE_COMPONENTS
)
484 case GL_TEXTURE_WIDTH
:
485 *params
= img
->Width
;
487 case GL_TEXTURE_HEIGHT
:
488 if (dimensions
> 1) {
489 *params
= img
->Height
;
492 gl_error( ctx
, GL_INVALID_ENUM
,
493 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
496 case GL_TEXTURE_DEPTH
:
497 if (dimensions
> 2) {
498 *params
= img
->Depth
;
501 gl_error( ctx
, GL_INVALID_ENUM
,
502 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
505 case GL_TEXTURE_COMPONENTS
:
506 *params
= img
->IntFormat
;
508 case GL_TEXTURE_BORDER
:
509 *params
= img
->Border
;
511 case GL_TEXTURE_RED_SIZE
:
512 *params
= img
->RedBits
;
514 case GL_TEXTURE_GREEN_SIZE
:
515 *params
= img
->GreenBits
;
517 case GL_TEXTURE_BLUE_SIZE
:
518 *params
= img
->BlueBits
;
520 case GL_TEXTURE_ALPHA_SIZE
:
521 *params
= img
->AlphaBits
;
523 case GL_TEXTURE_INTENSITY_SIZE
:
524 *params
= img
->IntensityBits
;
526 case GL_TEXTURE_LUMINANCE_SIZE
:
527 *params
= img
->LuminanceBits
;
529 case GL_TEXTURE_INDEX_SIZE_EXT
:
530 *params
= img
->IndexBits
;
533 gl_error( ctx
, GL_INVALID_ENUM
,
534 "glGetTexLevelParameter[if]v(pname)" );
541 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
543 GET_CURRENT_CONTEXT(ctx
);
544 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
545 struct gl_texture_object
*obj
;
547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexParameterfv");
551 obj
= texUnit
->CurrentD
[1];
554 obj
= texUnit
->CurrentD
[2];
556 case GL_TEXTURE_3D_EXT
:
557 obj
= texUnit
->CurrentD
[3];
560 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
565 case GL_TEXTURE_MAG_FILTER
:
566 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
568 case GL_TEXTURE_MIN_FILTER
:
569 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
571 case GL_TEXTURE_WRAP_S
:
572 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
574 case GL_TEXTURE_WRAP_T
:
575 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
577 case GL_TEXTURE_WRAP_R_EXT
:
578 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
580 case GL_TEXTURE_BORDER_COLOR
:
581 params
[0] = obj
->BorderColor
[0] / 255.0F
;
582 params
[1] = obj
->BorderColor
[1] / 255.0F
;
583 params
[2] = obj
->BorderColor
[2] / 255.0F
;
584 params
[3] = obj
->BorderColor
[3] / 255.0F
;
586 case GL_TEXTURE_RESIDENT
:
587 *params
= ENUM_TO_FLOAT(GL_TRUE
);
589 case GL_TEXTURE_PRIORITY
:
590 *params
= obj
->Priority
;
592 case GL_TEXTURE_MIN_LOD
:
593 *params
= obj
->MinLod
;
595 case GL_TEXTURE_MAX_LOD
:
596 *params
= obj
->MaxLod
;
598 case GL_TEXTURE_BASE_LEVEL
:
599 *params
= (GLfloat
) obj
->BaseLevel
;
601 case GL_TEXTURE_MAX_LEVEL
:
602 *params
= (GLfloat
) obj
->MaxLevel
;
605 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
611 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
613 GET_CURRENT_CONTEXT(ctx
);
614 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
615 struct gl_texture_object
*obj
;
617 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexParameteriv");
621 obj
= texUnit
->CurrentD
[1];
624 obj
= texUnit
->CurrentD
[2];
626 case GL_TEXTURE_3D_EXT
:
627 obj
= texUnit
->CurrentD
[3];
630 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
635 case GL_TEXTURE_MAG_FILTER
:
636 *params
= (GLint
) obj
->MagFilter
;
638 case GL_TEXTURE_MIN_FILTER
:
639 *params
= (GLint
) obj
->MinFilter
;
641 case GL_TEXTURE_WRAP_S
:
642 *params
= (GLint
) obj
->WrapS
;
644 case GL_TEXTURE_WRAP_T
:
645 *params
= (GLint
) obj
->WrapT
;
647 case GL_TEXTURE_WRAP_R_EXT
:
648 *params
= (GLint
) obj
->WrapR
;
650 case GL_TEXTURE_BORDER_COLOR
:
653 color
[0] = obj
->BorderColor
[0] / 255.0F
;
654 color
[1] = obj
->BorderColor
[1] / 255.0F
;
655 color
[2] = obj
->BorderColor
[2] / 255.0F
;
656 color
[3] = obj
->BorderColor
[3] / 255.0F
;
657 params
[0] = FLOAT_TO_INT( color
[0] );
658 params
[1] = FLOAT_TO_INT( color
[1] );
659 params
[2] = FLOAT_TO_INT( color
[2] );
660 params
[3] = FLOAT_TO_INT( color
[3] );
663 case GL_TEXTURE_RESIDENT
:
664 *params
= (GLint
) GL_TRUE
;
666 case GL_TEXTURE_PRIORITY
:
667 *params
= (GLint
) obj
->Priority
;
669 case GL_TEXTURE_MIN_LOD
:
670 *params
= (GLint
) obj
->MinLod
;
672 case GL_TEXTURE_MAX_LOD
:
673 *params
= (GLint
) obj
->MaxLod
;
675 case GL_TEXTURE_BASE_LEVEL
:
676 *params
= obj
->BaseLevel
;
678 case GL_TEXTURE_MAX_LEVEL
:
679 *params
= obj
->MaxLevel
;
682 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
689 /**********************************************************************/
690 /* Texture Coord Generation */
691 /**********************************************************************/
695 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
697 GET_CURRENT_CONTEXT(ctx
);
698 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
699 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
700 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
702 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
703 fprintf(stderr
, "texGEN %s %s %x...\n",
704 gl_lookup_enum_by_nr(coord
),
705 gl_lookup_enum_by_nr(pname
),
710 if (pname
==GL_TEXTURE_GEN_MODE
) {
711 GLenum mode
= (GLenum
) (GLint
) *params
;
713 case GL_OBJECT_LINEAR
:
714 texUnit
->GenModeS
= mode
;
715 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
718 texUnit
->GenModeS
= mode
;
719 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
721 case GL_REFLECTION_MAP_NV
:
722 texUnit
->GenModeS
= mode
;
723 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
725 case GL_NORMAL_MAP_NV
:
726 texUnit
->GenModeS
= mode
;
727 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
730 texUnit
->GenModeS
= mode
;
731 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
734 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
738 else if (pname
==GL_OBJECT_PLANE
) {
739 texUnit
->ObjectPlaneS
[0] = params
[0];
740 texUnit
->ObjectPlaneS
[1] = params
[1];
741 texUnit
->ObjectPlaneS
[2] = params
[2];
742 texUnit
->ObjectPlaneS
[3] = params
[3];
744 else if (pname
==GL_EYE_PLANE
) {
745 /* Transform plane equation by the inverse modelview matrix */
746 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
747 gl_matrix_analyze( &ctx
->ModelView
);
749 gl_transform_vector( texUnit
->EyePlaneS
, params
,
750 ctx
->ModelView
.inv
);
753 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
758 if (pname
==GL_TEXTURE_GEN_MODE
) {
759 GLenum mode
= (GLenum
) (GLint
) *params
;
761 case GL_OBJECT_LINEAR
:
762 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
763 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
766 texUnit
->GenModeT
= GL_EYE_LINEAR
;
767 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
769 case GL_REFLECTION_MAP_NV
:
770 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
771 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
773 case GL_NORMAL_MAP_NV
:
774 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
775 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
778 texUnit
->GenModeT
= GL_SPHERE_MAP
;
779 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
782 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
786 else if (pname
==GL_OBJECT_PLANE
) {
787 texUnit
->ObjectPlaneT
[0] = params
[0];
788 texUnit
->ObjectPlaneT
[1] = params
[1];
789 texUnit
->ObjectPlaneT
[2] = params
[2];
790 texUnit
->ObjectPlaneT
[3] = params
[3];
792 else if (pname
==GL_EYE_PLANE
) {
793 /* Transform plane equation by the inverse modelview matrix */
794 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
795 gl_matrix_analyze( &ctx
->ModelView
);
797 gl_transform_vector( texUnit
->EyePlaneT
, params
,
798 ctx
->ModelView
.inv
);
801 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
806 if (pname
==GL_TEXTURE_GEN_MODE
) {
807 GLenum mode
= (GLenum
) (GLint
) *params
;
809 case GL_OBJECT_LINEAR
:
810 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
811 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
813 case GL_REFLECTION_MAP_NV
:
814 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
815 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
817 case GL_NORMAL_MAP_NV
:
818 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
819 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
822 texUnit
->GenModeR
= GL_EYE_LINEAR
;
823 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
826 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
830 else if (pname
==GL_OBJECT_PLANE
) {
831 texUnit
->ObjectPlaneR
[0] = params
[0];
832 texUnit
->ObjectPlaneR
[1] = params
[1];
833 texUnit
->ObjectPlaneR
[2] = params
[2];
834 texUnit
->ObjectPlaneR
[3] = params
[3];
836 else if (pname
==GL_EYE_PLANE
) {
837 /* Transform plane equation by the inverse modelview matrix */
838 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
839 gl_matrix_analyze( &ctx
->ModelView
);
841 gl_transform_vector( texUnit
->EyePlaneR
, params
,
842 ctx
->ModelView
.inv
);
845 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
850 if (pname
==GL_TEXTURE_GEN_MODE
) {
851 GLenum mode
= (GLenum
) (GLint
) *params
;
853 case GL_OBJECT_LINEAR
:
854 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
855 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
858 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
859 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
862 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
866 else if (pname
==GL_OBJECT_PLANE
) {
867 texUnit
->ObjectPlaneQ
[0] = params
[0];
868 texUnit
->ObjectPlaneQ
[1] = params
[1];
869 texUnit
->ObjectPlaneQ
[2] = params
[2];
870 texUnit
->ObjectPlaneQ
[3] = params
[3];
872 else if (pname
==GL_EYE_PLANE
) {
873 /* Transform plane equation by the inverse modelview matrix */
874 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
875 gl_matrix_analyze( &ctx
->ModelView
);
877 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
878 ctx
->ModelView
.inv
);
881 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
886 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
890 ctx
->NewState
|= NEW_TEXTURING
;
895 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
902 _mesa_TexGenfv(coord
, pname
, p
);
907 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
909 GLfloat p
= (GLfloat
) param
;
910 _mesa_TexGenfv( coord
, pname
, &p
);
915 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
922 _mesa_TexGenfv( coord
, pname
, p
);
927 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
929 _mesa_TexGenfv(coord
, pname
, ¶m
);
934 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
936 _mesa_TexGeniv( coord
, pname
, ¶m
);
942 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
944 GET_CURRENT_CONTEXT(ctx
);
945 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
946 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
948 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
952 if (pname
==GL_TEXTURE_GEN_MODE
) {
953 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
955 else if (pname
==GL_OBJECT_PLANE
) {
956 COPY_4V( params
, texUnit
->ObjectPlaneS
);
958 else if (pname
==GL_EYE_PLANE
) {
959 COPY_4V( params
, texUnit
->EyePlaneS
);
962 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
967 if (pname
==GL_TEXTURE_GEN_MODE
) {
968 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
970 else if (pname
==GL_OBJECT_PLANE
) {
971 COPY_4V( params
, texUnit
->ObjectPlaneT
);
973 else if (pname
==GL_EYE_PLANE
) {
974 COPY_4V( params
, texUnit
->EyePlaneT
);
977 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
982 if (pname
==GL_TEXTURE_GEN_MODE
) {
983 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
985 else if (pname
==GL_OBJECT_PLANE
) {
986 COPY_4V( params
, texUnit
->ObjectPlaneR
);
988 else if (pname
==GL_EYE_PLANE
) {
989 COPY_4V( params
, texUnit
->EyePlaneR
);
992 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
997 if (pname
==GL_TEXTURE_GEN_MODE
) {
998 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
1000 else if (pname
==GL_OBJECT_PLANE
) {
1001 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1003 else if (pname
==GL_EYE_PLANE
) {
1004 COPY_4V( params
, texUnit
->EyePlaneQ
);
1007 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1012 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
1020 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
1022 GET_CURRENT_CONTEXT(ctx
);
1023 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1024 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1026 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
1030 if (pname
==GL_TEXTURE_GEN_MODE
) {
1031 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
1033 else if (pname
==GL_OBJECT_PLANE
) {
1034 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1036 else if (pname
==GL_EYE_PLANE
) {
1037 COPY_4V( params
, texUnit
->EyePlaneS
);
1040 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1045 if (pname
==GL_TEXTURE_GEN_MODE
) {
1046 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1048 else if (pname
==GL_OBJECT_PLANE
) {
1049 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1051 else if (pname
==GL_EYE_PLANE
) {
1052 COPY_4V( params
, texUnit
->EyePlaneT
);
1055 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1060 if (pname
==GL_TEXTURE_GEN_MODE
) {
1061 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1063 else if (pname
==GL_OBJECT_PLANE
) {
1064 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1066 else if (pname
==GL_EYE_PLANE
) {
1067 COPY_4V( params
, texUnit
->EyePlaneR
);
1070 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1075 if (pname
==GL_TEXTURE_GEN_MODE
) {
1076 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1078 else if (pname
==GL_OBJECT_PLANE
) {
1079 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1081 else if (pname
==GL_EYE_PLANE
) {
1082 COPY_4V( params
, texUnit
->EyePlaneQ
);
1085 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1090 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1098 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1100 GET_CURRENT_CONTEXT(ctx
);
1101 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1102 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
1108 if (pname
==GL_TEXTURE_GEN_MODE
) {
1109 params
[0] = texUnit
->GenModeS
;
1111 else if (pname
==GL_OBJECT_PLANE
) {
1112 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1113 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1114 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1115 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1117 else if (pname
==GL_EYE_PLANE
) {
1118 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1119 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1120 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1121 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1124 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1129 if (pname
==GL_TEXTURE_GEN_MODE
) {
1130 params
[0] = texUnit
->GenModeT
;
1132 else if (pname
==GL_OBJECT_PLANE
) {
1133 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1134 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1135 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1136 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1138 else if (pname
==GL_EYE_PLANE
) {
1139 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1140 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1141 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1142 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1145 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1150 if (pname
==GL_TEXTURE_GEN_MODE
) {
1151 params
[0] = texUnit
->GenModeR
;
1153 else if (pname
==GL_OBJECT_PLANE
) {
1154 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1155 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1156 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1157 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1159 else if (pname
==GL_EYE_PLANE
) {
1160 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1161 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1162 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1163 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1166 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1171 if (pname
==GL_TEXTURE_GEN_MODE
) {
1172 params
[0] = texUnit
->GenModeQ
;
1174 else if (pname
==GL_OBJECT_PLANE
) {
1175 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1176 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1177 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1178 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1180 else if (pname
==GL_EYE_PLANE
) {
1181 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1182 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1183 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1184 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1187 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1192 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1198 /* GL_ARB_multitexture */
1200 _mesa_ActiveTextureARB( GLenum target
)
1202 GET_CURRENT_CONTEXT(ctx
);
1203 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1205 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1207 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1208 fprintf(stderr
, "glActiveTexture %s\n",
1209 gl_lookup_enum_by_nr(target
));
1211 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1212 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1213 ctx
->Texture
.CurrentUnit
= texUnit
;
1214 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1215 if (ctx
->Driver
.ActiveTexture
) {
1216 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1220 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1225 /* GL_ARB_multitexture */
1227 _mesa_ClientActiveTextureARB( GLenum target
)
1229 GET_CURRENT_CONTEXT(ctx
);
1230 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1232 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glClientActiveTextureARB" );
1234 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1235 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1236 ctx
->Array
.ActiveTexture
= texUnit
;
1239 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1246 * Put the given texture object into the list of dirty texture objects.
1247 * When a texture object is dirty we have to reexamine it for completeness
1248 * and perhaps choose a different texture sampling function.
1250 void gl_put_texobj_on_dirty_list( GLcontext
*ctx
, struct gl_texture_object
*t
)
1254 /* Only insert if not already in the dirty list.
1255 * The Dirty flag is only set iff the texture object is in the dirty list.
1258 ASSERT(t
->NextDirty
== NULL
);
1260 t
->NextDirty
= ctx
->Shared
->DirtyTexObjList
;
1261 ctx
->Shared
->DirtyTexObjList
= t
;
1265 /* make sure t is in the list */
1266 struct gl_texture_object
*obj
= ctx
->Shared
->DirtyTexObjList
;
1271 obj
= obj
->NextDirty
;
1273 gl_problem(ctx
, "Error in gl_put_texobj_on_dirty_list");
1280 * Remove a texture object from the dirty texture list.
1282 void gl_remove_texobj_from_dirty_list( struct gl_shared_state
*shared
,
1283 struct gl_texture_object
*tObj
)
1285 struct gl_texture_object
*t
, *prev
= NULL
;
1288 for (t
= shared
->DirtyTexObjList
; t
; t
= t
->NextDirty
) {
1291 prev
->NextDirty
= t
->NextDirty
;
1294 shared
->DirtyTexObjList
= t
->NextDirty
;
1304 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1305 * ctx->NewState is set.
1307 void gl_update_dirty_texobjs( GLcontext
*ctx
)
1309 struct gl_texture_object
*t
, *next
;
1310 for (t
= ctx
->Shared
->DirtyTexObjList
; t
; t
= next
) {
1311 next
= t
->NextDirty
;
1312 gl_test_texture_object_completeness(ctx
, t
);
1313 gl_set_texture_sampler(t
);
1314 t
->NextDirty
= NULL
;
1315 t
->Dirty
= GL_FALSE
;
1317 ctx
->Shared
->DirtyTexObjList
= NULL
;