2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * glTexParameter-related functions
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/enums.h"
36 #include "main/colormac.h"
37 #include "main/macros.h"
38 #include "main/texcompress.h"
39 #include "main/texparam.h"
40 #include "main/teximage.h"
41 #include "shader/prog_instruction.h"
45 * Check if a coordinate wrap mode is supported for the texture target.
46 * \return GL_TRUE if legal, GL_FALSE otherwise
49 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
51 const struct gl_extensions
* const e
= & ctx
->Extensions
;
53 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
54 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
55 /* any texture target */
58 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
60 (wrap
== GL_MIRRORED_REPEAT
&&
61 e
->ARB_texture_mirrored_repeat
) ||
62 (wrap
== GL_MIRROR_CLAMP_EXT
&&
63 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
64 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
65 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
66 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
67 (e
->EXT_texture_mirror_clamp
)))) {
68 /* non-rectangle texture */
72 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
78 * Get current texture object for given target.
79 * Return NULL if any error.
81 static struct gl_texture_object
*
82 get_texobj(GLcontext
*ctx
, GLenum target
)
84 struct gl_texture_unit
*texUnit
;
86 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
87 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(current unit)");
91 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
95 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
97 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
99 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
100 case GL_TEXTURE_CUBE_MAP
:
101 if (ctx
->Extensions
.ARB_texture_cube_map
) {
102 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
105 case GL_TEXTURE_RECTANGLE_NV
:
106 if (ctx
->Extensions
.NV_texture_rectangle
) {
107 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
110 case GL_TEXTURE_1D_ARRAY_EXT
:
111 if (ctx
->Extensions
.MESA_texture_array
) {
112 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
115 case GL_TEXTURE_2D_ARRAY_EXT
:
116 if (ctx
->Extensions
.MESA_texture_array
) {
117 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
124 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(target)");
130 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
131 * \return -1 if error.
134 comp_to_swizzle(GLenum comp
)
156 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
159 ASSERT(swz
<= SWIZZLE_NIL
);
161 GLuint mask
= 0x7 << (3 * comp
);
162 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
169 * This is called just prior to changing any texture object state.
170 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
171 * state flag and then mark the texture object as 'incomplete' so that any
172 * per-texture derived state gets recomputed.
175 flush(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
177 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
178 texObj
->_Complete
= GL_FALSE
;
182 /** Set an integer-valued texture parameter */
184 set_tex_parameteri(GLcontext
*ctx
,
185 struct gl_texture_object
*texObj
,
186 GLenum pname
, const GLint
*params
)
189 case GL_TEXTURE_MIN_FILTER
:
190 if (texObj
->MinFilter
== params
[0])
196 texObj
->MinFilter
= params
[0];
198 case GL_NEAREST_MIPMAP_NEAREST
:
199 case GL_LINEAR_MIPMAP_NEAREST
:
200 case GL_NEAREST_MIPMAP_LINEAR
:
201 case GL_LINEAR_MIPMAP_LINEAR
:
202 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
204 texObj
->MinFilter
= params
[0];
209 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
213 case GL_TEXTURE_MAG_FILTER
:
214 if (texObj
->MagFilter
== params
[0])
220 texObj
->MagFilter
= params
[0];
223 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
227 case GL_TEXTURE_WRAP_S
:
228 if (texObj
->WrapS
== params
[0])
230 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
232 texObj
->WrapS
= params
[0];
236 case GL_TEXTURE_WRAP_T
:
237 if (texObj
->WrapT
== params
[0])
239 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
241 texObj
->WrapT
= params
[0];
245 case GL_TEXTURE_WRAP_R
:
246 if (texObj
->WrapR
== params
[0])
248 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
250 texObj
->WrapR
= params
[0];
254 case GL_TEXTURE_BASE_LEVEL
:
255 if (texObj
->BaseLevel
== params
[0])
258 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
259 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
263 texObj
->BaseLevel
= params
[0];
266 case GL_TEXTURE_MAX_LEVEL
:
267 if (texObj
->MaxLevel
== params
[0])
269 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
270 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
274 texObj
->MaxLevel
= params
[0];
277 case GL_GENERATE_MIPMAP_SGIS
:
278 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
279 if (texObj
->GenerateMipmap
!= params
[0]) {
281 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
285 _mesa_error(ctx
, GL_INVALID_ENUM
,
286 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
290 case GL_TEXTURE_COMPARE_MODE_ARB
:
291 if (ctx
->Extensions
.ARB_shadow
&&
292 (params
[0] == GL_NONE
||
293 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
294 if (texObj
->CompareMode
!= params
[0]) {
296 texObj
->CompareMode
= params
[0];
300 _mesa_error(ctx
, GL_INVALID_ENUM
,
301 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
305 case GL_TEXTURE_COMPARE_FUNC_ARB
:
306 if (ctx
->Extensions
.ARB_shadow
) {
307 if (texObj
->CompareFunc
== params
[0])
313 texObj
->CompareFunc
= params
[0];
321 if (ctx
->Extensions
.EXT_shadow_funcs
) {
323 texObj
->CompareFunc
= params
[0];
328 _mesa_error(ctx
, GL_INVALID_ENUM
,
329 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
333 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
337 case GL_DEPTH_TEXTURE_MODE_ARB
:
338 if (ctx
->Extensions
.ARB_depth_texture
&&
339 (params
[0] == GL_LUMINANCE
||
340 params
[0] == GL_INTENSITY
||
341 params
[0] == GL_ALPHA
)) {
342 if (texObj
->DepthMode
!= params
[0]) {
344 texObj
->DepthMode
= params
[0];
348 _mesa_error(ctx
, GL_INVALID_ENUM
,
349 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
353 #ifdef FEATURE_OES_draw_texture
354 case GL_TEXTURE_CROP_RECT_OES
:
355 texObj
->CropRect
[0] = params
[0];
356 texObj
->CropRect
[1] = params
[1];
357 texObj
->CropRect
[2] = params
[2];
358 texObj
->CropRect
[3] = params
[3];
362 case GL_TEXTURE_SWIZZLE_R_EXT
:
363 case GL_TEXTURE_SWIZZLE_G_EXT
:
364 case GL_TEXTURE_SWIZZLE_B_EXT
:
365 case GL_TEXTURE_SWIZZLE_A_EXT
:
366 if (ctx
->Extensions
.EXT_texture_swizzle
) {
367 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
368 const GLint swz
= comp_to_swizzle(params
[0]);
370 _mesa_error(ctx
, GL_INVALID_OPERATION
,
371 "glTexParameter(swizzle 0x%x)", params
[0]);
377 texObj
->Swizzle
[comp
] = params
[0];
378 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
382 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
385 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
386 if (ctx
->Extensions
.EXT_texture_swizzle
) {
389 for (comp
= 0; comp
< 4; comp
++) {
390 const GLint swz
= comp_to_swizzle(params
[comp
]);
392 texObj
->Swizzle
[comp
] = params
[comp
];
393 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
397 "glTexParameter(swizzle 0x%x)", params
[comp
]);
403 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
407 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
412 /** Set a float-valued texture parameter */
414 set_tex_parameterf(GLcontext
*ctx
,
415 struct gl_texture_object
*texObj
,
416 GLenum pname
, const GLfloat
*params
)
419 case GL_TEXTURE_MIN_LOD
:
420 if (texObj
->MinLod
== params
[0])
423 texObj
->MinLod
= params
[0];
426 case GL_TEXTURE_MAX_LOD
:
427 if (texObj
->MaxLod
== params
[0])
430 texObj
->MaxLod
= params
[0];
433 case GL_TEXTURE_PRIORITY
:
435 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
438 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
439 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
440 if (texObj
->MaxAnisotropy
== params
[0])
442 if (params
[0] < 1.0) {
443 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
447 /* clamp to max, that's what NVIDIA does */
448 texObj
->MaxAnisotropy
= MIN2(params
[0],
449 ctx
->Const
.MaxTextureMaxAnisotropy
);
452 _mesa_error(ctx
, GL_INVALID_ENUM
,
453 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
457 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
458 if (ctx
->Extensions
.ARB_shadow_ambient
) {
459 if (texObj
->CompareFailValue
!= params
[0]) {
461 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
465 _mesa_error(ctx
, GL_INVALID_ENUM
,
466 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
470 case GL_TEXTURE_LOD_BIAS
:
471 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
472 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
473 if (texObj
->LodBias
!= params
[0]) {
475 texObj
->LodBias
= params
[0];
480 case GL_TEXTURE_BORDER_COLOR
:
482 texObj
->BorderColor
[RCOMP
] = params
[0];
483 texObj
->BorderColor
[GCOMP
] = params
[1];
484 texObj
->BorderColor
[BCOMP
] = params
[2];
485 texObj
->BorderColor
[ACOMP
] = params
[3];
489 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
495 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
497 struct gl_texture_object
*texObj
;
498 GET_CURRENT_CONTEXT(ctx
);
499 ASSERT_OUTSIDE_BEGIN_END(ctx
);
501 texObj
= get_texobj(ctx
, target
);
506 case GL_TEXTURE_MIN_FILTER
:
507 case GL_TEXTURE_MAG_FILTER
:
508 case GL_TEXTURE_WRAP_S
:
509 case GL_TEXTURE_WRAP_T
:
510 case GL_TEXTURE_WRAP_R
:
511 case GL_TEXTURE_BASE_LEVEL
:
512 case GL_TEXTURE_MAX_LEVEL
:
513 case GL_GENERATE_MIPMAP_SGIS
:
514 case GL_TEXTURE_COMPARE_MODE_ARB
:
515 case GL_TEXTURE_COMPARE_FUNC_ARB
:
516 case GL_DEPTH_TEXTURE_MODE_ARB
:
518 /* convert float param to int */
519 GLint p
= (GLint
) param
;
520 set_tex_parameteri(ctx
, texObj
, pname
, &p
);
524 /* this will generate an error if pname is illegal */
525 set_tex_parameterf(ctx
, texObj
, pname
, ¶m
);
528 if (ctx
->Driver
.TexParameter
&& ctx
->ErrorValue
== GL_NO_ERROR
) {
529 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
535 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
537 struct gl_texture_object
*texObj
;
538 GET_CURRENT_CONTEXT(ctx
);
539 ASSERT_OUTSIDE_BEGIN_END(ctx
);
541 texObj
= get_texobj(ctx
, target
);
546 case GL_TEXTURE_MIN_FILTER
:
547 case GL_TEXTURE_MAG_FILTER
:
548 case GL_TEXTURE_WRAP_S
:
549 case GL_TEXTURE_WRAP_T
:
550 case GL_TEXTURE_WRAP_R
:
551 case GL_TEXTURE_BASE_LEVEL
:
552 case GL_TEXTURE_MAX_LEVEL
:
553 case GL_GENERATE_MIPMAP_SGIS
:
554 case GL_TEXTURE_COMPARE_MODE_ARB
:
555 case GL_TEXTURE_COMPARE_FUNC_ARB
:
556 case GL_DEPTH_TEXTURE_MODE_ARB
:
558 /* convert float param to int */
559 GLint p
= (GLint
) params
[0];
560 set_tex_parameteri(ctx
, texObj
, pname
, &p
);
564 #ifdef FEATURE_OES_draw_texture
565 case GL_TEXTURE_CROP_RECT_OES
:
567 /* convert float params to int */
569 iparams
[0] = (GLint
) params
[0];
570 iparams
[1] = (GLint
) params
[1];
571 iparams
[2] = (GLint
) params
[2];
572 iparams
[3] = (GLint
) params
[3];
573 set_tex_parameteri(ctx
, target
, iparams
);
579 /* this will generate an error if pname is illegal */
580 set_tex_parameterf(ctx
, texObj
, pname
, params
);
583 if (ctx
->Driver
.TexParameter
&& ctx
->ErrorValue
== GL_NO_ERROR
) {
584 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
590 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
592 struct gl_texture_object
*texObj
;
593 GET_CURRENT_CONTEXT(ctx
);
594 ASSERT_OUTSIDE_BEGIN_END(ctx
);
596 texObj
= get_texobj(ctx
, target
);
601 case GL_TEXTURE_MIN_LOD
:
602 case GL_TEXTURE_MAX_LOD
:
603 case GL_TEXTURE_PRIORITY
:
604 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
605 case GL_TEXTURE_LOD_BIAS
:
606 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
608 GLfloat fparam
= (GLfloat
) param
;
609 /* convert int param to float */
610 set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
614 /* this will generate an error if pname is illegal */
615 set_tex_parameteri(ctx
, texObj
, pname
, ¶m
);
618 if (ctx
->Driver
.TexParameter
&& ctx
->ErrorValue
== GL_NO_ERROR
) {
619 GLfloat fparam
= (GLfloat
) param
;
620 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
626 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
628 struct gl_texture_object
*texObj
;
629 GET_CURRENT_CONTEXT(ctx
);
630 ASSERT_OUTSIDE_BEGIN_END(ctx
);
632 texObj
= get_texobj(ctx
, target
);
637 case GL_TEXTURE_BORDER_COLOR
:
639 /* convert int params to float */
641 fparams
[0] = INT_TO_FLOAT(params
[0]);
642 fparams
[1] = INT_TO_FLOAT(params
[1]);
643 fparams
[2] = INT_TO_FLOAT(params
[2]);
644 fparams
[3] = INT_TO_FLOAT(params
[3]);
645 set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
648 case GL_TEXTURE_MIN_LOD
:
649 case GL_TEXTURE_MAX_LOD
:
650 case GL_TEXTURE_PRIORITY
:
651 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
652 case GL_TEXTURE_LOD_BIAS
:
653 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
655 /* convert int param to float */
656 GLfloat fparam
= (GLfloat
) params
[0];
657 set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
661 /* this will generate an error if pname is illegal */
662 set_tex_parameteri(ctx
, texObj
, pname
, params
);
665 if (ctx
->Driver
.TexParameter
&& ctx
->ErrorValue
== GL_NO_ERROR
) {
667 fparams
[0] = INT_TO_FLOAT(params
[0]);
668 if (pname
== GL_TEXTURE_BORDER_COLOR
||
669 pname
== GL_TEXTURE_CROP_RECT_OES
) {
670 fparams
[1] = INT_TO_FLOAT(params
[1]);
671 fparams
[2] = INT_TO_FLOAT(params
[2]);
672 fparams
[3] = INT_TO_FLOAT(params
[3]);
674 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
680 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
681 GLenum pname
, GLfloat
*params
)
684 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
685 *params
= (GLfloat
) iparam
;
690 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
694 case GL_PROXY_TEXTURE_1D
:
697 case GL_PROXY_TEXTURE_2D
:
700 case GL_PROXY_TEXTURE_3D
:
702 case GL_TEXTURE_CUBE_MAP
:
703 case GL_PROXY_TEXTURE_CUBE_MAP
:
704 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
705 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
706 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
707 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
708 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
709 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
710 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
711 case GL_TEXTURE_RECTANGLE_NV
:
712 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
713 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
714 case GL_TEXTURE_1D_ARRAY_EXT
:
715 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
716 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
717 case GL_TEXTURE_2D_ARRAY_EXT
:
718 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
719 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
721 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
728 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
729 GLenum pname
, GLint
*params
)
731 const struct gl_texture_unit
*texUnit
;
732 struct gl_texture_object
*texObj
;
733 const struct gl_texture_image
*img
= NULL
;
737 GET_CURRENT_CONTEXT(ctx
);
738 ASSERT_OUTSIDE_BEGIN_END(ctx
);
740 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
741 _mesa_error(ctx
, GL_INVALID_OPERATION
,
742 "glGetTexLevelParameteriv(current unit)");
746 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
748 /* this will catch bad target values */
749 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
750 if (dimensions
== 0) {
751 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
755 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
756 if (maxLevels
== 0) {
757 /* should not happen since <target> was just checked above */
758 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
762 if (level
< 0 || level
>= maxLevels
) {
763 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
767 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
768 _mesa_lock_texture(ctx
, texObj
);
770 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
771 if (!img
|| !img
->TexFormat
) {
772 /* undefined texture image */
773 if (pname
== GL_TEXTURE_COMPONENTS
)
780 isProxy
= _mesa_is_proxy_texture(target
);
783 case GL_TEXTURE_WIDTH
:
784 *params
= img
->Width
;
786 case GL_TEXTURE_HEIGHT
:
787 *params
= img
->Height
;
789 case GL_TEXTURE_DEPTH
:
790 *params
= img
->Depth
;
792 case GL_TEXTURE_INTERNAL_FORMAT
:
793 *params
= img
->InternalFormat
;
795 case GL_TEXTURE_BORDER
:
796 *params
= img
->Border
;
798 case GL_TEXTURE_RED_SIZE
:
799 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
800 *params
= img
->TexFormat
->RedBits
;
804 case GL_TEXTURE_GREEN_SIZE
:
805 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
806 *params
= img
->TexFormat
->GreenBits
;
810 case GL_TEXTURE_BLUE_SIZE
:
811 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
812 *params
= img
->TexFormat
->BlueBits
;
816 case GL_TEXTURE_ALPHA_SIZE
:
817 if (img
->_BaseFormat
== GL_ALPHA
||
818 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
819 img
->_BaseFormat
== GL_RGBA
)
820 *params
= img
->TexFormat
->AlphaBits
;
824 case GL_TEXTURE_INTENSITY_SIZE
:
825 if (img
->_BaseFormat
!= GL_INTENSITY
)
827 else if (img
->TexFormat
->IntensityBits
> 0)
828 *params
= img
->TexFormat
->IntensityBits
;
829 else /* intensity probably stored as rgb texture */
830 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
832 case GL_TEXTURE_LUMINANCE_SIZE
:
833 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
834 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
836 else if (img
->TexFormat
->LuminanceBits
> 0)
837 *params
= img
->TexFormat
->LuminanceBits
;
838 else /* luminance probably stored as rgb texture */
839 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
841 case GL_TEXTURE_INDEX_SIZE_EXT
:
842 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
843 *params
= img
->TexFormat
->IndexBits
;
847 case GL_TEXTURE_DEPTH_SIZE_ARB
:
848 if (ctx
->Extensions
.ARB_depth_texture
)
849 *params
= img
->TexFormat
->DepthBits
;
851 _mesa_error(ctx
, GL_INVALID_ENUM
,
852 "glGetTexLevelParameter[if]v(pname)");
854 case GL_TEXTURE_STENCIL_SIZE_EXT
:
855 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
856 *params
= img
->TexFormat
->StencilBits
;
859 _mesa_error(ctx
, GL_INVALID_ENUM
,
860 "glGetTexLevelParameter[if]v(pname)");
864 /* GL_ARB_texture_compression */
865 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
866 if (img
->IsCompressed
&& !isProxy
) {
867 /* Don't use ctx->Driver.CompressedTextureSize() since that
868 * may returned a padded hardware size.
870 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
871 img
->Height
, img
->Depth
,
872 img
->TexFormat
->MesaFormat
);
875 _mesa_error(ctx
, GL_INVALID_OPERATION
,
876 "glGetTexLevelParameter[if]v(pname)");
879 case GL_TEXTURE_COMPRESSED
:
880 *params
= (GLint
) img
->IsCompressed
;
883 /* GL_ARB_texture_float */
884 case GL_TEXTURE_RED_TYPE_ARB
:
885 if (ctx
->Extensions
.ARB_texture_float
) {
886 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
889 _mesa_error(ctx
, GL_INVALID_ENUM
,
890 "glGetTexLevelParameter[if]v(pname)");
893 case GL_TEXTURE_GREEN_TYPE_ARB
:
894 if (ctx
->Extensions
.ARB_texture_float
) {
895 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
898 _mesa_error(ctx
, GL_INVALID_ENUM
,
899 "glGetTexLevelParameter[if]v(pname)");
902 case GL_TEXTURE_BLUE_TYPE_ARB
:
903 if (ctx
->Extensions
.ARB_texture_float
) {
904 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
907 _mesa_error(ctx
, GL_INVALID_ENUM
,
908 "glGetTexLevelParameter[if]v(pname)");
911 case GL_TEXTURE_ALPHA_TYPE_ARB
:
912 if (ctx
->Extensions
.ARB_texture_float
) {
913 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
916 _mesa_error(ctx
, GL_INVALID_ENUM
,
917 "glGetTexLevelParameter[if]v(pname)");
920 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
921 if (ctx
->Extensions
.ARB_texture_float
) {
922 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
925 _mesa_error(ctx
, GL_INVALID_ENUM
,
926 "glGetTexLevelParameter[if]v(pname)");
929 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
930 if (ctx
->Extensions
.ARB_texture_float
) {
931 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
934 _mesa_error(ctx
, GL_INVALID_ENUM
,
935 "glGetTexLevelParameter[if]v(pname)");
938 case GL_TEXTURE_DEPTH_TYPE_ARB
:
939 if (ctx
->Extensions
.ARB_texture_float
) {
940 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
943 _mesa_error(ctx
, GL_INVALID_ENUM
,
944 "glGetTexLevelParameter[if]v(pname)");
949 _mesa_error(ctx
, GL_INVALID_ENUM
,
950 "glGetTexLevelParameter[if]v(pname)");
954 _mesa_unlock_texture(ctx
, texObj
);
960 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
962 struct gl_texture_unit
*texUnit
;
963 struct gl_texture_object
*obj
;
964 GLboolean error
= GL_FALSE
;
965 GET_CURRENT_CONTEXT(ctx
);
966 ASSERT_OUTSIDE_BEGIN_END(ctx
);
968 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
969 _mesa_error(ctx
, GL_INVALID_OPERATION
,
970 "glGetTexParameterfv(current unit)");
974 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
976 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
978 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
982 _mesa_lock_texture(ctx
, obj
);
984 case GL_TEXTURE_MAG_FILTER
:
985 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
987 case GL_TEXTURE_MIN_FILTER
:
988 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
990 case GL_TEXTURE_WRAP_S
:
991 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
993 case GL_TEXTURE_WRAP_T
:
994 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
996 case GL_TEXTURE_WRAP_R
:
997 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
999 case GL_TEXTURE_BORDER_COLOR
:
1000 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1001 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1002 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1003 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1005 case GL_TEXTURE_RESIDENT
:
1008 if (ctx
->Driver
.IsTextureResident
)
1009 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1012 *params
= ENUM_TO_FLOAT(resident
);
1015 case GL_TEXTURE_PRIORITY
:
1016 *params
= obj
->Priority
;
1018 case GL_TEXTURE_MIN_LOD
:
1019 *params
= obj
->MinLod
;
1021 case GL_TEXTURE_MAX_LOD
:
1022 *params
= obj
->MaxLod
;
1024 case GL_TEXTURE_BASE_LEVEL
:
1025 *params
= (GLfloat
) obj
->BaseLevel
;
1027 case GL_TEXTURE_MAX_LEVEL
:
1028 *params
= (GLfloat
) obj
->MaxLevel
;
1030 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1031 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1032 *params
= obj
->MaxAnisotropy
;
1037 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1038 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1039 *params
= obj
->CompareFailValue
;
1044 case GL_GENERATE_MIPMAP_SGIS
:
1045 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1046 *params
= (GLfloat
) obj
->GenerateMipmap
;
1051 case GL_TEXTURE_COMPARE_MODE_ARB
:
1052 if (ctx
->Extensions
.ARB_shadow
) {
1053 *params
= (GLfloat
) obj
->CompareMode
;
1058 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1059 if (ctx
->Extensions
.ARB_shadow
) {
1060 *params
= (GLfloat
) obj
->CompareFunc
;
1065 case GL_DEPTH_TEXTURE_MODE_ARB
:
1066 if (ctx
->Extensions
.ARB_depth_texture
) {
1067 *params
= (GLfloat
) obj
->DepthMode
;
1072 case GL_TEXTURE_LOD_BIAS
:
1073 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1074 *params
= obj
->LodBias
;
1079 #ifdef FEATURE_OES_draw_texture
1080 case GL_TEXTURE_CROP_RECT_OES
:
1081 params
[0] = obj
->CropRect
[0];
1082 params
[1] = obj
->CropRect
[1];
1083 params
[2] = obj
->CropRect
[2];
1084 params
[3] = obj
->CropRect
[3];
1088 case GL_TEXTURE_SWIZZLE_R_EXT
:
1089 case GL_TEXTURE_SWIZZLE_G_EXT
:
1090 case GL_TEXTURE_SWIZZLE_B_EXT
:
1091 case GL_TEXTURE_SWIZZLE_A_EXT
:
1092 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1093 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1094 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1101 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1102 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1104 for (comp
= 0; comp
< 4; comp
++) {
1105 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1119 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1122 _mesa_unlock_texture(ctx
, obj
);
1127 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1129 struct gl_texture_unit
*texUnit
;
1130 struct gl_texture_object
*obj
;
1131 GLboolean error
= GL_FALSE
;
1132 GET_CURRENT_CONTEXT(ctx
);
1133 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1135 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1136 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1137 "glGetTexParameteriv(current unit)");
1141 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1143 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1145 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1150 case GL_TEXTURE_MAG_FILTER
:
1151 *params
= (GLint
) obj
->MagFilter
;
1153 case GL_TEXTURE_MIN_FILTER
:
1154 *params
= (GLint
) obj
->MinFilter
;
1156 case GL_TEXTURE_WRAP_S
:
1157 *params
= (GLint
) obj
->WrapS
;
1159 case GL_TEXTURE_WRAP_T
:
1160 *params
= (GLint
) obj
->WrapT
;
1162 case GL_TEXTURE_WRAP_R
:
1163 *params
= (GLint
) obj
->WrapR
;
1165 case GL_TEXTURE_BORDER_COLOR
:
1168 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1169 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1170 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1171 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1172 params
[0] = FLOAT_TO_INT(b
[0]);
1173 params
[1] = FLOAT_TO_INT(b
[1]);
1174 params
[2] = FLOAT_TO_INT(b
[2]);
1175 params
[3] = FLOAT_TO_INT(b
[3]);
1178 case GL_TEXTURE_RESIDENT
:
1181 if (ctx
->Driver
.IsTextureResident
)
1182 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1185 *params
= (GLint
) resident
;
1188 case GL_TEXTURE_PRIORITY
:
1189 *params
= FLOAT_TO_INT(obj
->Priority
);
1191 case GL_TEXTURE_MIN_LOD
:
1192 *params
= (GLint
) obj
->MinLod
;
1194 case GL_TEXTURE_MAX_LOD
:
1195 *params
= (GLint
) obj
->MaxLod
;
1197 case GL_TEXTURE_BASE_LEVEL
:
1198 *params
= obj
->BaseLevel
;
1200 case GL_TEXTURE_MAX_LEVEL
:
1201 *params
= obj
->MaxLevel
;
1203 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1204 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1205 *params
= (GLint
) obj
->MaxAnisotropy
;
1211 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1212 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1213 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1219 case GL_GENERATE_MIPMAP_SGIS
:
1220 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1221 *params
= (GLint
) obj
->GenerateMipmap
;
1227 case GL_TEXTURE_COMPARE_MODE_ARB
:
1228 if (ctx
->Extensions
.ARB_shadow
) {
1229 *params
= (GLint
) obj
->CompareMode
;
1235 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1236 if (ctx
->Extensions
.ARB_shadow
) {
1237 *params
= (GLint
) obj
->CompareFunc
;
1243 case GL_DEPTH_TEXTURE_MODE_ARB
:
1244 if (ctx
->Extensions
.ARB_depth_texture
) {
1245 *params
= (GLint
) obj
->DepthMode
;
1251 case GL_TEXTURE_LOD_BIAS
:
1252 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1253 *params
= (GLint
) obj
->LodBias
;
1259 #ifdef FEATURE_OES_draw_texture
1260 case GL_TEXTURE_CROP_RECT_OES
:
1261 params
[0] = obj
->CropRect
[0];
1262 params
[1] = obj
->CropRect
[1];
1263 params
[2] = obj
->CropRect
[2];
1264 params
[3] = obj
->CropRect
[3];
1267 case GL_TEXTURE_SWIZZLE_R_EXT
:
1268 case GL_TEXTURE_SWIZZLE_G_EXT
:
1269 case GL_TEXTURE_SWIZZLE_B_EXT
:
1270 case GL_TEXTURE_SWIZZLE_A_EXT
:
1271 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1272 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1273 *params
= obj
->Swizzle
[comp
];
1280 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1281 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1282 COPY_4V(params
, obj
->Swizzle
);
1290 ; /* silence warnings */
1294 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1297 _mesa_unlock_texture(ctx
, obj
);