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/mtypes.h"
38 #include "main/texenv.h"
39 #include "main/texstate.h"
42 #define TE_ERROR(errCode, msg, value) \
43 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
46 /** Set texture env mode */
48 set_env_mode(struct gl_context
*ctx
,
49 struct gl_texture_unit
*texUnit
,
54 if (texUnit
->EnvMode
== mode
)
65 mode
= GL_REPLACE
; /* GL_REPLACE_EXT != GL_REPLACE */
69 legal
= ctx
->Extensions
.EXT_texture_env_add
;
72 legal
= (ctx
->Extensions
.EXT_texture_env_combine
||
73 ctx
->Extensions
.ARB_texture_env_combine
);
76 legal
= ctx
->Extensions
.NV_texture_env_combine4
;
83 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
84 texUnit
->EnvMode
= mode
;
87 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
93 set_env_color(struct gl_context
*ctx
,
94 struct gl_texture_unit
*texUnit
,
98 tmp
[0] = CLAMP(color
[0], 0.0F
, 1.0F
);
99 tmp
[1] = CLAMP(color
[1], 0.0F
, 1.0F
);
100 tmp
[2] = CLAMP(color
[2], 0.0F
, 1.0F
);
101 tmp
[3] = CLAMP(color
[3], 0.0F
, 1.0F
);
102 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
104 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
105 COPY_4FV(texUnit
->EnvColor
, tmp
);
109 /** Set an RGB or A combiner mode/function */
111 set_combiner_mode(struct gl_context
*ctx
,
112 struct gl_texture_unit
*texUnit
,
113 GLenum pname
, GLenum mode
)
117 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
118 !ctx
->Extensions
.ARB_texture_env_combine
) {
119 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
132 legal
= ctx
->Extensions
.ARB_texture_env_combine
;
134 case GL_DOT3_RGB_EXT
:
135 case GL_DOT3_RGBA_EXT
:
136 legal
= (ctx
->Extensions
.EXT_texture_env_dot3
&&
137 pname
== GL_COMBINE_RGB
);
141 legal
= (ctx
->Extensions
.ARB_texture_env_dot3
&&
142 pname
== GL_COMBINE_RGB
);
144 case GL_MODULATE_ADD_ATI
:
145 case GL_MODULATE_SIGNED_ADD_ATI
:
146 case GL_MODULATE_SUBTRACT_ATI
:
147 legal
= ctx
->Extensions
.ATI_texture_env_combine3
;
149 case GL_BUMP_ENVMAP_ATI
:
150 legal
= (ctx
->Extensions
.ATI_envmap_bumpmap
&&
151 pname
== GL_COMBINE_RGB
);
158 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
164 if (texUnit
->Combine
.ModeRGB
== mode
)
166 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
167 texUnit
->Combine
.ModeRGB
= mode
;
170 case GL_COMBINE_ALPHA
:
171 if (texUnit
->Combine
.ModeA
== mode
)
173 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
174 texUnit
->Combine
.ModeA
= mode
;
177 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
183 /** Set an RGB or A combiner source term */
185 set_combiner_source(struct gl_context
*ctx
,
186 struct gl_texture_unit
*texUnit
,
187 GLenum pname
, GLenum param
)
190 GLboolean alpha
, legal
;
192 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
193 !ctx
->Extensions
.ARB_texture_env_combine
) {
194 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
199 * Translate pname to (term, alpha).
201 * The enums were given sequential values for a reason.
207 case GL_SOURCE3_RGB_NV
:
208 term
= pname
- GL_SOURCE0_RGB
;
211 case GL_SOURCE0_ALPHA
:
212 case GL_SOURCE1_ALPHA
:
213 case GL_SOURCE2_ALPHA
:
214 case GL_SOURCE3_ALPHA_NV
:
215 term
= pname
- GL_SOURCE0_ALPHA
;
219 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
223 if ((term
== 3) && !ctx
->Extensions
.NV_texture_env_combine4
) {
224 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
228 assert(term
< MAX_COMBINER_TERMS
);
231 * Error-check param (the source term)
236 case GL_PRIMARY_COLOR
:
248 legal
= (ctx
->Extensions
.ARB_texture_env_crossbar
&&
249 param
- GL_TEXTURE0
< ctx
->Const
.MaxTextureUnits
);
252 legal
= (ctx
->Extensions
.ATI_texture_env_combine3
||
253 ctx
->Extensions
.NV_texture_env_combine4
);
256 legal
= ctx
->Extensions
.ATI_texture_env_combine3
;
263 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", param
);
267 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
270 texUnit
->Combine
.SourceA
[term
] = param
;
272 texUnit
->Combine
.SourceRGB
[term
] = param
;
276 /** Set an RGB or A combiner operand term */
278 set_combiner_operand(struct gl_context
*ctx
,
279 struct gl_texture_unit
*texUnit
,
280 GLenum pname
, GLenum param
)
283 GLboolean alpha
, legal
;
285 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
286 !ctx
->Extensions
.ARB_texture_env_combine
) {
287 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
291 /* The enums were given sequential values for a reason.
294 case GL_OPERAND0_RGB
:
295 case GL_OPERAND1_RGB
:
296 case GL_OPERAND2_RGB
:
297 case GL_OPERAND3_RGB_NV
:
298 term
= pname
- GL_OPERAND0_RGB
;
301 case GL_OPERAND0_ALPHA
:
302 case GL_OPERAND1_ALPHA
:
303 case GL_OPERAND2_ALPHA
:
304 case GL_OPERAND3_ALPHA_NV
:
305 term
= pname
- GL_OPERAND0_ALPHA
;
309 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
313 if ((term
== 3) && !ctx
->Extensions
.NV_texture_env_combine4
) {
314 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
318 assert(term
< MAX_COMBINER_TERMS
);
321 * Error-check param (the source operand)
325 case GL_ONE_MINUS_SRC_COLOR
:
326 /* The color input can only be used with GL_OPERAND[01]_RGB in the EXT
327 * version. In the ARB and NV versions they can be used for any RGB
331 && ((term
< 2) || ctx
->Extensions
.ARB_texture_env_combine
332 || ctx
->Extensions
.NV_texture_env_combine4
);
334 case GL_ONE_MINUS_SRC_ALPHA
:
335 /* GL_ONE_MINUS_SRC_ALPHA can only be used with
336 * GL_OPERAND[01]_(RGB|ALPHA) in the EXT version. In the ARB and NV
337 * versions it can be used for any operand.
339 legal
= (term
< 2) || ctx
->Extensions
.ARB_texture_env_combine
340 || ctx
->Extensions
.NV_texture_env_combine4
;
350 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", param
);
354 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
357 texUnit
->Combine
.OperandA
[term
] = param
;
359 texUnit
->Combine
.OperandRGB
[term
] = param
;
364 set_combiner_scale(struct gl_context
*ctx
,
365 struct gl_texture_unit
*texUnit
,
366 GLenum pname
, GLfloat scale
)
370 if (!ctx
->Extensions
.EXT_texture_env_combine
&&
371 !ctx
->Extensions
.ARB_texture_env_combine
) {
372 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)");
379 else if (scale
== 2.0F
) {
382 else if (scale
== 4.0F
) {
386 _mesa_error( ctx
, GL_INVALID_VALUE
,
387 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
393 if (texUnit
->Combine
.ScaleShiftRGB
== shift
)
395 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
396 texUnit
->Combine
.ScaleShiftRGB
= shift
;
399 if (texUnit
->Combine
.ScaleShiftA
== shift
)
401 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
402 texUnit
->Combine
.ScaleShiftA
= shift
;
405 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
412 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
415 GET_CURRENT_CONTEXT(ctx
);
416 struct gl_texture_unit
*texUnit
;
417 ASSERT_OUTSIDE_BEGIN_END(ctx
);
419 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
420 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
421 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
422 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
426 texUnit
= _mesa_get_current_tex_unit(ctx
);
428 if (target
== GL_TEXTURE_ENV
) {
430 case GL_TEXTURE_ENV_MODE
:
431 set_env_mode(ctx
, texUnit
, (GLenum
) (GLint
) param
[0]);
433 case GL_TEXTURE_ENV_COLOR
:
434 set_env_color(ctx
, texUnit
, param
);
437 case GL_COMBINE_ALPHA
:
438 set_combiner_mode(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
443 case GL_SOURCE3_RGB_NV
:
444 case GL_SOURCE0_ALPHA
:
445 case GL_SOURCE1_ALPHA
:
446 case GL_SOURCE2_ALPHA
:
447 case GL_SOURCE3_ALPHA_NV
:
448 set_combiner_source(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
450 case GL_OPERAND0_RGB
:
451 case GL_OPERAND1_RGB
:
452 case GL_OPERAND2_RGB
:
453 case GL_OPERAND3_RGB_NV
:
454 case GL_OPERAND0_ALPHA
:
455 case GL_OPERAND1_ALPHA
:
456 case GL_OPERAND2_ALPHA
:
457 case GL_OPERAND3_ALPHA_NV
:
458 set_combiner_operand(ctx
, texUnit
, pname
, (GLenum
) (GLint
) param
[0]);
462 set_combiner_scale(ctx
, texUnit
, pname
, param
[0]);
464 case GL_BUMP_TARGET_ATI
:
465 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
466 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
469 if (((GLenum
) (GLint
) param
[0] < GL_TEXTURE0
) ||
470 ((GLenum
) (GLint
) param
[0] > GL_TEXTURE31
)) {
471 /* spec doesn't say this but it seems logical */
472 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(param=0x%x)", (GLenum
) (GLint
) param
[0]);
475 if (!((1 << ((GLenum
) (GLint
) param
[0] - GL_TEXTURE0
)) & ctx
->Const
.SupportedBumpUnits
)) {
476 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", (GLenum
) (GLint
) param
[0]);
480 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
481 texUnit
->BumpTarget
= (GLenum
) (GLint
) param
[0];
485 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
489 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
490 /* GL_EXT_texture_lod_bias */
491 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
492 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
495 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
496 if (texUnit
->LodBias
== param
[0])
498 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
499 texUnit
->LodBias
= param
[0];
502 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
506 else if (target
== GL_POINT_SPRITE_NV
) {
507 /* GL_ARB_point_sprite / GL_NV_point_sprite */
508 if (!ctx
->Extensions
.NV_point_sprite
509 && !ctx
->Extensions
.ARB_point_sprite
) {
510 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
513 if (pname
== GL_COORD_REPLACE_NV
) {
514 const GLenum value
= (GLenum
) param
[0];
515 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
516 /* It's kind of weird to set point state via glTexEnv,
517 * but that's what the spec calls for.
519 const GLboolean state
= (GLboolean
) value
;
520 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
522 FLUSH_VERTICES(ctx
, _NEW_POINT
);
523 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
526 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
531 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
536 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
540 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
541 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
542 _mesa_lookup_enum_by_nr(target
),
543 _mesa_lookup_enum_by_nr(pname
),
545 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
547 /* Tell device driver about the new texture environment */
548 if (ctx
->Driver
.TexEnv
) {
549 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
555 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
559 p
[1] = p
[2] = p
[3] = 0.0;
560 _mesa_TexEnvfv( target
, pname
, p
);
566 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
569 p
[0] = (GLfloat
) param
;
570 p
[1] = p
[2] = p
[3] = 0.0;
571 _mesa_TexEnvfv( target
, pname
, p
);
576 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
579 if (pname
== GL_TEXTURE_ENV_COLOR
) {
580 p
[0] = INT_TO_FLOAT( param
[0] );
581 p
[1] = INT_TO_FLOAT( param
[1] );
582 p
[2] = INT_TO_FLOAT( param
[2] );
583 p
[3] = INT_TO_FLOAT( param
[3] );
586 p
[0] = (GLfloat
) param
[0];
587 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
589 _mesa_TexEnvfv( target
, pname
, p
);
595 * Helper for glGetTexEnvi/f()
596 * \return value of queried pname or -1 if error.
599 get_texenvi(struct gl_context
*ctx
, const struct gl_texture_unit
*texUnit
,
603 case GL_TEXTURE_ENV_MODE
:
604 return texUnit
->EnvMode
;
607 if (ctx
->Extensions
.EXT_texture_env_combine
||
608 ctx
->Extensions
.ARB_texture_env_combine
) {
609 return texUnit
->Combine
.ModeRGB
;
612 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
615 case GL_COMBINE_ALPHA
:
616 if (ctx
->Extensions
.EXT_texture_env_combine
||
617 ctx
->Extensions
.ARB_texture_env_combine
) {
618 return texUnit
->Combine
.ModeA
;
621 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
627 if (ctx
->Extensions
.EXT_texture_env_combine
||
628 ctx
->Extensions
.ARB_texture_env_combine
) {
629 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
630 return texUnit
->Combine
.SourceRGB
[rgb_idx
];
633 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
636 case GL_SOURCE3_RGB_NV
:
637 if (ctx
->Extensions
.NV_texture_env_combine4
) {
638 return texUnit
->Combine
.SourceRGB
[3];
641 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
644 case GL_SOURCE0_ALPHA
:
645 case GL_SOURCE1_ALPHA
:
646 case GL_SOURCE2_ALPHA
:
647 if (ctx
->Extensions
.EXT_texture_env_combine
||
648 ctx
->Extensions
.ARB_texture_env_combine
) {
649 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
650 return texUnit
->Combine
.SourceA
[alpha_idx
];
653 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
656 case GL_SOURCE3_ALPHA_NV
:
657 if (ctx
->Extensions
.NV_texture_env_combine4
) {
658 return texUnit
->Combine
.SourceA
[3];
661 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
664 case GL_OPERAND0_RGB
:
665 case GL_OPERAND1_RGB
:
666 case GL_OPERAND2_RGB
:
667 if (ctx
->Extensions
.EXT_texture_env_combine
||
668 ctx
->Extensions
.ARB_texture_env_combine
) {
669 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
670 return texUnit
->Combine
.OperandRGB
[op_rgb
];
673 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
676 case GL_OPERAND3_RGB_NV
:
677 if (ctx
->Extensions
.NV_texture_env_combine4
) {
678 return texUnit
->Combine
.OperandRGB
[3];
681 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
684 case GL_OPERAND0_ALPHA
:
685 case GL_OPERAND1_ALPHA
:
686 case GL_OPERAND2_ALPHA
:
687 if (ctx
->Extensions
.EXT_texture_env_combine
||
688 ctx
->Extensions
.ARB_texture_env_combine
) {
689 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
690 return texUnit
->Combine
.OperandA
[op_alpha
];
693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
696 case GL_OPERAND3_ALPHA_NV
:
697 if (ctx
->Extensions
.NV_texture_env_combine4
) {
698 return texUnit
->Combine
.OperandA
[3];
701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
705 if (ctx
->Extensions
.EXT_texture_env_combine
||
706 ctx
->Extensions
.ARB_texture_env_combine
) {
707 return 1 << texUnit
->Combine
.ScaleShiftRGB
;
710 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
714 if (ctx
->Extensions
.EXT_texture_env_combine
||
715 ctx
->Extensions
.ARB_texture_env_combine
) {
716 return 1 << texUnit
->Combine
.ScaleShiftA
;
719 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
722 case GL_BUMP_TARGET_ATI
:
723 /* spec doesn't say so, but I think this should be queryable */
724 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
725 return texUnit
->BumpTarget
;
728 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
736 return -1; /* error */
742 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
745 const struct gl_texture_unit
*texUnit
;
746 GET_CURRENT_CONTEXT(ctx
);
747 ASSERT_OUTSIDE_BEGIN_END(ctx
);
749 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
750 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
751 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
752 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
756 texUnit
= _mesa_get_current_tex_unit(ctx
);
758 if (target
== GL_TEXTURE_ENV
) {
759 if (pname
== GL_TEXTURE_ENV_COLOR
) {
760 COPY_4FV( params
, texUnit
->EnvColor
);
763 GLint val
= get_texenvi(ctx
, texUnit
, pname
);
765 *params
= (GLfloat
) val
;
769 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
770 /* GL_EXT_texture_lod_bias */
771 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
772 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
775 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
776 *params
= texUnit
->LodBias
;
779 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
783 else if (target
== GL_POINT_SPRITE_NV
) {
784 /* GL_ARB_point_sprite / GL_NV_point_sprite */
785 if (!ctx
->Extensions
.NV_point_sprite
786 && !ctx
->Extensions
.ARB_point_sprite
) {
787 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
790 if (pname
== GL_COORD_REPLACE_NV
) {
791 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
794 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
799 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
806 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
809 const struct gl_texture_unit
*texUnit
;
810 GET_CURRENT_CONTEXT(ctx
);
811 ASSERT_OUTSIDE_BEGIN_END(ctx
);
813 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
814 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
815 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
816 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
820 texUnit
= _mesa_get_current_tex_unit(ctx
);
822 if (target
== GL_TEXTURE_ENV
) {
823 if (pname
== GL_TEXTURE_ENV_COLOR
) {
824 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
825 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
826 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
827 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
830 GLint val
= get_texenvi(ctx
, texUnit
, pname
);
836 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
837 /* GL_EXT_texture_lod_bias */
838 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
839 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
842 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
843 *params
= (GLint
) texUnit
->LodBias
;
846 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
850 else if (target
== GL_POINT_SPRITE_NV
) {
851 /* GL_ARB_point_sprite / GL_NV_point_sprite */
852 if (!ctx
->Extensions
.NV_point_sprite
853 && !ctx
->Extensions
.ARB_point_sprite
) {
854 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
857 if (pname
== GL_COORD_REPLACE_NV
) {
858 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
861 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
866 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
873 * Why does ATI_envmap_bumpmap require new entrypoints? Should just
874 * reuse TexEnv ones...
877 _mesa_TexBumpParameterivATI( GLenum pname
, const GLint
*param
)
880 GET_CURRENT_CONTEXT(ctx
);
881 ASSERT_OUTSIDE_BEGIN_END(ctx
);
883 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
884 /* This isn't an "official" error case, but let's tell the user
885 * that something's wrong.
887 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBumpParameterivATI");
891 if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
892 /* hope that conversion is correct here */
893 p
[0] = INT_TO_FLOAT( param
[0] );
894 p
[1] = INT_TO_FLOAT( param
[1] );
895 p
[2] = INT_TO_FLOAT( param
[2] );
896 p
[3] = INT_TO_FLOAT( param
[3] );
899 p
[0] = (GLfloat
) param
[0];
900 p
[1] = p
[2] = p
[3] = 0.0F
; /* init to zero, just to be safe */
902 _mesa_TexBumpParameterfvATI( pname
, p
);
907 _mesa_TexBumpParameterfvATI( GLenum pname
, const GLfloat
*param
)
909 struct gl_texture_unit
*texUnit
;
910 GET_CURRENT_CONTEXT(ctx
);
911 ASSERT_OUTSIDE_BEGIN_END(ctx
);
913 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
914 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBumpParameterfvATI");
918 texUnit
= _mesa_get_current_tex_unit(ctx
);
920 if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
921 if (TEST_EQ_4V(param
, texUnit
->RotMatrix
))
923 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
924 COPY_4FV(texUnit
->RotMatrix
, param
);
927 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexBumpParameter(pname)" );
930 /* Drivers might want to know about this, instead of dedicated function
931 just shove it into TexEnv where it really belongs anyway */
932 if (ctx
->Driver
.TexEnv
) {
933 (*ctx
->Driver
.TexEnv
)( ctx
, 0, pname
, param
);
939 _mesa_GetTexBumpParameterivATI( GLenum pname
, GLint
*param
)
941 const struct gl_texture_unit
*texUnit
;
943 GET_CURRENT_CONTEXT(ctx
);
944 ASSERT_OUTSIDE_BEGIN_END(ctx
);
946 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
947 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexBumpParameterivATI");
951 texUnit
= _mesa_get_current_tex_unit(ctx
);
953 if (pname
== GL_BUMP_ROT_MATRIX_SIZE_ATI
) {
954 /* spec leaves open to support larger matrices.
955 Don't think anyone would ever want to use it
956 (and apps almost certainly would not understand it and
957 thus fail to submit matrices correctly) so hardcode this. */
960 else if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
961 /* hope that conversion is correct here */
962 param
[0] = FLOAT_TO_INT(texUnit
->RotMatrix
[0]);
963 param
[1] = FLOAT_TO_INT(texUnit
->RotMatrix
[1]);
964 param
[2] = FLOAT_TO_INT(texUnit
->RotMatrix
[2]);
965 param
[3] = FLOAT_TO_INT(texUnit
->RotMatrix
[3]);
967 else if (pname
== GL_BUMP_NUM_TEX_UNITS_ATI
) {
969 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
970 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
976 else if (pname
== GL_BUMP_TEX_UNITS_ATI
) {
977 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
978 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
979 *param
++ = i
+ GL_TEXTURE0
;
984 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexBumpParameter(pname)" );
991 _mesa_GetTexBumpParameterfvATI( GLenum pname
, GLfloat
*param
)
993 const struct gl_texture_unit
*texUnit
;
995 GET_CURRENT_CONTEXT(ctx
);
996 ASSERT_OUTSIDE_BEGIN_END(ctx
);
998 if (!ctx
->Extensions
.ATI_envmap_bumpmap
) {
999 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexBumpParameterfvATI");
1003 texUnit
= _mesa_get_current_tex_unit(ctx
);
1005 if (pname
== GL_BUMP_ROT_MATRIX_SIZE_ATI
) {
1006 /* spec leaves open to support larger matrices.
1007 Don't think anyone would ever want to use it
1008 (and apps might not understand it) so hardcode this. */
1011 else if (pname
== GL_BUMP_ROT_MATRIX_ATI
) {
1012 param
[0] = texUnit
->RotMatrix
[0];
1013 param
[1] = texUnit
->RotMatrix
[1];
1014 param
[2] = texUnit
->RotMatrix
[2];
1015 param
[3] = texUnit
->RotMatrix
[3];
1017 else if (pname
== GL_BUMP_NUM_TEX_UNITS_ATI
) {
1019 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1020 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
1024 *param
= (GLfloat
) count
;
1026 else if (pname
== GL_BUMP_TEX_UNITS_ATI
) {
1027 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1028 if (ctx
->Const
.SupportedBumpUnits
& (1 << i
)) {
1029 *param
++ = (GLfloat
) (i
+ GL_TEXTURE0
);
1034 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexBumpParameter(pname)" );