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/formats.h"
37 #include "main/macros.h"
38 #include "main/texcompress.h"
39 #include "main/texparam.h"
40 #include "main/teximage.h"
41 #include "main/texstate.h"
42 #include "shader/prog_instruction.h"
46 * Check if a coordinate wrap mode is supported for the texture target.
47 * \return GL_TRUE if legal, GL_FALSE otherwise
50 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
52 const struct gl_extensions
* const e
= & ctx
->Extensions
;
54 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
55 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
56 /* any texture target */
59 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
61 (wrap
== GL_MIRRORED_REPEAT
&&
62 e
->ARB_texture_mirrored_repeat
) ||
63 (wrap
== GL_MIRROR_CLAMP_EXT
&&
64 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
65 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
66 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
67 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
68 (e
->EXT_texture_mirror_clamp
)))) {
69 /* non-rectangle texture */
73 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
79 * Get current texture object for given target.
80 * Return NULL if any error.
81 * Note that this is different from _mesa_select_tex_object() in that proxy
82 * targets are not accepted.
84 static struct gl_texture_object
*
85 get_texobj(GLcontext
*ctx
, GLenum target
)
87 struct gl_texture_unit
*texUnit
;
89 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
90 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(current unit)");
94 texUnit
= _mesa_get_current_tex_unit(ctx
);
98 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
100 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
102 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
103 case GL_TEXTURE_CUBE_MAP
:
104 if (ctx
->Extensions
.ARB_texture_cube_map
) {
105 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
108 case GL_TEXTURE_RECTANGLE_NV
:
109 if (ctx
->Extensions
.NV_texture_rectangle
) {
110 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
113 case GL_TEXTURE_1D_ARRAY_EXT
:
114 if (ctx
->Extensions
.MESA_texture_array
) {
115 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
118 case GL_TEXTURE_2D_ARRAY_EXT
:
119 if (ctx
->Extensions
.MESA_texture_array
) {
120 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
127 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(target)");
133 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
134 * \return -1 if error.
137 comp_to_swizzle(GLenum comp
)
159 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
162 ASSERT(swz
<= SWIZZLE_NIL
);
164 GLuint mask
= 0x7 << (3 * comp
);
165 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
172 * This is called just prior to changing any texture object state.
173 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
174 * state flag and then mark the texture object as 'incomplete' so that any
175 * per-texture derived state gets recomputed.
178 flush(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
180 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
181 texObj
->_Complete
= GL_FALSE
;
186 * Set an integer-valued texture parameter
187 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
190 set_tex_parameteri(GLcontext
*ctx
,
191 struct gl_texture_object
*texObj
,
192 GLenum pname
, const GLint
*params
)
195 case GL_TEXTURE_MIN_FILTER
:
196 if (texObj
->MinFilter
== params
[0])
202 texObj
->MinFilter
= params
[0];
204 case GL_NEAREST_MIPMAP_NEAREST
:
205 case GL_LINEAR_MIPMAP_NEAREST
:
206 case GL_NEAREST_MIPMAP_LINEAR
:
207 case GL_LINEAR_MIPMAP_LINEAR
:
208 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
210 texObj
->MinFilter
= params
[0];
215 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
220 case GL_TEXTURE_MAG_FILTER
:
221 if (texObj
->MagFilter
== params
[0])
227 texObj
->MagFilter
= params
[0];
230 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
235 case GL_TEXTURE_WRAP_S
:
236 if (texObj
->WrapS
== params
[0])
238 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
240 texObj
->WrapS
= params
[0];
245 case GL_TEXTURE_WRAP_T
:
246 if (texObj
->WrapT
== params
[0])
248 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
250 texObj
->WrapT
= params
[0];
255 case GL_TEXTURE_WRAP_R
:
256 if (texObj
->WrapR
== params
[0])
258 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
260 texObj
->WrapR
= params
[0];
265 case GL_TEXTURE_BASE_LEVEL
:
266 if (texObj
->BaseLevel
== params
[0])
269 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
270 _mesa_error(ctx
, GL_INVALID_VALUE
,
271 "glTexParameter(param=%d)", params
[0]);
275 texObj
->BaseLevel
= params
[0];
278 case GL_TEXTURE_MAX_LEVEL
:
279 if (texObj
->MaxLevel
== params
[0])
281 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
283 "glTexParameter(param=%d)", params
[0]);
287 texObj
->MaxLevel
= params
[0];
290 case GL_GENERATE_MIPMAP_SGIS
:
291 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
292 if (texObj
->GenerateMipmap
!= params
[0]) {
294 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
300 _mesa_error(ctx
, GL_INVALID_ENUM
,
301 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
305 case GL_TEXTURE_COMPARE_MODE_ARB
:
306 if (ctx
->Extensions
.ARB_shadow
&&
307 (params
[0] == GL_NONE
||
308 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
309 if (texObj
->CompareMode
!= params
[0]) {
311 texObj
->CompareMode
= params
[0];
317 _mesa_error(ctx
, GL_INVALID_ENUM
,
318 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
322 case GL_TEXTURE_COMPARE_FUNC_ARB
:
323 if (ctx
->Extensions
.ARB_shadow
) {
324 if (texObj
->CompareFunc
== params
[0])
330 texObj
->CompareFunc
= params
[0];
338 if (ctx
->Extensions
.EXT_shadow_funcs
) {
340 texObj
->CompareFunc
= params
[0];
345 _mesa_error(ctx
, GL_INVALID_ENUM
,
346 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
350 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
354 case GL_DEPTH_TEXTURE_MODE_ARB
:
355 if (ctx
->Extensions
.ARB_depth_texture
&&
356 (params
[0] == GL_LUMINANCE
||
357 params
[0] == GL_INTENSITY
||
358 params
[0] == GL_ALPHA
)) {
359 if (texObj
->DepthMode
!= params
[0]) {
361 texObj
->DepthMode
= params
[0];
366 _mesa_error(ctx
, GL_INVALID_ENUM
,
367 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
371 #ifdef FEATURE_OES_draw_texture
372 case GL_TEXTURE_CROP_RECT_OES
:
373 texObj
->CropRect
[0] = params
[0];
374 texObj
->CropRect
[1] = params
[1];
375 texObj
->CropRect
[2] = params
[2];
376 texObj
->CropRect
[3] = params
[3];
380 case GL_TEXTURE_SWIZZLE_R_EXT
:
381 case GL_TEXTURE_SWIZZLE_G_EXT
:
382 case GL_TEXTURE_SWIZZLE_B_EXT
:
383 case GL_TEXTURE_SWIZZLE_A_EXT
:
384 if (ctx
->Extensions
.EXT_texture_swizzle
) {
385 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
386 const GLint swz
= comp_to_swizzle(params
[0]);
388 _mesa_error(ctx
, GL_INVALID_OPERATION
,
389 "glTexParameter(swizzle 0x%x)", params
[0]);
395 texObj
->Swizzle
[comp
] = params
[0];
396 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
400 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
403 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
404 if (ctx
->Extensions
.EXT_texture_swizzle
) {
407 for (comp
= 0; comp
< 4; comp
++) {
408 const GLint swz
= comp_to_swizzle(params
[comp
]);
410 texObj
->Swizzle
[comp
] = params
[comp
];
411 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
415 "glTexParameter(swizzle 0x%x)", params
[comp
]);
421 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
425 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
432 * Set a float-valued texture parameter
433 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
436 set_tex_parameterf(GLcontext
*ctx
,
437 struct gl_texture_object
*texObj
,
438 GLenum pname
, const GLfloat
*params
)
441 case GL_TEXTURE_MIN_LOD
:
442 if (texObj
->MinLod
== params
[0])
445 texObj
->MinLod
= params
[0];
448 case GL_TEXTURE_MAX_LOD
:
449 if (texObj
->MaxLod
== params
[0])
452 texObj
->MaxLod
= params
[0];
455 case GL_TEXTURE_PRIORITY
:
457 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
460 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
461 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
462 if (texObj
->MaxAnisotropy
== params
[0])
464 if (params
[0] < 1.0) {
465 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
469 /* clamp to max, that's what NVIDIA does */
470 texObj
->MaxAnisotropy
= MIN2(params
[0],
471 ctx
->Const
.MaxTextureMaxAnisotropy
);
475 static GLuint count
= 0;
477 _mesa_error(ctx
, GL_INVALID_ENUM
,
478 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
482 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
483 if (ctx
->Extensions
.ARB_shadow_ambient
) {
484 if (texObj
->CompareFailValue
!= params
[0]) {
486 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
491 _mesa_error(ctx
, GL_INVALID_ENUM
,
492 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
496 case GL_TEXTURE_LOD_BIAS
:
497 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
498 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
499 if (texObj
->LodBias
!= params
[0]) {
501 texObj
->LodBias
= params
[0];
508 case GL_TEXTURE_BORDER_COLOR
:
510 texObj
->BorderColor
[RCOMP
] = params
[0];
511 texObj
->BorderColor
[GCOMP
] = params
[1];
512 texObj
->BorderColor
[BCOMP
] = params
[2];
513 texObj
->BorderColor
[ACOMP
] = params
[3];
517 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
524 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
526 GLboolean need_update
;
527 struct gl_texture_object
*texObj
;
528 GET_CURRENT_CONTEXT(ctx
);
529 ASSERT_OUTSIDE_BEGIN_END(ctx
);
531 texObj
= get_texobj(ctx
, target
);
536 case GL_TEXTURE_MIN_FILTER
:
537 case GL_TEXTURE_MAG_FILTER
:
538 case GL_TEXTURE_WRAP_S
:
539 case GL_TEXTURE_WRAP_T
:
540 case GL_TEXTURE_WRAP_R
:
541 case GL_TEXTURE_BASE_LEVEL
:
542 case GL_TEXTURE_MAX_LEVEL
:
543 case GL_GENERATE_MIPMAP_SGIS
:
544 case GL_TEXTURE_COMPARE_MODE_ARB
:
545 case GL_TEXTURE_COMPARE_FUNC_ARB
:
546 case GL_DEPTH_TEXTURE_MODE_ARB
:
548 /* convert float param to int */
550 p
[0] = (GLint
) param
;
551 p
[1] = p
[2] = p
[3] = 0;
552 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
557 /* this will generate an error if pname is illegal */
560 p
[1] = p
[2] = p
[3] = 0.0F
;
561 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
565 if (ctx
->Driver
.TexParameter
&& need_update
) {
566 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
572 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
574 GLboolean need_update
;
575 struct gl_texture_object
*texObj
;
576 GET_CURRENT_CONTEXT(ctx
);
577 ASSERT_OUTSIDE_BEGIN_END(ctx
);
579 texObj
= get_texobj(ctx
, target
);
584 case GL_TEXTURE_MIN_FILTER
:
585 case GL_TEXTURE_MAG_FILTER
:
586 case GL_TEXTURE_WRAP_S
:
587 case GL_TEXTURE_WRAP_T
:
588 case GL_TEXTURE_WRAP_R
:
589 case GL_TEXTURE_BASE_LEVEL
:
590 case GL_TEXTURE_MAX_LEVEL
:
591 case GL_GENERATE_MIPMAP_SGIS
:
592 case GL_TEXTURE_COMPARE_MODE_ARB
:
593 case GL_TEXTURE_COMPARE_FUNC_ARB
:
594 case GL_DEPTH_TEXTURE_MODE_ARB
:
596 /* convert float param to int */
598 p
[0] = (GLint
) params
[0];
599 p
[1] = p
[2] = p
[3] = 0;
600 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
604 #ifdef FEATURE_OES_draw_texture
605 case GL_TEXTURE_CROP_RECT_OES
:
607 /* convert float params to int */
609 iparams
[0] = (GLint
) params
[0];
610 iparams
[1] = (GLint
) params
[1];
611 iparams
[2] = (GLint
) params
[2];
612 iparams
[3] = (GLint
) params
[3];
613 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
619 /* this will generate an error if pname is illegal */
620 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
623 if (ctx
->Driver
.TexParameter
&& need_update
) {
624 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
630 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
632 GLboolean need_update
;
633 struct gl_texture_object
*texObj
;
634 GET_CURRENT_CONTEXT(ctx
);
635 ASSERT_OUTSIDE_BEGIN_END(ctx
);
637 texObj
= get_texobj(ctx
, target
);
642 case GL_TEXTURE_MIN_LOD
:
643 case GL_TEXTURE_MAX_LOD
:
644 case GL_TEXTURE_PRIORITY
:
645 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
646 case GL_TEXTURE_LOD_BIAS
:
647 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
650 fparam
[0] = (GLfloat
) param
;
651 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
652 /* convert int param to float */
653 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
657 /* this will generate an error if pname is illegal */
661 iparam
[1] = iparam
[2] = iparam
[3] = 0;
662 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
666 if (ctx
->Driver
.TexParameter
&& need_update
) {
667 GLfloat fparam
= (GLfloat
) param
;
668 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
674 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
676 GLboolean need_update
;
677 struct gl_texture_object
*texObj
;
678 GET_CURRENT_CONTEXT(ctx
);
679 ASSERT_OUTSIDE_BEGIN_END(ctx
);
681 texObj
= get_texobj(ctx
, target
);
686 case GL_TEXTURE_BORDER_COLOR
:
688 /* convert int params to float */
690 fparams
[0] = INT_TO_FLOAT(params
[0]);
691 fparams
[1] = INT_TO_FLOAT(params
[1]);
692 fparams
[2] = INT_TO_FLOAT(params
[2]);
693 fparams
[3] = INT_TO_FLOAT(params
[3]);
694 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
697 case GL_TEXTURE_MIN_LOD
:
698 case GL_TEXTURE_MAX_LOD
:
699 case GL_TEXTURE_PRIORITY
:
700 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
701 case GL_TEXTURE_LOD_BIAS
:
702 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
704 /* convert int param to float */
706 fparams
[0] = (GLfloat
) params
[0];
707 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
708 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
712 /* this will generate an error if pname is illegal */
713 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
716 if (ctx
->Driver
.TexParameter
&& need_update
) {
718 fparams
[0] = INT_TO_FLOAT(params
[0]);
719 if (pname
== GL_TEXTURE_BORDER_COLOR
||
720 pname
== GL_TEXTURE_CROP_RECT_OES
) {
721 fparams
[1] = INT_TO_FLOAT(params
[1]);
722 fparams
[2] = INT_TO_FLOAT(params
[2]);
723 fparams
[3] = INT_TO_FLOAT(params
[3]);
725 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
731 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
732 GLenum pname
, GLfloat
*params
)
735 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
736 *params
= (GLfloat
) iparam
;
741 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
742 GLenum pname
, GLint
*params
)
744 const struct gl_texture_unit
*texUnit
;
745 struct gl_texture_object
*texObj
;
746 const struct gl_texture_image
*img
= NULL
;
750 GET_CURRENT_CONTEXT(ctx
);
751 ASSERT_OUTSIDE_BEGIN_END(ctx
);
753 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
755 "glGetTexLevelParameteriv(current unit)");
759 texUnit
= _mesa_get_current_tex_unit(ctx
);
761 /* this will catch bad target values */
762 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
763 if (maxLevels
== 0) {
764 _mesa_error(ctx
, GL_INVALID_ENUM
,
765 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
769 if (level
< 0 || level
>= maxLevels
) {
770 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
774 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
775 _mesa_lock_texture(ctx
, texObj
);
777 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
778 if (!img
|| !img
->TexFormat
) {
779 /* undefined texture image */
780 if (pname
== GL_TEXTURE_COMPONENTS
)
787 texFormat
= img
->TexFormat
;
789 isProxy
= _mesa_is_proxy_texture(target
);
792 case GL_TEXTURE_WIDTH
:
793 *params
= img
->Width
;
795 case GL_TEXTURE_HEIGHT
:
796 *params
= img
->Height
;
798 case GL_TEXTURE_DEPTH
:
799 *params
= img
->Depth
;
801 case GL_TEXTURE_INTERNAL_FORMAT
:
802 if (_mesa_is_format_compressed(img
->TexFormat
)) {
803 /* need to return the actual compressed format */
804 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
807 /* return the user's requested internal format */
808 *params
= img
->InternalFormat
;
811 case GL_TEXTURE_BORDER
:
812 *params
= img
->Border
;
814 case GL_TEXTURE_RED_SIZE
:
815 case GL_TEXTURE_GREEN_SIZE
:
816 case GL_TEXTURE_BLUE_SIZE
:
817 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
818 *params
= _mesa_get_format_bits(texFormat
, pname
);
822 case GL_TEXTURE_ALPHA_SIZE
:
823 if (img
->_BaseFormat
== GL_ALPHA
||
824 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
825 img
->_BaseFormat
== GL_RGBA
)
826 *params
= _mesa_get_format_bits(texFormat
, pname
);
830 case GL_TEXTURE_INTENSITY_SIZE
:
831 if (img
->_BaseFormat
!= GL_INTENSITY
)
834 *params
= _mesa_get_format_bits(texFormat
, pname
);
836 /* intensity probably stored as rgb texture */
837 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
838 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
842 case GL_TEXTURE_LUMINANCE_SIZE
:
843 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
844 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
847 *params
= _mesa_get_format_bits(texFormat
, pname
);
849 /* luminance probably stored as rgb texture */
850 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
851 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
855 case GL_TEXTURE_INDEX_SIZE_EXT
:
856 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
857 *params
= _mesa_get_format_bits(texFormat
, pname
);
861 case GL_TEXTURE_DEPTH_SIZE_ARB
:
862 if (ctx
->Extensions
.ARB_depth_texture
)
863 *params
= _mesa_get_format_bits(texFormat
, pname
);
865 _mesa_error(ctx
, GL_INVALID_ENUM
,
866 "glGetTexLevelParameter[if]v(pname)");
868 case GL_TEXTURE_STENCIL_SIZE_EXT
:
869 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
870 ctx
->Extensions
.ARB_framebuffer_object
) {
871 *params
= _mesa_get_format_bits(texFormat
, pname
);
874 _mesa_error(ctx
, GL_INVALID_ENUM
,
875 "glGetTexLevelParameter[if]v(pname)");
879 /* GL_ARB_texture_compression */
880 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
881 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
882 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
883 img
->Height
, img
->Depth
);
886 _mesa_error(ctx
, GL_INVALID_OPERATION
,
887 "glGetTexLevelParameter[if]v(pname)");
890 case GL_TEXTURE_COMPRESSED
:
891 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
894 /* GL_ARB_texture_float */
895 case GL_TEXTURE_RED_TYPE_ARB
:
896 if (ctx
->Extensions
.ARB_texture_float
) {
897 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_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_GREEN_TYPE_ARB
:
906 if (ctx
->Extensions
.ARB_texture_float
) {
907 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_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_BLUE_TYPE_ARB
:
916 if (ctx
->Extensions
.ARB_texture_float
) {
917 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_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_ALPHA_TYPE_ARB
:
926 if (ctx
->Extensions
.ARB_texture_float
) {
927 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_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_LUMINANCE_TYPE_ARB
:
936 if (ctx
->Extensions
.ARB_texture_float
) {
937 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_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_INTENSITY_TYPE_ARB
:
946 if (ctx
->Extensions
.ARB_texture_float
) {
947 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
948 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
951 _mesa_error(ctx
, GL_INVALID_ENUM
,
952 "glGetTexLevelParameter[if]v(pname)");
955 case GL_TEXTURE_DEPTH_TYPE_ARB
:
956 if (ctx
->Extensions
.ARB_texture_float
) {
957 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
958 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
961 _mesa_error(ctx
, GL_INVALID_ENUM
,
962 "glGetTexLevelParameter[if]v(pname)");
967 _mesa_error(ctx
, GL_INVALID_ENUM
,
968 "glGetTexLevelParameter[if]v(pname)");
972 _mesa_unlock_texture(ctx
, texObj
);
978 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
980 struct gl_texture_unit
*texUnit
;
981 struct gl_texture_object
*obj
;
982 GLboolean error
= GL_FALSE
;
983 GET_CURRENT_CONTEXT(ctx
);
984 ASSERT_OUTSIDE_BEGIN_END(ctx
);
986 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
988 "glGetTexParameterfv(current unit)");
992 texUnit
= _mesa_get_current_tex_unit(ctx
);
994 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
996 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1000 _mesa_lock_texture(ctx
, obj
);
1002 case GL_TEXTURE_MAG_FILTER
:
1003 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1005 case GL_TEXTURE_MIN_FILTER
:
1006 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1008 case GL_TEXTURE_WRAP_S
:
1009 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1011 case GL_TEXTURE_WRAP_T
:
1012 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1014 case GL_TEXTURE_WRAP_R
:
1015 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1017 case GL_TEXTURE_BORDER_COLOR
:
1018 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1019 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1020 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1021 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1023 case GL_TEXTURE_RESIDENT
:
1026 if (ctx
->Driver
.IsTextureResident
)
1027 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1030 *params
= ENUM_TO_FLOAT(resident
);
1033 case GL_TEXTURE_PRIORITY
:
1034 *params
= obj
->Priority
;
1036 case GL_TEXTURE_MIN_LOD
:
1037 *params
= obj
->MinLod
;
1039 case GL_TEXTURE_MAX_LOD
:
1040 *params
= obj
->MaxLod
;
1042 case GL_TEXTURE_BASE_LEVEL
:
1043 *params
= (GLfloat
) obj
->BaseLevel
;
1045 case GL_TEXTURE_MAX_LEVEL
:
1046 *params
= (GLfloat
) obj
->MaxLevel
;
1048 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1049 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1050 *params
= obj
->MaxAnisotropy
;
1055 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1056 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1057 *params
= obj
->CompareFailValue
;
1062 case GL_GENERATE_MIPMAP_SGIS
:
1063 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1064 *params
= (GLfloat
) obj
->GenerateMipmap
;
1069 case GL_TEXTURE_COMPARE_MODE_ARB
:
1070 if (ctx
->Extensions
.ARB_shadow
) {
1071 *params
= (GLfloat
) obj
->CompareMode
;
1076 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1077 if (ctx
->Extensions
.ARB_shadow
) {
1078 *params
= (GLfloat
) obj
->CompareFunc
;
1083 case GL_DEPTH_TEXTURE_MODE_ARB
:
1084 if (ctx
->Extensions
.ARB_depth_texture
) {
1085 *params
= (GLfloat
) obj
->DepthMode
;
1090 case GL_TEXTURE_LOD_BIAS
:
1091 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1092 *params
= obj
->LodBias
;
1097 #ifdef FEATURE_OES_draw_texture
1098 case GL_TEXTURE_CROP_RECT_OES
:
1099 params
[0] = obj
->CropRect
[0];
1100 params
[1] = obj
->CropRect
[1];
1101 params
[2] = obj
->CropRect
[2];
1102 params
[3] = obj
->CropRect
[3];
1106 case GL_TEXTURE_SWIZZLE_R_EXT
:
1107 case GL_TEXTURE_SWIZZLE_G_EXT
:
1108 case GL_TEXTURE_SWIZZLE_B_EXT
:
1109 case GL_TEXTURE_SWIZZLE_A_EXT
:
1110 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1111 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1112 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1119 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1120 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1122 for (comp
= 0; comp
< 4; comp
++) {
1123 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1137 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1140 _mesa_unlock_texture(ctx
, obj
);
1145 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1147 struct gl_texture_unit
*texUnit
;
1148 struct gl_texture_object
*obj
;
1149 GLboolean error
= GL_FALSE
;
1150 GET_CURRENT_CONTEXT(ctx
);
1151 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1153 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1154 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1155 "glGetTexParameteriv(current unit)");
1159 texUnit
= _mesa_get_current_tex_unit(ctx
);
1161 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1163 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1167 _mesa_lock_texture(ctx
, obj
);
1169 case GL_TEXTURE_MAG_FILTER
:
1170 *params
= (GLint
) obj
->MagFilter
;
1172 case GL_TEXTURE_MIN_FILTER
:
1173 *params
= (GLint
) obj
->MinFilter
;
1175 case GL_TEXTURE_WRAP_S
:
1176 *params
= (GLint
) obj
->WrapS
;
1178 case GL_TEXTURE_WRAP_T
:
1179 *params
= (GLint
) obj
->WrapT
;
1181 case GL_TEXTURE_WRAP_R
:
1182 *params
= (GLint
) obj
->WrapR
;
1184 case GL_TEXTURE_BORDER_COLOR
:
1187 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1188 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1189 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1190 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1191 params
[0] = FLOAT_TO_INT(b
[0]);
1192 params
[1] = FLOAT_TO_INT(b
[1]);
1193 params
[2] = FLOAT_TO_INT(b
[2]);
1194 params
[3] = FLOAT_TO_INT(b
[3]);
1197 case GL_TEXTURE_RESIDENT
:
1200 if (ctx
->Driver
.IsTextureResident
)
1201 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1204 *params
= (GLint
) resident
;
1207 case GL_TEXTURE_PRIORITY
:
1208 *params
= FLOAT_TO_INT(obj
->Priority
);
1210 case GL_TEXTURE_MIN_LOD
:
1211 *params
= (GLint
) obj
->MinLod
;
1213 case GL_TEXTURE_MAX_LOD
:
1214 *params
= (GLint
) obj
->MaxLod
;
1216 case GL_TEXTURE_BASE_LEVEL
:
1217 *params
= obj
->BaseLevel
;
1219 case GL_TEXTURE_MAX_LEVEL
:
1220 *params
= obj
->MaxLevel
;
1222 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1223 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1224 *params
= (GLint
) obj
->MaxAnisotropy
;
1230 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1231 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1232 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1238 case GL_GENERATE_MIPMAP_SGIS
:
1239 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1240 *params
= (GLint
) obj
->GenerateMipmap
;
1246 case GL_TEXTURE_COMPARE_MODE_ARB
:
1247 if (ctx
->Extensions
.ARB_shadow
) {
1248 *params
= (GLint
) obj
->CompareMode
;
1254 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1255 if (ctx
->Extensions
.ARB_shadow
) {
1256 *params
= (GLint
) obj
->CompareFunc
;
1262 case GL_DEPTH_TEXTURE_MODE_ARB
:
1263 if (ctx
->Extensions
.ARB_depth_texture
) {
1264 *params
= (GLint
) obj
->DepthMode
;
1270 case GL_TEXTURE_LOD_BIAS
:
1271 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1272 *params
= (GLint
) obj
->LodBias
;
1278 #ifdef FEATURE_OES_draw_texture
1279 case GL_TEXTURE_CROP_RECT_OES
:
1280 params
[0] = obj
->CropRect
[0];
1281 params
[1] = obj
->CropRect
[1];
1282 params
[2] = obj
->CropRect
[2];
1283 params
[3] = obj
->CropRect
[3];
1286 case GL_TEXTURE_SWIZZLE_R_EXT
:
1287 case GL_TEXTURE_SWIZZLE_G_EXT
:
1288 case GL_TEXTURE_SWIZZLE_B_EXT
:
1289 case GL_TEXTURE_SWIZZLE_A_EXT
:
1290 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1291 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1292 *params
= obj
->Swizzle
[comp
];
1299 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1300 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1301 COPY_4V(params
, obj
->Swizzle
);
1309 ; /* silence warnings */
1313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1316 _mesa_unlock_texture(ctx
, obj
);