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/colormac.h"
35 #include "main/context.h"
36 #include "main/enums.h"
37 #include "main/formats.h"
38 #include "main/macros.h"
39 #include "main/texcompress.h"
40 #include "main/texparam.h"
41 #include "main/teximage.h"
42 #include "main/texstate.h"
43 #include "shader/prog_instruction.h"
47 * Check if a coordinate wrap mode is supported for the texture target.
48 * \return GL_TRUE if legal, GL_FALSE otherwise
51 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
53 const struct gl_extensions
* const e
= & ctx
->Extensions
;
55 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
56 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
57 /* any texture target */
60 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
62 (wrap
== GL_MIRRORED_REPEAT
&&
63 e
->ARB_texture_mirrored_repeat
) ||
64 (wrap
== GL_MIRROR_CLAMP_EXT
&&
65 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
66 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
67 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
68 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
69 (e
->EXT_texture_mirror_clamp
)))) {
70 /* non-rectangle texture */
74 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
80 * Get current texture object for given target.
81 * Return NULL if any error.
82 * Note that this is different from _mesa_select_tex_object() in that proxy
83 * targets are not accepted.
85 static struct gl_texture_object
*
86 get_texobj(GLcontext
*ctx
, GLenum target
)
88 struct gl_texture_unit
*texUnit
;
90 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
91 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(current unit)");
95 texUnit
= _mesa_get_current_tex_unit(ctx
);
99 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
101 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
103 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
104 case GL_TEXTURE_CUBE_MAP
:
105 if (ctx
->Extensions
.ARB_texture_cube_map
) {
106 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
109 case GL_TEXTURE_RECTANGLE_NV
:
110 if (ctx
->Extensions
.NV_texture_rectangle
) {
111 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
114 case GL_TEXTURE_1D_ARRAY_EXT
:
115 if (ctx
->Extensions
.MESA_texture_array
) {
116 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
119 case GL_TEXTURE_2D_ARRAY_EXT
:
120 if (ctx
->Extensions
.MESA_texture_array
) {
121 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
128 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(target)");
134 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
135 * \return -1 if error.
138 comp_to_swizzle(GLenum comp
)
160 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
163 ASSERT(swz
<= SWIZZLE_NIL
);
165 GLuint mask
= 0x7 << (3 * comp
);
166 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
173 * This is called just prior to changing any texture object state.
174 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
175 * state flag and then mark the texture object as 'incomplete' so that any
176 * per-texture derived state gets recomputed.
179 flush(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
181 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
182 texObj
->_Complete
= GL_FALSE
;
187 * Set an integer-valued texture parameter
188 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
191 set_tex_parameteri(GLcontext
*ctx
,
192 struct gl_texture_object
*texObj
,
193 GLenum pname
, const GLint
*params
)
196 case GL_TEXTURE_MIN_FILTER
:
197 if (texObj
->MinFilter
== params
[0])
203 texObj
->MinFilter
= params
[0];
205 case GL_NEAREST_MIPMAP_NEAREST
:
206 case GL_LINEAR_MIPMAP_NEAREST
:
207 case GL_NEAREST_MIPMAP_LINEAR
:
208 case GL_LINEAR_MIPMAP_LINEAR
:
209 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
211 texObj
->MinFilter
= params
[0];
216 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
221 case GL_TEXTURE_MAG_FILTER
:
222 if (texObj
->MagFilter
== params
[0])
228 texObj
->MagFilter
= params
[0];
231 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
236 case GL_TEXTURE_WRAP_S
:
237 if (texObj
->WrapS
== params
[0])
239 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
241 texObj
->WrapS
= params
[0];
246 case GL_TEXTURE_WRAP_T
:
247 if (texObj
->WrapT
== params
[0])
249 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
251 texObj
->WrapT
= params
[0];
256 case GL_TEXTURE_WRAP_R
:
257 if (texObj
->WrapR
== params
[0])
259 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
261 texObj
->WrapR
= params
[0];
266 case GL_TEXTURE_BASE_LEVEL
:
267 if (texObj
->BaseLevel
== params
[0])
270 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
271 _mesa_error(ctx
, GL_INVALID_VALUE
,
272 "glTexParameter(param=%d)", params
[0]);
276 texObj
->BaseLevel
= params
[0];
279 case GL_TEXTURE_MAX_LEVEL
:
280 if (texObj
->MaxLevel
== params
[0])
282 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
284 "glTexParameter(param=%d)", params
[0]);
288 texObj
->MaxLevel
= params
[0];
291 case GL_GENERATE_MIPMAP_SGIS
:
292 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
293 if (texObj
->GenerateMipmap
!= params
[0]) {
295 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
301 _mesa_error(ctx
, GL_INVALID_ENUM
,
302 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
306 case GL_TEXTURE_COMPARE_MODE_ARB
:
307 if (ctx
->Extensions
.ARB_shadow
&&
308 (params
[0] == GL_NONE
||
309 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
310 if (texObj
->CompareMode
!= params
[0]) {
312 texObj
->CompareMode
= params
[0];
318 _mesa_error(ctx
, GL_INVALID_ENUM
,
319 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
323 case GL_TEXTURE_COMPARE_FUNC_ARB
:
324 if (ctx
->Extensions
.ARB_shadow
) {
325 if (texObj
->CompareFunc
== params
[0])
331 texObj
->CompareFunc
= params
[0];
339 if (ctx
->Extensions
.EXT_shadow_funcs
) {
341 texObj
->CompareFunc
= params
[0];
346 _mesa_error(ctx
, GL_INVALID_ENUM
,
347 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
351 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
355 case GL_DEPTH_TEXTURE_MODE_ARB
:
356 if (ctx
->Extensions
.ARB_depth_texture
&&
357 (params
[0] == GL_LUMINANCE
||
358 params
[0] == GL_INTENSITY
||
359 params
[0] == GL_ALPHA
)) {
360 if (texObj
->DepthMode
!= params
[0]) {
362 texObj
->DepthMode
= params
[0];
367 _mesa_error(ctx
, GL_INVALID_ENUM
,
368 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
372 #ifdef FEATURE_OES_draw_texture
373 case GL_TEXTURE_CROP_RECT_OES
:
374 texObj
->CropRect
[0] = params
[0];
375 texObj
->CropRect
[1] = params
[1];
376 texObj
->CropRect
[2] = params
[2];
377 texObj
->CropRect
[3] = params
[3];
381 case GL_TEXTURE_SWIZZLE_R_EXT
:
382 case GL_TEXTURE_SWIZZLE_G_EXT
:
383 case GL_TEXTURE_SWIZZLE_B_EXT
:
384 case GL_TEXTURE_SWIZZLE_A_EXT
:
385 if (ctx
->Extensions
.EXT_texture_swizzle
) {
386 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
387 const GLint swz
= comp_to_swizzle(params
[0]);
389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
390 "glTexParameter(swizzle 0x%x)", params
[0]);
396 texObj
->Swizzle
[comp
] = params
[0];
397 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
401 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
404 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
405 if (ctx
->Extensions
.EXT_texture_swizzle
) {
408 for (comp
= 0; comp
< 4; comp
++) {
409 const GLint swz
= comp_to_swizzle(params
[comp
]);
411 texObj
->Swizzle
[comp
] = params
[comp
];
412 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
416 "glTexParameter(swizzle 0x%x)", params
[comp
]);
422 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
426 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
433 * Set a float-valued texture parameter
434 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
437 set_tex_parameterf(GLcontext
*ctx
,
438 struct gl_texture_object
*texObj
,
439 GLenum pname
, const GLfloat
*params
)
442 case GL_TEXTURE_MIN_LOD
:
443 if (texObj
->MinLod
== params
[0])
446 texObj
->MinLod
= params
[0];
449 case GL_TEXTURE_MAX_LOD
:
450 if (texObj
->MaxLod
== params
[0])
453 texObj
->MaxLod
= params
[0];
456 case GL_TEXTURE_PRIORITY
:
458 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
461 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
462 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
463 if (texObj
->MaxAnisotropy
== params
[0])
465 if (params
[0] < 1.0) {
466 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
470 /* clamp to max, that's what NVIDIA does */
471 texObj
->MaxAnisotropy
= MIN2(params
[0],
472 ctx
->Const
.MaxTextureMaxAnisotropy
);
476 static GLuint count
= 0;
478 _mesa_error(ctx
, GL_INVALID_ENUM
,
479 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
483 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
484 if (ctx
->Extensions
.ARB_shadow_ambient
) {
485 if (texObj
->CompareFailValue
!= params
[0]) {
487 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
492 _mesa_error(ctx
, GL_INVALID_ENUM
,
493 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
497 case GL_TEXTURE_LOD_BIAS
:
498 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
499 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
500 if (texObj
->LodBias
!= params
[0]) {
502 texObj
->LodBias
= params
[0];
509 case GL_TEXTURE_BORDER_COLOR
:
511 texObj
->BorderColor
[RCOMP
] = params
[0];
512 texObj
->BorderColor
[GCOMP
] = params
[1];
513 texObj
->BorderColor
[BCOMP
] = params
[2];
514 texObj
->BorderColor
[ACOMP
] = params
[3];
518 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
525 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
527 GLboolean need_update
;
528 struct gl_texture_object
*texObj
;
529 GET_CURRENT_CONTEXT(ctx
);
530 ASSERT_OUTSIDE_BEGIN_END(ctx
);
532 texObj
= get_texobj(ctx
, target
);
537 case GL_TEXTURE_MIN_FILTER
:
538 case GL_TEXTURE_MAG_FILTER
:
539 case GL_TEXTURE_WRAP_S
:
540 case GL_TEXTURE_WRAP_T
:
541 case GL_TEXTURE_WRAP_R
:
542 case GL_TEXTURE_BASE_LEVEL
:
543 case GL_TEXTURE_MAX_LEVEL
:
544 case GL_GENERATE_MIPMAP_SGIS
:
545 case GL_TEXTURE_COMPARE_MODE_ARB
:
546 case GL_TEXTURE_COMPARE_FUNC_ARB
:
547 case GL_DEPTH_TEXTURE_MODE_ARB
:
549 /* convert float param to int */
551 p
[0] = (GLint
) param
;
552 p
[1] = p
[2] = p
[3] = 0;
553 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
558 /* this will generate an error if pname is illegal */
561 p
[1] = p
[2] = p
[3] = 0.0F
;
562 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
566 if (ctx
->Driver
.TexParameter
&& need_update
) {
567 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
573 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
575 GLboolean need_update
;
576 struct gl_texture_object
*texObj
;
577 GET_CURRENT_CONTEXT(ctx
);
578 ASSERT_OUTSIDE_BEGIN_END(ctx
);
580 texObj
= get_texobj(ctx
, target
);
585 case GL_TEXTURE_MIN_FILTER
:
586 case GL_TEXTURE_MAG_FILTER
:
587 case GL_TEXTURE_WRAP_S
:
588 case GL_TEXTURE_WRAP_T
:
589 case GL_TEXTURE_WRAP_R
:
590 case GL_TEXTURE_BASE_LEVEL
:
591 case GL_TEXTURE_MAX_LEVEL
:
592 case GL_GENERATE_MIPMAP_SGIS
:
593 case GL_TEXTURE_COMPARE_MODE_ARB
:
594 case GL_TEXTURE_COMPARE_FUNC_ARB
:
595 case GL_DEPTH_TEXTURE_MODE_ARB
:
597 /* convert float param to int */
598 GLint p
= (GLint
) params
[0];
599 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
603 #ifdef FEATURE_OES_draw_texture
604 case GL_TEXTURE_CROP_RECT_OES
:
606 /* convert float params to int */
608 iparams
[0] = (GLint
) params
[0];
609 iparams
[1] = (GLint
) params
[1];
610 iparams
[2] = (GLint
) params
[2];
611 iparams
[3] = (GLint
) params
[3];
612 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
618 /* this will generate an error if pname is illegal */
619 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
622 if (ctx
->Driver
.TexParameter
&& need_update
) {
623 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
629 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
631 GLboolean need_update
;
632 struct gl_texture_object
*texObj
;
633 GET_CURRENT_CONTEXT(ctx
);
634 ASSERT_OUTSIDE_BEGIN_END(ctx
);
636 texObj
= get_texobj(ctx
, target
);
641 case GL_TEXTURE_MIN_LOD
:
642 case GL_TEXTURE_MAX_LOD
:
643 case GL_TEXTURE_PRIORITY
:
644 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
645 case GL_TEXTURE_LOD_BIAS
:
646 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
648 GLfloat fparam
= (GLfloat
) param
;
649 /* convert int param to float */
650 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
654 /* this will generate an error if pname is illegal */
655 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, ¶m
);
658 if (ctx
->Driver
.TexParameter
&& need_update
) {
659 GLfloat fparam
= (GLfloat
) param
;
660 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
666 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
668 GLboolean need_update
;
669 struct gl_texture_object
*texObj
;
670 GET_CURRENT_CONTEXT(ctx
);
671 ASSERT_OUTSIDE_BEGIN_END(ctx
);
673 texObj
= get_texobj(ctx
, target
);
678 case GL_TEXTURE_BORDER_COLOR
:
680 /* convert int params to float */
682 fparams
[0] = INT_TO_FLOAT(params
[0]);
683 fparams
[1] = INT_TO_FLOAT(params
[1]);
684 fparams
[2] = INT_TO_FLOAT(params
[2]);
685 fparams
[3] = INT_TO_FLOAT(params
[3]);
686 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
689 case GL_TEXTURE_MIN_LOD
:
690 case GL_TEXTURE_MAX_LOD
:
691 case GL_TEXTURE_PRIORITY
:
692 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
693 case GL_TEXTURE_LOD_BIAS
:
694 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
696 /* convert int param to float */
697 GLfloat fparam
= (GLfloat
) params
[0];
698 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
702 /* this will generate an error if pname is illegal */
703 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
706 if (ctx
->Driver
.TexParameter
&& need_update
) {
708 fparams
[0] = INT_TO_FLOAT(params
[0]);
709 if (pname
== GL_TEXTURE_BORDER_COLOR
||
710 pname
== GL_TEXTURE_CROP_RECT_OES
) {
711 fparams
[1] = INT_TO_FLOAT(params
[1]);
712 fparams
[2] = INT_TO_FLOAT(params
[2]);
713 fparams
[3] = INT_TO_FLOAT(params
[3]);
715 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
721 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
722 GLenum pname
, GLfloat
*params
)
725 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
726 *params
= (GLfloat
) iparam
;
731 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
732 GLenum pname
, GLint
*params
)
734 const struct gl_texture_unit
*texUnit
;
735 struct gl_texture_object
*texObj
;
736 const struct gl_texture_image
*img
= NULL
;
740 GET_CURRENT_CONTEXT(ctx
);
741 ASSERT_OUTSIDE_BEGIN_END(ctx
);
743 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
744 _mesa_error(ctx
, GL_INVALID_OPERATION
,
745 "glGetTexLevelParameteriv(current unit)");
749 texUnit
= _mesa_get_current_tex_unit(ctx
);
751 /* this will catch bad target values */
752 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
753 if (maxLevels
== 0) {
754 _mesa_error(ctx
, GL_INVALID_ENUM
,
755 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
759 if (level
< 0 || level
>= maxLevels
) {
760 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
764 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
765 _mesa_lock_texture(ctx
, texObj
);
767 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
768 if (!img
|| !img
->TexFormat
) {
769 /* undefined texture image */
770 if (pname
== GL_TEXTURE_COMPONENTS
)
777 texFormat
= img
->TexFormat
;
779 isProxy
= _mesa_is_proxy_texture(target
);
782 case GL_TEXTURE_WIDTH
:
783 *params
= img
->Width
;
785 case GL_TEXTURE_HEIGHT
:
786 *params
= img
->Height
;
788 case GL_TEXTURE_DEPTH
:
789 *params
= img
->Depth
;
791 case GL_TEXTURE_INTERNAL_FORMAT
:
792 if (_mesa_is_format_compressed(img
->TexFormat
)) {
793 /* need to return the actual compressed format */
794 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
797 /* return the user's requested internal format */
798 *params
= img
->InternalFormat
;
801 case GL_TEXTURE_BORDER
:
802 *params
= img
->Border
;
804 case GL_TEXTURE_RED_SIZE
:
805 case GL_TEXTURE_GREEN_SIZE
:
806 case GL_TEXTURE_BLUE_SIZE
:
807 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
808 *params
= _mesa_get_format_bits(texFormat
, pname
);
812 case GL_TEXTURE_ALPHA_SIZE
:
813 if (img
->_BaseFormat
== GL_ALPHA
||
814 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
815 img
->_BaseFormat
== GL_RGBA
)
816 *params
= _mesa_get_format_bits(texFormat
, pname
);
820 case GL_TEXTURE_INTENSITY_SIZE
:
821 if (img
->_BaseFormat
!= GL_INTENSITY
)
824 *params
= _mesa_get_format_bits(texFormat
, pname
);
826 /* intensity probably stored as rgb texture */
827 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
828 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
832 case GL_TEXTURE_LUMINANCE_SIZE
:
833 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
834 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
837 *params
= _mesa_get_format_bits(texFormat
, pname
);
839 /* luminance probably stored as rgb texture */
840 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
841 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
845 case GL_TEXTURE_INDEX_SIZE_EXT
:
846 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
847 *params
= _mesa_get_format_bits(texFormat
, pname
);
851 case GL_TEXTURE_DEPTH_SIZE_ARB
:
852 if (ctx
->Extensions
.ARB_depth_texture
)
853 *params
= _mesa_get_format_bits(texFormat
, pname
);
855 _mesa_error(ctx
, GL_INVALID_ENUM
,
856 "glGetTexLevelParameter[if]v(pname)");
858 case GL_TEXTURE_STENCIL_SIZE_EXT
:
859 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
860 ctx
->Extensions
.ARB_framebuffer_object
) {
861 *params
= _mesa_get_format_bits(texFormat
, pname
);
864 _mesa_error(ctx
, GL_INVALID_ENUM
,
865 "glGetTexLevelParameter[if]v(pname)");
869 /* GL_ARB_texture_compression */
870 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
871 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
872 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
873 img
->Height
, img
->Depth
);
876 _mesa_error(ctx
, GL_INVALID_OPERATION
,
877 "glGetTexLevelParameter[if]v(pname)");
880 case GL_TEXTURE_COMPRESSED
:
881 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
884 /* GL_ARB_texture_float */
885 case GL_TEXTURE_RED_TYPE_ARB
:
886 if (ctx
->Extensions
.ARB_texture_float
) {
887 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
888 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
891 _mesa_error(ctx
, GL_INVALID_ENUM
,
892 "glGetTexLevelParameter[if]v(pname)");
895 case GL_TEXTURE_GREEN_TYPE_ARB
:
896 if (ctx
->Extensions
.ARB_texture_float
) {
897 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
898 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
901 _mesa_error(ctx
, GL_INVALID_ENUM
,
902 "glGetTexLevelParameter[if]v(pname)");
905 case GL_TEXTURE_BLUE_TYPE_ARB
:
906 if (ctx
->Extensions
.ARB_texture_float
) {
907 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
908 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
911 _mesa_error(ctx
, GL_INVALID_ENUM
,
912 "glGetTexLevelParameter[if]v(pname)");
915 case GL_TEXTURE_ALPHA_TYPE_ARB
:
916 if (ctx
->Extensions
.ARB_texture_float
) {
917 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
918 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
921 _mesa_error(ctx
, GL_INVALID_ENUM
,
922 "glGetTexLevelParameter[if]v(pname)");
925 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
926 if (ctx
->Extensions
.ARB_texture_float
) {
927 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
928 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
931 _mesa_error(ctx
, GL_INVALID_ENUM
,
932 "glGetTexLevelParameter[if]v(pname)");
935 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
936 if (ctx
->Extensions
.ARB_texture_float
) {
937 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
938 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
941 _mesa_error(ctx
, GL_INVALID_ENUM
,
942 "glGetTexLevelParameter[if]v(pname)");
945 case GL_TEXTURE_DEPTH_TYPE_ARB
:
946 if (ctx
->Extensions
.ARB_texture_float
) {
947 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
948 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
951 _mesa_error(ctx
, GL_INVALID_ENUM
,
952 "glGetTexLevelParameter[if]v(pname)");
957 _mesa_error(ctx
, GL_INVALID_ENUM
,
958 "glGetTexLevelParameter[if]v(pname)");
962 _mesa_unlock_texture(ctx
, texObj
);
968 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
970 struct gl_texture_unit
*texUnit
;
971 struct gl_texture_object
*obj
;
972 GLboolean error
= GL_FALSE
;
973 GET_CURRENT_CONTEXT(ctx
);
974 ASSERT_OUTSIDE_BEGIN_END(ctx
);
976 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
977 _mesa_error(ctx
, GL_INVALID_OPERATION
,
978 "glGetTexParameterfv(current unit)");
982 texUnit
= _mesa_get_current_tex_unit(ctx
);
984 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
986 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
990 _mesa_lock_texture(ctx
, obj
);
992 case GL_TEXTURE_MAG_FILTER
:
993 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
995 case GL_TEXTURE_MIN_FILTER
:
996 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
998 case GL_TEXTURE_WRAP_S
:
999 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1001 case GL_TEXTURE_WRAP_T
:
1002 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1004 case GL_TEXTURE_WRAP_R
:
1005 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1007 case GL_TEXTURE_BORDER_COLOR
:
1008 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1009 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1010 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1011 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1013 case GL_TEXTURE_RESIDENT
:
1016 if (ctx
->Driver
.IsTextureResident
)
1017 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1020 *params
= ENUM_TO_FLOAT(resident
);
1023 case GL_TEXTURE_PRIORITY
:
1024 *params
= obj
->Priority
;
1026 case GL_TEXTURE_MIN_LOD
:
1027 *params
= obj
->MinLod
;
1029 case GL_TEXTURE_MAX_LOD
:
1030 *params
= obj
->MaxLod
;
1032 case GL_TEXTURE_BASE_LEVEL
:
1033 *params
= (GLfloat
) obj
->BaseLevel
;
1035 case GL_TEXTURE_MAX_LEVEL
:
1036 *params
= (GLfloat
) obj
->MaxLevel
;
1038 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1039 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1040 *params
= obj
->MaxAnisotropy
;
1045 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1046 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1047 *params
= obj
->CompareFailValue
;
1052 case GL_GENERATE_MIPMAP_SGIS
:
1053 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1054 *params
= (GLfloat
) obj
->GenerateMipmap
;
1059 case GL_TEXTURE_COMPARE_MODE_ARB
:
1060 if (ctx
->Extensions
.ARB_shadow
) {
1061 *params
= (GLfloat
) obj
->CompareMode
;
1066 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1067 if (ctx
->Extensions
.ARB_shadow
) {
1068 *params
= (GLfloat
) obj
->CompareFunc
;
1073 case GL_DEPTH_TEXTURE_MODE_ARB
:
1074 if (ctx
->Extensions
.ARB_depth_texture
) {
1075 *params
= (GLfloat
) obj
->DepthMode
;
1080 case GL_TEXTURE_LOD_BIAS
:
1081 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1082 *params
= obj
->LodBias
;
1087 #ifdef FEATURE_OES_draw_texture
1088 case GL_TEXTURE_CROP_RECT_OES
:
1089 params
[0] = obj
->CropRect
[0];
1090 params
[1] = obj
->CropRect
[1];
1091 params
[2] = obj
->CropRect
[2];
1092 params
[3] = obj
->CropRect
[3];
1096 case GL_TEXTURE_SWIZZLE_R_EXT
:
1097 case GL_TEXTURE_SWIZZLE_G_EXT
:
1098 case GL_TEXTURE_SWIZZLE_B_EXT
:
1099 case GL_TEXTURE_SWIZZLE_A_EXT
:
1100 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1101 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1102 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1109 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1110 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1112 for (comp
= 0; comp
< 4; comp
++) {
1113 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1127 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1130 _mesa_unlock_texture(ctx
, obj
);
1135 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1137 struct gl_texture_unit
*texUnit
;
1138 struct gl_texture_object
*obj
;
1139 GLboolean error
= GL_FALSE
;
1140 GET_CURRENT_CONTEXT(ctx
);
1141 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1143 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1145 "glGetTexParameteriv(current unit)");
1149 texUnit
= _mesa_get_current_tex_unit(ctx
);
1151 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1153 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1158 case GL_TEXTURE_MAG_FILTER
:
1159 *params
= (GLint
) obj
->MagFilter
;
1161 case GL_TEXTURE_MIN_FILTER
:
1162 *params
= (GLint
) obj
->MinFilter
;
1164 case GL_TEXTURE_WRAP_S
:
1165 *params
= (GLint
) obj
->WrapS
;
1167 case GL_TEXTURE_WRAP_T
:
1168 *params
= (GLint
) obj
->WrapT
;
1170 case GL_TEXTURE_WRAP_R
:
1171 *params
= (GLint
) obj
->WrapR
;
1173 case GL_TEXTURE_BORDER_COLOR
:
1176 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1177 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1178 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1179 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1180 params
[0] = FLOAT_TO_INT(b
[0]);
1181 params
[1] = FLOAT_TO_INT(b
[1]);
1182 params
[2] = FLOAT_TO_INT(b
[2]);
1183 params
[3] = FLOAT_TO_INT(b
[3]);
1186 case GL_TEXTURE_RESIDENT
:
1189 if (ctx
->Driver
.IsTextureResident
)
1190 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1193 *params
= (GLint
) resident
;
1196 case GL_TEXTURE_PRIORITY
:
1197 *params
= FLOAT_TO_INT(obj
->Priority
);
1199 case GL_TEXTURE_MIN_LOD
:
1200 *params
= (GLint
) obj
->MinLod
;
1202 case GL_TEXTURE_MAX_LOD
:
1203 *params
= (GLint
) obj
->MaxLod
;
1205 case GL_TEXTURE_BASE_LEVEL
:
1206 *params
= obj
->BaseLevel
;
1208 case GL_TEXTURE_MAX_LEVEL
:
1209 *params
= obj
->MaxLevel
;
1211 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1212 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1213 *params
= (GLint
) obj
->MaxAnisotropy
;
1219 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1220 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1221 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1227 case GL_GENERATE_MIPMAP_SGIS
:
1228 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1229 *params
= (GLint
) obj
->GenerateMipmap
;
1235 case GL_TEXTURE_COMPARE_MODE_ARB
:
1236 if (ctx
->Extensions
.ARB_shadow
) {
1237 *params
= (GLint
) obj
->CompareMode
;
1243 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1244 if (ctx
->Extensions
.ARB_shadow
) {
1245 *params
= (GLint
) obj
->CompareFunc
;
1251 case GL_DEPTH_TEXTURE_MODE_ARB
:
1252 if (ctx
->Extensions
.ARB_depth_texture
) {
1253 *params
= (GLint
) obj
->DepthMode
;
1259 case GL_TEXTURE_LOD_BIAS
:
1260 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1261 *params
= (GLint
) obj
->LodBias
;
1267 #ifdef FEATURE_OES_draw_texture
1268 case GL_TEXTURE_CROP_RECT_OES
:
1269 params
[0] = obj
->CropRect
[0];
1270 params
[1] = obj
->CropRect
[1];
1271 params
[2] = obj
->CropRect
[2];
1272 params
[3] = obj
->CropRect
[3];
1275 case GL_TEXTURE_SWIZZLE_R_EXT
:
1276 case GL_TEXTURE_SWIZZLE_G_EXT
:
1277 case GL_TEXTURE_SWIZZLE_B_EXT
:
1278 case GL_TEXTURE_SWIZZLE_A_EXT
:
1279 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1280 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1281 *params
= obj
->Swizzle
[comp
];
1288 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1289 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1290 COPY_4V(params
, obj
->Swizzle
);
1298 ; /* silence warnings */
1302 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1305 _mesa_unlock_texture(ctx
, obj
);