2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * glTexEnv-related functions
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/enums.h"
35 #include "main/macros.h"
36 #include "main/texenv.h"
37 #include "math/m_xform.h"
42 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
45 GET_CURRENT_CONTEXT(ctx
);
46 struct gl_texture_unit
*texUnit
;
47 ASSERT_OUTSIDE_BEGIN_END(ctx
);
49 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
50 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
51 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
52 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
56 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
58 #define TE_ERROR(errCode, msg, value) \
59 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
61 if (target
== GL_TEXTURE_ENV
) {
63 case GL_TEXTURE_ENV_MODE
:
65 GLenum mode
= (GLenum
) (GLint
) *param
;
66 if (mode
== GL_REPLACE_EXT
)
68 if (texUnit
->EnvMode
== mode
)
70 if (mode
== GL_MODULATE
||
74 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
75 (mode
== GL_COMBINE
&&
76 (ctx
->Extensions
.EXT_texture_env_combine
||
77 ctx
->Extensions
.ARB_texture_env_combine
))) {
79 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
80 texUnit
->EnvMode
= mode
;
83 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
88 case GL_TEXTURE_ENV_COLOR
:
91 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
92 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
93 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
94 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
95 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
97 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
98 COPY_4FV(texUnit
->EnvColor
, tmp
);
102 if (ctx
->Extensions
.EXT_texture_env_combine
||
103 ctx
->Extensions
.ARB_texture_env_combine
) {
104 const GLenum mode
= (GLenum
) (GLint
) *param
;
105 if (texUnit
->Combine
.ModeRGB
== mode
)
116 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
117 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
121 case GL_DOT3_RGB_EXT
:
122 case GL_DOT3_RGBA_EXT
:
123 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
124 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
130 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
131 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
135 case GL_MODULATE_ADD_ATI
:
136 case GL_MODULATE_SIGNED_ADD_ATI
:
137 case GL_MODULATE_SUBTRACT_ATI
:
138 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
139 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
144 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
147 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
148 texUnit
->Combine
.ModeRGB
= mode
;
151 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
155 case GL_COMBINE_ALPHA
:
156 if (ctx
->Extensions
.EXT_texture_env_combine
||
157 ctx
->Extensions
.ARB_texture_env_combine
) {
158 const GLenum mode
= (GLenum
) (GLint
) *param
;
159 if (texUnit
->Combine
.ModeA
== mode
)
170 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
171 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
175 case GL_MODULATE_ADD_ATI
:
176 case GL_MODULATE_SIGNED_ADD_ATI
:
177 case GL_MODULATE_SUBTRACT_ATI
:
178 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
179 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
184 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
187 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
188 texUnit
->Combine
.ModeA
= mode
;
191 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
198 if (ctx
->Extensions
.EXT_texture_env_combine
||
199 ctx
->Extensions
.ARB_texture_env_combine
) {
200 const GLenum source
= (GLenum
) (GLint
) *param
;
201 const GLuint s
= pname
- GL_SOURCE0_RGB
;
202 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
204 if (source
== GL_TEXTURE
||
205 source
== GL_CONSTANT
||
206 source
== GL_PRIMARY_COLOR
||
207 source
== GL_PREVIOUS
||
208 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
209 source
>= GL_TEXTURE0
&&
210 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
211 (ctx
->Extensions
.ATI_texture_env_combine3
&&
212 (source
== GL_ZERO
|| source
== GL_ONE
))) {
214 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
215 texUnit
->Combine
.SourceRGB
[s
] = source
;
218 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
223 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
227 case GL_SOURCE0_ALPHA
:
228 case GL_SOURCE1_ALPHA
:
229 case GL_SOURCE2_ALPHA
:
230 if (ctx
->Extensions
.EXT_texture_env_combine
||
231 ctx
->Extensions
.ARB_texture_env_combine
) {
232 const GLenum source
= (GLenum
) (GLint
) *param
;
233 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
234 if (texUnit
->Combine
.SourceA
[s
] == source
)
236 if (source
== GL_TEXTURE
||
237 source
== GL_CONSTANT
||
238 source
== GL_PRIMARY_COLOR
||
239 source
== GL_PREVIOUS
||
240 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
241 source
>= GL_TEXTURE0
&&
242 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
243 (ctx
->Extensions
.ATI_texture_env_combine3
&&
244 (source
== GL_ZERO
|| source
== GL_ONE
))) {
246 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
247 texUnit
->Combine
.SourceA
[s
] = source
;
250 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
255 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
259 case GL_OPERAND0_RGB
:
260 case GL_OPERAND1_RGB
:
261 if (ctx
->Extensions
.EXT_texture_env_combine
||
262 ctx
->Extensions
.ARB_texture_env_combine
) {
263 const GLenum operand
= (GLenum
) (GLint
) *param
;
264 const GLuint s
= pname
- GL_OPERAND0_RGB
;
265 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
269 case GL_ONE_MINUS_SRC_COLOR
:
271 case GL_ONE_MINUS_SRC_ALPHA
:
272 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
273 texUnit
->Combine
.OperandRGB
[s
] = operand
;
276 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
281 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
285 case GL_OPERAND0_ALPHA
:
286 case GL_OPERAND1_ALPHA
:
287 if (ctx
->Extensions
.EXT_texture_env_combine
||
288 ctx
->Extensions
.ARB_texture_env_combine
) {
289 const GLenum operand
= (GLenum
) (GLint
) *param
;
290 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
294 case GL_ONE_MINUS_SRC_ALPHA
:
295 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
296 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
299 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
304 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
308 case GL_OPERAND2_RGB
:
309 if (ctx
->Extensions
.ARB_texture_env_combine
) {
310 const GLenum operand
= (GLenum
) (GLint
) *param
;
311 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
314 case GL_SRC_COLOR
: /* ARB combine only */
315 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
317 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
318 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
319 texUnit
->Combine
.OperandRGB
[2] = operand
;
322 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
326 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
327 const GLenum operand
= (GLenum
) (GLint
) *param
;
328 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
330 /* operand must be GL_SRC_ALPHA which is the initial value - thus
331 don't need to actually compare the operand to the possible value */
333 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
338 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
342 case GL_OPERAND2_ALPHA
:
343 if (ctx
->Extensions
.ARB_texture_env_combine
) {
344 const GLenum operand
= (GLenum
) (GLint
) *param
;
345 if (texUnit
->Combine
.OperandA
[2] == operand
)
349 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
350 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
351 texUnit
->Combine
.OperandA
[2] = operand
;
354 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
358 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
359 const GLenum operand
= (GLenum
) (GLint
) *param
;
360 if (texUnit
->Combine
.OperandA
[2] == operand
)
362 /* operand must be GL_SRC_ALPHA which is the initial value - thus
363 don't need to actually compare the operand to the possible value */
365 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
370 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
375 if (ctx
->Extensions
.EXT_texture_env_combine
||
376 ctx
->Extensions
.ARB_texture_env_combine
) {
381 else if (*param
== 2.0) {
384 else if (*param
== 4.0) {
388 _mesa_error( ctx
, GL_INVALID_VALUE
,
389 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
392 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
394 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
395 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
398 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
403 if (ctx
->Extensions
.EXT_texture_env_combine
||
404 ctx
->Extensions
.ARB_texture_env_combine
) {
409 else if (*param
== 2.0) {
412 else if (*param
== 4.0) {
416 _mesa_error( ctx
, GL_INVALID_VALUE
,
417 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
420 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
422 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
423 texUnit
->Combine
.ScaleShiftA
= newshift
;
426 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
431 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
435 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
436 /* GL_EXT_texture_lod_bias */
437 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
438 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
441 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
442 if (texUnit
->LodBias
== param
[0])
444 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
445 texUnit
->LodBias
= param
[0];
448 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
452 else if (target
== GL_POINT_SPRITE_NV
) {
453 /* GL_ARB_point_sprite / GL_NV_point_sprite */
454 if (!ctx
->Extensions
.NV_point_sprite
455 && !ctx
->Extensions
.ARB_point_sprite
) {
456 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
459 if (pname
== GL_COORD_REPLACE_NV
) {
460 const GLenum value
= (GLenum
) param
[0];
461 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
462 /* It's kind of weird to set point state via glTexEnv,
463 * but that's what the spec calls for.
465 const GLboolean state
= (GLboolean
) value
;
466 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
468 FLUSH_VERTICES(ctx
, _NEW_POINT
);
469 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
472 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
477 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
482 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
486 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
487 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
488 _mesa_lookup_enum_by_nr(target
),
489 _mesa_lookup_enum_by_nr(pname
),
491 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
493 /* Tell device driver about the new texture environment */
494 if (ctx
->Driver
.TexEnv
) {
495 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
501 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
503 _mesa_TexEnvfv( target
, pname
, ¶m
);
509 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
512 p
[0] = (GLfloat
) param
;
513 p
[1] = p
[2] = p
[3] = 0.0;
514 _mesa_TexEnvfv( target
, pname
, p
);
519 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
522 if (pname
== GL_TEXTURE_ENV_COLOR
) {
523 p
[0] = INT_TO_FLOAT( param
[0] );
524 p
[1] = INT_TO_FLOAT( param
[1] );
525 p
[2] = INT_TO_FLOAT( param
[2] );
526 p
[3] = INT_TO_FLOAT( param
[3] );
529 p
[0] = (GLfloat
) param
[0];
530 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
532 _mesa_TexEnvfv( target
, pname
, p
);
537 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
540 const struct gl_texture_unit
*texUnit
;
541 GET_CURRENT_CONTEXT(ctx
);
542 ASSERT_OUTSIDE_BEGIN_END(ctx
);
544 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
545 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
546 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
547 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
551 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
553 if (target
== GL_TEXTURE_ENV
) {
555 case GL_TEXTURE_ENV_MODE
:
556 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
558 case GL_TEXTURE_ENV_COLOR
:
559 COPY_4FV( params
, texUnit
->EnvColor
);
562 if (ctx
->Extensions
.EXT_texture_env_combine
||
563 ctx
->Extensions
.ARB_texture_env_combine
) {
564 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
567 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
570 case GL_COMBINE_ALPHA
:
571 if (ctx
->Extensions
.EXT_texture_env_combine
||
572 ctx
->Extensions
.ARB_texture_env_combine
) {
573 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
576 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
582 if (ctx
->Extensions
.EXT_texture_env_combine
||
583 ctx
->Extensions
.ARB_texture_env_combine
) {
584 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
585 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
588 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
591 case GL_SOURCE0_ALPHA
:
592 case GL_SOURCE1_ALPHA
:
593 case GL_SOURCE2_ALPHA
:
594 if (ctx
->Extensions
.EXT_texture_env_combine
||
595 ctx
->Extensions
.ARB_texture_env_combine
) {
596 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
597 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[alpha_idx
];
600 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
603 case GL_OPERAND0_RGB
:
604 case GL_OPERAND1_RGB
:
605 case GL_OPERAND2_RGB
:
606 if (ctx
->Extensions
.EXT_texture_env_combine
||
607 ctx
->Extensions
.ARB_texture_env_combine
) {
608 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
609 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[op_rgb
];
612 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
615 case GL_OPERAND0_ALPHA
:
616 case GL_OPERAND1_ALPHA
:
617 case GL_OPERAND2_ALPHA
:
618 if (ctx
->Extensions
.EXT_texture_env_combine
||
619 ctx
->Extensions
.ARB_texture_env_combine
) {
620 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
621 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[op_alpha
];
624 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
628 if (ctx
->Extensions
.EXT_texture_env_combine
||
629 ctx
->Extensions
.ARB_texture_env_combine
) {
630 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
632 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
638 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
643 if (ctx
->Extensions
.EXT_texture_env_combine
||
644 ctx
->Extensions
.ARB_texture_env_combine
) {
645 if (texUnit
->Combine
.ScaleShiftA
== 0)
647 else if (texUnit
->Combine
.ScaleShiftA
== 1)
653 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
658 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
661 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
662 /* GL_EXT_texture_lod_bias */
663 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
664 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
667 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
668 *params
= texUnit
->LodBias
;
671 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
675 else if (target
== GL_POINT_SPRITE_NV
) {
676 /* GL_ARB_point_sprite / GL_NV_point_sprite */
677 if (!ctx
->Extensions
.NV_point_sprite
678 && !ctx
->Extensions
.ARB_point_sprite
) {
679 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
682 if (pname
== GL_COORD_REPLACE_NV
) {
683 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
686 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
691 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
698 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
701 const struct gl_texture_unit
*texUnit
;
702 GET_CURRENT_CONTEXT(ctx
);
703 ASSERT_OUTSIDE_BEGIN_END(ctx
);
705 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
706 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
707 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
708 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
712 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
714 if (target
== GL_TEXTURE_ENV
) {
716 case GL_TEXTURE_ENV_MODE
:
717 *params
= (GLint
) texUnit
->EnvMode
;
719 case GL_TEXTURE_ENV_COLOR
:
720 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
721 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
722 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
723 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
726 if (ctx
->Extensions
.EXT_texture_env_combine
||
727 ctx
->Extensions
.ARB_texture_env_combine
) {
728 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
731 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
734 case GL_COMBINE_ALPHA
:
735 if (ctx
->Extensions
.EXT_texture_env_combine
||
736 ctx
->Extensions
.ARB_texture_env_combine
) {
737 *params
= (GLint
) texUnit
->Combine
.ModeA
;
740 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
746 if (ctx
->Extensions
.EXT_texture_env_combine
||
747 ctx
->Extensions
.ARB_texture_env_combine
) {
748 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
749 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
752 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
755 case GL_SOURCE0_ALPHA
:
756 case GL_SOURCE1_ALPHA
:
757 case GL_SOURCE2_ALPHA
:
758 if (ctx
->Extensions
.EXT_texture_env_combine
||
759 ctx
->Extensions
.ARB_texture_env_combine
) {
760 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
761 *params
= (GLint
) texUnit
->Combine
.SourceA
[alpha_idx
];
764 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
767 case GL_OPERAND0_RGB
:
768 case GL_OPERAND1_RGB
:
769 case GL_OPERAND2_RGB
:
770 if (ctx
->Extensions
.EXT_texture_env_combine
||
771 ctx
->Extensions
.ARB_texture_env_combine
) {
772 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
773 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[op_rgb
];
776 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
779 case GL_OPERAND0_ALPHA
:
780 case GL_OPERAND1_ALPHA
:
781 case GL_OPERAND2_ALPHA
:
782 if (ctx
->Extensions
.EXT_texture_env_combine
||
783 ctx
->Extensions
.ARB_texture_env_combine
) {
784 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
785 *params
= (GLint
) texUnit
->Combine
.OperandA
[op_alpha
];
788 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
792 if (ctx
->Extensions
.EXT_texture_env_combine
||
793 ctx
->Extensions
.ARB_texture_env_combine
) {
794 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
796 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
807 if (ctx
->Extensions
.EXT_texture_env_combine
||
808 ctx
->Extensions
.ARB_texture_env_combine
) {
809 if (texUnit
->Combine
.ScaleShiftA
== 0)
811 else if (texUnit
->Combine
.ScaleShiftA
== 1)
817 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
822 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
826 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
827 /* GL_EXT_texture_lod_bias */
828 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
829 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
832 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
833 *params
= (GLint
) texUnit
->LodBias
;
836 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
840 else if (target
== GL_POINT_SPRITE_NV
) {
841 /* GL_ARB_point_sprite / GL_NV_point_sprite */
842 if (!ctx
->Extensions
.NV_point_sprite
843 && !ctx
->Extensions
.ARB_point_sprite
) {
844 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
847 if (pname
== GL_COORD_REPLACE_NV
) {
848 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
851 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
856 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );