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"
40 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
44 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
47 GET_CURRENT_CONTEXT(ctx
);
48 struct gl_texture_unit
*texUnit
;
49 ASSERT_OUTSIDE_BEGIN_END(ctx
);
51 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
52 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
53 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
54 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
58 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
60 #define TE_ERROR(errCode, msg, value) \
61 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
63 if (target
== GL_TEXTURE_ENV
) {
65 case GL_TEXTURE_ENV_MODE
:
67 GLenum mode
= (GLenum
) (GLint
) *param
;
68 if (mode
== GL_REPLACE_EXT
)
70 if (texUnit
->EnvMode
== mode
)
72 if (mode
== GL_MODULATE
||
76 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
77 (mode
== GL_COMBINE
&&
78 (ctx
->Extensions
.EXT_texture_env_combine
||
79 ctx
->Extensions
.ARB_texture_env_combine
))) {
81 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
82 texUnit
->EnvMode
= mode
;
85 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
90 case GL_TEXTURE_ENV_COLOR
:
93 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
94 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
95 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
96 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
97 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
99 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
100 COPY_4FV(texUnit
->EnvColor
, tmp
);
104 if (ctx
->Extensions
.EXT_texture_env_combine
||
105 ctx
->Extensions
.ARB_texture_env_combine
) {
106 const GLenum mode
= (GLenum
) (GLint
) *param
;
107 if (texUnit
->Combine
.ModeRGB
== mode
)
118 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
119 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
123 case GL_DOT3_RGB_EXT
:
124 case GL_DOT3_RGBA_EXT
:
125 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
126 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
132 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
133 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
137 case GL_MODULATE_ADD_ATI
:
138 case GL_MODULATE_SIGNED_ADD_ATI
:
139 case GL_MODULATE_SUBTRACT_ATI
:
140 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
141 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
146 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
149 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
150 texUnit
->Combine
.ModeRGB
= mode
;
153 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
157 case GL_COMBINE_ALPHA
:
158 if (ctx
->Extensions
.EXT_texture_env_combine
||
159 ctx
->Extensions
.ARB_texture_env_combine
) {
160 const GLenum mode
= (GLenum
) (GLint
) *param
;
161 if (texUnit
->Combine
.ModeA
== mode
)
172 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
173 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
177 case GL_MODULATE_ADD_ATI
:
178 case GL_MODULATE_SIGNED_ADD_ATI
:
179 case GL_MODULATE_SUBTRACT_ATI
:
180 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
181 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
186 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
189 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
190 texUnit
->Combine
.ModeA
= mode
;
193 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
200 if (ctx
->Extensions
.EXT_texture_env_combine
||
201 ctx
->Extensions
.ARB_texture_env_combine
) {
202 const GLenum source
= (GLenum
) (GLint
) *param
;
203 const GLuint s
= pname
- GL_SOURCE0_RGB
;
204 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
206 if (source
== GL_TEXTURE
||
207 source
== GL_CONSTANT
||
208 source
== GL_PRIMARY_COLOR
||
209 source
== GL_PREVIOUS
||
210 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
211 source
>= GL_TEXTURE0
&&
212 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
213 (ctx
->Extensions
.ATI_texture_env_combine3
&&
214 (source
== GL_ZERO
|| source
== GL_ONE
))) {
216 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
217 texUnit
->Combine
.SourceRGB
[s
] = source
;
220 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
225 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
229 case GL_SOURCE0_ALPHA
:
230 case GL_SOURCE1_ALPHA
:
231 case GL_SOURCE2_ALPHA
:
232 if (ctx
->Extensions
.EXT_texture_env_combine
||
233 ctx
->Extensions
.ARB_texture_env_combine
) {
234 const GLenum source
= (GLenum
) (GLint
) *param
;
235 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
236 if (texUnit
->Combine
.SourceA
[s
] == source
)
238 if (source
== GL_TEXTURE
||
239 source
== GL_CONSTANT
||
240 source
== GL_PRIMARY_COLOR
||
241 source
== GL_PREVIOUS
||
242 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
243 source
>= GL_TEXTURE0
&&
244 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
245 (ctx
->Extensions
.ATI_texture_env_combine3
&&
246 (source
== GL_ZERO
|| source
== GL_ONE
))) {
248 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
249 texUnit
->Combine
.SourceA
[s
] = source
;
252 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
257 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
261 case GL_OPERAND0_RGB
:
262 case GL_OPERAND1_RGB
:
263 if (ctx
->Extensions
.EXT_texture_env_combine
||
264 ctx
->Extensions
.ARB_texture_env_combine
) {
265 const GLenum operand
= (GLenum
) (GLint
) *param
;
266 const GLuint s
= pname
- GL_OPERAND0_RGB
;
267 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
271 case GL_ONE_MINUS_SRC_COLOR
:
273 case GL_ONE_MINUS_SRC_ALPHA
:
274 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
275 texUnit
->Combine
.OperandRGB
[s
] = operand
;
278 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
283 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
287 case GL_OPERAND0_ALPHA
:
288 case GL_OPERAND1_ALPHA
:
289 if (ctx
->Extensions
.EXT_texture_env_combine
||
290 ctx
->Extensions
.ARB_texture_env_combine
) {
291 const GLenum operand
= (GLenum
) (GLint
) *param
;
292 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
296 case GL_ONE_MINUS_SRC_ALPHA
:
297 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
298 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
301 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
306 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
310 case GL_OPERAND2_RGB
:
311 if (ctx
->Extensions
.ARB_texture_env_combine
) {
312 const GLenum operand
= (GLenum
) (GLint
) *param
;
313 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
316 case GL_SRC_COLOR
: /* ARB combine only */
317 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
319 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
320 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
321 texUnit
->Combine
.OperandRGB
[2] = operand
;
324 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
328 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
329 const GLenum operand
= (GLenum
) (GLint
) *param
;
330 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
332 /* operand must be GL_SRC_ALPHA which is the initial value - thus
333 don't need to actually compare the operand to the possible value */
335 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
340 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
344 case GL_OPERAND2_ALPHA
:
345 if (ctx
->Extensions
.ARB_texture_env_combine
) {
346 const GLenum operand
= (GLenum
) (GLint
) *param
;
347 if (texUnit
->Combine
.OperandA
[2] == operand
)
351 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
352 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
353 texUnit
->Combine
.OperandA
[2] = operand
;
356 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
360 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
361 const GLenum operand
= (GLenum
) (GLint
) *param
;
362 if (texUnit
->Combine
.OperandA
[2] == operand
)
364 /* operand must be GL_SRC_ALPHA which is the initial value - thus
365 don't need to actually compare the operand to the possible value */
367 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
372 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
377 if (ctx
->Extensions
.EXT_texture_env_combine
||
378 ctx
->Extensions
.ARB_texture_env_combine
) {
383 else if (*param
== 2.0) {
386 else if (*param
== 4.0) {
390 _mesa_error( ctx
, GL_INVALID_VALUE
,
391 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
394 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
396 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
397 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
400 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
405 if (ctx
->Extensions
.EXT_texture_env_combine
||
406 ctx
->Extensions
.ARB_texture_env_combine
) {
411 else if (*param
== 2.0) {
414 else if (*param
== 4.0) {
418 _mesa_error( ctx
, GL_INVALID_VALUE
,
419 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
422 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
424 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
425 texUnit
->Combine
.ScaleShiftA
= newshift
;
428 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
433 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
437 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
438 /* GL_EXT_texture_lod_bias */
439 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
440 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
443 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
444 if (texUnit
->LodBias
== param
[0])
446 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
447 texUnit
->LodBias
= param
[0];
450 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
454 else if (target
== GL_POINT_SPRITE_NV
) {
455 /* GL_ARB_point_sprite / GL_NV_point_sprite */
456 if (!ctx
->Extensions
.NV_point_sprite
457 && !ctx
->Extensions
.ARB_point_sprite
) {
458 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
461 if (pname
== GL_COORD_REPLACE_NV
) {
462 const GLenum value
= (GLenum
) param
[0];
463 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
464 /* It's kind of weird to set point state via glTexEnv,
465 * but that's what the spec calls for.
467 const GLboolean state
= (GLboolean
) value
;
468 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
470 FLUSH_VERTICES(ctx
, _NEW_POINT
);
471 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
474 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
479 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
484 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
488 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
489 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
490 _mesa_lookup_enum_by_nr(target
),
491 _mesa_lookup_enum_by_nr(pname
),
493 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
495 /* Tell device driver about the new texture environment */
496 if (ctx
->Driver
.TexEnv
) {
497 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
503 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
505 _mesa_TexEnvfv( target
, pname
, ¶m
);
511 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
514 p
[0] = (GLfloat
) param
;
515 p
[1] = p
[2] = p
[3] = 0.0;
516 _mesa_TexEnvfv( target
, pname
, p
);
521 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
524 if (pname
== GL_TEXTURE_ENV_COLOR
) {
525 p
[0] = INT_TO_FLOAT( param
[0] );
526 p
[1] = INT_TO_FLOAT( param
[1] );
527 p
[2] = INT_TO_FLOAT( param
[2] );
528 p
[3] = INT_TO_FLOAT( param
[3] );
531 p
[0] = (GLfloat
) param
[0];
532 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
534 _mesa_TexEnvfv( target
, pname
, p
);
539 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
542 const struct gl_texture_unit
*texUnit
;
543 GET_CURRENT_CONTEXT(ctx
);
544 ASSERT_OUTSIDE_BEGIN_END(ctx
);
546 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
547 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
548 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
549 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
553 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
555 if (target
== GL_TEXTURE_ENV
) {
557 case GL_TEXTURE_ENV_MODE
:
558 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
560 case GL_TEXTURE_ENV_COLOR
:
561 COPY_4FV( params
, texUnit
->EnvColor
);
564 if (ctx
->Extensions
.EXT_texture_env_combine
||
565 ctx
->Extensions
.ARB_texture_env_combine
) {
566 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
569 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
572 case GL_COMBINE_ALPHA
:
573 if (ctx
->Extensions
.EXT_texture_env_combine
||
574 ctx
->Extensions
.ARB_texture_env_combine
) {
575 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
584 if (ctx
->Extensions
.EXT_texture_env_combine
||
585 ctx
->Extensions
.ARB_texture_env_combine
) {
586 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
587 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
590 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
593 case GL_SOURCE0_ALPHA
:
594 case GL_SOURCE1_ALPHA
:
595 case GL_SOURCE2_ALPHA
:
596 if (ctx
->Extensions
.EXT_texture_env_combine
||
597 ctx
->Extensions
.ARB_texture_env_combine
) {
598 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
599 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[alpha_idx
];
602 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
605 case GL_OPERAND0_RGB
:
606 case GL_OPERAND1_RGB
:
607 case GL_OPERAND2_RGB
:
608 if (ctx
->Extensions
.EXT_texture_env_combine
||
609 ctx
->Extensions
.ARB_texture_env_combine
) {
610 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
611 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[op_rgb
];
614 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
617 case GL_OPERAND0_ALPHA
:
618 case GL_OPERAND1_ALPHA
:
619 case GL_OPERAND2_ALPHA
:
620 if (ctx
->Extensions
.EXT_texture_env_combine
||
621 ctx
->Extensions
.ARB_texture_env_combine
) {
622 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
623 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[op_alpha
];
626 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
630 if (ctx
->Extensions
.EXT_texture_env_combine
||
631 ctx
->Extensions
.ARB_texture_env_combine
) {
632 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
634 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
640 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
645 if (ctx
->Extensions
.EXT_texture_env_combine
||
646 ctx
->Extensions
.ARB_texture_env_combine
) {
647 if (texUnit
->Combine
.ScaleShiftA
== 0)
649 else if (texUnit
->Combine
.ScaleShiftA
== 1)
655 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
660 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
663 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
664 /* GL_EXT_texture_lod_bias */
665 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
666 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
669 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
670 *params
= texUnit
->LodBias
;
673 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
677 else if (target
== GL_POINT_SPRITE_NV
) {
678 /* GL_ARB_point_sprite / GL_NV_point_sprite */
679 if (!ctx
->Extensions
.NV_point_sprite
680 && !ctx
->Extensions
.ARB_point_sprite
) {
681 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
684 if (pname
== GL_COORD_REPLACE_NV
) {
685 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
688 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
693 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
700 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
703 const struct gl_texture_unit
*texUnit
;
704 GET_CURRENT_CONTEXT(ctx
);
705 ASSERT_OUTSIDE_BEGIN_END(ctx
);
707 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
708 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
709 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
710 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
714 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
716 if (target
== GL_TEXTURE_ENV
) {
718 case GL_TEXTURE_ENV_MODE
:
719 *params
= (GLint
) texUnit
->EnvMode
;
721 case GL_TEXTURE_ENV_COLOR
:
722 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
723 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
724 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
725 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
728 if (ctx
->Extensions
.EXT_texture_env_combine
||
729 ctx
->Extensions
.ARB_texture_env_combine
) {
730 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
733 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
736 case GL_COMBINE_ALPHA
:
737 if (ctx
->Extensions
.EXT_texture_env_combine
||
738 ctx
->Extensions
.ARB_texture_env_combine
) {
739 *params
= (GLint
) texUnit
->Combine
.ModeA
;
742 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
748 if (ctx
->Extensions
.EXT_texture_env_combine
||
749 ctx
->Extensions
.ARB_texture_env_combine
) {
750 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
751 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
754 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
757 case GL_SOURCE0_ALPHA
:
758 case GL_SOURCE1_ALPHA
:
759 case GL_SOURCE2_ALPHA
:
760 if (ctx
->Extensions
.EXT_texture_env_combine
||
761 ctx
->Extensions
.ARB_texture_env_combine
) {
762 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
763 *params
= (GLint
) texUnit
->Combine
.SourceA
[alpha_idx
];
766 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
769 case GL_OPERAND0_RGB
:
770 case GL_OPERAND1_RGB
:
771 case GL_OPERAND2_RGB
:
772 if (ctx
->Extensions
.EXT_texture_env_combine
||
773 ctx
->Extensions
.ARB_texture_env_combine
) {
774 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
775 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[op_rgb
];
778 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
781 case GL_OPERAND0_ALPHA
:
782 case GL_OPERAND1_ALPHA
:
783 case GL_OPERAND2_ALPHA
:
784 if (ctx
->Extensions
.EXT_texture_env_combine
||
785 ctx
->Extensions
.ARB_texture_env_combine
) {
786 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
787 *params
= (GLint
) texUnit
->Combine
.OperandA
[op_alpha
];
790 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
794 if (ctx
->Extensions
.EXT_texture_env_combine
||
795 ctx
->Extensions
.ARB_texture_env_combine
) {
796 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
798 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
804 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
809 if (ctx
->Extensions
.EXT_texture_env_combine
||
810 ctx
->Extensions
.ARB_texture_env_combine
) {
811 if (texUnit
->Combine
.ScaleShiftA
== 0)
813 else if (texUnit
->Combine
.ScaleShiftA
== 1)
819 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
824 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
828 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
829 /* GL_EXT_texture_lod_bias */
830 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
831 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
834 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
835 *params
= (GLint
) texUnit
->LodBias
;
838 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
842 else if (target
== GL_POINT_SPRITE_NV
) {
843 /* GL_ARB_point_sprite / GL_NV_point_sprite */
844 if (!ctx
->Extensions
.NV_point_sprite
845 && !ctx
->Extensions
.ARB_point_sprite
) {
846 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
849 if (pname
== GL_COORD_REPLACE_NV
) {
850 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
853 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
858 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );