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"
40 #define TE_ERROR(errCode, msg, value) \
41 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
44 /** Set texture env mode */
46 set_env_mode(GLcontext
*ctx
,
47 struct gl_texture_unit
*texUnit
,
52 if (texUnit
->EnvMode
== mode
)
63 mode
= GL_REPLACE
; /* GL_REPLACE_EXT != GL_REPLACE */
67 legal
= ctx
->Extensions
.EXT_texture_env_add
;
70 legal
= (ctx
->Extensions
.EXT_texture_env_combine
||
71 ctx
->Extensions
.ARB_texture_env_combine
);
74 legal
= ctx
->Extensions
.NV_texture_env_combine4
;
81 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
82 texUnit
->EnvMode
= mode
;
85 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
91 set_env_color(GLcontext
*ctx
,
92 struct gl_texture_unit
*texUnit
,
96 tmp
[0] = CLAMP(color
[0], 0.0F
, 1.0F
);
97 tmp
[1] = CLAMP(color
[1], 0.0F
, 1.0F
);
98 tmp
[2] = CLAMP(color
[2], 0.0F
, 1.0F
);
99 tmp
[3] = CLAMP(color
[3], 0.0F
, 1.0F
);
100 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
102 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
103 COPY_4FV(texUnit
->EnvColor
, tmp
);
107 /** Set an RGB or A combiner mode/function */
109 set_combiner_mode(GLcontext
*ctx
,
110 struct gl_texture_unit
*texUnit
,
111 GLenum pname
, GLenum mode
)
115 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
116 !ctx
->Extensions
.ARB_texture_env_combine
) {
117 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
130 legal
= ctx
->Extensions
.ARB_texture_env_combine
;
132 case GL_DOT3_RGB_EXT
:
133 case GL_DOT3_RGBA_EXT
:
134 legal
= (ctx
->Extensions
.EXT_texture_env_dot3
&&
135 pname
== GL_COMBINE_RGB
);
139 legal
= (ctx
->Extensions
.ARB_texture_env_dot3
&&
140 pname
== GL_COMBINE_RGB
);
142 case GL_MODULATE_ADD_ATI
:
143 case GL_MODULATE_SIGNED_ADD_ATI
:
144 case GL_MODULATE_SUBTRACT_ATI
:
145 legal
= ctx
->Extensions
.ATI_texture_env_combine3
;
147 case GL_BUMP_ENVMAP_ATI
:
148 legal
= (ctx
->Extensions
.ATI_envmap_bumpmap
&&
149 pname
== GL_COMBINE_RGB
);
156 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
162 if (texUnit
->Combine
.ModeRGB
== mode
)
164 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
165 texUnit
->Combine
.ModeRGB
= mode
;
168 case GL_COMBINE_ALPHA
:
169 if (texUnit
->Combine
.ModeA
== mode
)
171 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
172 texUnit
->Combine
.ModeA
= mode
;
175 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
181 /** Set an RGB or A combiner source term */
183 set_combiner_source(GLcontext
*ctx
,
184 struct gl_texture_unit
*texUnit
,
185 GLenum pname
, GLenum param
)
188 GLboolean alpha
, legal
;
190 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
191 !ctx
->Extensions
.ARB_texture_env_combine
) {
192 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
197 * Translate pname to (term, alpha).
212 case GL_SOURCE3_RGB_NV
:
213 if (ctx
->Extensions
.NV_texture_env_combine4
) {
218 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
222 case GL_SOURCE0_ALPHA
:
226 case GL_SOURCE1_ALPHA
:
230 case GL_SOURCE2_ALPHA
:
234 case GL_SOURCE3_ALPHA_NV
:
235 if (ctx
->Extensions
.NV_texture_env_combine4
) {
240 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
245 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
249 assert(term
< MAX_COMBINER_TERMS
);
252 * Error-check param (the source term)
257 case GL_PRIMARY_COLOR
:
269 legal
= (ctx
->Extensions
.ARB_texture_env_crossbar
&&
270 param
- GL_TEXTURE0
< ctx
->Const
.MaxTextureUnits
);
273 legal
= (ctx
->Extensions
.ATI_texture_env_combine3
||
274 ctx
->Extensions
.NV_texture_env_combine4
);
277 legal
= ctx
->Extensions
.ATI_texture_env_combine3
;
284 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", param
);
288 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
291 texUnit
->Combine
.SourceA
[term
] = param
;
293 texUnit
->Combine
.SourceRGB
[term
] = param
;
297 /** Set an RGB or A combiner operand term */
299 set_combiner_operand(GLcontext
*ctx
,
300 struct gl_texture_unit
*texUnit
,
301 GLenum pname
, GLenum param
)
304 GLboolean alpha
, legal
;
306 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
307 !ctx
->Extensions
.ARB_texture_env_combine
) {
308 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
313 case GL_OPERAND0_RGB
:
317 case GL_OPERAND1_RGB
:
321 case GL_OPERAND2_RGB
:
322 if (ctx
->Extensions
.ARB_texture_env_combine
) {
327 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
331 case GL_OPERAND3_RGB_NV
:
332 if (ctx
->Extensions
.NV_texture_env_combine4
) {
337 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
341 case GL_OPERAND0_ALPHA
:
345 case GL_OPERAND1_ALPHA
:
349 case GL_OPERAND2_ALPHA
:
350 if (ctx
->Extensions
.ARB_texture_env_combine
) {
355 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
359 case GL_OPERAND3_ALPHA_NV
:
360 if (ctx
->Extensions
.NV_texture_env_combine4
) {
365 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
370 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
374 assert(term
< MAX_COMBINER_TERMS
);
377 * Error-check param (the source operand)
381 case GL_ONE_MINUS_SRC_COLOR
:
385 case GL_ONE_MINUS_SRC_ALPHA
:
393 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", param
);
397 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
400 texUnit
->Combine
.OperandA
[term
] = param
;
402 texUnit
->Combine
.OperandRGB
[term
] = param
;
407 set_combiner_scale(GLcontext
*ctx
,
408 struct gl_texture_unit
*texUnit
,
409 GLenum pname
, GLfloat scale
)
413 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
414 !ctx
->Extensions
.ARB_texture_env_combine
) {
415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
422 else if (scale
== 2.0F
) {
425 else if (scale
== 4.0F
) {
429 _mesa_error( ctx
, GL_INVALID_VALUE
,
430 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
436 if (texUnit
->Combine
.ScaleShiftRGB
== shift
)
438 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
439 texUnit
->Combine
.ScaleShiftRGB
= shift
;
442 if (texUnit
->Combine
.ScaleShiftA
== shift
)
444 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
445 texUnit
->Combine
.ScaleShiftA
= shift
;
448 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
455 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
458 GET_CURRENT_CONTEXT(ctx
);
459 struct gl_texture_unit
*texUnit
;
460 ASSERT_OUTSIDE_BEGIN_END(ctx
);
462 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
463 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
464 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
465 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
469 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
471 if (target
== GL_TEXTURE_ENV
) {
473 case GL_TEXTURE_ENV_MODE
:
474 set_env_mode(ctx
, texUnit
, (GLenum
) (GLint
) param
[0]);
476 case GL_TEXTURE_ENV_COLOR
:
477 set_env_color(ctx
, texUnit
, param
);
480 case GL_COMBINE_ALPHA
:
481 set_combiner_mode(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
486 case GL_SOURCE3_RGB_NV
:
487 case GL_SOURCE0_ALPHA
:
488 case GL_SOURCE1_ALPHA
:
489 case GL_SOURCE2_ALPHA
:
490 case GL_SOURCE3_ALPHA_NV
:
491 set_combiner_source(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
493 case GL_OPERAND0_RGB
:
494 case GL_OPERAND1_RGB
:
495 case GL_OPERAND2_RGB
:
496 case GL_OPERAND3_RGB_NV
:
497 case GL_OPERAND0_ALPHA
:
498 case GL_OPERAND1_ALPHA
:
499 case GL_OPERAND2_ALPHA
:
500 case GL_OPERAND3_ALPHA_NV
:
501 set_combiner_operand(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
505 set_combiner_scale(ctx
, texUnit
, pname
, param
[0]);
507 case GL_BUMP_TARGET_ATI
:
508 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
509 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
512 if (((GLenum
) (GLint
) param
[0] < GL_TEXTURE0
) ||
513 ((GLenum
) (GLint
) param
[0] > GL_TEXTURE31
)) {
514 /* spec doesn't say this but it seems logical */
515 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param=0x%x)", (GLenum
) (GLint
) param
[0]);
518 if (!((1 << ((GLenum
) (GLint
) param
[0] - GL_TEXTURE0
)) & ctx
->Const
.SupportedBumpUnits
)) {
519 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", (GLenum
) (GLint
) param
[0]);
523 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
524 texUnit
->BumpTarget
= (GLenum
) (GLint
) param
[0];
528 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
532 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
533 /* GL_EXT_texture_lod_bias */
534 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
535 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
538 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
539 if (texUnit
->LodBias
== param
[0])
541 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
542 texUnit
->LodBias
= param
[0];
545 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
549 else if (target
== GL_POINT_SPRITE_NV
) {
550 /* GL_ARB_point_sprite / GL_NV_point_sprite */
551 if (!ctx
->Extensions
.NV_point_sprite
552 && !ctx
->Extensions
.ARB_point_sprite
) {
553 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
556 if (pname
== GL_COORD_REPLACE_NV
) {
557 const GLenum value
= (GLenum
) param
[0];
558 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
559 /* It's kind of weird to set point state via glTexEnv,
560 * but that's what the spec calls for.
562 const GLboolean state
= (GLboolean
) value
;
563 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
565 FLUSH_VERTICES(ctx
, _NEW_POINT
);
566 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
569 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
574 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
579 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
583 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
584 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
585 _mesa_lookup_enum_by_nr(target
),
586 _mesa_lookup_enum_by_nr(pname
),
588 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
590 /* Tell device driver about the new texture environment */
591 if (ctx
->Driver
.TexEnv
) {
592 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
598 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
600 _mesa_TexEnvfv( target
, pname
, ¶m
);
606 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
609 p
[0] = (GLfloat
) param
;
610 p
[1] = p
[2] = p
[3] = 0.0;
611 _mesa_TexEnvfv( target
, pname
, p
);
616 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
619 if (pname
== GL_TEXTURE_ENV_COLOR
) {
620 p
[0] = INT_TO_FLOAT( param
[0] );
621 p
[1] = INT_TO_FLOAT( param
[1] );
622 p
[2] = INT_TO_FLOAT( param
[2] );
623 p
[3] = INT_TO_FLOAT( param
[3] );
626 p
[0] = (GLfloat
) param
[0];
627 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
629 _mesa_TexEnvfv( target
, pname
, p
);
635 * Helper for glGetTexEnvi/f()
636 * \return value of queried pname or -1 if error.
639 get_texenvi(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
643 case GL_TEXTURE_ENV_MODE
:
644 return texUnit
->EnvMode
;
647 if (ctx
->Extensions
.EXT_texture_env_combine
||
648 ctx
->Extensions
.ARB_texture_env_combine
) {
649 return texUnit
->Combine
.ModeRGB
;
652 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
655 case GL_COMBINE_ALPHA
:
656 if (ctx
->Extensions
.EXT_texture_env_combine
||
657 ctx
->Extensions
.ARB_texture_env_combine
) {
658 return texUnit
->Combine
.ModeA
;
661 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
667 if (ctx
->Extensions
.EXT_texture_env_combine
||
668 ctx
->Extensions
.ARB_texture_env_combine
) {
669 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
670 return texUnit
->Combine
.SourceRGB
[rgb_idx
];
673 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
676 case GL_SOURCE3_RGB_NV
:
677 if (ctx
->Extensions
.NV_texture_env_combine4
) {
678 return texUnit
->Combine
.SourceRGB
[3];
681 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
684 case GL_SOURCE0_ALPHA
:
685 case GL_SOURCE1_ALPHA
:
686 case GL_SOURCE2_ALPHA
:
687 if (ctx
->Extensions
.EXT_texture_env_combine
||
688 ctx
->Extensions
.ARB_texture_env_combine
) {
689 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
690 return texUnit
->Combine
.SourceA
[alpha_idx
];
693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
696 case GL_SOURCE3_ALPHA_NV
:
697 if (ctx
->Extensions
.NV_texture_env_combine4
) {
698 return texUnit
->Combine
.SourceA
[3];
701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
704 case GL_OPERAND0_RGB
:
705 case GL_OPERAND1_RGB
:
706 case GL_OPERAND2_RGB
:
707 if (ctx
->Extensions
.EXT_texture_env_combine
||
708 ctx
->Extensions
.ARB_texture_env_combine
) {
709 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
710 return texUnit
->Combine
.OperandRGB
[op_rgb
];
713 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
716 case GL_OPERAND3_RGB_NV
:
717 if (ctx
->Extensions
.NV_texture_env_combine4
) {
718 return texUnit
->Combine
.OperandRGB
[3];
721 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
724 case GL_OPERAND0_ALPHA
:
725 case GL_OPERAND1_ALPHA
:
726 case GL_OPERAND2_ALPHA
:
727 if (ctx
->Extensions
.EXT_texture_env_combine
||
728 ctx
->Extensions
.ARB_texture_env_combine
) {
729 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
730 return texUnit
->Combine
.OperandA
[op_alpha
];
733 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
736 case GL_OPERAND3_ALPHA_NV
:
737 if (ctx
->Extensions
.NV_texture_env_combine4
) {
738 return texUnit
->Combine
.OperandA
[3];
741 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
745 if (ctx
->Extensions
.EXT_texture_env_combine
||
746 ctx
->Extensions
.ARB_texture_env_combine
) {
747 return 1 << texUnit
->Combine
.ScaleShiftRGB
;
750 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
754 if (ctx
->Extensions
.EXT_texture_env_combine
||
755 ctx
->Extensions
.ARB_texture_env_combine
) {
756 return 1 << texUnit
->Combine
.ScaleShiftA
;
759 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
762 case GL_BUMP_TARGET_ATI
:
763 /* spec doesn't say so, but I think this should be queryable */
764 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
765 return texUnit
->BumpTarget
;
768 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
776 return -1; /* error */
782 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
785 const struct gl_texture_unit
*texUnit
;
786 GET_CURRENT_CONTEXT(ctx
);
787 ASSERT_OUTSIDE_BEGIN_END(ctx
);
789 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
790 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
791 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
792 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
796 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
798 if (target
== GL_TEXTURE_ENV
) {
799 if (pname
== GL_TEXTURE_ENV_COLOR
) {
800 COPY_4FV( params
, texUnit
->EnvColor
);
803 GLint val
= get_texenvi(ctx
, texUnit
, pname
);
805 *params
= (GLfloat
) val
;
809 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
810 /* GL_EXT_texture_lod_bias */
811 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
812 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
815 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
816 *params
= texUnit
->LodBias
;
819 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
823 else if (target
== GL_POINT_SPRITE_NV
) {
824 /* GL_ARB_point_sprite / GL_NV_point_sprite */
825 if (!ctx
->Extensions
.NV_point_sprite
826 && !ctx
->Extensions
.ARB_point_sprite
) {
827 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
830 if (pname
== GL_COORD_REPLACE_NV
) {
831 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
834 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
839 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
846 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
849 const struct gl_texture_unit
*texUnit
;
850 GET_CURRENT_CONTEXT(ctx
);
851 ASSERT_OUTSIDE_BEGIN_END(ctx
);
853 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
854 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
855 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
856 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
860 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
862 if (target
== GL_TEXTURE_ENV
) {
863 if (pname
== GL_TEXTURE_ENV_COLOR
) {
864 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
865 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
866 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
867 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
870 GLint val
= get_texenvi(ctx
, texUnit
, pname
);
876 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
877 /* GL_EXT_texture_lod_bias */
878 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
879 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
882 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
883 *params
= (GLint
) texUnit
->LodBias
;
886 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
890 else if (target
== GL_POINT_SPRITE_NV
) {
891 /* GL_ARB_point_sprite / GL_NV_point_sprite */
892 if (!ctx
->Extensions
.NV_point_sprite
893 && !ctx
->Extensions
.ARB_point_sprite
) {
894 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
897 if (pname
== GL_COORD_REPLACE_NV
) {
898 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
901 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
906 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
911 /* why does ATI_envmap_bumpmap require new entrypoints? Should just
912 reuse TexEnv ones... */
914 _mesa_TexBumpParameterivATI( GLenum pname
, const GLint
*param
)
917 if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
918 /* hope that conversion is correct here */
919 p
[0] = INT_TO_FLOAT( param
[0] );
920 p
[1] = INT_TO_FLOAT( param
[1] );
921 p
[2] = INT_TO_FLOAT( param
[2] );
922 p
[3] = INT_TO_FLOAT( param
[3] );
925 p
[0] = (GLfloat
) param
[0];
926 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
928 _mesa_TexBumpParameterfvATI( pname
, p
);
932 _mesa_TexBumpParameterfvATI( GLenum pname
, const GLfloat
*param
)
934 struct gl_texture_unit
*texUnit
;
935 GET_CURRENT_CONTEXT(ctx
);
936 ASSERT_OUTSIDE_BEGIN_END(ctx
);
938 /* should return error if extension not supported? */
939 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
941 if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
942 if (TEST_EQ_4V(param
, texUnit
->RotMatrix
))
944 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
945 COPY_4FV(texUnit
->RotMatrix
, param
);
948 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexBumpParameter(pname)" );
951 /* Drivers might want to know about this, instead of dedicated function
952 just shove it into TexEnv where it really belongs anyway */
953 if (ctx
->Driver
.TexEnv
) {
954 (*ctx
->Driver
.TexEnv
)( ctx
, 0, pname
, param
);
959 _mesa_GetTexBumpParameterivATI( GLenum pname
, GLint
*param
)
961 const struct gl_texture_unit
*texUnit
;
964 GET_CURRENT_CONTEXT(ctx
);
965 ASSERT_OUTSIDE_BEGIN_END(ctx
);
967 /* should return error if extension not supported? */
968 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
970 if (pname
== GL_BUMP_ROT_MATRIX_SIZE_ATI
) {
971 /* spec leaves open to support larger matrices.
972 Don't think anyone would ever want to use it
973 (and apps almost certainly would not understand it and
974 thus fail to submit matrices correctly) so hardcode this. */
977 else if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
978 /* hope that conversion is correct here */
979 param
[0] = FLOAT_TO_INT(texUnit
->RotMatrix
[0]);
980 param
[1] = FLOAT_TO_INT(texUnit
->RotMatrix
[1]);
981 param
[2] = FLOAT_TO_INT(texUnit
->RotMatrix
[2]);
982 param
[3] = FLOAT_TO_INT(texUnit
->RotMatrix
[3]);
984 else if (pname
== GL_BUMP_NUM_TEX_UNITS_ATI
) {
985 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
986 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
992 else if (pname
== GL_BUMP_TEX_UNITS_ATI
) {
993 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
994 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
995 *param
++ = i
+ GL_TEXTURE0
;
1000 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexBumpParameter(pname)" );
1006 _mesa_GetTexBumpParameterfvATI( GLenum pname
, GLfloat
*param
)
1008 const struct gl_texture_unit
*texUnit
;
1011 GET_CURRENT_CONTEXT(ctx
);
1012 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1014 /* should return error if extension not supported? */
1015 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1017 if (pname
== GL_BUMP_ROT_MATRIX_SIZE_ATI
) {
1018 /* spec leaves open to support larger matrices.
1019 Don't think anyone would ever want to use it
1020 (and apps might not understand it) so hardcode this. */
1021 *param
= (GLfloat
) 4;
1023 else if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
1024 param
[0] = texUnit
->RotMatrix
[0];
1025 param
[1] = texUnit
->RotMatrix
[1];
1026 param
[2] = texUnit
->RotMatrix
[2];
1027 param
[3] = texUnit
->RotMatrix
[3];
1029 else if (pname
== GL_BUMP_NUM_TEX_UNITS_ATI
) {
1030 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1031 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
1035 *param
= (GLfloat
) temp
;
1037 else if (pname
== GL_BUMP_TEX_UNITS_ATI
) {
1038 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1039 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
1040 *param
++ = (GLfloat
) (i
+ GL_TEXTURE0
);
1045 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexBumpParameter(pname)" );