2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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 * Texture state handling.
36 #include "extensions.h"
38 #include "nvfragprog.h"
43 #include "math/m_xform.h"
44 #include "math/m_matrix.h"
49 /* Needed for an Amiga compiler */
50 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
51 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
53 /* all other compilers */
54 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
55 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
59 * Default texture combine environment state. This is used to initialize
60 * a context's texture units and as the basis for converting "classic"
61 * texture environmnets to ARB_texture_env_combine style values.
63 static const struct gl_tex_env_combine_state default_combine_state
= {
64 GL_MODULATE
, GL_MODULATE
,
65 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
66 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
67 { GL_SRC_COLOR
, GL_SRC_COLOR
, GL_SRC_ALPHA
},
68 { GL_SRC_ALPHA
, GL_SRC_ALPHA
, GL_SRC_ALPHA
},
75 _mesa_copy_texture_state( const GLcontext
*src
, GLcontext
*dst
)
82 dst
->Texture
.CurrentUnit
= src
->Texture
.CurrentUnit
;
83 dst
->Texture
._GenFlags
= src
->Texture
._GenFlags
;
84 dst
->Texture
._TexGenEnabled
= src
->Texture
._TexGenEnabled
;
85 dst
->Texture
._TexMatEnabled
= src
->Texture
._TexMatEnabled
;
86 dst
->Texture
.SharedPalette
= src
->Texture
.SharedPalette
;
89 for (i
= 0; i
< src
->Const
.MaxTextureUnits
; i
++) {
90 dst
->Texture
.Unit
[i
].Enabled
= src
->Texture
.Unit
[i
].Enabled
;
91 dst
->Texture
.Unit
[i
].EnvMode
= src
->Texture
.Unit
[i
].EnvMode
;
92 COPY_4V(dst
->Texture
.Unit
[i
].EnvColor
, src
->Texture
.Unit
[i
].EnvColor
);
93 dst
->Texture
.Unit
[i
].TexGenEnabled
= src
->Texture
.Unit
[i
].TexGenEnabled
;
94 dst
->Texture
.Unit
[i
].GenModeS
= src
->Texture
.Unit
[i
].GenModeS
;
95 dst
->Texture
.Unit
[i
].GenModeT
= src
->Texture
.Unit
[i
].GenModeT
;
96 dst
->Texture
.Unit
[i
].GenModeR
= src
->Texture
.Unit
[i
].GenModeR
;
97 dst
->Texture
.Unit
[i
].GenModeQ
= src
->Texture
.Unit
[i
].GenModeQ
;
98 dst
->Texture
.Unit
[i
]._GenBitS
= src
->Texture
.Unit
[i
]._GenBitS
;
99 dst
->Texture
.Unit
[i
]._GenBitT
= src
->Texture
.Unit
[i
]._GenBitT
;
100 dst
->Texture
.Unit
[i
]._GenBitR
= src
->Texture
.Unit
[i
]._GenBitR
;
101 dst
->Texture
.Unit
[i
]._GenBitQ
= src
->Texture
.Unit
[i
]._GenBitQ
;
102 dst
->Texture
.Unit
[i
]._GenFlags
= src
->Texture
.Unit
[i
]._GenFlags
;
103 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneS
, src
->Texture
.Unit
[i
].ObjectPlaneS
);
104 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneT
, src
->Texture
.Unit
[i
].ObjectPlaneT
);
105 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneR
, src
->Texture
.Unit
[i
].ObjectPlaneR
);
106 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneQ
, src
->Texture
.Unit
[i
].ObjectPlaneQ
);
107 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneS
, src
->Texture
.Unit
[i
].EyePlaneS
);
108 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneT
, src
->Texture
.Unit
[i
].EyePlaneT
);
109 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneR
, src
->Texture
.Unit
[i
].EyePlaneR
);
110 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneQ
, src
->Texture
.Unit
[i
].EyePlaneQ
);
111 dst
->Texture
.Unit
[i
].LodBias
= src
->Texture
.Unit
[i
].LodBias
;
113 /* GL_EXT_texture_env_combine */
114 dst
->Texture
.Unit
[i
].Combine
.ModeRGB
= src
->Texture
.Unit
[i
].Combine
.ModeRGB
;
115 dst
->Texture
.Unit
[i
].Combine
.ModeA
= src
->Texture
.Unit
[i
].Combine
.ModeA
;
116 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceRGB
, src
->Texture
.Unit
[i
].Combine
.SourceRGB
);
117 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceA
, src
->Texture
.Unit
[i
].Combine
.SourceA
);
118 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandRGB
, src
->Texture
.Unit
[i
].Combine
.OperandRGB
);
119 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandA
, src
->Texture
.Unit
[i
].Combine
.OperandA
);
120 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
;
121 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftA
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftA
;
123 /* texture object state */
124 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].Current1D
,
125 src
->Texture
.Unit
[i
].Current1D
);
126 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].Current2D
,
127 src
->Texture
.Unit
[i
].Current2D
);
128 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].Current3D
,
129 src
->Texture
.Unit
[i
].Current3D
);
130 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].CurrentCubeMap
,
131 src
->Texture
.Unit
[i
].CurrentCubeMap
);
132 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].CurrentRect
,
133 src
->Texture
.Unit
[i
].CurrentRect
);
142 _mesa_print_texunit_state( GLcontext
*ctx
, GLuint unit
)
144 const struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
+ unit
;
145 _mesa_printf("Texture Unit %d\n", unit
);
146 _mesa_printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit
->EnvMode
));
147 _mesa_printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeRGB
));
148 _mesa_printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeA
));
149 _mesa_printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[0]));
150 _mesa_printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[1]));
151 _mesa_printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[2]));
152 _mesa_printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[0]));
153 _mesa_printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[1]));
154 _mesa_printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[2]));
155 _mesa_printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[0]));
156 _mesa_printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[1]));
157 _mesa_printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[2]));
158 _mesa_printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[0]));
159 _mesa_printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[1]));
160 _mesa_printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[2]));
161 _mesa_printf(" GL_RGB_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftRGB
);
162 _mesa_printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftA
);
163 _mesa_printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit
->EnvColor
[0], texUnit
->EnvColor
[1], texUnit
->EnvColor
[2], texUnit
->EnvColor
[3]);
168 /**********************************************************************/
169 /* Texture Environment */
170 /**********************************************************************/
173 * Convert "classic" texture environment to ARB_texture_env_combine style
176 * \param state texture_env_combine state vector to be filled-in.
177 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
178 * \c GL_BLEND, \c GL_DECAL, etc.).
179 * \param texBaseFormat Base format of the texture associated with the
183 calculate_derived_texenv( struct gl_tex_env_combine_state
*state
,
184 GLenum mode
, GLenum texBaseFormat
)
189 *state
= default_combine_state
;
191 switch (texBaseFormat
) {
193 state
->SourceRGB
[0] = GL_PREVIOUS
;
196 case GL_LUMINANCE_ALPHA
:
204 state
->SourceA
[0] = GL_PREVIOUS
;
208 _mesa_problem(NULL
, "Invalid texBaseFormat in calculate_derived_texenv");
215 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: mode
;
220 mode_rgb
= GL_INTERPOLATE
;
223 state
->SourceA
[0] = GL_PREVIOUS
;
225 /* Having alpha / luminance / intensity textures replace using the
226 * incoming fragment color matches the definition in NV_texture_shader.
227 * The 1.5 spec simply marks these as "undefined".
229 switch (texBaseFormat
) {
232 case GL_LUMINANCE_ALPHA
:
234 state
->SourceRGB
[0] = GL_PREVIOUS
;
238 mode_rgb
= GL_REPLACE
;
241 state
->SourceRGB
[2] = GL_TEXTURE
;
247 mode_rgb
= GL_INTERPOLATE
;
248 mode_a
= GL_MODULATE
;
250 switch (texBaseFormat
) {
252 mode_rgb
= GL_REPLACE
;
255 mode_a
= GL_INTERPOLATE
;
256 state
->SourceA
[0] = GL_CONSTANT
;
257 state
->OperandA
[2] = GL_SRC_ALPHA
;
261 case GL_LUMINANCE_ALPHA
:
264 state
->SourceRGB
[2] = GL_TEXTURE
;
265 state
->SourceA
[2] = GL_TEXTURE
;
266 state
->SourceRGB
[0] = GL_CONSTANT
;
267 state
->OperandRGB
[2] = GL_SRC_COLOR
;
273 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
274 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
279 "Invalid texture env mode in calculate_derived_texenv");
283 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
284 ? mode_rgb
: GL_REPLACE
;
285 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
286 ? mode_a
: GL_REPLACE
;
291 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
293 GET_CURRENT_CONTEXT(ctx
);
294 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
295 ASSERT_OUTSIDE_BEGIN_END(ctx
);
297 #define TE_ERROR(errCode, msg, value) \
298 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
300 if (target
== GL_TEXTURE_ENV
) {
302 case GL_TEXTURE_ENV_MODE
:
304 const GLenum mode
= (GLenum
) (GLint
) *param
;
305 if (texUnit
->EnvMode
== mode
)
307 if (mode
== GL_MODULATE
||
310 mode
== GL_REPLACE
||
311 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
312 (mode
== GL_COMBINE
&&
313 (ctx
->Extensions
.EXT_texture_env_combine
||
314 ctx
->Extensions
.ARB_texture_env_combine
))) {
316 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
317 texUnit
->EnvMode
= mode
;
320 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
325 case GL_TEXTURE_ENV_COLOR
:
328 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
329 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
330 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
331 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
332 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
334 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
335 COPY_4FV(texUnit
->EnvColor
, tmp
);
339 if (ctx
->Extensions
.EXT_texture_env_combine
||
340 ctx
->Extensions
.ARB_texture_env_combine
) {
341 const GLenum mode
= (GLenum
) (GLint
) *param
;
342 if (texUnit
->Combine
.ModeRGB
== mode
)
353 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
354 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
358 case GL_DOT3_RGB_EXT
:
359 case GL_DOT3_RGBA_EXT
:
360 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
361 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
367 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
368 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
372 case GL_MODULATE_ADD_ATI
:
373 case GL_MODULATE_SIGNED_ADD_ATI
:
374 case GL_MODULATE_SUBTRACT_ATI
:
375 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
376 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
381 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
384 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
385 texUnit
->Combine
.ModeRGB
= mode
;
388 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
392 case GL_COMBINE_ALPHA
:
393 if (ctx
->Extensions
.EXT_texture_env_combine
||
394 ctx
->Extensions
.ARB_texture_env_combine
) {
395 const GLenum mode
= (GLenum
) (GLint
) *param
;
396 if (texUnit
->Combine
.ModeA
== mode
)
407 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
408 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
412 case GL_MODULATE_ADD_ATI
:
413 case GL_MODULATE_SIGNED_ADD_ATI
:
414 case GL_MODULATE_SUBTRACT_ATI
:
415 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
416 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
421 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
424 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
425 texUnit
->Combine
.ModeA
= mode
;
428 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
435 if (ctx
->Extensions
.EXT_texture_env_combine
||
436 ctx
->Extensions
.ARB_texture_env_combine
) {
437 const GLenum source
= (GLenum
) (GLint
) *param
;
438 const GLuint s
= pname
- GL_SOURCE0_RGB
;
439 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
441 if (source
== GL_TEXTURE
||
442 source
== GL_CONSTANT
||
443 source
== GL_PRIMARY_COLOR
||
444 source
== GL_PREVIOUS
||
445 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
446 source
>= GL_TEXTURE0
&&
447 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
448 (ctx
->Extensions
.ATI_texture_env_combine3
&&
449 (source
== GL_ZERO
|| source
== GL_ONE
))) {
451 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
452 texUnit
->Combine
.SourceRGB
[s
] = source
;
455 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
460 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
464 case GL_SOURCE0_ALPHA
:
465 case GL_SOURCE1_ALPHA
:
466 case GL_SOURCE2_ALPHA
:
467 if (ctx
->Extensions
.EXT_texture_env_combine
||
468 ctx
->Extensions
.ARB_texture_env_combine
) {
469 const GLenum source
= (GLenum
) (GLint
) *param
;
470 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
471 if (texUnit
->Combine
.SourceA
[s
] == source
)
473 if (source
== GL_TEXTURE
||
474 source
== GL_CONSTANT
||
475 source
== GL_PRIMARY_COLOR
||
476 source
== GL_PREVIOUS
||
477 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
478 source
>= GL_TEXTURE0
&&
479 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
480 (ctx
->Extensions
.ATI_texture_env_combine3
&&
481 (source
== GL_ZERO
|| source
== GL_ONE
))) {
483 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
484 texUnit
->Combine
.SourceA
[s
] = source
;
487 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
492 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
496 case GL_OPERAND0_RGB
:
497 case GL_OPERAND1_RGB
:
498 if (ctx
->Extensions
.EXT_texture_env_combine
||
499 ctx
->Extensions
.ARB_texture_env_combine
) {
500 const GLenum operand
= (GLenum
) (GLint
) *param
;
501 const GLuint s
= pname
- GL_OPERAND0_RGB
;
502 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
506 case GL_ONE_MINUS_SRC_COLOR
:
508 case GL_ONE_MINUS_SRC_ALPHA
:
509 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
510 texUnit
->Combine
.OperandRGB
[s
] = operand
;
513 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
518 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
522 case GL_OPERAND0_ALPHA
:
523 case GL_OPERAND1_ALPHA
:
524 if (ctx
->Extensions
.EXT_texture_env_combine
||
525 ctx
->Extensions
.ARB_texture_env_combine
) {
526 const GLenum operand
= (GLenum
) (GLint
) *param
;
527 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
531 case GL_ONE_MINUS_SRC_ALPHA
:
532 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
533 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
536 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
541 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
545 case GL_OPERAND2_RGB
:
546 if (ctx
->Extensions
.EXT_texture_env_combine
||
547 ctx
->Extensions
.ARB_texture_env_combine
) {
548 const GLenum operand
= (GLenum
) (GLint
) *param
;
549 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
552 case GL_SRC_COLOR
: /* ARB combine only */
553 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
555 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
556 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
557 texUnit
->Combine
.OperandRGB
[2] = operand
;
560 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
565 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
569 case GL_OPERAND2_ALPHA
:
570 if (ctx
->Extensions
.EXT_texture_env_combine
||
571 ctx
->Extensions
.ARB_texture_env_combine
) {
572 const GLenum operand
= (GLenum
) (GLint
) *param
;
573 if (texUnit
->Combine
.OperandA
[2] == operand
)
577 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
578 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
579 texUnit
->Combine
.OperandA
[2] = operand
;
582 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
587 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
592 if (ctx
->Extensions
.EXT_texture_env_combine
||
593 ctx
->Extensions
.ARB_texture_env_combine
) {
598 else if (*param
== 2.0) {
601 else if (*param
== 4.0) {
605 _mesa_error( ctx
, GL_INVALID_VALUE
,
606 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
609 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
611 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
612 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
615 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
620 if (ctx
->Extensions
.EXT_texture_env_combine
||
621 ctx
->Extensions
.ARB_texture_env_combine
) {
626 else if (*param
== 2.0) {
629 else if (*param
== 4.0) {
633 _mesa_error( ctx
, GL_INVALID_VALUE
,
634 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
637 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
639 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
640 texUnit
->Combine
.ScaleShiftA
= newshift
;
643 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
648 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
652 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
653 /* GL_EXT_texture_lod_bias */
654 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
655 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
658 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
659 if (texUnit
->LodBias
== param
[0])
661 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
662 texUnit
->LodBias
= param
[0];
665 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
669 else if (target
== GL_POINT_SPRITE_NV
) {
670 /* GL_ARB_point_sprite / GL_NV_point_sprite */
671 if (!ctx
->Extensions
.NV_point_sprite
672 && !ctx
->Extensions
.ARB_point_sprite
) {
673 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
676 if (pname
== GL_COORD_REPLACE_NV
) {
677 const GLenum value
= (GLenum
) param
[0];
678 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
679 /* It's kind of weird to set point state via glTexEnv,
680 * but that's what the spec calls for.
682 const GLboolean state
= (GLboolean
) value
;
683 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
685 FLUSH_VERTICES(ctx
, _NEW_POINT
);
686 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
689 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
694 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
699 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
703 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
704 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
705 _mesa_lookup_enum_by_nr(target
),
706 _mesa_lookup_enum_by_nr(pname
),
708 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
710 /* Tell device driver about the new texture environment */
711 if (ctx
->Driver
.TexEnv
) {
712 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
718 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
720 _mesa_TexEnvfv( target
, pname
, ¶m
);
726 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
729 p
[0] = (GLfloat
) param
;
730 p
[1] = p
[2] = p
[3] = 0.0;
731 _mesa_TexEnvfv( target
, pname
, p
);
736 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
739 if (pname
== GL_TEXTURE_ENV_COLOR
) {
740 p
[0] = INT_TO_FLOAT( param
[0] );
741 p
[1] = INT_TO_FLOAT( param
[1] );
742 p
[2] = INT_TO_FLOAT( param
[2] );
743 p
[3] = INT_TO_FLOAT( param
[3] );
746 p
[0] = (GLfloat
) param
[0];
747 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
749 _mesa_TexEnvfv( target
, pname
, p
);
754 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
756 GET_CURRENT_CONTEXT(ctx
);
757 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
758 ASSERT_OUTSIDE_BEGIN_END(ctx
);
760 if (target
== GL_TEXTURE_ENV
) {
762 case GL_TEXTURE_ENV_MODE
:
763 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
765 case GL_TEXTURE_ENV_COLOR
:
766 COPY_4FV( params
, texUnit
->EnvColor
);
769 if (ctx
->Extensions
.EXT_texture_env_combine
||
770 ctx
->Extensions
.ARB_texture_env_combine
) {
771 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
774 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
777 case GL_COMBINE_ALPHA
:
778 if (ctx
->Extensions
.EXT_texture_env_combine
||
779 ctx
->Extensions
.ARB_texture_env_combine
) {
780 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
783 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
787 if (ctx
->Extensions
.EXT_texture_env_combine
||
788 ctx
->Extensions
.ARB_texture_env_combine
) {
789 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[0];
792 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
796 if (ctx
->Extensions
.EXT_texture_env_combine
||
797 ctx
->Extensions
.ARB_texture_env_combine
) {
798 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[1];
801 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
805 if (ctx
->Extensions
.EXT_texture_env_combine
||
806 ctx
->Extensions
.ARB_texture_env_combine
) {
807 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[2];
810 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
813 case GL_SOURCE0_ALPHA
:
814 if (ctx
->Extensions
.EXT_texture_env_combine
||
815 ctx
->Extensions
.ARB_texture_env_combine
) {
816 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[0];
819 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
822 case GL_SOURCE1_ALPHA
:
823 if (ctx
->Extensions
.EXT_texture_env_combine
||
824 ctx
->Extensions
.ARB_texture_env_combine
) {
825 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[1];
828 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
831 case GL_SOURCE2_ALPHA
:
832 if (ctx
->Extensions
.EXT_texture_env_combine
||
833 ctx
->Extensions
.ARB_texture_env_combine
) {
834 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[2];
837 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
840 case GL_OPERAND0_RGB
:
841 if (ctx
->Extensions
.EXT_texture_env_combine
||
842 ctx
->Extensions
.ARB_texture_env_combine
) {
843 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[0];
846 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
849 case GL_OPERAND1_RGB
:
850 if (ctx
->Extensions
.EXT_texture_env_combine
||
851 ctx
->Extensions
.ARB_texture_env_combine
) {
852 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[1];
855 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
858 case GL_OPERAND2_RGB
:
859 if (ctx
->Extensions
.EXT_texture_env_combine
||
860 ctx
->Extensions
.ARB_texture_env_combine
) {
861 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[2];
864 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
867 case GL_OPERAND0_ALPHA
:
868 if (ctx
->Extensions
.EXT_texture_env_combine
||
869 ctx
->Extensions
.ARB_texture_env_combine
) {
870 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[0];
873 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
876 case GL_OPERAND1_ALPHA
:
877 if (ctx
->Extensions
.EXT_texture_env_combine
||
878 ctx
->Extensions
.ARB_texture_env_combine
) {
879 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[1];
882 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
885 case GL_OPERAND2_ALPHA
:
886 if (ctx
->Extensions
.EXT_texture_env_combine
||
887 ctx
->Extensions
.ARB_texture_env_combine
) {
888 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[2];
891 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
895 if (ctx
->Extensions
.EXT_texture_env_combine
||
896 ctx
->Extensions
.ARB_texture_env_combine
) {
897 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
899 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
910 if (ctx
->Extensions
.EXT_texture_env_combine
||
911 ctx
->Extensions
.ARB_texture_env_combine
) {
912 if (texUnit
->Combine
.ScaleShiftA
== 0)
914 else if (texUnit
->Combine
.ScaleShiftA
== 1)
920 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
925 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
928 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
929 /* GL_EXT_texture_lod_bias */
930 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
931 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
934 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
935 *params
= texUnit
->LodBias
;
938 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
942 else if (target
== GL_POINT_SPRITE_NV
) {
943 /* GL_ARB_point_sprite / GL_NV_point_sprite */
944 if (!ctx
->Extensions
.NV_point_sprite
945 && !ctx
->Extensions
.ARB_point_sprite
) {
946 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
949 if (pname
== GL_COORD_REPLACE_NV
) {
950 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
953 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
958 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
965 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
967 GET_CURRENT_CONTEXT(ctx
);
968 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
969 ASSERT_OUTSIDE_BEGIN_END(ctx
);
971 if (target
== GL_TEXTURE_ENV
) {
973 case GL_TEXTURE_ENV_MODE
:
974 *params
= (GLint
) texUnit
->EnvMode
;
976 case GL_TEXTURE_ENV_COLOR
:
977 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
978 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
979 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
980 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
983 if (ctx
->Extensions
.EXT_texture_env_combine
||
984 ctx
->Extensions
.ARB_texture_env_combine
) {
985 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
988 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
991 case GL_COMBINE_ALPHA
:
992 if (ctx
->Extensions
.EXT_texture_env_combine
||
993 ctx
->Extensions
.ARB_texture_env_combine
) {
994 *params
= (GLint
) texUnit
->Combine
.ModeA
;
997 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1000 case GL_SOURCE0_RGB
:
1001 if (ctx
->Extensions
.EXT_texture_env_combine
||
1002 ctx
->Extensions
.ARB_texture_env_combine
) {
1003 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[0];
1006 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1009 case GL_SOURCE1_RGB
:
1010 if (ctx
->Extensions
.EXT_texture_env_combine
||
1011 ctx
->Extensions
.ARB_texture_env_combine
) {
1012 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[1];
1015 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1018 case GL_SOURCE2_RGB
:
1019 if (ctx
->Extensions
.EXT_texture_env_combine
||
1020 ctx
->Extensions
.ARB_texture_env_combine
) {
1021 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[2];
1024 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1027 case GL_SOURCE0_ALPHA
:
1028 if (ctx
->Extensions
.EXT_texture_env_combine
||
1029 ctx
->Extensions
.ARB_texture_env_combine
) {
1030 *params
= (GLint
) texUnit
->Combine
.SourceA
[0];
1033 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1036 case GL_SOURCE1_ALPHA
:
1037 if (ctx
->Extensions
.EXT_texture_env_combine
||
1038 ctx
->Extensions
.ARB_texture_env_combine
) {
1039 *params
= (GLint
) texUnit
->Combine
.SourceA
[1];
1042 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1045 case GL_SOURCE2_ALPHA
:
1046 if (ctx
->Extensions
.EXT_texture_env_combine
||
1047 ctx
->Extensions
.ARB_texture_env_combine
) {
1048 *params
= (GLint
) texUnit
->Combine
.SourceA
[2];
1051 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1054 case GL_OPERAND0_RGB
:
1055 if (ctx
->Extensions
.EXT_texture_env_combine
||
1056 ctx
->Extensions
.ARB_texture_env_combine
) {
1057 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[0];
1060 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1063 case GL_OPERAND1_RGB
:
1064 if (ctx
->Extensions
.EXT_texture_env_combine
||
1065 ctx
->Extensions
.ARB_texture_env_combine
) {
1066 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[1];
1069 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1072 case GL_OPERAND2_RGB
:
1073 if (ctx
->Extensions
.EXT_texture_env_combine
||
1074 ctx
->Extensions
.ARB_texture_env_combine
) {
1075 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[2];
1078 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1081 case GL_OPERAND0_ALPHA
:
1082 if (ctx
->Extensions
.EXT_texture_env_combine
||
1083 ctx
->Extensions
.ARB_texture_env_combine
) {
1084 *params
= (GLint
) texUnit
->Combine
.OperandA
[0];
1087 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1090 case GL_OPERAND1_ALPHA
:
1091 if (ctx
->Extensions
.EXT_texture_env_combine
||
1092 ctx
->Extensions
.ARB_texture_env_combine
) {
1093 *params
= (GLint
) texUnit
->Combine
.OperandA
[1];
1096 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1099 case GL_OPERAND2_ALPHA
:
1100 if (ctx
->Extensions
.EXT_texture_env_combine
||
1101 ctx
->Extensions
.ARB_texture_env_combine
) {
1102 *params
= (GLint
) texUnit
->Combine
.OperandA
[2];
1105 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1109 if (ctx
->Extensions
.EXT_texture_env_combine
||
1110 ctx
->Extensions
.ARB_texture_env_combine
) {
1111 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1113 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1119 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1123 case GL_ALPHA_SCALE
:
1124 if (ctx
->Extensions
.EXT_texture_env_combine
||
1125 ctx
->Extensions
.ARB_texture_env_combine
) {
1126 if (texUnit
->Combine
.ScaleShiftA
== 0)
1128 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1134 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1139 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1143 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1144 /* GL_EXT_texture_lod_bias */
1145 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1146 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1149 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1150 *params
= (GLint
) texUnit
->LodBias
;
1153 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1157 else if (target
== GL_POINT_SPRITE_NV
) {
1158 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1159 if (!ctx
->Extensions
.NV_point_sprite
1160 && !ctx
->Extensions
.ARB_point_sprite
) {
1161 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1164 if (pname
== GL_COORD_REPLACE_NV
) {
1165 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1168 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1173 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1181 /**********************************************************************/
1182 /* Texture Parameters */
1183 /**********************************************************************/
1186 _mesa_validate_texture_wrap_mode(GLcontext
* ctx
,
1187 GLenum target
, GLenum eparam
)
1189 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1191 if (eparam
== GL_CLAMP
|| eparam
== GL_CLAMP_TO_EDGE
||
1192 (eparam
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1193 /* any texture target */
1196 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1197 (eparam
== GL_REPEAT
||
1198 (eparam
== GL_MIRRORED_REPEAT
&&
1199 e
->ARB_texture_mirrored_repeat
) ||
1200 (eparam
== GL_MIRROR_CLAMP_EXT
&&
1201 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1202 (eparam
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1203 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1204 (eparam
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1205 (e
->EXT_texture_mirror_clamp
)))) {
1206 /* non-rectangle texture */
1210 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1216 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1218 _mesa_TexParameterfv(target
, pname
, ¶m
);
1223 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1225 GET_CURRENT_CONTEXT(ctx
);
1226 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1227 GLenum eparam
= (GLenum
) (GLint
) params
[0];
1228 struct gl_texture_object
*texObj
;
1229 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1231 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1232 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1233 _mesa_lookup_enum_by_nr(target
),
1234 _mesa_lookup_enum_by_nr(pname
),
1236 _mesa_lookup_enum_by_nr(eparam
));
1241 texObj
= texUnit
->Current1D
;
1244 texObj
= texUnit
->Current2D
;
1247 texObj
= texUnit
->Current3D
;
1249 case GL_TEXTURE_CUBE_MAP
:
1250 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1251 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1254 texObj
= texUnit
->CurrentCubeMap
;
1256 case GL_TEXTURE_RECTANGLE_NV
:
1257 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1258 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1261 texObj
= texUnit
->CurrentRect
;
1264 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1269 case GL_TEXTURE_MIN_FILTER
:
1270 /* A small optimization */
1271 if (texObj
->MinFilter
== eparam
)
1273 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1274 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1275 texObj
->MinFilter
= eparam
;
1277 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1278 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1279 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1280 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1281 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1282 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1283 texObj
->MinFilter
= eparam
;
1286 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1290 case GL_TEXTURE_MAG_FILTER
:
1291 /* A small optimization */
1292 if (texObj
->MagFilter
== eparam
)
1295 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1296 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1297 texObj
->MagFilter
= eparam
;
1300 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1304 case GL_TEXTURE_WRAP_S
:
1305 if (texObj
->WrapS
== eparam
)
1307 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1308 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1309 texObj
->WrapS
= eparam
;
1315 case GL_TEXTURE_WRAP_T
:
1316 if (texObj
->WrapT
== eparam
)
1318 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1319 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1320 texObj
->WrapT
= eparam
;
1326 case GL_TEXTURE_WRAP_R
:
1327 if (texObj
->WrapR
== eparam
)
1329 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1330 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1331 texObj
->WrapR
= eparam
;
1337 case GL_TEXTURE_BORDER_COLOR
:
1338 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1339 texObj
->BorderColor
[RCOMP
] = params
[0];
1340 texObj
->BorderColor
[GCOMP
] = params
[1];
1341 texObj
->BorderColor
[BCOMP
] = params
[2];
1342 texObj
->BorderColor
[ACOMP
] = params
[3];
1343 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1344 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1345 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1346 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1348 case GL_TEXTURE_MIN_LOD
:
1349 if (texObj
->MinLod
== params
[0])
1351 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1352 texObj
->MinLod
= params
[0];
1354 case GL_TEXTURE_MAX_LOD
:
1355 if (texObj
->MaxLod
== params
[0])
1357 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1358 texObj
->MaxLod
= params
[0];
1360 case GL_TEXTURE_BASE_LEVEL
:
1361 if (params
[0] < 0.0) {
1362 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1365 if (target
== GL_TEXTURE_RECTANGLE_NV
&& params
[0] != 0.0) {
1366 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1369 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1370 texObj
->BaseLevel
= (GLint
) params
[0];
1372 case GL_TEXTURE_MAX_LEVEL
:
1373 if (params
[0] < 0.0) {
1374 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1377 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1378 texObj
->MaxLevel
= (GLint
) params
[0];
1380 case GL_TEXTURE_PRIORITY
:
1381 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1382 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1384 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1385 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1386 if (params
[0] < 1.0) {
1387 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1390 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1391 /* clamp to max, that's what NVIDIA does */
1392 texObj
->MaxAnisotropy
= MIN2(params
[0],
1393 ctx
->Const
.MaxTextureMaxAnisotropy
);
1396 _mesa_error(ctx
, GL_INVALID_ENUM
,
1397 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1401 case GL_TEXTURE_COMPARE_SGIX
:
1402 if (ctx
->Extensions
.SGIX_shadow
) {
1403 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1404 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1407 _mesa_error(ctx
, GL_INVALID_ENUM
,
1408 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1412 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1413 if (ctx
->Extensions
.SGIX_shadow
) {
1414 GLenum op
= (GLenum
) params
[0];
1415 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1416 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1417 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1418 texObj
->CompareOperator
= op
;
1421 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1425 _mesa_error(ctx
, GL_INVALID_ENUM
,
1426 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1430 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1431 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1432 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1433 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1436 _mesa_error(ctx
, GL_INVALID_ENUM
,
1437 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1441 case GL_GENERATE_MIPMAP_SGIS
:
1442 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1443 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1446 _mesa_error(ctx
, GL_INVALID_ENUM
,
1447 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1451 case GL_TEXTURE_COMPARE_MODE_ARB
:
1452 if (ctx
->Extensions
.ARB_shadow
) {
1453 const GLenum mode
= (GLenum
) params
[0];
1454 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1455 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1456 texObj
->CompareMode
= mode
;
1459 _mesa_error(ctx
, GL_INVALID_ENUM
,
1460 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1465 _mesa_error(ctx
, GL_INVALID_ENUM
,
1466 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1470 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1471 if (ctx
->Extensions
.ARB_shadow
) {
1472 const GLenum func
= (GLenum
) params
[0];
1473 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1474 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1475 texObj
->CompareFunc
= func
;
1477 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1478 (func
== GL_EQUAL
||
1479 func
== GL_NOTEQUAL
||
1481 func
== GL_GREATER
||
1482 func
== GL_ALWAYS
||
1483 func
== GL_NEVER
)) {
1484 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1485 texObj
->CompareFunc
= func
;
1488 _mesa_error(ctx
, GL_INVALID_ENUM
,
1489 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1494 _mesa_error(ctx
, GL_INVALID_ENUM
,
1495 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1499 case GL_DEPTH_TEXTURE_MODE_ARB
:
1500 if (ctx
->Extensions
.ARB_depth_texture
) {
1501 const GLenum result
= (GLenum
) params
[0];
1502 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1503 || result
== GL_ALPHA
) {
1504 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1505 texObj
->DepthMode
= result
;
1508 _mesa_error(ctx
, GL_INVALID_ENUM
,
1509 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1514 _mesa_error(ctx
, GL_INVALID_ENUM
,
1515 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1519 case GL_TEXTURE_LOD_BIAS
:
1520 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1521 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1522 if (texObj
->LodBias
!= params
[0]) {
1523 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1524 texObj
->LodBias
= params
[0];
1530 _mesa_error(ctx
, GL_INVALID_ENUM
,
1531 "glTexParameter(pname=0x%x)", pname
);
1535 texObj
->Complete
= GL_FALSE
;
1537 if (ctx
->Driver
.TexParameter
) {
1538 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1544 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1547 if (pname
== GL_TEXTURE_PRIORITY
)
1548 fparam
[0] = INT_TO_FLOAT(param
);
1550 fparam
[0] = (GLfloat
) param
;
1551 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1552 _mesa_TexParameterfv(target
, pname
, fparam
);
1557 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1560 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1561 fparam
[0] = INT_TO_FLOAT(params
[0]);
1562 fparam
[1] = INT_TO_FLOAT(params
[1]);
1563 fparam
[2] = INT_TO_FLOAT(params
[2]);
1564 fparam
[3] = INT_TO_FLOAT(params
[3]);
1567 if (pname
== GL_TEXTURE_PRIORITY
)
1568 fparam
[0] = INT_TO_FLOAT(params
[0]);
1570 fparam
[0] = (GLfloat
) params
[0];
1571 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1573 _mesa_TexParameterfv(target
, pname
, fparam
);
1578 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1579 GLenum pname
, GLfloat
*params
)
1582 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1583 *params
= (GLfloat
) iparam
;
1588 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1592 case GL_PROXY_TEXTURE_1D
:
1595 case GL_PROXY_TEXTURE_2D
:
1598 case GL_PROXY_TEXTURE_3D
:
1600 case GL_TEXTURE_CUBE_MAP
:
1601 case GL_PROXY_TEXTURE_CUBE_MAP
:
1602 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1603 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1604 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1605 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1606 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1607 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1608 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1609 case GL_TEXTURE_RECTANGLE_NV
:
1610 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1611 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1613 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1620 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1621 GLenum pname
, GLint
*params
)
1623 GET_CURRENT_CONTEXT(ctx
);
1624 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1625 const struct gl_texture_image
*img
= NULL
;
1629 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1631 /* this will catch bad target values */
1632 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1633 if (dimensions
== 0) {
1634 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1640 case GL_PROXY_TEXTURE_1D
:
1642 case GL_PROXY_TEXTURE_2D
:
1643 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1646 case GL_PROXY_TEXTURE_3D
:
1647 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1649 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1650 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1651 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1652 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1653 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1654 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1655 case GL_PROXY_TEXTURE_CUBE_MAP
:
1656 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1658 case GL_TEXTURE_RECTANGLE_NV
:
1659 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1663 _mesa_problem(ctx
, "switch in _mesa_GetTexLevelParameter");
1667 if (level
< 0 || level
>= maxLevels
) {
1668 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1672 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1673 if (!img
|| !img
->TexFormat
) {
1674 /* undefined texture image */
1675 if (pname
== GL_TEXTURE_COMPONENTS
)
1682 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
1683 (target
== GL_PROXY_TEXTURE_2D
) ||
1684 (target
== GL_PROXY_TEXTURE_3D
) ||
1685 (target
== GL_PROXY_TEXTURE_CUBE_MAP
) ||
1686 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
);
1689 case GL_TEXTURE_WIDTH
:
1690 *params
= img
->Width
;
1692 case GL_TEXTURE_HEIGHT
:
1693 *params
= img
->Height
;
1695 case GL_TEXTURE_DEPTH
:
1696 *params
= img
->Depth
;
1698 case GL_TEXTURE_INTERNAL_FORMAT
:
1699 *params
= img
->IntFormat
;
1701 case GL_TEXTURE_BORDER
:
1702 *params
= img
->Border
;
1704 case GL_TEXTURE_RED_SIZE
:
1705 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1706 *params
= img
->TexFormat
->RedBits
;
1710 case GL_TEXTURE_GREEN_SIZE
:
1711 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1712 *params
= img
->TexFormat
->GreenBits
;
1716 case GL_TEXTURE_BLUE_SIZE
:
1717 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1718 *params
= img
->TexFormat
->BlueBits
;
1722 case GL_TEXTURE_ALPHA_SIZE
:
1723 if (img
->Format
== GL_ALPHA
|| img
->Format
== GL_LUMINANCE_ALPHA
||
1724 img
->Format
== GL_RGBA
)
1725 *params
= img
->TexFormat
->AlphaBits
;
1729 case GL_TEXTURE_INTENSITY_SIZE
:
1730 if (img
->Format
!= GL_INTENSITY
)
1732 else if (img
->TexFormat
->IntensityBits
> 0)
1733 *params
= img
->TexFormat
->IntensityBits
;
1734 else /* intensity probably stored as rgb texture */
1735 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1737 case GL_TEXTURE_LUMINANCE_SIZE
:
1738 if (img
->Format
!= GL_LUMINANCE
&&
1739 img
->Format
!= GL_LUMINANCE_ALPHA
)
1741 else if (img
->TexFormat
->LuminanceBits
> 0)
1742 *params
= img
->TexFormat
->LuminanceBits
;
1743 else /* luminance probably stored as rgb texture */
1744 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1746 case GL_TEXTURE_INDEX_SIZE_EXT
:
1747 if (img
->Format
== GL_COLOR_INDEX
)
1748 *params
= img
->TexFormat
->IndexBits
;
1753 /* XXX this isn't in the GL_SGIX_depth_texture spec
1754 * but seems appropriate.
1756 if (ctx
->Extensions
.SGIX_depth_texture
)
1757 *params
= img
->TexFormat
->DepthBits
;
1759 _mesa_error(ctx
, GL_INVALID_ENUM
,
1760 "glGetTexLevelParameter[if]v(pname)");
1763 /* GL_ARB_texture_compression */
1764 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1765 if (ctx
->Extensions
.ARB_texture_compression
) {
1766 if (img
->IsCompressed
&& !isProxy
)
1767 *params
= img
->CompressedSize
;
1769 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1770 "glGetTexLevelParameter[if]v(pname)");
1773 _mesa_error(ctx
, GL_INVALID_ENUM
,
1774 "glGetTexLevelParameter[if]v(pname)");
1777 case GL_TEXTURE_COMPRESSED
:
1778 if (ctx
->Extensions
.ARB_texture_compression
) {
1779 *params
= (GLint
) img
->IsCompressed
;
1782 _mesa_error(ctx
, GL_INVALID_ENUM
,
1783 "glGetTexLevelParameter[if]v(pname)");
1787 /* GL_ARB_texture_float */
1788 case GL_TEXTURE_RED_TYPE_ARB
:
1789 if (ctx
->Extensions
.ARB_texture_float
) {
1790 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
1793 _mesa_error(ctx
, GL_INVALID_ENUM
,
1794 "glGetTexLevelParameter[if]v(pname)");
1797 case GL_TEXTURE_GREEN_TYPE_ARB
:
1798 if (ctx
->Extensions
.ARB_texture_float
) {
1799 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
1802 _mesa_error(ctx
, GL_INVALID_ENUM
,
1803 "glGetTexLevelParameter[if]v(pname)");
1806 case GL_TEXTURE_BLUE_TYPE_ARB
:
1807 if (ctx
->Extensions
.ARB_texture_float
) {
1808 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
1811 _mesa_error(ctx
, GL_INVALID_ENUM
,
1812 "glGetTexLevelParameter[if]v(pname)");
1815 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1816 if (ctx
->Extensions
.ARB_texture_float
) {
1817 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
1820 _mesa_error(ctx
, GL_INVALID_ENUM
,
1821 "glGetTexLevelParameter[if]v(pname)");
1824 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1825 if (ctx
->Extensions
.ARB_texture_float
) {
1826 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
1829 _mesa_error(ctx
, GL_INVALID_ENUM
,
1830 "glGetTexLevelParameter[if]v(pname)");
1833 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1834 if (ctx
->Extensions
.ARB_texture_float
) {
1835 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
1838 _mesa_error(ctx
, GL_INVALID_ENUM
,
1839 "glGetTexLevelParameter[if]v(pname)");
1842 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1843 if (ctx
->Extensions
.ARB_texture_float
) {
1844 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
1847 _mesa_error(ctx
, GL_INVALID_ENUM
,
1848 "glGetTexLevelParameter[if]v(pname)");
1852 _mesa_error(ctx
, GL_INVALID_ENUM
,
1853 "glGetTexLevelParameter[if]v(pname)");
1860 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1862 GET_CURRENT_CONTEXT(ctx
);
1863 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1864 struct gl_texture_object
*obj
;
1865 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1867 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1869 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1874 case GL_TEXTURE_MAG_FILTER
:
1875 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1877 case GL_TEXTURE_MIN_FILTER
:
1878 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1880 case GL_TEXTURE_WRAP_S
:
1881 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1883 case GL_TEXTURE_WRAP_T
:
1884 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1886 case GL_TEXTURE_WRAP_R
:
1887 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1889 case GL_TEXTURE_BORDER_COLOR
:
1890 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1891 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1892 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1893 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1895 case GL_TEXTURE_RESIDENT
:
1898 if (ctx
->Driver
.IsTextureResident
)
1899 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1902 *params
= ENUM_TO_FLOAT(resident
);
1905 case GL_TEXTURE_PRIORITY
:
1906 *params
= obj
->Priority
;
1908 case GL_TEXTURE_MIN_LOD
:
1909 *params
= obj
->MinLod
;
1911 case GL_TEXTURE_MAX_LOD
:
1912 *params
= obj
->MaxLod
;
1914 case GL_TEXTURE_BASE_LEVEL
:
1915 *params
= (GLfloat
) obj
->BaseLevel
;
1917 case GL_TEXTURE_MAX_LEVEL
:
1918 *params
= (GLfloat
) obj
->MaxLevel
;
1920 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1921 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1922 *params
= obj
->MaxAnisotropy
;
1926 case GL_TEXTURE_COMPARE_SGIX
:
1927 if (ctx
->Extensions
.SGIX_shadow
) {
1928 *params
= (GLfloat
) obj
->CompareFlag
;
1932 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1933 if (ctx
->Extensions
.SGIX_shadow
) {
1934 *params
= (GLfloat
) obj
->CompareOperator
;
1938 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1939 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1940 *params
= obj
->ShadowAmbient
;
1944 case GL_GENERATE_MIPMAP_SGIS
:
1945 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1946 *params
= (GLfloat
) obj
->GenerateMipmap
;
1950 case GL_TEXTURE_COMPARE_MODE_ARB
:
1951 if (ctx
->Extensions
.ARB_shadow
) {
1952 *params
= (GLfloat
) obj
->CompareMode
;
1956 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1957 if (ctx
->Extensions
.ARB_shadow
) {
1958 *params
= (GLfloat
) obj
->CompareFunc
;
1962 case GL_DEPTH_TEXTURE_MODE_ARB
:
1963 if (ctx
->Extensions
.ARB_depth_texture
) {
1964 *params
= (GLfloat
) obj
->DepthMode
;
1968 case GL_TEXTURE_LOD_BIAS
:
1969 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1970 *params
= obj
->LodBias
;
1975 ; /* silence warnings */
1977 /* If we get here, pname was an unrecognized enum */
1978 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1984 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1986 GET_CURRENT_CONTEXT(ctx
);
1987 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1988 struct gl_texture_object
*obj
;
1989 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1991 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1993 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1998 case GL_TEXTURE_MAG_FILTER
:
1999 *params
= (GLint
) obj
->MagFilter
;
2001 case GL_TEXTURE_MIN_FILTER
:
2002 *params
= (GLint
) obj
->MinFilter
;
2004 case GL_TEXTURE_WRAP_S
:
2005 *params
= (GLint
) obj
->WrapS
;
2007 case GL_TEXTURE_WRAP_T
:
2008 *params
= (GLint
) obj
->WrapT
;
2010 case GL_TEXTURE_WRAP_R
:
2011 *params
= (GLint
) obj
->WrapR
;
2013 case GL_TEXTURE_BORDER_COLOR
:
2016 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
2017 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
2018 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
2019 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
2020 params
[0] = FLOAT_TO_INT(b
[0]);
2021 params
[1] = FLOAT_TO_INT(b
[1]);
2022 params
[2] = FLOAT_TO_INT(b
[2]);
2023 params
[3] = FLOAT_TO_INT(b
[3]);
2026 case GL_TEXTURE_RESIDENT
:
2029 if (ctx
->Driver
.IsTextureResident
)
2030 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
2033 *params
= (GLint
) resident
;
2036 case GL_TEXTURE_PRIORITY
:
2037 *params
= FLOAT_TO_INT(obj
->Priority
);
2039 case GL_TEXTURE_MIN_LOD
:
2040 *params
= (GLint
) obj
->MinLod
;
2042 case GL_TEXTURE_MAX_LOD
:
2043 *params
= (GLint
) obj
->MaxLod
;
2045 case GL_TEXTURE_BASE_LEVEL
:
2046 *params
= obj
->BaseLevel
;
2048 case GL_TEXTURE_MAX_LEVEL
:
2049 *params
= obj
->MaxLevel
;
2051 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2052 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2053 *params
= (GLint
) obj
->MaxAnisotropy
;
2057 case GL_TEXTURE_COMPARE_SGIX
:
2058 if (ctx
->Extensions
.SGIX_shadow
) {
2059 *params
= (GLint
) obj
->CompareFlag
;
2063 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2064 if (ctx
->Extensions
.SGIX_shadow
) {
2065 *params
= (GLint
) obj
->CompareOperator
;
2069 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2070 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2071 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2075 case GL_GENERATE_MIPMAP_SGIS
:
2076 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2077 *params
= (GLint
) obj
->GenerateMipmap
;
2081 case GL_TEXTURE_COMPARE_MODE_ARB
:
2082 if (ctx
->Extensions
.ARB_shadow
) {
2083 *params
= (GLint
) obj
->CompareMode
;
2087 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2088 if (ctx
->Extensions
.ARB_shadow
) {
2089 *params
= (GLint
) obj
->CompareFunc
;
2093 case GL_DEPTH_TEXTURE_MODE_ARB
:
2094 if (ctx
->Extensions
.ARB_depth_texture
) {
2095 *params
= (GLint
) obj
->DepthMode
;
2099 case GL_TEXTURE_LOD_BIAS
:
2100 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
2101 *params
= (GLint
) obj
->LodBias
;
2106 ; /* silence warnings */
2108 /* If we get here, pname was an unrecognized enum */
2109 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2115 /**********************************************************************/
2116 /* Texture Coord Generation */
2117 /**********************************************************************/
2121 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2123 GET_CURRENT_CONTEXT(ctx
);
2124 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2125 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2126 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2128 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2129 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2130 _mesa_lookup_enum_by_nr(coord
),
2131 _mesa_lookup_enum_by_nr(pname
),
2133 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2137 if (pname
==GL_TEXTURE_GEN_MODE
) {
2138 GLenum mode
= (GLenum
) (GLint
) *params
;
2141 case GL_OBJECT_LINEAR
:
2142 bits
= TEXGEN_OBJ_LINEAR
;
2145 bits
= TEXGEN_EYE_LINEAR
;
2147 case GL_REFLECTION_MAP_NV
:
2148 bits
= TEXGEN_REFLECTION_MAP_NV
;
2150 case GL_NORMAL_MAP_NV
:
2151 bits
= TEXGEN_NORMAL_MAP_NV
;
2154 bits
= TEXGEN_SPHERE_MAP
;
2157 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2160 if (texUnit
->GenModeS
== mode
)
2162 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2163 texUnit
->GenModeS
= mode
;
2164 texUnit
->_GenBitS
= bits
;
2166 else if (pname
==GL_OBJECT_PLANE
) {
2167 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2169 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2170 texUnit
->ObjectPlaneS
[0] = params
[0];
2171 texUnit
->ObjectPlaneS
[1] = params
[1];
2172 texUnit
->ObjectPlaneS
[2] = params
[2];
2173 texUnit
->ObjectPlaneS
[3] = params
[3];
2175 else if (pname
==GL_EYE_PLANE
) {
2178 /* Transform plane equation by the inverse modelview matrix */
2179 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2180 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2182 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2183 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2185 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2186 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2194 if (pname
==GL_TEXTURE_GEN_MODE
) {
2195 GLenum mode
= (GLenum
) (GLint
) *params
;
2198 case GL_OBJECT_LINEAR
:
2199 bitt
= TEXGEN_OBJ_LINEAR
;
2202 bitt
= TEXGEN_EYE_LINEAR
;
2204 case GL_REFLECTION_MAP_NV
:
2205 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2207 case GL_NORMAL_MAP_NV
:
2208 bitt
= TEXGEN_NORMAL_MAP_NV
;
2211 bitt
= TEXGEN_SPHERE_MAP
;
2214 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2217 if (texUnit
->GenModeT
== mode
)
2219 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2220 texUnit
->GenModeT
= mode
;
2221 texUnit
->_GenBitT
= bitt
;
2223 else if (pname
==GL_OBJECT_PLANE
) {
2224 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2226 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2227 texUnit
->ObjectPlaneT
[0] = params
[0];
2228 texUnit
->ObjectPlaneT
[1] = params
[1];
2229 texUnit
->ObjectPlaneT
[2] = params
[2];
2230 texUnit
->ObjectPlaneT
[3] = params
[3];
2232 else if (pname
==GL_EYE_PLANE
) {
2234 /* Transform plane equation by the inverse modelview matrix */
2235 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2236 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2238 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2239 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2241 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2242 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2245 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2250 if (pname
==GL_TEXTURE_GEN_MODE
) {
2251 GLenum mode
= (GLenum
) (GLint
) *params
;
2254 case GL_OBJECT_LINEAR
:
2255 bitr
= TEXGEN_OBJ_LINEAR
;
2257 case GL_REFLECTION_MAP_NV
:
2258 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2260 case GL_NORMAL_MAP_NV
:
2261 bitr
= TEXGEN_NORMAL_MAP_NV
;
2264 bitr
= TEXGEN_EYE_LINEAR
;
2267 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2270 if (texUnit
->GenModeR
== mode
)
2272 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2273 texUnit
->GenModeR
= mode
;
2274 texUnit
->_GenBitR
= bitr
;
2276 else if (pname
==GL_OBJECT_PLANE
) {
2277 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2279 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2280 texUnit
->ObjectPlaneR
[0] = params
[0];
2281 texUnit
->ObjectPlaneR
[1] = params
[1];
2282 texUnit
->ObjectPlaneR
[2] = params
[2];
2283 texUnit
->ObjectPlaneR
[3] = params
[3];
2285 else if (pname
==GL_EYE_PLANE
) {
2287 /* Transform plane equation by the inverse modelview matrix */
2288 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2289 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2291 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2292 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2294 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2295 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2298 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2303 if (pname
==GL_TEXTURE_GEN_MODE
) {
2304 GLenum mode
= (GLenum
) (GLint
) *params
;
2307 case GL_OBJECT_LINEAR
:
2308 bitq
= TEXGEN_OBJ_LINEAR
;
2311 bitq
= TEXGEN_EYE_LINEAR
;
2314 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2317 if (texUnit
->GenModeQ
== mode
)
2319 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2320 texUnit
->GenModeQ
= mode
;
2321 texUnit
->_GenBitQ
= bitq
;
2323 else if (pname
==GL_OBJECT_PLANE
) {
2324 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2326 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2327 texUnit
->ObjectPlaneQ
[0] = params
[0];
2328 texUnit
->ObjectPlaneQ
[1] = params
[1];
2329 texUnit
->ObjectPlaneQ
[2] = params
[2];
2330 texUnit
->ObjectPlaneQ
[3] = params
[3];
2332 else if (pname
==GL_EYE_PLANE
) {
2334 /* Transform plane equation by the inverse modelview matrix */
2335 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2336 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2338 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2339 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2341 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2342 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2345 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2350 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2354 if (ctx
->Driver
.TexGen
)
2355 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2360 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2363 p
[0] = (GLfloat
) params
[0];
2364 if (pname
== GL_TEXTURE_GEN_MODE
) {
2365 p
[1] = p
[2] = p
[3] = 0.0F
;
2368 p
[1] = (GLfloat
) params
[1];
2369 p
[2] = (GLfloat
) params
[2];
2370 p
[3] = (GLfloat
) params
[3];
2372 _mesa_TexGenfv(coord
, pname
, p
);
2377 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2379 GLfloat p
= (GLfloat
) param
;
2380 _mesa_TexGenfv( coord
, pname
, &p
);
2385 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2388 p
[0] = (GLfloat
) params
[0];
2389 if (pname
== GL_TEXTURE_GEN_MODE
) {
2390 p
[1] = p
[2] = p
[3] = 0.0F
;
2393 p
[1] = (GLfloat
) params
[1];
2394 p
[2] = (GLfloat
) params
[2];
2395 p
[3] = (GLfloat
) params
[3];
2397 _mesa_TexGenfv( coord
, pname
, p
);
2402 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2404 _mesa_TexGenfv(coord
, pname
, ¶m
);
2409 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2411 _mesa_TexGeniv( coord
, pname
, ¶m
);
2417 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2419 GET_CURRENT_CONTEXT(ctx
);
2420 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2421 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2422 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2426 if (pname
==GL_TEXTURE_GEN_MODE
) {
2427 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2429 else if (pname
==GL_OBJECT_PLANE
) {
2430 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2432 else if (pname
==GL_EYE_PLANE
) {
2433 COPY_4V( params
, texUnit
->EyePlaneS
);
2436 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2441 if (pname
==GL_TEXTURE_GEN_MODE
) {
2442 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2444 else if (pname
==GL_OBJECT_PLANE
) {
2445 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2447 else if (pname
==GL_EYE_PLANE
) {
2448 COPY_4V( params
, texUnit
->EyePlaneT
);
2451 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2456 if (pname
==GL_TEXTURE_GEN_MODE
) {
2457 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2459 else if (pname
==GL_OBJECT_PLANE
) {
2460 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2462 else if (pname
==GL_EYE_PLANE
) {
2463 COPY_4V( params
, texUnit
->EyePlaneR
);
2466 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2471 if (pname
==GL_TEXTURE_GEN_MODE
) {
2472 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2474 else if (pname
==GL_OBJECT_PLANE
) {
2475 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2477 else if (pname
==GL_EYE_PLANE
) {
2478 COPY_4V( params
, texUnit
->EyePlaneQ
);
2481 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2486 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2494 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2496 GET_CURRENT_CONTEXT(ctx
);
2497 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2498 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2499 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2503 if (pname
==GL_TEXTURE_GEN_MODE
) {
2504 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2506 else if (pname
==GL_OBJECT_PLANE
) {
2507 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2509 else if (pname
==GL_EYE_PLANE
) {
2510 COPY_4V( params
, texUnit
->EyePlaneS
);
2513 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2518 if (pname
==GL_TEXTURE_GEN_MODE
) {
2519 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2521 else if (pname
==GL_OBJECT_PLANE
) {
2522 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2524 else if (pname
==GL_EYE_PLANE
) {
2525 COPY_4V( params
, texUnit
->EyePlaneT
);
2528 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2533 if (pname
==GL_TEXTURE_GEN_MODE
) {
2534 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2536 else if (pname
==GL_OBJECT_PLANE
) {
2537 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2539 else if (pname
==GL_EYE_PLANE
) {
2540 COPY_4V( params
, texUnit
->EyePlaneR
);
2543 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2548 if (pname
==GL_TEXTURE_GEN_MODE
) {
2549 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2551 else if (pname
==GL_OBJECT_PLANE
) {
2552 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2554 else if (pname
==GL_EYE_PLANE
) {
2555 COPY_4V( params
, texUnit
->EyePlaneQ
);
2558 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2563 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2571 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2573 GET_CURRENT_CONTEXT(ctx
);
2574 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2575 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2576 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2580 if (pname
==GL_TEXTURE_GEN_MODE
) {
2581 params
[0] = texUnit
->GenModeS
;
2583 else if (pname
==GL_OBJECT_PLANE
) {
2584 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2585 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2586 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2587 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2589 else if (pname
==GL_EYE_PLANE
) {
2590 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2591 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2592 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2593 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2596 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2601 if (pname
==GL_TEXTURE_GEN_MODE
) {
2602 params
[0] = texUnit
->GenModeT
;
2604 else if (pname
==GL_OBJECT_PLANE
) {
2605 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2606 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2607 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2608 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2610 else if (pname
==GL_EYE_PLANE
) {
2611 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2612 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2613 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2614 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2617 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2622 if (pname
==GL_TEXTURE_GEN_MODE
) {
2623 params
[0] = texUnit
->GenModeR
;
2625 else if (pname
==GL_OBJECT_PLANE
) {
2626 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2627 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2628 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2629 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2631 else if (pname
==GL_EYE_PLANE
) {
2632 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2633 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2634 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2635 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2638 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2643 if (pname
==GL_TEXTURE_GEN_MODE
) {
2644 params
[0] = texUnit
->GenModeQ
;
2646 else if (pname
==GL_OBJECT_PLANE
) {
2647 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2648 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2649 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2650 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2652 else if (pname
==GL_EYE_PLANE
) {
2653 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2654 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2655 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2656 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2659 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2664 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2670 /* GL_ARB_multitexture */
2672 _mesa_ActiveTextureARB( GLenum target
)
2674 GET_CURRENT_CONTEXT(ctx
);
2675 const GLuint texUnit
= target
- GL_TEXTURE0
;
2676 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2678 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2679 _mesa_debug(ctx
, "glActiveTexture %s\n",
2680 _mesa_lookup_enum_by_nr(target
));
2682 /* Cater for texture unit 0 is first, therefore use >= */
2683 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2684 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(target)");
2688 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2691 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2693 ctx
->Texture
.CurrentUnit
= texUnit
;
2694 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2695 /* update current stack pointer */
2696 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2699 if (ctx
->Driver
.ActiveTexture
) {
2700 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2705 /* GL_ARB_multitexture */
2707 _mesa_ClientActiveTextureARB( GLenum target
)
2709 GET_CURRENT_CONTEXT(ctx
);
2710 GLuint texUnit
= target
- GL_TEXTURE0
;
2711 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2713 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
2714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(target)");
2718 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2719 ctx
->Array
.ActiveTexture
= texUnit
;
2724 /**********************************************************************/
2725 /* Pixel Texgen Extensions */
2726 /**********************************************************************/
2729 _mesa_PixelTexGenSGIX(GLenum mode
)
2731 GLenum newRgbSource
, newAlphaSource
;
2732 GET_CURRENT_CONTEXT(ctx
);
2733 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2737 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2738 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2741 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2742 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2745 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2746 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2749 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2750 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2753 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenSGIX(mode)");
2757 if (newRgbSource
== ctx
->Pixel
.FragmentRgbSource
&&
2758 newAlphaSource
== ctx
->Pixel
.FragmentAlphaSource
)
2761 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2762 ctx
->Pixel
.FragmentRgbSource
= newRgbSource
;
2763 ctx
->Pixel
.FragmentAlphaSource
= newAlphaSource
;
2768 _mesa_PixelTexGenParameterfSGIS(GLenum target
, GLfloat value
)
2770 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) value
);
2775 _mesa_PixelTexGenParameterfvSGIS(GLenum target
, const GLfloat
*value
)
2777 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) *value
);
2782 _mesa_PixelTexGenParameteriSGIS(GLenum target
, GLint value
)
2784 GET_CURRENT_CONTEXT(ctx
);
2785 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2787 if (value
!= GL_CURRENT_RASTER_COLOR
&& value
!= GL_PIXEL_GROUP_COLOR_SGIS
) {
2788 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(value)");
2793 case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
:
2794 if (ctx
->Pixel
.FragmentRgbSource
== (GLenum
) value
)
2796 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2797 ctx
->Pixel
.FragmentRgbSource
= (GLenum
) value
;
2799 case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
:
2800 if (ctx
->Pixel
.FragmentAlphaSource
== (GLenum
) value
)
2802 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2803 ctx
->Pixel
.FragmentAlphaSource
= (GLenum
) value
;
2806 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(target)");
2813 _mesa_PixelTexGenParameterivSGIS(GLenum target
, const GLint
*value
)
2815 _mesa_PixelTexGenParameteriSGIS(target
, *value
);
2820 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target
, GLfloat
*value
)
2822 GET_CURRENT_CONTEXT(ctx
);
2823 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2825 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2826 *value
= (GLfloat
) ctx
->Pixel
.FragmentRgbSource
;
2828 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2829 *value
= (GLfloat
) ctx
->Pixel
.FragmentAlphaSource
;
2832 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterfvSGIS(target)");
2838 _mesa_GetPixelTexGenParameterivSGIS(GLenum target
, GLint
*value
)
2840 GET_CURRENT_CONTEXT(ctx
);
2841 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2843 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2844 *value
= (GLint
) ctx
->Pixel
.FragmentRgbSource
;
2846 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2847 *value
= (GLint
) ctx
->Pixel
.FragmentAlphaSource
;
2850 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterivSGIS(target)");
2856 /**********************************************************************/
2857 /***** State management *****/
2858 /**********************************************************************/
2862 * \note This routine refers to derived texture attribute values to
2863 * compute the ENABLE_TEXMAT flags, but is only called on
2864 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2865 * flags are updated by _mesa_update_textures(), below.
2867 * \param ctx GL context.
2870 update_texture_matrices( GLcontext
*ctx
)
2874 ctx
->Texture
._TexMatEnabled
= 0;
2876 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2877 if (ctx
->TextureMatrixStack
[i
].Top
->flags
& MAT_DIRTY
) {
2878 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2880 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2881 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2882 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2884 if (ctx
->Driver
.TextureMatrix
)
2885 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2894 * \note This routine refers to derived texture matrix values to
2895 * compute the ENABLE_TEXMAT flags, but is only called on
2896 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2897 * flags are updated by _mesa_update_texture_matrices, above.
2899 * \param ctx GL context.
2902 update_texture_state( GLcontext
*ctx
)
2906 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2910 ctx
->Texture
._EnabledUnits
= 0;
2911 ctx
->Texture
._GenFlags
= 0;
2912 ctx
->Texture
._TexMatEnabled
= 0;
2913 ctx
->Texture
._TexGenEnabled
= 0;
2915 /* Update texture unit state.
2916 * XXX this loop should probably be broken into separate loops for
2917 * texture coord units and texture image units.
2919 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2920 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2923 texUnit
->_Current
= NULL
;
2924 texUnit
->_ReallyEnabled
= 0;
2925 texUnit
->_GenFlags
= 0;
2927 /* Get the bitmask of texture enables */
2928 if (ctx
->FragmentProgram
._Enabled
) {
2929 enableBits
= ctx
->FragmentProgram
.Current
->TexturesUsed
[unit
];
2932 if (!texUnit
->Enabled
)
2934 enableBits
= texUnit
->Enabled
;
2937 /* Look for the highest-priority texture target that's enabled and
2938 * complete. That's the one we'll use for texturing. If we're using
2939 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2941 if (enableBits
& TEXTURE_CUBE_BIT
) {
2942 struct gl_texture_object
*texObj
= texUnit
->CurrentCubeMap
;
2943 if (!texObj
->Complete
) {
2944 _mesa_test_texobj_completeness(ctx
, texObj
);
2946 if (texObj
->Complete
) {
2947 texUnit
->_ReallyEnabled
= TEXTURE_CUBE_BIT
;
2948 texUnit
->_Current
= texObj
;
2952 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_3D_BIT
)) {
2953 struct gl_texture_object
*texObj
= texUnit
->Current3D
;
2954 if (!texObj
->Complete
) {
2955 _mesa_test_texobj_completeness(ctx
, texObj
);
2957 if (texObj
->Complete
) {
2958 texUnit
->_ReallyEnabled
= TEXTURE_3D_BIT
;
2959 texUnit
->_Current
= texObj
;
2963 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_RECT_BIT
)) {
2964 struct gl_texture_object
*texObj
= texUnit
->CurrentRect
;
2965 if (!texObj
->Complete
) {
2966 _mesa_test_texobj_completeness(ctx
, texObj
);
2968 if (texObj
->Complete
) {
2969 texUnit
->_ReallyEnabled
= TEXTURE_RECT_BIT
;
2970 texUnit
->_Current
= texObj
;
2974 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_2D_BIT
)) {
2975 struct gl_texture_object
*texObj
= texUnit
->Current2D
;
2976 if (!texObj
->Complete
) {
2977 _mesa_test_texobj_completeness(ctx
, texObj
);
2979 if (texObj
->Complete
) {
2980 texUnit
->_ReallyEnabled
= TEXTURE_2D_BIT
;
2981 texUnit
->_Current
= texObj
;
2985 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_1D_BIT
)) {
2986 struct gl_texture_object
*texObj
= texUnit
->Current1D
;
2987 if (!texObj
->Complete
) {
2988 _mesa_test_texobj_completeness(ctx
, texObj
);
2990 if (texObj
->Complete
) {
2991 texUnit
->_ReallyEnabled
= TEXTURE_1D_BIT
;
2992 texUnit
->_Current
= texObj
;
2996 if (!texUnit
->_ReallyEnabled
) {
3000 if (texUnit
->_ReallyEnabled
)
3001 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
3003 if (texUnit
->EnvMode
== GL_COMBINE
) {
3004 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
3007 GLenum format
= texUnit
->_Current
->Image
[0][0]->Format
;
3008 if (format
== GL_COLOR_INDEX
) {
3009 format
= GL_RGBA
; /* a bit of a hack */
3011 else if (format
== GL_DEPTH_COMPONENT
) {
3012 format
= texUnit
->_Current
->DepthMode
;
3014 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
3015 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3018 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
3020 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
3028 case GL_DOT3_RGB_EXT
:
3029 case GL_DOT3_RGBA_EXT
:
3030 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
3032 case GL_INTERPOLATE
:
3033 case GL_MODULATE_ADD_ATI
:
3034 case GL_MODULATE_SIGNED_ADD_ATI
:
3035 case GL_MODULATE_SUBTRACT_ATI
:
3036 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
3039 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
3040 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
3044 switch (texUnit
->_CurrentCombine
->ModeA
) {
3046 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
3052 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
3054 case GL_INTERPOLATE
:
3055 case GL_MODULATE_ADD_ATI
:
3056 case GL_MODULATE_SIGNED_ADD_ATI
:
3057 case GL_MODULATE_SUBTRACT_ATI
:
3058 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
3061 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
3062 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
3066 if (texUnit
->TexGenEnabled
) {
3067 if (texUnit
->TexGenEnabled
& S_BIT
) {
3068 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3070 if (texUnit
->TexGenEnabled
& T_BIT
) {
3071 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3073 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3074 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3076 if (texUnit
->TexGenEnabled
& R_BIT
) {
3077 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3080 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3081 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3084 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3085 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3088 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3089 /* Fragment programs may need texture coordinates but not the
3090 * corresponding texture images.
3092 if (ctx
->FragmentProgram
._Enabled
) {
3093 ctx
->Texture
._EnabledCoordUnits
|=
3094 (ctx
->FragmentProgram
.Current
->InputsRead
>> FRAG_ATTRIB_TEX0
);
3099 void _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3101 if (new_state
& _NEW_TEXTURE_MATRIX
)
3102 update_texture_matrices( ctx
);
3104 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3105 update_texture_state( ctx
);
3108 /**********************************************************************/
3109 /***** Initialization *****/
3110 /**********************************************************************/
3113 * Allocate the proxy textures for the given context.
3115 * \param ctx the context to allocate proxies for.
3117 * \return GL_TRUE on success, or GL_FALSE on failure
3119 * If run out of memory part way through the allocations, clean up and return
3123 alloc_proxy_textures( GLcontext
*ctx
)
3125 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
3126 if (!ctx
->Texture
.Proxy1D
)
3129 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
3130 if (!ctx
->Texture
.Proxy2D
)
3133 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
3134 if (!ctx
->Texture
.Proxy3D
)
3137 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
3138 if (!ctx
->Texture
.ProxyCubeMap
)
3141 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
3142 if (!ctx
->Texture
.ProxyRect
)
3148 if (ctx
->Texture
.Proxy1D
)
3149 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3150 if (ctx
->Texture
.Proxy2D
)
3151 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3152 if (ctx
->Texture
.Proxy3D
)
3153 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3154 if (ctx
->Texture
.ProxyCubeMap
)
3155 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3156 if (ctx
->Texture
.ProxyRect
)
3157 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3163 * Initialize a texture unit.
3165 * \param ctx GL context.
3166 * \param unit texture unit number to be initialized.
3169 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3171 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3173 texUnit
->EnvMode
= GL_MODULATE
;
3174 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3176 texUnit
->Combine
= default_combine_state
;
3177 texUnit
->_EnvMode
= default_combine_state
;
3178 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3180 texUnit
->TexGenEnabled
= 0;
3181 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3182 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3183 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3184 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3185 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3186 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3187 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3188 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3190 /* Yes, these plane coefficients are correct! */
3191 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3192 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3193 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3194 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3195 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3196 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3197 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3198 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3200 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
3201 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
3202 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
3203 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
3204 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
3208 GLboolean
_mesa_init_texture( GLcontext
* ctx
)
3212 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3213 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3215 /* Effectively bind the default textures to all texture units */
3216 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
3217 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
3218 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
3219 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
3220 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
3223 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3224 ctx
->Texture
._EnabledUnits
= 0;
3225 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
3226 init_texture_unit( ctx
, i
);
3227 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3228 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3230 /* Allocate proxy textures */
3231 if (!alloc_proxy_textures( ctx
))
3237 void _mesa_free_texture_data( GLcontext
*ctx
)
3241 /* Free proxy texture objects */
3242 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3243 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3244 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3245 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3246 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3248 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
3249 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);