2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 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
;
259 case GL_LUMINANCE_ALPHA
:
262 state
->SourceRGB
[2] = GL_TEXTURE
;
263 state
->SourceA
[2] = GL_TEXTURE
;
264 state
->SourceRGB
[0] = GL_CONSTANT
;
265 state
->OperandRGB
[2] = GL_SRC_COLOR
;
271 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
272 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
277 "Invalid texture env mode in calculate_derived_texenv");
281 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
282 ? mode_rgb
: GL_REPLACE
;
283 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
284 ? mode_a
: GL_REPLACE
;
289 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
291 GET_CURRENT_CONTEXT(ctx
);
292 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
293 ASSERT_OUTSIDE_BEGIN_END(ctx
);
295 #define TE_ERROR(errCode, msg, value) \
296 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
298 if (target
== GL_TEXTURE_ENV
) {
300 case GL_TEXTURE_ENV_MODE
:
302 const GLenum mode
= (GLenum
) (GLint
) *param
;
303 if (mode
== GL_MODULATE
||
306 mode
== GL_REPLACE
||
307 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
308 (mode
== GL_COMBINE
&&
309 (ctx
->Extensions
.EXT_texture_env_combine
||
310 ctx
->Extensions
.ARB_texture_env_combine
))) {
312 if (texUnit
->EnvMode
== mode
)
314 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
315 texUnit
->EnvMode
= mode
;
317 /* FIXME: Is this needed here or is having it in
318 * FIXME: update_texture_state enough?
320 if ( mode
== GL_COMBINE
) {
321 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
323 else if ( texUnit
->_Current
!= NULL
) {
324 calculate_derived_texenv( & texUnit
->_EnvMode
, mode
,
325 texUnit
->_Current
->Image
[0][0]->Format
);
326 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
330 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
335 case GL_TEXTURE_ENV_COLOR
:
338 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
339 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
340 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
341 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
342 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
344 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
345 COPY_4FV(texUnit
->EnvColor
, tmp
);
349 if (ctx
->Extensions
.EXT_texture_env_combine
||
350 ctx
->Extensions
.ARB_texture_env_combine
) {
351 const GLenum mode
= (GLenum
) (GLint
) *param
;
361 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
362 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
366 case GL_DOT3_RGB_EXT
:
367 case GL_DOT3_RGBA_EXT
:
368 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
369 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
375 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
376 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
380 case GL_MODULATE_ADD_ATI
:
381 case GL_MODULATE_SIGNED_ADD_ATI
:
382 case GL_MODULATE_SUBTRACT_ATI
:
383 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
384 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
389 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
392 if (texUnit
->Combine
.ModeRGB
== mode
)
394 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
395 texUnit
->Combine
.ModeRGB
= mode
;
398 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
402 case GL_COMBINE_ALPHA
:
403 if (ctx
->Extensions
.EXT_texture_env_combine
||
404 ctx
->Extensions
.ARB_texture_env_combine
) {
405 const GLenum mode
= (GLenum
) (GLint
) *param
;
415 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
416 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
420 case GL_MODULATE_ADD_ATI
:
421 case GL_MODULATE_SIGNED_ADD_ATI
:
422 case GL_MODULATE_SUBTRACT_ATI
:
423 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
424 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
429 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
433 if (texUnit
->Combine
.ModeA
== mode
)
435 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
436 texUnit
->Combine
.ModeA
= mode
;
439 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
446 if (ctx
->Extensions
.EXT_texture_env_combine
||
447 ctx
->Extensions
.ARB_texture_env_combine
) {
448 const GLenum source
= (GLenum
) (GLint
) *param
;
449 const GLuint s
= pname
- GL_SOURCE0_RGB
;
450 if (source
== GL_TEXTURE
||
451 source
== GL_CONSTANT
||
452 source
== GL_PRIMARY_COLOR
||
453 source
== GL_PREVIOUS
||
454 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
455 source
>= GL_TEXTURE0
&&
456 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
457 (ctx
->Extensions
.ATI_texture_env_combine3
&&
458 (source
== GL_ZERO
|| source
== GL_ONE
))) {
460 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
462 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
463 texUnit
->Combine
.SourceRGB
[s
] = source
;
466 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
471 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
475 case GL_SOURCE0_ALPHA
:
476 case GL_SOURCE1_ALPHA
:
477 case GL_SOURCE2_ALPHA
:
478 if (ctx
->Extensions
.EXT_texture_env_combine
||
479 ctx
->Extensions
.ARB_texture_env_combine
) {
480 const GLenum source
= (GLenum
) (GLint
) *param
;
481 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
482 if (source
== GL_TEXTURE
||
483 source
== GL_CONSTANT
||
484 source
== GL_PRIMARY_COLOR
||
485 source
== GL_PREVIOUS
||
486 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
487 source
>= GL_TEXTURE0
&&
488 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
489 (ctx
->Extensions
.ATI_texture_env_combine3
&&
490 (source
== GL_ZERO
|| source
== GL_ONE
))) {
492 if (texUnit
->Combine
.SourceA
[s
] == source
)
494 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
495 texUnit
->Combine
.SourceA
[s
] = source
;
498 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
503 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
507 case GL_OPERAND0_RGB
:
508 case GL_OPERAND1_RGB
:
509 if (ctx
->Extensions
.EXT_texture_env_combine
||
510 ctx
->Extensions
.ARB_texture_env_combine
) {
511 const GLenum operand
= (GLenum
) (GLint
) *param
;
512 const GLuint s
= pname
- GL_OPERAND0_RGB
;
515 case GL_ONE_MINUS_SRC_COLOR
:
517 case GL_ONE_MINUS_SRC_ALPHA
:
518 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
520 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
521 texUnit
->Combine
.OperandRGB
[s
] = operand
;
524 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
529 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
533 case GL_OPERAND0_ALPHA
:
534 case GL_OPERAND1_ALPHA
:
535 if (ctx
->Extensions
.EXT_texture_env_combine
||
536 ctx
->Extensions
.ARB_texture_env_combine
) {
537 const GLenum operand
= (GLenum
) (GLint
) *param
;
540 case GL_ONE_MINUS_SRC_ALPHA
:
541 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] ==
544 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
545 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
548 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
553 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
557 case GL_OPERAND2_RGB
:
558 if (ctx
->Extensions
.EXT_texture_env_combine
||
559 ctx
->Extensions
.ARB_texture_env_combine
) {
560 const GLenum operand
= (GLenum
) (GLint
) *param
;
562 case GL_SRC_COLOR
: /* ARB combine only */
563 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
565 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
566 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
568 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
569 texUnit
->Combine
.OperandRGB
[2] = operand
;
572 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
577 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
581 case GL_OPERAND2_ALPHA
:
582 if (ctx
->Extensions
.EXT_texture_env_combine
||
583 ctx
->Extensions
.ARB_texture_env_combine
) {
584 const GLenum operand
= (GLenum
) (GLint
) *param
;
587 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
588 if (texUnit
->Combine
.OperandA
[2] == operand
)
590 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
591 texUnit
->Combine
.OperandA
[2] = operand
;
594 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
599 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
604 if (ctx
->Extensions
.EXT_texture_env_combine
||
605 ctx
->Extensions
.ARB_texture_env_combine
) {
610 else if (*param
== 2.0) {
613 else if (*param
== 4.0) {
617 _mesa_error( ctx
, GL_INVALID_VALUE
,
618 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
621 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
623 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
624 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
627 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
632 if (ctx
->Extensions
.EXT_texture_env_combine
||
633 ctx
->Extensions
.ARB_texture_env_combine
) {
638 else if (*param
== 2.0) {
641 else if (*param
== 4.0) {
645 _mesa_error( ctx
, GL_INVALID_VALUE
,
646 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
649 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
651 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
652 texUnit
->Combine
.ScaleShiftA
= newshift
;
655 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
660 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
664 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
665 /* GL_EXT_texture_lod_bias */
666 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
667 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
670 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
671 if (texUnit
->LodBias
== param
[0])
673 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
674 texUnit
->LodBias
= param
[0];
677 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
681 else if (target
== GL_POINT_SPRITE_NV
) {
682 /* GL_ARB_point_sprite / GL_NV_point_sprite */
683 if (!ctx
->Extensions
.NV_point_sprite
684 && !ctx
->Extensions
.ARB_point_sprite
) {
685 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
688 if (pname
== GL_COORD_REPLACE_NV
) {
689 const GLenum value
= (GLenum
) param
[0];
690 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
691 /* It's kind of weird to set point state via glTexEnv,
692 * but that's what the spec calls for.
694 const GLboolean state
= (GLboolean
) value
;
695 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
697 FLUSH_VERTICES(ctx
, _NEW_POINT
);
698 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
701 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
706 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
715 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
716 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
717 _mesa_lookup_enum_by_nr(target
),
718 _mesa_lookup_enum_by_nr(pname
),
720 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
722 /* Tell device driver about the new texture environment */
723 if (ctx
->Driver
.TexEnv
) {
724 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
730 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
732 _mesa_TexEnvfv( target
, pname
, ¶m
);
738 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
741 p
[0] = (GLfloat
) param
;
742 p
[1] = p
[2] = p
[3] = 0.0;
743 _mesa_TexEnvfv( target
, pname
, p
);
748 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
751 if (pname
== GL_TEXTURE_ENV_COLOR
) {
752 p
[0] = INT_TO_FLOAT( param
[0] );
753 p
[1] = INT_TO_FLOAT( param
[1] );
754 p
[2] = INT_TO_FLOAT( param
[2] );
755 p
[3] = INT_TO_FLOAT( param
[3] );
758 p
[0] = (GLfloat
) param
[0];
759 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
761 _mesa_TexEnvfv( target
, pname
, p
);
766 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
768 GET_CURRENT_CONTEXT(ctx
);
769 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
770 ASSERT_OUTSIDE_BEGIN_END(ctx
);
772 if (target
== GL_TEXTURE_ENV
) {
774 case GL_TEXTURE_ENV_MODE
:
775 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
777 case GL_TEXTURE_ENV_COLOR
:
778 COPY_4FV( params
, texUnit
->EnvColor
);
781 if (ctx
->Extensions
.EXT_texture_env_combine
||
782 ctx
->Extensions
.ARB_texture_env_combine
) {
783 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
786 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
789 case GL_COMBINE_ALPHA
:
790 if (ctx
->Extensions
.EXT_texture_env_combine
||
791 ctx
->Extensions
.ARB_texture_env_combine
) {
792 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
795 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
799 if (ctx
->Extensions
.EXT_texture_env_combine
||
800 ctx
->Extensions
.ARB_texture_env_combine
) {
801 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[0];
804 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
808 if (ctx
->Extensions
.EXT_texture_env_combine
||
809 ctx
->Extensions
.ARB_texture_env_combine
) {
810 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[1];
813 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
817 if (ctx
->Extensions
.EXT_texture_env_combine
||
818 ctx
->Extensions
.ARB_texture_env_combine
) {
819 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[2];
822 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
825 case GL_SOURCE0_ALPHA
:
826 if (ctx
->Extensions
.EXT_texture_env_combine
||
827 ctx
->Extensions
.ARB_texture_env_combine
) {
828 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[0];
831 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
834 case GL_SOURCE1_ALPHA
:
835 if (ctx
->Extensions
.EXT_texture_env_combine
||
836 ctx
->Extensions
.ARB_texture_env_combine
) {
837 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[1];
840 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
843 case GL_SOURCE2_ALPHA
:
844 if (ctx
->Extensions
.EXT_texture_env_combine
||
845 ctx
->Extensions
.ARB_texture_env_combine
) {
846 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[2];
849 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
852 case GL_OPERAND0_RGB
:
853 if (ctx
->Extensions
.EXT_texture_env_combine
||
854 ctx
->Extensions
.ARB_texture_env_combine
) {
855 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[0];
858 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
861 case GL_OPERAND1_RGB
:
862 if (ctx
->Extensions
.EXT_texture_env_combine
||
863 ctx
->Extensions
.ARB_texture_env_combine
) {
864 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[1];
867 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
870 case GL_OPERAND2_RGB
:
871 if (ctx
->Extensions
.EXT_texture_env_combine
||
872 ctx
->Extensions
.ARB_texture_env_combine
) {
873 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[2];
876 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
879 case GL_OPERAND0_ALPHA
:
880 if (ctx
->Extensions
.EXT_texture_env_combine
||
881 ctx
->Extensions
.ARB_texture_env_combine
) {
882 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[0];
885 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
888 case GL_OPERAND1_ALPHA
:
889 if (ctx
->Extensions
.EXT_texture_env_combine
||
890 ctx
->Extensions
.ARB_texture_env_combine
) {
891 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[1];
894 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
897 case GL_OPERAND2_ALPHA
:
898 if (ctx
->Extensions
.EXT_texture_env_combine
||
899 ctx
->Extensions
.ARB_texture_env_combine
) {
900 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[2];
903 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
907 if (ctx
->Extensions
.EXT_texture_env_combine
||
908 ctx
->Extensions
.ARB_texture_env_combine
) {
909 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
911 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
917 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
922 if (ctx
->Extensions
.EXT_texture_env_combine
||
923 ctx
->Extensions
.ARB_texture_env_combine
) {
924 if (texUnit
->Combine
.ScaleShiftA
== 0)
926 else if (texUnit
->Combine
.ScaleShiftA
== 1)
932 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
937 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
940 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
941 /* GL_EXT_texture_lod_bias */
942 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
943 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
946 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
947 *params
= texUnit
->LodBias
;
950 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
954 else if (target
== GL_POINT_SPRITE_NV
) {
955 /* GL_ARB_point_sprite / GL_NV_point_sprite */
956 if (!ctx
->Extensions
.NV_point_sprite
957 && !ctx
->Extensions
.ARB_point_sprite
) {
958 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
961 if (pname
== GL_COORD_REPLACE_NV
) {
962 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
965 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
970 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
977 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
979 GET_CURRENT_CONTEXT(ctx
);
980 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
981 ASSERT_OUTSIDE_BEGIN_END(ctx
);
983 if (target
== GL_TEXTURE_ENV
) {
985 case GL_TEXTURE_ENV_MODE
:
986 *params
= (GLint
) texUnit
->EnvMode
;
988 case GL_TEXTURE_ENV_COLOR
:
989 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
990 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
991 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
992 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
995 if (ctx
->Extensions
.EXT_texture_env_combine
||
996 ctx
->Extensions
.ARB_texture_env_combine
) {
997 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
1000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1003 case GL_COMBINE_ALPHA
:
1004 if (ctx
->Extensions
.EXT_texture_env_combine
||
1005 ctx
->Extensions
.ARB_texture_env_combine
) {
1006 *params
= (GLint
) texUnit
->Combine
.ModeA
;
1009 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1012 case GL_SOURCE0_RGB
:
1013 if (ctx
->Extensions
.EXT_texture_env_combine
||
1014 ctx
->Extensions
.ARB_texture_env_combine
) {
1015 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[0];
1018 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1021 case GL_SOURCE1_RGB
:
1022 if (ctx
->Extensions
.EXT_texture_env_combine
||
1023 ctx
->Extensions
.ARB_texture_env_combine
) {
1024 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[1];
1027 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1030 case GL_SOURCE2_RGB
:
1031 if (ctx
->Extensions
.EXT_texture_env_combine
||
1032 ctx
->Extensions
.ARB_texture_env_combine
) {
1033 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[2];
1036 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1039 case GL_SOURCE0_ALPHA
:
1040 if (ctx
->Extensions
.EXT_texture_env_combine
||
1041 ctx
->Extensions
.ARB_texture_env_combine
) {
1042 *params
= (GLint
) texUnit
->Combine
.SourceA
[0];
1045 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1048 case GL_SOURCE1_ALPHA
:
1049 if (ctx
->Extensions
.EXT_texture_env_combine
||
1050 ctx
->Extensions
.ARB_texture_env_combine
) {
1051 *params
= (GLint
) texUnit
->Combine
.SourceA
[1];
1054 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1057 case GL_SOURCE2_ALPHA
:
1058 if (ctx
->Extensions
.EXT_texture_env_combine
||
1059 ctx
->Extensions
.ARB_texture_env_combine
) {
1060 *params
= (GLint
) texUnit
->Combine
.SourceA
[2];
1063 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1066 case GL_OPERAND0_RGB
:
1067 if (ctx
->Extensions
.EXT_texture_env_combine
||
1068 ctx
->Extensions
.ARB_texture_env_combine
) {
1069 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[0];
1072 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1075 case GL_OPERAND1_RGB
:
1076 if (ctx
->Extensions
.EXT_texture_env_combine
||
1077 ctx
->Extensions
.ARB_texture_env_combine
) {
1078 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[1];
1081 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1084 case GL_OPERAND2_RGB
:
1085 if (ctx
->Extensions
.EXT_texture_env_combine
||
1086 ctx
->Extensions
.ARB_texture_env_combine
) {
1087 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[2];
1090 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1093 case GL_OPERAND0_ALPHA
:
1094 if (ctx
->Extensions
.EXT_texture_env_combine
||
1095 ctx
->Extensions
.ARB_texture_env_combine
) {
1096 *params
= (GLint
) texUnit
->Combine
.OperandA
[0];
1099 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1102 case GL_OPERAND1_ALPHA
:
1103 if (ctx
->Extensions
.EXT_texture_env_combine
||
1104 ctx
->Extensions
.ARB_texture_env_combine
) {
1105 *params
= (GLint
) texUnit
->Combine
.OperandA
[1];
1108 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1111 case GL_OPERAND2_ALPHA
:
1112 if (ctx
->Extensions
.EXT_texture_env_combine
||
1113 ctx
->Extensions
.ARB_texture_env_combine
) {
1114 *params
= (GLint
) texUnit
->Combine
.OperandA
[2];
1117 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1121 if (ctx
->Extensions
.EXT_texture_env_combine
||
1122 ctx
->Extensions
.ARB_texture_env_combine
) {
1123 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1125 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1131 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1135 case GL_ALPHA_SCALE
:
1136 if (ctx
->Extensions
.EXT_texture_env_combine
||
1137 ctx
->Extensions
.ARB_texture_env_combine
) {
1138 if (texUnit
->Combine
.ScaleShiftA
== 0)
1140 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1146 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1151 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1155 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1156 /* GL_EXT_texture_lod_bias */
1157 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1158 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1161 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1162 *params
= (GLint
) texUnit
->LodBias
;
1165 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1169 else if (target
== GL_POINT_SPRITE_NV
) {
1170 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1171 if (!ctx
->Extensions
.NV_point_sprite
1172 && !ctx
->Extensions
.ARB_point_sprite
) {
1173 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1176 if (pname
== GL_COORD_REPLACE_NV
) {
1177 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1180 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1185 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1193 /**********************************************************************/
1194 /* Texture Parameters */
1195 /**********************************************************************/
1198 _mesa_validate_texture_wrap_mode(GLcontext
* ctx
,
1199 GLenum target
, GLenum eparam
)
1201 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1203 if (eparam
== GL_CLAMP
|| eparam
== GL_CLAMP_TO_EDGE
||
1204 (eparam
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1205 /* any texture target */
1208 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1209 (eparam
== GL_REPEAT
||
1210 (eparam
== GL_MIRRORED_REPEAT
&&
1211 e
->ARB_texture_mirrored_repeat
) ||
1212 (eparam
== GL_MIRROR_CLAMP_EXT
&&
1213 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1214 (eparam
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1215 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1216 (eparam
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1217 (e
->EXT_texture_mirror_clamp
)))) {
1218 /* non-rectangle texture */
1222 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1228 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1230 _mesa_TexParameterfv(target
, pname
, ¶m
);
1235 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1237 GET_CURRENT_CONTEXT(ctx
);
1238 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1239 GLenum eparam
= (GLenum
) (GLint
) params
[0];
1240 struct gl_texture_object
*texObj
;
1241 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1243 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1244 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1245 _mesa_lookup_enum_by_nr(target
),
1246 _mesa_lookup_enum_by_nr(pname
),
1248 _mesa_lookup_enum_by_nr(eparam
));
1253 texObj
= texUnit
->Current1D
;
1256 texObj
= texUnit
->Current2D
;
1259 texObj
= texUnit
->Current3D
;
1261 case GL_TEXTURE_CUBE_MAP
:
1262 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1263 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1266 texObj
= texUnit
->CurrentCubeMap
;
1268 case GL_TEXTURE_RECTANGLE_NV
:
1269 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1270 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1273 texObj
= texUnit
->CurrentRect
;
1276 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1281 case GL_TEXTURE_MIN_FILTER
:
1282 /* A small optimization */
1283 if (texObj
->MinFilter
== eparam
)
1285 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1286 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1287 texObj
->MinFilter
= eparam
;
1289 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1290 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1291 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1292 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1293 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1294 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1295 texObj
->MinFilter
= eparam
;
1298 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1302 case GL_TEXTURE_MAG_FILTER
:
1303 /* A small optimization */
1304 if (texObj
->MagFilter
== eparam
)
1307 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1308 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1309 texObj
->MagFilter
= eparam
;
1312 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1316 case GL_TEXTURE_WRAP_S
:
1317 if (texObj
->WrapS
== eparam
)
1319 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1320 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1321 texObj
->WrapS
= eparam
;
1327 case GL_TEXTURE_WRAP_T
:
1328 if (texObj
->WrapT
== eparam
)
1330 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1331 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1332 texObj
->WrapT
= eparam
;
1338 case GL_TEXTURE_WRAP_R
:
1339 if (texObj
->WrapR
== eparam
)
1341 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1342 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1343 texObj
->WrapR
= eparam
;
1349 case GL_TEXTURE_BORDER_COLOR
:
1350 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1351 texObj
->BorderColor
[RCOMP
] = params
[0];
1352 texObj
->BorderColor
[GCOMP
] = params
[1];
1353 texObj
->BorderColor
[BCOMP
] = params
[2];
1354 texObj
->BorderColor
[ACOMP
] = params
[3];
1355 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1356 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1357 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1358 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1360 case GL_TEXTURE_MIN_LOD
:
1361 if (texObj
->MinLod
== params
[0])
1363 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1364 texObj
->MinLod
= params
[0];
1366 case GL_TEXTURE_MAX_LOD
:
1367 if (texObj
->MaxLod
== params
[0])
1369 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1370 texObj
->MaxLod
= params
[0];
1372 case GL_TEXTURE_BASE_LEVEL
:
1373 if (params
[0] < 0.0) {
1374 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1377 if (target
== GL_TEXTURE_RECTANGLE_NV
&& params
[0] != 0.0) {
1378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1381 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1382 texObj
->BaseLevel
= (GLint
) params
[0];
1384 case GL_TEXTURE_MAX_LEVEL
:
1385 if (params
[0] < 0.0) {
1386 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1389 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1390 texObj
->MaxLevel
= (GLint
) params
[0];
1392 case GL_TEXTURE_PRIORITY
:
1393 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1394 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1396 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1397 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1398 if (params
[0] < 1.0) {
1399 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1402 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1403 texObj
->MaxAnisotropy
= params
[0];
1406 _mesa_error(ctx
, GL_INVALID_ENUM
,
1407 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1411 case GL_TEXTURE_COMPARE_SGIX
:
1412 if (ctx
->Extensions
.SGIX_shadow
) {
1413 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1414 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1417 _mesa_error(ctx
, GL_INVALID_ENUM
,
1418 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1422 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1423 if (ctx
->Extensions
.SGIX_shadow
) {
1424 GLenum op
= (GLenum
) params
[0];
1425 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1426 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1427 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1428 texObj
->CompareOperator
= op
;
1431 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1435 _mesa_error(ctx
, GL_INVALID_ENUM
,
1436 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1440 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1441 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1442 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1443 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1446 _mesa_error(ctx
, GL_INVALID_ENUM
,
1447 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1451 case GL_GENERATE_MIPMAP_SGIS
:
1452 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1453 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1456 _mesa_error(ctx
, GL_INVALID_ENUM
,
1457 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1461 case GL_TEXTURE_COMPARE_MODE_ARB
:
1462 if (ctx
->Extensions
.ARB_shadow
) {
1463 const GLenum mode
= (GLenum
) params
[0];
1464 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1465 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1466 texObj
->CompareMode
= mode
;
1469 _mesa_error(ctx
, GL_INVALID_ENUM
,
1470 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1475 _mesa_error(ctx
, GL_INVALID_ENUM
,
1476 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1480 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1481 if (ctx
->Extensions
.ARB_shadow
) {
1482 const GLenum func
= (GLenum
) params
[0];
1483 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1484 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1485 texObj
->CompareFunc
= func
;
1487 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1488 (func
== GL_EQUAL
||
1489 func
== GL_NOTEQUAL
||
1491 func
== GL_GREATER
||
1492 func
== GL_ALWAYS
||
1493 func
== GL_NEVER
)) {
1494 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1495 texObj
->CompareFunc
= func
;
1498 _mesa_error(ctx
, GL_INVALID_ENUM
,
1499 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1504 _mesa_error(ctx
, GL_INVALID_ENUM
,
1505 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1509 case GL_DEPTH_TEXTURE_MODE_ARB
:
1510 if (ctx
->Extensions
.ARB_depth_texture
) {
1511 const GLenum result
= (GLenum
) params
[0];
1512 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1513 || result
== GL_ALPHA
) {
1514 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1515 texObj
->DepthMode
= result
;
1518 _mesa_error(ctx
, GL_INVALID_ENUM
,
1519 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1524 _mesa_error(ctx
, GL_INVALID_ENUM
,
1525 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1529 case GL_TEXTURE_LOD_BIAS
:
1530 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1531 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1532 if (texObj
->LodBias
!= params
[0]) {
1533 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1534 texObj
->LodBias
= params
[0];
1540 _mesa_error(ctx
, GL_INVALID_ENUM
,
1541 "glTexParameter(pname=0x%x)", pname
);
1545 texObj
->Complete
= GL_FALSE
;
1547 if (ctx
->Driver
.TexParameter
) {
1548 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1554 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1557 if (pname
== GL_TEXTURE_PRIORITY
)
1558 fparam
[0] = INT_TO_FLOAT(param
);
1560 fparam
[0] = (GLfloat
) param
;
1561 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1562 _mesa_TexParameterfv(target
, pname
, fparam
);
1567 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1570 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1571 fparam
[0] = INT_TO_FLOAT(params
[0]);
1572 fparam
[1] = INT_TO_FLOAT(params
[1]);
1573 fparam
[2] = INT_TO_FLOAT(params
[2]);
1574 fparam
[3] = INT_TO_FLOAT(params
[3]);
1577 if (pname
== GL_TEXTURE_PRIORITY
)
1578 fparam
[0] = INT_TO_FLOAT(params
[0]);
1580 fparam
[0] = (GLfloat
) params
[0];
1581 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1583 _mesa_TexParameterfv(target
, pname
, fparam
);
1588 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1589 GLenum pname
, GLfloat
*params
)
1592 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1593 *params
= (GLfloat
) iparam
;
1598 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1602 case GL_PROXY_TEXTURE_1D
:
1605 case GL_PROXY_TEXTURE_2D
:
1608 case GL_PROXY_TEXTURE_3D
:
1610 case GL_TEXTURE_CUBE_MAP
:
1611 case GL_PROXY_TEXTURE_CUBE_MAP
:
1612 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1613 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1614 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1615 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1616 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1617 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1618 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1619 case GL_TEXTURE_RECTANGLE_NV
:
1620 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1621 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1623 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1630 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1631 GLenum pname
, GLint
*params
)
1633 GET_CURRENT_CONTEXT(ctx
);
1634 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1635 const struct gl_texture_image
*img
= NULL
;
1639 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1641 /* this will catch bad target values */
1642 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1643 if (dimensions
== 0) {
1644 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1650 case GL_PROXY_TEXTURE_1D
:
1652 case GL_PROXY_TEXTURE_2D
:
1653 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1656 case GL_PROXY_TEXTURE_3D
:
1657 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1659 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1660 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1661 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1662 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1663 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1664 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1665 case GL_PROXY_TEXTURE_CUBE_MAP
:
1666 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1668 case GL_TEXTURE_RECTANGLE_NV
:
1669 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1673 _mesa_problem(ctx
, "switch in _mesa_GetTexLevelParameter");
1677 if (level
< 0 || level
>= maxLevels
) {
1678 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1682 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1683 if (!img
|| !img
->TexFormat
) {
1684 /* undefined texture image */
1685 if (pname
== GL_TEXTURE_COMPONENTS
)
1692 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
1693 (target
== GL_PROXY_TEXTURE_2D
) ||
1694 (target
== GL_PROXY_TEXTURE_3D
) ||
1695 (target
== GL_PROXY_TEXTURE_CUBE_MAP
) ||
1696 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
);
1699 case GL_TEXTURE_WIDTH
:
1700 *params
= img
->Width
;
1702 case GL_TEXTURE_HEIGHT
:
1703 *params
= img
->Height
;
1705 case GL_TEXTURE_DEPTH
:
1706 *params
= img
->Depth
;
1708 case GL_TEXTURE_INTERNAL_FORMAT
:
1709 *params
= img
->IntFormat
;
1711 case GL_TEXTURE_BORDER
:
1712 *params
= img
->Border
;
1714 case GL_TEXTURE_RED_SIZE
:
1715 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1716 *params
= img
->TexFormat
->RedBits
;
1720 case GL_TEXTURE_GREEN_SIZE
:
1721 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1722 *params
= img
->TexFormat
->GreenBits
;
1726 case GL_TEXTURE_BLUE_SIZE
:
1727 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1728 *params
= img
->TexFormat
->BlueBits
;
1732 case GL_TEXTURE_ALPHA_SIZE
:
1733 if (img
->Format
== GL_ALPHA
|| img
->Format
== GL_LUMINANCE_ALPHA
||
1734 img
->Format
== GL_RGBA
)
1735 *params
= img
->TexFormat
->AlphaBits
;
1739 case GL_TEXTURE_INTENSITY_SIZE
:
1740 if (img
->Format
!= GL_INTENSITY
)
1742 else if (img
->TexFormat
->IntensityBits
> 0)
1743 *params
= img
->TexFormat
->IntensityBits
;
1744 else /* intensity probably stored as rgb texture */
1745 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1747 case GL_TEXTURE_LUMINANCE_SIZE
:
1748 if (img
->Format
!= GL_LUMINANCE
&&
1749 img
->Format
!= GL_LUMINANCE_ALPHA
)
1751 else if (img
->TexFormat
->LuminanceBits
> 0)
1752 *params
= img
->TexFormat
->LuminanceBits
;
1753 else /* luminance probably stored as rgb texture */
1754 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1756 case GL_TEXTURE_INDEX_SIZE_EXT
:
1757 if (img
->Format
== GL_COLOR_INDEX
)
1758 *params
= img
->TexFormat
->IndexBits
;
1763 /* XXX this isn't in the GL_SGIX_depth_texture spec
1764 * but seems appropriate.
1766 if (ctx
->Extensions
.SGIX_depth_texture
)
1767 *params
= img
->TexFormat
->DepthBits
;
1769 _mesa_error(ctx
, GL_INVALID_ENUM
,
1770 "glGetTexLevelParameter[if]v(pname)");
1773 /* GL_ARB_texture_compression */
1774 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1775 if (ctx
->Extensions
.ARB_texture_compression
) {
1776 if (img
->IsCompressed
&& !isProxy
)
1777 *params
= img
->CompressedSize
;
1779 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1780 "glGetTexLevelParameter[if]v(pname)");
1783 _mesa_error(ctx
, GL_INVALID_ENUM
,
1784 "glGetTexLevelParameter[if]v(pname)");
1787 case GL_TEXTURE_COMPRESSED
:
1788 if (ctx
->Extensions
.ARB_texture_compression
) {
1789 *params
= (GLint
) img
->IsCompressed
;
1792 _mesa_error(ctx
, GL_INVALID_ENUM
,
1793 "glGetTexLevelParameter[if]v(pname)");
1798 _mesa_error(ctx
, GL_INVALID_ENUM
,
1799 "glGetTexLevelParameter[if]v(pname)");
1806 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1808 GET_CURRENT_CONTEXT(ctx
);
1809 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1810 struct gl_texture_object
*obj
;
1811 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1813 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1815 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1820 case GL_TEXTURE_MAG_FILTER
:
1821 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1823 case GL_TEXTURE_MIN_FILTER
:
1824 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1826 case GL_TEXTURE_WRAP_S
:
1827 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1829 case GL_TEXTURE_WRAP_T
:
1830 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1832 case GL_TEXTURE_WRAP_R
:
1833 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1835 case GL_TEXTURE_BORDER_COLOR
:
1836 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1837 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1838 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1839 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1841 case GL_TEXTURE_RESIDENT
:
1844 if (ctx
->Driver
.IsTextureResident
)
1845 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1848 *params
= ENUM_TO_FLOAT(resident
);
1851 case GL_TEXTURE_PRIORITY
:
1852 *params
= obj
->Priority
;
1854 case GL_TEXTURE_MIN_LOD
:
1855 *params
= obj
->MinLod
;
1857 case GL_TEXTURE_MAX_LOD
:
1858 *params
= obj
->MaxLod
;
1860 case GL_TEXTURE_BASE_LEVEL
:
1861 *params
= (GLfloat
) obj
->BaseLevel
;
1863 case GL_TEXTURE_MAX_LEVEL
:
1864 *params
= (GLfloat
) obj
->MaxLevel
;
1866 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1867 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1868 *params
= obj
->MaxAnisotropy
;
1872 case GL_TEXTURE_COMPARE_SGIX
:
1873 if (ctx
->Extensions
.SGIX_shadow
) {
1874 *params
= (GLfloat
) obj
->CompareFlag
;
1878 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1879 if (ctx
->Extensions
.SGIX_shadow
) {
1880 *params
= (GLfloat
) obj
->CompareOperator
;
1884 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1885 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1886 *params
= obj
->ShadowAmbient
;
1890 case GL_GENERATE_MIPMAP_SGIS
:
1891 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1892 *params
= (GLfloat
) obj
->GenerateMipmap
;
1896 case GL_TEXTURE_COMPARE_MODE_ARB
:
1897 if (ctx
->Extensions
.ARB_shadow
) {
1898 *params
= (GLfloat
) obj
->CompareMode
;
1902 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1903 if (ctx
->Extensions
.ARB_shadow
) {
1904 *params
= (GLfloat
) obj
->CompareFunc
;
1908 case GL_DEPTH_TEXTURE_MODE_ARB
:
1909 if (ctx
->Extensions
.ARB_depth_texture
) {
1910 *params
= (GLfloat
) obj
->DepthMode
;
1914 case GL_TEXTURE_LOD_BIAS
:
1915 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1916 *params
= obj
->LodBias
;
1921 ; /* silence warnings */
1923 /* If we get here, pname was an unrecognized enum */
1924 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1930 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1932 GET_CURRENT_CONTEXT(ctx
);
1933 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1934 struct gl_texture_object
*obj
;
1935 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1937 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1939 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1944 case GL_TEXTURE_MAG_FILTER
:
1945 *params
= (GLint
) obj
->MagFilter
;
1946 case GL_TEXTURE_LOD_BIAS
:
1947 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1948 *params
= (GLint
) obj
->LodBias
;
1953 case GL_TEXTURE_MIN_FILTER
:
1954 *params
= (GLint
) obj
->MinFilter
;
1956 case GL_TEXTURE_WRAP_S
:
1957 *params
= (GLint
) obj
->WrapS
;
1959 case GL_TEXTURE_WRAP_T
:
1960 *params
= (GLint
) obj
->WrapT
;
1962 case GL_TEXTURE_WRAP_R
:
1963 *params
= (GLint
) obj
->WrapR
;
1965 case GL_TEXTURE_BORDER_COLOR
:
1968 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1969 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1970 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1971 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1972 params
[0] = FLOAT_TO_INT(b
[0]);
1973 params
[1] = FLOAT_TO_INT(b
[1]);
1974 params
[2] = FLOAT_TO_INT(b
[2]);
1975 params
[3] = FLOAT_TO_INT(b
[3]);
1978 case GL_TEXTURE_RESIDENT
:
1981 if (ctx
->Driver
.IsTextureResident
)
1982 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1985 *params
= (GLint
) resident
;
1988 case GL_TEXTURE_PRIORITY
:
1989 *params
= FLOAT_TO_INT(obj
->Priority
);
1991 case GL_TEXTURE_MIN_LOD
:
1992 *params
= (GLint
) obj
->MinLod
;
1994 case GL_TEXTURE_MAX_LOD
:
1995 *params
= (GLint
) obj
->MaxLod
;
1997 case GL_TEXTURE_BASE_LEVEL
:
1998 *params
= obj
->BaseLevel
;
2000 case GL_TEXTURE_MAX_LEVEL
:
2001 *params
= obj
->MaxLevel
;
2003 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2004 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2005 *params
= (GLint
) obj
->MaxAnisotropy
;
2009 case GL_TEXTURE_COMPARE_SGIX
:
2010 if (ctx
->Extensions
.SGIX_shadow
) {
2011 *params
= (GLint
) obj
->CompareFlag
;
2015 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2016 if (ctx
->Extensions
.SGIX_shadow
) {
2017 *params
= (GLint
) obj
->CompareOperator
;
2021 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2022 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2023 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2027 case GL_GENERATE_MIPMAP_SGIS
:
2028 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2029 *params
= (GLint
) obj
->GenerateMipmap
;
2033 case GL_TEXTURE_COMPARE_MODE_ARB
:
2034 if (ctx
->Extensions
.ARB_shadow
) {
2035 *params
= (GLint
) obj
->CompareMode
;
2039 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2040 if (ctx
->Extensions
.ARB_shadow
) {
2041 *params
= (GLint
) obj
->CompareFunc
;
2045 case GL_DEPTH_TEXTURE_MODE_ARB
:
2046 if (ctx
->Extensions
.ARB_depth_texture
) {
2047 *params
= (GLint
) obj
->DepthMode
;
2052 ; /* silence warnings */
2054 /* If we get here, pname was an unrecognized enum */
2055 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2061 /**********************************************************************/
2062 /* Texture Coord Generation */
2063 /**********************************************************************/
2067 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2069 GET_CURRENT_CONTEXT(ctx
);
2070 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2071 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2072 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2074 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2075 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2076 _mesa_lookup_enum_by_nr(coord
),
2077 _mesa_lookup_enum_by_nr(pname
),
2079 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2083 if (pname
==GL_TEXTURE_GEN_MODE
) {
2084 GLenum mode
= (GLenum
) (GLint
) *params
;
2087 case GL_OBJECT_LINEAR
:
2088 bits
= TEXGEN_OBJ_LINEAR
;
2091 bits
= TEXGEN_EYE_LINEAR
;
2093 case GL_REFLECTION_MAP_NV
:
2094 bits
= TEXGEN_REFLECTION_MAP_NV
;
2096 case GL_NORMAL_MAP_NV
:
2097 bits
= TEXGEN_NORMAL_MAP_NV
;
2100 bits
= TEXGEN_SPHERE_MAP
;
2103 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2106 if (texUnit
->GenModeS
== mode
)
2108 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2109 texUnit
->GenModeS
= mode
;
2110 texUnit
->_GenBitS
= bits
;
2112 else if (pname
==GL_OBJECT_PLANE
) {
2113 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2115 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2116 texUnit
->ObjectPlaneS
[0] = params
[0];
2117 texUnit
->ObjectPlaneS
[1] = params
[1];
2118 texUnit
->ObjectPlaneS
[2] = params
[2];
2119 texUnit
->ObjectPlaneS
[3] = params
[3];
2121 else if (pname
==GL_EYE_PLANE
) {
2124 /* Transform plane equation by the inverse modelview matrix */
2125 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2126 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2128 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2129 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2131 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2132 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2135 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2140 if (pname
==GL_TEXTURE_GEN_MODE
) {
2141 GLenum mode
= (GLenum
) (GLint
) *params
;
2144 case GL_OBJECT_LINEAR
:
2145 bitt
= TEXGEN_OBJ_LINEAR
;
2148 bitt
= TEXGEN_EYE_LINEAR
;
2150 case GL_REFLECTION_MAP_NV
:
2151 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2153 case GL_NORMAL_MAP_NV
:
2154 bitt
= TEXGEN_NORMAL_MAP_NV
;
2157 bitt
= TEXGEN_SPHERE_MAP
;
2160 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2163 if (texUnit
->GenModeT
== mode
)
2165 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2166 texUnit
->GenModeT
= mode
;
2167 texUnit
->_GenBitT
= bitt
;
2169 else if (pname
==GL_OBJECT_PLANE
) {
2170 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2172 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2173 texUnit
->ObjectPlaneT
[0] = params
[0];
2174 texUnit
->ObjectPlaneT
[1] = params
[1];
2175 texUnit
->ObjectPlaneT
[2] = params
[2];
2176 texUnit
->ObjectPlaneT
[3] = params
[3];
2178 else if (pname
==GL_EYE_PLANE
) {
2180 /* Transform plane equation by the inverse modelview matrix */
2181 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2182 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2184 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2185 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2187 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2188 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2191 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2196 if (pname
==GL_TEXTURE_GEN_MODE
) {
2197 GLenum mode
= (GLenum
) (GLint
) *params
;
2200 case GL_OBJECT_LINEAR
:
2201 bitr
= TEXGEN_OBJ_LINEAR
;
2203 case GL_REFLECTION_MAP_NV
:
2204 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2206 case GL_NORMAL_MAP_NV
:
2207 bitr
= TEXGEN_NORMAL_MAP_NV
;
2210 bitr
= TEXGEN_EYE_LINEAR
;
2213 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2216 if (texUnit
->GenModeR
== mode
)
2218 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2219 texUnit
->GenModeR
= mode
;
2220 texUnit
->_GenBitR
= bitr
;
2222 else if (pname
==GL_OBJECT_PLANE
) {
2223 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2225 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2226 texUnit
->ObjectPlaneR
[0] = params
[0];
2227 texUnit
->ObjectPlaneR
[1] = params
[1];
2228 texUnit
->ObjectPlaneR
[2] = params
[2];
2229 texUnit
->ObjectPlaneR
[3] = params
[3];
2231 else if (pname
==GL_EYE_PLANE
) {
2233 /* Transform plane equation by the inverse modelview matrix */
2234 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2235 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2237 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2238 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2240 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2241 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2244 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2249 if (pname
==GL_TEXTURE_GEN_MODE
) {
2250 GLenum mode
= (GLenum
) (GLint
) *params
;
2253 case GL_OBJECT_LINEAR
:
2254 bitq
= TEXGEN_OBJ_LINEAR
;
2257 bitq
= TEXGEN_EYE_LINEAR
;
2260 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2263 if (texUnit
->GenModeQ
== mode
)
2265 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2266 texUnit
->GenModeQ
= mode
;
2267 texUnit
->_GenBitQ
= bitq
;
2269 else if (pname
==GL_OBJECT_PLANE
) {
2270 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2272 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2273 texUnit
->ObjectPlaneQ
[0] = params
[0];
2274 texUnit
->ObjectPlaneQ
[1] = params
[1];
2275 texUnit
->ObjectPlaneQ
[2] = params
[2];
2276 texUnit
->ObjectPlaneQ
[3] = params
[3];
2278 else if (pname
==GL_EYE_PLANE
) {
2280 /* Transform plane equation by the inverse modelview matrix */
2281 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2282 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2284 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2285 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2287 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2288 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2291 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2296 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2300 if (ctx
->Driver
.TexGen
)
2301 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2306 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2309 p
[0] = (GLfloat
) params
[0];
2310 if (pname
== GL_TEXTURE_GEN_MODE
) {
2311 p
[1] = p
[2] = p
[3] = 0.0F
;
2314 p
[1] = (GLfloat
) params
[1];
2315 p
[2] = (GLfloat
) params
[2];
2316 p
[3] = (GLfloat
) params
[3];
2318 _mesa_TexGenfv(coord
, pname
, p
);
2323 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2325 GLfloat p
= (GLfloat
) param
;
2326 _mesa_TexGenfv( coord
, pname
, &p
);
2331 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2334 p
[0] = (GLfloat
) params
[0];
2335 if (pname
== GL_TEXTURE_GEN_MODE
) {
2336 p
[1] = p
[2] = p
[3] = 0.0F
;
2339 p
[1] = (GLfloat
) params
[1];
2340 p
[2] = (GLfloat
) params
[2];
2341 p
[3] = (GLfloat
) params
[3];
2343 _mesa_TexGenfv( coord
, pname
, p
);
2348 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2350 _mesa_TexGenfv(coord
, pname
, ¶m
);
2355 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2357 _mesa_TexGeniv( coord
, pname
, ¶m
);
2363 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2365 GET_CURRENT_CONTEXT(ctx
);
2366 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2367 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2368 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2372 if (pname
==GL_TEXTURE_GEN_MODE
) {
2373 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2375 else if (pname
==GL_OBJECT_PLANE
) {
2376 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2378 else if (pname
==GL_EYE_PLANE
) {
2379 COPY_4V( params
, texUnit
->EyePlaneS
);
2382 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2387 if (pname
==GL_TEXTURE_GEN_MODE
) {
2388 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2390 else if (pname
==GL_OBJECT_PLANE
) {
2391 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2393 else if (pname
==GL_EYE_PLANE
) {
2394 COPY_4V( params
, texUnit
->EyePlaneT
);
2397 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2402 if (pname
==GL_TEXTURE_GEN_MODE
) {
2403 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2405 else if (pname
==GL_OBJECT_PLANE
) {
2406 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2408 else if (pname
==GL_EYE_PLANE
) {
2409 COPY_4V( params
, texUnit
->EyePlaneR
);
2412 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2417 if (pname
==GL_TEXTURE_GEN_MODE
) {
2418 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2420 else if (pname
==GL_OBJECT_PLANE
) {
2421 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2423 else if (pname
==GL_EYE_PLANE
) {
2424 COPY_4V( params
, texUnit
->EyePlaneQ
);
2427 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2432 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2440 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2442 GET_CURRENT_CONTEXT(ctx
);
2443 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2444 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2445 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2449 if (pname
==GL_TEXTURE_GEN_MODE
) {
2450 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2452 else if (pname
==GL_OBJECT_PLANE
) {
2453 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2455 else if (pname
==GL_EYE_PLANE
) {
2456 COPY_4V( params
, texUnit
->EyePlaneS
);
2459 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2464 if (pname
==GL_TEXTURE_GEN_MODE
) {
2465 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2467 else if (pname
==GL_OBJECT_PLANE
) {
2468 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2470 else if (pname
==GL_EYE_PLANE
) {
2471 COPY_4V( params
, texUnit
->EyePlaneT
);
2474 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2479 if (pname
==GL_TEXTURE_GEN_MODE
) {
2480 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2482 else if (pname
==GL_OBJECT_PLANE
) {
2483 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2485 else if (pname
==GL_EYE_PLANE
) {
2486 COPY_4V( params
, texUnit
->EyePlaneR
);
2489 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2494 if (pname
==GL_TEXTURE_GEN_MODE
) {
2495 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2497 else if (pname
==GL_OBJECT_PLANE
) {
2498 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2500 else if (pname
==GL_EYE_PLANE
) {
2501 COPY_4V( params
, texUnit
->EyePlaneQ
);
2504 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2509 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2517 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2519 GET_CURRENT_CONTEXT(ctx
);
2520 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2521 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2522 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2526 if (pname
==GL_TEXTURE_GEN_MODE
) {
2527 params
[0] = texUnit
->GenModeS
;
2529 else if (pname
==GL_OBJECT_PLANE
) {
2530 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2531 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2532 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2533 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2535 else if (pname
==GL_EYE_PLANE
) {
2536 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2537 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2538 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2539 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2542 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2547 if (pname
==GL_TEXTURE_GEN_MODE
) {
2548 params
[0] = texUnit
->GenModeT
;
2550 else if (pname
==GL_OBJECT_PLANE
) {
2551 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2552 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2553 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2554 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2556 else if (pname
==GL_EYE_PLANE
) {
2557 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2558 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2559 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2560 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2563 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2568 if (pname
==GL_TEXTURE_GEN_MODE
) {
2569 params
[0] = texUnit
->GenModeR
;
2571 else if (pname
==GL_OBJECT_PLANE
) {
2572 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2573 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2574 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2575 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2577 else if (pname
==GL_EYE_PLANE
) {
2578 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2579 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2580 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2581 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2584 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2589 if (pname
==GL_TEXTURE_GEN_MODE
) {
2590 params
[0] = texUnit
->GenModeQ
;
2592 else if (pname
==GL_OBJECT_PLANE
) {
2593 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2594 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2595 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2596 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2598 else if (pname
==GL_EYE_PLANE
) {
2599 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2600 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2601 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2602 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2605 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2610 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2616 /* GL_ARB_multitexture */
2618 _mesa_ActiveTextureARB( GLenum target
)
2620 GET_CURRENT_CONTEXT(ctx
);
2621 const GLuint texUnit
= target
- GL_TEXTURE0
;
2622 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2624 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2625 _mesa_debug(ctx
, "glActiveTexture %s\n",
2626 _mesa_lookup_enum_by_nr(target
));
2628 /* Cater for texture unit 0 is first, therefore use >= */
2629 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2630 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(target)");
2634 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2637 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2639 ctx
->Texture
.CurrentUnit
= texUnit
;
2640 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2641 /* update current stack pointer */
2642 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2645 if (ctx
->Driver
.ActiveTexture
) {
2646 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2651 /* GL_ARB_multitexture */
2653 _mesa_ClientActiveTextureARB( GLenum target
)
2655 GET_CURRENT_CONTEXT(ctx
);
2656 GLuint texUnit
= target
- GL_TEXTURE0
;
2657 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2659 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
2660 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(target)");
2664 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2665 ctx
->Array
.ActiveTexture
= texUnit
;
2670 /**********************************************************************/
2671 /* Pixel Texgen Extensions */
2672 /**********************************************************************/
2675 _mesa_PixelTexGenSGIX(GLenum mode
)
2677 GLenum newRgbSource
, newAlphaSource
;
2678 GET_CURRENT_CONTEXT(ctx
);
2679 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2683 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2684 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2687 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2688 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2691 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2692 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2695 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2696 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2699 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenSGIX(mode)");
2703 if (newRgbSource
== ctx
->Pixel
.FragmentRgbSource
&&
2704 newAlphaSource
== ctx
->Pixel
.FragmentAlphaSource
)
2707 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2708 ctx
->Pixel
.FragmentRgbSource
= newRgbSource
;
2709 ctx
->Pixel
.FragmentAlphaSource
= newAlphaSource
;
2714 _mesa_PixelTexGenParameterfSGIS(GLenum target
, GLfloat value
)
2716 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) value
);
2721 _mesa_PixelTexGenParameterfvSGIS(GLenum target
, const GLfloat
*value
)
2723 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) *value
);
2728 _mesa_PixelTexGenParameteriSGIS(GLenum target
, GLint value
)
2730 GET_CURRENT_CONTEXT(ctx
);
2731 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2733 if (value
!= GL_CURRENT_RASTER_COLOR
&& value
!= GL_PIXEL_GROUP_COLOR_SGIS
) {
2734 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(value)");
2739 case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
:
2740 if (ctx
->Pixel
.FragmentRgbSource
== (GLenum
) value
)
2742 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2743 ctx
->Pixel
.FragmentRgbSource
= (GLenum
) value
;
2745 case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
:
2746 if (ctx
->Pixel
.FragmentAlphaSource
== (GLenum
) value
)
2748 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2749 ctx
->Pixel
.FragmentAlphaSource
= (GLenum
) value
;
2752 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(target)");
2759 _mesa_PixelTexGenParameterivSGIS(GLenum target
, const GLint
*value
)
2761 _mesa_PixelTexGenParameteriSGIS(target
, *value
);
2766 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target
, GLfloat
*value
)
2768 GET_CURRENT_CONTEXT(ctx
);
2769 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2771 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2772 *value
= (GLfloat
) ctx
->Pixel
.FragmentRgbSource
;
2774 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2775 *value
= (GLfloat
) ctx
->Pixel
.FragmentAlphaSource
;
2778 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterfvSGIS(target)");
2784 _mesa_GetPixelTexGenParameterivSGIS(GLenum target
, GLint
*value
)
2786 GET_CURRENT_CONTEXT(ctx
);
2787 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2789 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2790 *value
= (GLint
) ctx
->Pixel
.FragmentRgbSource
;
2792 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2793 *value
= (GLint
) ctx
->Pixel
.FragmentAlphaSource
;
2796 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterivSGIS(target)");
2802 /**********************************************************************/
2803 /***** State management *****/
2804 /**********************************************************************/
2808 * \note This routine refers to derived texture attribute values to
2809 * compute the ENABLE_TEXMAT flags, but is only called on
2810 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2811 * flags are updated by _mesa_update_textures(), below.
2813 * \param ctx GL context.
2816 update_texture_matrices( GLcontext
*ctx
)
2820 ctx
->Texture
._TexMatEnabled
= 0;
2822 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2823 if (ctx
->TextureMatrixStack
[i
].Top
->flags
& MAT_DIRTY
) {
2824 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2826 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2827 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2828 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2830 if (ctx
->Driver
.TextureMatrix
)
2831 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2840 * \note This routine refers to derived texture matrix values to
2841 * compute the ENABLE_TEXMAT flags, but is only called on
2842 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2843 * flags are updated by _mesa_update_texture_matrices, above.
2845 * \param ctx GL context.
2848 update_texture_state( GLcontext
*ctx
)
2852 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2856 ctx
->Texture
._EnabledUnits
= 0;
2857 ctx
->Texture
._GenFlags
= 0;
2858 ctx
->Texture
._TexMatEnabled
= 0;
2859 ctx
->Texture
._TexGenEnabled
= 0;
2861 /* Update texture unit state.
2862 * XXX this loop should probably be broken into separate loops for
2863 * texture coord units and texture image units.
2865 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2866 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2869 texUnit
->_Current
= NULL
;
2870 texUnit
->_ReallyEnabled
= 0;
2871 texUnit
->_GenFlags
= 0;
2873 /* Get the bitmask of texture enables */
2874 if (ctx
->FragmentProgram
.Enabled
&& ctx
->FragmentProgram
.Current
) {
2875 enableBits
= ctx
->FragmentProgram
.Current
->TexturesUsed
[unit
];
2878 if (!texUnit
->Enabled
)
2880 enableBits
= texUnit
->Enabled
;
2883 /* Look for the highest-priority texture target that's enabled and
2884 * complete. That's the one we'll use for texturing. If we're using
2885 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2887 if (enableBits
& TEXTURE_CUBE_BIT
) {
2888 struct gl_texture_object
*texObj
= texUnit
->CurrentCubeMap
;
2889 if (!texObj
->Complete
) {
2890 _mesa_test_texobj_completeness(ctx
, texObj
);
2892 if (texObj
->Complete
) {
2893 texUnit
->_ReallyEnabled
= TEXTURE_CUBE_BIT
;
2894 texUnit
->_Current
= texObj
;
2898 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_3D_BIT
)) {
2899 struct gl_texture_object
*texObj
= texUnit
->Current3D
;
2900 if (!texObj
->Complete
) {
2901 _mesa_test_texobj_completeness(ctx
, texObj
);
2903 if (texObj
->Complete
) {
2904 texUnit
->_ReallyEnabled
= TEXTURE_3D_BIT
;
2905 texUnit
->_Current
= texObj
;
2909 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_RECT_BIT
)) {
2910 struct gl_texture_object
*texObj
= texUnit
->CurrentRect
;
2911 if (!texObj
->Complete
) {
2912 _mesa_test_texobj_completeness(ctx
, texObj
);
2914 if (texObj
->Complete
) {
2915 texUnit
->_ReallyEnabled
= TEXTURE_RECT_BIT
;
2916 texUnit
->_Current
= texObj
;
2920 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_2D_BIT
)) {
2921 struct gl_texture_object
*texObj
= texUnit
->Current2D
;
2922 if (!texObj
->Complete
) {
2923 _mesa_test_texobj_completeness(ctx
, texObj
);
2925 if (texObj
->Complete
) {
2926 texUnit
->_ReallyEnabled
= TEXTURE_2D_BIT
;
2927 texUnit
->_Current
= texObj
;
2931 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_1D_BIT
)) {
2932 struct gl_texture_object
*texObj
= texUnit
->Current1D
;
2933 if (!texObj
->Complete
) {
2934 _mesa_test_texobj_completeness(ctx
, texObj
);
2936 if (texObj
->Complete
) {
2937 texUnit
->_ReallyEnabled
= TEXTURE_1D_BIT
;
2938 texUnit
->_Current
= texObj
;
2942 if (!texUnit
->_ReallyEnabled
) {
2946 if (texUnit
->_ReallyEnabled
)
2947 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
2949 if (texUnit
->EnvMode
== GL_COMBINE
) {
2950 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
2953 GLenum format
= texUnit
->_Current
->Image
[0][0]->Format
;
2954 if (format
== GL_COLOR_INDEX
) {
2955 format
= GL_RGBA
; /* a bit of a hack */
2957 else if (format
== GL_DEPTH_COMPONENT
) {
2958 format
= texUnit
->_Current
->DepthMode
;
2960 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
2961 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
2964 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
2966 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
2974 case GL_DOT3_RGB_EXT
:
2975 case GL_DOT3_RGBA_EXT
:
2976 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
2978 case GL_INTERPOLATE
:
2979 case GL_MODULATE_ADD_ATI
:
2980 case GL_MODULATE_SIGNED_ADD_ATI
:
2981 case GL_MODULATE_SUBTRACT_ATI
:
2982 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
2985 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
2986 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
2990 switch (texUnit
->_CurrentCombine
->ModeA
) {
2992 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
2998 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
3000 case GL_INTERPOLATE
:
3001 case GL_MODULATE_ADD_ATI
:
3002 case GL_MODULATE_SIGNED_ADD_ATI
:
3003 case GL_MODULATE_SUBTRACT_ATI
:
3004 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
3007 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
3008 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
3012 if (texUnit
->TexGenEnabled
) {
3013 if (texUnit
->TexGenEnabled
& S_BIT
) {
3014 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3016 if (texUnit
->TexGenEnabled
& T_BIT
) {
3017 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3019 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3020 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3022 if (texUnit
->TexGenEnabled
& R_BIT
) {
3023 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3026 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3027 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3030 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3031 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3034 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3035 /* Fragment programs may need texture coordinates but not the
3036 * corresponding texture images.
3038 if (ctx
->FragmentProgram
.Enabled
&& ctx
->FragmentProgram
.Current
) {
3039 ctx
->Texture
._EnabledCoordUnits
|=
3040 (ctx
->FragmentProgram
.Current
->InputsRead
>> FRAG_ATTRIB_TEX0
);
3045 void _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3047 if (new_state
& _NEW_TEXTURE_MATRIX
)
3048 update_texture_matrices( ctx
);
3050 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3051 update_texture_state( ctx
);
3054 /**********************************************************************/
3055 /***** Initialization *****/
3056 /**********************************************************************/
3059 * Allocate the proxy textures for the given context.
3061 * \param ctx the context to allocate proxies for.
3063 * \return GL_TRUE on success, or GL_FALSE on failure
3065 * If run out of memory part way through the allocations, clean up and return
3069 alloc_proxy_textures( GLcontext
*ctx
)
3071 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
3072 if (!ctx
->Texture
.Proxy1D
)
3075 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
3076 if (!ctx
->Texture
.Proxy2D
)
3079 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
3080 if (!ctx
->Texture
.Proxy3D
)
3083 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
3084 if (!ctx
->Texture
.ProxyCubeMap
)
3087 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
3088 if (!ctx
->Texture
.ProxyRect
)
3094 if (ctx
->Texture
.Proxy1D
)
3095 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3096 if (ctx
->Texture
.Proxy2D
)
3097 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3098 if (ctx
->Texture
.Proxy3D
)
3099 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3100 if (ctx
->Texture
.ProxyCubeMap
)
3101 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3102 if (ctx
->Texture
.ProxyRect
)
3103 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3109 * Initialize a texture unit.
3111 * \param ctx GL context.
3112 * \param unit texture unit number to be initialized.
3115 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3117 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3119 texUnit
->EnvMode
= GL_MODULATE
;
3120 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3122 texUnit
->Combine
= default_combine_state
;
3123 texUnit
->_EnvMode
= default_combine_state
;
3124 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3126 texUnit
->TexGenEnabled
= 0;
3127 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3128 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3129 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3130 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3131 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3132 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3133 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3134 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3136 /* Yes, these plane coefficients are correct! */
3137 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3138 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3139 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3140 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3141 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3142 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3143 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3144 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3146 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
3147 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
3148 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
3149 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
3150 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
3154 GLboolean
_mesa_init_texture( GLcontext
* ctx
)
3158 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3159 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3161 /* Effectively bind the default textures to all texture units */
3162 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
3163 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
3164 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
3165 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
3166 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
3169 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3170 ctx
->Texture
._EnabledUnits
= 0;
3171 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
3172 init_texture_unit( ctx
, i
);
3173 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3174 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3176 /* Allocate proxy textures */
3177 if (!alloc_proxy_textures( ctx
))
3183 void _mesa_free_texture_data( GLcontext
*ctx
)
3187 /* Free proxy texture objects */
3188 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3189 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3190 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3191 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3192 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3194 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
3195 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);