1 /* $Id: texstate.c,v 1.75 2002/06/15 03:03:09 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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))
59 /**********************************************************************/
60 /* Texture Environment */
61 /**********************************************************************/
65 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
67 GET_CURRENT_CONTEXT(ctx
);
68 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
69 ASSERT_OUTSIDE_BEGIN_END(ctx
);
71 #define TE_ERROR(errCode, msg, value) \
74 sprintf(s, msg, _mesa_lookup_enum_by_nr(value)); \
75 _mesa_error(ctx, errCode, s); \
78 if (target
== GL_TEXTURE_ENV
) {
80 case GL_TEXTURE_ENV_MODE
:
82 const GLenum mode
= (GLenum
) (GLint
) *param
;
83 if (mode
== GL_MODULATE
||
87 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
88 (mode
== GL_COMBINE_EXT
&&
89 (ctx
->Extensions
.EXT_texture_env_combine
||
90 ctx
->Extensions
.ARB_texture_env_combine
))) {
92 if (texUnit
->EnvMode
== mode
)
94 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
95 texUnit
->EnvMode
= mode
;
98 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
103 case GL_TEXTURE_ENV_COLOR
:
106 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
107 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
108 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
109 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
110 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
112 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
113 COPY_4FV(texUnit
->EnvColor
, tmp
);
116 case GL_COMBINE_RGB_EXT
:
117 if (ctx
->Extensions
.EXT_texture_env_combine
||
118 ctx
->Extensions
.ARB_texture_env_combine
) {
119 const GLenum mode
= (GLenum
) (GLint
) *param
;
124 case GL_ADD_SIGNED_EXT
:
125 case GL_INTERPOLATE_EXT
:
128 case GL_SUBTRACT_ARB
:
129 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
130 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
134 case GL_DOT3_RGB_EXT
:
135 case GL_DOT3_RGBA_EXT
:
136 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
137 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
141 case GL_DOT3_RGB_ARB
:
142 case GL_DOT3_RGBA_ARB
:
143 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
144 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
149 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
152 if (texUnit
->CombineModeRGB
== mode
)
154 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
155 texUnit
->CombineModeRGB
= mode
;
158 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
162 case GL_COMBINE_ALPHA_EXT
:
163 if (ctx
->Extensions
.EXT_texture_env_combine
||
164 ctx
->Extensions
.ARB_texture_env_combine
) {
165 const GLenum mode
= (GLenum
) (GLint
) *param
;
166 if (mode
== GL_REPLACE
||
167 mode
== GL_MODULATE
||
169 mode
== GL_ADD_SIGNED_EXT
||
170 mode
== GL_INTERPOLATE_EXT
||
171 (mode
== GL_SUBTRACT_ARB
&&
172 ctx
->Extensions
.ARB_texture_env_combine
)) {
174 if (texUnit
->CombineModeA
== mode
)
176 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
177 texUnit
->CombineModeA
= mode
;
180 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
185 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
189 case GL_SOURCE0_RGB_EXT
:
190 case GL_SOURCE1_RGB_EXT
:
191 case GL_SOURCE2_RGB_EXT
:
192 if (ctx
->Extensions
.EXT_texture_env_combine
||
193 ctx
->Extensions
.ARB_texture_env_combine
) {
194 const GLenum source
= (GLenum
) (GLint
) *param
;
195 const GLuint s
= pname
- GL_SOURCE0_RGB_EXT
;
196 if (source
== GL_TEXTURE
||
197 source
== GL_CONSTANT_EXT
||
198 source
== GL_PRIMARY_COLOR_EXT
||
199 source
== GL_PREVIOUS_EXT
||
200 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
201 source
>= GL_TEXTURE0_ARB
&&
202 source
< GL_TEXTURE0_ARB
+ ctx
->Const
.MaxTextureUnits
)) {
204 if (texUnit
->CombineSourceRGB
[s
] == source
)
206 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
207 texUnit
->CombineSourceRGB
[s
] = source
;
210 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
215 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
219 case GL_SOURCE0_ALPHA_EXT
:
220 case GL_SOURCE1_ALPHA_EXT
:
221 case GL_SOURCE2_ALPHA_EXT
:
222 if (ctx
->Extensions
.EXT_texture_env_combine
||
223 ctx
->Extensions
.ARB_texture_env_combine
) {
224 const GLenum source
= (GLenum
) (GLint
) *param
;
225 const GLuint s
= pname
- GL_SOURCE0_ALPHA_EXT
;
226 if (source
== GL_TEXTURE
||
227 source
== GL_CONSTANT_EXT
||
228 source
== GL_PRIMARY_COLOR_EXT
||
229 source
== GL_PREVIOUS_EXT
||
230 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
231 source
>= GL_TEXTURE0_ARB
&&
232 source
< GL_TEXTURE0_ARB
+ ctx
->Const
.MaxTextureUnits
)) {
234 if (texUnit
->CombineSourceA
[s
] == source
)
236 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
237 texUnit
->CombineSourceA
[s
] = source
;
240 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
245 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
249 case GL_OPERAND0_RGB_EXT
:
250 case GL_OPERAND1_RGB_EXT
:
251 if (ctx
->Extensions
.EXT_texture_env_combine
||
252 ctx
->Extensions
.ARB_texture_env_combine
) {
253 const GLenum operand
= (GLenum
) (GLint
) *param
;
254 const GLuint s
= pname
- GL_OPERAND0_RGB_EXT
;
257 case GL_ONE_MINUS_SRC_COLOR
:
259 case GL_ONE_MINUS_SRC_ALPHA
:
260 if (texUnit
->CombineOperandRGB
[s
] == operand
)
262 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
263 texUnit
->CombineOperandRGB
[s
] = operand
;
266 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
271 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
275 case GL_OPERAND0_ALPHA_EXT
:
276 case GL_OPERAND1_ALPHA_EXT
:
277 if (ctx
->Extensions
.EXT_texture_env_combine
||
278 ctx
->Extensions
.ARB_texture_env_combine
) {
279 const GLenum operand
= (GLenum
) (GLint
) *param
;
282 case GL_ONE_MINUS_SRC_ALPHA
:
283 if (texUnit
->CombineOperandA
[pname
-GL_OPERAND0_ALPHA_EXT
] ==
286 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
287 texUnit
->CombineOperandA
[pname
-GL_OPERAND0_ALPHA_EXT
] = operand
;
290 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
295 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
299 case GL_OPERAND2_RGB_EXT
:
300 if (ctx
->Extensions
.EXT_texture_env_combine
||
301 ctx
->Extensions
.ARB_texture_env_combine
) {
302 const GLenum operand
= (GLenum
) (GLint
) *param
;
304 case GL_SRC_COLOR
: /* ARB combine only */
305 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
307 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
308 if (texUnit
->CombineOperandRGB
[2] == operand
)
310 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
311 texUnit
->CombineOperandRGB
[2] = operand
;
313 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
318 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
322 case GL_OPERAND2_ALPHA_EXT
:
323 if (ctx
->Extensions
.EXT_texture_env_combine
||
324 ctx
->Extensions
.ARB_texture_env_combine
) {
325 const GLenum operand
= (GLenum
) (GLint
) *param
;
328 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
329 if (texUnit
->CombineOperandA
[2] == operand
)
331 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
332 texUnit
->CombineOperandA
[2] = operand
;
335 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
340 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
344 case GL_RGB_SCALE_EXT
:
345 if (ctx
->Extensions
.EXT_texture_env_combine
||
346 ctx
->Extensions
.ARB_texture_env_combine
) {
351 else if (*param
== 2.0) {
354 else if (*param
== 4.0) {
358 _mesa_error( ctx
, GL_INVALID_VALUE
,
359 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
362 if (texUnit
->CombineScaleShiftRGB
== newshift
)
364 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
365 texUnit
->CombineScaleShiftRGB
= newshift
;
368 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
373 if (ctx
->Extensions
.EXT_texture_env_combine
||
374 ctx
->Extensions
.ARB_texture_env_combine
) {
379 else if (*param
== 2.0) {
382 else if (*param
== 4.0) {
386 _mesa_error( ctx
, GL_INVALID_VALUE
,
387 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
390 if (texUnit
->CombineScaleShiftA
== newshift
)
392 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
393 texUnit
->CombineScaleShiftA
= newshift
;
396 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
401 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
405 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
406 /* GL_EXT_texture_lod_bias */
407 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
408 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
411 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
412 if (texUnit
->LodBias
== param
[0])
414 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
415 texUnit
->LodBias
= CLAMP(param
[0], -ctx
->Const
.MaxTextureLodBias
,
416 ctx
->Const
.MaxTextureLodBias
);
419 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
423 else if (target
== GL_POINT_SPRITE_NV
) {
424 /* GL_NV_point_sprite */
425 if (!ctx
->Extensions
.NV_point_sprite
) {
426 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
429 if (pname
== GL_COORD_REPLACE_NV
) {
430 const GLenum value
= (GLenum
) param
[0];
431 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
432 /* It's kind of weird to set point state via glTexEnv,
433 * but that's what the spec calls for.
435 const GLboolean state
= (GLboolean
) value
;
436 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
438 FLUSH_VERTICES(ctx
, _NEW_POINT
);
439 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
442 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param)" );
447 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
452 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target)" );
456 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
457 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
458 _mesa_lookup_enum_by_nr(target
),
459 _mesa_lookup_enum_by_nr(pname
),
461 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
463 /* Tell device driver about the new texture environment */
464 if (ctx
->Driver
.TexEnv
) {
465 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
471 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
473 _mesa_TexEnvfv( target
, pname
, ¶m
);
479 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
482 p
[0] = (GLfloat
) param
;
483 p
[1] = p
[2] = p
[3] = 0.0;
484 _mesa_TexEnvfv( target
, pname
, p
);
489 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
492 if (pname
== GL_TEXTURE_ENV_COLOR
) {
493 p
[0] = INT_TO_FLOAT( param
[0] );
494 p
[1] = INT_TO_FLOAT( param
[1] );
495 p
[2] = INT_TO_FLOAT( param
[2] );
496 p
[3] = INT_TO_FLOAT( param
[3] );
499 p
[0] = (GLint
) param
[0];
500 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
502 _mesa_TexEnvfv( target
, pname
, p
);
507 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
509 GET_CURRENT_CONTEXT(ctx
);
510 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
511 ASSERT_OUTSIDE_BEGIN_END(ctx
);
513 if (target
== GL_TEXTURE_ENV
) {
515 case GL_TEXTURE_ENV_MODE
:
516 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
518 case GL_TEXTURE_ENV_COLOR
:
519 COPY_4FV( params
, texUnit
->EnvColor
);
521 case GL_COMBINE_RGB_EXT
:
522 if (ctx
->Extensions
.EXT_texture_env_combine
||
523 ctx
->Extensions
.ARB_texture_env_combine
) {
524 *params
= (GLfloat
) texUnit
->CombineModeRGB
;
527 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
530 case GL_COMBINE_ALPHA_EXT
:
531 if (ctx
->Extensions
.EXT_texture_env_combine
||
532 ctx
->Extensions
.ARB_texture_env_combine
) {
533 *params
= (GLfloat
) texUnit
->CombineModeA
;
536 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
539 case GL_SOURCE0_RGB_EXT
:
540 if (ctx
->Extensions
.EXT_texture_env_combine
||
541 ctx
->Extensions
.ARB_texture_env_combine
) {
542 *params
= (GLfloat
) texUnit
->CombineSourceRGB
[0];
545 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
548 case GL_SOURCE1_RGB_EXT
:
549 if (ctx
->Extensions
.EXT_texture_env_combine
||
550 ctx
->Extensions
.ARB_texture_env_combine
) {
551 *params
= (GLfloat
) texUnit
->CombineSourceRGB
[1];
554 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
557 case GL_SOURCE2_RGB_EXT
:
558 if (ctx
->Extensions
.EXT_texture_env_combine
||
559 ctx
->Extensions
.ARB_texture_env_combine
) {
560 *params
= (GLfloat
) texUnit
->CombineSourceRGB
[2];
563 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
566 case GL_SOURCE0_ALPHA_EXT
:
567 if (ctx
->Extensions
.EXT_texture_env_combine
||
568 ctx
->Extensions
.ARB_texture_env_combine
) {
569 *params
= (GLfloat
) texUnit
->CombineSourceA
[0];
572 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
575 case GL_SOURCE1_ALPHA_EXT
:
576 if (ctx
->Extensions
.EXT_texture_env_combine
||
577 ctx
->Extensions
.ARB_texture_env_combine
) {
578 *params
= (GLfloat
) texUnit
->CombineSourceA
[1];
581 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
584 case GL_SOURCE2_ALPHA_EXT
:
585 if (ctx
->Extensions
.EXT_texture_env_combine
||
586 ctx
->Extensions
.ARB_texture_env_combine
) {
587 *params
= (GLfloat
) texUnit
->CombineSourceA
[2];
590 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
593 case GL_OPERAND0_RGB_EXT
:
594 if (ctx
->Extensions
.EXT_texture_env_combine
||
595 ctx
->Extensions
.ARB_texture_env_combine
) {
596 *params
= (GLfloat
) texUnit
->CombineOperandRGB
[0];
599 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
602 case GL_OPERAND1_RGB_EXT
:
603 if (ctx
->Extensions
.EXT_texture_env_combine
||
604 ctx
->Extensions
.ARB_texture_env_combine
) {
605 *params
= (GLfloat
) texUnit
->CombineOperandRGB
[1];
608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
611 case GL_OPERAND2_RGB_EXT
:
612 if (ctx
->Extensions
.EXT_texture_env_combine
||
613 ctx
->Extensions
.ARB_texture_env_combine
) {
614 *params
= (GLfloat
) texUnit
->CombineOperandRGB
[2];
617 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
620 case GL_OPERAND0_ALPHA_EXT
:
621 if (ctx
->Extensions
.EXT_texture_env_combine
||
622 ctx
->Extensions
.ARB_texture_env_combine
) {
623 *params
= (GLfloat
) texUnit
->CombineOperandA
[0];
626 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
629 case GL_OPERAND1_ALPHA_EXT
:
630 if (ctx
->Extensions
.EXT_texture_env_combine
||
631 ctx
->Extensions
.ARB_texture_env_combine
) {
632 *params
= (GLfloat
) texUnit
->CombineOperandA
[1];
635 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
638 case GL_OPERAND2_ALPHA_EXT
:
639 if (ctx
->Extensions
.EXT_texture_env_combine
||
640 ctx
->Extensions
.ARB_texture_env_combine
) {
641 *params
= (GLfloat
) texUnit
->CombineOperandA
[2];
644 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
647 case GL_RGB_SCALE_EXT
:
648 if (ctx
->Extensions
.EXT_texture_env_combine
||
649 ctx
->Extensions
.ARB_texture_env_combine
) {
650 if (texUnit
->CombineScaleShiftRGB
== 0)
652 else if (texUnit
->CombineScaleShiftRGB
== 1)
658 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
663 if (ctx
->Extensions
.EXT_texture_env_combine
||
664 ctx
->Extensions
.ARB_texture_env_combine
) {
665 if (texUnit
->CombineScaleShiftA
== 0)
667 else if (texUnit
->CombineScaleShiftA
== 1)
673 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
678 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
681 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
682 /* GL_EXT_texture_lod_bias */
683 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
684 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
687 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
688 *params
= texUnit
->LodBias
;
691 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
695 else if (target
== GL_POINT_SPRITE_NV
) {
696 /* GL_NV_point_sprite */
697 if (!ctx
->Extensions
.NV_point_sprite
) {
698 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
701 if (pname
== GL_COORD_REPLACE_NV
) {
702 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
705 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
710 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
717 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
719 GET_CURRENT_CONTEXT(ctx
);
720 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
721 ASSERT_OUTSIDE_BEGIN_END(ctx
);
723 if (target
== GL_TEXTURE_ENV
) {
725 case GL_TEXTURE_ENV_MODE
:
726 *params
= (GLint
) texUnit
->EnvMode
;
728 case GL_TEXTURE_ENV_COLOR
:
729 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
730 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
731 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
732 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
734 case GL_COMBINE_RGB_EXT
:
735 if (ctx
->Extensions
.EXT_texture_env_combine
||
736 ctx
->Extensions
.ARB_texture_env_combine
) {
737 *params
= (GLint
) texUnit
->CombineModeRGB
;
740 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
743 case GL_COMBINE_ALPHA_EXT
:
744 if (ctx
->Extensions
.EXT_texture_env_combine
||
745 ctx
->Extensions
.ARB_texture_env_combine
) {
746 *params
= (GLint
) texUnit
->CombineModeA
;
749 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
752 case GL_SOURCE0_RGB_EXT
:
753 if (ctx
->Extensions
.EXT_texture_env_combine
||
754 ctx
->Extensions
.ARB_texture_env_combine
) {
755 *params
= (GLint
) texUnit
->CombineSourceRGB
[0];
758 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
761 case GL_SOURCE1_RGB_EXT
:
762 if (ctx
->Extensions
.EXT_texture_env_combine
||
763 ctx
->Extensions
.ARB_texture_env_combine
) {
764 *params
= (GLint
) texUnit
->CombineSourceRGB
[1];
767 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
770 case GL_SOURCE2_RGB_EXT
:
771 if (ctx
->Extensions
.EXT_texture_env_combine
||
772 ctx
->Extensions
.ARB_texture_env_combine
) {
773 *params
= (GLint
) texUnit
->CombineSourceRGB
[2];
776 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
779 case GL_SOURCE0_ALPHA_EXT
:
780 if (ctx
->Extensions
.EXT_texture_env_combine
||
781 ctx
->Extensions
.ARB_texture_env_combine
) {
782 *params
= (GLint
) texUnit
->CombineSourceA
[0];
785 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
788 case GL_SOURCE1_ALPHA_EXT
:
789 if (ctx
->Extensions
.EXT_texture_env_combine
||
790 ctx
->Extensions
.ARB_texture_env_combine
) {
791 *params
= (GLint
) texUnit
->CombineSourceA
[1];
794 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
797 case GL_SOURCE2_ALPHA_EXT
:
798 if (ctx
->Extensions
.EXT_texture_env_combine
||
799 ctx
->Extensions
.ARB_texture_env_combine
) {
800 *params
= (GLint
) texUnit
->CombineSourceA
[2];
803 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
806 case GL_OPERAND0_RGB_EXT
:
807 if (ctx
->Extensions
.EXT_texture_env_combine
||
808 ctx
->Extensions
.ARB_texture_env_combine
) {
809 *params
= (GLint
) texUnit
->CombineOperandRGB
[0];
812 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
815 case GL_OPERAND1_RGB_EXT
:
816 if (ctx
->Extensions
.EXT_texture_env_combine
||
817 ctx
->Extensions
.ARB_texture_env_combine
) {
818 *params
= (GLint
) texUnit
->CombineOperandRGB
[1];
821 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
824 case GL_OPERAND2_RGB_EXT
:
825 if (ctx
->Extensions
.EXT_texture_env_combine
||
826 ctx
->Extensions
.ARB_texture_env_combine
) {
827 *params
= (GLint
) texUnit
->CombineOperandRGB
[2];
830 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
833 case GL_OPERAND0_ALPHA_EXT
:
834 if (ctx
->Extensions
.EXT_texture_env_combine
||
835 ctx
->Extensions
.ARB_texture_env_combine
) {
836 *params
= (GLint
) texUnit
->CombineOperandA
[0];
839 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
842 case GL_OPERAND1_ALPHA_EXT
:
843 if (ctx
->Extensions
.EXT_texture_env_combine
||
844 ctx
->Extensions
.ARB_texture_env_combine
) {
845 *params
= (GLint
) texUnit
->CombineOperandA
[1];
848 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
851 case GL_OPERAND2_ALPHA_EXT
:
852 if (ctx
->Extensions
.EXT_texture_env_combine
||
853 ctx
->Extensions
.ARB_texture_env_combine
) {
854 *params
= (GLint
) texUnit
->CombineOperandA
[2];
857 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
860 case GL_RGB_SCALE_EXT
:
861 if (ctx
->Extensions
.EXT_texture_env_combine
||
862 ctx
->Extensions
.ARB_texture_env_combine
) {
863 if (texUnit
->CombineScaleShiftRGB
== 0)
865 else if (texUnit
->CombineScaleShiftRGB
== 1)
871 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
876 if (ctx
->Extensions
.EXT_texture_env_combine
||
877 ctx
->Extensions
.ARB_texture_env_combine
) {
878 if (texUnit
->CombineScaleShiftA
== 0)
880 else if (texUnit
->CombineScaleShiftA
== 1)
886 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
891 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
894 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
895 /* GL_EXT_texture_lod_bias */
896 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
897 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
900 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
901 *params
= (GLint
) texUnit
->LodBias
;
904 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
908 else if (target
== GL_POINT_SPRITE_NV
) {
909 /* GL_NV_point_sprite */
910 if (!ctx
->Extensions
.NV_point_sprite
) {
911 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
914 if (pname
== GL_COORD_REPLACE_NV
) {
915 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
918 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
923 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
931 /**********************************************************************/
932 /* Texture Parameters */
933 /**********************************************************************/
937 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
939 _mesa_TexParameterfv(target
, pname
, ¶m
);
944 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
946 GET_CURRENT_CONTEXT(ctx
);
947 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
948 GLenum eparam
= (GLenum
) (GLint
) params
[0];
949 struct gl_texture_object
*texObj
;
950 ASSERT_OUTSIDE_BEGIN_END(ctx
);
952 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
953 _mesa_debug(ctx
, "texPARAM %s %s %d...\n",
954 _mesa_lookup_enum_by_nr(target
),
955 _mesa_lookup_enum_by_nr(pname
),
961 texObj
= texUnit
->Current1D
;
964 texObj
= texUnit
->Current2D
;
966 case GL_TEXTURE_3D_EXT
:
967 texObj
= texUnit
->Current3D
;
969 case GL_TEXTURE_CUBE_MAP_ARB
:
970 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
971 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
974 texObj
= texUnit
->CurrentCubeMap
;
976 case GL_TEXTURE_RECTANGLE_NV
:
977 if (!ctx
->Extensions
.NV_texture_rectangle
) {
978 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
981 texObj
= texUnit
->CurrentRect
;
984 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
989 case GL_TEXTURE_MIN_FILTER
:
990 /* A small optimization */
991 if (texObj
->MinFilter
== eparam
)
994 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
995 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
996 texObj
->MinFilter
= eparam
;
998 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
999 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1000 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1001 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1002 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1003 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1004 texObj
->MinFilter
= eparam
;
1007 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1011 case GL_TEXTURE_MAG_FILTER
:
1012 /* A small optimization */
1013 if (texObj
->MagFilter
== eparam
)
1016 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1017 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1018 texObj
->MagFilter
= eparam
;
1021 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1025 case GL_TEXTURE_WRAP_S
:
1026 if (texObj
->WrapS
== eparam
)
1028 if (eparam
== GL_CLAMP
|| eparam
== GL_CLAMP_TO_EDGE
||
1029 (eparam
== GL_CLAMP_TO_BORDER_ARB
&&
1030 ctx
->Extensions
.ARB_texture_border_clamp
)) {
1031 /* any texture target */
1032 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1033 texObj
->WrapS
= eparam
;
1035 else if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
1036 (eparam
== GL_REPEAT
||
1037 (eparam
== GL_MIRRORED_REPEAT_ARB
&&
1038 ctx
->Extensions
.ARB_texture_mirrored_repeat
))) {
1039 /* non-rectangle texture */
1040 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1041 texObj
->WrapS
= eparam
;
1044 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1048 case GL_TEXTURE_WRAP_T
:
1049 if (texObj
->WrapT
== eparam
)
1051 if (eparam
== GL_CLAMP
|| eparam
== GL_CLAMP_TO_EDGE
||
1052 (eparam
== GL_CLAMP_TO_BORDER_ARB
&&
1053 ctx
->Extensions
.ARB_texture_border_clamp
)) {
1054 /* any texture target */
1055 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1056 texObj
->WrapT
= eparam
;
1058 else if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
1059 (eparam
== GL_REPEAT
||
1060 (eparam
== GL_MIRRORED_REPEAT_ARB
&&
1061 ctx
->Extensions
.ARB_texture_mirrored_repeat
))) {
1062 /* non-rectangle texture */
1063 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1064 texObj
->WrapT
= eparam
;
1067 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1071 case GL_TEXTURE_WRAP_R_EXT
:
1072 if (texObj
->WrapR
== eparam
)
1074 if (eparam
== GL_CLAMP
|| eparam
== GL_CLAMP_TO_EDGE
||
1075 (eparam
== GL_CLAMP_TO_BORDER_ARB
&&
1076 ctx
->Extensions
.ARB_texture_border_clamp
)) {
1077 /* any texture target */
1078 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1079 texObj
->WrapR
= eparam
;
1081 else if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
1082 (eparam
== GL_REPEAT
||
1083 (eparam
== GL_MIRRORED_REPEAT_ARB
&&
1084 ctx
->Extensions
.ARB_texture_mirrored_repeat
))) {
1085 /* non-rectangle texture */
1086 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1087 texObj
->WrapR
= eparam
;
1090 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1094 case GL_TEXTUER_BORDER_VALUES_NV
:
1096 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1097 COPY_4V(texObj
->BorderValues
, params
);
1098 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[0], params
[0]);
1099 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[1], params
[1]);
1100 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[2], params
[2]);
1101 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[3], params
[3]);
1104 case GL_TEXTURE_BORDER_COLOR
:
1106 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1107 texObj
->BorderValues
[0] = CLAMP(params
[0], 0.0F
, 1.0F
);
1108 texObj
->BorderValues
[1] = CLAMP(params
[1], 0.0F
, 1.0F
);
1109 texObj
->BorderValues
[2] = CLAMP(params
[2], 0.0F
, 1.0F
);
1110 texObj
->BorderValues
[3] = CLAMP(params
[3], 0.0F
, 1.0F
);
1111 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[0], texObj
->BorderValues
[0]);
1112 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[1], texObj
->BorderValues
[1]);
1113 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[2], texObj
->BorderValues
[2]);
1114 UNCLAMPED_FLOAT_TO_CHAN(texObj
->BorderColor
[3], texObj
->BorderValues
[3]);
1116 case GL_TEXTURE_MIN_LOD
:
1117 if (texObj
->MinLod
== params
[0])
1119 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1120 texObj
->MinLod
= params
[0];
1122 case GL_TEXTURE_MAX_LOD
:
1123 if (texObj
->MaxLod
== params
[0])
1125 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1126 texObj
->MaxLod
= params
[0];
1128 case GL_TEXTURE_BASE_LEVEL
:
1129 if (params
[0] < 0.0) {
1130 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1133 if (target
== GL_TEXTURE_RECTANGLE_NV
&& params
[0] != 0.0) {
1134 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1137 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1138 texObj
->BaseLevel
= (GLint
) params
[0];
1140 case GL_TEXTURE_MAX_LEVEL
:
1141 if (params
[0] < 0.0) {
1142 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1145 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1146 texObj
->MaxLevel
= (GLint
) params
[0];
1148 case GL_TEXTURE_PRIORITY
:
1149 /* (keithh@netcomuk.co.uk) */
1150 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1151 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1153 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1154 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1155 if (params
[0] < 1.0) {
1156 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1159 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1160 texObj
->MaxAnisotropy
= params
[0];
1163 _mesa_error(ctx
, GL_INVALID_ENUM
,
1164 "glTexParameter(pname=GL_MAX_TEXTURE_ANISOTROPY_EXT)");
1168 case GL_TEXTURE_COMPARE_SGIX
:
1169 if (ctx
->Extensions
.SGIX_shadow
) {
1170 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1171 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1174 _mesa_error(ctx
, GL_INVALID_ENUM
,
1175 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1179 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1180 if (ctx
->Extensions
.SGIX_shadow
) {
1181 GLenum op
= (GLenum
) params
[0];
1182 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1183 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1184 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1185 texObj
->CompareOperator
= op
;
1188 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1192 _mesa_error(ctx
, GL_INVALID_ENUM
,
1193 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1197 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1198 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1199 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1200 UNCLAMPED_FLOAT_TO_CHAN(texObj
->ShadowAmbient
, params
[0]);
1203 _mesa_error(ctx
, GL_INVALID_ENUM
,
1204 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1208 case GL_GENERATE_MIPMAP_SGIS
:
1209 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1210 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1213 _mesa_error(ctx
, GL_INVALID_ENUM
,
1214 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1218 case GL_TEXTURE_COMPARE_MODE_ARB
:
1219 if (ctx
->Extensions
.ARB_shadow
) {
1220 const GLenum mode
= (GLenum
) params
[0];
1221 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1222 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1223 texObj
->CompareMode
= mode
;
1226 _mesa_error(ctx
, GL_INVALID_ENUM
,
1227 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB)");
1232 _mesa_error(ctx
, GL_INVALID_ENUM
,
1233 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1237 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1238 if (ctx
->Extensions
.ARB_shadow
) {
1239 const GLenum func
= (GLenum
) params
[0];
1240 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1241 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1242 texObj
->CompareFunc
= func
;
1244 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1245 (func
== GL_EQUAL
||
1246 func
== GL_NOTEQUAL
||
1248 func
== GL_GREATER
||
1249 func
== GL_ALWAYS
||
1250 func
== GL_NEVER
)) {
1251 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1252 texObj
->CompareFunc
= func
;
1255 _mesa_error(ctx
, GL_INVALID_ENUM
,
1256 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1261 _mesa_error(ctx
, GL_INVALID_ENUM
,
1262 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1266 case GL_DEPTH_TEXTURE_MODE_ARB
:
1267 if (ctx
->Extensions
.ARB_depth_texture
) {
1268 const GLenum result
= (GLenum
) params
[0];
1269 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1270 || result
== GL_ALPHA
) {
1271 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1272 texObj
->DepthMode
= result
;
1275 _mesa_error(ctx
, GL_INVALID_ENUM
,
1276 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1281 _mesa_error(ctx
, GL_INVALID_ENUM
,
1282 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1290 sprintf(s
, "glTexParameter(pname=0x%x)", pname
);
1291 _mesa_error( ctx
, GL_INVALID_ENUM
, s
);
1296 texObj
->Complete
= GL_FALSE
;
1298 if (ctx
->Driver
.TexParameter
) {
1299 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1305 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1308 fparam
[0] = (GLfloat
) param
;
1309 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1310 _mesa_TexParameterfv(target
, pname
, fparam
);
1314 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1317 fparam
[0] = (GLfloat
) params
[0];
1318 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1319 _mesa_TexParameterfv(target
, pname
, fparam
);
1324 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1325 GLenum pname
, GLfloat
*params
)
1328 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1329 *params
= (GLfloat
) iparam
;
1334 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1338 case GL_PROXY_TEXTURE_1D
:
1341 case GL_PROXY_TEXTURE_2D
:
1344 case GL_PROXY_TEXTURE_3D
:
1346 case GL_TEXTURE_CUBE_MAP_ARB
:
1347 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1348 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1349 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1350 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1351 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1352 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1353 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1354 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1355 case GL_TEXTURE_RECTANGLE_NV
:
1356 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1357 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1359 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1366 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1367 GLenum pname
, GLint
*params
)
1369 GET_CURRENT_CONTEXT(ctx
);
1370 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1371 const struct gl_texture_image
*img
= NULL
;
1375 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1377 /* this will catch bad target values */
1378 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1379 if (dimensions
== 0) {
1380 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1386 case GL_PROXY_TEXTURE_1D
:
1388 case GL_PROXY_TEXTURE_2D
:
1389 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1392 case GL_PROXY_TEXTURE_3D
:
1393 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1395 case GL_TEXTURE_CUBE_MAP_ARB
:
1396 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1397 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1399 case GL_TEXTURE_RECTANGLE_NV
:
1400 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1404 _mesa_problem(ctx
, "bad target in _mesa_GetTexLevelParameter");
1408 if (level
< 0 || level
>= maxLevels
) {
1409 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1413 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1414 if (!img
|| !img
->TexFormat
) {
1415 /* undefined texture image */
1416 if (pname
== GL_TEXTURE_COMPONENTS
)
1423 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
1424 (target
== GL_PROXY_TEXTURE_2D
) ||
1425 (target
== GL_PROXY_TEXTURE_3D
) ||
1426 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) ||
1427 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
);
1430 case GL_TEXTURE_WIDTH
:
1431 *params
= img
->Width
;
1433 case GL_TEXTURE_HEIGHT
:
1434 *params
= img
->Height
;
1436 case GL_TEXTURE_DEPTH
:
1437 *params
= img
->Depth
;
1439 case GL_TEXTURE_INTERNAL_FORMAT
:
1440 *params
= img
->IntFormat
;
1442 case GL_TEXTURE_BORDER
:
1443 *params
= img
->Border
;
1445 case GL_TEXTURE_RED_SIZE
:
1446 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1447 *params
= img
->TexFormat
->RedBits
;
1451 case GL_TEXTURE_GREEN_SIZE
:
1452 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1453 *params
= img
->TexFormat
->GreenBits
;
1457 case GL_TEXTURE_BLUE_SIZE
:
1458 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1459 *params
= img
->TexFormat
->BlueBits
;
1463 case GL_TEXTURE_ALPHA_SIZE
:
1464 if (img
->Format
== GL_ALPHA
|| img
->Format
== GL_LUMINANCE_ALPHA
||
1465 img
->Format
== GL_RGBA
)
1466 *params
= img
->TexFormat
->AlphaBits
;
1470 case GL_TEXTURE_INTENSITY_SIZE
:
1471 if (img
->Format
!= GL_INTENSITY
)
1473 else if (img
->TexFormat
->IntensityBits
> 0)
1474 *params
= img
->TexFormat
->IntensityBits
;
1475 else /* intensity probably stored as rgb texture */
1476 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1478 case GL_TEXTURE_LUMINANCE_SIZE
:
1479 if (img
->Format
!= GL_LUMINANCE
&&
1480 img
->Format
!= GL_LUMINANCE_ALPHA
)
1482 else if (img
->TexFormat
->LuminanceBits
> 0)
1483 *params
= img
->TexFormat
->LuminanceBits
;
1484 else /* luminance probably stored as rgb texture */
1485 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1487 case GL_TEXTURE_INDEX_SIZE_EXT
:
1488 if (img
->Format
== GL_COLOR_INDEX
)
1489 *params
= img
->TexFormat
->IndexBits
;
1494 /* XXX this isn't in the GL_SGIX_depth_texture spec
1495 * but seems appropriate.
1497 if (ctx
->Extensions
.SGIX_depth_texture
)
1498 *params
= img
->TexFormat
->DepthBits
;
1500 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
1503 /* GL_ARB_texture_compression */
1504 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
:
1505 if (ctx
->Extensions
.ARB_texture_compression
) {
1506 if (img
->IsCompressed
&& !isProxy
)
1507 *params
= img
->CompressedSize
;
1509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1510 "glGetTexLevelParameter[if]v(pname)");
1513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
1516 case GL_TEXTURE_COMPRESSED_ARB
:
1517 if (ctx
->Extensions
.ARB_texture_compression
) {
1518 *params
= (GLint
) img
->IsCompressed
;
1521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
1526 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(pname)");
1533 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1535 GET_CURRENT_CONTEXT(ctx
);
1536 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1537 struct gl_texture_object
*obj
;
1538 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1540 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1542 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1547 case GL_TEXTURE_MAG_FILTER
:
1548 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1550 case GL_TEXTURE_MIN_FILTER
:
1551 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1553 case GL_TEXTURE_WRAP_S
:
1554 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1556 case GL_TEXTURE_WRAP_T
:
1557 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1559 case GL_TEXTURE_WRAP_R_EXT
:
1560 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1563 case GL_TEXTURE_BORDER_VALUES_NV
:
1565 params
[0] = obj
->BorderValues
[0];
1566 params
[1] = obj
->BorderValues
[1];
1567 params
[2] = obj
->BorderValues
[2];
1568 params
[3] = obj
->BorderValues
[3];
1571 case GL_TEXTURE_BORDER_COLOR
:
1573 params
[0] = obj
->BorderColor
[0] / CHAN_MAXF
;
1574 params
[1] = obj
->BorderColor
[1] / CHAN_MAXF
;
1575 params
[2] = obj
->BorderColor
[2] / CHAN_MAXF
;
1576 params
[3] = obj
->BorderColor
[3] / CHAN_MAXF
;
1578 case GL_TEXTURE_RESIDENT
:
1581 if (ctx
->Driver
.IsTextureResident
)
1582 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1585 *params
= ENUM_TO_FLOAT(resident
);
1588 case GL_TEXTURE_PRIORITY
:
1589 *params
= obj
->Priority
;
1591 case GL_TEXTURE_MIN_LOD
:
1592 *params
= obj
->MinLod
;
1594 case GL_TEXTURE_MAX_LOD
:
1595 *params
= obj
->MaxLod
;
1597 case GL_TEXTURE_BASE_LEVEL
:
1598 *params
= (GLfloat
) obj
->BaseLevel
;
1600 case GL_TEXTURE_MAX_LEVEL
:
1601 *params
= (GLfloat
) obj
->MaxLevel
;
1603 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1604 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1605 *params
= obj
->MaxAnisotropy
;
1609 case GL_TEXTURE_COMPARE_SGIX
:
1610 if (ctx
->Extensions
.SGIX_shadow
) {
1611 *params
= (GLfloat
) obj
->CompareFlag
;
1615 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1616 if (ctx
->Extensions
.SGIX_shadow
) {
1617 *params
= (GLfloat
) obj
->CompareOperator
;
1621 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1622 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1623 *params
= CHAN_TO_FLOAT(obj
->ShadowAmbient
);
1627 case GL_GENERATE_MIPMAP_SGIS
:
1628 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1629 *params
= (GLfloat
) obj
->GenerateMipmap
;
1633 case GL_TEXTURE_COMPARE_MODE_ARB
:
1634 if (ctx
->Extensions
.ARB_shadow
) {
1635 *params
= (GLfloat
) obj
->CompareMode
;
1639 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1640 if (ctx
->Extensions
.ARB_shadow
) {
1641 *params
= (GLfloat
) obj
->CompareFunc
;
1645 case GL_DEPTH_TEXTURE_MODE_ARB
:
1646 if (ctx
->Extensions
.ARB_depth_texture
) {
1647 *params
= (GLfloat
) obj
->DepthMode
;
1652 ; /* silence warnings */
1654 /* If we get here, pname was an unrecognized enum */
1655 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname)" );
1660 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1662 GET_CURRENT_CONTEXT(ctx
);
1663 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1664 struct gl_texture_object
*obj
;
1665 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1667 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1669 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1674 case GL_TEXTURE_MAG_FILTER
:
1675 *params
= (GLint
) obj
->MagFilter
;
1677 case GL_TEXTURE_MIN_FILTER
:
1678 *params
= (GLint
) obj
->MinFilter
;
1680 case GL_TEXTURE_WRAP_S
:
1681 *params
= (GLint
) obj
->WrapS
;
1683 case GL_TEXTURE_WRAP_T
:
1684 *params
= (GLint
) obj
->WrapT
;
1686 case GL_TEXTURE_WRAP_R_EXT
:
1687 *params
= (GLint
) obj
->WrapR
;
1690 case GL_TEXTURE_BORDER_VALUES_NV
:
1692 params
[0] = FLOAT_TO_INT(obj
->BorderValues
[0]);
1693 params
[1] = FLOAT_TO_INT(obj
->BorderValues
[1]);
1694 params
[2] = FLOAT_TO_INT(obj
->BorderValues
[2]);
1695 params
[3] = FLOAT_TO_INT(obj
->BorderValues
[3]);
1698 case GL_TEXTURE_BORDER_COLOR
:
1702 b
[0] = CLAMP(obj
->BorderValues
[0], 0.0F
, 1.0F
);
1703 b
[1] = CLAMP(obj
->BorderValues
[1], 0.0F
, 1.0F
);
1704 b
[2] = CLAMP(obj
->BorderValues
[2], 0.0F
, 1.0F
);
1705 b
[3] = CLAMP(obj
->BorderValues
[3], 0.0F
, 1.0F
);
1706 params
[0] = FLOAT_TO_INT(b
[0]);
1707 params
[1] = FLOAT_TO_INT(b
[1]);
1708 params
[2] = FLOAT_TO_INT(b
[2]);
1709 params
[3] = FLOAT_TO_INT(b
[3]);
1712 case GL_TEXTURE_RESIDENT
:
1715 if (ctx
->Driver
.IsTextureResident
)
1716 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1719 *params
= (GLint
) resident
;
1722 case GL_TEXTURE_PRIORITY
:
1723 *params
= (GLint
) obj
->Priority
;
1725 case GL_TEXTURE_MIN_LOD
:
1726 *params
= (GLint
) obj
->MinLod
;
1728 case GL_TEXTURE_MAX_LOD
:
1729 *params
= (GLint
) obj
->MaxLod
;
1731 case GL_TEXTURE_BASE_LEVEL
:
1732 *params
= obj
->BaseLevel
;
1734 case GL_TEXTURE_MAX_LEVEL
:
1735 *params
= obj
->MaxLevel
;
1737 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1738 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1739 *params
= (GLint
) obj
->MaxAnisotropy
;
1743 case GL_TEXTURE_COMPARE_SGIX
:
1744 if (ctx
->Extensions
.SGIX_shadow
) {
1745 *params
= (GLint
) obj
->CompareFlag
;
1749 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1750 if (ctx
->Extensions
.SGIX_shadow
) {
1751 *params
= (GLint
) obj
->CompareOperator
;
1755 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1756 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1757 GLfloat a
= CHAN_TO_FLOAT(obj
->ShadowAmbient
);
1758 *params
= (GLint
) FLOAT_TO_INT(a
);
1762 case GL_GENERATE_MIPMAP_SGIS
:
1763 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1764 *params
= (GLint
) obj
->GenerateMipmap
;
1768 case GL_TEXTURE_COMPARE_MODE_ARB
:
1769 if (ctx
->Extensions
.ARB_shadow
) {
1770 *params
= (GLint
) obj
->CompareMode
;
1774 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1775 if (ctx
->Extensions
.ARB_shadow
) {
1776 *params
= (GLint
) obj
->CompareFunc
;
1780 case GL_DEPTH_TEXTURE_MODE_ARB
:
1781 if (ctx
->Extensions
.ARB_depth_texture
) {
1782 *params
= (GLint
) obj
->DepthMode
;
1787 ; /* silence warnings */
1789 /* If we get here, pname was an unrecognized enum */
1790 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname)" );
1796 /**********************************************************************/
1797 /* Texture Coord Generation */
1798 /**********************************************************************/
1802 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
1804 GET_CURRENT_CONTEXT(ctx
);
1805 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
1806 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
1807 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1809 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1810 _mesa_debug(ctx
, "texGEN %s %s %x...\n",
1811 _mesa_lookup_enum_by_nr(coord
),
1812 _mesa_lookup_enum_by_nr(pname
),
1817 if (pname
==GL_TEXTURE_GEN_MODE
) {
1818 GLenum mode
= (GLenum
) (GLint
) *params
;
1821 case GL_OBJECT_LINEAR
:
1822 bits
= TEXGEN_OBJ_LINEAR
;
1825 bits
= TEXGEN_EYE_LINEAR
;
1827 case GL_REFLECTION_MAP_NV
:
1828 bits
= TEXGEN_REFLECTION_MAP_NV
;
1830 case GL_NORMAL_MAP_NV
:
1831 bits
= TEXGEN_NORMAL_MAP_NV
;
1834 bits
= TEXGEN_SPHERE_MAP
;
1837 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1840 if (texUnit
->GenModeS
== mode
)
1842 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1843 texUnit
->GenModeS
= mode
;
1844 texUnit
->_GenBitS
= bits
;
1846 else if (pname
==GL_OBJECT_PLANE
) {
1847 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
1849 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1850 texUnit
->ObjectPlaneS
[0] = params
[0];
1851 texUnit
->ObjectPlaneS
[1] = params
[1];
1852 texUnit
->ObjectPlaneS
[2] = params
[2];
1853 texUnit
->ObjectPlaneS
[3] = params
[3];
1855 else if (pname
==GL_EYE_PLANE
) {
1858 /* Transform plane equation by the inverse modelview matrix */
1859 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
1860 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1862 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
1863 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
1865 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1866 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
1869 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1874 if (pname
==GL_TEXTURE_GEN_MODE
) {
1875 GLenum mode
= (GLenum
) (GLint
) *params
;
1878 case GL_OBJECT_LINEAR
:
1879 bitt
= TEXGEN_OBJ_LINEAR
;
1882 bitt
= TEXGEN_EYE_LINEAR
;
1884 case GL_REFLECTION_MAP_NV
:
1885 bitt
= TEXGEN_REFLECTION_MAP_NV
;
1887 case GL_NORMAL_MAP_NV
:
1888 bitt
= TEXGEN_NORMAL_MAP_NV
;
1891 bitt
= TEXGEN_SPHERE_MAP
;
1894 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1897 if (texUnit
->GenModeT
== mode
)
1899 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1900 texUnit
->GenModeT
= mode
;
1901 texUnit
->_GenBitT
= bitt
;
1903 else if (pname
==GL_OBJECT_PLANE
) {
1904 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
1906 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1907 texUnit
->ObjectPlaneT
[0] = params
[0];
1908 texUnit
->ObjectPlaneT
[1] = params
[1];
1909 texUnit
->ObjectPlaneT
[2] = params
[2];
1910 texUnit
->ObjectPlaneT
[3] = params
[3];
1912 else if (pname
==GL_EYE_PLANE
) {
1914 /* Transform plane equation by the inverse modelview matrix */
1915 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
1916 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1918 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
1919 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
1921 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1922 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
1925 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1930 if (pname
==GL_TEXTURE_GEN_MODE
) {
1931 GLenum mode
= (GLenum
) (GLint
) *params
;
1934 case GL_OBJECT_LINEAR
:
1935 bitr
= TEXGEN_OBJ_LINEAR
;
1937 case GL_REFLECTION_MAP_NV
:
1938 bitr
= TEXGEN_REFLECTION_MAP_NV
;
1940 case GL_NORMAL_MAP_NV
:
1941 bitr
= TEXGEN_NORMAL_MAP_NV
;
1944 bitr
= TEXGEN_EYE_LINEAR
;
1947 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1950 if (texUnit
->GenModeR
== mode
)
1952 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1953 texUnit
->GenModeR
= mode
;
1954 texUnit
->_GenBitR
= bitr
;
1956 else if (pname
==GL_OBJECT_PLANE
) {
1957 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
1959 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1960 texUnit
->ObjectPlaneR
[0] = params
[0];
1961 texUnit
->ObjectPlaneR
[1] = params
[1];
1962 texUnit
->ObjectPlaneR
[2] = params
[2];
1963 texUnit
->ObjectPlaneR
[3] = params
[3];
1965 else if (pname
==GL_EYE_PLANE
) {
1967 /* Transform plane equation by the inverse modelview matrix */
1968 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
1969 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1971 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
1972 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
1974 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1975 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
1978 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
1983 if (pname
==GL_TEXTURE_GEN_MODE
) {
1984 GLenum mode
= (GLenum
) (GLint
) *params
;
1987 case GL_OBJECT_LINEAR
:
1988 bitq
= TEXGEN_OBJ_LINEAR
;
1991 bitq
= TEXGEN_EYE_LINEAR
;
1994 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
1997 if (texUnit
->GenModeQ
== mode
)
1999 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2000 texUnit
->GenModeQ
= mode
;
2001 texUnit
->_GenBitQ
= bitq
;
2003 else if (pname
==GL_OBJECT_PLANE
) {
2004 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2006 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2007 texUnit
->ObjectPlaneQ
[0] = params
[0];
2008 texUnit
->ObjectPlaneQ
[1] = params
[1];
2009 texUnit
->ObjectPlaneQ
[2] = params
[2];
2010 texUnit
->ObjectPlaneQ
[3] = params
[3];
2012 else if (pname
==GL_EYE_PLANE
) {
2014 /* Transform plane equation by the inverse modelview matrix */
2015 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2016 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2018 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2019 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2021 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2022 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2025 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2030 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2034 if (ctx
->Driver
.TexGen
)
2035 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2040 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2043 p
[0] = (GLfloat
) params
[0];
2044 p
[1] = (GLfloat
) params
[1];
2045 p
[2] = (GLfloat
) params
[2];
2046 p
[3] = (GLfloat
) params
[3];
2047 _mesa_TexGenfv(coord
, pname
, p
);
2052 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2054 GLfloat p
= (GLfloat
) param
;
2055 _mesa_TexGenfv( coord
, pname
, &p
);
2060 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2063 p
[0] = (GLfloat
) params
[0];
2064 p
[1] = (GLfloat
) params
[1];
2065 p
[2] = (GLfloat
) params
[2];
2066 p
[3] = (GLfloat
) params
[3];
2067 _mesa_TexGenfv( coord
, pname
, p
);
2072 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2074 _mesa_TexGenfv(coord
, pname
, ¶m
);
2079 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2081 _mesa_TexGeniv( coord
, pname
, ¶m
);
2087 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2089 GET_CURRENT_CONTEXT(ctx
);
2090 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2091 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2092 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2096 if (pname
==GL_TEXTURE_GEN_MODE
) {
2097 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2099 else if (pname
==GL_OBJECT_PLANE
) {
2100 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2102 else if (pname
==GL_EYE_PLANE
) {
2103 COPY_4V( params
, texUnit
->EyePlaneS
);
2106 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2111 if (pname
==GL_TEXTURE_GEN_MODE
) {
2112 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2114 else if (pname
==GL_OBJECT_PLANE
) {
2115 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2117 else if (pname
==GL_EYE_PLANE
) {
2118 COPY_4V( params
, texUnit
->EyePlaneT
);
2121 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2126 if (pname
==GL_TEXTURE_GEN_MODE
) {
2127 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2129 else if (pname
==GL_OBJECT_PLANE
) {
2130 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2132 else if (pname
==GL_EYE_PLANE
) {
2133 COPY_4V( params
, texUnit
->EyePlaneR
);
2136 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2141 if (pname
==GL_TEXTURE_GEN_MODE
) {
2142 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2144 else if (pname
==GL_OBJECT_PLANE
) {
2145 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2147 else if (pname
==GL_EYE_PLANE
) {
2148 COPY_4V( params
, texUnit
->EyePlaneQ
);
2151 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2156 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2164 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2166 GET_CURRENT_CONTEXT(ctx
);
2167 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2168 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2169 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2173 if (pname
==GL_TEXTURE_GEN_MODE
) {
2174 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2176 else if (pname
==GL_OBJECT_PLANE
) {
2177 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2179 else if (pname
==GL_EYE_PLANE
) {
2180 COPY_4V( params
, texUnit
->EyePlaneS
);
2183 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2188 if (pname
==GL_TEXTURE_GEN_MODE
) {
2189 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2191 else if (pname
==GL_OBJECT_PLANE
) {
2192 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2194 else if (pname
==GL_EYE_PLANE
) {
2195 COPY_4V( params
, texUnit
->EyePlaneT
);
2198 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2203 if (pname
==GL_TEXTURE_GEN_MODE
) {
2204 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2206 else if (pname
==GL_OBJECT_PLANE
) {
2207 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2209 else if (pname
==GL_EYE_PLANE
) {
2210 COPY_4V( params
, texUnit
->EyePlaneR
);
2213 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2218 if (pname
==GL_TEXTURE_GEN_MODE
) {
2219 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2221 else if (pname
==GL_OBJECT_PLANE
) {
2222 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2224 else if (pname
==GL_EYE_PLANE
) {
2225 COPY_4V( params
, texUnit
->EyePlaneQ
);
2228 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2233 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2241 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2243 GET_CURRENT_CONTEXT(ctx
);
2244 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2245 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2246 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2250 if (pname
==GL_TEXTURE_GEN_MODE
) {
2251 params
[0] = texUnit
->GenModeS
;
2253 else if (pname
==GL_OBJECT_PLANE
) {
2254 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2255 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2256 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2257 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2259 else if (pname
==GL_EYE_PLANE
) {
2260 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2261 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2262 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2263 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2266 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2271 if (pname
==GL_TEXTURE_GEN_MODE
) {
2272 params
[0] = texUnit
->GenModeT
;
2274 else if (pname
==GL_OBJECT_PLANE
) {
2275 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2276 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2277 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2278 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2280 else if (pname
==GL_EYE_PLANE
) {
2281 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2282 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2283 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2284 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2287 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2292 if (pname
==GL_TEXTURE_GEN_MODE
) {
2293 params
[0] = texUnit
->GenModeR
;
2295 else if (pname
==GL_OBJECT_PLANE
) {
2296 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2297 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2298 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2299 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2301 else if (pname
==GL_EYE_PLANE
) {
2302 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2303 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2304 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2305 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2308 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2313 if (pname
==GL_TEXTURE_GEN_MODE
) {
2314 params
[0] = texUnit
->GenModeQ
;
2316 else if (pname
==GL_OBJECT_PLANE
) {
2317 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2318 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2319 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2320 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2322 else if (pname
==GL_EYE_PLANE
) {
2323 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2324 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2325 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2326 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2329 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2334 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2340 /* GL_ARB_multitexture */
2342 _mesa_ActiveTextureARB( GLenum target
)
2344 GET_CURRENT_CONTEXT(ctx
);
2345 GLuint texUnit
= target
- GL_TEXTURE0_ARB
;
2346 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2348 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2349 _mesa_debug(ctx
, "glActiveTexture %s\n",
2350 _mesa_lookup_enum_by_nr(target
));
2352 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
2353 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTextureARB(target)");
2357 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2358 ctx
->Texture
.CurrentUnit
= texUnit
;
2359 if (ctx
->Driver
.ActiveTexture
) {
2360 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2365 /* GL_ARB_multitexture */
2367 _mesa_ClientActiveTextureARB( GLenum target
)
2369 GET_CURRENT_CONTEXT(ctx
);
2370 GLuint texUnit
= target
- GL_TEXTURE0_ARB
;
2371 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2373 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
2374 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTextureARB(target)");
2378 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2379 ctx
->Array
.ActiveTexture
= texUnit
;
2384 /**********************************************************************/
2385 /* Pixel Texgen Extensions */
2386 /**********************************************************************/
2389 _mesa_PixelTexGenSGIX(GLenum mode
)
2391 GLenum newRgbSource
, newAlphaSource
;
2392 GET_CURRENT_CONTEXT(ctx
);
2393 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2397 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2398 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2401 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2402 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2405 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2406 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2409 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2410 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2413 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenSGIX(mode)");
2417 if (newRgbSource
== ctx
->Pixel
.FragmentRgbSource
&&
2418 newAlphaSource
== ctx
->Pixel
.FragmentAlphaSource
)
2421 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2422 ctx
->Pixel
.FragmentRgbSource
= newRgbSource
;
2423 ctx
->Pixel
.FragmentAlphaSource
= newAlphaSource
;
2428 _mesa_PixelTexGenParameterfSGIS(GLenum target
, GLfloat value
)
2430 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) value
);
2435 _mesa_PixelTexGenParameterfvSGIS(GLenum target
, const GLfloat
*value
)
2437 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) *value
);
2442 _mesa_PixelTexGenParameteriSGIS(GLenum target
, GLint value
)
2444 GET_CURRENT_CONTEXT(ctx
);
2445 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2447 if (value
!= GL_CURRENT_RASTER_COLOR
&& value
!= GL_PIXEL_GROUP_COLOR_SGIS
) {
2448 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(value)");
2453 case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
:
2454 if (ctx
->Pixel
.FragmentRgbSource
== (GLenum
) value
)
2456 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2457 ctx
->Pixel
.FragmentRgbSource
= (GLenum
) value
;
2459 case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
:
2460 if (ctx
->Pixel
.FragmentAlphaSource
== (GLenum
) value
)
2462 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2463 ctx
->Pixel
.FragmentAlphaSource
= (GLenum
) value
;
2466 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(target)");
2473 _mesa_PixelTexGenParameterivSGIS(GLenum target
, const GLint
*value
)
2475 _mesa_PixelTexGenParameteriSGIS(target
, *value
);
2480 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target
, GLfloat
*value
)
2482 GET_CURRENT_CONTEXT(ctx
);
2483 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2485 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2486 *value
= (GLfloat
) ctx
->Pixel
.FragmentRgbSource
;
2488 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2489 *value
= (GLfloat
) ctx
->Pixel
.FragmentAlphaSource
;
2492 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterfvSGIS(target)");
2498 _mesa_GetPixelTexGenParameterivSGIS(GLenum target
, GLint
*value
)
2500 GET_CURRENT_CONTEXT(ctx
);
2501 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2503 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2504 *value
= (GLint
) ctx
->Pixel
.FragmentRgbSource
;
2506 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2507 *value
= (GLint
) ctx
->Pixel
.FragmentAlphaSource
;
2510 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterivSGIS(target)");