1 /* $Id: texstate.c,v 1.12 2000/05/23 17:14:49 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"
48 /* Needed for an Amiga compiler */
49 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
50 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
52 /* all other compilers */
53 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
54 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
60 /**********************************************************************/
61 /* Texture Environment */
62 /**********************************************************************/
66 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
68 GET_CURRENT_CONTEXT(ctx
);
69 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
71 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexEnv");
73 if (target
==GL_TEXTURE_ENV
) {
75 if (pname
==GL_TEXTURE_ENV_MODE
) {
76 GLenum mode
= (GLenum
) (GLint
) *param
;
79 if (!ctx
->Extensions
.HaveTextureEnvAdd
) {
80 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
88 /* A small optimization for drivers */
89 if (texUnit
->EnvMode
== mode
)
92 if (MESA_VERBOSE
& (VERBOSE_STATE
|VERBOSE_TEXTURE
))
93 fprintf(stderr
, "glTexEnv: old mode %s, new mode %s\n",
94 gl_lookup_enum_by_nr(texUnit
->EnvMode
),
95 gl_lookup_enum_by_nr(mode
));
97 texUnit
->EnvMode
= mode
;
98 ctx
->NewState
|= NEW_TEXTURE_ENV
;
101 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
105 else if (pname
==GL_TEXTURE_ENV_COLOR
) {
106 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
107 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
108 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
109 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
112 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
117 else if (target
==GL_TEXTURE_FILTER_CONTROL_EXT
) {
119 if (!ctx
->Extensions
.HaveTextureLodBias
) {
120 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
124 if (pname
==GL_TEXTURE_LOD_BIAS_EXT
) {
125 texUnit
->LodBias
= param
[0];
128 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
134 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
138 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
139 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
140 gl_lookup_enum_by_nr(target
),
141 gl_lookup_enum_by_nr(pname
),
143 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
145 /* Tell device driver about the new texture environment */
146 if (ctx
->Driver
.TexEnv
) {
147 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
154 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
156 _mesa_TexEnvfv( target
, pname
, ¶m
);
162 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
165 p
[0] = (GLfloat
) param
;
166 p
[1] = p
[2] = p
[3] = 0.0;
167 _mesa_TexEnvfv( target
, pname
, p
);
172 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
175 p
[0] = INT_TO_FLOAT( param
[0] );
176 p
[1] = INT_TO_FLOAT( param
[1] );
177 p
[2] = INT_TO_FLOAT( param
[2] );
178 p
[3] = INT_TO_FLOAT( param
[3] );
179 _mesa_TexEnvfv( target
, pname
, p
);
184 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
186 GET_CURRENT_CONTEXT(ctx
);
187 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
189 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexEnvfv");
191 if (target
!=GL_TEXTURE_ENV
) {
192 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
196 case GL_TEXTURE_ENV_MODE
:
197 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
199 case GL_TEXTURE_ENV_COLOR
:
200 COPY_4FV( params
, texUnit
->EnvColor
);
203 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
209 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
211 GET_CURRENT_CONTEXT(ctx
);
212 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
214 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexEnviv");
216 if (target
!=GL_TEXTURE_ENV
) {
217 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
221 case GL_TEXTURE_ENV_MODE
:
222 *params
= (GLint
) texUnit
->EnvMode
;
224 case GL_TEXTURE_ENV_COLOR
:
225 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
226 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
227 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
228 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
231 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
238 /**********************************************************************/
239 /* Texture Parameters */
240 /**********************************************************************/
244 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
246 _mesa_TexParameterfv(target
, pname
, ¶m
);
251 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
253 GET_CURRENT_CONTEXT(ctx
);
254 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
255 GLenum eparam
= (GLenum
) (GLint
) params
[0];
256 struct gl_texture_object
*texObj
;
258 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexParameterfv");
260 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
261 fprintf(stderr
, "texPARAM %s %s %d...\n",
262 gl_lookup_enum_by_nr(target
),
263 gl_lookup_enum_by_nr(pname
),
269 texObj
= texUnit
->CurrentD
[1];
272 texObj
= texUnit
->CurrentD
[2];
274 case GL_TEXTURE_3D_EXT
:
275 texObj
= texUnit
->CurrentD
[3];
277 case GL_TEXTURE_CUBE_MAP_ARB
:
278 if (ctx
->Extensions
.HaveTextureCubeMap
) {
279 texObj
= texUnit
->CurrentCubeMap
;
284 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
289 case GL_TEXTURE_MIN_FILTER
:
290 /* A small optimization */
291 if (texObj
->MinFilter
== eparam
)
294 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
295 || eparam
==GL_NEAREST_MIPMAP_NEAREST
296 || eparam
==GL_LINEAR_MIPMAP_NEAREST
297 || eparam
==GL_NEAREST_MIPMAP_LINEAR
298 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
299 texObj
->MinFilter
= eparam
;
300 ctx
->NewState
|= NEW_TEXTURING
;
303 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
307 case GL_TEXTURE_MAG_FILTER
:
308 /* A small optimization */
309 if (texObj
->MagFilter
== eparam
)
312 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
313 texObj
->MagFilter
= eparam
;
314 ctx
->NewState
|= NEW_TEXTURING
;
317 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
321 case GL_TEXTURE_WRAP_S
:
322 if (texObj
->WrapS
== eparam
)
325 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
326 texObj
->WrapS
= eparam
;
327 ctx
->NewState
|= NEW_TEXTURING
;
330 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
334 case GL_TEXTURE_WRAP_T
:
335 if (texObj
->WrapT
== eparam
)
338 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
339 texObj
->WrapT
= eparam
;
340 ctx
->NewState
|= NEW_TEXTURING
;
343 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
347 case GL_TEXTURE_WRAP_R_EXT
:
348 if (texObj
->WrapR
== eparam
)
351 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
352 texObj
->WrapR
= eparam
;
353 ctx
->NewState
|= NEW_TEXTURING
;
356 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
359 case GL_TEXTURE_BORDER_COLOR
:
360 texObj
->BorderColor
[0] = (GLubyte
) CLAMP((GLint
)(params
[0]*255.0), 0, 255);
361 texObj
->BorderColor
[1] = (GLubyte
) CLAMP((GLint
)(params
[1]*255.0), 0, 255);
362 texObj
->BorderColor
[2] = (GLubyte
) CLAMP((GLint
)(params
[2]*255.0), 0, 255);
363 texObj
->BorderColor
[3] = (GLubyte
) CLAMP((GLint
)(params
[3]*255.0), 0, 255);
365 case GL_TEXTURE_MIN_LOD
:
366 texObj
->MinLod
= params
[0];
367 ctx
->NewState
|= NEW_TEXTURING
;
369 case GL_TEXTURE_MAX_LOD
:
370 texObj
->MaxLod
= params
[0];
371 ctx
->NewState
|= NEW_TEXTURING
;
373 case GL_TEXTURE_BASE_LEVEL
:
374 if (params
[0] < 0.0) {
375 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
378 texObj
->BaseLevel
= (GLint
) params
[0];
379 ctx
->NewState
|= NEW_TEXTURING
;
381 case GL_TEXTURE_MAX_LEVEL
:
382 if (params
[0] < 0.0) {
383 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
386 texObj
->MaxLevel
= (GLint
) params
[0];
387 ctx
->NewState
|= NEW_TEXTURING
;
389 case GL_TEXTURE_PRIORITY
:
390 /* (keithh@netcomuk.co.uk) */
391 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
394 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
398 gl_put_texobj_on_dirty_list( ctx
, texObj
);
400 if (ctx
->Driver
.TexParameter
) {
401 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
407 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
410 fparam
[0] = (GLfloat
) param
;
411 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
412 _mesa_TexParameterfv(target
, pname
, fparam
);
416 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
419 fparam
[0] = (GLfloat
) params
[0];
420 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
421 _mesa_TexParameterfv(target
, pname
, fparam
);
426 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
427 GLenum pname
, GLfloat
*params
)
430 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
431 *params
= (GLfloat
) iparam
;
436 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
440 case GL_PROXY_TEXTURE_1D
:
443 case GL_PROXY_TEXTURE_2D
:
446 case GL_PROXY_TEXTURE_3D
:
448 case GL_TEXTURE_CUBE_MAP_ARB
:
449 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
450 return ctx
->Extensions
.HaveTextureCubeMap
? 2 : 0;
452 gl_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
459 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
460 GLenum pname
, GLint
*params
)
462 GET_CURRENT_CONTEXT(ctx
);
463 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
464 const struct gl_texture_image
*img
= NULL
;
467 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexLevelParameter");
469 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
470 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
474 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
475 if (dimensions
== 0) {
476 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
480 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
482 if (pname
== GL_TEXTURE_COMPONENTS
)
490 case GL_TEXTURE_WIDTH
:
491 *params
= img
->Width
;
493 case GL_TEXTURE_HEIGHT
:
494 if (dimensions
> 1) {
495 *params
= img
->Height
;
498 gl_error( ctx
, GL_INVALID_ENUM
,
499 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
502 case GL_TEXTURE_DEPTH
:
503 if (dimensions
> 2) {
504 *params
= img
->Depth
;
507 gl_error( ctx
, GL_INVALID_ENUM
,
508 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
511 case GL_TEXTURE_COMPONENTS
:
512 *params
= img
->IntFormat
;
514 case GL_TEXTURE_BORDER
:
515 *params
= img
->Border
;
517 case GL_TEXTURE_RED_SIZE
:
518 *params
= img
->RedBits
;
520 case GL_TEXTURE_GREEN_SIZE
:
521 *params
= img
->GreenBits
;
523 case GL_TEXTURE_BLUE_SIZE
:
524 *params
= img
->BlueBits
;
526 case GL_TEXTURE_ALPHA_SIZE
:
527 *params
= img
->AlphaBits
;
529 case GL_TEXTURE_INTENSITY_SIZE
:
530 *params
= img
->IntensityBits
;
532 case GL_TEXTURE_LUMINANCE_SIZE
:
533 *params
= img
->LuminanceBits
;
535 case GL_TEXTURE_INDEX_SIZE_EXT
:
536 *params
= img
->IndexBits
;
539 gl_error( ctx
, GL_INVALID_ENUM
,
540 "glGetTexLevelParameter[if]v(pname)" );
547 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
549 GET_CURRENT_CONTEXT(ctx
);
550 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
551 struct gl_texture_object
*obj
;
553 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexParameterfv");
555 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
557 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
562 case GL_TEXTURE_MAG_FILTER
:
563 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
565 case GL_TEXTURE_MIN_FILTER
:
566 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
568 case GL_TEXTURE_WRAP_S
:
569 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
571 case GL_TEXTURE_WRAP_T
:
572 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
574 case GL_TEXTURE_WRAP_R_EXT
:
575 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
577 case GL_TEXTURE_BORDER_COLOR
:
578 params
[0] = obj
->BorderColor
[0] / 255.0F
;
579 params
[1] = obj
->BorderColor
[1] / 255.0F
;
580 params
[2] = obj
->BorderColor
[2] / 255.0F
;
581 params
[3] = obj
->BorderColor
[3] / 255.0F
;
583 case GL_TEXTURE_RESIDENT
:
584 *params
= ENUM_TO_FLOAT(GL_TRUE
);
586 case GL_TEXTURE_PRIORITY
:
587 *params
= obj
->Priority
;
589 case GL_TEXTURE_MIN_LOD
:
590 *params
= obj
->MinLod
;
592 case GL_TEXTURE_MAX_LOD
:
593 *params
= obj
->MaxLod
;
595 case GL_TEXTURE_BASE_LEVEL
:
596 *params
= (GLfloat
) obj
->BaseLevel
;
598 case GL_TEXTURE_MAX_LEVEL
:
599 *params
= (GLfloat
) obj
->MaxLevel
;
602 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
608 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
610 GET_CURRENT_CONTEXT(ctx
);
611 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
612 struct gl_texture_object
*obj
;
614 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexParameteriv");
616 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
618 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
623 case GL_TEXTURE_MAG_FILTER
:
624 *params
= (GLint
) obj
->MagFilter
;
626 case GL_TEXTURE_MIN_FILTER
:
627 *params
= (GLint
) obj
->MinFilter
;
629 case GL_TEXTURE_WRAP_S
:
630 *params
= (GLint
) obj
->WrapS
;
632 case GL_TEXTURE_WRAP_T
:
633 *params
= (GLint
) obj
->WrapT
;
635 case GL_TEXTURE_WRAP_R_EXT
:
636 *params
= (GLint
) obj
->WrapR
;
638 case GL_TEXTURE_BORDER_COLOR
:
641 color
[0] = obj
->BorderColor
[0] / 255.0F
;
642 color
[1] = obj
->BorderColor
[1] / 255.0F
;
643 color
[2] = obj
->BorderColor
[2] / 255.0F
;
644 color
[3] = obj
->BorderColor
[3] / 255.0F
;
645 params
[0] = FLOAT_TO_INT( color
[0] );
646 params
[1] = FLOAT_TO_INT( color
[1] );
647 params
[2] = FLOAT_TO_INT( color
[2] );
648 params
[3] = FLOAT_TO_INT( color
[3] );
651 case GL_TEXTURE_RESIDENT
:
652 *params
= (GLint
) GL_TRUE
;
654 case GL_TEXTURE_PRIORITY
:
655 *params
= (GLint
) obj
->Priority
;
657 case GL_TEXTURE_MIN_LOD
:
658 *params
= (GLint
) obj
->MinLod
;
660 case GL_TEXTURE_MAX_LOD
:
661 *params
= (GLint
) obj
->MaxLod
;
663 case GL_TEXTURE_BASE_LEVEL
:
664 *params
= obj
->BaseLevel
;
666 case GL_TEXTURE_MAX_LEVEL
:
667 *params
= obj
->MaxLevel
;
670 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
677 /**********************************************************************/
678 /* Texture Coord Generation */
679 /**********************************************************************/
683 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
685 GET_CURRENT_CONTEXT(ctx
);
686 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
687 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
688 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
690 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
691 fprintf(stderr
, "texGEN %s %s %x...\n",
692 gl_lookup_enum_by_nr(coord
),
693 gl_lookup_enum_by_nr(pname
),
698 if (pname
==GL_TEXTURE_GEN_MODE
) {
699 GLenum mode
= (GLenum
) (GLint
) *params
;
701 case GL_OBJECT_LINEAR
:
702 texUnit
->GenModeS
= mode
;
703 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
706 texUnit
->GenModeS
= mode
;
707 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
709 case GL_REFLECTION_MAP_NV
:
710 texUnit
->GenModeS
= mode
;
711 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
713 case GL_NORMAL_MAP_NV
:
714 texUnit
->GenModeS
= mode
;
715 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
718 texUnit
->GenModeS
= mode
;
719 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
722 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
726 else if (pname
==GL_OBJECT_PLANE
) {
727 texUnit
->ObjectPlaneS
[0] = params
[0];
728 texUnit
->ObjectPlaneS
[1] = params
[1];
729 texUnit
->ObjectPlaneS
[2] = params
[2];
730 texUnit
->ObjectPlaneS
[3] = params
[3];
732 else if (pname
==GL_EYE_PLANE
) {
733 /* Transform plane equation by the inverse modelview matrix */
734 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
735 gl_matrix_analyze( &ctx
->ModelView
);
737 gl_transform_vector( texUnit
->EyePlaneS
, params
,
738 ctx
->ModelView
.inv
);
741 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
746 if (pname
==GL_TEXTURE_GEN_MODE
) {
747 GLenum mode
= (GLenum
) (GLint
) *params
;
749 case GL_OBJECT_LINEAR
:
750 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
751 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
754 texUnit
->GenModeT
= GL_EYE_LINEAR
;
755 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
757 case GL_REFLECTION_MAP_NV
:
758 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
759 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
761 case GL_NORMAL_MAP_NV
:
762 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
763 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
766 texUnit
->GenModeT
= GL_SPHERE_MAP
;
767 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
770 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
774 else if (pname
==GL_OBJECT_PLANE
) {
775 texUnit
->ObjectPlaneT
[0] = params
[0];
776 texUnit
->ObjectPlaneT
[1] = params
[1];
777 texUnit
->ObjectPlaneT
[2] = params
[2];
778 texUnit
->ObjectPlaneT
[3] = params
[3];
780 else if (pname
==GL_EYE_PLANE
) {
781 /* Transform plane equation by the inverse modelview matrix */
782 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
783 gl_matrix_analyze( &ctx
->ModelView
);
785 gl_transform_vector( texUnit
->EyePlaneT
, params
,
786 ctx
->ModelView
.inv
);
789 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
794 if (pname
==GL_TEXTURE_GEN_MODE
) {
795 GLenum mode
= (GLenum
) (GLint
) *params
;
797 case GL_OBJECT_LINEAR
:
798 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
799 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
801 case GL_REFLECTION_MAP_NV
:
802 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
803 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
805 case GL_NORMAL_MAP_NV
:
806 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
807 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
810 texUnit
->GenModeR
= GL_EYE_LINEAR
;
811 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
814 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
818 else if (pname
==GL_OBJECT_PLANE
) {
819 texUnit
->ObjectPlaneR
[0] = params
[0];
820 texUnit
->ObjectPlaneR
[1] = params
[1];
821 texUnit
->ObjectPlaneR
[2] = params
[2];
822 texUnit
->ObjectPlaneR
[3] = params
[3];
824 else if (pname
==GL_EYE_PLANE
) {
825 /* Transform plane equation by the inverse modelview matrix */
826 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
827 gl_matrix_analyze( &ctx
->ModelView
);
829 gl_transform_vector( texUnit
->EyePlaneR
, params
,
830 ctx
->ModelView
.inv
);
833 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
838 if (pname
==GL_TEXTURE_GEN_MODE
) {
839 GLenum mode
= (GLenum
) (GLint
) *params
;
841 case GL_OBJECT_LINEAR
:
842 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
843 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
846 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
847 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
850 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
854 else if (pname
==GL_OBJECT_PLANE
) {
855 texUnit
->ObjectPlaneQ
[0] = params
[0];
856 texUnit
->ObjectPlaneQ
[1] = params
[1];
857 texUnit
->ObjectPlaneQ
[2] = params
[2];
858 texUnit
->ObjectPlaneQ
[3] = params
[3];
860 else if (pname
==GL_EYE_PLANE
) {
861 /* Transform plane equation by the inverse modelview matrix */
862 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
863 gl_matrix_analyze( &ctx
->ModelView
);
865 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
866 ctx
->ModelView
.inv
);
869 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
874 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
878 ctx
->NewState
|= NEW_TEXTURING
;
883 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
890 _mesa_TexGenfv(coord
, pname
, p
);
895 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
897 GLfloat p
= (GLfloat
) param
;
898 _mesa_TexGenfv( coord
, pname
, &p
);
903 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
910 _mesa_TexGenfv( coord
, pname
, p
);
915 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
917 _mesa_TexGenfv(coord
, pname
, ¶m
);
922 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
924 _mesa_TexGeniv( coord
, pname
, ¶m
);
930 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
932 GET_CURRENT_CONTEXT(ctx
);
933 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
934 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
936 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
940 if (pname
==GL_TEXTURE_GEN_MODE
) {
941 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
943 else if (pname
==GL_OBJECT_PLANE
) {
944 COPY_4V( params
, texUnit
->ObjectPlaneS
);
946 else if (pname
==GL_EYE_PLANE
) {
947 COPY_4V( params
, texUnit
->EyePlaneS
);
950 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
955 if (pname
==GL_TEXTURE_GEN_MODE
) {
956 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
958 else if (pname
==GL_OBJECT_PLANE
) {
959 COPY_4V( params
, texUnit
->ObjectPlaneT
);
961 else if (pname
==GL_EYE_PLANE
) {
962 COPY_4V( params
, texUnit
->EyePlaneT
);
965 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
970 if (pname
==GL_TEXTURE_GEN_MODE
) {
971 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
973 else if (pname
==GL_OBJECT_PLANE
) {
974 COPY_4V( params
, texUnit
->ObjectPlaneR
);
976 else if (pname
==GL_EYE_PLANE
) {
977 COPY_4V( params
, texUnit
->EyePlaneR
);
980 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
985 if (pname
==GL_TEXTURE_GEN_MODE
) {
986 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
988 else if (pname
==GL_OBJECT_PLANE
) {
989 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
991 else if (pname
==GL_EYE_PLANE
) {
992 COPY_4V( params
, texUnit
->EyePlaneQ
);
995 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1000 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
1008 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
1010 GET_CURRENT_CONTEXT(ctx
);
1011 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1012 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1014 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
1018 if (pname
==GL_TEXTURE_GEN_MODE
) {
1019 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
1021 else if (pname
==GL_OBJECT_PLANE
) {
1022 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1024 else if (pname
==GL_EYE_PLANE
) {
1025 COPY_4V( params
, texUnit
->EyePlaneS
);
1028 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1033 if (pname
==GL_TEXTURE_GEN_MODE
) {
1034 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1036 else if (pname
==GL_OBJECT_PLANE
) {
1037 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1039 else if (pname
==GL_EYE_PLANE
) {
1040 COPY_4V( params
, texUnit
->EyePlaneT
);
1043 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1048 if (pname
==GL_TEXTURE_GEN_MODE
) {
1049 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1051 else if (pname
==GL_OBJECT_PLANE
) {
1052 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1054 else if (pname
==GL_EYE_PLANE
) {
1055 COPY_4V( params
, texUnit
->EyePlaneR
);
1058 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1063 if (pname
==GL_TEXTURE_GEN_MODE
) {
1064 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1066 else if (pname
==GL_OBJECT_PLANE
) {
1067 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1069 else if (pname
==GL_EYE_PLANE
) {
1070 COPY_4V( params
, texUnit
->EyePlaneQ
);
1073 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1078 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1086 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1088 GET_CURRENT_CONTEXT(ctx
);
1089 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1090 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1092 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
1096 if (pname
==GL_TEXTURE_GEN_MODE
) {
1097 params
[0] = texUnit
->GenModeS
;
1099 else if (pname
==GL_OBJECT_PLANE
) {
1100 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1101 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1102 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1103 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1105 else if (pname
==GL_EYE_PLANE
) {
1106 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1107 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1108 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1109 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1112 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1117 if (pname
==GL_TEXTURE_GEN_MODE
) {
1118 params
[0] = texUnit
->GenModeT
;
1120 else if (pname
==GL_OBJECT_PLANE
) {
1121 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1122 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1123 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1124 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1126 else if (pname
==GL_EYE_PLANE
) {
1127 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1128 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1129 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1130 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1133 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1138 if (pname
==GL_TEXTURE_GEN_MODE
) {
1139 params
[0] = texUnit
->GenModeR
;
1141 else if (pname
==GL_OBJECT_PLANE
) {
1142 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1143 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1144 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1145 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1147 else if (pname
==GL_EYE_PLANE
) {
1148 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1149 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1150 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1151 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1154 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1159 if (pname
==GL_TEXTURE_GEN_MODE
) {
1160 params
[0] = texUnit
->GenModeQ
;
1162 else if (pname
==GL_OBJECT_PLANE
) {
1163 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1164 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1165 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1166 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1168 else if (pname
==GL_EYE_PLANE
) {
1169 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1170 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1171 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1172 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1175 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1180 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1186 /* GL_ARB_multitexture */
1188 _mesa_ActiveTextureARB( GLenum target
)
1190 GET_CURRENT_CONTEXT(ctx
);
1191 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1193 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1195 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1196 fprintf(stderr
, "glActiveTexture %s\n",
1197 gl_lookup_enum_by_nr(target
));
1199 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1200 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1201 ctx
->Texture
.CurrentUnit
= texUnit
;
1202 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1203 if (ctx
->Driver
.ActiveTexture
) {
1204 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1208 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1213 /* GL_ARB_multitexture */
1215 _mesa_ClientActiveTextureARB( GLenum target
)
1217 GET_CURRENT_CONTEXT(ctx
);
1218 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1220 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glClientActiveTextureARB" );
1222 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1223 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1224 ctx
->Array
.ActiveTexture
= texUnit
;
1227 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1234 * Put the given texture object into the list of dirty texture objects.
1235 * When a texture object is dirty we have to reexamine it for completeness
1236 * and perhaps choose a different texture sampling function.
1238 void gl_put_texobj_on_dirty_list( GLcontext
*ctx
, struct gl_texture_object
*t
)
1242 /* Only insert if not already in the dirty list.
1243 * The Dirty flag is only set iff the texture object is in the dirty list.
1246 ASSERT(t
->NextDirty
== NULL
);
1248 t
->NextDirty
= ctx
->Shared
->DirtyTexObjList
;
1249 ctx
->Shared
->DirtyTexObjList
= t
;
1253 /* make sure t is in the list */
1254 struct gl_texture_object
*obj
= ctx
->Shared
->DirtyTexObjList
;
1259 obj
= obj
->NextDirty
;
1261 gl_problem(ctx
, "Error in gl_put_texobj_on_dirty_list");
1268 * Remove a texture object from the dirty texture list.
1270 void gl_remove_texobj_from_dirty_list( struct gl_shared_state
*shared
,
1271 struct gl_texture_object
*tObj
)
1273 struct gl_texture_object
*t
, *prev
= NULL
;
1276 for (t
= shared
->DirtyTexObjList
; t
; t
= t
->NextDirty
) {
1279 prev
->NextDirty
= t
->NextDirty
;
1282 shared
->DirtyTexObjList
= t
->NextDirty
;
1292 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1293 * ctx->NewState is set.
1295 void gl_update_dirty_texobjs( GLcontext
*ctx
)
1297 struct gl_texture_object
*t
, *next
;
1298 for (t
= ctx
->Shared
->DirtyTexObjList
; t
; t
= next
) {
1299 next
= t
->NextDirty
;
1300 _mesa_test_texobj_completeness(ctx
, t
);
1301 _mesa_set_texture_sampler(t
);
1302 t
->NextDirty
= NULL
;
1303 t
->Dirty
= GL_FALSE
;
1305 ctx
->Shared
->DirtyTexObjList
= NULL
;