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_ENUM
, "glTexParameter(param=0x%x)", wrap
);
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_ENUM
, "glTexParameter(param=0x%x)",
217 case GL_TEXTURE_MAG_FILTER
:
218 if (texObj
->MagFilter
== params
[0])
224 texObj
->MagFilter
= params
[0];
227 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
232 case GL_TEXTURE_WRAP_S
:
233 if (texObj
->WrapS
== params
[0])
235 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
237 texObj
->WrapS
= params
[0];
242 case GL_TEXTURE_WRAP_T
:
243 if (texObj
->WrapT
== params
[0])
245 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
247 texObj
->WrapT
= params
[0];
252 case GL_TEXTURE_WRAP_R
:
253 if (texObj
->WrapR
== params
[0])
255 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
257 texObj
->WrapR
= params
[0];
262 case GL_TEXTURE_BASE_LEVEL
:
263 if (texObj
->BaseLevel
== params
[0])
266 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
267 _mesa_error(ctx
, GL_INVALID_VALUE
,
268 "glTexParameter(param=%d)", params
[0]);
272 texObj
->BaseLevel
= params
[0];
275 case GL_TEXTURE_MAX_LEVEL
:
276 if (texObj
->MaxLevel
== params
[0])
278 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
279 _mesa_error(ctx
, GL_INVALID_OPERATION
,
280 "glTexParameter(param=%d)", params
[0]);
284 texObj
->MaxLevel
= params
[0];
287 case GL_GENERATE_MIPMAP_SGIS
:
288 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
289 if (texObj
->GenerateMipmap
!= params
[0]) {
291 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
297 _mesa_error(ctx
, GL_INVALID_ENUM
,
298 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
302 case GL_TEXTURE_COMPARE_MODE_ARB
:
303 if (ctx
->Extensions
.ARB_shadow
&&
304 (params
[0] == GL_NONE
||
305 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
306 if (texObj
->CompareMode
!= params
[0]) {
308 texObj
->CompareMode
= params
[0];
314 _mesa_error(ctx
, GL_INVALID_ENUM
,
315 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
319 case GL_TEXTURE_COMPARE_FUNC_ARB
:
320 if (ctx
->Extensions
.ARB_shadow
) {
321 if (texObj
->CompareFunc
== params
[0])
327 texObj
->CompareFunc
= params
[0];
335 if (ctx
->Extensions
.EXT_shadow_funcs
) {
337 texObj
->CompareFunc
= params
[0];
342 _mesa_error(ctx
, GL_INVALID_ENUM
,
343 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
347 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
351 case GL_DEPTH_TEXTURE_MODE_ARB
:
352 if (ctx
->Extensions
.ARB_depth_texture
&&
353 (params
[0] == GL_LUMINANCE
||
354 params
[0] == GL_INTENSITY
||
355 params
[0] == GL_ALPHA
)) {
356 if (texObj
->DepthMode
!= params
[0]) {
358 texObj
->DepthMode
= params
[0];
363 _mesa_error(ctx
, GL_INVALID_ENUM
,
364 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
368 #ifdef FEATURE_OES_draw_texture
369 case GL_TEXTURE_CROP_RECT_OES
:
370 texObj
->CropRect
[0] = params
[0];
371 texObj
->CropRect
[1] = params
[1];
372 texObj
->CropRect
[2] = params
[2];
373 texObj
->CropRect
[3] = params
[3];
377 case GL_TEXTURE_SWIZZLE_R_EXT
:
378 case GL_TEXTURE_SWIZZLE_G_EXT
:
379 case GL_TEXTURE_SWIZZLE_B_EXT
:
380 case GL_TEXTURE_SWIZZLE_A_EXT
:
381 if (ctx
->Extensions
.EXT_texture_swizzle
) {
382 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
383 const GLint swz
= comp_to_swizzle(params
[0]);
385 _mesa_error(ctx
, GL_INVALID_OPERATION
,
386 "glTexParameter(swizzle 0x%x)", params
[0]);
392 texObj
->Swizzle
[comp
] = params
[0];
393 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
397 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
400 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
401 if (ctx
->Extensions
.EXT_texture_swizzle
) {
404 for (comp
= 0; comp
< 4; comp
++) {
405 const GLint swz
= comp_to_swizzle(params
[comp
]);
407 texObj
->Swizzle
[comp
] = params
[comp
];
408 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
412 "glTexParameter(swizzle 0x%x)", params
[comp
]);
418 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
422 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
429 * Set a float-valued texture parameter
430 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
433 set_tex_parameterf(GLcontext
*ctx
,
434 struct gl_texture_object
*texObj
,
435 GLenum pname
, const GLfloat
*params
)
438 case GL_TEXTURE_MIN_LOD
:
439 if (texObj
->MinLod
== params
[0])
442 texObj
->MinLod
= params
[0];
445 case GL_TEXTURE_MAX_LOD
:
446 if (texObj
->MaxLod
== params
[0])
449 texObj
->MaxLod
= params
[0];
452 case GL_TEXTURE_PRIORITY
:
454 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
457 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
458 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
459 if (texObj
->MaxAnisotropy
== params
[0])
461 if (params
[0] < 1.0) {
462 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
466 /* clamp to max, that's what NVIDIA does */
467 texObj
->MaxAnisotropy
= MIN2(params
[0],
468 ctx
->Const
.MaxTextureMaxAnisotropy
);
472 _mesa_error(ctx
, GL_INVALID_ENUM
,
473 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
477 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
478 if (ctx
->Extensions
.ARB_shadow_ambient
) {
479 if (texObj
->CompareFailValue
!= params
[0]) {
481 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
486 _mesa_error(ctx
, GL_INVALID_ENUM
,
487 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
491 case GL_TEXTURE_LOD_BIAS
:
492 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
493 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
494 if (texObj
->LodBias
!= params
[0]) {
496 texObj
->LodBias
= params
[0];
503 case GL_TEXTURE_BORDER_COLOR
:
505 texObj
->BorderColor
[RCOMP
] = params
[0];
506 texObj
->BorderColor
[GCOMP
] = params
[1];
507 texObj
->BorderColor
[BCOMP
] = params
[2];
508 texObj
->BorderColor
[ACOMP
] = params
[3];
512 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
519 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
521 GLboolean need_update
;
522 struct gl_texture_object
*texObj
;
523 GET_CURRENT_CONTEXT(ctx
);
524 ASSERT_OUTSIDE_BEGIN_END(ctx
);
526 texObj
= get_texobj(ctx
, target
);
531 case GL_TEXTURE_MIN_FILTER
:
532 case GL_TEXTURE_MAG_FILTER
:
533 case GL_TEXTURE_WRAP_S
:
534 case GL_TEXTURE_WRAP_T
:
535 case GL_TEXTURE_WRAP_R
:
536 case GL_TEXTURE_BASE_LEVEL
:
537 case GL_TEXTURE_MAX_LEVEL
:
538 case GL_GENERATE_MIPMAP_SGIS
:
539 case GL_TEXTURE_COMPARE_MODE_ARB
:
540 case GL_TEXTURE_COMPARE_FUNC_ARB
:
541 case GL_DEPTH_TEXTURE_MODE_ARB
:
543 /* convert float param to int */
544 GLint p
= (GLint
) param
;
545 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
549 /* this will generate an error if pname is illegal */
550 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, ¶m
);
553 if (ctx
->Driver
.TexParameter
&& need_update
) {
554 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
560 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
562 GLboolean need_update
;
563 struct gl_texture_object
*texObj
;
564 GET_CURRENT_CONTEXT(ctx
);
565 ASSERT_OUTSIDE_BEGIN_END(ctx
);
567 texObj
= get_texobj(ctx
, target
);
572 case GL_TEXTURE_MIN_FILTER
:
573 case GL_TEXTURE_MAG_FILTER
:
574 case GL_TEXTURE_WRAP_S
:
575 case GL_TEXTURE_WRAP_T
:
576 case GL_TEXTURE_WRAP_R
:
577 case GL_TEXTURE_BASE_LEVEL
:
578 case GL_TEXTURE_MAX_LEVEL
:
579 case GL_GENERATE_MIPMAP_SGIS
:
580 case GL_TEXTURE_COMPARE_MODE_ARB
:
581 case GL_TEXTURE_COMPARE_FUNC_ARB
:
582 case GL_DEPTH_TEXTURE_MODE_ARB
:
584 /* convert float param to int */
585 GLint p
= (GLint
) params
[0];
586 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
590 #ifdef FEATURE_OES_draw_texture
591 case GL_TEXTURE_CROP_RECT_OES
:
593 /* convert float params to int */
595 iparams
[0] = (GLint
) params
[0];
596 iparams
[1] = (GLint
) params
[1];
597 iparams
[2] = (GLint
) params
[2];
598 iparams
[3] = (GLint
) params
[3];
599 need_update
= set_tex_parameteri(ctx
, target
, iparams
);
605 /* this will generate an error if pname is illegal */
606 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
609 if (ctx
->Driver
.TexParameter
&& need_update
) {
610 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
616 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
618 GLboolean need_update
;
619 struct gl_texture_object
*texObj
;
620 GET_CURRENT_CONTEXT(ctx
);
621 ASSERT_OUTSIDE_BEGIN_END(ctx
);
623 texObj
= get_texobj(ctx
, target
);
628 case GL_TEXTURE_MIN_LOD
:
629 case GL_TEXTURE_MAX_LOD
:
630 case GL_TEXTURE_PRIORITY
:
631 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
632 case GL_TEXTURE_LOD_BIAS
:
633 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
635 GLfloat fparam
= (GLfloat
) param
;
636 /* convert int param to float */
637 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
641 /* this will generate an error if pname is illegal */
642 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, ¶m
);
645 if (ctx
->Driver
.TexParameter
&& need_update
) {
646 GLfloat fparam
= (GLfloat
) param
;
647 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
653 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
655 GLboolean need_update
;
656 struct gl_texture_object
*texObj
;
657 GET_CURRENT_CONTEXT(ctx
);
658 ASSERT_OUTSIDE_BEGIN_END(ctx
);
660 texObj
= get_texobj(ctx
, target
);
665 case GL_TEXTURE_BORDER_COLOR
:
667 /* convert int params to float */
669 fparams
[0] = INT_TO_FLOAT(params
[0]);
670 fparams
[1] = INT_TO_FLOAT(params
[1]);
671 fparams
[2] = INT_TO_FLOAT(params
[2]);
672 fparams
[3] = INT_TO_FLOAT(params
[3]);
673 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
676 case GL_TEXTURE_MIN_LOD
:
677 case GL_TEXTURE_MAX_LOD
:
678 case GL_TEXTURE_PRIORITY
:
679 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
680 case GL_TEXTURE_LOD_BIAS
:
681 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
683 /* convert int param to float */
684 GLfloat fparam
= (GLfloat
) params
[0];
685 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
689 /* this will generate an error if pname is illegal */
690 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
693 if (ctx
->Driver
.TexParameter
&& need_update
) {
695 fparams
[0] = INT_TO_FLOAT(params
[0]);
696 if (pname
== GL_TEXTURE_BORDER_COLOR
||
697 pname
== GL_TEXTURE_CROP_RECT_OES
) {
698 fparams
[1] = INT_TO_FLOAT(params
[1]);
699 fparams
[2] = INT_TO_FLOAT(params
[2]);
700 fparams
[3] = INT_TO_FLOAT(params
[3]);
702 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
708 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
709 GLenum pname
, GLfloat
*params
)
712 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
713 *params
= (GLfloat
) iparam
;
718 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
722 case GL_PROXY_TEXTURE_1D
:
725 case GL_PROXY_TEXTURE_2D
:
728 case GL_PROXY_TEXTURE_3D
:
730 case GL_TEXTURE_CUBE_MAP
:
731 case GL_PROXY_TEXTURE_CUBE_MAP
:
732 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
733 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
734 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
735 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
736 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
738 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
739 case GL_TEXTURE_RECTANGLE_NV
:
740 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
741 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
742 case GL_TEXTURE_1D_ARRAY_EXT
:
743 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
744 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
745 case GL_TEXTURE_2D_ARRAY_EXT
:
746 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
747 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
749 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
756 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
757 GLenum pname
, GLint
*params
)
759 const struct gl_texture_unit
*texUnit
;
760 struct gl_texture_object
*texObj
;
761 const struct gl_texture_image
*img
= NULL
;
765 GET_CURRENT_CONTEXT(ctx
);
766 ASSERT_OUTSIDE_BEGIN_END(ctx
);
768 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
769 _mesa_error(ctx
, GL_INVALID_OPERATION
,
770 "glGetTexLevelParameteriv(current unit)");
774 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
776 /* this will catch bad target values */
777 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
778 if (dimensions
== 0) {
779 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
783 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
784 if (maxLevels
== 0) {
785 /* should not happen since <target> was just checked above */
786 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
790 if (level
< 0 || level
>= maxLevels
) {
791 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
795 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
796 _mesa_lock_texture(ctx
, texObj
);
798 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
799 if (!img
|| !img
->TexFormat
) {
800 /* undefined texture image */
801 if (pname
== GL_TEXTURE_COMPONENTS
)
808 isProxy
= _mesa_is_proxy_texture(target
);
811 case GL_TEXTURE_WIDTH
:
812 *params
= img
->Width
;
814 case GL_TEXTURE_HEIGHT
:
815 *params
= img
->Height
;
817 case GL_TEXTURE_DEPTH
:
818 *params
= img
->Depth
;
820 case GL_TEXTURE_INTERNAL_FORMAT
:
821 *params
= img
->InternalFormat
;
823 case GL_TEXTURE_BORDER
:
824 *params
= img
->Border
;
826 case GL_TEXTURE_RED_SIZE
:
827 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
828 *params
= img
->TexFormat
->RedBits
;
832 case GL_TEXTURE_GREEN_SIZE
:
833 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
834 *params
= img
->TexFormat
->GreenBits
;
838 case GL_TEXTURE_BLUE_SIZE
:
839 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
840 *params
= img
->TexFormat
->BlueBits
;
844 case GL_TEXTURE_ALPHA_SIZE
:
845 if (img
->_BaseFormat
== GL_ALPHA
||
846 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
847 img
->_BaseFormat
== GL_RGBA
)
848 *params
= img
->TexFormat
->AlphaBits
;
852 case GL_TEXTURE_INTENSITY_SIZE
:
853 if (img
->_BaseFormat
!= GL_INTENSITY
)
855 else if (img
->TexFormat
->IntensityBits
> 0)
856 *params
= img
->TexFormat
->IntensityBits
;
857 else /* intensity probably stored as rgb texture */
858 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
860 case GL_TEXTURE_LUMINANCE_SIZE
:
861 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
862 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
864 else if (img
->TexFormat
->LuminanceBits
> 0)
865 *params
= img
->TexFormat
->LuminanceBits
;
866 else /* luminance probably stored as rgb texture */
867 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
869 case GL_TEXTURE_INDEX_SIZE_EXT
:
870 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
871 *params
= img
->TexFormat
->IndexBits
;
875 case GL_TEXTURE_DEPTH_SIZE_ARB
:
876 if (ctx
->Extensions
.ARB_depth_texture
)
877 *params
= img
->TexFormat
->DepthBits
;
879 _mesa_error(ctx
, GL_INVALID_ENUM
,
880 "glGetTexLevelParameter[if]v(pname)");
882 case GL_TEXTURE_STENCIL_SIZE_EXT
:
883 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
884 *params
= img
->TexFormat
->StencilBits
;
887 _mesa_error(ctx
, GL_INVALID_ENUM
,
888 "glGetTexLevelParameter[if]v(pname)");
892 /* GL_ARB_texture_compression */
893 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
894 if (img
->IsCompressed
&& !isProxy
) {
895 /* Don't use ctx->Driver.CompressedTextureSize() since that
896 * may returned a padded hardware size.
898 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
899 img
->Height
, img
->Depth
,
900 img
->TexFormat
->MesaFormat
);
903 _mesa_error(ctx
, GL_INVALID_OPERATION
,
904 "glGetTexLevelParameter[if]v(pname)");
907 case GL_TEXTURE_COMPRESSED
:
908 *params
= (GLint
) img
->IsCompressed
;
911 /* GL_ARB_texture_float */
912 case GL_TEXTURE_RED_TYPE_ARB
:
913 if (ctx
->Extensions
.ARB_texture_float
) {
914 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
917 _mesa_error(ctx
, GL_INVALID_ENUM
,
918 "glGetTexLevelParameter[if]v(pname)");
921 case GL_TEXTURE_GREEN_TYPE_ARB
:
922 if (ctx
->Extensions
.ARB_texture_float
) {
923 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
926 _mesa_error(ctx
, GL_INVALID_ENUM
,
927 "glGetTexLevelParameter[if]v(pname)");
930 case GL_TEXTURE_BLUE_TYPE_ARB
:
931 if (ctx
->Extensions
.ARB_texture_float
) {
932 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
935 _mesa_error(ctx
, GL_INVALID_ENUM
,
936 "glGetTexLevelParameter[if]v(pname)");
939 case GL_TEXTURE_ALPHA_TYPE_ARB
:
940 if (ctx
->Extensions
.ARB_texture_float
) {
941 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
944 _mesa_error(ctx
, GL_INVALID_ENUM
,
945 "glGetTexLevelParameter[if]v(pname)");
948 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
949 if (ctx
->Extensions
.ARB_texture_float
) {
950 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
953 _mesa_error(ctx
, GL_INVALID_ENUM
,
954 "glGetTexLevelParameter[if]v(pname)");
957 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
958 if (ctx
->Extensions
.ARB_texture_float
) {
959 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
962 _mesa_error(ctx
, GL_INVALID_ENUM
,
963 "glGetTexLevelParameter[if]v(pname)");
966 case GL_TEXTURE_DEPTH_TYPE_ARB
:
967 if (ctx
->Extensions
.ARB_texture_float
) {
968 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
971 _mesa_error(ctx
, GL_INVALID_ENUM
,
972 "glGetTexLevelParameter[if]v(pname)");
977 _mesa_error(ctx
, GL_INVALID_ENUM
,
978 "glGetTexLevelParameter[if]v(pname)");
982 _mesa_unlock_texture(ctx
, texObj
);
988 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
990 struct gl_texture_unit
*texUnit
;
991 struct gl_texture_object
*obj
;
992 GLboolean error
= GL_FALSE
;
993 GET_CURRENT_CONTEXT(ctx
);
994 ASSERT_OUTSIDE_BEGIN_END(ctx
);
996 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
998 "glGetTexParameterfv(current unit)");
1002 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1004 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1006 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1010 _mesa_lock_texture(ctx
, obj
);
1012 case GL_TEXTURE_MAG_FILTER
:
1013 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1015 case GL_TEXTURE_MIN_FILTER
:
1016 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1018 case GL_TEXTURE_WRAP_S
:
1019 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1021 case GL_TEXTURE_WRAP_T
:
1022 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1024 case GL_TEXTURE_WRAP_R
:
1025 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1027 case GL_TEXTURE_BORDER_COLOR
:
1028 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1029 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1030 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1031 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1033 case GL_TEXTURE_RESIDENT
:
1036 if (ctx
->Driver
.IsTextureResident
)
1037 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1040 *params
= ENUM_TO_FLOAT(resident
);
1043 case GL_TEXTURE_PRIORITY
:
1044 *params
= obj
->Priority
;
1046 case GL_TEXTURE_MIN_LOD
:
1047 *params
= obj
->MinLod
;
1049 case GL_TEXTURE_MAX_LOD
:
1050 *params
= obj
->MaxLod
;
1052 case GL_TEXTURE_BASE_LEVEL
:
1053 *params
= (GLfloat
) obj
->BaseLevel
;
1055 case GL_TEXTURE_MAX_LEVEL
:
1056 *params
= (GLfloat
) obj
->MaxLevel
;
1058 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1059 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1060 *params
= obj
->MaxAnisotropy
;
1065 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1066 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1067 *params
= obj
->CompareFailValue
;
1072 case GL_GENERATE_MIPMAP_SGIS
:
1073 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1074 *params
= (GLfloat
) obj
->GenerateMipmap
;
1079 case GL_TEXTURE_COMPARE_MODE_ARB
:
1080 if (ctx
->Extensions
.ARB_shadow
) {
1081 *params
= (GLfloat
) obj
->CompareMode
;
1086 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1087 if (ctx
->Extensions
.ARB_shadow
) {
1088 *params
= (GLfloat
) obj
->CompareFunc
;
1093 case GL_DEPTH_TEXTURE_MODE_ARB
:
1094 if (ctx
->Extensions
.ARB_depth_texture
) {
1095 *params
= (GLfloat
) obj
->DepthMode
;
1100 case GL_TEXTURE_LOD_BIAS
:
1101 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1102 *params
= obj
->LodBias
;
1107 #ifdef FEATURE_OES_draw_texture
1108 case GL_TEXTURE_CROP_RECT_OES
:
1109 params
[0] = obj
->CropRect
[0];
1110 params
[1] = obj
->CropRect
[1];
1111 params
[2] = obj
->CropRect
[2];
1112 params
[3] = obj
->CropRect
[3];
1116 case GL_TEXTURE_SWIZZLE_R_EXT
:
1117 case GL_TEXTURE_SWIZZLE_G_EXT
:
1118 case GL_TEXTURE_SWIZZLE_B_EXT
:
1119 case GL_TEXTURE_SWIZZLE_A_EXT
:
1120 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1121 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1122 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1129 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1130 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1132 for (comp
= 0; comp
< 4; comp
++) {
1133 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1147 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1150 _mesa_unlock_texture(ctx
, obj
);
1155 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1157 struct gl_texture_unit
*texUnit
;
1158 struct gl_texture_object
*obj
;
1159 GLboolean error
= GL_FALSE
;
1160 GET_CURRENT_CONTEXT(ctx
);
1161 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1163 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1164 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1165 "glGetTexParameteriv(current unit)");
1169 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1171 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1173 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1178 case GL_TEXTURE_MAG_FILTER
:
1179 *params
= (GLint
) obj
->MagFilter
;
1181 case GL_TEXTURE_MIN_FILTER
:
1182 *params
= (GLint
) obj
->MinFilter
;
1184 case GL_TEXTURE_WRAP_S
:
1185 *params
= (GLint
) obj
->WrapS
;
1187 case GL_TEXTURE_WRAP_T
:
1188 *params
= (GLint
) obj
->WrapT
;
1190 case GL_TEXTURE_WRAP_R
:
1191 *params
= (GLint
) obj
->WrapR
;
1193 case GL_TEXTURE_BORDER_COLOR
:
1196 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1197 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1198 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1199 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1200 params
[0] = FLOAT_TO_INT(b
[0]);
1201 params
[1] = FLOAT_TO_INT(b
[1]);
1202 params
[2] = FLOAT_TO_INT(b
[2]);
1203 params
[3] = FLOAT_TO_INT(b
[3]);
1206 case GL_TEXTURE_RESIDENT
:
1209 if (ctx
->Driver
.IsTextureResident
)
1210 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1213 *params
= (GLint
) resident
;
1216 case GL_TEXTURE_PRIORITY
:
1217 *params
= FLOAT_TO_INT(obj
->Priority
);
1219 case GL_TEXTURE_MIN_LOD
:
1220 *params
= (GLint
) obj
->MinLod
;
1222 case GL_TEXTURE_MAX_LOD
:
1223 *params
= (GLint
) obj
->MaxLod
;
1225 case GL_TEXTURE_BASE_LEVEL
:
1226 *params
= obj
->BaseLevel
;
1228 case GL_TEXTURE_MAX_LEVEL
:
1229 *params
= obj
->MaxLevel
;
1231 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1232 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1233 *params
= (GLint
) obj
->MaxAnisotropy
;
1239 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1240 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1241 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1247 case GL_GENERATE_MIPMAP_SGIS
:
1248 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1249 *params
= (GLint
) obj
->GenerateMipmap
;
1255 case GL_TEXTURE_COMPARE_MODE_ARB
:
1256 if (ctx
->Extensions
.ARB_shadow
) {
1257 *params
= (GLint
) obj
->CompareMode
;
1263 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1264 if (ctx
->Extensions
.ARB_shadow
) {
1265 *params
= (GLint
) obj
->CompareFunc
;
1271 case GL_DEPTH_TEXTURE_MODE_ARB
:
1272 if (ctx
->Extensions
.ARB_depth_texture
) {
1273 *params
= (GLint
) obj
->DepthMode
;
1279 case GL_TEXTURE_LOD_BIAS
:
1280 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1281 *params
= (GLint
) obj
->LodBias
;
1287 #ifdef FEATURE_OES_draw_texture
1288 case GL_TEXTURE_CROP_RECT_OES
:
1289 params
[0] = obj
->CropRect
[0];
1290 params
[1] = obj
->CropRect
[1];
1291 params
[2] = obj
->CropRect
[2];
1292 params
[3] = obj
->CropRect
[3];
1295 case GL_TEXTURE_SWIZZLE_R_EXT
:
1296 case GL_TEXTURE_SWIZZLE_G_EXT
:
1297 case GL_TEXTURE_SWIZZLE_B_EXT
:
1298 case GL_TEXTURE_SWIZZLE_A_EXT
:
1299 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1300 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1301 *params
= obj
->Swizzle
[comp
];
1308 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1309 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1310 COPY_4V(params
, obj
->Swizzle
);
1318 ; /* silence warnings */
1322 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1325 _mesa_unlock_texture(ctx
, obj
);