2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * glTexEnv-related functions
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/enums.h"
36 #include "main/macros.h"
37 #include "main/texenv.h"
38 #include "main/texstate.h"
41 #define TE_ERROR(errCode, msg, value) \
42 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
45 /** Set texture env mode */
47 set_env_mode(GLcontext
*ctx
,
48 struct gl_texture_unit
*texUnit
,
53 if (texUnit
->EnvMode
== mode
)
64 mode
= GL_REPLACE
; /* GL_REPLACE_EXT != GL_REPLACE */
68 legal
= ctx
->Extensions
.EXT_texture_env_add
;
71 legal
= (ctx
->Extensions
.EXT_texture_env_combine
||
72 ctx
->Extensions
.ARB_texture_env_combine
);
75 legal
= ctx
->Extensions
.NV_texture_env_combine4
;
82 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
83 texUnit
->EnvMode
= mode
;
86 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
92 set_env_color(GLcontext
*ctx
,
93 struct gl_texture_unit
*texUnit
,
97 tmp
[0] = CLAMP(color
[0], 0.0F
, 1.0F
);
98 tmp
[1] = CLAMP(color
[1], 0.0F
, 1.0F
);
99 tmp
[2] = CLAMP(color
[2], 0.0F
, 1.0F
);
100 tmp
[3] = CLAMP(color
[3], 0.0F
, 1.0F
);
101 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
103 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
104 COPY_4FV(texUnit
->EnvColor
, tmp
);
108 /** Set an RGB or A combiner mode/function */
110 set_combiner_mode(GLcontext
*ctx
,
111 struct gl_texture_unit
*texUnit
,
112 GLenum pname
, GLenum mode
)
116 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
117 !ctx
->Extensions
.ARB_texture_env_combine
) {
118 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
131 legal
= ctx
->Extensions
.ARB_texture_env_combine
;
133 case GL_DOT3_RGB_EXT
:
134 case GL_DOT3_RGBA_EXT
:
135 legal
= (ctx
->Extensions
.EXT_texture_env_dot3
&&
136 pname
== GL_COMBINE_RGB
);
140 legal
= (ctx
->Extensions
.ARB_texture_env_dot3
&&
141 pname
== GL_COMBINE_RGB
);
143 case GL_MODULATE_ADD_ATI
:
144 case GL_MODULATE_SIGNED_ADD_ATI
:
145 case GL_MODULATE_SUBTRACT_ATI
:
146 legal
= ctx
->Extensions
.ATI_texture_env_combine3
;
148 case GL_BUMP_ENVMAP_ATI
:
149 legal
= (ctx
->Extensions
.ATI_envmap_bumpmap
&&
150 pname
== GL_COMBINE_RGB
);
157 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
163 if (texUnit
->Combine
.ModeRGB
== mode
)
165 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
166 texUnit
->Combine
.ModeRGB
= mode
;
169 case GL_COMBINE_ALPHA
:
170 if (texUnit
->Combine
.ModeA
== mode
)
172 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
173 texUnit
->Combine
.ModeA
= mode
;
176 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
182 /** Set an RGB or A combiner source term */
184 set_combiner_source(GLcontext
*ctx
,
185 struct gl_texture_unit
*texUnit
,
186 GLenum pname
, GLenum param
)
189 GLboolean alpha
, legal
;
191 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
192 !ctx
->Extensions
.ARB_texture_env_combine
) {
193 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
198 * Translate pname to (term, alpha).
213 case GL_SOURCE3_RGB_NV
:
214 if (ctx
->Extensions
.NV_texture_env_combine4
) {
219 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
223 case GL_SOURCE0_ALPHA
:
227 case GL_SOURCE1_ALPHA
:
231 case GL_SOURCE2_ALPHA
:
235 case GL_SOURCE3_ALPHA_NV
:
236 if (ctx
->Extensions
.NV_texture_env_combine4
) {
241 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
246 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
250 assert(term
< MAX_COMBINER_TERMS
);
253 * Error-check param (the source term)
258 case GL_PRIMARY_COLOR
:
270 legal
= (ctx
->Extensions
.ARB_texture_env_crossbar
&&
271 param
- GL_TEXTURE0
< ctx
->Const
.MaxTextureUnits
);
274 legal
= (ctx
->Extensions
.ATI_texture_env_combine3
||
275 ctx
->Extensions
.NV_texture_env_combine4
);
278 legal
= ctx
->Extensions
.ATI_texture_env_combine3
;
285 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", param
);
289 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
292 texUnit
->Combine
.SourceA
[term
] = param
;
294 texUnit
->Combine
.SourceRGB
[term
] = param
;
298 /** Set an RGB or A combiner operand term */
300 set_combiner_operand(GLcontext
*ctx
,
301 struct gl_texture_unit
*texUnit
,
302 GLenum pname
, GLenum param
)
305 GLboolean alpha
, legal
;
307 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
308 !ctx
->Extensions
.ARB_texture_env_combine
) {
309 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
314 case GL_OPERAND0_RGB
:
318 case GL_OPERAND1_RGB
:
322 case GL_OPERAND2_RGB
:
323 if (ctx
->Extensions
.ARB_texture_env_combine
) {
328 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
332 case GL_OPERAND3_RGB_NV
:
333 if (ctx
->Extensions
.NV_texture_env_combine4
) {
338 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
342 case GL_OPERAND0_ALPHA
:
346 case GL_OPERAND1_ALPHA
:
350 case GL_OPERAND2_ALPHA
:
351 if (ctx
->Extensions
.ARB_texture_env_combine
) {
356 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
360 case GL_OPERAND3_ALPHA_NV
:
361 if (ctx
->Extensions
.NV_texture_env_combine4
) {
366 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
371 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
375 assert(term
< MAX_COMBINER_TERMS
);
378 * Error-check param (the source operand)
382 case GL_ONE_MINUS_SRC_COLOR
:
386 case GL_ONE_MINUS_SRC_ALPHA
:
394 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", param
);
398 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
401 texUnit
->Combine
.OperandA
[term
] = param
;
403 texUnit
->Combine
.OperandRGB
[term
] = param
;
408 set_combiner_scale(GLcontext
*ctx
,
409 struct gl_texture_unit
*texUnit
,
410 GLenum pname
, GLfloat scale
)
414 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
415 !ctx
->Extensions
.ARB_texture_env_combine
) {
416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
423 else if (scale
== 2.0F
) {
426 else if (scale
== 4.0F
) {
430 _mesa_error( ctx
, GL_INVALID_VALUE
,
431 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
437 if (texUnit
->Combine
.ScaleShiftRGB
== shift
)
439 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
440 texUnit
->Combine
.ScaleShiftRGB
= shift
;
443 if (texUnit
->Combine
.ScaleShiftA
== shift
)
445 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
446 texUnit
->Combine
.ScaleShiftA
= shift
;
449 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
456 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
459 GET_CURRENT_CONTEXT(ctx
);
460 struct gl_texture_unit
*texUnit
;
461 ASSERT_OUTSIDE_BEGIN_END(ctx
);
463 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
464 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
465 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
466 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
470 texUnit
= _mesa_get_current_tex_unit(ctx
);
472 if (target
== GL_TEXTURE_ENV
) {
474 case GL_TEXTURE_ENV_MODE
:
475 set_env_mode(ctx
, texUnit
, (GLenum
) (GLint
) param
[0]);
477 case GL_TEXTURE_ENV_COLOR
:
478 set_env_color(ctx
, texUnit
, param
);
481 case GL_COMBINE_ALPHA
:
482 set_combiner_mode(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
487 case GL_SOURCE3_RGB_NV
:
488 case GL_SOURCE0_ALPHA
:
489 case GL_SOURCE1_ALPHA
:
490 case GL_SOURCE2_ALPHA
:
491 case GL_SOURCE3_ALPHA_NV
:
492 set_combiner_source(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
494 case GL_OPERAND0_RGB
:
495 case GL_OPERAND1_RGB
:
496 case GL_OPERAND2_RGB
:
497 case GL_OPERAND3_RGB_NV
:
498 case GL_OPERAND0_ALPHA
:
499 case GL_OPERAND1_ALPHA
:
500 case GL_OPERAND2_ALPHA
:
501 case GL_OPERAND3_ALPHA_NV
:
502 set_combiner_operand(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
506 set_combiner_scale(ctx
, texUnit
, pname
, param
[0]);
508 case GL_BUMP_TARGET_ATI
:
509 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
510 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
513 if (((GLenum
) (GLint
) param
[0] < GL_TEXTURE0
) ||
514 ((GLenum
) (GLint
) param
[0] > GL_TEXTURE31
)) {
515 /* spec doesn't say this but it seems logical */
516 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param=0x%x)", (GLenum
) (GLint
) param
[0]);
519 if (!((1 << ((GLenum
) (GLint
) param
[0] - GL_TEXTURE0
)) & ctx
->Const
.SupportedBumpUnits
)) {
520 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", (GLenum
) (GLint
) param
[0]);
524 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
525 texUnit
->BumpTarget
= (GLenum
) (GLint
) param
[0];
529 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
533 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
534 /* GL_EXT_texture_lod_bias */
535 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
536 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
539 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
540 if (texUnit
->LodBias
== param
[0])
542 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
543 texUnit
->LodBias
= param
[0];
546 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
550 else if (target
== GL_POINT_SPRITE_NV
) {
551 /* GL_ARB_point_sprite / GL_NV_point_sprite */
552 if (!ctx
->Extensions
.NV_point_sprite
553 && !ctx
->Extensions
.ARB_point_sprite
) {
554 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
557 if (pname
== GL_COORD_REPLACE_NV
) {
558 const GLenum value
= (GLenum
) param
[0];
559 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
560 /* It's kind of weird to set point state via glTexEnv,
561 * but that's what the spec calls for.
563 const GLboolean state
= (GLboolean
) value
;
564 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
566 FLUSH_VERTICES(ctx
, _NEW_POINT
);
567 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
570 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
575 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
580 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
584 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
585 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
586 _mesa_lookup_enum_by_nr(target
),
587 _mesa_lookup_enum_by_nr(pname
),
589 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
591 /* Tell device driver about the new texture environment */
592 if (ctx
->Driver
.TexEnv
) {
593 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
599 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
601 _mesa_TexEnvfv( target
, pname
, ¶m
);
607 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
610 p
[0] = (GLfloat
) param
;
611 p
[1] = p
[2] = p
[3] = 0.0;
612 _mesa_TexEnvfv( target
, pname
, p
);
617 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
620 if (pname
== GL_TEXTURE_ENV_COLOR
) {
621 p
[0] = INT_TO_FLOAT( param
[0] );
622 p
[1] = INT_TO_FLOAT( param
[1] );
623 p
[2] = INT_TO_FLOAT( param
[2] );
624 p
[3] = INT_TO_FLOAT( param
[3] );
627 p
[0] = (GLfloat
) param
[0];
628 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
630 _mesa_TexEnvfv( target
, pname
, p
);
636 * Helper for glGetTexEnvi/f()
637 * \return value of queried pname or -1 if error.
640 get_texenvi(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
644 case GL_TEXTURE_ENV_MODE
:
645 return texUnit
->EnvMode
;
648 if (ctx
->Extensions
.EXT_texture_env_combine
||
649 ctx
->Extensions
.ARB_texture_env_combine
) {
650 return texUnit
->Combine
.ModeRGB
;
653 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
656 case GL_COMBINE_ALPHA
:
657 if (ctx
->Extensions
.EXT_texture_env_combine
||
658 ctx
->Extensions
.ARB_texture_env_combine
) {
659 return texUnit
->Combine
.ModeA
;
662 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
668 if (ctx
->Extensions
.EXT_texture_env_combine
||
669 ctx
->Extensions
.ARB_texture_env_combine
) {
670 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
671 return texUnit
->Combine
.SourceRGB
[rgb_idx
];
674 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
677 case GL_SOURCE3_RGB_NV
:
678 if (ctx
->Extensions
.NV_texture_env_combine4
) {
679 return texUnit
->Combine
.SourceRGB
[3];
682 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
685 case GL_SOURCE0_ALPHA
:
686 case GL_SOURCE1_ALPHA
:
687 case GL_SOURCE2_ALPHA
:
688 if (ctx
->Extensions
.EXT_texture_env_combine
||
689 ctx
->Extensions
.ARB_texture_env_combine
) {
690 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
691 return texUnit
->Combine
.SourceA
[alpha_idx
];
694 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
697 case GL_SOURCE3_ALPHA_NV
:
698 if (ctx
->Extensions
.NV_texture_env_combine4
) {
699 return texUnit
->Combine
.SourceA
[3];
702 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
705 case GL_OPERAND0_RGB
:
706 case GL_OPERAND1_RGB
:
707 case GL_OPERAND2_RGB
:
708 if (ctx
->Extensions
.EXT_texture_env_combine
||
709 ctx
->Extensions
.ARB_texture_env_combine
) {
710 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
711 return texUnit
->Combine
.OperandRGB
[op_rgb
];
714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
717 case GL_OPERAND3_RGB_NV
:
718 if (ctx
->Extensions
.NV_texture_env_combine4
) {
719 return texUnit
->Combine
.OperandRGB
[3];
722 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
725 case GL_OPERAND0_ALPHA
:
726 case GL_OPERAND1_ALPHA
:
727 case GL_OPERAND2_ALPHA
:
728 if (ctx
->Extensions
.EXT_texture_env_combine
||
729 ctx
->Extensions
.ARB_texture_env_combine
) {
730 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
731 return texUnit
->Combine
.OperandA
[op_alpha
];
734 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
737 case GL_OPERAND3_ALPHA_NV
:
738 if (ctx
->Extensions
.NV_texture_env_combine4
) {
739 return texUnit
->Combine
.OperandA
[3];
742 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
746 if (ctx
->Extensions
.EXT_texture_env_combine
||
747 ctx
->Extensions
.ARB_texture_env_combine
) {
748 return 1 << texUnit
->Combine
.ScaleShiftRGB
;
751 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
755 if (ctx
->Extensions
.EXT_texture_env_combine
||
756 ctx
->Extensions
.ARB_texture_env_combine
) {
757 return 1 << texUnit
->Combine
.ScaleShiftA
;
760 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
763 case GL_BUMP_TARGET_ATI
:
764 /* spec doesn't say so, but I think this should be queryable */
765 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
766 return texUnit
->BumpTarget
;
769 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
777 return -1; /* error */
783 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
786 const struct gl_texture_unit
*texUnit
;
787 GET_CURRENT_CONTEXT(ctx
);
788 ASSERT_OUTSIDE_BEGIN_END(ctx
);
790 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
791 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
792 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
793 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
797 texUnit
= _mesa_get_current_tex_unit(ctx
);
799 if (target
== GL_TEXTURE_ENV
) {
800 if (pname
== GL_TEXTURE_ENV_COLOR
) {
801 COPY_4FV( params
, texUnit
->EnvColor
);
804 GLint val
= get_texenvi(ctx
, texUnit
, pname
);
806 *params
= (GLfloat
) val
;
810 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
811 /* GL_EXT_texture_lod_bias */
812 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
813 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
816 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
817 *params
= texUnit
->LodBias
;
820 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
824 else if (target
== GL_POINT_SPRITE_NV
) {
825 /* GL_ARB_point_sprite / GL_NV_point_sprite */
826 if (!ctx
->Extensions
.NV_point_sprite
827 && !ctx
->Extensions
.ARB_point_sprite
) {
828 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
831 if (pname
== GL_COORD_REPLACE_NV
) {
832 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
835 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
840 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
847 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
850 const struct gl_texture_unit
*texUnit
;
851 GET_CURRENT_CONTEXT(ctx
);
852 ASSERT_OUTSIDE_BEGIN_END(ctx
);
854 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
855 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
856 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
857 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
861 texUnit
= _mesa_get_current_tex_unit(ctx
);
863 if (target
== GL_TEXTURE_ENV
) {
864 if (pname
== GL_TEXTURE_ENV_COLOR
) {
865 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
866 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
867 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
868 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
871 GLint val
= get_texenvi(ctx
, texUnit
, pname
);
877 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
878 /* GL_EXT_texture_lod_bias */
879 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
880 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
883 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
884 *params
= (GLint
) texUnit
->LodBias
;
887 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
891 else if (target
== GL_POINT_SPRITE_NV
) {
892 /* GL_ARB_point_sprite / GL_NV_point_sprite */
893 if (!ctx
->Extensions
.NV_point_sprite
894 && !ctx
->Extensions
.ARB_point_sprite
) {
895 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
898 if (pname
== GL_COORD_REPLACE_NV
) {
899 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
902 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
907 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
912 /* why does ATI_envmap_bumpmap require new entrypoints? Should just
913 reuse TexEnv ones... */
915 _mesa_TexBumpParameterivATI( GLenum pname
, const GLint
*param
)
918 if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
919 /* hope that conversion is correct here */
920 p
[0] = INT_TO_FLOAT( param
[0] );
921 p
[1] = INT_TO_FLOAT( param
[1] );
922 p
[2] = INT_TO_FLOAT( param
[2] );
923 p
[3] = INT_TO_FLOAT( param
[3] );
926 p
[0] = (GLfloat
) param
[0];
927 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
929 _mesa_TexBumpParameterfvATI( pname
, p
);
933 _mesa_TexBumpParameterfvATI( GLenum pname
, const GLfloat
*param
)
935 struct gl_texture_unit
*texUnit
;
936 GET_CURRENT_CONTEXT(ctx
);
937 ASSERT_OUTSIDE_BEGIN_END(ctx
);
939 /* should return error if extension not supported? */
941 texUnit
= _mesa_get_current_tex_unit(ctx
);
943 if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
944 if (TEST_EQ_4V(param
, texUnit
->RotMatrix
))
946 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
947 COPY_4FV(texUnit
->RotMatrix
, param
);
950 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexBumpParameter(pname)" );
953 /* Drivers might want to know about this, instead of dedicated function
954 just shove it into TexEnv where it really belongs anyway */
955 if (ctx
->Driver
.TexEnv
) {
956 (*ctx
->Driver
.TexEnv
)( ctx
, 0, pname
, param
);
961 _mesa_GetTexBumpParameterivATI( GLenum pname
, GLint
*param
)
963 const struct gl_texture_unit
*texUnit
;
966 GET_CURRENT_CONTEXT(ctx
);
967 ASSERT_OUTSIDE_BEGIN_END(ctx
);
969 /* should return error if extension not supported? */
971 texUnit
= _mesa_get_current_tex_unit(ctx
);
973 if (pname
== GL_BUMP_ROT_MATRIX_SIZE_ATI
) {
974 /* spec leaves open to support larger matrices.
975 Don't think anyone would ever want to use it
976 (and apps almost certainly would not understand it and
977 thus fail to submit matrices correctly) so hardcode this. */
980 else if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
981 /* hope that conversion is correct here */
982 param
[0] = FLOAT_TO_INT(texUnit
->RotMatrix
[0]);
983 param
[1] = FLOAT_TO_INT(texUnit
->RotMatrix
[1]);
984 param
[2] = FLOAT_TO_INT(texUnit
->RotMatrix
[2]);
985 param
[3] = FLOAT_TO_INT(texUnit
->RotMatrix
[3]);
987 else if (pname
== GL_BUMP_NUM_TEX_UNITS_ATI
) {
988 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
989 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
995 else if (pname
== GL_BUMP_TEX_UNITS_ATI
) {
996 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
997 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
998 *param
++ = i
+ GL_TEXTURE0
;
1003 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexBumpParameter(pname)" );
1009 _mesa_GetTexBumpParameterfvATI( GLenum pname
, GLfloat
*param
)
1011 const struct gl_texture_unit
*texUnit
;
1014 GET_CURRENT_CONTEXT(ctx
);
1015 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1017 /* should return error if extension not supported? */
1019 texUnit
= _mesa_get_current_tex_unit(ctx
);
1021 if (pname
== GL_BUMP_ROT_MATRIX_SIZE_ATI
) {
1022 /* spec leaves open to support larger matrices.
1023 Don't think anyone would ever want to use it
1024 (and apps might not understand it) so hardcode this. */
1025 *param
= (GLfloat
) 4;
1027 else if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
1028 param
[0] = texUnit
->RotMatrix
[0];
1029 param
[1] = texUnit
->RotMatrix
[1];
1030 param
[2] = texUnit
->RotMatrix
[2];
1031 param
[3] = texUnit
->RotMatrix
[3];
1033 else if (pname
== GL_BUMP_NUM_TEX_UNITS_ATI
) {
1034 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1035 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
1039 *param
= (GLfloat
) temp
;
1041 else if (pname
== GL_BUMP_TEX_UNITS_ATI
) {
1042 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1043 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
1044 *param
++ = (GLfloat
) (i
+ GL_TEXTURE0
);
1049 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexBumpParameter(pname)" );