2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 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.
33 #if FEATURE_colortable
39 #include "texcompress.h"
43 #include "texenvprogram.h"
45 #include "math/m_xform.h"
48 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
49 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
53 * Default texture combine environment state. This is used to initialize
54 * a context's texture units and as the basis for converting "classic"
55 * texture environmnets to ARB_texture_env_combine style values.
57 static const struct gl_tex_env_combine_state default_combine_state
= {
58 GL_MODULATE
, GL_MODULATE
,
59 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
60 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
61 { GL_SRC_COLOR
, GL_SRC_COLOR
, GL_SRC_ALPHA
},
62 { GL_SRC_ALPHA
, GL_SRC_ALPHA
, GL_SRC_ALPHA
},
69 * Copy a texture binding. Helper used by _mesa_copy_texture_state().
72 copy_texture_binding(const GLcontext
*ctx
,
73 struct gl_texture_object
**dst
,
74 struct gl_texture_object
*src
)
76 /* only copy if names differ (per OpenGL SI) */
77 if ((*dst
)->Name
!= src
->Name
) {
78 /* unbind/delete dest binding which we're changing */
80 if ((*dst
)->RefCount
== 0) {
81 /* time to delete this texture object */
82 ASSERT((*dst
)->Name
!= 0);
83 ASSERT(ctx
->Driver
.DeleteTexture
);
84 /* XXX cast-away const, unfortunately */
85 (*ctx
->Driver
.DeleteTexture
)((GLcontext
*) ctx
, *dst
);
87 /* make new binding, incrementing ref count */
95 * Used by glXCopyContext to copy texture state from one context to another.
98 _mesa_copy_texture_state( const GLcontext
*src
, GLcontext
*dst
)
105 dst
->Texture
.CurrentUnit
= src
->Texture
.CurrentUnit
;
106 dst
->Texture
._GenFlags
= src
->Texture
._GenFlags
;
107 dst
->Texture
._TexGenEnabled
= src
->Texture
._TexGenEnabled
;
108 dst
->Texture
._TexMatEnabled
= src
->Texture
._TexMatEnabled
;
109 dst
->Texture
.SharedPalette
= src
->Texture
.SharedPalette
;
112 for (i
= 0; i
< src
->Const
.MaxTextureUnits
; i
++) {
113 dst
->Texture
.Unit
[i
].Enabled
= src
->Texture
.Unit
[i
].Enabled
;
114 dst
->Texture
.Unit
[i
].EnvMode
= src
->Texture
.Unit
[i
].EnvMode
;
115 COPY_4V(dst
->Texture
.Unit
[i
].EnvColor
, src
->Texture
.Unit
[i
].EnvColor
);
116 dst
->Texture
.Unit
[i
].TexGenEnabled
= src
->Texture
.Unit
[i
].TexGenEnabled
;
117 dst
->Texture
.Unit
[i
].GenModeS
= src
->Texture
.Unit
[i
].GenModeS
;
118 dst
->Texture
.Unit
[i
].GenModeT
= src
->Texture
.Unit
[i
].GenModeT
;
119 dst
->Texture
.Unit
[i
].GenModeR
= src
->Texture
.Unit
[i
].GenModeR
;
120 dst
->Texture
.Unit
[i
].GenModeQ
= src
->Texture
.Unit
[i
].GenModeQ
;
121 dst
->Texture
.Unit
[i
]._GenBitS
= src
->Texture
.Unit
[i
]._GenBitS
;
122 dst
->Texture
.Unit
[i
]._GenBitT
= src
->Texture
.Unit
[i
]._GenBitT
;
123 dst
->Texture
.Unit
[i
]._GenBitR
= src
->Texture
.Unit
[i
]._GenBitR
;
124 dst
->Texture
.Unit
[i
]._GenBitQ
= src
->Texture
.Unit
[i
]._GenBitQ
;
125 dst
->Texture
.Unit
[i
]._GenFlags
= src
->Texture
.Unit
[i
]._GenFlags
;
126 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneS
, src
->Texture
.Unit
[i
].ObjectPlaneS
);
127 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneT
, src
->Texture
.Unit
[i
].ObjectPlaneT
);
128 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneR
, src
->Texture
.Unit
[i
].ObjectPlaneR
);
129 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneQ
, src
->Texture
.Unit
[i
].ObjectPlaneQ
);
130 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneS
, src
->Texture
.Unit
[i
].EyePlaneS
);
131 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneT
, src
->Texture
.Unit
[i
].EyePlaneT
);
132 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneR
, src
->Texture
.Unit
[i
].EyePlaneR
);
133 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneQ
, src
->Texture
.Unit
[i
].EyePlaneQ
);
134 dst
->Texture
.Unit
[i
].LodBias
= src
->Texture
.Unit
[i
].LodBias
;
136 /* GL_EXT_texture_env_combine */
137 dst
->Texture
.Unit
[i
].Combine
.ModeRGB
= src
->Texture
.Unit
[i
].Combine
.ModeRGB
;
138 dst
->Texture
.Unit
[i
].Combine
.ModeA
= src
->Texture
.Unit
[i
].Combine
.ModeA
;
139 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceRGB
, src
->Texture
.Unit
[i
].Combine
.SourceRGB
);
140 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceA
, src
->Texture
.Unit
[i
].Combine
.SourceA
);
141 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandRGB
, src
->Texture
.Unit
[i
].Combine
.OperandRGB
);
142 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandA
, src
->Texture
.Unit
[i
].Combine
.OperandA
);
143 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
;
144 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftA
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftA
;
146 /* copy texture object bindings, not contents of texture objects */
147 _mesa_lock_context_textures(dst
);
149 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current1D
,
150 src
->Texture
.Unit
[i
].Current1D
);
151 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current2D
,
152 src
->Texture
.Unit
[i
].Current2D
);
153 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current3D
,
154 src
->Texture
.Unit
[i
].Current3D
);
155 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].CurrentCubeMap
,
156 src
->Texture
.Unit
[i
].CurrentCubeMap
);
157 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].CurrentRect
,
158 src
->Texture
.Unit
[i
].CurrentRect
);
159 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current1DArray
,
160 src
->Texture
.Unit
[i
].Current1DArray
);
161 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current2DArray
,
162 src
->Texture
.Unit
[i
].Current2DArray
);
164 _mesa_unlock_context_textures(dst
);
173 _mesa_print_texunit_state( GLcontext
*ctx
, GLuint unit
)
175 const struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
+ unit
;
176 _mesa_printf("Texture Unit %d\n", unit
);
177 _mesa_printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit
->EnvMode
));
178 _mesa_printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeRGB
));
179 _mesa_printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeA
));
180 _mesa_printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[0]));
181 _mesa_printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[1]));
182 _mesa_printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[2]));
183 _mesa_printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[0]));
184 _mesa_printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[1]));
185 _mesa_printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[2]));
186 _mesa_printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[0]));
187 _mesa_printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[1]));
188 _mesa_printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[2]));
189 _mesa_printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[0]));
190 _mesa_printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[1]));
191 _mesa_printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[2]));
192 _mesa_printf(" GL_RGB_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftRGB
);
193 _mesa_printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftA
);
194 _mesa_printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit
->EnvColor
[0], texUnit
->EnvColor
[1], texUnit
->EnvColor
[2], texUnit
->EnvColor
[3]);
199 /**********************************************************************/
200 /* Texture Environment */
201 /**********************************************************************/
204 * Convert "classic" texture environment to ARB_texture_env_combine style
207 * \param state texture_env_combine state vector to be filled-in.
208 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
209 * \c GL_BLEND, \c GL_DECAL, etc.).
210 * \param texBaseFormat Base format of the texture associated with the
214 calculate_derived_texenv( struct gl_tex_env_combine_state
*state
,
215 GLenum mode
, GLenum texBaseFormat
)
220 *state
= default_combine_state
;
222 switch (texBaseFormat
) {
224 state
->SourceRGB
[0] = GL_PREVIOUS
;
227 case GL_LUMINANCE_ALPHA
:
235 state
->SourceA
[0] = GL_PREVIOUS
;
239 _mesa_problem(NULL
, "Invalid texBaseFormat in calculate_derived_texenv");
243 if (mode
== GL_REPLACE_EXT
)
249 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: mode
;
254 mode_rgb
= GL_INTERPOLATE
;
257 state
->SourceA
[0] = GL_PREVIOUS
;
259 /* Having alpha / luminance / intensity textures replace using the
260 * incoming fragment color matches the definition in NV_texture_shader.
261 * The 1.5 spec simply marks these as "undefined".
263 switch (texBaseFormat
) {
266 case GL_LUMINANCE_ALPHA
:
268 state
->SourceRGB
[0] = GL_PREVIOUS
;
272 mode_rgb
= GL_REPLACE
;
275 state
->SourceRGB
[2] = GL_TEXTURE
;
281 mode_rgb
= GL_INTERPOLATE
;
282 mode_a
= GL_MODULATE
;
284 switch (texBaseFormat
) {
286 mode_rgb
= GL_REPLACE
;
289 mode_a
= GL_INTERPOLATE
;
290 state
->SourceA
[0] = GL_CONSTANT
;
291 state
->OperandA
[2] = GL_SRC_ALPHA
;
295 case GL_LUMINANCE_ALPHA
:
298 state
->SourceRGB
[2] = GL_TEXTURE
;
299 state
->SourceA
[2] = GL_TEXTURE
;
300 state
->SourceRGB
[0] = GL_CONSTANT
;
301 state
->OperandRGB
[2] = GL_SRC_COLOR
;
307 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
308 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
313 "Invalid texture env mode in calculate_derived_texenv");
317 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
318 ? mode_rgb
: GL_REPLACE
;
319 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
320 ? mode_a
: GL_REPLACE
;
324 /**********************************************************************/
325 /* Texture Parameters */
326 /**********************************************************************/
329 * Check if a coordinate wrap mode is supported for the texture target.
330 * \return GL_TRUE if legal, GL_FALSE otherwise
333 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
335 const struct gl_extensions
* const e
= & ctx
->Extensions
;
337 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
338 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
339 /* any texture target */
342 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
343 (wrap
== GL_REPEAT
||
344 (wrap
== GL_MIRRORED_REPEAT
&&
345 e
->ARB_texture_mirrored_repeat
) ||
346 (wrap
== GL_MIRROR_CLAMP_EXT
&&
347 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
348 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
349 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
350 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
351 (e
->EXT_texture_mirror_clamp
)))) {
352 /* non-rectangle texture */
356 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
362 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
364 _mesa_TexParameterfv(target
, pname
, ¶m
);
369 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
371 const GLenum eparam
= (GLenum
) (GLint
) params
[0];
372 struct gl_texture_unit
*texUnit
;
373 struct gl_texture_object
*texObj
;
374 GET_CURRENT_CONTEXT(ctx
);
375 ASSERT_OUTSIDE_BEGIN_END(ctx
);
377 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
378 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
379 _mesa_lookup_enum_by_nr(target
),
380 _mesa_lookup_enum_by_nr(pname
),
382 _mesa_lookup_enum_by_nr(eparam
));
384 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
385 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameterfv(current unit)");
389 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
393 texObj
= texUnit
->Current1D
;
396 texObj
= texUnit
->Current2D
;
399 texObj
= texUnit
->Current3D
;
401 case GL_TEXTURE_CUBE_MAP
:
402 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
403 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
406 texObj
= texUnit
->CurrentCubeMap
;
408 case GL_TEXTURE_RECTANGLE_NV
:
409 if (!ctx
->Extensions
.NV_texture_rectangle
) {
410 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
413 texObj
= texUnit
->CurrentRect
;
415 case GL_TEXTURE_1D_ARRAY_EXT
:
416 if (!ctx
->Extensions
.MESA_texture_array
) {
417 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
420 texObj
= texUnit
->Current1DArray
;
422 case GL_TEXTURE_2D_ARRAY_EXT
:
423 if (!ctx
->Extensions
.MESA_texture_array
) {
424 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
427 texObj
= texUnit
->Current2DArray
;
430 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
435 case GL_TEXTURE_MIN_FILTER
:
436 /* A small optimization */
437 if (texObj
->MinFilter
== eparam
)
439 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
440 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
441 texObj
->MinFilter
= eparam
;
443 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
444 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
445 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
446 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
447 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
448 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
449 texObj
->MinFilter
= eparam
;
452 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
456 case GL_TEXTURE_MAG_FILTER
:
457 /* A small optimization */
458 if (texObj
->MagFilter
== eparam
)
461 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
462 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
463 texObj
->MagFilter
= eparam
;
466 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
470 case GL_TEXTURE_WRAP_S
:
471 if (texObj
->WrapS
== eparam
)
473 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
474 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
475 texObj
->WrapS
= eparam
;
481 case GL_TEXTURE_WRAP_T
:
482 if (texObj
->WrapT
== eparam
)
484 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
485 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
486 texObj
->WrapT
= eparam
;
492 case GL_TEXTURE_WRAP_R
:
493 if (texObj
->WrapR
== eparam
)
495 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
496 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
497 texObj
->WrapR
= eparam
;
503 case GL_TEXTURE_BORDER_COLOR
:
504 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
505 texObj
->BorderColor
[RCOMP
] = params
[0];
506 texObj
->BorderColor
[GCOMP
] = params
[1];
507 texObj
->BorderColor
[BCOMP
] = params
[2];
508 texObj
->BorderColor
[ACOMP
] = params
[3];
509 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
510 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
511 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
512 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
514 case GL_TEXTURE_MIN_LOD
:
515 if (texObj
->MinLod
== params
[0])
517 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
518 texObj
->MinLod
= params
[0];
520 case GL_TEXTURE_MAX_LOD
:
521 if (texObj
->MaxLod
== params
[0])
523 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
524 texObj
->MaxLod
= params
[0];
526 case GL_TEXTURE_BASE_LEVEL
:
527 if (params
[0] < 0.0) {
528 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
531 if (target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0.0) {
532 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
535 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
536 texObj
->BaseLevel
= (GLint
) params
[0];
538 case GL_TEXTURE_MAX_LEVEL
:
539 if (params
[0] < 0.0) {
540 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
543 if (target
== GL_TEXTURE_RECTANGLE_ARB
) {
544 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
547 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
548 texObj
->MaxLevel
= (GLint
) params
[0];
550 case GL_TEXTURE_PRIORITY
:
551 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
552 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
554 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
555 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
556 if (params
[0] < 1.0) {
557 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
560 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
561 /* clamp to max, that's what NVIDIA does */
562 texObj
->MaxAnisotropy
= MIN2(params
[0],
563 ctx
->Const
.MaxTextureMaxAnisotropy
);
566 _mesa_error(ctx
, GL_INVALID_ENUM
,
567 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
571 case GL_TEXTURE_COMPARE_SGIX
:
572 if (ctx
->Extensions
.SGIX_shadow
) {
573 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
574 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
577 _mesa_error(ctx
, GL_INVALID_ENUM
,
578 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
582 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
583 if (ctx
->Extensions
.SGIX_shadow
) {
584 GLenum op
= (GLenum
) params
[0];
585 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
586 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
587 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
588 texObj
->CompareOperator
= op
;
591 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
595 _mesa_error(ctx
, GL_INVALID_ENUM
,
596 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
600 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
601 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
602 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
603 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
606 _mesa_error(ctx
, GL_INVALID_ENUM
,
607 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
611 case GL_GENERATE_MIPMAP_SGIS
:
612 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
613 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
616 _mesa_error(ctx
, GL_INVALID_ENUM
,
617 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
621 case GL_TEXTURE_COMPARE_MODE_ARB
:
622 if (ctx
->Extensions
.ARB_shadow
) {
623 const GLenum mode
= (GLenum
) params
[0];
624 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
625 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
626 texObj
->CompareMode
= mode
;
629 _mesa_error(ctx
, GL_INVALID_ENUM
,
630 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
635 _mesa_error(ctx
, GL_INVALID_ENUM
,
636 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
640 case GL_TEXTURE_COMPARE_FUNC_ARB
:
641 if (ctx
->Extensions
.ARB_shadow
) {
642 const GLenum func
= (GLenum
) params
[0];
643 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
644 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
645 texObj
->CompareFunc
= func
;
647 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
649 func
== GL_NOTEQUAL
||
651 func
== GL_GREATER
||
654 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
655 texObj
->CompareFunc
= func
;
658 _mesa_error(ctx
, GL_INVALID_ENUM
,
659 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
664 _mesa_error(ctx
, GL_INVALID_ENUM
,
665 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
669 case GL_DEPTH_TEXTURE_MODE_ARB
:
670 if (ctx
->Extensions
.ARB_depth_texture
) {
671 const GLenum result
= (GLenum
) params
[0];
672 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
673 || result
== GL_ALPHA
) {
674 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
675 texObj
->DepthMode
= result
;
678 _mesa_error(ctx
, GL_INVALID_ENUM
,
679 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
684 _mesa_error(ctx
, GL_INVALID_ENUM
,
685 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
689 case GL_TEXTURE_LOD_BIAS
:
690 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
691 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
692 if (texObj
->LodBias
!= params
[0]) {
693 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
694 texObj
->LodBias
= params
[0];
700 _mesa_error(ctx
, GL_INVALID_ENUM
,
701 "glTexParameter(pname=0x%x)", pname
);
705 texObj
->_Complete
= GL_FALSE
;
707 if (ctx
->Driver
.TexParameter
) {
708 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
714 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
717 if (pname
== GL_TEXTURE_PRIORITY
)
718 fparam
[0] = INT_TO_FLOAT(param
);
720 fparam
[0] = (GLfloat
) param
;
721 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
722 _mesa_TexParameterfv(target
, pname
, fparam
);
727 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
730 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
731 fparam
[0] = INT_TO_FLOAT(params
[0]);
732 fparam
[1] = INT_TO_FLOAT(params
[1]);
733 fparam
[2] = INT_TO_FLOAT(params
[2]);
734 fparam
[3] = INT_TO_FLOAT(params
[3]);
737 if (pname
== GL_TEXTURE_PRIORITY
)
738 fparam
[0] = INT_TO_FLOAT(params
[0]);
740 fparam
[0] = (GLfloat
) params
[0];
741 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
743 _mesa_TexParameterfv(target
, pname
, fparam
);
748 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
749 GLenum pname
, GLfloat
*params
)
752 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
753 *params
= (GLfloat
) iparam
;
758 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
762 case GL_PROXY_TEXTURE_1D
:
765 case GL_PROXY_TEXTURE_2D
:
768 case GL_PROXY_TEXTURE_3D
:
770 case GL_TEXTURE_CUBE_MAP
:
771 case GL_PROXY_TEXTURE_CUBE_MAP
:
772 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
773 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
774 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
775 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
776 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
777 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
778 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
779 case GL_TEXTURE_RECTANGLE_NV
:
780 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
781 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
782 case GL_TEXTURE_1D_ARRAY_EXT
:
783 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
784 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
785 case GL_TEXTURE_2D_ARRAY_EXT
:
786 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
787 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
789 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
796 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
797 GLenum pname
, GLint
*params
)
799 const struct gl_texture_unit
*texUnit
;
800 struct gl_texture_object
*texObj
;
801 const struct gl_texture_image
*img
= NULL
;
805 GET_CURRENT_CONTEXT(ctx
);
806 ASSERT_OUTSIDE_BEGIN_END(ctx
);
808 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
809 _mesa_error(ctx
, GL_INVALID_OPERATION
,
810 "glGetTexLevelParameteriv(current unit)");
814 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
816 /* this will catch bad target values */
817 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
818 if (dimensions
== 0) {
819 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
823 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
824 if (maxLevels
== 0) {
825 /* should not happen since <target> was just checked above */
826 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
830 if (level
< 0 || level
>= maxLevels
) {
831 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
835 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
836 _mesa_lock_texture(ctx
, texObj
);
838 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
839 if (!img
|| !img
->TexFormat
) {
840 /* undefined texture image */
841 if (pname
== GL_TEXTURE_COMPONENTS
)
848 isProxy
= _mesa_is_proxy_texture(target
);
851 case GL_TEXTURE_WIDTH
:
852 *params
= img
->Width
;
854 case GL_TEXTURE_HEIGHT
:
855 *params
= img
->Height
;
857 case GL_TEXTURE_DEPTH
:
858 *params
= img
->Depth
;
860 case GL_TEXTURE_INTERNAL_FORMAT
:
861 *params
= img
->InternalFormat
;
863 case GL_TEXTURE_BORDER
:
864 *params
= img
->Border
;
866 case GL_TEXTURE_RED_SIZE
:
867 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
868 *params
= img
->TexFormat
->RedBits
;
872 case GL_TEXTURE_GREEN_SIZE
:
873 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
874 *params
= img
->TexFormat
->GreenBits
;
878 case GL_TEXTURE_BLUE_SIZE
:
879 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
880 *params
= img
->TexFormat
->BlueBits
;
884 case GL_TEXTURE_ALPHA_SIZE
:
885 if (img
->_BaseFormat
== GL_ALPHA
||
886 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
887 img
->_BaseFormat
== GL_RGBA
)
888 *params
= img
->TexFormat
->AlphaBits
;
892 case GL_TEXTURE_INTENSITY_SIZE
:
893 if (img
->_BaseFormat
!= GL_INTENSITY
)
895 else if (img
->TexFormat
->IntensityBits
> 0)
896 *params
= img
->TexFormat
->IntensityBits
;
897 else /* intensity probably stored as rgb texture */
898 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
900 case GL_TEXTURE_LUMINANCE_SIZE
:
901 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
902 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
904 else if (img
->TexFormat
->LuminanceBits
> 0)
905 *params
= img
->TexFormat
->LuminanceBits
;
906 else /* luminance probably stored as rgb texture */
907 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
909 case GL_TEXTURE_INDEX_SIZE_EXT
:
910 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
911 *params
= img
->TexFormat
->IndexBits
;
915 case GL_TEXTURE_DEPTH_SIZE_ARB
:
916 if (ctx
->Extensions
.SGIX_depth_texture
||
917 ctx
->Extensions
.ARB_depth_texture
)
918 *params
= img
->TexFormat
->DepthBits
;
920 _mesa_error(ctx
, GL_INVALID_ENUM
,
921 "glGetTexLevelParameter[if]v(pname)");
923 case GL_TEXTURE_STENCIL_SIZE_EXT
:
924 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
925 *params
= img
->TexFormat
->StencilBits
;
928 _mesa_error(ctx
, GL_INVALID_ENUM
,
929 "glGetTexLevelParameter[if]v(pname)");
933 /* GL_ARB_texture_compression */
934 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
935 if (ctx
->Extensions
.ARB_texture_compression
) {
936 if (img
->IsCompressed
&& !isProxy
) {
937 /* Don't use ctx->Driver.CompressedTextureSize() since that
938 * may returned a padded hardware size.
940 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
941 img
->Height
, img
->Depth
,
942 img
->TexFormat
->MesaFormat
);
945 _mesa_error(ctx
, GL_INVALID_OPERATION
,
946 "glGetTexLevelParameter[if]v(pname)");
950 _mesa_error(ctx
, GL_INVALID_ENUM
,
951 "glGetTexLevelParameter[if]v(pname)");
954 case GL_TEXTURE_COMPRESSED
:
955 if (ctx
->Extensions
.ARB_texture_compression
) {
956 *params
= (GLint
) img
->IsCompressed
;
959 _mesa_error(ctx
, GL_INVALID_ENUM
,
960 "glGetTexLevelParameter[if]v(pname)");
964 /* GL_ARB_texture_float */
965 case GL_TEXTURE_RED_TYPE_ARB
:
966 if (ctx
->Extensions
.ARB_texture_float
) {
967 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
970 _mesa_error(ctx
, GL_INVALID_ENUM
,
971 "glGetTexLevelParameter[if]v(pname)");
974 case GL_TEXTURE_GREEN_TYPE_ARB
:
975 if (ctx
->Extensions
.ARB_texture_float
) {
976 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
979 _mesa_error(ctx
, GL_INVALID_ENUM
,
980 "glGetTexLevelParameter[if]v(pname)");
983 case GL_TEXTURE_BLUE_TYPE_ARB
:
984 if (ctx
->Extensions
.ARB_texture_float
) {
985 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
988 _mesa_error(ctx
, GL_INVALID_ENUM
,
989 "glGetTexLevelParameter[if]v(pname)");
992 case GL_TEXTURE_ALPHA_TYPE_ARB
:
993 if (ctx
->Extensions
.ARB_texture_float
) {
994 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
997 _mesa_error(ctx
, GL_INVALID_ENUM
,
998 "glGetTexLevelParameter[if]v(pname)");
1001 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1002 if (ctx
->Extensions
.ARB_texture_float
) {
1003 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
1006 _mesa_error(ctx
, GL_INVALID_ENUM
,
1007 "glGetTexLevelParameter[if]v(pname)");
1010 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1011 if (ctx
->Extensions
.ARB_texture_float
) {
1012 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
1015 _mesa_error(ctx
, GL_INVALID_ENUM
,
1016 "glGetTexLevelParameter[if]v(pname)");
1019 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1020 if (ctx
->Extensions
.ARB_texture_float
) {
1021 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
1024 _mesa_error(ctx
, GL_INVALID_ENUM
,
1025 "glGetTexLevelParameter[if]v(pname)");
1030 _mesa_error(ctx
, GL_INVALID_ENUM
,
1031 "glGetTexLevelParameter[if]v(pname)");
1035 _mesa_unlock_texture(ctx
, texObj
);
1041 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1043 struct gl_texture_unit
*texUnit
;
1044 struct gl_texture_object
*obj
;
1045 GLboolean error
= GL_FALSE
;
1046 GET_CURRENT_CONTEXT(ctx
);
1047 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1049 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1050 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1051 "glGetTexParameterfv(current unit)");
1055 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1057 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1059 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1063 _mesa_lock_texture(ctx
, obj
);
1065 case GL_TEXTURE_MAG_FILTER
:
1066 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1068 case GL_TEXTURE_MIN_FILTER
:
1069 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1071 case GL_TEXTURE_WRAP_S
:
1072 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1074 case GL_TEXTURE_WRAP_T
:
1075 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1077 case GL_TEXTURE_WRAP_R
:
1078 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1080 case GL_TEXTURE_BORDER_COLOR
:
1081 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1082 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1083 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1084 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1086 case GL_TEXTURE_RESIDENT
:
1089 if (ctx
->Driver
.IsTextureResident
)
1090 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1093 *params
= ENUM_TO_FLOAT(resident
);
1096 case GL_TEXTURE_PRIORITY
:
1097 *params
= obj
->Priority
;
1099 case GL_TEXTURE_MIN_LOD
:
1100 *params
= obj
->MinLod
;
1102 case GL_TEXTURE_MAX_LOD
:
1103 *params
= obj
->MaxLod
;
1105 case GL_TEXTURE_BASE_LEVEL
:
1106 *params
= (GLfloat
) obj
->BaseLevel
;
1108 case GL_TEXTURE_MAX_LEVEL
:
1109 *params
= (GLfloat
) obj
->MaxLevel
;
1111 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1112 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1113 *params
= obj
->MaxAnisotropy
;
1118 case GL_TEXTURE_COMPARE_SGIX
:
1119 if (ctx
->Extensions
.SGIX_shadow
) {
1120 *params
= (GLfloat
) obj
->CompareFlag
;
1125 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1126 if (ctx
->Extensions
.SGIX_shadow
) {
1127 *params
= (GLfloat
) obj
->CompareOperator
;
1132 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1133 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1134 *params
= obj
->ShadowAmbient
;
1139 case GL_GENERATE_MIPMAP_SGIS
:
1140 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1141 *params
= (GLfloat
) obj
->GenerateMipmap
;
1146 case GL_TEXTURE_COMPARE_MODE_ARB
:
1147 if (ctx
->Extensions
.ARB_shadow
) {
1148 *params
= (GLfloat
) obj
->CompareMode
;
1153 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1154 if (ctx
->Extensions
.ARB_shadow
) {
1155 *params
= (GLfloat
) obj
->CompareFunc
;
1160 case GL_DEPTH_TEXTURE_MODE_ARB
:
1161 if (ctx
->Extensions
.ARB_depth_texture
) {
1162 *params
= (GLfloat
) obj
->DepthMode
;
1167 case GL_TEXTURE_LOD_BIAS
:
1168 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1169 *params
= obj
->LodBias
;
1179 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1182 _mesa_unlock_texture(ctx
, obj
);
1187 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1189 struct gl_texture_unit
*texUnit
;
1190 struct gl_texture_object
*obj
;
1191 GET_CURRENT_CONTEXT(ctx
);
1192 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1194 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1195 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1196 "glGetTexParameteriv(current unit)");
1200 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1202 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1204 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1209 case GL_TEXTURE_MAG_FILTER
:
1210 *params
= (GLint
) obj
->MagFilter
;
1212 case GL_TEXTURE_MIN_FILTER
:
1213 *params
= (GLint
) obj
->MinFilter
;
1215 case GL_TEXTURE_WRAP_S
:
1216 *params
= (GLint
) obj
->WrapS
;
1218 case GL_TEXTURE_WRAP_T
:
1219 *params
= (GLint
) obj
->WrapT
;
1221 case GL_TEXTURE_WRAP_R
:
1222 *params
= (GLint
) obj
->WrapR
;
1224 case GL_TEXTURE_BORDER_COLOR
:
1227 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1228 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1229 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1230 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1231 params
[0] = FLOAT_TO_INT(b
[0]);
1232 params
[1] = FLOAT_TO_INT(b
[1]);
1233 params
[2] = FLOAT_TO_INT(b
[2]);
1234 params
[3] = FLOAT_TO_INT(b
[3]);
1237 case GL_TEXTURE_RESIDENT
:
1240 if (ctx
->Driver
.IsTextureResident
)
1241 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1244 *params
= (GLint
) resident
;
1247 case GL_TEXTURE_PRIORITY
:
1248 *params
= FLOAT_TO_INT(obj
->Priority
);
1250 case GL_TEXTURE_MIN_LOD
:
1251 *params
= (GLint
) obj
->MinLod
;
1253 case GL_TEXTURE_MAX_LOD
:
1254 *params
= (GLint
) obj
->MaxLod
;
1256 case GL_TEXTURE_BASE_LEVEL
:
1257 *params
= obj
->BaseLevel
;
1259 case GL_TEXTURE_MAX_LEVEL
:
1260 *params
= obj
->MaxLevel
;
1262 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1263 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1264 *params
= (GLint
) obj
->MaxAnisotropy
;
1268 case GL_TEXTURE_COMPARE_SGIX
:
1269 if (ctx
->Extensions
.SGIX_shadow
) {
1270 *params
= (GLint
) obj
->CompareFlag
;
1274 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1275 if (ctx
->Extensions
.SGIX_shadow
) {
1276 *params
= (GLint
) obj
->CompareOperator
;
1280 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1281 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1282 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
1286 case GL_GENERATE_MIPMAP_SGIS
:
1287 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1288 *params
= (GLint
) obj
->GenerateMipmap
;
1292 case GL_TEXTURE_COMPARE_MODE_ARB
:
1293 if (ctx
->Extensions
.ARB_shadow
) {
1294 *params
= (GLint
) obj
->CompareMode
;
1298 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1299 if (ctx
->Extensions
.ARB_shadow
) {
1300 *params
= (GLint
) obj
->CompareFunc
;
1304 case GL_DEPTH_TEXTURE_MODE_ARB
:
1305 if (ctx
->Extensions
.ARB_depth_texture
) {
1306 *params
= (GLint
) obj
->DepthMode
;
1310 case GL_TEXTURE_LOD_BIAS
:
1311 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1312 *params
= (GLint
) obj
->LodBias
;
1317 ; /* silence warnings */
1319 /* If we get here, pname was an unrecognized enum */
1320 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1325 /* GL_ARB_multitexture */
1327 _mesa_ActiveTextureARB(GLenum texture
)
1329 GET_CURRENT_CONTEXT(ctx
);
1330 const GLuint texUnit
= texture
- GL_TEXTURE0
;
1331 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1333 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1334 _mesa_debug(ctx
, "glActiveTexture %s\n",
1335 _mesa_lookup_enum_by_nr(texture
));
1337 /* XXX error-check against max(coordunits, imageunits) */
1338 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
1339 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(texture)");
1343 if (ctx
->Texture
.CurrentUnit
== texUnit
)
1346 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1348 ctx
->Texture
.CurrentUnit
= texUnit
;
1349 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
1350 /* update current stack pointer */
1351 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
1354 if (ctx
->Driver
.ActiveTexture
) {
1355 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
1360 /* GL_ARB_multitexture */
1362 _mesa_ClientActiveTextureARB(GLenum texture
)
1364 GET_CURRENT_CONTEXT(ctx
);
1365 GLuint texUnit
= texture
- GL_TEXTURE0
;
1366 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1368 if (texUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1369 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(texture)");
1373 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1374 ctx
->Array
.ActiveTexture
= texUnit
;
1379 /**********************************************************************/
1380 /***** State management *****/
1381 /**********************************************************************/
1385 * \note This routine refers to derived texture attribute values to
1386 * compute the ENABLE_TEXMAT flags, but is only called on
1387 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
1388 * flags are updated by _mesa_update_textures(), below.
1390 * \param ctx GL context.
1393 update_texture_matrices( GLcontext
*ctx
)
1397 ctx
->Texture
._TexMatEnabled
= 0;
1399 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1400 if (_math_matrix_is_dirty(ctx
->TextureMatrixStack
[i
].Top
)) {
1401 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
1403 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
1404 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
1405 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
1407 if (ctx
->Driver
.TextureMatrix
)
1408 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
1415 * Update texture object's _Function field. We need to do this
1416 * whenever any of the texture object's shadow-related fields change
1417 * or when we start/stop using a fragment program.
1419 * This function could be expanded someday to update additional per-object
1420 * fields that depend on assorted state changes.
1423 update_texture_compare_function(GLcontext
*ctx
,
1424 struct gl_texture_object
*tObj
)
1426 /* XXX temporarily disable this test since it breaks the GLSL
1427 * shadow2D(), etc. functions.
1429 if (0 /*ctx->FragmentProgram._Current*/) {
1430 /* Texel/coordinate comparison is ignored for programs.
1431 * See GL_ARB_fragment_program/shader spec for details.
1433 tObj
->_Function
= GL_NONE
;
1435 else if (tObj
->CompareFlag
) {
1436 /* GL_SGIX_shadow */
1437 if (tObj
->CompareOperator
== GL_TEXTURE_LEQUAL_R_SGIX
) {
1438 tObj
->_Function
= GL_LEQUAL
;
1441 ASSERT(tObj
->CompareOperator
== GL_TEXTURE_GEQUAL_R_SGIX
);
1442 tObj
->_Function
= GL_GEQUAL
;
1445 else if (tObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1447 tObj
->_Function
= tObj
->CompareFunc
;
1450 tObj
->_Function
= GL_NONE
; /* pass depth through as grayscale */
1456 * Helper function for determining which texture object (1D, 2D, cube, etc)
1457 * should actually be used.
1460 texture_override(GLcontext
*ctx
,
1461 struct gl_texture_unit
*texUnit
, GLbitfield enableBits
,
1462 struct gl_texture_object
*texObj
, GLuint textureBit
)
1464 if (!texUnit
->_ReallyEnabled
&& (enableBits
& textureBit
)) {
1465 if (!texObj
->_Complete
) {
1466 _mesa_test_texobj_completeness(ctx
, texObj
);
1468 if (texObj
->_Complete
) {
1469 texUnit
->_ReallyEnabled
= textureBit
;
1470 texUnit
->_Current
= texObj
;
1471 update_texture_compare_function(ctx
, texObj
);
1478 * \note This routine refers to derived texture matrix values to
1479 * compute the ENABLE_TEXMAT flags, but is only called on
1480 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
1481 * flags are updated by _mesa_update_texture_matrices, above.
1483 * \param ctx GL context.
1486 update_texture_state( GLcontext
*ctx
)
1489 struct gl_fragment_program
*fprog
= NULL
;
1490 struct gl_vertex_program
*vprog
= NULL
;
1492 if (ctx
->Shader
.CurrentProgram
&&
1493 ctx
->Shader
.CurrentProgram
->LinkStatus
) {
1494 fprog
= ctx
->Shader
.CurrentProgram
->FragmentProgram
;
1495 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
1498 if (ctx
->FragmentProgram
._Enabled
) {
1499 fprog
= ctx
->FragmentProgram
.Current
;
1501 if (ctx
->VertexProgram
._Enabled
) {
1502 /* XXX enable this if/when non-shader vertex programs get
1504 vprog = ctx->VertexProgram.Current;
1509 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
1513 ctx
->Texture
._EnabledUnits
= 0;
1514 ctx
->Texture
._GenFlags
= 0;
1515 ctx
->Texture
._TexMatEnabled
= 0;
1516 ctx
->Texture
._TexGenEnabled
= 0;
1519 * Update texture unit state.
1521 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
1522 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
1523 GLbitfield enableBits
;
1525 texUnit
->_Current
= NULL
;
1526 texUnit
->_ReallyEnabled
= 0;
1527 texUnit
->_GenFlags
= 0;
1529 /* Get the bitmask of texture enables.
1530 * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
1531 * which texture targets are enabled (fixed function) or referenced
1532 * by a fragment shader/program. When multiple flags are set, we'll
1533 * settle on the one with highest priority (see texture_override below).
1535 if (fprog
|| vprog
) {
1538 enableBits
|= fprog
->Base
.TexturesUsed
[unit
];
1540 enableBits
|= vprog
->Base
.TexturesUsed
[unit
];
1543 if (!texUnit
->Enabled
)
1545 enableBits
= texUnit
->Enabled
;
1548 /* Look for the highest-priority texture target that's enabled and
1549 * complete. That's the one we'll use for texturing. If we're using
1550 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
1552 texture_override(ctx
, texUnit
, enableBits
,
1553 texUnit
->Current2DArray
, TEXTURE_2D_ARRAY_BIT
);
1554 texture_override(ctx
, texUnit
, enableBits
,
1555 texUnit
->Current1DArray
, TEXTURE_1D_ARRAY_BIT
);
1556 texture_override(ctx
, texUnit
, enableBits
,
1557 texUnit
->CurrentCubeMap
, TEXTURE_CUBE_BIT
);
1558 texture_override(ctx
, texUnit
, enableBits
,
1559 texUnit
->Current3D
, TEXTURE_3D_BIT
);
1560 texture_override(ctx
, texUnit
, enableBits
,
1561 texUnit
->CurrentRect
, TEXTURE_RECT_BIT
);
1562 texture_override(ctx
, texUnit
, enableBits
,
1563 texUnit
->Current2D
, TEXTURE_2D_BIT
);
1564 texture_override(ctx
, texUnit
, enableBits
,
1565 texUnit
->Current1D
, TEXTURE_1D_BIT
);
1567 if (!texUnit
->_ReallyEnabled
) {
1571 if (texUnit
->_ReallyEnabled
)
1572 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
1574 if (texUnit
->EnvMode
== GL_COMBINE
) {
1575 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
1578 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
1579 GLenum format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
1580 if (format
== GL_COLOR_INDEX
) {
1581 format
= GL_RGBA
; /* a bit of a hack */
1583 else if (format
== GL_DEPTH_COMPONENT
1584 || format
== GL_DEPTH_STENCIL_EXT
) {
1585 format
= texObj
->DepthMode
;
1587 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
1588 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
1591 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
1593 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
1601 case GL_DOT3_RGB_EXT
:
1602 case GL_DOT3_RGBA_EXT
:
1603 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
1605 case GL_INTERPOLATE
:
1606 case GL_MODULATE_ADD_ATI
:
1607 case GL_MODULATE_SIGNED_ADD_ATI
:
1608 case GL_MODULATE_SUBTRACT_ATI
:
1609 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
1612 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
1613 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
1617 switch (texUnit
->_CurrentCombine
->ModeA
) {
1619 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
1625 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
1627 case GL_INTERPOLATE
:
1628 case GL_MODULATE_ADD_ATI
:
1629 case GL_MODULATE_SIGNED_ADD_ATI
:
1630 case GL_MODULATE_SUBTRACT_ATI
:
1631 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
1634 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
1635 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
1639 if (texUnit
->TexGenEnabled
) {
1640 if (texUnit
->TexGenEnabled
& S_BIT
) {
1641 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
1643 if (texUnit
->TexGenEnabled
& T_BIT
) {
1644 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
1646 if (texUnit
->TexGenEnabled
& Q_BIT
) {
1647 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
1649 if (texUnit
->TexGenEnabled
& R_BIT
) {
1650 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
1653 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
1654 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
1657 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
1658 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
1661 /* Determine which texture coordinate sets are actually needed */
1663 const GLuint coordMask
= (1 << MAX_TEXTURE_COORD_UNITS
) - 1;
1664 ctx
->Texture
._EnabledCoordUnits
1665 = (fprog
->Base
.InputsRead
>> FRAG_ATTRIB_TEX0
) & coordMask
;
1668 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
1674 * Update texture-related derived state.
1677 _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
1679 if (new_state
& _NEW_TEXTURE_MATRIX
)
1680 update_texture_matrices( ctx
);
1682 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
1683 update_texture_state( ctx
);
1687 /**********************************************************************/
1688 /***** Initialization *****/
1689 /**********************************************************************/
1692 * Allocate the proxy textures for the given context.
1694 * \param ctx the context to allocate proxies for.
1696 * \return GL_TRUE on success, or GL_FALSE on failure
1698 * If run out of memory part way through the allocations, clean up and return
1702 alloc_proxy_textures( GLcontext
*ctx
)
1704 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
1705 if (!ctx
->Texture
.Proxy1D
)
1708 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
1709 if (!ctx
->Texture
.Proxy2D
)
1712 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
1713 if (!ctx
->Texture
.Proxy3D
)
1716 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
1717 if (!ctx
->Texture
.ProxyCubeMap
)
1720 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
1721 if (!ctx
->Texture
.ProxyRect
)
1724 ctx
->Texture
.Proxy1DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D_ARRAY_EXT
);
1725 if (!ctx
->Texture
.Proxy1DArray
)
1728 ctx
->Texture
.Proxy2DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D_ARRAY_EXT
);
1729 if (!ctx
->Texture
.Proxy2DArray
)
1735 if (ctx
->Texture
.Proxy1D
)
1736 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
1737 if (ctx
->Texture
.Proxy2D
)
1738 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
1739 if (ctx
->Texture
.Proxy3D
)
1740 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
1741 if (ctx
->Texture
.ProxyCubeMap
)
1742 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
1743 if (ctx
->Texture
.ProxyRect
)
1744 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
1745 if (ctx
->Texture
.Proxy1DArray
)
1746 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
1747 if (ctx
->Texture
.Proxy2DArray
)
1748 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
1754 * Initialize a texture unit.
1756 * \param ctx GL context.
1757 * \param unit texture unit number to be initialized.
1760 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
1762 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
1764 texUnit
->EnvMode
= GL_MODULATE
;
1765 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
1767 texUnit
->Combine
= default_combine_state
;
1768 texUnit
->_EnvMode
= default_combine_state
;
1769 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
1771 texUnit
->TexGenEnabled
= 0;
1772 texUnit
->GenModeS
= GL_EYE_LINEAR
;
1773 texUnit
->GenModeT
= GL_EYE_LINEAR
;
1774 texUnit
->GenModeR
= GL_EYE_LINEAR
;
1775 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
1776 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
1777 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
1778 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
1779 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
1781 /* Yes, these plane coefficients are correct! */
1782 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
1783 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
1784 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
1785 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
1786 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
1787 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
1788 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
1789 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
1791 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
1792 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
1793 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
1794 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
1795 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
1796 texUnit
->Current1DArray
= ctx
->Shared
->Default1DArray
;
1797 texUnit
->Current2DArray
= ctx
->Shared
->Default2DArray
;
1802 * Initialize texture state for the given context.
1805 _mesa_init_texture(GLcontext
*ctx
)
1809 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
1810 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
1812 /* Effectively bind the default textures to all texture units */
1813 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
1814 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
1815 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
1816 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
1817 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
1818 ctx
->Shared
->Default1DArray
->RefCount
+= MAX_TEXTURE_UNITS
;
1819 ctx
->Shared
->Default2DArray
->RefCount
+= MAX_TEXTURE_UNITS
;
1822 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
1823 ctx
->Texture
._EnabledUnits
= 0;
1824 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
1825 init_texture_unit( ctx
, i
);
1826 ctx
->Texture
.SharedPalette
= GL_FALSE
;
1827 #if FEATURE_colortable
1828 _mesa_init_colortable(&ctx
->Texture
.Palette
);
1831 /* Allocate proxy textures */
1832 if (!alloc_proxy_textures( ctx
))
1840 * Free dynamically-allocted texture data attached to the given context.
1843 _mesa_free_texture_data(GLcontext
*ctx
)
1845 /* Free proxy texture objects */
1846 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
1847 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
1848 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
1849 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
1850 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
1851 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
1852 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
1854 #if FEATURE_colortable
1857 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
1858 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);