1 /* $Id: texstate.c,v 1.15 2000/07/05 16:14:24 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 case GL_TEXTURE_ENV_MODE
:
77 GLenum mode
= (GLenum
) (GLint
) *param
;
86 !ctx
->Extensions
.HaveTextureEnvAdd
) {
87 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
90 if (mode
== GL_COMBINE_EXT
&&
91 !ctx
->Extensions
.HaveTextureEnvCombine
) {
92 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
95 if (texUnit
->EnvMode
== mode
)
96 return; /* no change */
97 texUnit
->EnvMode
= mode
;
98 ctx
->NewState
|= NEW_TEXTURE_ENV
;
101 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
106 case GL_TEXTURE_ENV_COLOR
:
107 texUnit
->EnvColor
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
108 texUnit
->EnvColor
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
109 texUnit
->EnvColor
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
110 texUnit
->EnvColor
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
112 case GL_COMBINE_RGB_EXT
:
113 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
114 GLenum mode
= (GLenum
) (GLint
) *param
;
119 case GL_ADD_SIGNED_EXT
:
120 case GL_INTERPOLATE_EXT
:
121 if (texUnit
->CombineModeRGB
== mode
)
122 return; /* no change */
123 texUnit
->CombineModeRGB
= mode
;
124 ctx
->NewState
|= NEW_TEXTURE_ENV
;
127 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
132 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
136 case GL_COMBINE_ALPHA_EXT
:
137 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
138 GLenum mode
= (GLenum
) (GLint
) *param
;
143 case GL_ADD_SIGNED_EXT
:
144 case GL_INTERPOLATE_EXT
:
145 if (texUnit
->CombineModeA
== mode
)
146 return; /* no change */
147 texUnit
->CombineModeA
= mode
;
148 ctx
->NewState
|= NEW_TEXTURE_ENV
;
151 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
156 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
160 case GL_SOURCE0_RGB_EXT
:
161 case GL_SOURCE1_RGB_EXT
:
162 case GL_SOURCE2_RGB_EXT
:
163 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
164 GLenum source
= (GLenum
) (GLint
) *param
;
165 GLuint s
= pname
- GL_SOURCE0_RGB_EXT
;
168 case GL_CONSTANT_EXT
:
169 case GL_PRIMARY_COLOR_EXT
:
170 case GL_PREVIOUS_EXT
:
171 if (texUnit
->CombineSourceRGB
[s
] == source
)
172 return; /* no change */
173 texUnit
->CombineSourceRGB
[s
] = source
;
174 ctx
->NewState
|= NEW_TEXTURE_ENV
;
177 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
182 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
186 case GL_SOURCE0_ALPHA_EXT
:
187 case GL_SOURCE1_ALPHA_EXT
:
188 case GL_SOURCE2_ALPHA_EXT
:
189 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
190 GLenum source
= (GLenum
) (GLint
) *param
;
191 GLuint s
= pname
- GL_SOURCE0_ALPHA_EXT
;
194 case GL_CONSTANT_EXT
:
195 case GL_PRIMARY_COLOR_EXT
:
196 case GL_PREVIOUS_EXT
:
197 if (texUnit
->CombineSourceA
[s
] == source
) return;
198 texUnit
->CombineSourceA
[s
] = source
;
199 ctx
->NewState
|= NEW_TEXTURE_ENV
;
202 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
207 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
211 case GL_OPERAND0_RGB_EXT
:
212 case GL_OPERAND1_RGB_EXT
:
213 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
214 GLenum operand
= (GLenum
) (GLint
) *param
;
215 GLuint s
= pname
- GL_OPERAND0_RGB_EXT
;
218 case GL_ONE_MINUS_SRC_COLOR
:
220 case GL_ONE_MINUS_SRC_ALPHA
:
221 texUnit
->CombineOperandRGB
[s
] = operand
;
222 ctx
->NewState
|= NEW_TEXTURE_ENV
;
225 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
230 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
234 case GL_OPERAND0_ALPHA_EXT
:
235 case GL_OPERAND1_ALPHA_EXT
:
236 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
237 GLenum operand
= (GLenum
) (GLint
) *param
;
240 case GL_ONE_MINUS_SRC_ALPHA
:
241 texUnit
->CombineOperandA
[pname
-GL_OPERAND0_ALPHA_EXT
]
243 ctx
->NewState
|= NEW_TEXTURE_ENV
;
246 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
251 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
255 case GL_OPERAND2_RGB_EXT
:
256 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
257 if ((GLenum
) (GLint
) *param
== GL_SRC_ALPHA
) {
258 texUnit
->CombineOperandRGB
[2] = (GLenum
) (GLint
) *param
;
259 ctx
->NewState
|= NEW_TEXTURE_ENV
;
262 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
267 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
271 case GL_OPERAND2_ALPHA_EXT
:
272 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
273 if ((GLenum
) (GLint
) *param
== GL_SRC_ALPHA
) {
274 texUnit
->CombineOperandA
[2] = (GLenum
) (GLint
) *param
;
275 ctx
->NewState
|= NEW_TEXTURE_ENV
;
278 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
283 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
287 case GL_RGB_SCALE_EXT
:
288 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
290 texUnit
->CombineScaleShiftRGB
= 0;
291 ctx
->NewState
|= NEW_TEXTURE_ENV
;
293 else if (*param
== 2.0) {
294 texUnit
->CombineScaleShiftRGB
= 1;
295 ctx
->NewState
|= NEW_TEXTURE_ENV
;
297 else if (*param
== 4.0) {
298 texUnit
->CombineScaleShiftRGB
= 2;
299 ctx
->NewState
|= NEW_TEXTURE_ENV
;
302 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
307 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
312 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
314 texUnit
->CombineScaleShiftA
= 0;
315 ctx
->NewState
|= NEW_TEXTURE_ENV
;
317 else if (*param
== 2.0) {
318 texUnit
->CombineScaleShiftA
= 1;
319 ctx
->NewState
|= NEW_TEXTURE_ENV
;
321 else if (*param
== 4.0) {
322 texUnit
->CombineScaleShiftA
= 2;
323 ctx
->NewState
|= NEW_TEXTURE_ENV
;
326 gl_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
331 gl_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
336 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
340 else if (target
==GL_TEXTURE_FILTER_CONTROL_EXT
) {
341 if (!ctx
->Extensions
.HaveTextureLodBias
) {
342 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
345 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
346 texUnit
->LodBias
= param
[0];
349 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
354 gl_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
358 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
359 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
360 gl_lookup_enum_by_nr(target
),
361 gl_lookup_enum_by_nr(pname
),
363 gl_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
365 /* Tell device driver about the new texture environment */
366 if (ctx
->Driver
.TexEnv
) {
367 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
374 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
376 _mesa_TexEnvfv( target
, pname
, ¶m
);
382 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
385 p
[0] = (GLfloat
) param
;
386 p
[1] = p
[2] = p
[3] = 0.0;
387 _mesa_TexEnvfv( target
, pname
, p
);
392 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
395 p
[0] = INT_TO_FLOAT( param
[0] );
396 p
[1] = INT_TO_FLOAT( param
[1] );
397 p
[2] = INT_TO_FLOAT( param
[2] );
398 p
[3] = INT_TO_FLOAT( param
[3] );
399 _mesa_TexEnvfv( target
, pname
, p
);
404 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
406 GET_CURRENT_CONTEXT(ctx
);
407 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
409 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexEnvfv");
411 if (target
!=GL_TEXTURE_ENV
) {
412 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
417 case GL_TEXTURE_ENV_MODE
:
418 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
420 case GL_TEXTURE_ENV_COLOR
:
421 COPY_4FV( params
, texUnit
->EnvColor
);
423 case GL_RGB_SCALE_EXT
:
424 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
425 if (texUnit
->CombineScaleShiftRGB
== 0)
427 else if (texUnit
->CombineScaleShiftRGB
== 1)
433 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
438 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
439 if (texUnit
->CombineScaleShiftA
== 0)
441 else if (texUnit
->CombineScaleShiftA
== 1)
447 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
452 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
458 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
460 GET_CURRENT_CONTEXT(ctx
);
461 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
463 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexEnviv");
465 if (target
!= GL_TEXTURE_ENV
) {
466 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
471 case GL_TEXTURE_ENV_MODE
:
472 *params
= (GLint
) texUnit
->EnvMode
;
474 case GL_TEXTURE_ENV_COLOR
:
475 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
476 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
477 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
478 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
480 case GL_COMBINE_RGB_EXT
:
481 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
482 *params
= (GLint
) texUnit
->CombineModeRGB
;
485 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
488 case GL_COMBINE_ALPHA_EXT
:
489 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
490 *params
= (GLint
) texUnit
->CombineModeA
;
493 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
496 case GL_SOURCE0_RGB_EXT
:
497 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
498 *params
= (GLint
) texUnit
->CombineSourceRGB
[0];
501 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
504 case GL_SOURCE1_RGB_EXT
:
505 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
506 *params
= (GLint
) texUnit
->CombineSourceRGB
[1];
509 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
512 case GL_SOURCE2_RGB_EXT
:
513 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
514 *params
= (GLint
) texUnit
->CombineSourceRGB
[2];
517 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
520 case GL_SOURCE0_ALPHA_EXT
:
521 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
522 *params
= (GLint
) texUnit
->CombineSourceA
[0];
525 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
528 case GL_SOURCE1_ALPHA_EXT
:
529 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
530 *params
= (GLint
) texUnit
->CombineSourceA
[1];
533 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
536 case GL_SOURCE2_ALPHA_EXT
:
537 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
538 *params
= (GLint
) texUnit
->CombineSourceA
[2];
541 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
544 case GL_OPERAND0_RGB_EXT
:
545 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
546 *params
= (GLint
) texUnit
->CombineOperandRGB
[0];
549 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
552 case GL_OPERAND1_RGB_EXT
:
553 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
554 *params
= (GLint
) texUnit
->CombineOperandRGB
[1];
557 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
560 case GL_OPERAND2_RGB_EXT
:
561 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
562 *params
= (GLint
) texUnit
->CombineOperandRGB
[2];
565 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
568 case GL_OPERAND0_ALPHA_EXT
:
569 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
570 *params
= (GLint
) texUnit
->CombineOperandA
[0];
573 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
576 case GL_OPERAND1_ALPHA_EXT
:
577 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
578 *params
= (GLint
) texUnit
->CombineOperandA
[1];
581 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
584 case GL_OPERAND2_ALPHA_EXT
:
585 if (ctx
->Extensions
.HaveTextureEnvCombine
) {
586 *params
= (GLint
) texUnit
->CombineOperandA
[2];
589 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
593 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
600 /**********************************************************************/
601 /* Texture Parameters */
602 /**********************************************************************/
606 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
608 _mesa_TexParameterfv(target
, pname
, ¶m
);
613 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
615 GET_CURRENT_CONTEXT(ctx
);
616 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
617 GLenum eparam
= (GLenum
) (GLint
) params
[0];
618 struct gl_texture_object
*texObj
;
620 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexParameterfv");
622 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
623 fprintf(stderr
, "texPARAM %s %s %d...\n",
624 gl_lookup_enum_by_nr(target
),
625 gl_lookup_enum_by_nr(pname
),
631 texObj
= texUnit
->CurrentD
[1];
634 texObj
= texUnit
->CurrentD
[2];
636 case GL_TEXTURE_3D_EXT
:
637 texObj
= texUnit
->CurrentD
[3];
639 case GL_TEXTURE_CUBE_MAP_ARB
:
640 if (ctx
->Extensions
.HaveTextureCubeMap
) {
641 texObj
= texUnit
->CurrentCubeMap
;
646 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
651 case GL_TEXTURE_MIN_FILTER
:
652 /* A small optimization */
653 if (texObj
->MinFilter
== eparam
)
656 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
657 || eparam
==GL_NEAREST_MIPMAP_NEAREST
658 || eparam
==GL_LINEAR_MIPMAP_NEAREST
659 || eparam
==GL_NEAREST_MIPMAP_LINEAR
660 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
661 texObj
->MinFilter
= eparam
;
662 ctx
->NewState
|= NEW_TEXTURING
;
665 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
669 case GL_TEXTURE_MAG_FILTER
:
670 /* A small optimization */
671 if (texObj
->MagFilter
== eparam
)
674 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
675 texObj
->MagFilter
= eparam
;
676 ctx
->NewState
|= NEW_TEXTURING
;
679 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
683 case GL_TEXTURE_WRAP_S
:
684 if (texObj
->WrapS
== eparam
)
687 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
688 texObj
->WrapS
= eparam
;
689 ctx
->NewState
|= NEW_TEXTURING
;
692 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
696 case GL_TEXTURE_WRAP_T
:
697 if (texObj
->WrapT
== eparam
)
700 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
701 texObj
->WrapT
= eparam
;
702 ctx
->NewState
|= NEW_TEXTURING
;
705 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
709 case GL_TEXTURE_WRAP_R_EXT
:
710 if (texObj
->WrapR
== eparam
)
713 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
714 texObj
->WrapR
= eparam
;
715 ctx
->NewState
|= NEW_TEXTURING
;
718 gl_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
721 case GL_TEXTURE_BORDER_COLOR
:
722 texObj
->BorderColor
[0] = (GLubyte
) CLAMP((GLint
)(params
[0]*255.0), 0, 255);
723 texObj
->BorderColor
[1] = (GLubyte
) CLAMP((GLint
)(params
[1]*255.0), 0, 255);
724 texObj
->BorderColor
[2] = (GLubyte
) CLAMP((GLint
)(params
[2]*255.0), 0, 255);
725 texObj
->BorderColor
[3] = (GLubyte
) CLAMP((GLint
)(params
[3]*255.0), 0, 255);
727 case GL_TEXTURE_MIN_LOD
:
728 texObj
->MinLod
= params
[0];
729 ctx
->NewState
|= NEW_TEXTURING
;
731 case GL_TEXTURE_MAX_LOD
:
732 texObj
->MaxLod
= params
[0];
733 ctx
->NewState
|= NEW_TEXTURING
;
735 case GL_TEXTURE_BASE_LEVEL
:
736 if (params
[0] < 0.0) {
737 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
740 texObj
->BaseLevel
= (GLint
) params
[0];
741 ctx
->NewState
|= NEW_TEXTURING
;
743 case GL_TEXTURE_MAX_LEVEL
:
744 if (params
[0] < 0.0) {
745 gl_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
748 texObj
->MaxLevel
= (GLint
) params
[0];
749 ctx
->NewState
|= NEW_TEXTURING
;
751 case GL_TEXTURE_PRIORITY
:
752 /* (keithh@netcomuk.co.uk) */
753 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
756 gl_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
760 gl_put_texobj_on_dirty_list( ctx
, texObj
);
762 if (ctx
->Driver
.TexParameter
) {
763 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
769 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
772 fparam
[0] = (GLfloat
) param
;
773 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
774 _mesa_TexParameterfv(target
, pname
, fparam
);
778 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
781 fparam
[0] = (GLfloat
) params
[0];
782 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
783 _mesa_TexParameterfv(target
, pname
, fparam
);
788 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
789 GLenum pname
, GLfloat
*params
)
792 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
793 *params
= (GLfloat
) iparam
;
798 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
802 case GL_PROXY_TEXTURE_1D
:
805 case GL_PROXY_TEXTURE_2D
:
808 case GL_PROXY_TEXTURE_3D
:
810 case GL_TEXTURE_CUBE_MAP_ARB
:
811 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
812 return ctx
->Extensions
.HaveTextureCubeMap
? 2 : 0;
814 gl_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
821 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
822 GLenum pname
, GLint
*params
)
824 GET_CURRENT_CONTEXT(ctx
);
825 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
826 const struct gl_texture_image
*img
= NULL
;
830 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexLevelParameter");
832 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
833 gl_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
837 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
838 if (dimensions
== 0) {
839 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
843 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
845 if (pname
== GL_TEXTURE_COMPONENTS
)
852 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
853 (target
== GL_PROXY_TEXTURE_2D
) ||
854 (target
== GL_PROXY_TEXTURE_3D
) ||
855 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
858 case GL_TEXTURE_WIDTH
:
859 *params
= img
->Width
;
861 case GL_TEXTURE_HEIGHT
:
862 if (dimensions
> 1) {
863 *params
= img
->Height
;
866 gl_error( ctx
, GL_INVALID_ENUM
,
867 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
870 case GL_TEXTURE_DEPTH
:
871 if (dimensions
> 2) {
872 *params
= img
->Depth
;
875 gl_error( ctx
, GL_INVALID_ENUM
,
876 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
879 case GL_TEXTURE_COMPONENTS
:
880 *params
= img
->IntFormat
;
882 case GL_TEXTURE_BORDER
:
883 *params
= img
->Border
;
885 case GL_TEXTURE_RED_SIZE
:
886 *params
= img
->RedBits
;
888 case GL_TEXTURE_GREEN_SIZE
:
889 *params
= img
->GreenBits
;
891 case GL_TEXTURE_BLUE_SIZE
:
892 *params
= img
->BlueBits
;
894 case GL_TEXTURE_ALPHA_SIZE
:
895 *params
= img
->AlphaBits
;
897 case GL_TEXTURE_INTENSITY_SIZE
:
898 *params
= img
->IntensityBits
;
900 case GL_TEXTURE_LUMINANCE_SIZE
:
901 *params
= img
->LuminanceBits
;
903 case GL_TEXTURE_INDEX_SIZE_EXT
:
904 *params
= img
->IndexBits
;
907 /* GL_ARB_texture_compression */
908 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
:
909 if (ctx
->Extensions
.HaveTextureCompression
) {
910 if (img
->IsCompressed
&& !isProxy
)
911 *params
= img
->CompressedSize
;
913 gl_error(ctx
, GL_INVALID_OPERATION
,
914 "glGetTexLevelParameter[if]v(pname)");
917 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
920 case GL_TEXTURE_COMPRESSED_ARB
:
921 if (ctx
->Extensions
.HaveTextureCompression
) {
922 *params
= (GLint
) img
->IsCompressed
;
925 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
930 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
937 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
939 GET_CURRENT_CONTEXT(ctx
);
940 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
941 struct gl_texture_object
*obj
;
943 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexParameterfv");
945 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
947 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
952 case GL_TEXTURE_MAG_FILTER
:
953 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
955 case GL_TEXTURE_MIN_FILTER
:
956 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
958 case GL_TEXTURE_WRAP_S
:
959 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
961 case GL_TEXTURE_WRAP_T
:
962 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
964 case GL_TEXTURE_WRAP_R_EXT
:
965 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
967 case GL_TEXTURE_BORDER_COLOR
:
968 params
[0] = obj
->BorderColor
[0] / 255.0F
;
969 params
[1] = obj
->BorderColor
[1] / 255.0F
;
970 params
[2] = obj
->BorderColor
[2] / 255.0F
;
971 params
[3] = obj
->BorderColor
[3] / 255.0F
;
973 case GL_TEXTURE_RESIDENT
:
974 *params
= ENUM_TO_FLOAT(GL_TRUE
);
976 case GL_TEXTURE_PRIORITY
:
977 *params
= obj
->Priority
;
979 case GL_TEXTURE_MIN_LOD
:
980 *params
= obj
->MinLod
;
982 case GL_TEXTURE_MAX_LOD
:
983 *params
= obj
->MaxLod
;
985 case GL_TEXTURE_BASE_LEVEL
:
986 *params
= (GLfloat
) obj
->BaseLevel
;
988 case GL_TEXTURE_MAX_LEVEL
:
989 *params
= (GLfloat
) obj
->MaxLevel
;
992 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
998 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1000 GET_CURRENT_CONTEXT(ctx
);
1001 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1002 struct gl_texture_object
*obj
;
1004 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexParameteriv");
1006 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1008 gl_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1013 case GL_TEXTURE_MAG_FILTER
:
1014 *params
= (GLint
) obj
->MagFilter
;
1016 case GL_TEXTURE_MIN_FILTER
:
1017 *params
= (GLint
) obj
->MinFilter
;
1019 case GL_TEXTURE_WRAP_S
:
1020 *params
= (GLint
) obj
->WrapS
;
1022 case GL_TEXTURE_WRAP_T
:
1023 *params
= (GLint
) obj
->WrapT
;
1025 case GL_TEXTURE_WRAP_R_EXT
:
1026 *params
= (GLint
) obj
->WrapR
;
1028 case GL_TEXTURE_BORDER_COLOR
:
1031 color
[0] = obj
->BorderColor
[0] / 255.0F
;
1032 color
[1] = obj
->BorderColor
[1] / 255.0F
;
1033 color
[2] = obj
->BorderColor
[2] / 255.0F
;
1034 color
[3] = obj
->BorderColor
[3] / 255.0F
;
1035 params
[0] = FLOAT_TO_INT( color
[0] );
1036 params
[1] = FLOAT_TO_INT( color
[1] );
1037 params
[2] = FLOAT_TO_INT( color
[2] );
1038 params
[3] = FLOAT_TO_INT( color
[3] );
1041 case GL_TEXTURE_RESIDENT
:
1042 *params
= (GLint
) GL_TRUE
;
1044 case GL_TEXTURE_PRIORITY
:
1045 *params
= (GLint
) obj
->Priority
;
1047 case GL_TEXTURE_MIN_LOD
:
1048 *params
= (GLint
) obj
->MinLod
;
1050 case GL_TEXTURE_MAX_LOD
:
1051 *params
= (GLint
) obj
->MaxLod
;
1053 case GL_TEXTURE_BASE_LEVEL
:
1054 *params
= obj
->BaseLevel
;
1056 case GL_TEXTURE_MAX_LEVEL
:
1057 *params
= obj
->MaxLevel
;
1060 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1067 /**********************************************************************/
1068 /* Texture Coord Generation */
1069 /**********************************************************************/
1073 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
1075 GET_CURRENT_CONTEXT(ctx
);
1076 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1077 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1078 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glTexGenfv");
1080 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1081 fprintf(stderr
, "texGEN %s %s %x...\n",
1082 gl_lookup_enum_by_nr(coord
),
1083 gl_lookup_enum_by_nr(pname
),
1088 if (pname
==GL_TEXTURE_GEN_MODE
) {
1089 GLenum mode
= (GLenum
) (GLint
) *params
;
1091 case GL_OBJECT_LINEAR
:
1092 texUnit
->GenModeS
= mode
;
1093 texUnit
->GenBitS
= TEXGEN_OBJ_LINEAR
;
1096 texUnit
->GenModeS
= mode
;
1097 texUnit
->GenBitS
= TEXGEN_EYE_LINEAR
;
1099 case GL_REFLECTION_MAP_NV
:
1100 texUnit
->GenModeS
= mode
;
1101 texUnit
->GenBitS
= TEXGEN_REFLECTION_MAP_NV
;
1103 case GL_NORMAL_MAP_NV
:
1104 texUnit
->GenModeS
= mode
;
1105 texUnit
->GenBitS
= TEXGEN_NORMAL_MAP_NV
;
1108 texUnit
->GenModeS
= mode
;
1109 texUnit
->GenBitS
= TEXGEN_SPHERE_MAP
;
1112 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1116 else if (pname
==GL_OBJECT_PLANE
) {
1117 texUnit
->ObjectPlaneS
[0] = params
[0];
1118 texUnit
->ObjectPlaneS
[1] = params
[1];
1119 texUnit
->ObjectPlaneS
[2] = params
[2];
1120 texUnit
->ObjectPlaneS
[3] = params
[3];
1122 else if (pname
==GL_EYE_PLANE
) {
1123 /* Transform plane equation by the inverse modelview matrix */
1124 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1125 gl_matrix_analyze( &ctx
->ModelView
);
1127 gl_transform_vector( texUnit
->EyePlaneS
, params
,
1128 ctx
->ModelView
.inv
);
1131 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1136 if (pname
==GL_TEXTURE_GEN_MODE
) {
1137 GLenum mode
= (GLenum
) (GLint
) *params
;
1139 case GL_OBJECT_LINEAR
:
1140 texUnit
->GenModeT
= GL_OBJECT_LINEAR
;
1141 texUnit
->GenBitT
= TEXGEN_OBJ_LINEAR
;
1144 texUnit
->GenModeT
= GL_EYE_LINEAR
;
1145 texUnit
->GenBitT
= TEXGEN_EYE_LINEAR
;
1147 case GL_REFLECTION_MAP_NV
:
1148 texUnit
->GenModeT
= GL_REFLECTION_MAP_NV
;
1149 texUnit
->GenBitT
= TEXGEN_REFLECTION_MAP_NV
;
1151 case GL_NORMAL_MAP_NV
:
1152 texUnit
->GenModeT
= GL_NORMAL_MAP_NV
;
1153 texUnit
->GenBitT
= TEXGEN_NORMAL_MAP_NV
;
1156 texUnit
->GenModeT
= GL_SPHERE_MAP
;
1157 texUnit
->GenBitT
= TEXGEN_SPHERE_MAP
;
1160 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1164 else if (pname
==GL_OBJECT_PLANE
) {
1165 texUnit
->ObjectPlaneT
[0] = params
[0];
1166 texUnit
->ObjectPlaneT
[1] = params
[1];
1167 texUnit
->ObjectPlaneT
[2] = params
[2];
1168 texUnit
->ObjectPlaneT
[3] = params
[3];
1170 else if (pname
==GL_EYE_PLANE
) {
1171 /* Transform plane equation by the inverse modelview matrix */
1172 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1173 gl_matrix_analyze( &ctx
->ModelView
);
1175 gl_transform_vector( texUnit
->EyePlaneT
, params
,
1176 ctx
->ModelView
.inv
);
1179 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1184 if (pname
==GL_TEXTURE_GEN_MODE
) {
1185 GLenum mode
= (GLenum
) (GLint
) *params
;
1187 case GL_OBJECT_LINEAR
:
1188 texUnit
->GenModeR
= GL_OBJECT_LINEAR
;
1189 texUnit
->GenBitR
= TEXGEN_OBJ_LINEAR
;
1191 case GL_REFLECTION_MAP_NV
:
1192 texUnit
->GenModeR
= GL_REFLECTION_MAP_NV
;
1193 texUnit
->GenBitR
= TEXGEN_REFLECTION_MAP_NV
;
1195 case GL_NORMAL_MAP_NV
:
1196 texUnit
->GenModeR
= GL_NORMAL_MAP_NV
;
1197 texUnit
->GenBitR
= TEXGEN_NORMAL_MAP_NV
;
1200 texUnit
->GenModeR
= GL_EYE_LINEAR
;
1201 texUnit
->GenBitR
= TEXGEN_EYE_LINEAR
;
1204 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1208 else if (pname
==GL_OBJECT_PLANE
) {
1209 texUnit
->ObjectPlaneR
[0] = params
[0];
1210 texUnit
->ObjectPlaneR
[1] = params
[1];
1211 texUnit
->ObjectPlaneR
[2] = params
[2];
1212 texUnit
->ObjectPlaneR
[3] = params
[3];
1214 else if (pname
==GL_EYE_PLANE
) {
1215 /* Transform plane equation by the inverse modelview matrix */
1216 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1217 gl_matrix_analyze( &ctx
->ModelView
);
1219 gl_transform_vector( texUnit
->EyePlaneR
, params
,
1220 ctx
->ModelView
.inv
);
1223 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1228 if (pname
==GL_TEXTURE_GEN_MODE
) {
1229 GLenum mode
= (GLenum
) (GLint
) *params
;
1231 case GL_OBJECT_LINEAR
:
1232 texUnit
->GenModeQ
= GL_OBJECT_LINEAR
;
1233 texUnit
->GenBitQ
= TEXGEN_OBJ_LINEAR
;
1236 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
1237 texUnit
->GenBitQ
= TEXGEN_EYE_LINEAR
;
1240 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1244 else if (pname
==GL_OBJECT_PLANE
) {
1245 texUnit
->ObjectPlaneQ
[0] = params
[0];
1246 texUnit
->ObjectPlaneQ
[1] = params
[1];
1247 texUnit
->ObjectPlaneQ
[2] = params
[2];
1248 texUnit
->ObjectPlaneQ
[3] = params
[3];
1250 else if (pname
==GL_EYE_PLANE
) {
1251 /* Transform plane equation by the inverse modelview matrix */
1252 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1253 gl_matrix_analyze( &ctx
->ModelView
);
1255 gl_transform_vector( texUnit
->EyePlaneQ
, params
,
1256 ctx
->ModelView
.inv
);
1259 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1264 gl_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
1268 ctx
->NewState
|= NEW_TEXTURING
;
1273 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
1280 _mesa_TexGenfv(coord
, pname
, p
);
1285 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
1287 GLfloat p
= (GLfloat
) param
;
1288 _mesa_TexGenfv( coord
, pname
, &p
);
1293 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
1300 _mesa_TexGenfv( coord
, pname
, p
);
1305 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
1307 _mesa_TexGenfv(coord
, pname
, ¶m
);
1312 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
1314 _mesa_TexGeniv( coord
, pname
, ¶m
);
1320 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
1322 GET_CURRENT_CONTEXT(ctx
);
1323 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1324 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1326 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGendv");
1330 if (pname
==GL_TEXTURE_GEN_MODE
) {
1331 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
1333 else if (pname
==GL_OBJECT_PLANE
) {
1334 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1336 else if (pname
==GL_EYE_PLANE
) {
1337 COPY_4V( params
, texUnit
->EyePlaneS
);
1340 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1345 if (pname
==GL_TEXTURE_GEN_MODE
) {
1346 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
1348 else if (pname
==GL_OBJECT_PLANE
) {
1349 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1351 else if (pname
==GL_EYE_PLANE
) {
1352 COPY_4V( params
, texUnit
->EyePlaneT
);
1355 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1360 if (pname
==GL_TEXTURE_GEN_MODE
) {
1361 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
1363 else if (pname
==GL_OBJECT_PLANE
) {
1364 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1366 else if (pname
==GL_EYE_PLANE
) {
1367 COPY_4V( params
, texUnit
->EyePlaneR
);
1370 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1375 if (pname
==GL_TEXTURE_GEN_MODE
) {
1376 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
1378 else if (pname
==GL_OBJECT_PLANE
) {
1379 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1381 else if (pname
==GL_EYE_PLANE
) {
1382 COPY_4V( params
, texUnit
->EyePlaneQ
);
1385 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1390 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
1398 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
1400 GET_CURRENT_CONTEXT(ctx
);
1401 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1402 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1404 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGenfv");
1408 if (pname
==GL_TEXTURE_GEN_MODE
) {
1409 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
1411 else if (pname
==GL_OBJECT_PLANE
) {
1412 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1414 else if (pname
==GL_EYE_PLANE
) {
1415 COPY_4V( params
, texUnit
->EyePlaneS
);
1418 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1423 if (pname
==GL_TEXTURE_GEN_MODE
) {
1424 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1426 else if (pname
==GL_OBJECT_PLANE
) {
1427 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1429 else if (pname
==GL_EYE_PLANE
) {
1430 COPY_4V( params
, texUnit
->EyePlaneT
);
1433 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1438 if (pname
==GL_TEXTURE_GEN_MODE
) {
1439 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1441 else if (pname
==GL_OBJECT_PLANE
) {
1442 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1444 else if (pname
==GL_EYE_PLANE
) {
1445 COPY_4V( params
, texUnit
->EyePlaneR
);
1448 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1453 if (pname
==GL_TEXTURE_GEN_MODE
) {
1454 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1456 else if (pname
==GL_OBJECT_PLANE
) {
1457 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1459 else if (pname
==GL_EYE_PLANE
) {
1460 COPY_4V( params
, texUnit
->EyePlaneQ
);
1463 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1468 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1476 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1478 GET_CURRENT_CONTEXT(ctx
);
1479 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1480 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1482 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glGetTexGeniv");
1486 if (pname
==GL_TEXTURE_GEN_MODE
) {
1487 params
[0] = texUnit
->GenModeS
;
1489 else if (pname
==GL_OBJECT_PLANE
) {
1490 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1491 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1492 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1493 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1495 else if (pname
==GL_EYE_PLANE
) {
1496 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1497 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1498 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1499 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1502 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1507 if (pname
==GL_TEXTURE_GEN_MODE
) {
1508 params
[0] = texUnit
->GenModeT
;
1510 else if (pname
==GL_OBJECT_PLANE
) {
1511 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1512 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1513 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1514 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1516 else if (pname
==GL_EYE_PLANE
) {
1517 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1518 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1519 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1520 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1523 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1528 if (pname
==GL_TEXTURE_GEN_MODE
) {
1529 params
[0] = texUnit
->GenModeR
;
1531 else if (pname
==GL_OBJECT_PLANE
) {
1532 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1533 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1534 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1535 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1537 else if (pname
==GL_EYE_PLANE
) {
1538 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1539 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1540 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1541 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1544 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1549 if (pname
==GL_TEXTURE_GEN_MODE
) {
1550 params
[0] = texUnit
->GenModeQ
;
1552 else if (pname
==GL_OBJECT_PLANE
) {
1553 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1554 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1555 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1556 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1558 else if (pname
==GL_EYE_PLANE
) {
1559 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1560 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1561 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1562 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1565 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1570 gl_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1576 /* GL_ARB_multitexture */
1578 _mesa_ActiveTextureARB( GLenum target
)
1580 GET_CURRENT_CONTEXT(ctx
);
1581 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1583 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glActiveTextureARB" );
1585 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1586 fprintf(stderr
, "glActiveTexture %s\n",
1587 gl_lookup_enum_by_nr(target
));
1589 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1590 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1591 ctx
->Texture
.CurrentUnit
= texUnit
;
1592 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1593 if (ctx
->Driver
.ActiveTexture
) {
1594 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1598 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1603 /* GL_ARB_multitexture */
1605 _mesa_ClientActiveTextureARB( GLenum target
)
1607 GET_CURRENT_CONTEXT(ctx
);
1608 GLint maxUnits
= ctx
->Const
.MaxTextureUnits
;
1610 ASSERT_OUTSIDE_BEGIN_END( ctx
, "glClientActiveTextureARB" );
1612 if (target
>= GL_TEXTURE0_ARB
&& target
< GL_TEXTURE0_ARB
+ maxUnits
) {
1613 GLint texUnit
= target
- GL_TEXTURE0_ARB
;
1614 ctx
->Array
.ActiveTexture
= texUnit
;
1617 gl_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1624 * Put the given texture object into the list of dirty texture objects.
1625 * When a texture object is dirty we have to reexamine it for completeness
1626 * and perhaps choose a different texture sampling function.
1628 void gl_put_texobj_on_dirty_list( GLcontext
*ctx
, struct gl_texture_object
*t
)
1632 /* Only insert if not already in the dirty list.
1633 * The Dirty flag is only set iff the texture object is in the dirty list.
1636 ASSERT(t
->NextDirty
== NULL
);
1638 t
->NextDirty
= ctx
->Shared
->DirtyTexObjList
;
1639 ctx
->Shared
->DirtyTexObjList
= t
;
1643 /* make sure t is in the list */
1644 struct gl_texture_object
*obj
= ctx
->Shared
->DirtyTexObjList
;
1649 obj
= obj
->NextDirty
;
1651 gl_problem(ctx
, "Error in gl_put_texobj_on_dirty_list");
1658 * Remove a texture object from the dirty texture list.
1660 void gl_remove_texobj_from_dirty_list( struct gl_shared_state
*shared
,
1661 struct gl_texture_object
*tObj
)
1663 struct gl_texture_object
*t
, *prev
= NULL
;
1666 for (t
= shared
->DirtyTexObjList
; t
; t
= t
->NextDirty
) {
1669 prev
->NextDirty
= t
->NextDirty
;
1672 shared
->DirtyTexObjList
= t
->NextDirty
;
1682 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1683 * ctx->NewState is set.
1685 void gl_update_dirty_texobjs( GLcontext
*ctx
)
1687 struct gl_texture_object
*t
, *next
;
1688 for (t
= ctx
->Shared
->DirtyTexObjList
; t
; t
= next
) {
1689 next
= t
->NextDirty
;
1690 _mesa_test_texobj_completeness(ctx
, t
);
1691 _mesa_set_texture_sampler(t
);
1692 t
->NextDirty
= NULL
;
1693 t
->Dirty
= GL_FALSE
;
1695 ctx
->Shared
->DirtyTexObjList
= NULL
;