1 /* $Id: texstate.c,v 1.6 1999/11/12 02:07:56 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.
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
) {
73 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
77 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
78 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
79 gl_lookup_enum_by_nr(target
),
80 gl_lookup_enum_by_nr(pname
),
82 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
85 if (pname
==GL_TEXTURE_ENV_MODE
) {
86 GLenum mode
= (GLenum
) (GLint
) *param
;
89 if (!gl_extension_is_enabled(ctx
, "GL_EXT_texture_env_add")) {
90 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
98 /* A small optimization for drivers */
99 if (texUnit
->EnvMode
== mode
)
102 if (MESA_VERBOSE
& (VERBOSE_STATE
|VERBOSE_TEXTURE
))
103 fprintf(stderr
, "glTexEnv: old mode %s, new mode %s\n",
104 gl_lookup_enum_by_nr(texUnit
->EnvMode
),
105 gl_lookup_enum_by_nr(mode
));
107 texUnit
->EnvMode
= mode
;
108 ctx
->NewState
|= NEW_TEXTURE_ENV
;
111 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
115 else if (pname
==GL_TEXTURE_ENV_COLOR
) {
116 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
117 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
118 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
119 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
122 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
126 /* Tell device driver about the new texture environment */
127 if (ctx
->Driver
.TexEnv
) {
128 (*ctx
->Driver
.TexEnv
)( ctx
, pname
, param
);
134 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
136 _mesa_TexEnvfv( target
, pname
, ¶m
);
142 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
145 p
[0] = (GLfloat
) param
;
146 p
[1] = p
[2] = p
[3] = 0.0;
147 _mesa_TexEnvfv( target
, pname
, p
);
152 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
155 p
[0] = INT_TO_FLOAT( param
[0] );
156 p
[1] = INT_TO_FLOAT( param
[1] );
157 p
[2] = INT_TO_FLOAT( param
[2] );
158 p
[3] = INT_TO_FLOAT( param
[3] );
159 _mesa_TexEnvfv( target
, pname
, p
);
164 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
166 GET_CURRENT_CONTEXT(ctx
);
167 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
168 if (target
!=GL_TEXTURE_ENV
) {
169 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
173 case GL_TEXTURE_ENV_MODE
:
174 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
176 case GL_TEXTURE_ENV_COLOR
:
177 COPY_4FV( params
, texUnit
->EnvColor
);
180 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
186 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
188 GET_CURRENT_CONTEXT(ctx
);
189 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
190 if (target
!=GL_TEXTURE_ENV
) {
191 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
195 case GL_TEXTURE_ENV_MODE
:
196 *params
= (GLint
) texUnit
->EnvMode
;
198 case GL_TEXTURE_ENV_COLOR
:
199 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
200 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
201 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
202 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
205 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
212 /**********************************************************************/
213 /* Texture Parameters */
214 /**********************************************************************/
218 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
220 _mesa_TexParameterfv(target
, pname
, ¶m
);
225 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
227 GET_CURRENT_CONTEXT(ctx
);
228 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
229 GLenum eparam
= (GLenum
) (GLint
) params
[0];
230 struct gl_texture_object
*texObj
;
232 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
233 fprintf(stderr
, "texPARAM %s %s %d...\n",
234 gl_lookup_enum_by_nr(target
),
235 gl_lookup_enum_by_nr(pname
),
241 texObj
= texUnit
->CurrentD
[1];
244 texObj
= texUnit
->CurrentD
[2];
246 case GL_TEXTURE_3D_EXT
:
247 texObj
= texUnit
->CurrentD
[3];
250 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
255 case GL_TEXTURE_MIN_FILTER
:
256 /* A small optimization */
257 if (texObj
->MinFilter
== eparam
)
260 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
261 || eparam
==GL_NEAREST_MIPMAP_NEAREST
262 || eparam
==GL_LINEAR_MIPMAP_NEAREST
263 || eparam
==GL_NEAREST_MIPMAP_LINEAR
264 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
265 texObj
->MinFilter
= eparam
;
266 ctx
->NewState
|= NEW_TEXTURING
;
269 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
273 case GL_TEXTURE_MAG_FILTER
:
274 /* A small optimization */
275 if (texObj
->MagFilter
== eparam
)
278 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
279 texObj
->MagFilter
= eparam
;
280 ctx
->NewState
|= NEW_TEXTURING
;
283 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
287 case GL_TEXTURE_WRAP_S
:
288 if (texObj
->WrapS
== eparam
)
291 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
292 texObj
->WrapS
= eparam
;
293 ctx
->NewState
|= NEW_TEXTURING
;
296 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
300 case GL_TEXTURE_WRAP_T
:
301 if (texObj
->WrapT
== eparam
)
304 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
305 texObj
->WrapT
= eparam
;
306 ctx
->NewState
|= NEW_TEXTURING
;
309 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
313 case GL_TEXTURE_WRAP_R_EXT
:
314 if (texObj
->WrapR
== eparam
)
317 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
318 texObj
->WrapR
= eparam
;
319 ctx
->NewState
|= NEW_TEXTURING
;
322 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
325 case GL_TEXTURE_BORDER_COLOR
:
326 texObj
->BorderColor
[0] = (GLubyte
) CLAMP((GLint
)(params
[0]*255.0), 0, 255);
327 texObj
->BorderColor
[1] = (GLubyte
) CLAMP((GLint
)(params
[1]*255.0), 0, 255);
328 texObj
->BorderColor
[2] = (GLubyte
) CLAMP((GLint
)(params
[2]*255.0), 0, 255);
329 texObj
->BorderColor
[3] = (GLubyte
) CLAMP((GLint
)(params
[3]*255.0), 0, 255);
331 case GL_TEXTURE_MIN_LOD
:
332 texObj
->MinLod
= params
[0];
333 ctx
->NewState
|= NEW_TEXTURING
;
335 case GL_TEXTURE_MAX_LOD
:
336 texObj
->MaxLod
= params
[0];
337 ctx
->NewState
|= NEW_TEXTURING
;
339 case GL_TEXTURE_BASE_LEVEL
:
340 if (params
[0] < 0.0) {
341 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
344 texObj
->BaseLevel
= (GLint
) params
[0];
345 ctx
->NewState
|= NEW_TEXTURING
;
347 case GL_TEXTURE_MAX_LEVEL
:
348 if (params
[0] < 0.0) {
349 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
352 texObj
->MaxLevel
= (GLint
) params
[0];
353 ctx
->NewState
|= NEW_TEXTURING
;
355 case GL_TEXTURE_PRIORITY
:
356 /* (keithh@netcomuk.co.uk) */
357 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
360 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
364 gl_put_texobj_on_dirty_list( ctx
, texObj
);
366 if (ctx
->Driver
.TexParameter
) {
367 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
373 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
376 fparam
[0] = (GLfloat
) param
;
377 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
378 _mesa_TexParameterfv(target
, pname
, fparam
);
382 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
385 fparam
[0] = (GLfloat
) params
[0];
386 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
387 _mesa_TexParameterfv(target
, pname
, fparam
);
392 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
393 GLenum pname
, GLfloat
*params
)
396 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
397 *params
= (GLfloat
) iparam
;
403 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
404 GLenum pname
, GLint
*params
)
406 GET_CURRENT_CONTEXT(ctx
);
407 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
408 const struct gl_texture_image
*img
= NULL
;
411 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
412 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
418 img
= texUnit
->CurrentD
[1]->Image
[level
];
422 img
= texUnit
->CurrentD
[2]->Image
[level
];
426 img
= texUnit
->CurrentD
[3]->Image
[level
];
429 case GL_PROXY_TEXTURE_1D
:
430 img
= ctx
->Texture
.Proxy1D
->Image
[level
];
433 case GL_PROXY_TEXTURE_2D
:
434 img
= ctx
->Texture
.Proxy2D
->Image
[level
];
437 case GL_PROXY_TEXTURE_3D
:
438 img
= ctx
->Texture
.Proxy3D
->Image
[level
];
442 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
447 if (pname
== GL_TEXTURE_COMPONENTS
)
455 case GL_TEXTURE_WIDTH
:
456 *params
= img
->Width
;
458 case GL_TEXTURE_HEIGHT
:
459 if (dimensions
> 1) {
460 *params
= img
->Height
;
463 gl_error( ctx
, GL_INVALID_ENUM
,
464 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
467 case GL_TEXTURE_DEPTH
:
468 if (dimensions
> 2) {
469 *params
= img
->Depth
;
472 gl_error( ctx
, GL_INVALID_ENUM
,
473 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
476 case GL_TEXTURE_COMPONENTS
:
477 *params
= img
->IntFormat
;
479 case GL_TEXTURE_BORDER
:
480 *params
= img
->Border
;
482 case GL_TEXTURE_RED_SIZE
:
483 *params
= img
->RedBits
;
485 case GL_TEXTURE_GREEN_SIZE
:
486 *params
= img
->GreenBits
;
488 case GL_TEXTURE_BLUE_SIZE
:
489 *params
= img
->BlueBits
;
491 case GL_TEXTURE_ALPHA_SIZE
:
492 *params
= img
->AlphaBits
;
494 case GL_TEXTURE_INTENSITY_SIZE
:
495 *params
= img
->IntensityBits
;
497 case GL_TEXTURE_LUMINANCE_SIZE
:
498 *params
= img
->LuminanceBits
;
500 case GL_TEXTURE_INDEX_SIZE_EXT
:
501 *params
= img
->IndexBits
;
504 gl_error( ctx
, GL_INVALID_ENUM
,
505 "glGetTexLevelParameter[if]v(pname)" );
512 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
514 GET_CURRENT_CONTEXT(ctx
);
515 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
516 struct gl_texture_object
*obj
;
520 obj
= texUnit
->CurrentD
[1];
523 obj
= texUnit
->CurrentD
[2];
525 case GL_TEXTURE_3D_EXT
:
526 obj
= texUnit
->CurrentD
[3];
529 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
534 case GL_TEXTURE_MAG_FILTER
:
535 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
537 case GL_TEXTURE_MIN_FILTER
:
538 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
540 case GL_TEXTURE_WRAP_S
:
541 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
543 case GL_TEXTURE_WRAP_T
:
544 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
546 case GL_TEXTURE_WRAP_R_EXT
:
547 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
549 case GL_TEXTURE_BORDER_COLOR
:
550 params
[0] = obj
->BorderColor
[0] / 255.0F
;
551 params
[1] = obj
->BorderColor
[1] / 255.0F
;
552 params
[2] = obj
->BorderColor
[2] / 255.0F
;
553 params
[3] = obj
->BorderColor
[3] / 255.0F
;
555 case GL_TEXTURE_RESIDENT
:
556 *params
= ENUM_TO_FLOAT(GL_TRUE
);
558 case GL_TEXTURE_PRIORITY
:
559 *params
= obj
->Priority
;
561 case GL_TEXTURE_MIN_LOD
:
562 *params
= obj
->MinLod
;
564 case GL_TEXTURE_MAX_LOD
:
565 *params
= obj
->MaxLod
;
567 case GL_TEXTURE_BASE_LEVEL
:
568 *params
= (GLfloat
) obj
->BaseLevel
;
570 case GL_TEXTURE_MAX_LEVEL
:
571 *params
= (GLfloat
) obj
->MaxLevel
;
574 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
580 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
582 GET_CURRENT_CONTEXT(ctx
);
583 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
584 struct gl_texture_object
*obj
;
588 obj
= texUnit
->CurrentD
[1];
591 obj
= texUnit
->CurrentD
[2];
593 case GL_TEXTURE_3D_EXT
:
594 obj
= texUnit
->CurrentD
[3];
597 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
602 case GL_TEXTURE_MAG_FILTER
:
603 *params
= (GLint
) obj
->MagFilter
;
605 case GL_TEXTURE_MIN_FILTER
:
606 *params
= (GLint
) obj
->MinFilter
;
608 case GL_TEXTURE_WRAP_S
:
609 *params
= (GLint
) obj
->WrapS
;
611 case GL_TEXTURE_WRAP_T
:
612 *params
= (GLint
) obj
->WrapT
;
614 case GL_TEXTURE_WRAP_R_EXT
:
615 *params
= (GLint
) obj
->WrapR
;
617 case GL_TEXTURE_BORDER_COLOR
:
620 color
[0] = obj
->BorderColor
[0] / 255.0F
;
621 color
[1] = obj
->BorderColor
[1] / 255.0F
;
622 color
[2] = obj
->BorderColor
[2] / 255.0F
;
623 color
[3] = obj
->BorderColor
[3] / 255.0F
;
624 params
[0] = FLOAT_TO_INT( color
[0] );
625 params
[1] = FLOAT_TO_INT( color
[1] );
626 params
[2] = FLOAT_TO_INT( color
[2] );
627 params
[3] = FLOAT_TO_INT( color
[3] );
630 case GL_TEXTURE_RESIDENT
:
631 *params
= (GLint
) GL_TRUE
;
633 case GL_TEXTURE_PRIORITY
:
634 *params
= (GLint
) obj
->Priority
;
636 case GL_TEXTURE_MIN_LOD
:
637 *params
= (GLint
) obj
->MinLod
;
639 case GL_TEXTURE_MAX_LOD
:
640 *params
= (GLint
) obj
->MaxLod
;
642 case GL_TEXTURE_BASE_LEVEL
:
643 *params
= obj
->BaseLevel
;
645 case GL_TEXTURE_MAX_LEVEL
:
646 *params
= obj
->MaxLevel
;
649 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
656 /**********************************************************************/
657 /* Texture Coord Generation */
658 /**********************************************************************/
662 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
664 GET_CURRENT_CONTEXT(ctx
);
665 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
666 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
667 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
669 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
670 fprintf(stderr
, "texGEN %s %s %x...\n",
671 gl_lookup_enum_by_nr(coord
),
672 gl_lookup_enum_by_nr(pname
),
677 if (pname
==GL_TEXTURE_GEN_MODE
) {
678 GLenum mode
= (GLenum
) (GLint
) *params
;
680 case GL_OBJECT_LINEAR
:
681 texUnit
->GenModeS
= mode
;
682 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
685 texUnit
->GenModeS
= mode
;
686 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
688 case GL_REFLECTION_MAP_NV
:
689 texUnit
->GenModeS
= mode
;
690 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
692 case GL_NORMAL_MAP_NV
:
693 texUnit
->GenModeS
= mode
;
694 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
697 texUnit
->GenModeS
= mode
;
698 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
701 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
705 else if (pname
==GL_OBJECT_PLANE
) {
706 texUnit
->ObjectPlaneS
[0] = params
[0];
707 texUnit
->ObjectPlaneS
[1] = params
[1];
708 texUnit
->ObjectPlaneS
[2] = params
[2];
709 texUnit
->ObjectPlaneS
[3] = params
[3];
711 else if (pname
==GL_EYE_PLANE
) {
712 /* Transform plane equation by the inverse modelview matrix */
713 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
714 gl_matrix_analyze( &ctx
->ModelView
);
716 gl_transform_vector( texUnit
->EyePlaneS
, params
,
717 ctx
->ModelView
.inv
);
720 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
725 if (pname
==GL_TEXTURE_GEN_MODE
) {
726 GLenum mode
= (GLenum
) (GLint
) *params
;
728 case GL_OBJECT_LINEAR
:
729 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
730 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
733 texUnit
->GenModeT
= GL_EYE_LINEAR
;
734 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
736 case GL_REFLECTION_MAP_NV
:
737 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
738 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
740 case GL_NORMAL_MAP_NV
:
741 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
742 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
745 texUnit
->GenModeT
= GL_SPHERE_MAP
;
746 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
749 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
753 else if (pname
==GL_OBJECT_PLANE
) {
754 texUnit
->ObjectPlaneT
[0] = params
[0];
755 texUnit
->ObjectPlaneT
[1] = params
[1];
756 texUnit
->ObjectPlaneT
[2] = params
[2];
757 texUnit
->ObjectPlaneT
[3] = params
[3];
759 else if (pname
==GL_EYE_PLANE
) {
760 /* Transform plane equation by the inverse modelview matrix */
761 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
762 gl_matrix_analyze( &ctx
->ModelView
);
764 gl_transform_vector( texUnit
->EyePlaneT
, params
,
765 ctx
->ModelView
.inv
);
768 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
773 if (pname
==GL_TEXTURE_GEN_MODE
) {
774 GLenum mode
= (GLenum
) (GLint
) *params
;
776 case GL_OBJECT_LINEAR
:
777 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
778 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
780 case GL_REFLECTION_MAP_NV
:
781 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
782 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
784 case GL_NORMAL_MAP_NV
:
785 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
786 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
789 texUnit
->GenModeR
= GL_EYE_LINEAR
;
790 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
793 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
797 else if (pname
==GL_OBJECT_PLANE
) {
798 texUnit
->ObjectPlaneR
[0] = params
[0];
799 texUnit
->ObjectPlaneR
[1] = params
[1];
800 texUnit
->ObjectPlaneR
[2] = params
[2];
801 texUnit
->ObjectPlaneR
[3] = params
[3];
803 else if (pname
==GL_EYE_PLANE
) {
804 /* Transform plane equation by the inverse modelview matrix */
805 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
806 gl_matrix_analyze( &ctx
->ModelView
);
808 gl_transform_vector( texUnit
->EyePlaneR
, params
,
809 ctx
->ModelView
.inv
);
812 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
817 if (pname
==GL_TEXTURE_GEN_MODE
) {
818 GLenum mode
= (GLenum
) (GLint
) *params
;
820 case GL_OBJECT_LINEAR
:
821 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
822 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
825 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
826 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
829 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
833 else if (pname
==GL_OBJECT_PLANE
) {
834 texUnit
->ObjectPlaneQ
[0] = params
[0];
835 texUnit
->ObjectPlaneQ
[1] = params
[1];
836 texUnit
->ObjectPlaneQ
[2] = params
[2];
837 texUnit
->ObjectPlaneQ
[3] = params
[3];
839 else if (pname
==GL_EYE_PLANE
) {
840 /* Transform plane equation by the inverse modelview matrix */
841 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
842 gl_matrix_analyze( &ctx
->ModelView
);
844 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
845 ctx
->ModelView
.inv
);
848 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
853 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
857 ctx
->NewState
|= NEW_TEXTURING
;
862 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
869 _mesa_TexGenfv(coord
, pname
, p
);
874 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
876 GLfloat p
= (GLfloat
) param
;
877 _mesa_TexGenfv( coord
, pname
, &p
);
882 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
889 _mesa_TexGenfv( coord
, pname
, p
);
894 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
896 _mesa_TexGenfv(coord
, pname
, ¶m
);
901 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
903 _mesa_TexGeniv( coord
, pname
, ¶m
);
909 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
911 GET_CURRENT_CONTEXT(ctx
);
912 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
913 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
915 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
919 if (pname
==GL_TEXTURE_GEN_MODE
) {
920 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
922 else if (pname
==GL_OBJECT_PLANE
) {
923 COPY_4V( params
, texUnit
->ObjectPlaneS
);
925 else if (pname
==GL_EYE_PLANE
) {
926 COPY_4V( params
, texUnit
->EyePlaneS
);
929 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
934 if (pname
==GL_TEXTURE_GEN_MODE
) {
935 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
937 else if (pname
==GL_OBJECT_PLANE
) {
938 COPY_4V( params
, texUnit
->ObjectPlaneT
);
940 else if (pname
==GL_EYE_PLANE
) {
941 COPY_4V( params
, texUnit
->EyePlaneT
);
944 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
949 if (pname
==GL_TEXTURE_GEN_MODE
) {
950 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
952 else if (pname
==GL_OBJECT_PLANE
) {
953 COPY_4V( params
, texUnit
->ObjectPlaneR
);
955 else if (pname
==GL_EYE_PLANE
) {
956 COPY_4V( params
, texUnit
->EyePlaneR
);
959 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
964 if (pname
==GL_TEXTURE_GEN_MODE
) {
965 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
967 else if (pname
==GL_OBJECT_PLANE
) {
968 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
970 else if (pname
==GL_EYE_PLANE
) {
971 COPY_4V( params
, texUnit
->EyePlaneQ
);
974 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
979 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
987 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
989 GET_CURRENT_CONTEXT(ctx
);
990 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
991 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
993 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
997 if (pname
==GL_TEXTURE_GEN_MODE
) {
998 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
1000 else if (pname
==GL_OBJECT_PLANE
) {
1001 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1003 else if (pname
==GL_EYE_PLANE
) {
1004 COPY_4V( params
, texUnit
->EyePlaneS
);
1007 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1012 if (pname
==GL_TEXTURE_GEN_MODE
) {
1013 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1015 else if (pname
==GL_OBJECT_PLANE
) {
1016 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1018 else if (pname
==GL_EYE_PLANE
) {
1019 COPY_4V( params
, texUnit
->EyePlaneT
);
1022 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1027 if (pname
==GL_TEXTURE_GEN_MODE
) {
1028 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1030 else if (pname
==GL_OBJECT_PLANE
) {
1031 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1033 else if (pname
==GL_EYE_PLANE
) {
1034 COPY_4V( params
, texUnit
->EyePlaneR
);
1037 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1042 if (pname
==GL_TEXTURE_GEN_MODE
) {
1043 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1045 else if (pname
==GL_OBJECT_PLANE
) {
1046 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1048 else if (pname
==GL_EYE_PLANE
) {
1049 COPY_4V( params
, texUnit
->EyePlaneQ
);
1052 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1057 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1065 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1067 GET_CURRENT_CONTEXT(ctx
);
1068 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1069 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1071 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
1075 if (pname
==GL_TEXTURE_GEN_MODE
) {
1076 params
[0] = texUnit
->GenModeS
;
1078 else if (pname
==GL_OBJECT_PLANE
) {
1079 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1080 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1081 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1082 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1084 else if (pname
==GL_EYE_PLANE
) {
1085 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1086 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1087 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1088 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1091 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1096 if (pname
==GL_TEXTURE_GEN_MODE
) {
1097 params
[0] = texUnit
->GenModeT
;
1099 else if (pname
==GL_OBJECT_PLANE
) {
1100 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1101 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1102 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1103 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1105 else if (pname
==GL_EYE_PLANE
) {
1106 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1107 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1108 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1109 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1112 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1117 if (pname
==GL_TEXTURE_GEN_MODE
) {
1118 params
[0] = texUnit
->GenModeR
;
1120 else if (pname
==GL_OBJECT_PLANE
) {
1121 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1122 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1123 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1124 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1126 else if (pname
==GL_EYE_PLANE
) {
1127 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1128 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1129 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1130 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1133 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1138 if (pname
==GL_TEXTURE_GEN_MODE
) {
1139 params
[0] = texUnit
->GenModeQ
;
1141 else if (pname
==GL_OBJECT_PLANE
) {
1142 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1143 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1144 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1145 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1147 else if (pname
==GL_EYE_PLANE
) {
1148 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1149 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1150 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1151 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1154 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1159 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1165 /* GL_ARB_multitexture */
1167 _mesa_ActiveTextureARB( GLenum target
)
1169 GET_CURRENT_CONTEXT(ctx
);
1170 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1172 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1174 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1175 fprintf(stderr
, "glActiveTexture %s\n",
1176 gl_lookup_enum_by_nr(target
));
1178 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1179 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1180 ctx
->Texture
.CurrentUnit
= texUnit
;
1181 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1182 if (ctx
->Driver
.ActiveTexture
) {
1183 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1187 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1192 /* GL_ARB_multitexture */
1194 _mesa_ClientActiveTextureARB( GLenum target
)
1196 GET_CURRENT_CONTEXT(ctx
);
1197 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1199 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glClientActiveTextureARB" );
1201 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1202 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1203 ctx
->Array
.ActiveTexture
= texUnit
;
1206 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1213 * Put the given texture object into the list of dirty texture objects.
1214 * When a texture object is dirty we have to reexamine it for completeness
1215 * and perhaps choose a different texture sampling function.
1217 void gl_put_texobj_on_dirty_list( GLcontext
*ctx
, struct gl_texture_object
*t
)
1221 /* Only insert if not already in the dirty list.
1222 * The Dirty flag is only set iff the texture object is in the dirty list.
1225 ASSERT(t
->NextDirty
== NULL
);
1227 t
->NextDirty
= ctx
->Shared
->DirtyTexObjList
;
1228 ctx
->Shared
->DirtyTexObjList
= t
;
1232 /* make sure t is in the list */
1233 struct gl_texture_object
*obj
= ctx
->Shared
->DirtyTexObjList
;
1238 obj
= obj
->NextDirty
;
1240 gl_problem(ctx
, "Error in gl_put_texobj_on_dirty_list");
1247 * Remove a texture object from the dirty texture list.
1249 void gl_remove_texobj_from_dirty_list( struct gl_shared_state
*shared
,
1250 struct gl_texture_object
*tObj
)
1252 struct gl_texture_object
*t
, *prev
= NULL
;
1255 for (t
= shared
->DirtyTexObjList
; t
; t
= t
->NextDirty
) {
1258 prev
->NextDirty
= t
->NextDirty
;
1261 shared
->DirtyTexObjList
= t
->NextDirty
;
1271 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1272 * ctx->NewState is unit.
1274 void gl_update_dirty_texobjs( GLcontext
*ctx
)
1276 struct gl_texture_object
*t
, *next
;
1277 for (t
= ctx
->Shared
->DirtyTexObjList
; t
; t
= next
) {
1278 next
= t
->NextDirty
;
1279 gl_test_texture_object_completeness(ctx
, t
);
1280 gl_set_texture_sampler(t
);
1281 t
->NextDirty
= NULL
;
1282 t
->Dirty
= GL_FALSE
;
1284 ctx
->Shared
->DirtyTexObjList
= NULL
;