1 /* $Id: texstate.c,v 1.3 1999/10/08 09:27:11 keithw 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.
36 #include "GL/xf86glx.h"
52 /* Needed for an Amiga compiler */
53 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
54 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
56 /* all other compilers */
57 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
58 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
64 /**********************************************************************/
65 /* Texture Environment */
66 /**********************************************************************/
69 void gl_TexEnvfv( GLcontext
*ctx
,
70 GLenum target
, GLenum pname
, const GLfloat
*param
)
72 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
74 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexEnv");
76 if (target
!=GL_TEXTURE_ENV
) {
77 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
81 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
82 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
83 gl_lookup_enum_by_nr(target
),
84 gl_lookup_enum_by_nr(pname
),
86 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
89 if (pname
==GL_TEXTURE_ENV_MODE
) {
90 GLenum mode
= (GLenum
) (GLint
) *param
;
96 /* A small optimization for drivers */
97 if (texUnit
->EnvMode
== mode
)
100 if (MESA_VERBOSE
& (VERBOSE_STATE
|VERBOSE_TEXTURE
))
101 fprintf(stderr
, "glTexEnv: old mode %s, new mode %s\n",
102 gl_lookup_enum_by_nr(texUnit
->EnvMode
),
103 gl_lookup_enum_by_nr(mode
));
105 texUnit
->EnvMode
= mode
;
106 ctx
->NewState
|= NEW_TEXTURE_ENV
;
109 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
113 else if (pname
==GL_TEXTURE_ENV_COLOR
) {
114 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0, 1.0 );
115 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0, 1.0 );
116 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0, 1.0 );
117 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0, 1.0 );
120 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
124 /* Tell device driver about the new texture environment */
125 if (ctx
->Driver
.TexEnv
) {
126 (*ctx
->Driver
.TexEnv
)( ctx
, pname
, param
);
134 void gl_GetTexEnvfv( GLcontext
*ctx
,
135 GLenum target
, GLenum pname
, GLfloat
*params
)
137 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
138 if (target
!=GL_TEXTURE_ENV
) {
139 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
143 case GL_TEXTURE_ENV_MODE
:
144 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
146 case GL_TEXTURE_ENV_COLOR
:
147 COPY_4FV( params
, texUnit
->EnvColor
);
150 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
155 void gl_GetTexEnviv( GLcontext
*ctx
,
156 GLenum target
, GLenum pname
, GLint
*params
)
158 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
159 if (target
!=GL_TEXTURE_ENV
) {
160 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
164 case GL_TEXTURE_ENV_MODE
:
165 *params
= (GLint
) texUnit
->EnvMode
;
167 case GL_TEXTURE_ENV_COLOR
:
168 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
169 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
170 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
171 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
174 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
181 /**********************************************************************/
182 /* Texture Parameters */
183 /**********************************************************************/
186 void gl_TexParameterfv( GLcontext
*ctx
,
187 GLenum target
, GLenum pname
, const GLfloat
*params
)
189 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
190 GLenum eparam
= (GLenum
) (GLint
) params
[0];
191 struct gl_texture_object
*texObj
;
193 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
194 fprintf(stderr
, "texPARAM %s %s %d...\n",
195 gl_lookup_enum_by_nr(target
),
196 gl_lookup_enum_by_nr(pname
),
202 texObj
= texUnit
->CurrentD
[1];
205 texObj
= texUnit
->CurrentD
[2];
207 case GL_TEXTURE_3D_EXT
:
208 texObj
= texUnit
->CurrentD
[3];
211 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
216 case GL_TEXTURE_MIN_FILTER
:
217 /* A small optimization */
218 if (texObj
->MinFilter
== eparam
)
221 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
222 || eparam
==GL_NEAREST_MIPMAP_NEAREST
223 || eparam
==GL_LINEAR_MIPMAP_NEAREST
224 || eparam
==GL_NEAREST_MIPMAP_LINEAR
225 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
226 texObj
->MinFilter
= eparam
;
227 ctx
->NewState
|= NEW_TEXTURING
;
230 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
234 case GL_TEXTURE_MAG_FILTER
:
235 /* A small optimization */
236 if (texObj
->MagFilter
== eparam
)
239 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
240 texObj
->MagFilter
= eparam
;
241 ctx
->NewState
|= NEW_TEXTURING
;
244 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
248 case GL_TEXTURE_WRAP_S
:
249 if (texObj
->WrapS
== eparam
)
252 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
253 texObj
->WrapS
= eparam
;
254 ctx
->NewState
|= NEW_TEXTURING
;
257 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
261 case GL_TEXTURE_WRAP_T
:
262 if (texObj
->WrapT
== eparam
)
265 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
266 texObj
->WrapT
= eparam
;
267 ctx
->NewState
|= NEW_TEXTURING
;
270 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
274 case GL_TEXTURE_WRAP_R_EXT
:
275 if (texObj
->WrapR
== eparam
)
278 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
279 texObj
->WrapR
= eparam
;
280 ctx
->NewState
|= NEW_TEXTURING
;
283 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
286 case GL_TEXTURE_BORDER_COLOR
:
287 texObj
->BorderColor
[0] = CLAMP((GLint
)(params
[0]*255.0), 0, 255);
288 texObj
->BorderColor
[1] = CLAMP((GLint
)(params
[1]*255.0), 0, 255);
289 texObj
->BorderColor
[2] = CLAMP((GLint
)(params
[2]*255.0), 0, 255);
290 texObj
->BorderColor
[3] = CLAMP((GLint
)(params
[3]*255.0), 0, 255);
292 case GL_TEXTURE_MIN_LOD
:
293 texObj
->MinLod
= params
[0];
294 ctx
->NewState
|= NEW_TEXTURING
;
296 case GL_TEXTURE_MAX_LOD
:
297 texObj
->MaxLod
= params
[0];
298 ctx
->NewState
|= NEW_TEXTURING
;
300 case GL_TEXTURE_BASE_LEVEL
:
301 if (params
[0] < 0.0) {
302 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
305 texObj
->BaseLevel
= (GLint
) params
[0];
306 ctx
->NewState
|= NEW_TEXTURING
;
308 case GL_TEXTURE_MAX_LEVEL
:
309 if (params
[0] < 0.0) {
310 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
313 texObj
->MaxLevel
= (GLint
) params
[0];
314 ctx
->NewState
|= NEW_TEXTURING
;
316 case GL_TEXTURE_PRIORITY
:
317 /* (keithh@netcomuk.co.uk) */
318 texObj
->Priority
= CLAMP( params
[0], 0.0, 1.0 );
321 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
325 gl_put_texobj_on_dirty_list( ctx
, texObj
);
327 if (ctx
->Driver
.TexParameter
) {
328 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
334 void gl_GetTexLevelParameterfv( GLcontext
*ctx
, GLenum target
, GLint level
,
335 GLenum pname
, GLfloat
*params
)
338 gl_GetTexLevelParameteriv( ctx
, target
, level
, pname
, &iparam
);
339 *params
= (GLfloat
) iparam
;
344 void gl_GetTexLevelParameteriv( GLcontext
*ctx
, GLenum target
, GLint level
,
345 GLenum pname
, GLint
*params
)
347 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
348 const struct gl_texture_image
*img
= NULL
;
351 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
352 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
358 img
= texUnit
->CurrentD
[1]->Image
[level
];
362 img
= texUnit
->CurrentD
[2]->Image
[level
];
366 img
= texUnit
->CurrentD
[3]->Image
[level
];
369 case GL_PROXY_TEXTURE_1D
:
370 img
= ctx
->Texture
.Proxy1D
->Image
[level
];
373 case GL_PROXY_TEXTURE_2D
:
374 img
= ctx
->Texture
.Proxy2D
->Image
[level
];
377 case GL_PROXY_TEXTURE_3D
:
378 img
= ctx
->Texture
.Proxy3D
->Image
[level
];
382 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
387 if (pname
== GL_TEXTURE_COMPONENTS
)
395 case GL_TEXTURE_WIDTH
:
396 *params
= img
->Width
;
398 case GL_TEXTURE_HEIGHT
:
399 if (dimensions
> 1) {
400 *params
= img
->Height
;
403 gl_error( ctx
, GL_INVALID_ENUM
,
404 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
407 case GL_TEXTURE_DEPTH
:
408 if (dimensions
> 2) {
409 *params
= img
->Depth
;
412 gl_error( ctx
, GL_INVALID_ENUM
,
413 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
416 case GL_TEXTURE_COMPONENTS
:
417 *params
= img
->IntFormat
;
419 case GL_TEXTURE_BORDER
:
420 *params
= img
->Border
;
422 case GL_TEXTURE_RED_SIZE
:
423 *params
= img
->RedBits
;
425 case GL_TEXTURE_GREEN_SIZE
:
426 *params
= img
->GreenBits
;
428 case GL_TEXTURE_BLUE_SIZE
:
429 *params
= img
->BlueBits
;
431 case GL_TEXTURE_ALPHA_SIZE
:
432 *params
= img
->AlphaBits
;
434 case GL_TEXTURE_INTENSITY_SIZE
:
435 *params
= img
->IntensityBits
;
437 case GL_TEXTURE_LUMINANCE_SIZE
:
438 *params
= img
->LuminanceBits
;
440 case GL_TEXTURE_INDEX_SIZE_EXT
:
441 *params
= img
->IndexBits
;
444 gl_error( ctx
, GL_INVALID_ENUM
,
445 "glGetTexLevelParameter[if]v(pname)" );
452 void gl_GetTexParameterfv( GLcontext
*ctx
,
453 GLenum target
, GLenum pname
, GLfloat
*params
)
455 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
456 struct gl_texture_object
*obj
;
460 obj
= texUnit
->CurrentD
[1];
463 obj
= texUnit
->CurrentD
[2];
465 case GL_TEXTURE_3D_EXT
:
466 obj
= texUnit
->CurrentD
[3];
469 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
474 case GL_TEXTURE_MAG_FILTER
:
475 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
477 case GL_TEXTURE_MIN_FILTER
:
478 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
480 case GL_TEXTURE_WRAP_S
:
481 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
483 case GL_TEXTURE_WRAP_T
:
484 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
486 case GL_TEXTURE_WRAP_R_EXT
:
487 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
489 case GL_TEXTURE_BORDER_COLOR
:
490 params
[0] = obj
->BorderColor
[0] / 255.0F
;
491 params
[1] = obj
->BorderColor
[1] / 255.0F
;
492 params
[2] = obj
->BorderColor
[2] / 255.0F
;
493 params
[3] = obj
->BorderColor
[3] / 255.0F
;
495 case GL_TEXTURE_RESIDENT
:
496 *params
= ENUM_TO_FLOAT(GL_TRUE
);
498 case GL_TEXTURE_PRIORITY
:
499 *params
= obj
->Priority
;
501 case GL_TEXTURE_MIN_LOD
:
502 *params
= obj
->MinLod
;
504 case GL_TEXTURE_MAX_LOD
:
505 *params
= obj
->MaxLod
;
507 case GL_TEXTURE_BASE_LEVEL
:
508 *params
= obj
->BaseLevel
;
510 case GL_TEXTURE_MAX_LEVEL
:
511 *params
= obj
->MaxLevel
;
514 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
519 void gl_GetTexParameteriv( GLcontext
*ctx
,
520 GLenum target
, GLenum pname
, GLint
*params
)
522 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
523 struct gl_texture_object
*obj
;
527 obj
= texUnit
->CurrentD
[1];
530 obj
= texUnit
->CurrentD
[2];
532 case GL_TEXTURE_3D_EXT
:
533 obj
= texUnit
->CurrentD
[3];
536 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
541 case GL_TEXTURE_MAG_FILTER
:
542 *params
= (GLint
) obj
->MagFilter
;
544 case GL_TEXTURE_MIN_FILTER
:
545 *params
= (GLint
) obj
->MinFilter
;
547 case GL_TEXTURE_WRAP_S
:
548 *params
= (GLint
) obj
->WrapS
;
550 case GL_TEXTURE_WRAP_T
:
551 *params
= (GLint
) obj
->WrapT
;
553 case GL_TEXTURE_WRAP_R_EXT
:
554 *params
= (GLint
) obj
->WrapR
;
556 case GL_TEXTURE_BORDER_COLOR
:
559 color
[0] = obj
->BorderColor
[0]/255.0;
560 color
[1] = obj
->BorderColor
[1]/255.0;
561 color
[2] = obj
->BorderColor
[2]/255.0;
562 color
[3] = obj
->BorderColor
[3]/255.0;
563 params
[0] = FLOAT_TO_INT( color
[0] );
564 params
[1] = FLOAT_TO_INT( color
[1] );
565 params
[2] = FLOAT_TO_INT( color
[2] );
566 params
[3] = FLOAT_TO_INT( color
[3] );
569 case GL_TEXTURE_RESIDENT
:
570 *params
= (GLint
) GL_TRUE
;
572 case GL_TEXTURE_PRIORITY
:
573 *params
= (GLint
) obj
->Priority
;
575 case GL_TEXTURE_MIN_LOD
:
576 *params
= (GLint
) obj
->MinLod
;
578 case GL_TEXTURE_MAX_LOD
:
579 *params
= (GLint
) obj
->MaxLod
;
581 case GL_TEXTURE_BASE_LEVEL
:
582 *params
= obj
->BaseLevel
;
584 case GL_TEXTURE_MAX_LEVEL
:
585 *params
= obj
->MaxLevel
;
588 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
595 /**********************************************************************/
596 /* Texture Coord Generation */
597 /**********************************************************************/
600 void gl_TexGenfv( GLcontext
*ctx
,
601 GLenum coord
, GLenum pname
, const GLfloat
*params
)
603 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
604 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
605 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
607 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
608 fprintf(stderr
, "texGEN %s %s %x...\n",
609 gl_lookup_enum_by_nr(coord
),
610 gl_lookup_enum_by_nr(pname
),
615 if (pname
==GL_TEXTURE_GEN_MODE
) {
616 GLenum mode
= (GLenum
) (GLint
) *params
;
618 case GL_OBJECT_LINEAR
:
619 texUnit
->GenModeS
= mode
;
620 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
623 texUnit
->GenModeS
= mode
;
624 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
626 case GL_REFLECTION_MAP_NV
:
627 texUnit
->GenModeS
= mode
;
628 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
630 case GL_NORMAL_MAP_NV
:
631 texUnit
->GenModeS
= mode
;
632 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
635 texUnit
->GenModeS
= mode
;
636 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
639 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
643 else if (pname
==GL_OBJECT_PLANE
) {
644 texUnit
->ObjectPlaneS
[0] = params
[0];
645 texUnit
->ObjectPlaneS
[1] = params
[1];
646 texUnit
->ObjectPlaneS
[2] = params
[2];
647 texUnit
->ObjectPlaneS
[3] = params
[3];
649 else if (pname
==GL_EYE_PLANE
) {
650 /* Transform plane equation by the inverse modelview matrix */
651 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
652 gl_matrix_analyze( &ctx
->ModelView
);
654 gl_transform_vector( texUnit
->EyePlaneS
, params
,
655 ctx
->ModelView
.inv
);
658 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
663 if (pname
==GL_TEXTURE_GEN_MODE
) {
664 GLenum mode
= (GLenum
) (GLint
) *params
;
666 case GL_OBJECT_LINEAR
:
667 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
668 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
671 texUnit
->GenModeT
= GL_EYE_LINEAR
;
672 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
674 case GL_REFLECTION_MAP_NV
:
675 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
676 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
678 case GL_NORMAL_MAP_NV
:
679 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
680 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
683 texUnit
->GenModeT
= GL_SPHERE_MAP
;
684 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
687 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
691 else if (pname
==GL_OBJECT_PLANE
) {
692 texUnit
->ObjectPlaneT
[0] = params
[0];
693 texUnit
->ObjectPlaneT
[1] = params
[1];
694 texUnit
->ObjectPlaneT
[2] = params
[2];
695 texUnit
->ObjectPlaneT
[3] = params
[3];
697 else if (pname
==GL_EYE_PLANE
) {
698 /* Transform plane equation by the inverse modelview matrix */
699 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
700 gl_matrix_analyze( &ctx
->ModelView
);
702 gl_transform_vector( texUnit
->EyePlaneT
, params
,
703 ctx
->ModelView
.inv
);
706 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
711 if (pname
==GL_TEXTURE_GEN_MODE
) {
712 GLenum mode
= (GLenum
) (GLint
) *params
;
714 case GL_OBJECT_LINEAR
:
715 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
716 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
718 case GL_REFLECTION_MAP_NV
:
719 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
720 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
722 case GL_NORMAL_MAP_NV
:
723 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
724 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
727 texUnit
->GenModeR
= GL_EYE_LINEAR
;
728 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
731 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
735 else if (pname
==GL_OBJECT_PLANE
) {
736 texUnit
->ObjectPlaneR
[0] = params
[0];
737 texUnit
->ObjectPlaneR
[1] = params
[1];
738 texUnit
->ObjectPlaneR
[2] = params
[2];
739 texUnit
->ObjectPlaneR
[3] = params
[3];
741 else if (pname
==GL_EYE_PLANE
) {
742 /* Transform plane equation by the inverse modelview matrix */
743 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
744 gl_matrix_analyze( &ctx
->ModelView
);
746 gl_transform_vector( texUnit
->EyePlaneR
, params
,
747 ctx
->ModelView
.inv
);
750 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
755 if (pname
==GL_TEXTURE_GEN_MODE
) {
756 GLenum mode
= (GLenum
) (GLint
) *params
;
758 case GL_OBJECT_LINEAR
:
759 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
760 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
763 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
764 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
767 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
771 else if (pname
==GL_OBJECT_PLANE
) {
772 texUnit
->ObjectPlaneQ
[0] = params
[0];
773 texUnit
->ObjectPlaneQ
[1] = params
[1];
774 texUnit
->ObjectPlaneQ
[2] = params
[2];
775 texUnit
->ObjectPlaneQ
[3] = params
[3];
777 else if (pname
==GL_EYE_PLANE
) {
778 /* Transform plane equation by the inverse modelview matrix */
779 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
780 gl_matrix_analyze( &ctx
->ModelView
);
782 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
783 ctx
->ModelView
.inv
);
786 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
791 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
795 ctx
->NewState
|= NEW_TEXTURING
;
800 void gl_GetTexGendv( GLcontext
*ctx
,
801 GLenum coord
, GLenum pname
, GLdouble
*params
)
803 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
804 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
806 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
810 if (pname
==GL_TEXTURE_GEN_MODE
) {
811 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
813 else if (pname
==GL_OBJECT_PLANE
) {
814 COPY_4V( params
, texUnit
->ObjectPlaneS
);
816 else if (pname
==GL_EYE_PLANE
) {
817 COPY_4V( params
, texUnit
->EyePlaneS
);
820 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
825 if (pname
==GL_TEXTURE_GEN_MODE
) {
826 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
828 else if (pname
==GL_OBJECT_PLANE
) {
829 COPY_4V( params
, texUnit
->ObjectPlaneT
);
831 else if (pname
==GL_EYE_PLANE
) {
832 COPY_4V( params
, texUnit
->EyePlaneT
);
835 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
840 if (pname
==GL_TEXTURE_GEN_MODE
) {
841 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
843 else if (pname
==GL_OBJECT_PLANE
) {
844 COPY_4V( params
, texUnit
->ObjectPlaneR
);
846 else if (pname
==GL_EYE_PLANE
) {
847 COPY_4V( params
, texUnit
->EyePlaneR
);
850 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
855 if (pname
==GL_TEXTURE_GEN_MODE
) {
856 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
858 else if (pname
==GL_OBJECT_PLANE
) {
859 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
861 else if (pname
==GL_EYE_PLANE
) {
862 COPY_4V( params
, texUnit
->EyePlaneQ
);
865 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
870 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
877 void gl_GetTexGenfv( GLcontext
*ctx
,
878 GLenum coord
, GLenum pname
, GLfloat
*params
)
880 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
881 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
883 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
887 if (pname
==GL_TEXTURE_GEN_MODE
) {
888 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
890 else if (pname
==GL_OBJECT_PLANE
) {
891 COPY_4V( params
, texUnit
->ObjectPlaneS
);
893 else if (pname
==GL_EYE_PLANE
) {
894 COPY_4V( params
, texUnit
->EyePlaneS
);
897 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
902 if (pname
==GL_TEXTURE_GEN_MODE
) {
903 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
905 else if (pname
==GL_OBJECT_PLANE
) {
906 COPY_4V( params
, texUnit
->ObjectPlaneT
);
908 else if (pname
==GL_EYE_PLANE
) {
909 COPY_4V( params
, texUnit
->EyePlaneT
);
912 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
917 if (pname
==GL_TEXTURE_GEN_MODE
) {
918 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
920 else if (pname
==GL_OBJECT_PLANE
) {
921 COPY_4V( params
, texUnit
->ObjectPlaneR
);
923 else if (pname
==GL_EYE_PLANE
) {
924 COPY_4V( params
, texUnit
->EyePlaneR
);
927 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
932 if (pname
==GL_TEXTURE_GEN_MODE
) {
933 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
935 else if (pname
==GL_OBJECT_PLANE
) {
936 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
938 else if (pname
==GL_EYE_PLANE
) {
939 COPY_4V( params
, texUnit
->EyePlaneQ
);
942 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
947 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
954 void gl_GetTexGeniv( GLcontext
*ctx
,
955 GLenum coord
, GLenum pname
, GLint
*params
)
957 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
958 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
960 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
964 if (pname
==GL_TEXTURE_GEN_MODE
) {
965 params
[0] = texUnit
->GenModeS
;
967 else if (pname
==GL_OBJECT_PLANE
) {
968 COPY_4V( params
, texUnit
->ObjectPlaneS
);
970 else if (pname
==GL_EYE_PLANE
) {
971 COPY_4V( params
, texUnit
->EyePlaneS
);
974 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
979 if (pname
==GL_TEXTURE_GEN_MODE
) {
980 params
[0] = texUnit
->GenModeT
;
982 else if (pname
==GL_OBJECT_PLANE
) {
983 COPY_4V( params
, texUnit
->ObjectPlaneT
);
985 else if (pname
==GL_EYE_PLANE
) {
986 COPY_4V( params
, texUnit
->EyePlaneT
);
989 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
994 if (pname
==GL_TEXTURE_GEN_MODE
) {
995 params
[0] = texUnit
->GenModeR
;
997 else if (pname
==GL_OBJECT_PLANE
) {
998 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1000 else if (pname
==GL_EYE_PLANE
) {
1001 COPY_4V( params
, texUnit
->EyePlaneR
);
1004 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1009 if (pname
==GL_TEXTURE_GEN_MODE
) {
1010 params
[0] = texUnit
->GenModeQ
;
1012 else if (pname
==GL_OBJECT_PLANE
) {
1013 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1015 else if (pname
==GL_EYE_PLANE
) {
1016 COPY_4V( params
, texUnit
->EyePlaneQ
);
1019 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1024 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1030 /* GL_ARB_multitexture */
1031 void gl_ActiveTexture( GLcontext
*ctx
, GLenum target
)
1033 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1035 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1037 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1038 fprintf(stderr
, "glActiveTexture %s\n",
1039 gl_lookup_enum_by_nr(target
));
1041 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1042 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1043 ctx
->Texture
.CurrentUnit
= texUnit
;
1044 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1045 if (ctx
->Driver
.ActiveTexture
) {
1046 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1050 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1055 /* GL_ARB_multitexture */
1056 void gl_ClientActiveTexture( GLcontext
*ctx
, GLenum target
)
1058 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1060 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glClientActiveTextureARB" );
1062 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1063 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1064 ctx
->Array
.ActiveTexture
= texUnit
;
1067 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1074 * Put the given texture object into the list of dirty texture objects.
1075 * When a texture object is dirty we have to reexamine it for completeness
1076 * and perhaps choose a different texture sampling function.
1078 void gl_put_texobj_on_dirty_list( GLcontext
*ctx
, struct gl_texture_object
*t
)
1082 /* Only insert if not already in the dirty list.
1083 * The Dirty flag is only set iff the texture object is in the dirty list.
1086 ASSERT(t
->NextDirty
== NULL
);
1088 t
->NextDirty
= ctx
->Shared
->DirtyTexObjList
;
1089 ctx
->Shared
->DirtyTexObjList
= t
;
1093 /* make sure t is in the list */
1094 struct gl_texture_object
*obj
= ctx
->Shared
->DirtyTexObjList
;
1099 obj
= obj
->NextDirty
;
1101 gl_problem(ctx
, "Error in gl_put_texobj_on_dirty_list");
1108 * Remove a texture object from the dirty texture list.
1110 void gl_remove_texobj_from_dirty_list( struct gl_shared_state
*shared
,
1111 struct gl_texture_object
*tObj
)
1113 struct gl_texture_object
*t
, *prev
= NULL
;
1116 for (t
= shared
->DirtyTexObjList
; t
; t
= t
->NextDirty
) {
1119 prev
->NextDirty
= t
->NextDirty
;
1122 shared
->DirtyTexObjList
= t
->NextDirty
;
1132 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1133 * ctx->NewState is unit.
1135 void gl_update_dirty_texobjs( GLcontext
*ctx
)
1137 struct gl_texture_object
*t
, *next
;
1138 for (t
= ctx
->Shared
->DirtyTexObjList
; t
; t
= next
) {
1139 next
= t
->NextDirty
;
1140 gl_test_texture_object_completeness(ctx
, t
);
1141 gl_set_texture_sampler(t
);
1142 t
->NextDirty
= NULL
;
1143 t
->Dirty
= GL_FALSE
;
1145 ctx
->Shared
->DirtyTexObjList
= NULL
;