1 /* $Id: texstate.c,v 1.1 1999/08/19 00:55:41 jtg 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.
44 #include "GL/xf86glx.h"
51 /* Needed for an Amiga compiler */
52 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
53 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
55 /* all other compilers */
56 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
57 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
63 /**********************************************************************/
64 /* Texture Environment */
65 /**********************************************************************/
68 void gl_TexEnvfv( GLcontext
*ctx
,
69 GLenum target
, GLenum pname
, const GLfloat
*param
)
71 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
73 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexEnv");
75 if (target
!=GL_TEXTURE_ENV
) {
76 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
80 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
81 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
82 gl_lookup_enum_by_nr(target
),
83 gl_lookup_enum_by_nr(pname
),
85 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
88 if (pname
==GL_TEXTURE_ENV_MODE
) {
89 GLenum mode
= (GLenum
) (GLint
) *param
;
95 /* A small optimization for drivers */
96 if (texUnit
->EnvMode
== mode
)
99 if (MESA_VERBOSE
& (VERBOSE_STATE
|VERBOSE_TEXTURE
))
100 fprintf(stderr
, "glTexEnv: old mode %s, new mode %s\n",
101 gl_lookup_enum_by_nr(texUnit
->EnvMode
),
102 gl_lookup_enum_by_nr(mode
));
104 texUnit
->EnvMode
= mode
;
105 ctx
->NewState
|= NEW_TEXTURE_ENV
;
108 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
112 else if (pname
==GL_TEXTURE_ENV_COLOR
) {
113 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0, 1.0 );
114 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0, 1.0 );
115 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0, 1.0 );
116 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0, 1.0 );
119 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
123 /* Tell device driver about the new texture environment */
124 if (ctx
->Driver
.TexEnv
) {
125 (*ctx
->Driver
.TexEnv
)( ctx
, pname
, param
);
133 void gl_GetTexEnvfv( GLcontext
*ctx
,
134 GLenum target
, GLenum pname
, GLfloat
*params
)
136 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
137 if (target
!=GL_TEXTURE_ENV
) {
138 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
142 case GL_TEXTURE_ENV_MODE
:
143 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
145 case GL_TEXTURE_ENV_COLOR
:
146 COPY_4FV( params
, texUnit
->EnvColor
);
149 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
154 void gl_GetTexEnviv( GLcontext
*ctx
,
155 GLenum target
, GLenum pname
, GLint
*params
)
157 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
158 if (target
!=GL_TEXTURE_ENV
) {
159 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
163 case GL_TEXTURE_ENV_MODE
:
164 *params
= (GLint
) texUnit
->EnvMode
;
166 case GL_TEXTURE_ENV_COLOR
:
167 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
168 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
169 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
170 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
173 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
180 /**********************************************************************/
181 /* Texture Parameters */
182 /**********************************************************************/
185 void gl_TexParameterfv( GLcontext
*ctx
,
186 GLenum target
, GLenum pname
, const GLfloat
*params
)
188 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
189 GLenum eparam
= (GLenum
) (GLint
) params
[0];
190 struct gl_texture_object
*texObj
;
192 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
193 fprintf(stderr
, "texPARAM %s %s %d...\n",
194 gl_lookup_enum_by_nr(target
),
195 gl_lookup_enum_by_nr(pname
),
201 texObj
= texUnit
->CurrentD
[1];
204 texObj
= texUnit
->CurrentD
[2];
206 case GL_TEXTURE_3D_EXT
:
207 texObj
= texUnit
->CurrentD
[3];
210 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
215 case GL_TEXTURE_MIN_FILTER
:
216 /* A small optimization */
217 if (texObj
->MinFilter
== eparam
)
220 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
221 || eparam
==GL_NEAREST_MIPMAP_NEAREST
222 || eparam
==GL_LINEAR_MIPMAP_NEAREST
223 || eparam
==GL_NEAREST_MIPMAP_LINEAR
224 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
225 texObj
->MinFilter
= eparam
;
226 ctx
->NewState
|= NEW_TEXTURING
;
229 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
233 case GL_TEXTURE_MAG_FILTER
:
234 /* A small optimization */
235 if (texObj
->MagFilter
== eparam
)
238 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
239 texObj
->MagFilter
= eparam
;
240 ctx
->NewState
|= NEW_TEXTURING
;
243 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
247 case GL_TEXTURE_WRAP_S
:
248 if (texObj
->WrapS
== eparam
)
251 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
252 texObj
->WrapS
= eparam
;
253 ctx
->NewState
|= NEW_TEXTURING
;
256 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
260 case GL_TEXTURE_WRAP_T
:
261 if (texObj
->WrapT
== eparam
)
264 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
265 texObj
->WrapT
= eparam
;
266 ctx
->NewState
|= NEW_TEXTURING
;
269 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
273 case GL_TEXTURE_WRAP_R_EXT
:
274 if (texObj
->WrapR
== eparam
)
277 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
278 texObj
->WrapR
= eparam
;
279 ctx
->NewState
|= NEW_TEXTURING
;
282 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
285 case GL_TEXTURE_BORDER_COLOR
:
286 texObj
->BorderColor
[0] = CLAMP((GLint
)(params
[0]*255.0), 0, 255);
287 texObj
->BorderColor
[1] = CLAMP((GLint
)(params
[1]*255.0), 0, 255);
288 texObj
->BorderColor
[2] = CLAMP((GLint
)(params
[2]*255.0), 0, 255);
289 texObj
->BorderColor
[3] = CLAMP((GLint
)(params
[3]*255.0), 0, 255);
291 case GL_TEXTURE_MIN_LOD
:
292 texObj
->MinLod
= params
[0];
293 ctx
->NewState
|= NEW_TEXTURING
;
295 case GL_TEXTURE_MAX_LOD
:
296 texObj
->MaxLod
= params
[0];
297 ctx
->NewState
|= NEW_TEXTURING
;
299 case GL_TEXTURE_BASE_LEVEL
:
300 if (params
[0] < 0.0) {
301 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
304 texObj
->BaseLevel
= (GLint
) params
[0];
305 ctx
->NewState
|= NEW_TEXTURING
;
307 case GL_TEXTURE_MAX_LEVEL
:
308 if (params
[0] < 0.0) {
309 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
312 texObj
->MaxLevel
= (GLint
) params
[0];
313 ctx
->NewState
|= NEW_TEXTURING
;
315 case GL_TEXTURE_PRIORITY
:
316 /* (keithh@netcomuk.co.uk) */
317 texObj
->Priority
= CLAMP( params
[0], 0.0, 1.0 );
320 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
324 gl_put_texobj_on_dirty_list( ctx
, texObj
);
326 if (ctx
->Driver
.TexParameter
) {
327 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
333 void gl_GetTexLevelParameterfv( GLcontext
*ctx
, GLenum target
, GLint level
,
334 GLenum pname
, GLfloat
*params
)
337 gl_GetTexLevelParameteriv( ctx
, target
, level
, pname
, &iparam
);
338 *params
= (GLfloat
) iparam
;
343 void gl_GetTexLevelParameteriv( GLcontext
*ctx
, GLenum target
, GLint level
,
344 GLenum pname
, GLint
*params
)
346 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
347 const struct gl_texture_image
*img
= NULL
;
350 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
351 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
357 img
= texUnit
->CurrentD
[1]->Image
[level
];
361 img
= texUnit
->CurrentD
[2]->Image
[level
];
365 img
= texUnit
->CurrentD
[3]->Image
[level
];
368 case GL_PROXY_TEXTURE_1D
:
369 img
= ctx
->Texture
.Proxy1D
->Image
[level
];
372 case GL_PROXY_TEXTURE_2D
:
373 img
= ctx
->Texture
.Proxy2D
->Image
[level
];
376 case GL_PROXY_TEXTURE_3D
:
377 img
= ctx
->Texture
.Proxy3D
->Image
[level
];
381 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
386 if (pname
== GL_TEXTURE_COMPONENTS
)
394 case GL_TEXTURE_WIDTH
:
395 *params
= img
->Width
;
397 case GL_TEXTURE_HEIGHT
:
398 if (dimensions
> 1) {
399 *params
= img
->Height
;
402 gl_error( ctx
, GL_INVALID_ENUM
,
403 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
406 case GL_TEXTURE_DEPTH
:
407 if (dimensions
> 2) {
408 *params
= img
->Depth
;
411 gl_error( ctx
, GL_INVALID_ENUM
,
412 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
415 case GL_TEXTURE_COMPONENTS
:
416 *params
= img
->IntFormat
;
418 case GL_TEXTURE_BORDER
:
419 *params
= img
->Border
;
421 case GL_TEXTURE_RED_SIZE
:
422 *params
= img
->RedBits
;
424 case GL_TEXTURE_GREEN_SIZE
:
425 *params
= img
->GreenBits
;
427 case GL_TEXTURE_BLUE_SIZE
:
428 *params
= img
->BlueBits
;
430 case GL_TEXTURE_ALPHA_SIZE
:
431 *params
= img
->AlphaBits
;
433 case GL_TEXTURE_INTENSITY_SIZE
:
434 *params
= img
->IntensityBits
;
436 case GL_TEXTURE_LUMINANCE_SIZE
:
437 *params
= img
->LuminanceBits
;
439 case GL_TEXTURE_INDEX_SIZE_EXT
:
440 *params
= img
->IndexBits
;
443 gl_error( ctx
, GL_INVALID_ENUM
,
444 "glGetTexLevelParameter[if]v(pname)" );
451 void gl_GetTexParameterfv( GLcontext
*ctx
,
452 GLenum target
, GLenum pname
, GLfloat
*params
)
454 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
455 struct gl_texture_object
*obj
;
459 obj
= texUnit
->CurrentD
[1];
462 obj
= texUnit
->CurrentD
[2];
464 case GL_TEXTURE_3D_EXT
:
465 obj
= texUnit
->CurrentD
[3];
468 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
473 case GL_TEXTURE_MAG_FILTER
:
474 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
476 case GL_TEXTURE_MIN_FILTER
:
477 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
479 case GL_TEXTURE_WRAP_S
:
480 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
482 case GL_TEXTURE_WRAP_T
:
483 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
485 case GL_TEXTURE_WRAP_R_EXT
:
486 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
488 case GL_TEXTURE_BORDER_COLOR
:
489 params
[0] = obj
->BorderColor
[0] / 255.0F
;
490 params
[1] = obj
->BorderColor
[1] / 255.0F
;
491 params
[2] = obj
->BorderColor
[2] / 255.0F
;
492 params
[3] = obj
->BorderColor
[3] / 255.0F
;
494 case GL_TEXTURE_RESIDENT
:
495 *params
= ENUM_TO_FLOAT(GL_TRUE
);
497 case GL_TEXTURE_PRIORITY
:
498 *params
= obj
->Priority
;
500 case GL_TEXTURE_MIN_LOD
:
501 *params
= obj
->MinLod
;
503 case GL_TEXTURE_MAX_LOD
:
504 *params
= obj
->MaxLod
;
506 case GL_TEXTURE_BASE_LEVEL
:
507 *params
= obj
->BaseLevel
;
509 case GL_TEXTURE_MAX_LEVEL
:
510 *params
= obj
->MaxLevel
;
513 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
518 void gl_GetTexParameteriv( GLcontext
*ctx
,
519 GLenum target
, GLenum pname
, GLint
*params
)
521 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
522 struct gl_texture_object
*obj
;
526 obj
= texUnit
->CurrentD
[1];
529 obj
= texUnit
->CurrentD
[2];
531 case GL_TEXTURE_3D_EXT
:
532 obj
= texUnit
->CurrentD
[3];
535 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
540 case GL_TEXTURE_MAG_FILTER
:
541 *params
= (GLint
) obj
->MagFilter
;
543 case GL_TEXTURE_MIN_FILTER
:
544 *params
= (GLint
) obj
->MinFilter
;
546 case GL_TEXTURE_WRAP_S
:
547 *params
= (GLint
) obj
->WrapS
;
549 case GL_TEXTURE_WRAP_T
:
550 *params
= (GLint
) obj
->WrapT
;
552 case GL_TEXTURE_WRAP_R_EXT
:
553 *params
= (GLint
) obj
->WrapR
;
555 case GL_TEXTURE_BORDER_COLOR
:
558 color
[0] = obj
->BorderColor
[0]/255.0;
559 color
[1] = obj
->BorderColor
[1]/255.0;
560 color
[2] = obj
->BorderColor
[2]/255.0;
561 color
[3] = obj
->BorderColor
[3]/255.0;
562 params
[0] = FLOAT_TO_INT( color
[0] );
563 params
[1] = FLOAT_TO_INT( color
[1] );
564 params
[2] = FLOAT_TO_INT( color
[2] );
565 params
[3] = FLOAT_TO_INT( color
[3] );
568 case GL_TEXTURE_RESIDENT
:
569 *params
= (GLint
) GL_TRUE
;
571 case GL_TEXTURE_PRIORITY
:
572 *params
= (GLint
) obj
->Priority
;
574 case GL_TEXTURE_MIN_LOD
:
575 *params
= (GLint
) obj
->MinLod
;
577 case GL_TEXTURE_MAX_LOD
:
578 *params
= (GLint
) obj
->MaxLod
;
580 case GL_TEXTURE_BASE_LEVEL
:
581 *params
= obj
->BaseLevel
;
583 case GL_TEXTURE_MAX_LEVEL
:
584 *params
= obj
->MaxLevel
;
587 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
594 /**********************************************************************/
595 /* Texture Coord Generation */
596 /**********************************************************************/
599 void gl_TexGenfv( GLcontext
*ctx
,
600 GLenum coord
, GLenum pname
, const GLfloat
*params
)
602 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
603 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
604 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
606 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
607 fprintf(stderr
, "texGEN %s %s %x...\n",
608 gl_lookup_enum_by_nr(coord
),
609 gl_lookup_enum_by_nr(pname
),
614 if (pname
==GL_TEXTURE_GEN_MODE
) {
615 GLenum mode
= (GLenum
) (GLint
) *params
;
617 case GL_OBJECT_LINEAR
:
618 texUnit
->GenModeS
= mode
;
619 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
622 texUnit
->GenModeS
= mode
;
623 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
625 case GL_REFLECTION_MAP_NV
:
626 texUnit
->GenModeS
= mode
;
627 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
629 case GL_NORMAL_MAP_NV
:
630 texUnit
->GenModeS
= mode
;
631 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
634 texUnit
->GenModeS
= mode
;
635 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
638 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
642 else if (pname
==GL_OBJECT_PLANE
) {
643 texUnit
->ObjectPlaneS
[0] = params
[0];
644 texUnit
->ObjectPlaneS
[1] = params
[1];
645 texUnit
->ObjectPlaneS
[2] = params
[2];
646 texUnit
->ObjectPlaneS
[3] = params
[3];
648 else if (pname
==GL_EYE_PLANE
) {
649 /* Transform plane equation by the inverse modelview matrix */
650 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
651 gl_matrix_analyze( &ctx
->ModelView
);
653 gl_transform_vector( texUnit
->EyePlaneS
, params
,
654 ctx
->ModelView
.inv
);
657 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
662 if (pname
==GL_TEXTURE_GEN_MODE
) {
663 GLenum mode
= (GLenum
) (GLint
) *params
;
665 case GL_OBJECT_LINEAR
:
666 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
667 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
670 texUnit
->GenModeT
= GL_EYE_LINEAR
;
671 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
673 case GL_REFLECTION_MAP_NV
:
674 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
675 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
677 case GL_NORMAL_MAP_NV
:
678 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
679 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
682 texUnit
->GenModeT
= GL_SPHERE_MAP
;
683 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
686 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
690 else if (pname
==GL_OBJECT_PLANE
) {
691 texUnit
->ObjectPlaneT
[0] = params
[0];
692 texUnit
->ObjectPlaneT
[1] = params
[1];
693 texUnit
->ObjectPlaneT
[2] = params
[2];
694 texUnit
->ObjectPlaneT
[3] = params
[3];
696 else if (pname
==GL_EYE_PLANE
) {
697 /* Transform plane equation by the inverse modelview matrix */
698 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
699 gl_matrix_analyze( &ctx
->ModelView
);
701 gl_transform_vector( texUnit
->EyePlaneT
, params
,
702 ctx
->ModelView
.inv
);
705 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
710 if (pname
==GL_TEXTURE_GEN_MODE
) {
711 GLenum mode
= (GLenum
) (GLint
) *params
;
713 case GL_OBJECT_LINEAR
:
714 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
715 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
717 case GL_REFLECTION_MAP_NV
:
718 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
719 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
721 case GL_NORMAL_MAP_NV
:
722 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
723 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
726 texUnit
->GenModeR
= GL_EYE_LINEAR
;
727 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
730 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
734 else if (pname
==GL_OBJECT_PLANE
) {
735 texUnit
->ObjectPlaneR
[0] = params
[0];
736 texUnit
->ObjectPlaneR
[1] = params
[1];
737 texUnit
->ObjectPlaneR
[2] = params
[2];
738 texUnit
->ObjectPlaneR
[3] = params
[3];
740 else if (pname
==GL_EYE_PLANE
) {
741 /* Transform plane equation by the inverse modelview matrix */
742 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
743 gl_matrix_analyze( &ctx
->ModelView
);
745 gl_transform_vector( texUnit
->EyePlaneR
, params
,
746 ctx
->ModelView
.inv
);
749 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
754 if (pname
==GL_TEXTURE_GEN_MODE
) {
755 GLenum mode
= (GLenum
) (GLint
) *params
;
757 case GL_OBJECT_LINEAR
:
758 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
759 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
762 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
763 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
766 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
770 else if (pname
==GL_OBJECT_PLANE
) {
771 texUnit
->ObjectPlaneQ
[0] = params
[0];
772 texUnit
->ObjectPlaneQ
[1] = params
[1];
773 texUnit
->ObjectPlaneQ
[2] = params
[2];
774 texUnit
->ObjectPlaneQ
[3] = params
[3];
776 else if (pname
==GL_EYE_PLANE
) {
777 /* Transform plane equation by the inverse modelview matrix */
778 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
779 gl_matrix_analyze( &ctx
->ModelView
);
781 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
782 ctx
->ModelView
.inv
);
785 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
790 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
794 ctx
->NewState
|= NEW_TEXTURING
;
799 void gl_GetTexGendv( GLcontext
*ctx
,
800 GLenum coord
, GLenum pname
, GLdouble
*params
)
802 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
803 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
805 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
809 if (pname
==GL_TEXTURE_GEN_MODE
) {
810 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
812 else if (pname
==GL_OBJECT_PLANE
) {
813 COPY_4V( params
, texUnit
->ObjectPlaneS
);
815 else if (pname
==GL_EYE_PLANE
) {
816 COPY_4V( params
, texUnit
->EyePlaneS
);
819 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
824 if (pname
==GL_TEXTURE_GEN_MODE
) {
825 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
827 else if (pname
==GL_OBJECT_PLANE
) {
828 COPY_4V( params
, texUnit
->ObjectPlaneT
);
830 else if (pname
==GL_EYE_PLANE
) {
831 COPY_4V( params
, texUnit
->EyePlaneT
);
834 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
839 if (pname
==GL_TEXTURE_GEN_MODE
) {
840 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
842 else if (pname
==GL_OBJECT_PLANE
) {
843 COPY_4V( params
, texUnit
->ObjectPlaneR
);
845 else if (pname
==GL_EYE_PLANE
) {
846 COPY_4V( params
, texUnit
->EyePlaneR
);
849 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
854 if (pname
==GL_TEXTURE_GEN_MODE
) {
855 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
857 else if (pname
==GL_OBJECT_PLANE
) {
858 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
860 else if (pname
==GL_EYE_PLANE
) {
861 COPY_4V( params
, texUnit
->EyePlaneQ
);
864 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
869 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
876 void gl_GetTexGenfv( GLcontext
*ctx
,
877 GLenum coord
, GLenum pname
, GLfloat
*params
)
879 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
880 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
882 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
886 if (pname
==GL_TEXTURE_GEN_MODE
) {
887 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
889 else if (pname
==GL_OBJECT_PLANE
) {
890 COPY_4V( params
, texUnit
->ObjectPlaneS
);
892 else if (pname
==GL_EYE_PLANE
) {
893 COPY_4V( params
, texUnit
->EyePlaneS
);
896 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
901 if (pname
==GL_TEXTURE_GEN_MODE
) {
902 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
904 else if (pname
==GL_OBJECT_PLANE
) {
905 COPY_4V( params
, texUnit
->ObjectPlaneT
);
907 else if (pname
==GL_EYE_PLANE
) {
908 COPY_4V( params
, texUnit
->EyePlaneT
);
911 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
916 if (pname
==GL_TEXTURE_GEN_MODE
) {
917 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
919 else if (pname
==GL_OBJECT_PLANE
) {
920 COPY_4V( params
, texUnit
->ObjectPlaneR
);
922 else if (pname
==GL_EYE_PLANE
) {
923 COPY_4V( params
, texUnit
->EyePlaneR
);
926 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
931 if (pname
==GL_TEXTURE_GEN_MODE
) {
932 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
934 else if (pname
==GL_OBJECT_PLANE
) {
935 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
937 else if (pname
==GL_EYE_PLANE
) {
938 COPY_4V( params
, texUnit
->EyePlaneQ
);
941 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
946 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
953 void gl_GetTexGeniv( GLcontext
*ctx
,
954 GLenum coord
, GLenum pname
, GLint
*params
)
956 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
957 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
959 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
963 if (pname
==GL_TEXTURE_GEN_MODE
) {
964 params
[0] = texUnit
->GenModeS
;
966 else if (pname
==GL_OBJECT_PLANE
) {
967 COPY_4V( params
, texUnit
->ObjectPlaneS
);
969 else if (pname
==GL_EYE_PLANE
) {
970 COPY_4V( params
, texUnit
->EyePlaneS
);
973 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
978 if (pname
==GL_TEXTURE_GEN_MODE
) {
979 params
[0] = texUnit
->GenModeT
;
981 else if (pname
==GL_OBJECT_PLANE
) {
982 COPY_4V( params
, texUnit
->ObjectPlaneT
);
984 else if (pname
==GL_EYE_PLANE
) {
985 COPY_4V( params
, texUnit
->EyePlaneT
);
988 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
993 if (pname
==GL_TEXTURE_GEN_MODE
) {
994 params
[0] = texUnit
->GenModeR
;
996 else if (pname
==GL_OBJECT_PLANE
) {
997 COPY_4V( params
, texUnit
->ObjectPlaneR
);
999 else if (pname
==GL_EYE_PLANE
) {
1000 COPY_4V( params
, texUnit
->EyePlaneR
);
1003 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1008 if (pname
==GL_TEXTURE_GEN_MODE
) {
1009 params
[0] = texUnit
->GenModeQ
;
1011 else if (pname
==GL_OBJECT_PLANE
) {
1012 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1014 else if (pname
==GL_EYE_PLANE
) {
1015 COPY_4V( params
, texUnit
->EyePlaneQ
);
1018 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1023 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1029 /* GL_ARB_multitexture */
1030 void gl_ActiveTexture( GLcontext
*ctx
, GLenum target
)
1032 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1034 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1036 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1037 fprintf(stderr
, "glActiveTexture %s\n",
1038 gl_lookup_enum_by_nr(target
));
1040 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1041 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1042 ctx
->TexCoordUnit
= texUnit
;
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
;