1 /* $Id: texstate.c,v 1.5 1999/11/11 01:22:28 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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.
46 /* Needed for an Amiga compiler */
47 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
48 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
50 /* all other compilers */
51 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
52 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
58 /**********************************************************************/
59 /* Texture Environment */
60 /**********************************************************************/
64 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
66 GET_CURRENT_CONTEXT(ctx
);
67 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
69 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexEnv");
71 if (target
!=GL_TEXTURE_ENV
) {
72 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
76 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
77 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
78 gl_lookup_enum_by_nr(target
),
79 gl_lookup_enum_by_nr(pname
),
81 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
84 if (pname
==GL_TEXTURE_ENV_MODE
) {
85 GLenum mode
= (GLenum
) (GLint
) *param
;
91 /* A small optimization for drivers */
92 if (texUnit
->EnvMode
== mode
)
95 if (MESA_VERBOSE
& (VERBOSE_STATE
|VERBOSE_TEXTURE
))
96 fprintf(stderr
, "glTexEnv: old mode %s, new mode %s\n",
97 gl_lookup_enum_by_nr(texUnit
->EnvMode
),
98 gl_lookup_enum_by_nr(mode
));
100 texUnit
->EnvMode
= mode
;
101 ctx
->NewState
|= NEW_TEXTURE_ENV
;
104 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
108 else if (pname
==GL_TEXTURE_ENV_COLOR
) {
109 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
110 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
111 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
112 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
115 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
119 /* Tell device driver about the new texture environment */
120 if (ctx
->Driver
.TexEnv
) {
121 (*ctx
->Driver
.TexEnv
)( ctx
, pname
, param
);
127 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
129 _mesa_TexEnvfv( target
, pname
, ¶m
);
135 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
138 p
[0] = (GLfloat
) param
;
139 p
[1] = p
[2] = p
[3] = 0.0;
140 _mesa_TexEnvfv( target
, pname
, p
);
145 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
148 p
[0] = INT_TO_FLOAT( param
[0] );
149 p
[1] = INT_TO_FLOAT( param
[1] );
150 p
[2] = INT_TO_FLOAT( param
[2] );
151 p
[3] = INT_TO_FLOAT( param
[3] );
152 _mesa_TexEnvfv( target
, pname
, p
);
157 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
159 GET_CURRENT_CONTEXT(ctx
);
160 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
161 if (target
!=GL_TEXTURE_ENV
) {
162 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
166 case GL_TEXTURE_ENV_MODE
:
167 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
169 case GL_TEXTURE_ENV_COLOR
:
170 COPY_4FV( params
, texUnit
->EnvColor
);
173 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
179 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
181 GET_CURRENT_CONTEXT(ctx
);
182 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
183 if (target
!=GL_TEXTURE_ENV
) {
184 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
188 case GL_TEXTURE_ENV_MODE
:
189 *params
= (GLint
) texUnit
->EnvMode
;
191 case GL_TEXTURE_ENV_COLOR
:
192 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
193 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
194 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
195 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
198 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
205 /**********************************************************************/
206 /* Texture Parameters */
207 /**********************************************************************/
211 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
213 _mesa_TexParameterfv(target
, pname
, ¶m
);
218 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
220 GET_CURRENT_CONTEXT(ctx
);
221 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
222 GLenum eparam
= (GLenum
) (GLint
) params
[0];
223 struct gl_texture_object
*texObj
;
225 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
226 fprintf(stderr
, "texPARAM %s %s %d...\n",
227 gl_lookup_enum_by_nr(target
),
228 gl_lookup_enum_by_nr(pname
),
234 texObj
= texUnit
->CurrentD
[1];
237 texObj
= texUnit
->CurrentD
[2];
239 case GL_TEXTURE_3D_EXT
:
240 texObj
= texUnit
->CurrentD
[3];
243 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
248 case GL_TEXTURE_MIN_FILTER
:
249 /* A small optimization */
250 if (texObj
->MinFilter
== eparam
)
253 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
254 || eparam
==GL_NEAREST_MIPMAP_NEAREST
255 || eparam
==GL_LINEAR_MIPMAP_NEAREST
256 || eparam
==GL_NEAREST_MIPMAP_LINEAR
257 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
258 texObj
->MinFilter
= eparam
;
259 ctx
->NewState
|= NEW_TEXTURING
;
262 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
266 case GL_TEXTURE_MAG_FILTER
:
267 /* A small optimization */
268 if (texObj
->MagFilter
== eparam
)
271 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
272 texObj
->MagFilter
= eparam
;
273 ctx
->NewState
|= NEW_TEXTURING
;
276 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
280 case GL_TEXTURE_WRAP_S
:
281 if (texObj
->WrapS
== eparam
)
284 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
285 texObj
->WrapS
= eparam
;
286 ctx
->NewState
|= NEW_TEXTURING
;
289 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
293 case GL_TEXTURE_WRAP_T
:
294 if (texObj
->WrapT
== eparam
)
297 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
298 texObj
->WrapT
= eparam
;
299 ctx
->NewState
|= NEW_TEXTURING
;
302 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
306 case GL_TEXTURE_WRAP_R_EXT
:
307 if (texObj
->WrapR
== eparam
)
310 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
311 texObj
->WrapR
= eparam
;
312 ctx
->NewState
|= NEW_TEXTURING
;
315 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
318 case GL_TEXTURE_BORDER_COLOR
:
319 texObj
->BorderColor
[0] = (GLubyte
) CLAMP((GLint
)(params
[0]*255.0), 0, 255);
320 texObj
->BorderColor
[1] = (GLubyte
) CLAMP((GLint
)(params
[1]*255.0), 0, 255);
321 texObj
->BorderColor
[2] = (GLubyte
) CLAMP((GLint
)(params
[2]*255.0), 0, 255);
322 texObj
->BorderColor
[3] = (GLubyte
) CLAMP((GLint
)(params
[3]*255.0), 0, 255);
324 case GL_TEXTURE_MIN_LOD
:
325 texObj
->MinLod
= params
[0];
326 ctx
->NewState
|= NEW_TEXTURING
;
328 case GL_TEXTURE_MAX_LOD
:
329 texObj
->MaxLod
= params
[0];
330 ctx
->NewState
|= NEW_TEXTURING
;
332 case GL_TEXTURE_BASE_LEVEL
:
333 if (params
[0] < 0.0) {
334 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
337 texObj
->BaseLevel
= (GLint
) params
[0];
338 ctx
->NewState
|= NEW_TEXTURING
;
340 case GL_TEXTURE_MAX_LEVEL
:
341 if (params
[0] < 0.0) {
342 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
345 texObj
->MaxLevel
= (GLint
) params
[0];
346 ctx
->NewState
|= NEW_TEXTURING
;
348 case GL_TEXTURE_PRIORITY
:
349 /* (keithh@netcomuk.co.uk) */
350 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
353 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
357 gl_put_texobj_on_dirty_list( ctx
, texObj
);
359 if (ctx
->Driver
.TexParameter
) {
360 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
366 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
369 fparam
[0] = (GLfloat
) param
;
370 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
371 _mesa_TexParameterfv(target
, pname
, fparam
);
375 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
378 fparam
[0] = (GLfloat
) params
[0];
379 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
380 _mesa_TexParameterfv(target
, pname
, fparam
);
385 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
386 GLenum pname
, GLfloat
*params
)
389 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
390 *params
= (GLfloat
) iparam
;
396 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
397 GLenum pname
, GLint
*params
)
399 GET_CURRENT_CONTEXT(ctx
);
400 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
401 const struct gl_texture_image
*img
= NULL
;
404 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
405 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
411 img
= texUnit
->CurrentD
[1]->Image
[level
];
415 img
= texUnit
->CurrentD
[2]->Image
[level
];
419 img
= texUnit
->CurrentD
[3]->Image
[level
];
422 case GL_PROXY_TEXTURE_1D
:
423 img
= ctx
->Texture
.Proxy1D
->Image
[level
];
426 case GL_PROXY_TEXTURE_2D
:
427 img
= ctx
->Texture
.Proxy2D
->Image
[level
];
430 case GL_PROXY_TEXTURE_3D
:
431 img
= ctx
->Texture
.Proxy3D
->Image
[level
];
435 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
440 if (pname
== GL_TEXTURE_COMPONENTS
)
448 case GL_TEXTURE_WIDTH
:
449 *params
= img
->Width
;
451 case GL_TEXTURE_HEIGHT
:
452 if (dimensions
> 1) {
453 *params
= img
->Height
;
456 gl_error( ctx
, GL_INVALID_ENUM
,
457 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
460 case GL_TEXTURE_DEPTH
:
461 if (dimensions
> 2) {
462 *params
= img
->Depth
;
465 gl_error( ctx
, GL_INVALID_ENUM
,
466 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
469 case GL_TEXTURE_COMPONENTS
:
470 *params
= img
->IntFormat
;
472 case GL_TEXTURE_BORDER
:
473 *params
= img
->Border
;
475 case GL_TEXTURE_RED_SIZE
:
476 *params
= img
->RedBits
;
478 case GL_TEXTURE_GREEN_SIZE
:
479 *params
= img
->GreenBits
;
481 case GL_TEXTURE_BLUE_SIZE
:
482 *params
= img
->BlueBits
;
484 case GL_TEXTURE_ALPHA_SIZE
:
485 *params
= img
->AlphaBits
;
487 case GL_TEXTURE_INTENSITY_SIZE
:
488 *params
= img
->IntensityBits
;
490 case GL_TEXTURE_LUMINANCE_SIZE
:
491 *params
= img
->LuminanceBits
;
493 case GL_TEXTURE_INDEX_SIZE_EXT
:
494 *params
= img
->IndexBits
;
497 gl_error( ctx
, GL_INVALID_ENUM
,
498 "glGetTexLevelParameter[if]v(pname)" );
505 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
507 GET_CURRENT_CONTEXT(ctx
);
508 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
509 struct gl_texture_object
*obj
;
513 obj
= texUnit
->CurrentD
[1];
516 obj
= texUnit
->CurrentD
[2];
518 case GL_TEXTURE_3D_EXT
:
519 obj
= texUnit
->CurrentD
[3];
522 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
527 case GL_TEXTURE_MAG_FILTER
:
528 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
530 case GL_TEXTURE_MIN_FILTER
:
531 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
533 case GL_TEXTURE_WRAP_S
:
534 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
536 case GL_TEXTURE_WRAP_T
:
537 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
539 case GL_TEXTURE_WRAP_R_EXT
:
540 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
542 case GL_TEXTURE_BORDER_COLOR
:
543 params
[0] = obj
->BorderColor
[0] / 255.0F
;
544 params
[1] = obj
->BorderColor
[1] / 255.0F
;
545 params
[2] = obj
->BorderColor
[2] / 255.0F
;
546 params
[3] = obj
->BorderColor
[3] / 255.0F
;
548 case GL_TEXTURE_RESIDENT
:
549 *params
= ENUM_TO_FLOAT(GL_TRUE
);
551 case GL_TEXTURE_PRIORITY
:
552 *params
= obj
->Priority
;
554 case GL_TEXTURE_MIN_LOD
:
555 *params
= obj
->MinLod
;
557 case GL_TEXTURE_MAX_LOD
:
558 *params
= obj
->MaxLod
;
560 case GL_TEXTURE_BASE_LEVEL
:
561 *params
= (GLfloat
) obj
->BaseLevel
;
563 case GL_TEXTURE_MAX_LEVEL
:
564 *params
= (GLfloat
) obj
->MaxLevel
;
567 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
573 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
575 GET_CURRENT_CONTEXT(ctx
);
576 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
577 struct gl_texture_object
*obj
;
581 obj
= texUnit
->CurrentD
[1];
584 obj
= texUnit
->CurrentD
[2];
586 case GL_TEXTURE_3D_EXT
:
587 obj
= texUnit
->CurrentD
[3];
590 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
595 case GL_TEXTURE_MAG_FILTER
:
596 *params
= (GLint
) obj
->MagFilter
;
598 case GL_TEXTURE_MIN_FILTER
:
599 *params
= (GLint
) obj
->MinFilter
;
601 case GL_TEXTURE_WRAP_S
:
602 *params
= (GLint
) obj
->WrapS
;
604 case GL_TEXTURE_WRAP_T
:
605 *params
= (GLint
) obj
->WrapT
;
607 case GL_TEXTURE_WRAP_R_EXT
:
608 *params
= (GLint
) obj
->WrapR
;
610 case GL_TEXTURE_BORDER_COLOR
:
613 color
[0] = obj
->BorderColor
[0] / 255.0F
;
614 color
[1] = obj
->BorderColor
[1] / 255.0F
;
615 color
[2] = obj
->BorderColor
[2] / 255.0F
;
616 color
[3] = obj
->BorderColor
[3] / 255.0F
;
617 params
[0] = FLOAT_TO_INT( color
[0] );
618 params
[1] = FLOAT_TO_INT( color
[1] );
619 params
[2] = FLOAT_TO_INT( color
[2] );
620 params
[3] = FLOAT_TO_INT( color
[3] );
623 case GL_TEXTURE_RESIDENT
:
624 *params
= (GLint
) GL_TRUE
;
626 case GL_TEXTURE_PRIORITY
:
627 *params
= (GLint
) obj
->Priority
;
629 case GL_TEXTURE_MIN_LOD
:
630 *params
= (GLint
) obj
->MinLod
;
632 case GL_TEXTURE_MAX_LOD
:
633 *params
= (GLint
) obj
->MaxLod
;
635 case GL_TEXTURE_BASE_LEVEL
:
636 *params
= obj
->BaseLevel
;
638 case GL_TEXTURE_MAX_LEVEL
:
639 *params
= obj
->MaxLevel
;
642 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
649 /**********************************************************************/
650 /* Texture Coord Generation */
651 /**********************************************************************/
655 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
657 GET_CURRENT_CONTEXT(ctx
);
658 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
659 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
660 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
662 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
663 fprintf(stderr
, "texGEN %s %s %x...\n",
664 gl_lookup_enum_by_nr(coord
),
665 gl_lookup_enum_by_nr(pname
),
670 if (pname
==GL_TEXTURE_GEN_MODE
) {
671 GLenum mode
= (GLenum
) (GLint
) *params
;
673 case GL_OBJECT_LINEAR
:
674 texUnit
->GenModeS
= mode
;
675 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
678 texUnit
->GenModeS
= mode
;
679 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
681 case GL_REFLECTION_MAP_NV
:
682 texUnit
->GenModeS
= mode
;
683 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
685 case GL_NORMAL_MAP_NV
:
686 texUnit
->GenModeS
= mode
;
687 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
690 texUnit
->GenModeS
= mode
;
691 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
694 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
698 else if (pname
==GL_OBJECT_PLANE
) {
699 texUnit
->ObjectPlaneS
[0] = params
[0];
700 texUnit
->ObjectPlaneS
[1] = params
[1];
701 texUnit
->ObjectPlaneS
[2] = params
[2];
702 texUnit
->ObjectPlaneS
[3] = params
[3];
704 else if (pname
==GL_EYE_PLANE
) {
705 /* Transform plane equation by the inverse modelview matrix */
706 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
707 gl_matrix_analyze( &ctx
->ModelView
);
709 gl_transform_vector( texUnit
->EyePlaneS
, params
,
710 ctx
->ModelView
.inv
);
713 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
718 if (pname
==GL_TEXTURE_GEN_MODE
) {
719 GLenum mode
= (GLenum
) (GLint
) *params
;
721 case GL_OBJECT_LINEAR
:
722 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
723 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
726 texUnit
->GenModeT
= GL_EYE_LINEAR
;
727 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
729 case GL_REFLECTION_MAP_NV
:
730 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
731 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
733 case GL_NORMAL_MAP_NV
:
734 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
735 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
738 texUnit
->GenModeT
= GL_SPHERE_MAP
;
739 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
742 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
746 else if (pname
==GL_OBJECT_PLANE
) {
747 texUnit
->ObjectPlaneT
[0] = params
[0];
748 texUnit
->ObjectPlaneT
[1] = params
[1];
749 texUnit
->ObjectPlaneT
[2] = params
[2];
750 texUnit
->ObjectPlaneT
[3] = params
[3];
752 else if (pname
==GL_EYE_PLANE
) {
753 /* Transform plane equation by the inverse modelview matrix */
754 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
755 gl_matrix_analyze( &ctx
->ModelView
);
757 gl_transform_vector( texUnit
->EyePlaneT
, params
,
758 ctx
->ModelView
.inv
);
761 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
766 if (pname
==GL_TEXTURE_GEN_MODE
) {
767 GLenum mode
= (GLenum
) (GLint
) *params
;
769 case GL_OBJECT_LINEAR
:
770 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
771 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
773 case GL_REFLECTION_MAP_NV
:
774 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
775 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
777 case GL_NORMAL_MAP_NV
:
778 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
779 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
782 texUnit
->GenModeR
= GL_EYE_LINEAR
;
783 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
786 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
790 else if (pname
==GL_OBJECT_PLANE
) {
791 texUnit
->ObjectPlaneR
[0] = params
[0];
792 texUnit
->ObjectPlaneR
[1] = params
[1];
793 texUnit
->ObjectPlaneR
[2] = params
[2];
794 texUnit
->ObjectPlaneR
[3] = params
[3];
796 else if (pname
==GL_EYE_PLANE
) {
797 /* Transform plane equation by the inverse modelview matrix */
798 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
799 gl_matrix_analyze( &ctx
->ModelView
);
801 gl_transform_vector( texUnit
->EyePlaneR
, params
,
802 ctx
->ModelView
.inv
);
805 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
810 if (pname
==GL_TEXTURE_GEN_MODE
) {
811 GLenum mode
= (GLenum
) (GLint
) *params
;
813 case GL_OBJECT_LINEAR
:
814 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
815 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
818 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
819 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
822 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
826 else if (pname
==GL_OBJECT_PLANE
) {
827 texUnit
->ObjectPlaneQ
[0] = params
[0];
828 texUnit
->ObjectPlaneQ
[1] = params
[1];
829 texUnit
->ObjectPlaneQ
[2] = params
[2];
830 texUnit
->ObjectPlaneQ
[3] = params
[3];
832 else if (pname
==GL_EYE_PLANE
) {
833 /* Transform plane equation by the inverse modelview matrix */
834 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
835 gl_matrix_analyze( &ctx
->ModelView
);
837 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
838 ctx
->ModelView
.inv
);
841 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
846 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
850 ctx
->NewState
|= NEW_TEXTURING
;
855 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
862 _mesa_TexGenfv(coord
, pname
, p
);
867 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
869 GLfloat p
= (GLfloat
) param
;
870 _mesa_TexGenfv( coord
, pname
, &p
);
875 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
882 _mesa_TexGenfv( coord
, pname
, p
);
887 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
889 _mesa_TexGenfv(coord
, pname
, ¶m
);
894 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
896 _mesa_TexGeniv( coord
, pname
, ¶m
);
902 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
904 GET_CURRENT_CONTEXT(ctx
);
905 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
906 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
908 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
912 if (pname
==GL_TEXTURE_GEN_MODE
) {
913 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
915 else if (pname
==GL_OBJECT_PLANE
) {
916 COPY_4V( params
, texUnit
->ObjectPlaneS
);
918 else if (pname
==GL_EYE_PLANE
) {
919 COPY_4V( params
, texUnit
->EyePlaneS
);
922 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
927 if (pname
==GL_TEXTURE_GEN_MODE
) {
928 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
930 else if (pname
==GL_OBJECT_PLANE
) {
931 COPY_4V( params
, texUnit
->ObjectPlaneT
);
933 else if (pname
==GL_EYE_PLANE
) {
934 COPY_4V( params
, texUnit
->EyePlaneT
);
937 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
942 if (pname
==GL_TEXTURE_GEN_MODE
) {
943 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
945 else if (pname
==GL_OBJECT_PLANE
) {
946 COPY_4V( params
, texUnit
->ObjectPlaneR
);
948 else if (pname
==GL_EYE_PLANE
) {
949 COPY_4V( params
, texUnit
->EyePlaneR
);
952 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
957 if (pname
==GL_TEXTURE_GEN_MODE
) {
958 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
960 else if (pname
==GL_OBJECT_PLANE
) {
961 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
963 else if (pname
==GL_EYE_PLANE
) {
964 COPY_4V( params
, texUnit
->EyePlaneQ
);
967 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
972 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
980 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
982 GET_CURRENT_CONTEXT(ctx
);
983 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
984 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
986 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
990 if (pname
==GL_TEXTURE_GEN_MODE
) {
991 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
993 else if (pname
==GL_OBJECT_PLANE
) {
994 COPY_4V( params
, texUnit
->ObjectPlaneS
);
996 else if (pname
==GL_EYE_PLANE
) {
997 COPY_4V( params
, texUnit
->EyePlaneS
);
1000 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1005 if (pname
==GL_TEXTURE_GEN_MODE
) {
1006 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1008 else if (pname
==GL_OBJECT_PLANE
) {
1009 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1011 else if (pname
==GL_EYE_PLANE
) {
1012 COPY_4V( params
, texUnit
->EyePlaneT
);
1015 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1020 if (pname
==GL_TEXTURE_GEN_MODE
) {
1021 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1023 else if (pname
==GL_OBJECT_PLANE
) {
1024 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1026 else if (pname
==GL_EYE_PLANE
) {
1027 COPY_4V( params
, texUnit
->EyePlaneR
);
1030 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1035 if (pname
==GL_TEXTURE_GEN_MODE
) {
1036 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1038 else if (pname
==GL_OBJECT_PLANE
) {
1039 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1041 else if (pname
==GL_EYE_PLANE
) {
1042 COPY_4V( params
, texUnit
->EyePlaneQ
);
1045 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1050 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1058 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1060 GET_CURRENT_CONTEXT(ctx
);
1061 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1062 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1064 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
1068 if (pname
==GL_TEXTURE_GEN_MODE
) {
1069 params
[0] = texUnit
->GenModeS
;
1071 else if (pname
==GL_OBJECT_PLANE
) {
1072 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1073 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1074 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1075 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1077 else if (pname
==GL_EYE_PLANE
) {
1078 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1079 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1080 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1081 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1084 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1089 if (pname
==GL_TEXTURE_GEN_MODE
) {
1090 params
[0] = texUnit
->GenModeT
;
1092 else if (pname
==GL_OBJECT_PLANE
) {
1093 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1094 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1095 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1096 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1098 else if (pname
==GL_EYE_PLANE
) {
1099 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1100 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1101 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1102 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1105 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1110 if (pname
==GL_TEXTURE_GEN_MODE
) {
1111 params
[0] = texUnit
->GenModeR
;
1113 else if (pname
==GL_OBJECT_PLANE
) {
1114 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1115 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1116 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1117 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1119 else if (pname
==GL_EYE_PLANE
) {
1120 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1121 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1122 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1123 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1126 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1131 if (pname
==GL_TEXTURE_GEN_MODE
) {
1132 params
[0] = texUnit
->GenModeQ
;
1134 else if (pname
==GL_OBJECT_PLANE
) {
1135 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1136 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1137 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1138 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1140 else if (pname
==GL_EYE_PLANE
) {
1141 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1142 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1143 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1144 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1147 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1152 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1158 /* GL_ARB_multitexture */
1160 _mesa_ActiveTextureARB( GLenum target
)
1162 GET_CURRENT_CONTEXT(ctx
);
1163 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1165 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1167 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1168 fprintf(stderr
, "glActiveTexture %s\n",
1169 gl_lookup_enum_by_nr(target
));
1171 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1172 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1173 ctx
->Texture
.CurrentUnit
= texUnit
;
1174 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1175 if (ctx
->Driver
.ActiveTexture
) {
1176 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1180 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1185 /* GL_ARB_multitexture */
1187 _mesa_ClientActiveTextureARB( GLenum target
)
1189 GET_CURRENT_CONTEXT(ctx
);
1190 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1192 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glClientActiveTextureARB" );
1194 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1195 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1196 ctx
->Array
.ActiveTexture
= texUnit
;
1199 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1206 * Put the given texture object into the list of dirty texture objects.
1207 * When a texture object is dirty we have to reexamine it for completeness
1208 * and perhaps choose a different texture sampling function.
1210 void gl_put_texobj_on_dirty_list( GLcontext
*ctx
, struct gl_texture_object
*t
)
1214 /* Only insert if not already in the dirty list.
1215 * The Dirty flag is only set iff the texture object is in the dirty list.
1218 ASSERT(t
->NextDirty
== NULL
);
1220 t
->NextDirty
= ctx
->Shared
->DirtyTexObjList
;
1221 ctx
->Shared
->DirtyTexObjList
= t
;
1225 /* make sure t is in the list */
1226 struct gl_texture_object
*obj
= ctx
->Shared
->DirtyTexObjList
;
1231 obj
= obj
->NextDirty
;
1233 gl_problem(ctx
, "Error in gl_put_texobj_on_dirty_list");
1240 * Remove a texture object from the dirty texture list.
1242 void gl_remove_texobj_from_dirty_list( struct gl_shared_state
*shared
,
1243 struct gl_texture_object
*tObj
)
1245 struct gl_texture_object
*t
, *prev
= NULL
;
1248 for (t
= shared
->DirtyTexObjList
; t
; t
= t
->NextDirty
) {
1251 prev
->NextDirty
= t
->NextDirty
;
1254 shared
->DirtyTexObjList
= t
->NextDirty
;
1264 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1265 * ctx->NewState is unit.
1267 void gl_update_dirty_texobjs( GLcontext
*ctx
)
1269 struct gl_texture_object
*t
, *next
;
1270 for (t
= ctx
->Shared
->DirtyTexObjList
; t
; t
= next
) {
1271 next
= t
->NextDirty
;
1272 gl_test_texture_object_completeness(ctx
, t
);
1273 gl_set_texture_sampler(t
);
1274 t
->NextDirty
= NULL
;
1275 t
->Dirty
= GL_FALSE
;
1277 ctx
->Shared
->DirtyTexObjList
= NULL
;