1 /* $Id: texstate.c,v 1.36 2001/03/07 05:06:12 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
35 #include "extensions.h"
41 #include "math/m_xform.h"
42 #include "math/m_matrix.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
];
70 ASSERT_OUTSIDE_BEGIN_END(ctx
);
72 if (target
==GL_TEXTURE_ENV
) {
74 case GL_TEXTURE_ENV_MODE
: {
75 GLenum mode
= (GLenum
) (GLint
) *param
;
79 if (!ctx
->Extensions
.EXT_texture_env_add
) {
80 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
85 if (!ctx
->Extensions
.EXT_texture_env_combine
) {
86 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
96 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
100 if (texUnit
->EnvMode
== mode
)
102 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
103 texUnit
->EnvMode
= mode
;
106 case GL_TEXTURE_ENV_COLOR
: {
108 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
109 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
110 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
111 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
112 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
114 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
115 COPY_4FV(texUnit
->EnvColor
, tmp
);
118 case GL_COMBINE_RGB_EXT
:
119 if (ctx
->Extensions
.EXT_texture_env_combine
) {
120 GLenum mode
= (GLenum
) (GLint
) *param
;
125 case GL_ADD_SIGNED_EXT
:
126 case GL_INTERPOLATE_EXT
:
128 case GL_DOT3_RGB_EXT
:
129 case GL_DOT3_RGBA_EXT
:
130 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
131 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(param)");
136 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
139 if (texUnit
->CombineModeRGB
== mode
)
141 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
142 texUnit
->CombineModeRGB
= mode
;
145 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
148 case GL_COMBINE_ALPHA_EXT
:
149 if (ctx
->Extensions
.EXT_texture_env_combine
) {
150 GLenum mode
= (GLenum
) (GLint
) *param
;
155 case GL_ADD_SIGNED_EXT
:
156 case GL_INTERPOLATE_EXT
:
157 if (texUnit
->CombineModeA
== mode
)
159 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
160 texUnit
->CombineModeA
= mode
;
163 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
168 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
172 case GL_SOURCE0_RGB_EXT
:
173 case GL_SOURCE1_RGB_EXT
:
174 case GL_SOURCE2_RGB_EXT
:
175 if (ctx
->Extensions
.EXT_texture_env_combine
) {
176 GLenum source
= (GLenum
) (GLint
) *param
;
177 GLuint s
= pname
- GL_SOURCE0_RGB_EXT
;
180 case GL_CONSTANT_EXT
:
181 case GL_PRIMARY_COLOR_EXT
:
182 case GL_PREVIOUS_EXT
:
183 if (texUnit
->CombineSourceRGB
[s
] == source
)
185 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
186 texUnit
->CombineSourceRGB
[s
] = source
;
189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
194 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
198 case GL_SOURCE0_ALPHA_EXT
:
199 case GL_SOURCE1_ALPHA_EXT
:
200 case GL_SOURCE2_ALPHA_EXT
:
201 if (ctx
->Extensions
.EXT_texture_env_combine
) {
202 GLenum source
= (GLenum
) (GLint
) *param
;
203 GLuint s
= pname
- GL_SOURCE0_ALPHA_EXT
;
206 case GL_CONSTANT_EXT
:
207 case GL_PRIMARY_COLOR_EXT
:
208 case GL_PREVIOUS_EXT
:
209 if (texUnit
->CombineSourceA
[s
] == source
) return;
210 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
211 texUnit
->CombineSourceA
[s
] = source
;
214 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
219 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
223 case GL_OPERAND0_RGB_EXT
:
224 case GL_OPERAND1_RGB_EXT
:
225 if (ctx
->Extensions
.EXT_texture_env_combine
) {
226 GLenum operand
= (GLenum
) (GLint
) *param
;
227 GLuint s
= pname
- GL_OPERAND0_RGB_EXT
;
230 case GL_ONE_MINUS_SRC_COLOR
:
232 case GL_ONE_MINUS_SRC_ALPHA
:
233 if (texUnit
->CombineOperandRGB
[s
] == operand
)
235 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
236 texUnit
->CombineOperandRGB
[s
] = operand
;
239 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
244 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
248 case GL_OPERAND0_ALPHA_EXT
:
249 case GL_OPERAND1_ALPHA_EXT
:
250 if (ctx
->Extensions
.EXT_texture_env_combine
) {
251 GLenum operand
= (GLenum
) (GLint
) *param
;
254 case GL_ONE_MINUS_SRC_ALPHA
:
255 if (texUnit
->CombineOperandA
[pname
-GL_OPERAND0_ALPHA_EXT
] ==
258 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
259 texUnit
->CombineOperandA
[pname
-GL_OPERAND0_ALPHA_EXT
] = operand
;
262 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
267 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
271 case GL_OPERAND2_RGB_EXT
:
272 if (ctx
->Extensions
.EXT_texture_env_combine
) {
273 GLenum operand
= (GLenum
) (GLint
) *param
;
276 if (texUnit
->CombineOperandRGB
[2] == operand
)
278 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
279 texUnit
->CombineOperandRGB
[2] = operand
;
281 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
286 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
290 case GL_OPERAND2_ALPHA_EXT
:
291 if (ctx
->Extensions
.EXT_texture_env_combine
) {
292 GLenum operand
= (GLenum
) (GLint
) *param
;
295 if (texUnit
->CombineOperandA
[2] == operand
)
297 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
298 texUnit
->CombineOperandA
[2] = operand
;
301 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
306 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
310 case GL_RGB_SCALE_EXT
:
311 if (ctx
->Extensions
.EXT_texture_env_combine
) {
316 else if (*param
== 2.0) {
319 else if (*param
== 4.0) {
323 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
326 if (texUnit
->CombineScaleShiftRGB
== newshift
)
328 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
329 texUnit
->CombineScaleShiftRGB
= newshift
;
332 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
337 if (ctx
->Extensions
.EXT_texture_env_combine
) {
342 else if (*param
== 2.0) {
345 else if (*param
== 4.0) {
349 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
352 if (texUnit
->CombineScaleShiftA
== newshift
)
354 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
355 texUnit
->CombineScaleShiftA
= newshift
;
358 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
363 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
367 else if (target
==GL_TEXTURE_FILTER_CONTROL_EXT
) {
368 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
369 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param)" );
373 case GL_TEXTURE_LOD_BIAS_EXT
:
374 if (texUnit
->LodBias
== param
[0])
376 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
377 texUnit
->LodBias
= param
[0];
380 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
385 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
389 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
390 fprintf(stderr
, "glTexEnv %s %s %.1f(%s) ...\n",
391 _mesa_lookup_enum_by_nr(target
),
392 _mesa_lookup_enum_by_nr(pname
),
394 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
396 /* Tell device driver about the new texture environment */
397 if (ctx
->Driver
.TexEnv
) {
398 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
404 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
406 _mesa_TexEnvfv( target
, pname
, ¶m
);
412 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
415 p
[0] = (GLfloat
) param
;
416 p
[1] = p
[2] = p
[3] = 0.0;
417 _mesa_TexEnvfv( target
, pname
, p
);
422 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
425 p
[0] = INT_TO_FLOAT( param
[0] );
426 p
[1] = INT_TO_FLOAT( param
[1] );
427 p
[2] = INT_TO_FLOAT( param
[2] );
428 p
[3] = INT_TO_FLOAT( param
[3] );
429 _mesa_TexEnvfv( target
, pname
, p
);
434 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
436 GET_CURRENT_CONTEXT(ctx
);
437 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
438 ASSERT_OUTSIDE_BEGIN_END(ctx
);
440 if (target
!=GL_TEXTURE_ENV
) {
441 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
446 case GL_TEXTURE_ENV_MODE
:
447 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
449 case GL_TEXTURE_ENV_COLOR
:
450 COPY_4FV( params
, texUnit
->EnvColor
);
452 case GL_RGB_SCALE_EXT
:
453 if (ctx
->Extensions
.EXT_texture_env_combine
) {
454 if (texUnit
->CombineScaleShiftRGB
== 0)
456 else if (texUnit
->CombineScaleShiftRGB
== 1)
462 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
467 if (ctx
->Extensions
.EXT_texture_env_combine
) {
468 if (texUnit
->CombineScaleShiftA
== 0)
470 else if (texUnit
->CombineScaleShiftA
== 1)
476 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
481 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
487 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
489 GET_CURRENT_CONTEXT(ctx
);
490 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
491 ASSERT_OUTSIDE_BEGIN_END(ctx
);
493 if (target
!= GL_TEXTURE_ENV
) {
494 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
499 case GL_TEXTURE_ENV_MODE
:
500 *params
= (GLint
) texUnit
->EnvMode
;
502 case GL_TEXTURE_ENV_COLOR
:
503 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
504 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
505 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
506 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
508 case GL_COMBINE_RGB_EXT
:
509 if (ctx
->Extensions
.EXT_texture_env_combine
) {
510 *params
= (GLint
) texUnit
->CombineModeRGB
;
513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
516 case GL_COMBINE_ALPHA_EXT
:
517 if (ctx
->Extensions
.EXT_texture_env_combine
) {
518 *params
= (GLint
) texUnit
->CombineModeA
;
521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
524 case GL_SOURCE0_RGB_EXT
:
525 if (ctx
->Extensions
.EXT_texture_env_combine
) {
526 *params
= (GLint
) texUnit
->CombineSourceRGB
[0];
529 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
532 case GL_SOURCE1_RGB_EXT
:
533 if (ctx
->Extensions
.EXT_texture_env_combine
) {
534 *params
= (GLint
) texUnit
->CombineSourceRGB
[1];
537 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
540 case GL_SOURCE2_RGB_EXT
:
541 if (ctx
->Extensions
.EXT_texture_env_combine
) {
542 *params
= (GLint
) texUnit
->CombineSourceRGB
[2];
545 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
548 case GL_SOURCE0_ALPHA_EXT
:
549 if (ctx
->Extensions
.EXT_texture_env_combine
) {
550 *params
= (GLint
) texUnit
->CombineSourceA
[0];
553 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
556 case GL_SOURCE1_ALPHA_EXT
:
557 if (ctx
->Extensions
.EXT_texture_env_combine
) {
558 *params
= (GLint
) texUnit
->CombineSourceA
[1];
561 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
564 case GL_SOURCE2_ALPHA_EXT
:
565 if (ctx
->Extensions
.EXT_texture_env_combine
) {
566 *params
= (GLint
) texUnit
->CombineSourceA
[2];
569 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
572 case GL_OPERAND0_RGB_EXT
:
573 if (ctx
->Extensions
.EXT_texture_env_combine
) {
574 *params
= (GLint
) texUnit
->CombineOperandRGB
[0];
577 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
580 case GL_OPERAND1_RGB_EXT
:
581 if (ctx
->Extensions
.EXT_texture_env_combine
) {
582 *params
= (GLint
) texUnit
->CombineOperandRGB
[1];
585 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
588 case GL_OPERAND2_RGB_EXT
:
589 if (ctx
->Extensions
.EXT_texture_env_combine
) {
590 *params
= (GLint
) texUnit
->CombineOperandRGB
[2];
593 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
596 case GL_OPERAND0_ALPHA_EXT
:
597 if (ctx
->Extensions
.EXT_texture_env_combine
) {
598 *params
= (GLint
) texUnit
->CombineOperandA
[0];
601 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
604 case GL_OPERAND1_ALPHA_EXT
:
605 if (ctx
->Extensions
.EXT_texture_env_combine
) {
606 *params
= (GLint
) texUnit
->CombineOperandA
[1];
609 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
612 case GL_OPERAND2_ALPHA_EXT
:
613 if (ctx
->Extensions
.EXT_texture_env_combine
) {
614 *params
= (GLint
) texUnit
->CombineOperandA
[2];
617 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
621 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
628 /**********************************************************************/
629 /* Texture Parameters */
630 /**********************************************************************/
634 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
636 _mesa_TexParameterfv(target
, pname
, ¶m
);
641 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
643 GET_CURRENT_CONTEXT(ctx
);
644 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
645 GLenum eparam
= (GLenum
) (GLint
) params
[0];
646 struct gl_texture_object
*texObj
;
647 ASSERT_OUTSIDE_BEGIN_END(ctx
);
649 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
650 fprintf(stderr
, "texPARAM %s %s %d...\n",
651 _mesa_lookup_enum_by_nr(target
),
652 _mesa_lookup_enum_by_nr(pname
),
658 texObj
= texUnit
->Current1D
;
661 texObj
= texUnit
->Current2D
;
663 case GL_TEXTURE_3D_EXT
:
664 texObj
= texUnit
->Current3D
;
666 case GL_TEXTURE_CUBE_MAP_ARB
:
667 if (ctx
->Extensions
.ARB_texture_cube_map
) {
668 texObj
= texUnit
->CurrentCubeMap
;
673 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
678 case GL_TEXTURE_MIN_FILTER
:
679 /* A small optimization */
680 if (texObj
->MinFilter
== eparam
)
683 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
684 || eparam
==GL_NEAREST_MIPMAP_NEAREST
685 || eparam
==GL_LINEAR_MIPMAP_NEAREST
686 || eparam
==GL_NEAREST_MIPMAP_LINEAR
687 || eparam
==GL_LINEAR_MIPMAP_LINEAR
) {
688 texObj
->MinFilter
= eparam
;
691 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
695 case GL_TEXTURE_MAG_FILTER
:
696 /* A small optimization */
697 if (texObj
->MagFilter
== eparam
)
700 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
701 texObj
->MagFilter
= eparam
;
704 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
708 case GL_TEXTURE_WRAP_S
:
709 if (texObj
->WrapS
== eparam
)
712 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
713 texObj
->WrapS
= eparam
;
716 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
720 case GL_TEXTURE_WRAP_T
:
721 if (texObj
->WrapT
== eparam
)
724 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
725 texObj
->WrapT
= eparam
;
728 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
732 case GL_TEXTURE_WRAP_R_EXT
:
733 if (texObj
->WrapR
== eparam
)
736 if (eparam
==GL_CLAMP
|| eparam
==GL_REPEAT
|| eparam
==GL_CLAMP_TO_EDGE
) {
737 texObj
->WrapR
= eparam
;
740 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
743 case GL_TEXTURE_BORDER_COLOR
:
744 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[0], params
[0]);
745 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[1], params
[1]);
746 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[2], params
[2]);
747 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[3], params
[3]);
749 case GL_TEXTURE_MIN_LOD
:
750 texObj
->MinLod
= params
[0];
752 case GL_TEXTURE_MAX_LOD
:
753 texObj
->MaxLod
= params
[0];
755 case GL_TEXTURE_BASE_LEVEL
:
756 if (params
[0] < 0.0) {
757 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
760 texObj
->BaseLevel
= (GLint
) params
[0];
762 case GL_TEXTURE_MAX_LEVEL
:
763 if (params
[0] < 0.0) {
764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
767 texObj
->MaxLevel
= (GLint
) params
[0];
769 case GL_TEXTURE_PRIORITY
:
770 /* (keithh@netcomuk.co.uk) */
771 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
773 case GL_TEXTURE_COMPARE_SGIX
:
774 if (ctx
->Extensions
.SGIX_shadow
) {
775 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
778 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
782 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
783 if (ctx
->Extensions
.SGIX_shadow
) {
784 GLenum op
= (GLenum
) params
[0];
785 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
786 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
787 texObj
->CompareOperator
= op
;
790 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
794 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
798 case GL_SHADOW_AMBIENT_SGIX
:
799 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
800 UNCLAMPED_FLOAT_TO_CHAN(texObj
->ShadowAmbient
, params
[0]);
803 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
808 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
812 ctx
->NewState
|= _NEW_TEXTURE
;
813 texObj
->Complete
= GL_FALSE
;
815 if (ctx
->Driver
.TexParameter
) {
816 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
822 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
825 fparam
[0] = (GLfloat
) param
;
826 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
827 _mesa_TexParameterfv(target
, pname
, fparam
);
831 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
834 fparam
[0] = (GLfloat
) params
[0];
835 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
836 _mesa_TexParameterfv(target
, pname
, fparam
);
841 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
842 GLenum pname
, GLfloat
*params
)
845 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
846 *params
= (GLfloat
) iparam
;
851 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
855 case GL_PROXY_TEXTURE_1D
:
858 case GL_PROXY_TEXTURE_2D
:
861 case GL_PROXY_TEXTURE_3D
:
863 case GL_TEXTURE_CUBE_MAP_ARB
:
864 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
865 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
867 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
874 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
875 GLenum pname
, GLint
*params
)
877 GET_CURRENT_CONTEXT(ctx
);
878 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
879 const struct gl_texture_image
*img
= NULL
;
882 ASSERT_OUTSIDE_BEGIN_END(ctx
);
884 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
885 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
889 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
890 if (dimensions
== 0) {
891 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
895 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
897 if (pname
== GL_TEXTURE_COMPONENTS
)
904 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
905 (target
== GL_PROXY_TEXTURE_2D
) ||
906 (target
== GL_PROXY_TEXTURE_3D
) ||
907 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
910 case GL_TEXTURE_WIDTH
:
911 *params
= img
->Width
;
913 case GL_TEXTURE_HEIGHT
:
914 *params
= img
->Height
;
916 case GL_TEXTURE_DEPTH
:
917 *params
= img
->Depth
;
919 case GL_TEXTURE_COMPONENTS
:
920 *params
= img
->IntFormat
;
922 case GL_TEXTURE_BORDER
:
923 *params
= img
->Border
;
925 case GL_TEXTURE_RED_SIZE
:
926 *params
= img
->RedBits
;
928 case GL_TEXTURE_GREEN_SIZE
:
929 *params
= img
->GreenBits
;
931 case GL_TEXTURE_BLUE_SIZE
:
932 *params
= img
->BlueBits
;
934 case GL_TEXTURE_ALPHA_SIZE
:
935 *params
= img
->AlphaBits
;
937 case GL_TEXTURE_INTENSITY_SIZE
:
938 *params
= img
->IntensityBits
;
940 case GL_TEXTURE_LUMINANCE_SIZE
:
941 *params
= img
->LuminanceBits
;
943 case GL_TEXTURE_INDEX_SIZE_EXT
:
944 *params
= img
->IndexBits
;
947 /* XXX this isn't in the GL_SGIX_depth_texture spec
948 * but seems appropriate.
950 if (ctx
->Extensions
.SGIX_depth_texture
)
951 *params
= img
->DepthBits
;
953 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
956 /* GL_ARB_texture_compression */
957 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
:
958 if (ctx
->Extensions
.ARB_texture_compression
) {
959 if (img
->IsCompressed
&& !isProxy
)
960 *params
= img
->CompressedSize
;
962 _mesa_error(ctx
, GL_INVALID_OPERATION
,
963 "glGetTexLevelParameter[if]v(pname)");
966 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
969 case GL_TEXTURE_COMPRESSED_ARB
:
970 if (ctx
->Extensions
.ARB_texture_compression
) {
971 *params
= (GLint
) img
->IsCompressed
;
974 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
979 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
986 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
988 GET_CURRENT_CONTEXT(ctx
);
989 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
990 struct gl_texture_object
*obj
;
991 ASSERT_OUTSIDE_BEGIN_END(ctx
);
993 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
995 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1000 case GL_TEXTURE_MAG_FILTER
:
1001 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1003 case GL_TEXTURE_MIN_FILTER
:
1004 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1006 case GL_TEXTURE_WRAP_S
:
1007 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1009 case GL_TEXTURE_WRAP_T
:
1010 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1012 case GL_TEXTURE_WRAP_R_EXT
:
1013 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1015 case GL_TEXTURE_BORDER_COLOR
:
1016 params
[0] = obj
->BorderColor
[0] / CHAN_MAXF
;
1017 params
[1] = obj
->BorderColor
[1] / CHAN_MAXF
;
1018 params
[2] = obj
->BorderColor
[2] / CHAN_MAXF
;
1019 params
[3] = obj
->BorderColor
[3] / CHAN_MAXF
;
1021 case GL_TEXTURE_RESIDENT
:
1024 if (ctx
->Driver
.IsTextureResident
)
1025 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1028 *params
= ENUM_TO_FLOAT(resident
);
1031 case GL_TEXTURE_PRIORITY
:
1032 *params
= obj
->Priority
;
1034 case GL_TEXTURE_MIN_LOD
:
1035 *params
= obj
->MinLod
;
1037 case GL_TEXTURE_MAX_LOD
:
1038 *params
= obj
->MaxLod
;
1040 case GL_TEXTURE_BASE_LEVEL
:
1041 *params
= (GLfloat
) obj
->BaseLevel
;
1043 case GL_TEXTURE_MAX_LEVEL
:
1044 *params
= (GLfloat
) obj
->MaxLevel
;
1046 case GL_TEXTURE_COMPARE_SGIX
:
1047 if (ctx
->Extensions
.SGIX_shadow
) {
1048 *params
= (GLfloat
) obj
->CompareFlag
;
1051 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1055 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1056 if (ctx
->Extensions
.SGIX_shadow
) {
1057 *params
= (GLfloat
) obj
->CompareOperator
;
1060 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1064 case GL_SHADOW_AMBIENT_SGIX
:
1065 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1066 *params
= CHAN_TO_FLOAT(obj
->ShadowAmbient
);
1069 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)");
1074 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1080 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1082 GET_CURRENT_CONTEXT(ctx
);
1083 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1084 struct gl_texture_object
*obj
;
1085 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1087 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1089 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1094 case GL_TEXTURE_MAG_FILTER
:
1095 *params
= (GLint
) obj
->MagFilter
;
1097 case GL_TEXTURE_MIN_FILTER
:
1098 *params
= (GLint
) obj
->MinFilter
;
1100 case GL_TEXTURE_WRAP_S
:
1101 *params
= (GLint
) obj
->WrapS
;
1103 case GL_TEXTURE_WRAP_T
:
1104 *params
= (GLint
) obj
->WrapT
;
1106 case GL_TEXTURE_WRAP_R_EXT
:
1107 *params
= (GLint
) obj
->WrapR
;
1109 case GL_TEXTURE_BORDER_COLOR
:
1112 color
[0] = obj
->BorderColor
[0] / CHAN_MAXF
;
1113 color
[1] = obj
->BorderColor
[1] / CHAN_MAXF
;
1114 color
[2] = obj
->BorderColor
[2] / CHAN_MAXF
;
1115 color
[3] = obj
->BorderColor
[3] / CHAN_MAXF
;
1116 params
[0] = FLOAT_TO_INT( color
[0] );
1117 params
[1] = FLOAT_TO_INT( color
[1] );
1118 params
[2] = FLOAT_TO_INT( color
[2] );
1119 params
[3] = FLOAT_TO_INT( color
[3] );
1122 case GL_TEXTURE_RESIDENT
:
1125 if (ctx
->Driver
.IsTextureResident
)
1126 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1129 *params
= (GLint
) resident
;
1132 case GL_TEXTURE_PRIORITY
:
1133 *params
= (GLint
) obj
->Priority
;
1135 case GL_TEXTURE_MIN_LOD
:
1136 *params
= (GLint
) obj
->MinLod
;
1138 case GL_TEXTURE_MAX_LOD
:
1139 *params
= (GLint
) obj
->MaxLod
;
1141 case GL_TEXTURE_BASE_LEVEL
:
1142 *params
= obj
->BaseLevel
;
1144 case GL_TEXTURE_MAX_LEVEL
:
1145 *params
= obj
->MaxLevel
;
1147 case GL_TEXTURE_COMPARE_SGIX
:
1148 if (ctx
->Extensions
.SGIX_shadow
) {
1149 *params
= (GLint
) obj
->CompareFlag
;
1152 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1156 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1157 if (ctx
->Extensions
.SGIX_shadow
) {
1158 *params
= (GLint
) obj
->CompareOperator
;
1161 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1165 case GL_SHADOW_AMBIENT_SGIX
:
1166 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1168 *params
= (GLint
) CHAN_TO_FLOAT(obj
->ShadowAmbient
);
1171 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)");
1176 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1183 /**********************************************************************/
1184 /* Texture Coord Generation */
1185 /**********************************************************************/
1189 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
1191 GET_CURRENT_CONTEXT(ctx
);
1192 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1193 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1194 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1196 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1197 fprintf(stderr
, "texGEN %s %s %x...\n",
1198 _mesa_lookup_enum_by_nr(coord
),
1199 _mesa_lookup_enum_by_nr(pname
),
1204 if (pname
==GL_TEXTURE_GEN_MODE
) {
1205 GLenum mode
= (GLenum
) (GLint
) *params
;
1208 case GL_OBJECT_LINEAR
:
1209 bits
= TEXGEN_OBJ_LINEAR
;
1212 bits
= TEXGEN_EYE_LINEAR
;
1214 case GL_REFLECTION_MAP_NV
:
1215 bits
= TEXGEN_REFLECTION_MAP_NV
;
1217 case GL_NORMAL_MAP_NV
:
1218 bits
= TEXGEN_NORMAL_MAP_NV
;
1221 bits
= TEXGEN_SPHERE_MAP
;
1224 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1227 if (texUnit
->GenModeS
== mode
)
1229 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1230 texUnit
->GenModeS
= mode
;
1231 texUnit
->_GenBitS
= bits
;
1233 else if (pname
==GL_OBJECT_PLANE
) {
1234 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
1236 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1237 texUnit
->ObjectPlaneS
[0] = params
[0];
1238 texUnit
->ObjectPlaneS
[1] = params
[1];
1239 texUnit
->ObjectPlaneS
[2] = params
[2];
1240 texUnit
->ObjectPlaneS
[3] = params
[3];
1242 else if (pname
==GL_EYE_PLANE
) {
1245 /* Transform plane equation by the inverse modelview matrix */
1246 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1247 _math_matrix_analyse( &ctx
->ModelView
);
1249 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1250 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
1252 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1253 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
1256 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1261 if (pname
==GL_TEXTURE_GEN_MODE
) {
1262 GLenum mode
= (GLenum
) (GLint
) *params
;
1265 case GL_OBJECT_LINEAR
:
1266 bitt
= TEXGEN_OBJ_LINEAR
;
1269 bitt
= TEXGEN_EYE_LINEAR
;
1271 case GL_REFLECTION_MAP_NV
:
1272 bitt
= TEXGEN_REFLECTION_MAP_NV
;
1274 case GL_NORMAL_MAP_NV
:
1275 bitt
= TEXGEN_NORMAL_MAP_NV
;
1278 bitt
= TEXGEN_SPHERE_MAP
;
1281 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1284 if (texUnit
->GenModeT
== mode
)
1286 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1287 texUnit
->GenModeT
= mode
;
1288 texUnit
->_GenBitT
= bitt
;
1290 else if (pname
==GL_OBJECT_PLANE
) {
1291 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
1293 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1294 texUnit
->ObjectPlaneT
[0] = params
[0];
1295 texUnit
->ObjectPlaneT
[1] = params
[1];
1296 texUnit
->ObjectPlaneT
[2] = params
[2];
1297 texUnit
->ObjectPlaneT
[3] = params
[3];
1299 else if (pname
==GL_EYE_PLANE
) {
1301 /* Transform plane equation by the inverse modelview matrix */
1302 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1303 _math_matrix_analyse( &ctx
->ModelView
);
1305 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1306 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
1308 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1309 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
1312 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1317 if (pname
==GL_TEXTURE_GEN_MODE
) {
1318 GLenum mode
= (GLenum
) (GLint
) *params
;
1321 case GL_OBJECT_LINEAR
:
1322 bitr
= TEXGEN_OBJ_LINEAR
;
1324 case GL_REFLECTION_MAP_NV
:
1325 bitr
= TEXGEN_REFLECTION_MAP_NV
;
1327 case GL_NORMAL_MAP_NV
:
1328 bitr
= TEXGEN_NORMAL_MAP_NV
;
1331 bitr
= TEXGEN_EYE_LINEAR
;
1334 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1337 if (texUnit
->GenModeR
== mode
)
1339 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1340 texUnit
->GenModeR
= mode
;
1341 texUnit
->_GenBitR
= bitr
;
1343 else if (pname
==GL_OBJECT_PLANE
) {
1344 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
1346 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1347 texUnit
->ObjectPlaneR
[0] = params
[0];
1348 texUnit
->ObjectPlaneR
[1] = params
[1];
1349 texUnit
->ObjectPlaneR
[2] = params
[2];
1350 texUnit
->ObjectPlaneR
[3] = params
[3];
1352 else if (pname
==GL_EYE_PLANE
) {
1354 /* Transform plane equation by the inverse modelview matrix */
1355 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1356 _math_matrix_analyse( &ctx
->ModelView
);
1358 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1359 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
1361 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1362 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
1365 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1370 if (pname
==GL_TEXTURE_GEN_MODE
) {
1371 GLenum mode
= (GLenum
) (GLint
) *params
;
1374 case GL_OBJECT_LINEAR
:
1375 bitq
= TEXGEN_OBJ_LINEAR
;
1378 bitq
= TEXGEN_EYE_LINEAR
;
1381 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1384 if (texUnit
->GenModeQ
== mode
)
1386 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1387 texUnit
->GenModeQ
= mode
;
1388 texUnit
->_GenBitQ
= bitq
;
1390 else if (pname
==GL_OBJECT_PLANE
) {
1391 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
1393 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1394 texUnit
->ObjectPlaneQ
[0] = params
[0];
1395 texUnit
->ObjectPlaneQ
[1] = params
[1];
1396 texUnit
->ObjectPlaneQ
[2] = params
[2];
1397 texUnit
->ObjectPlaneQ
[3] = params
[3];
1399 else if (pname
==GL_EYE_PLANE
) {
1401 /* Transform plane equation by the inverse modelview matrix */
1402 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1403 _math_matrix_analyse( &ctx
->ModelView
);
1405 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1406 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
1408 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1409 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
1412 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1417 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
1421 if (ctx
->Driver
.TexGen
)
1422 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
1427 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
1434 _mesa_TexGenfv(coord
, pname
, p
);
1439 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
1441 GLfloat p
= (GLfloat
) param
;
1442 _mesa_TexGenfv( coord
, pname
, &p
);
1447 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
1454 _mesa_TexGenfv( coord
, pname
, p
);
1459 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
1461 _mesa_TexGenfv(coord
, pname
, ¶m
);
1466 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
1468 _mesa_TexGeniv( coord
, pname
, ¶m
);
1474 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
1476 GET_CURRENT_CONTEXT(ctx
);
1477 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1478 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1479 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1483 if (pname
==GL_TEXTURE_GEN_MODE
) {
1484 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
1486 else if (pname
==GL_OBJECT_PLANE
) {
1487 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1489 else if (pname
==GL_EYE_PLANE
) {
1490 COPY_4V( params
, texUnit
->EyePlaneS
);
1493 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1498 if (pname
==GL_TEXTURE_GEN_MODE
) {
1499 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
1501 else if (pname
==GL_OBJECT_PLANE
) {
1502 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1504 else if (pname
==GL_EYE_PLANE
) {
1505 COPY_4V( params
, texUnit
->EyePlaneT
);
1508 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1513 if (pname
==GL_TEXTURE_GEN_MODE
) {
1514 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
1516 else if (pname
==GL_OBJECT_PLANE
) {
1517 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1519 else if (pname
==GL_EYE_PLANE
) {
1520 COPY_4V( params
, texUnit
->EyePlaneR
);
1523 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1528 if (pname
==GL_TEXTURE_GEN_MODE
) {
1529 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
1531 else if (pname
==GL_OBJECT_PLANE
) {
1532 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1534 else if (pname
==GL_EYE_PLANE
) {
1535 COPY_4V( params
, texUnit
->EyePlaneQ
);
1538 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1543 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
1551 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
1553 GET_CURRENT_CONTEXT(ctx
);
1554 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1555 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1556 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1560 if (pname
==GL_TEXTURE_GEN_MODE
) {
1561 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
1563 else if (pname
==GL_OBJECT_PLANE
) {
1564 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1566 else if (pname
==GL_EYE_PLANE
) {
1567 COPY_4V( params
, texUnit
->EyePlaneS
);
1570 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1575 if (pname
==GL_TEXTURE_GEN_MODE
) {
1576 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1578 else if (pname
==GL_OBJECT_PLANE
) {
1579 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1581 else if (pname
==GL_EYE_PLANE
) {
1582 COPY_4V( params
, texUnit
->EyePlaneT
);
1585 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1590 if (pname
==GL_TEXTURE_GEN_MODE
) {
1591 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1593 else if (pname
==GL_OBJECT_PLANE
) {
1594 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1596 else if (pname
==GL_EYE_PLANE
) {
1597 COPY_4V( params
, texUnit
->EyePlaneR
);
1600 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1605 if (pname
==GL_TEXTURE_GEN_MODE
) {
1606 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1608 else if (pname
==GL_OBJECT_PLANE
) {
1609 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1611 else if (pname
==GL_EYE_PLANE
) {
1612 COPY_4V( params
, texUnit
->EyePlaneQ
);
1615 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1620 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1628 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1630 GET_CURRENT_CONTEXT(ctx
);
1631 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1632 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1633 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1637 if (pname
==GL_TEXTURE_GEN_MODE
) {
1638 params
[0] = texUnit
->GenModeS
;
1640 else if (pname
==GL_OBJECT_PLANE
) {
1641 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1642 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1643 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1644 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1646 else if (pname
==GL_EYE_PLANE
) {
1647 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1648 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1649 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1650 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1653 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1658 if (pname
==GL_TEXTURE_GEN_MODE
) {
1659 params
[0] = texUnit
->GenModeT
;
1661 else if (pname
==GL_OBJECT_PLANE
) {
1662 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1663 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1664 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1665 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1667 else if (pname
==GL_EYE_PLANE
) {
1668 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1669 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1670 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1671 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1674 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1679 if (pname
==GL_TEXTURE_GEN_MODE
) {
1680 params
[0] = texUnit
->GenModeR
;
1682 else if (pname
==GL_OBJECT_PLANE
) {
1683 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1684 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1685 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1686 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1688 else if (pname
==GL_EYE_PLANE
) {
1689 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1690 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1691 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1692 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1695 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1700 if (pname
==GL_TEXTURE_GEN_MODE
) {
1701 params
[0] = texUnit
->GenModeQ
;
1703 else if (pname
==GL_OBJECT_PLANE
) {
1704 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1705 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1706 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1707 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1709 else if (pname
==GL_EYE_PLANE
) {
1710 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1711 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1712 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1713 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1716 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1721 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1727 /* GL_ARB_multitexture */
1729 _mesa_ActiveTextureARB( GLenum target
)
1731 GET_CURRENT_CONTEXT(ctx
);
1732 GLuint texUnit
= target
- GL_TEXTURE0_ARB
;
1733 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1735 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1736 fprintf(stderr
, "glActiveTexture %s\n",
1737 _mesa_lookup_enum_by_nr(target
));
1739 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
1740 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1744 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1745 ctx
->Texture
.CurrentUnit
= texUnit
;
1746 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1747 if (ctx
->Driver
.ActiveTexture
) {
1748 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1753 /* GL_ARB_multitexture */
1755 _mesa_ClientActiveTextureARB( GLenum target
)
1757 GET_CURRENT_CONTEXT(ctx
);
1758 GLuint texUnit
= target
- GL_TEXTURE0_ARB
;
1759 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1761 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
1762 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1766 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1767 ctx
->Array
.ActiveTexture
= texUnit
;