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
;
183 * Set an integer-valued texture parameter
184 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
187 set_tex_parameteri(GLcontext
*ctx
,
188 struct gl_texture_object
*texObj
,
189 GLenum pname
, const GLint
*params
)
192 case GL_TEXTURE_MIN_FILTER
:
193 if (texObj
->MinFilter
== params
[0])
199 texObj
->MinFilter
= params
[0];
201 case GL_NEAREST_MIPMAP_NEAREST
:
202 case GL_LINEAR_MIPMAP_NEAREST
:
203 case GL_NEAREST_MIPMAP_LINEAR
:
204 case GL_LINEAR_MIPMAP_LINEAR
:
205 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
207 texObj
->MinFilter
= params
[0];
212 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
216 case GL_TEXTURE_MAG_FILTER
:
217 if (texObj
->MagFilter
== params
[0])
223 texObj
->MagFilter
= params
[0];
226 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
230 case GL_TEXTURE_WRAP_S
:
231 if (texObj
->WrapS
== params
[0])
233 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
235 texObj
->WrapS
= params
[0];
240 case GL_TEXTURE_WRAP_T
:
241 if (texObj
->WrapT
== params
[0])
243 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
245 texObj
->WrapT
= params
[0];
250 case GL_TEXTURE_WRAP_R
:
251 if (texObj
->WrapR
== params
[0])
253 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
255 texObj
->WrapR
= params
[0];
260 case GL_TEXTURE_BASE_LEVEL
:
261 if (texObj
->BaseLevel
== params
[0])
264 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
265 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
269 texObj
->BaseLevel
= params
[0];
272 case GL_TEXTURE_MAX_LEVEL
:
273 if (texObj
->MaxLevel
== params
[0])
275 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
276 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
280 texObj
->MaxLevel
= params
[0];
283 case GL_GENERATE_MIPMAP_SGIS
:
284 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
285 if (texObj
->GenerateMipmap
!= params
[0]) {
287 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
293 _mesa_error(ctx
, GL_INVALID_ENUM
,
294 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
298 case GL_TEXTURE_COMPARE_MODE_ARB
:
299 if (ctx
->Extensions
.ARB_shadow
&&
300 (params
[0] == GL_NONE
||
301 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
302 if (texObj
->CompareMode
!= params
[0]) {
304 texObj
->CompareMode
= params
[0];
310 _mesa_error(ctx
, GL_INVALID_ENUM
,
311 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
315 case GL_TEXTURE_COMPARE_FUNC_ARB
:
316 if (ctx
->Extensions
.ARB_shadow
) {
317 if (texObj
->CompareFunc
== params
[0])
323 texObj
->CompareFunc
= params
[0];
331 if (ctx
->Extensions
.EXT_shadow_funcs
) {
333 texObj
->CompareFunc
= params
[0];
338 _mesa_error(ctx
, GL_INVALID_ENUM
,
339 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
343 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
347 case GL_DEPTH_TEXTURE_MODE_ARB
:
348 if (ctx
->Extensions
.ARB_depth_texture
&&
349 (params
[0] == GL_LUMINANCE
||
350 params
[0] == GL_INTENSITY
||
351 params
[0] == GL_ALPHA
)) {
352 if (texObj
->DepthMode
!= params
[0]) {
354 texObj
->DepthMode
= params
[0];
359 _mesa_error(ctx
, GL_INVALID_ENUM
,
360 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
364 #ifdef FEATURE_OES_draw_texture
365 case GL_TEXTURE_CROP_RECT_OES
:
366 texObj
->CropRect
[0] = params
[0];
367 texObj
->CropRect
[1] = params
[1];
368 texObj
->CropRect
[2] = params
[2];
369 texObj
->CropRect
[3] = params
[3];
373 case GL_TEXTURE_SWIZZLE_R_EXT
:
374 case GL_TEXTURE_SWIZZLE_G_EXT
:
375 case GL_TEXTURE_SWIZZLE_B_EXT
:
376 case GL_TEXTURE_SWIZZLE_A_EXT
:
377 if (ctx
->Extensions
.EXT_texture_swizzle
) {
378 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
379 const GLint swz
= comp_to_swizzle(params
[0]);
381 _mesa_error(ctx
, GL_INVALID_OPERATION
,
382 "glTexParameter(swizzle 0x%x)", params
[0]);
388 texObj
->Swizzle
[comp
] = params
[0];
389 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
393 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
396 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
397 if (ctx
->Extensions
.EXT_texture_swizzle
) {
400 for (comp
= 0; comp
< 4; comp
++) {
401 const GLint swz
= comp_to_swizzle(params
[comp
]);
403 texObj
->Swizzle
[comp
] = params
[comp
];
404 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
407 _mesa_error(ctx
, GL_INVALID_OPERATION
,
408 "glTexParameter(swizzle 0x%x)", params
[comp
]);
414 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
418 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
425 * Set a float-valued texture parameter
426 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
429 set_tex_parameterf(GLcontext
*ctx
,
430 struct gl_texture_object
*texObj
,
431 GLenum pname
, const GLfloat
*params
)
434 case GL_TEXTURE_MIN_LOD
:
435 if (texObj
->MinLod
== params
[0])
438 texObj
->MinLod
= params
[0];
441 case GL_TEXTURE_MAX_LOD
:
442 if (texObj
->MaxLod
== params
[0])
445 texObj
->MaxLod
= params
[0];
448 case GL_TEXTURE_PRIORITY
:
450 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
453 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
454 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
455 if (texObj
->MaxAnisotropy
== params
[0])
457 if (params
[0] < 1.0) {
458 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
462 /* clamp to max, that's what NVIDIA does */
463 texObj
->MaxAnisotropy
= MIN2(params
[0],
464 ctx
->Const
.MaxTextureMaxAnisotropy
);
468 _mesa_error(ctx
, GL_INVALID_ENUM
,
469 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
473 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
474 if (ctx
->Extensions
.ARB_shadow_ambient
) {
475 if (texObj
->CompareFailValue
!= params
[0]) {
477 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
482 _mesa_error(ctx
, GL_INVALID_ENUM
,
483 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
487 case GL_TEXTURE_LOD_BIAS
:
488 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
489 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
490 if (texObj
->LodBias
!= params
[0]) {
492 texObj
->LodBias
= params
[0];
499 case GL_TEXTURE_BORDER_COLOR
:
501 texObj
->BorderColor
[RCOMP
] = params
[0];
502 texObj
->BorderColor
[GCOMP
] = params
[1];
503 texObj
->BorderColor
[BCOMP
] = params
[2];
504 texObj
->BorderColor
[ACOMP
] = params
[3];
508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
515 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
517 GLboolean need_update
;
518 struct gl_texture_object
*texObj
;
519 GET_CURRENT_CONTEXT(ctx
);
520 ASSERT_OUTSIDE_BEGIN_END(ctx
);
522 texObj
= get_texobj(ctx
, target
);
527 case GL_TEXTURE_MIN_FILTER
:
528 case GL_TEXTURE_MAG_FILTER
:
529 case GL_TEXTURE_WRAP_S
:
530 case GL_TEXTURE_WRAP_T
:
531 case GL_TEXTURE_WRAP_R
:
532 case GL_TEXTURE_BASE_LEVEL
:
533 case GL_TEXTURE_MAX_LEVEL
:
534 case GL_GENERATE_MIPMAP_SGIS
:
535 case GL_TEXTURE_COMPARE_MODE_ARB
:
536 case GL_TEXTURE_COMPARE_FUNC_ARB
:
537 case GL_DEPTH_TEXTURE_MODE_ARB
:
539 /* convert float param to int */
540 GLint p
= (GLint
) param
;
541 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
545 /* this will generate an error if pname is illegal */
546 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, ¶m
);
549 if (ctx
->Driver
.TexParameter
&& need_update
) {
550 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
556 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
558 GLboolean need_update
;
559 struct gl_texture_object
*texObj
;
560 GET_CURRENT_CONTEXT(ctx
);
561 ASSERT_OUTSIDE_BEGIN_END(ctx
);
563 texObj
= get_texobj(ctx
, target
);
568 case GL_TEXTURE_MIN_FILTER
:
569 case GL_TEXTURE_MAG_FILTER
:
570 case GL_TEXTURE_WRAP_S
:
571 case GL_TEXTURE_WRAP_T
:
572 case GL_TEXTURE_WRAP_R
:
573 case GL_TEXTURE_BASE_LEVEL
:
574 case GL_TEXTURE_MAX_LEVEL
:
575 case GL_GENERATE_MIPMAP_SGIS
:
576 case GL_TEXTURE_COMPARE_MODE_ARB
:
577 case GL_TEXTURE_COMPARE_FUNC_ARB
:
578 case GL_DEPTH_TEXTURE_MODE_ARB
:
580 /* convert float param to int */
581 GLint p
= (GLint
) params
[0];
582 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
586 #ifdef FEATURE_OES_draw_texture
587 case GL_TEXTURE_CROP_RECT_OES
:
589 /* convert float params to int */
591 iparams
[0] = (GLint
) params
[0];
592 iparams
[1] = (GLint
) params
[1];
593 iparams
[2] = (GLint
) params
[2];
594 iparams
[3] = (GLint
) params
[3];
595 need_update
= set_tex_parameteri(ctx
, target
, iparams
);
601 /* this will generate an error if pname is illegal */
602 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
605 if (ctx
->Driver
.TexParameter
&& need_update
) {
606 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
612 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
614 GLboolean need_update
;
615 struct gl_texture_object
*texObj
;
616 GET_CURRENT_CONTEXT(ctx
);
617 ASSERT_OUTSIDE_BEGIN_END(ctx
);
619 texObj
= get_texobj(ctx
, target
);
624 case GL_TEXTURE_MIN_LOD
:
625 case GL_TEXTURE_MAX_LOD
:
626 case GL_TEXTURE_PRIORITY
:
627 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
628 case GL_TEXTURE_LOD_BIAS
:
629 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
631 GLfloat fparam
= (GLfloat
) param
;
632 /* convert int param to float */
633 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
637 /* this will generate an error if pname is illegal */
638 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, ¶m
);
641 if (ctx
->Driver
.TexParameter
&& need_update
) {
642 GLfloat fparam
= (GLfloat
) param
;
643 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
649 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
651 GLboolean need_update
;
652 struct gl_texture_object
*texObj
;
653 GET_CURRENT_CONTEXT(ctx
);
654 ASSERT_OUTSIDE_BEGIN_END(ctx
);
656 texObj
= get_texobj(ctx
, target
);
661 case GL_TEXTURE_BORDER_COLOR
:
663 /* convert int params to float */
665 fparams
[0] = INT_TO_FLOAT(params
[0]);
666 fparams
[1] = INT_TO_FLOAT(params
[1]);
667 fparams
[2] = INT_TO_FLOAT(params
[2]);
668 fparams
[3] = INT_TO_FLOAT(params
[3]);
669 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
672 case GL_TEXTURE_MIN_LOD
:
673 case GL_TEXTURE_MAX_LOD
:
674 case GL_TEXTURE_PRIORITY
:
675 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
676 case GL_TEXTURE_LOD_BIAS
:
677 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
679 /* convert int param to float */
680 GLfloat fparam
= (GLfloat
) params
[0];
681 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
685 /* this will generate an error if pname is illegal */
686 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
689 if (ctx
->Driver
.TexParameter
&& need_update
) {
691 fparams
[0] = INT_TO_FLOAT(params
[0]);
692 if (pname
== GL_TEXTURE_BORDER_COLOR
||
693 pname
== GL_TEXTURE_CROP_RECT_OES
) {
694 fparams
[1] = INT_TO_FLOAT(params
[1]);
695 fparams
[2] = INT_TO_FLOAT(params
[2]);
696 fparams
[3] = INT_TO_FLOAT(params
[3]);
698 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
704 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
705 GLenum pname
, GLfloat
*params
)
708 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
709 *params
= (GLfloat
) iparam
;
714 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
718 case GL_PROXY_TEXTURE_1D
:
721 case GL_PROXY_TEXTURE_2D
:
724 case GL_PROXY_TEXTURE_3D
:
726 case GL_TEXTURE_CUBE_MAP
:
727 case GL_PROXY_TEXTURE_CUBE_MAP
:
728 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
729 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
730 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
731 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
732 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
733 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
734 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
735 case GL_TEXTURE_RECTANGLE_NV
:
736 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
737 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
738 case GL_TEXTURE_1D_ARRAY_EXT
:
739 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
740 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
741 case GL_TEXTURE_2D_ARRAY_EXT
:
742 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
743 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
745 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
752 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
753 GLenum pname
, GLint
*params
)
755 const struct gl_texture_unit
*texUnit
;
756 struct gl_texture_object
*texObj
;
757 const struct gl_texture_image
*img
= NULL
;
761 GET_CURRENT_CONTEXT(ctx
);
762 ASSERT_OUTSIDE_BEGIN_END(ctx
);
764 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
765 _mesa_error(ctx
, GL_INVALID_OPERATION
,
766 "glGetTexLevelParameteriv(current unit)");
770 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
772 /* this will catch bad target values */
773 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
774 if (dimensions
== 0) {
775 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
779 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
780 if (maxLevels
== 0) {
781 /* should not happen since <target> was just checked above */
782 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
786 if (level
< 0 || level
>= maxLevels
) {
787 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
791 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
792 _mesa_lock_texture(ctx
, texObj
);
794 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
795 if (!img
|| !img
->TexFormat
) {
796 /* undefined texture image */
797 if (pname
== GL_TEXTURE_COMPONENTS
)
804 isProxy
= _mesa_is_proxy_texture(target
);
807 case GL_TEXTURE_WIDTH
:
808 *params
= img
->Width
;
810 case GL_TEXTURE_HEIGHT
:
811 *params
= img
->Height
;
813 case GL_TEXTURE_DEPTH
:
814 *params
= img
->Depth
;
816 case GL_TEXTURE_INTERNAL_FORMAT
:
817 *params
= img
->InternalFormat
;
819 case GL_TEXTURE_BORDER
:
820 *params
= img
->Border
;
822 case GL_TEXTURE_RED_SIZE
:
823 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
824 *params
= img
->TexFormat
->RedBits
;
828 case GL_TEXTURE_GREEN_SIZE
:
829 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
830 *params
= img
->TexFormat
->GreenBits
;
834 case GL_TEXTURE_BLUE_SIZE
:
835 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
836 *params
= img
->TexFormat
->BlueBits
;
840 case GL_TEXTURE_ALPHA_SIZE
:
841 if (img
->_BaseFormat
== GL_ALPHA
||
842 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
843 img
->_BaseFormat
== GL_RGBA
)
844 *params
= img
->TexFormat
->AlphaBits
;
848 case GL_TEXTURE_INTENSITY_SIZE
:
849 if (img
->_BaseFormat
!= GL_INTENSITY
)
851 else if (img
->TexFormat
->IntensityBits
> 0)
852 *params
= img
->TexFormat
->IntensityBits
;
853 else /* intensity probably stored as rgb texture */
854 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
856 case GL_TEXTURE_LUMINANCE_SIZE
:
857 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
858 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
860 else if (img
->TexFormat
->LuminanceBits
> 0)
861 *params
= img
->TexFormat
->LuminanceBits
;
862 else /* luminance probably stored as rgb texture */
863 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
865 case GL_TEXTURE_INDEX_SIZE_EXT
:
866 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
867 *params
= img
->TexFormat
->IndexBits
;
871 case GL_TEXTURE_DEPTH_SIZE_ARB
:
872 if (ctx
->Extensions
.ARB_depth_texture
)
873 *params
= img
->TexFormat
->DepthBits
;
875 _mesa_error(ctx
, GL_INVALID_ENUM
,
876 "glGetTexLevelParameter[if]v(pname)");
878 case GL_TEXTURE_STENCIL_SIZE_EXT
:
879 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
880 *params
= img
->TexFormat
->StencilBits
;
883 _mesa_error(ctx
, GL_INVALID_ENUM
,
884 "glGetTexLevelParameter[if]v(pname)");
888 /* GL_ARB_texture_compression */
889 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
890 if (img
->IsCompressed
&& !isProxy
) {
891 /* Don't use ctx->Driver.CompressedTextureSize() since that
892 * may returned a padded hardware size.
894 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
895 img
->Height
, img
->Depth
,
896 img
->TexFormat
->MesaFormat
);
899 _mesa_error(ctx
, GL_INVALID_OPERATION
,
900 "glGetTexLevelParameter[if]v(pname)");
903 case GL_TEXTURE_COMPRESSED
:
904 *params
= (GLint
) img
->IsCompressed
;
907 /* GL_ARB_texture_float */
908 case GL_TEXTURE_RED_TYPE_ARB
:
909 if (ctx
->Extensions
.ARB_texture_float
) {
910 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
913 _mesa_error(ctx
, GL_INVALID_ENUM
,
914 "glGetTexLevelParameter[if]v(pname)");
917 case GL_TEXTURE_GREEN_TYPE_ARB
:
918 if (ctx
->Extensions
.ARB_texture_float
) {
919 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
922 _mesa_error(ctx
, GL_INVALID_ENUM
,
923 "glGetTexLevelParameter[if]v(pname)");
926 case GL_TEXTURE_BLUE_TYPE_ARB
:
927 if (ctx
->Extensions
.ARB_texture_float
) {
928 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
931 _mesa_error(ctx
, GL_INVALID_ENUM
,
932 "glGetTexLevelParameter[if]v(pname)");
935 case GL_TEXTURE_ALPHA_TYPE_ARB
:
936 if (ctx
->Extensions
.ARB_texture_float
) {
937 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
940 _mesa_error(ctx
, GL_INVALID_ENUM
,
941 "glGetTexLevelParameter[if]v(pname)");
944 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
945 if (ctx
->Extensions
.ARB_texture_float
) {
946 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
949 _mesa_error(ctx
, GL_INVALID_ENUM
,
950 "glGetTexLevelParameter[if]v(pname)");
953 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
954 if (ctx
->Extensions
.ARB_texture_float
) {
955 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
958 _mesa_error(ctx
, GL_INVALID_ENUM
,
959 "glGetTexLevelParameter[if]v(pname)");
962 case GL_TEXTURE_DEPTH_TYPE_ARB
:
963 if (ctx
->Extensions
.ARB_texture_float
) {
964 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
967 _mesa_error(ctx
, GL_INVALID_ENUM
,
968 "glGetTexLevelParameter[if]v(pname)");
973 _mesa_error(ctx
, GL_INVALID_ENUM
,
974 "glGetTexLevelParameter[if]v(pname)");
978 _mesa_unlock_texture(ctx
, texObj
);
984 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
986 struct gl_texture_unit
*texUnit
;
987 struct gl_texture_object
*obj
;
988 GLboolean error
= GL_FALSE
;
989 GET_CURRENT_CONTEXT(ctx
);
990 ASSERT_OUTSIDE_BEGIN_END(ctx
);
992 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
994 "glGetTexParameterfv(current unit)");
998 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1000 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1002 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1006 _mesa_lock_texture(ctx
, obj
);
1008 case GL_TEXTURE_MAG_FILTER
:
1009 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1011 case GL_TEXTURE_MIN_FILTER
:
1012 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1014 case GL_TEXTURE_WRAP_S
:
1015 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1017 case GL_TEXTURE_WRAP_T
:
1018 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1020 case GL_TEXTURE_WRAP_R
:
1021 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1023 case GL_TEXTURE_BORDER_COLOR
:
1024 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1025 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1026 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1027 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1029 case GL_TEXTURE_RESIDENT
:
1032 if (ctx
->Driver
.IsTextureResident
)
1033 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1036 *params
= ENUM_TO_FLOAT(resident
);
1039 case GL_TEXTURE_PRIORITY
:
1040 *params
= obj
->Priority
;
1042 case GL_TEXTURE_MIN_LOD
:
1043 *params
= obj
->MinLod
;
1045 case GL_TEXTURE_MAX_LOD
:
1046 *params
= obj
->MaxLod
;
1048 case GL_TEXTURE_BASE_LEVEL
:
1049 *params
= (GLfloat
) obj
->BaseLevel
;
1051 case GL_TEXTURE_MAX_LEVEL
:
1052 *params
= (GLfloat
) obj
->MaxLevel
;
1054 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1055 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1056 *params
= obj
->MaxAnisotropy
;
1061 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1062 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1063 *params
= obj
->CompareFailValue
;
1068 case GL_GENERATE_MIPMAP_SGIS
:
1069 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1070 *params
= (GLfloat
) obj
->GenerateMipmap
;
1075 case GL_TEXTURE_COMPARE_MODE_ARB
:
1076 if (ctx
->Extensions
.ARB_shadow
) {
1077 *params
= (GLfloat
) obj
->CompareMode
;
1082 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1083 if (ctx
->Extensions
.ARB_shadow
) {
1084 *params
= (GLfloat
) obj
->CompareFunc
;
1089 case GL_DEPTH_TEXTURE_MODE_ARB
:
1090 if (ctx
->Extensions
.ARB_depth_texture
) {
1091 *params
= (GLfloat
) obj
->DepthMode
;
1096 case GL_TEXTURE_LOD_BIAS
:
1097 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1098 *params
= obj
->LodBias
;
1103 #ifdef FEATURE_OES_draw_texture
1104 case GL_TEXTURE_CROP_RECT_OES
:
1105 params
[0] = obj
->CropRect
[0];
1106 params
[1] = obj
->CropRect
[1];
1107 params
[2] = obj
->CropRect
[2];
1108 params
[3] = obj
->CropRect
[3];
1112 case GL_TEXTURE_SWIZZLE_R_EXT
:
1113 case GL_TEXTURE_SWIZZLE_G_EXT
:
1114 case GL_TEXTURE_SWIZZLE_B_EXT
:
1115 case GL_TEXTURE_SWIZZLE_A_EXT
:
1116 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1117 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1118 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1125 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1126 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1128 for (comp
= 0; comp
< 4; comp
++) {
1129 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1143 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1146 _mesa_unlock_texture(ctx
, obj
);
1151 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1153 struct gl_texture_unit
*texUnit
;
1154 struct gl_texture_object
*obj
;
1155 GLboolean error
= GL_FALSE
;
1156 GET_CURRENT_CONTEXT(ctx
);
1157 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1159 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1160 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1161 "glGetTexParameteriv(current unit)");
1165 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1167 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1169 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1174 case GL_TEXTURE_MAG_FILTER
:
1175 *params
= (GLint
) obj
->MagFilter
;
1177 case GL_TEXTURE_MIN_FILTER
:
1178 *params
= (GLint
) obj
->MinFilter
;
1180 case GL_TEXTURE_WRAP_S
:
1181 *params
= (GLint
) obj
->WrapS
;
1183 case GL_TEXTURE_WRAP_T
:
1184 *params
= (GLint
) obj
->WrapT
;
1186 case GL_TEXTURE_WRAP_R
:
1187 *params
= (GLint
) obj
->WrapR
;
1189 case GL_TEXTURE_BORDER_COLOR
:
1192 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1193 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1194 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1195 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1196 params
[0] = FLOAT_TO_INT(b
[0]);
1197 params
[1] = FLOAT_TO_INT(b
[1]);
1198 params
[2] = FLOAT_TO_INT(b
[2]);
1199 params
[3] = FLOAT_TO_INT(b
[3]);
1202 case GL_TEXTURE_RESIDENT
:
1205 if (ctx
->Driver
.IsTextureResident
)
1206 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1209 *params
= (GLint
) resident
;
1212 case GL_TEXTURE_PRIORITY
:
1213 *params
= FLOAT_TO_INT(obj
->Priority
);
1215 case GL_TEXTURE_MIN_LOD
:
1216 *params
= (GLint
) obj
->MinLod
;
1218 case GL_TEXTURE_MAX_LOD
:
1219 *params
= (GLint
) obj
->MaxLod
;
1221 case GL_TEXTURE_BASE_LEVEL
:
1222 *params
= obj
->BaseLevel
;
1224 case GL_TEXTURE_MAX_LEVEL
:
1225 *params
= obj
->MaxLevel
;
1227 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1228 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1229 *params
= (GLint
) obj
->MaxAnisotropy
;
1235 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1236 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1237 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1243 case GL_GENERATE_MIPMAP_SGIS
:
1244 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1245 *params
= (GLint
) obj
->GenerateMipmap
;
1251 case GL_TEXTURE_COMPARE_MODE_ARB
:
1252 if (ctx
->Extensions
.ARB_shadow
) {
1253 *params
= (GLint
) obj
->CompareMode
;
1259 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1260 if (ctx
->Extensions
.ARB_shadow
) {
1261 *params
= (GLint
) obj
->CompareFunc
;
1267 case GL_DEPTH_TEXTURE_MODE_ARB
:
1268 if (ctx
->Extensions
.ARB_depth_texture
) {
1269 *params
= (GLint
) obj
->DepthMode
;
1275 case GL_TEXTURE_LOD_BIAS
:
1276 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1277 *params
= (GLint
) obj
->LodBias
;
1283 #ifdef FEATURE_OES_draw_texture
1284 case GL_TEXTURE_CROP_RECT_OES
:
1285 params
[0] = obj
->CropRect
[0];
1286 params
[1] = obj
->CropRect
[1];
1287 params
[2] = obj
->CropRect
[2];
1288 params
[3] = obj
->CropRect
[3];
1291 case GL_TEXTURE_SWIZZLE_R_EXT
:
1292 case GL_TEXTURE_SWIZZLE_G_EXT
:
1293 case GL_TEXTURE_SWIZZLE_B_EXT
:
1294 case GL_TEXTURE_SWIZZLE_A_EXT
:
1295 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1296 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1297 *params
= obj
->Swizzle
[comp
];
1304 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1305 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1306 COPY_4V(params
, obj
->Swizzle
);
1314 ; /* silence warnings */
1318 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1321 _mesa_unlock_texture(ctx
, obj
);