1 /* $Id: texstate.c,v 1.37 2001/03/18 08:53:50 gareth 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_MAX_ANISOTROPY_EXT
:
774 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
775 if (params
[0] < 1.0) {
776 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
779 texObj
->MaxAnisotropy
= params
[0];
782 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
786 case GL_TEXTURE_COMPARE_SGIX
:
787 if (ctx
->Extensions
.SGIX_shadow
) {
788 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
791 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
795 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
796 if (ctx
->Extensions
.SGIX_shadow
) {
797 GLenum op
= (GLenum
) params
[0];
798 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
799 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
800 texObj
->CompareOperator
= op
;
803 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
807 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
811 case GL_SHADOW_AMBIENT_SGIX
:
812 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
813 UNCLAMPED_FLOAT_TO_CHAN(texObj
->ShadowAmbient
, params
[0]);
816 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)");
821 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(pname)" );
825 ctx
->NewState
|= _NEW_TEXTURE
;
826 texObj
->Complete
= GL_FALSE
;
828 if (ctx
->Driver
.TexParameter
) {
829 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
835 _mesa_TexParameteri( GLenum target
, GLenum pname
, const GLint param
)
838 fparam
[0] = (GLfloat
) param
;
839 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
840 _mesa_TexParameterfv(target
, pname
, fparam
);
844 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
847 fparam
[0] = (GLfloat
) params
[0];
848 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
849 _mesa_TexParameterfv(target
, pname
, fparam
);
854 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
855 GLenum pname
, GLfloat
*params
)
858 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
859 *params
= (GLfloat
) iparam
;
864 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
868 case GL_PROXY_TEXTURE_1D
:
871 case GL_PROXY_TEXTURE_2D
:
874 case GL_PROXY_TEXTURE_3D
:
876 case GL_TEXTURE_CUBE_MAP_ARB
:
877 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
878 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
880 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
887 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
888 GLenum pname
, GLint
*params
)
890 GET_CURRENT_CONTEXT(ctx
);
891 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
892 const struct gl_texture_image
*img
= NULL
;
895 ASSERT_OUTSIDE_BEGIN_END(ctx
);
897 if (level
< 0 || level
>= ctx
->Const
.MaxTextureLevels
) {
898 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
902 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
903 if (dimensions
== 0) {
904 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
908 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
910 if (pname
== GL_TEXTURE_COMPONENTS
)
917 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
918 (target
== GL_PROXY_TEXTURE_2D
) ||
919 (target
== GL_PROXY_TEXTURE_3D
) ||
920 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
923 case GL_TEXTURE_WIDTH
:
924 *params
= img
->Width
;
926 case GL_TEXTURE_HEIGHT
:
927 *params
= img
->Height
;
929 case GL_TEXTURE_DEPTH
:
930 *params
= img
->Depth
;
932 case GL_TEXTURE_COMPONENTS
:
933 *params
= img
->IntFormat
;
935 case GL_TEXTURE_BORDER
:
936 *params
= img
->Border
;
938 case GL_TEXTURE_RED_SIZE
:
939 *params
= img
->TexFormat
->RedBits
;
941 case GL_TEXTURE_GREEN_SIZE
:
942 *params
= img
->TexFormat
->GreenBits
;
944 case GL_TEXTURE_BLUE_SIZE
:
945 *params
= img
->TexFormat
->BlueBits
;
947 case GL_TEXTURE_ALPHA_SIZE
:
948 *params
= img
->TexFormat
->AlphaBits
;
950 case GL_TEXTURE_INTENSITY_SIZE
:
951 *params
= img
->TexFormat
->IntensityBits
;
953 case GL_TEXTURE_LUMINANCE_SIZE
:
954 *params
= img
->TexFormat
->LuminanceBits
;
956 case GL_TEXTURE_INDEX_SIZE_EXT
:
957 *params
= img
->TexFormat
->IndexBits
;
960 /* XXX this isn't in the GL_SGIX_depth_texture spec
961 * but seems appropriate.
963 if (ctx
->Extensions
.SGIX_depth_texture
)
964 *params
= img
->TexFormat
->DepthBits
;
966 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
969 /* GL_ARB_texture_compression */
970 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
:
971 if (ctx
->Extensions
.ARB_texture_compression
) {
972 if (img
->IsCompressed
&& !isProxy
)
973 *params
= img
->CompressedSize
;
975 _mesa_error(ctx
, GL_INVALID_OPERATION
,
976 "glGetTexLevelParameter[if]v(pname)");
979 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
982 case GL_TEXTURE_COMPRESSED_ARB
:
983 if (ctx
->Extensions
.ARB_texture_compression
) {
984 *params
= (GLint
) img
->IsCompressed
;
987 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
992 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
999 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1001 GET_CURRENT_CONTEXT(ctx
);
1002 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1003 struct gl_texture_object
*obj
;
1004 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1006 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1008 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1013 case GL_TEXTURE_MAG_FILTER
:
1014 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1016 case GL_TEXTURE_MIN_FILTER
:
1017 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1019 case GL_TEXTURE_WRAP_S
:
1020 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1022 case GL_TEXTURE_WRAP_T
:
1023 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1025 case GL_TEXTURE_WRAP_R_EXT
:
1026 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1028 case GL_TEXTURE_BORDER_COLOR
:
1029 params
[0] = obj
->BorderColor
[0] / CHAN_MAXF
;
1030 params
[1] = obj
->BorderColor
[1] / CHAN_MAXF
;
1031 params
[2] = obj
->BorderColor
[2] / CHAN_MAXF
;
1032 params
[3] = obj
->BorderColor
[3] / CHAN_MAXF
;
1034 case GL_TEXTURE_RESIDENT
:
1037 if (ctx
->Driver
.IsTextureResident
)
1038 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1041 *params
= ENUM_TO_FLOAT(resident
);
1044 case GL_TEXTURE_PRIORITY
:
1045 *params
= obj
->Priority
;
1047 case GL_TEXTURE_MIN_LOD
:
1048 *params
= obj
->MinLod
;
1050 case GL_TEXTURE_MAX_LOD
:
1051 *params
= obj
->MaxLod
;
1053 case GL_TEXTURE_BASE_LEVEL
:
1054 *params
= (GLfloat
) obj
->BaseLevel
;
1056 case GL_TEXTURE_MAX_LEVEL
:
1057 *params
= (GLfloat
) obj
->MaxLevel
;
1059 case GL_TEXTURE_COMPARE_SGIX
:
1060 if (ctx
->Extensions
.SGIX_shadow
) {
1061 *params
= (GLfloat
) obj
->CompareFlag
;
1064 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1068 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1069 if (ctx
->Extensions
.SGIX_shadow
) {
1070 *params
= (GLfloat
) obj
->CompareOperator
;
1073 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1077 case GL_SHADOW_AMBIENT_SGIX
:
1078 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1079 *params
= CHAN_TO_FLOAT(obj
->ShadowAmbient
);
1082 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)");
1087 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1093 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1095 GET_CURRENT_CONTEXT(ctx
);
1096 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1097 struct gl_texture_object
*obj
;
1098 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1100 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1102 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1107 case GL_TEXTURE_MAG_FILTER
:
1108 *params
= (GLint
) obj
->MagFilter
;
1110 case GL_TEXTURE_MIN_FILTER
:
1111 *params
= (GLint
) obj
->MinFilter
;
1113 case GL_TEXTURE_WRAP_S
:
1114 *params
= (GLint
) obj
->WrapS
;
1116 case GL_TEXTURE_WRAP_T
:
1117 *params
= (GLint
) obj
->WrapT
;
1119 case GL_TEXTURE_WRAP_R_EXT
:
1120 *params
= (GLint
) obj
->WrapR
;
1122 case GL_TEXTURE_BORDER_COLOR
:
1125 color
[0] = obj
->BorderColor
[0] / CHAN_MAXF
;
1126 color
[1] = obj
->BorderColor
[1] / CHAN_MAXF
;
1127 color
[2] = obj
->BorderColor
[2] / CHAN_MAXF
;
1128 color
[3] = obj
->BorderColor
[3] / CHAN_MAXF
;
1129 params
[0] = FLOAT_TO_INT( color
[0] );
1130 params
[1] = FLOAT_TO_INT( color
[1] );
1131 params
[2] = FLOAT_TO_INT( color
[2] );
1132 params
[3] = FLOAT_TO_INT( color
[3] );
1135 case GL_TEXTURE_RESIDENT
:
1138 if (ctx
->Driver
.IsTextureResident
)
1139 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1142 *params
= (GLint
) resident
;
1145 case GL_TEXTURE_PRIORITY
:
1146 *params
= (GLint
) obj
->Priority
;
1148 case GL_TEXTURE_MIN_LOD
:
1149 *params
= (GLint
) obj
->MinLod
;
1151 case GL_TEXTURE_MAX_LOD
:
1152 *params
= (GLint
) obj
->MaxLod
;
1154 case GL_TEXTURE_BASE_LEVEL
:
1155 *params
= obj
->BaseLevel
;
1157 case GL_TEXTURE_MAX_LEVEL
:
1158 *params
= obj
->MaxLevel
;
1160 case GL_TEXTURE_COMPARE_SGIX
:
1161 if (ctx
->Extensions
.SGIX_shadow
) {
1162 *params
= (GLint
) obj
->CompareFlag
;
1165 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1169 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1170 if (ctx
->Extensions
.SGIX_shadow
) {
1171 *params
= (GLint
) obj
->CompareOperator
;
1174 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1178 case GL_SHADOW_AMBIENT_SGIX
:
1179 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1181 *params
= (GLint
) CHAN_TO_FLOAT(obj
->ShadowAmbient
);
1184 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)");
1189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1196 /**********************************************************************/
1197 /* Texture Coord Generation */
1198 /**********************************************************************/
1202 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
1204 GET_CURRENT_CONTEXT(ctx
);
1205 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1206 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1207 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1209 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1210 fprintf(stderr
, "texGEN %s %s %x...\n",
1211 _mesa_lookup_enum_by_nr(coord
),
1212 _mesa_lookup_enum_by_nr(pname
),
1217 if (pname
==GL_TEXTURE_GEN_MODE
) {
1218 GLenum mode
= (GLenum
) (GLint
) *params
;
1221 case GL_OBJECT_LINEAR
:
1222 bits
= TEXGEN_OBJ_LINEAR
;
1225 bits
= TEXGEN_EYE_LINEAR
;
1227 case GL_REFLECTION_MAP_NV
:
1228 bits
= TEXGEN_REFLECTION_MAP_NV
;
1230 case GL_NORMAL_MAP_NV
:
1231 bits
= TEXGEN_NORMAL_MAP_NV
;
1234 bits
= TEXGEN_SPHERE_MAP
;
1237 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1240 if (texUnit
->GenModeS
== mode
)
1242 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1243 texUnit
->GenModeS
= mode
;
1244 texUnit
->_GenBitS
= bits
;
1246 else if (pname
==GL_OBJECT_PLANE
) {
1247 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
1249 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1250 texUnit
->ObjectPlaneS
[0] = params
[0];
1251 texUnit
->ObjectPlaneS
[1] = params
[1];
1252 texUnit
->ObjectPlaneS
[2] = params
[2];
1253 texUnit
->ObjectPlaneS
[3] = params
[3];
1255 else if (pname
==GL_EYE_PLANE
) {
1258 /* Transform plane equation by the inverse modelview matrix */
1259 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1260 _math_matrix_analyse( &ctx
->ModelView
);
1262 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1263 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
1265 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1266 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
1269 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1274 if (pname
==GL_TEXTURE_GEN_MODE
) {
1275 GLenum mode
= (GLenum
) (GLint
) *params
;
1278 case GL_OBJECT_LINEAR
:
1279 bitt
= TEXGEN_OBJ_LINEAR
;
1282 bitt
= TEXGEN_EYE_LINEAR
;
1284 case GL_REFLECTION_MAP_NV
:
1285 bitt
= TEXGEN_REFLECTION_MAP_NV
;
1287 case GL_NORMAL_MAP_NV
:
1288 bitt
= TEXGEN_NORMAL_MAP_NV
;
1291 bitt
= TEXGEN_SPHERE_MAP
;
1294 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1297 if (texUnit
->GenModeT
== mode
)
1299 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1300 texUnit
->GenModeT
= mode
;
1301 texUnit
->_GenBitT
= bitt
;
1303 else if (pname
==GL_OBJECT_PLANE
) {
1304 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
1306 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1307 texUnit
->ObjectPlaneT
[0] = params
[0];
1308 texUnit
->ObjectPlaneT
[1] = params
[1];
1309 texUnit
->ObjectPlaneT
[2] = params
[2];
1310 texUnit
->ObjectPlaneT
[3] = params
[3];
1312 else if (pname
==GL_EYE_PLANE
) {
1314 /* Transform plane equation by the inverse modelview matrix */
1315 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1316 _math_matrix_analyse( &ctx
->ModelView
);
1318 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1319 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
1321 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1322 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
1325 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1330 if (pname
==GL_TEXTURE_GEN_MODE
) {
1331 GLenum mode
= (GLenum
) (GLint
) *params
;
1334 case GL_OBJECT_LINEAR
:
1335 bitr
= TEXGEN_OBJ_LINEAR
;
1337 case GL_REFLECTION_MAP_NV
:
1338 bitr
= TEXGEN_REFLECTION_MAP_NV
;
1340 case GL_NORMAL_MAP_NV
:
1341 bitr
= TEXGEN_NORMAL_MAP_NV
;
1344 bitr
= TEXGEN_EYE_LINEAR
;
1347 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1350 if (texUnit
->GenModeR
== mode
)
1352 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1353 texUnit
->GenModeR
= mode
;
1354 texUnit
->_GenBitR
= bitr
;
1356 else if (pname
==GL_OBJECT_PLANE
) {
1357 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
1359 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1360 texUnit
->ObjectPlaneR
[0] = params
[0];
1361 texUnit
->ObjectPlaneR
[1] = params
[1];
1362 texUnit
->ObjectPlaneR
[2] = params
[2];
1363 texUnit
->ObjectPlaneR
[3] = params
[3];
1365 else if (pname
==GL_EYE_PLANE
) {
1367 /* Transform plane equation by the inverse modelview matrix */
1368 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1369 _math_matrix_analyse( &ctx
->ModelView
);
1371 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1372 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
1374 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1375 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
1378 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1383 if (pname
==GL_TEXTURE_GEN_MODE
) {
1384 GLenum mode
= (GLenum
) (GLint
) *params
;
1387 case GL_OBJECT_LINEAR
:
1388 bitq
= TEXGEN_OBJ_LINEAR
;
1391 bitq
= TEXGEN_EYE_LINEAR
;
1394 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1397 if (texUnit
->GenModeQ
== mode
)
1399 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1400 texUnit
->GenModeQ
= mode
;
1401 texUnit
->_GenBitQ
= bitq
;
1403 else if (pname
==GL_OBJECT_PLANE
) {
1404 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
1406 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1407 texUnit
->ObjectPlaneQ
[0] = params
[0];
1408 texUnit
->ObjectPlaneQ
[1] = params
[1];
1409 texUnit
->ObjectPlaneQ
[2] = params
[2];
1410 texUnit
->ObjectPlaneQ
[3] = params
[3];
1412 else if (pname
==GL_EYE_PLANE
) {
1414 /* Transform plane equation by the inverse modelview matrix */
1415 if (ctx
->ModelView
.flags
& MAT_DIRTY_INVERSE
) {
1416 _math_matrix_analyse( &ctx
->ModelView
);
1418 _mesa_transform_vector( tmp
, params
, ctx
->ModelView
.inv
);
1419 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
1421 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1422 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
1425 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1430 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
1434 if (ctx
->Driver
.TexGen
)
1435 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
1440 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
1447 _mesa_TexGenfv(coord
, pname
, p
);
1452 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
1454 GLfloat p
= (GLfloat
) param
;
1455 _mesa_TexGenfv( coord
, pname
, &p
);
1460 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
1467 _mesa_TexGenfv( coord
, pname
, p
);
1472 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
1474 _mesa_TexGenfv(coord
, pname
, ¶m
);
1479 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
1481 _mesa_TexGeniv( coord
, pname
, ¶m
);
1487 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
1489 GET_CURRENT_CONTEXT(ctx
);
1490 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1491 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1492 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1496 if (pname
==GL_TEXTURE_GEN_MODE
) {
1497 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
1499 else if (pname
==GL_OBJECT_PLANE
) {
1500 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1502 else if (pname
==GL_EYE_PLANE
) {
1503 COPY_4V( params
, texUnit
->EyePlaneS
);
1506 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1511 if (pname
==GL_TEXTURE_GEN_MODE
) {
1512 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
1514 else if (pname
==GL_OBJECT_PLANE
) {
1515 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1517 else if (pname
==GL_EYE_PLANE
) {
1518 COPY_4V( params
, texUnit
->EyePlaneT
);
1521 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1526 if (pname
==GL_TEXTURE_GEN_MODE
) {
1527 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
1529 else if (pname
==GL_OBJECT_PLANE
) {
1530 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1532 else if (pname
==GL_EYE_PLANE
) {
1533 COPY_4V( params
, texUnit
->EyePlaneR
);
1536 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1541 if (pname
==GL_TEXTURE_GEN_MODE
) {
1542 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
1544 else if (pname
==GL_OBJECT_PLANE
) {
1545 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1547 else if (pname
==GL_EYE_PLANE
) {
1548 COPY_4V( params
, texUnit
->EyePlaneQ
);
1551 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
1556 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
1564 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
1566 GET_CURRENT_CONTEXT(ctx
);
1567 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1568 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1569 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1573 if (pname
==GL_TEXTURE_GEN_MODE
) {
1574 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
1576 else if (pname
==GL_OBJECT_PLANE
) {
1577 COPY_4V( params
, texUnit
->ObjectPlaneS
);
1579 else if (pname
==GL_EYE_PLANE
) {
1580 COPY_4V( params
, texUnit
->EyePlaneS
);
1583 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1588 if (pname
==GL_TEXTURE_GEN_MODE
) {
1589 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
1591 else if (pname
==GL_OBJECT_PLANE
) {
1592 COPY_4V( params
, texUnit
->ObjectPlaneT
);
1594 else if (pname
==GL_EYE_PLANE
) {
1595 COPY_4V( params
, texUnit
->EyePlaneT
);
1598 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1603 if (pname
==GL_TEXTURE_GEN_MODE
) {
1604 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
1606 else if (pname
==GL_OBJECT_PLANE
) {
1607 COPY_4V( params
, texUnit
->ObjectPlaneR
);
1609 else if (pname
==GL_EYE_PLANE
) {
1610 COPY_4V( params
, texUnit
->EyePlaneR
);
1613 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1618 if (pname
==GL_TEXTURE_GEN_MODE
) {
1619 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
1621 else if (pname
==GL_OBJECT_PLANE
) {
1622 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
1624 else if (pname
==GL_EYE_PLANE
) {
1625 COPY_4V( params
, texUnit
->EyePlaneQ
);
1628 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
1633 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
1641 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
1643 GET_CURRENT_CONTEXT(ctx
);
1644 GLuint tUnit
= ctx
->Texture
.CurrentTransformUnit
;
1645 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1646 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1650 if (pname
==GL_TEXTURE_GEN_MODE
) {
1651 params
[0] = texUnit
->GenModeS
;
1653 else if (pname
==GL_OBJECT_PLANE
) {
1654 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
1655 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
1656 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
1657 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
1659 else if (pname
==GL_EYE_PLANE
) {
1660 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
1661 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
1662 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
1663 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
1666 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1671 if (pname
==GL_TEXTURE_GEN_MODE
) {
1672 params
[0] = texUnit
->GenModeT
;
1674 else if (pname
==GL_OBJECT_PLANE
) {
1675 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
1676 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
1677 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
1678 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
1680 else if (pname
==GL_EYE_PLANE
) {
1681 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
1682 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
1683 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
1684 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
1687 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1692 if (pname
==GL_TEXTURE_GEN_MODE
) {
1693 params
[0] = texUnit
->GenModeR
;
1695 else if (pname
==GL_OBJECT_PLANE
) {
1696 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
1697 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
1698 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
1699 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
1701 else if (pname
==GL_EYE_PLANE
) {
1702 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
1703 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
1704 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
1705 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
1708 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1713 if (pname
==GL_TEXTURE_GEN_MODE
) {
1714 params
[0] = texUnit
->GenModeQ
;
1716 else if (pname
==GL_OBJECT_PLANE
) {
1717 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
1718 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
1719 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
1720 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
1722 else if (pname
==GL_EYE_PLANE
) {
1723 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
1724 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
1725 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
1726 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
1729 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
1734 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
1740 /* GL_ARB_multitexture */
1742 _mesa_ActiveTextureARB( GLenum target
)
1744 GET_CURRENT_CONTEXT(ctx
);
1745 GLuint texUnit
= target
- GL_TEXTURE0_ARB
;
1746 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1748 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1749 fprintf(stderr
, "glActiveTexture %s\n",
1750 _mesa_lookup_enum_by_nr(target
));
1752 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
1753 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1757 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1758 ctx
->Texture
.CurrentUnit
= texUnit
;
1759 ctx
->Texture
.CurrentTransformUnit
= texUnit
;
1760 if (ctx
->Driver
.ActiveTexture
) {
1761 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1766 /* GL_ARB_multitexture */
1768 _mesa_ClientActiveTextureARB( GLenum target
)
1770 GET_CURRENT_CONTEXT(ctx
);
1771 GLuint texUnit
= target
- GL_TEXTURE0_ARB
;
1772 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1774 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
1775 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glActiveTextureARB(target)");
1779 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1780 ctx
->Array
.ActiveTexture
= texUnit
;