2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * glTexParameter-related functions
33 #include "main/glheader.h"
34 #include "main/blend.h"
35 #include "main/colormac.h"
36 #include "main/context.h"
37 #include "main/enums.h"
38 #include "main/formats.h"
39 #include "main/glformats.h"
40 #include "main/macros.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texcompress.h"
44 #include "main/texobj.h"
45 #include "main/texparam.h"
46 #include "main/teximage.h"
47 #include "main/texstate.h"
48 #include "program/prog_instruction.h"
52 * Check if a coordinate wrap mode is supported for the texture target.
53 * \return GL_TRUE if legal, GL_FALSE otherwise
56 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
58 const struct gl_extensions
* const e
= & ctx
->Extensions
;
59 const bool is_desktop_gl
= _mesa_is_desktop_gl(ctx
);
64 /* GL_CLAMP was removed in the core profile, and it has never existed in
67 supported
= (ctx
->API
== API_OPENGL_COMPAT
)
68 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
71 case GL_CLAMP_TO_EDGE
:
75 case GL_CLAMP_TO_BORDER
:
76 supported
= is_desktop_gl
&& e
->ARB_texture_border_clamp
77 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
81 case GL_MIRRORED_REPEAT
:
82 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
83 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
86 case GL_MIRROR_CLAMP_EXT
:
87 supported
= is_desktop_gl
88 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
89 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
90 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
93 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
94 supported
= is_desktop_gl
95 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
)
96 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
97 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
100 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
101 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
102 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
103 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
112 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
119 * Get current texture object for given target.
120 * Return NULL if any error (and record the error).
121 * Note that this is different from _mesa_get_current_tex_object() in that
122 * proxy targets are not accepted.
123 * Only the glGetTexLevelParameter() functions accept proxy targets.
125 static struct gl_texture_object
*
126 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
128 struct gl_texture_unit
*texUnit
;
131 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
132 _mesa_error(ctx
, GL_INVALID_OPERATION
,
133 "gl%sTexParameter(current unit)", get
? "Get" : "");
137 texUnit
= _mesa_get_current_tex_unit(ctx
);
139 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
140 if (targetIndex
< 0 || targetIndex
== TEXTURE_BUFFER_INDEX
) {
141 _mesa_error(ctx
, GL_INVALID_ENUM
,
142 "gl%sTexParameter(target)", get
? "Get" : "");
145 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
147 return texUnit
->CurrentTex
[targetIndex
];
152 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
153 * \return -1 if error.
156 comp_to_swizzle(GLenum comp
)
178 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
181 ASSERT(swz
<= SWIZZLE_NIL
);
183 GLuint mask
= 0x7 << (3 * comp
);
184 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
191 * This is called just prior to changing any texture object state which
192 * will not effect texture completeness.
195 flush(struct gl_context
*ctx
)
197 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
202 * This is called just prior to changing any texture object state which
203 * can effect texture completeness (texture base level, max level).
204 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
205 * state flag and then mark the texture object as 'incomplete' so that any
206 * per-texture derived state gets recomputed.
209 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
211 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
212 _mesa_dirty_texobj(ctx
, texObj
);
217 target_allows_setting_sampler_parameters(GLenum target
)
220 case GL_TEXTURE_2D_MULTISAMPLE
:
221 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
231 * Set an integer-valued texture parameter
232 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
235 set_tex_parameteri(struct gl_context
*ctx
,
236 struct gl_texture_object
*texObj
,
237 GLenum pname
, const GLint
*params
)
240 case GL_TEXTURE_MIN_FILTER
:
241 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
242 goto invalid_operation
;
244 if (texObj
->Sampler
.MinFilter
== params
[0])
250 texObj
->Sampler
.MinFilter
= params
[0];
252 case GL_NEAREST_MIPMAP_NEAREST
:
253 case GL_LINEAR_MIPMAP_NEAREST
:
254 case GL_NEAREST_MIPMAP_LINEAR
:
255 case GL_LINEAR_MIPMAP_LINEAR
:
256 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
257 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
259 texObj
->Sampler
.MinFilter
= params
[0];
268 case GL_TEXTURE_MAG_FILTER
:
269 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
270 goto invalid_operation
;
272 if (texObj
->Sampler
.MagFilter
== params
[0])
277 flush(ctx
); /* does not effect completeness */
278 texObj
->Sampler
.MagFilter
= params
[0];
285 case GL_TEXTURE_WRAP_S
:
286 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
287 goto invalid_operation
;
289 if (texObj
->Sampler
.WrapS
== params
[0])
291 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
293 texObj
->Sampler
.WrapS
= params
[0];
298 case GL_TEXTURE_WRAP_T
:
299 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
300 goto invalid_operation
;
302 if (texObj
->Sampler
.WrapT
== params
[0])
304 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
306 texObj
->Sampler
.WrapT
= params
[0];
311 case GL_TEXTURE_WRAP_R
:
312 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
313 goto invalid_operation
;
315 if (texObj
->Sampler
.WrapR
== params
[0])
317 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
319 texObj
->Sampler
.WrapR
= params
[0];
324 case GL_TEXTURE_BASE_LEVEL
:
325 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
328 if (texObj
->BaseLevel
== params
[0])
331 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
332 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
333 goto invalid_operation
;
336 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
337 _mesa_error(ctx
, GL_INVALID_VALUE
,
338 "glTexParameter(param=%d)", params
[0]);
341 incomplete(ctx
, texObj
);
343 /** See note about ARB_texture_storage below */
344 if (texObj
->Immutable
)
345 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
347 texObj
->BaseLevel
= params
[0];
351 case GL_TEXTURE_MAX_LEVEL
:
352 if (texObj
->MaxLevel
== params
[0])
355 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
356 _mesa_error(ctx
, GL_INVALID_VALUE
,
357 "glTexParameter(param=%d)", params
[0]);
360 incomplete(ctx
, texObj
);
362 /** From ARB_texture_storage:
363 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
364 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
365 * the range [level_base, <levels> - 1], where <levels> is the parameter
366 * passed the call to TexStorage* for the texture object.
368 if (texObj
->Immutable
)
369 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
370 texObj
->ImmutableLevels
- 1);
372 texObj
->MaxLevel
= params
[0];
376 case GL_GENERATE_MIPMAP_SGIS
:
377 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
380 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
382 if (texObj
->GenerateMipmap
!= params
[0]) {
384 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
389 case GL_TEXTURE_COMPARE_MODE_ARB
:
390 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
391 || _mesa_is_gles3(ctx
)) {
393 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
394 goto invalid_operation
;
396 if (texObj
->Sampler
.CompareMode
== params
[0])
398 if (params
[0] == GL_NONE
||
399 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
401 texObj
->Sampler
.CompareMode
= params
[0];
408 case GL_TEXTURE_COMPARE_FUNC_ARB
:
409 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
410 || _mesa_is_gles3(ctx
)) {
412 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
413 goto invalid_operation
;
415 if (texObj
->Sampler
.CompareFunc
== params
[0])
427 texObj
->Sampler
.CompareFunc
= params
[0];
435 case GL_DEPTH_TEXTURE_MODE_ARB
:
436 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
437 * existed in OpenGL ES.
439 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
440 if (texObj
->DepthMode
== params
[0])
442 if (params
[0] == GL_LUMINANCE
||
443 params
[0] == GL_INTENSITY
||
444 params
[0] == GL_ALPHA
||
445 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
447 texObj
->DepthMode
= params
[0];
454 case GL_TEXTURE_CROP_RECT_OES
:
455 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
458 texObj
->CropRect
[0] = params
[0];
459 texObj
->CropRect
[1] = params
[1];
460 texObj
->CropRect
[2] = params
[2];
461 texObj
->CropRect
[3] = params
[3];
464 case GL_TEXTURE_SWIZZLE_R_EXT
:
465 case GL_TEXTURE_SWIZZLE_G_EXT
:
466 case GL_TEXTURE_SWIZZLE_B_EXT
:
467 case GL_TEXTURE_SWIZZLE_A_EXT
:
468 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
469 || _mesa_is_gles3(ctx
)) {
470 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
471 const GLint swz
= comp_to_swizzle(params
[0]);
473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
474 "glTexParameter(swizzle 0x%x)", params
[0]);
480 texObj
->Swizzle
[comp
] = params
[0];
481 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
486 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
487 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
488 || _mesa_is_gles3(ctx
)) {
491 for (comp
= 0; comp
< 4; comp
++) {
492 const GLint swz
= comp_to_swizzle(params
[comp
]);
494 texObj
->Swizzle
[comp
] = params
[comp
];
495 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
498 _mesa_error(ctx
, GL_INVALID_OPERATION
,
499 "glTexParameter(swizzle 0x%x)", params
[comp
]);
507 case GL_TEXTURE_SRGB_DECODE_EXT
:
508 if (_mesa_is_desktop_gl(ctx
)
509 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
510 GLenum decode
= params
[0];
512 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
513 goto invalid_operation
;
515 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
516 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
518 texObj
->Sampler
.sRGBDecode
= decode
;
525 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
526 if (_mesa_is_desktop_gl(ctx
)
527 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
528 GLenum param
= params
[0];
530 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
531 goto invalid_operation
;
533 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
536 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
538 texObj
->Sampler
.CubeMapSeamless
= param
;
549 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
550 _mesa_lookup_enum_by_nr(pname
));
554 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
555 _mesa_lookup_enum_by_nr(params
[0]));
559 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
560 _mesa_lookup_enum_by_nr(pname
));
566 * Set a float-valued texture parameter
567 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
570 set_tex_parameterf(struct gl_context
*ctx
,
571 struct gl_texture_object
*texObj
,
572 GLenum pname
, const GLfloat
*params
)
575 case GL_TEXTURE_MIN_LOD
:
576 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
579 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
580 goto invalid_operation
;
582 if (texObj
->Sampler
.MinLod
== params
[0])
585 texObj
->Sampler
.MinLod
= params
[0];
588 case GL_TEXTURE_MAX_LOD
:
589 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
592 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
593 goto invalid_operation
;
595 if (texObj
->Sampler
.MaxLod
== params
[0])
598 texObj
->Sampler
.MaxLod
= params
[0];
601 case GL_TEXTURE_PRIORITY
:
602 if (ctx
->API
!= API_OPENGL_COMPAT
)
606 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
609 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
610 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
611 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
612 goto invalid_operation
;
614 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
616 if (params
[0] < 1.0) {
617 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
621 /* clamp to max, that's what NVIDIA does */
622 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
623 ctx
->Const
.MaxTextureMaxAnisotropy
);
627 static GLuint count
= 0;
633 case GL_TEXTURE_LOD_BIAS
:
634 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
635 if (_mesa_is_gles(ctx
))
638 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
639 goto invalid_operation
;
641 if (texObj
->Sampler
.LodBias
!= params
[0]) {
643 texObj
->Sampler
.LodBias
= params
[0];
648 case GL_TEXTURE_BORDER_COLOR
:
649 if (!_mesa_is_desktop_gl(ctx
))
652 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
653 goto invalid_operation
;
656 /* ARB_texture_float disables clamping */
657 if (ctx
->Extensions
.ARB_texture_float
) {
658 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
659 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
660 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
661 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
663 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
664 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
665 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
666 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
676 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
677 _mesa_lookup_enum_by_nr(pname
));
681 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
682 _mesa_lookup_enum_by_nr(pname
));
688 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
690 GLboolean need_update
;
691 struct gl_texture_object
*texObj
;
692 GET_CURRENT_CONTEXT(ctx
);
694 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
699 case GL_TEXTURE_MIN_FILTER
:
700 case GL_TEXTURE_MAG_FILTER
:
701 case GL_TEXTURE_WRAP_S
:
702 case GL_TEXTURE_WRAP_T
:
703 case GL_TEXTURE_WRAP_R
:
704 case GL_TEXTURE_BASE_LEVEL
:
705 case GL_TEXTURE_MAX_LEVEL
:
706 case GL_GENERATE_MIPMAP_SGIS
:
707 case GL_TEXTURE_COMPARE_MODE_ARB
:
708 case GL_TEXTURE_COMPARE_FUNC_ARB
:
709 case GL_DEPTH_TEXTURE_MODE_ARB
:
710 case GL_TEXTURE_SRGB_DECODE_EXT
:
711 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
712 case GL_TEXTURE_SWIZZLE_R_EXT
:
713 case GL_TEXTURE_SWIZZLE_G_EXT
:
714 case GL_TEXTURE_SWIZZLE_B_EXT
:
715 case GL_TEXTURE_SWIZZLE_A_EXT
:
719 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
720 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
722 p
[1] = p
[2] = p
[3] = 0;
723 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
728 /* this will generate an error if pname is illegal */
731 p
[1] = p
[2] = p
[3] = 0.0F
;
732 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
736 if (ctx
->Driver
.TexParameter
&& need_update
) {
737 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, ¶m
);
743 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
745 GLboolean need_update
;
746 struct gl_texture_object
*texObj
;
747 GET_CURRENT_CONTEXT(ctx
);
749 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
754 case GL_TEXTURE_MIN_FILTER
:
755 case GL_TEXTURE_MAG_FILTER
:
756 case GL_TEXTURE_WRAP_S
:
757 case GL_TEXTURE_WRAP_T
:
758 case GL_TEXTURE_WRAP_R
:
759 case GL_TEXTURE_BASE_LEVEL
:
760 case GL_TEXTURE_MAX_LEVEL
:
761 case GL_GENERATE_MIPMAP_SGIS
:
762 case GL_TEXTURE_COMPARE_MODE_ARB
:
763 case GL_TEXTURE_COMPARE_FUNC_ARB
:
764 case GL_DEPTH_TEXTURE_MODE_ARB
:
765 case GL_TEXTURE_SRGB_DECODE_EXT
:
766 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
768 /* convert float param to int */
770 p
[0] = (GLint
) params
[0];
771 p
[1] = p
[2] = p
[3] = 0;
772 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
775 case GL_TEXTURE_CROP_RECT_OES
:
777 /* convert float params to int */
779 iparams
[0] = (GLint
) params
[0];
780 iparams
[1] = (GLint
) params
[1];
781 iparams
[2] = (GLint
) params
[2];
782 iparams
[3] = (GLint
) params
[3];
783 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
786 case GL_TEXTURE_SWIZZLE_R_EXT
:
787 case GL_TEXTURE_SWIZZLE_G_EXT
:
788 case GL_TEXTURE_SWIZZLE_B_EXT
:
789 case GL_TEXTURE_SWIZZLE_A_EXT
:
790 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
792 GLint p
[4] = {0, 0, 0, 0};
793 p
[0] = (GLint
) params
[0];
794 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
795 p
[1] = (GLint
) params
[1];
796 p
[2] = (GLint
) params
[2];
797 p
[3] = (GLint
) params
[3];
799 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
803 /* this will generate an error if pname is illegal */
804 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
807 if (ctx
->Driver
.TexParameter
&& need_update
) {
808 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, params
);
814 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
816 GLboolean need_update
;
817 struct gl_texture_object
*texObj
;
818 GET_CURRENT_CONTEXT(ctx
);
820 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
825 case GL_TEXTURE_MIN_LOD
:
826 case GL_TEXTURE_MAX_LOD
:
827 case GL_TEXTURE_PRIORITY
:
828 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
829 case GL_TEXTURE_LOD_BIAS
:
830 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
833 fparam
[0] = (GLfloat
) param
;
834 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
835 /* convert int param to float */
836 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
840 /* this will generate an error if pname is illegal */
844 iparam
[1] = iparam
[2] = iparam
[3] = 0;
845 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
849 if (ctx
->Driver
.TexParameter
&& need_update
) {
850 GLfloat fparam
= (GLfloat
) param
;
851 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, &fparam
);
857 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
859 GLboolean need_update
;
860 struct gl_texture_object
*texObj
;
861 GET_CURRENT_CONTEXT(ctx
);
863 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
868 case GL_TEXTURE_BORDER_COLOR
:
870 /* convert int params to float */
872 fparams
[0] = INT_TO_FLOAT(params
[0]);
873 fparams
[1] = INT_TO_FLOAT(params
[1]);
874 fparams
[2] = INT_TO_FLOAT(params
[2]);
875 fparams
[3] = INT_TO_FLOAT(params
[3]);
876 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
879 case GL_TEXTURE_MIN_LOD
:
880 case GL_TEXTURE_MAX_LOD
:
881 case GL_TEXTURE_PRIORITY
:
882 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
883 case GL_TEXTURE_LOD_BIAS
:
884 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
886 /* convert int param to float */
888 fparams
[0] = (GLfloat
) params
[0];
889 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
890 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
894 /* this will generate an error if pname is illegal */
895 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
898 if (ctx
->Driver
.TexParameter
&& need_update
) {
900 fparams
[0] = INT_TO_FLOAT(params
[0]);
901 if (pname
== GL_TEXTURE_BORDER_COLOR
||
902 pname
== GL_TEXTURE_CROP_RECT_OES
) {
903 fparams
[1] = INT_TO_FLOAT(params
[1]);
904 fparams
[2] = INT_TO_FLOAT(params
[2]);
905 fparams
[3] = INT_TO_FLOAT(params
[3]);
907 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, fparams
);
913 * Set tex parameter to integer value(s). Primarily intended to set
914 * integer-valued texture border color (for integer-valued textures).
918 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
920 struct gl_texture_object
*texObj
;
921 GET_CURRENT_CONTEXT(ctx
);
923 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
928 case GL_TEXTURE_BORDER_COLOR
:
929 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
930 /* set the integer-valued border color */
931 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
934 _mesa_TexParameteriv(target
, pname
, params
);
937 /* XXX no driver hook for TexParameterIiv() yet */
942 * Set tex parameter to unsigned integer value(s). Primarily intended to set
943 * uint-valued texture border color (for integer-valued textures).
947 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
949 struct gl_texture_object
*texObj
;
950 GET_CURRENT_CONTEXT(ctx
);
952 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
957 case GL_TEXTURE_BORDER_COLOR
:
958 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
959 /* set the unsigned integer-valued border color */
960 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
963 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
966 /* XXX no driver hook for TexParameterIuiv() yet */
971 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
975 case GL_PROXY_TEXTURE_1D
:
977 case GL_PROXY_TEXTURE_2D
:
979 case GL_PROXY_TEXTURE_3D
:
981 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
982 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
983 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
984 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
985 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
986 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
987 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
988 return ctx
->Extensions
.ARB_texture_cube_map
;
989 case GL_TEXTURE_RECTANGLE_NV
:
990 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
991 return ctx
->Extensions
.NV_texture_rectangle
;
992 case GL_TEXTURE_1D_ARRAY_EXT
:
993 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
994 case GL_TEXTURE_2D_ARRAY_EXT
:
995 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
996 return ctx
->Extensions
.EXT_texture_array
;
997 case GL_TEXTURE_BUFFER
:
998 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
999 * but not in earlier versions that expose ARB_texture_buffer_object.
1001 * From the ARB_texture_buffer_object spec:
1002 * "(7) Do buffer textures support texture parameters (TexParameter) or
1003 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1005 * RESOLVED: No. [...] Note that the spec edits above don't add
1006 * explicit error language for any of these cases. That is because
1007 * each of the functions enumerate the set of valid <target>
1008 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1009 * these cases means that target is not legal, and an INVALID_ENUM
1010 * error should be generated."
1012 * From the OpenGL 3.1 spec:
1013 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1015 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1016 case GL_TEXTURE_2D_MULTISAMPLE
:
1017 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1018 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1019 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1020 return ctx
->Extensions
.ARB_texture_multisample
;
1028 get_tex_level_parameter_image(struct gl_context
*ctx
,
1029 const struct gl_texture_object
*texObj
,
1030 GLenum target
, GLint level
,
1031 GLenum pname
, GLint
*params
)
1033 const struct gl_texture_image
*img
= NULL
;
1034 mesa_format texFormat
;
1036 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1037 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1038 /* undefined texture image */
1039 if (pname
== GL_TEXTURE_COMPONENTS
)
1046 texFormat
= img
->TexFormat
;
1049 case GL_TEXTURE_WIDTH
:
1050 *params
= img
->Width
;
1052 case GL_TEXTURE_HEIGHT
:
1053 *params
= img
->Height
;
1055 case GL_TEXTURE_DEPTH
:
1056 *params
= img
->Depth
;
1058 case GL_TEXTURE_INTERNAL_FORMAT
:
1059 if (_mesa_is_format_compressed(texFormat
)) {
1060 /* need to return the actual compressed format */
1061 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1064 /* If the true internal format is not compressed but the user
1065 * requested a generic compressed format, we have to return the
1066 * generic base format that matches.
1068 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1070 * "If no specific compressed format is available,
1071 * internalformat is instead replaced by the corresponding base
1074 * Otherwise just return the user's requested internal format
1077 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1079 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1082 case GL_TEXTURE_BORDER
:
1083 *params
= img
->Border
;
1085 case GL_TEXTURE_RED_SIZE
:
1086 case GL_TEXTURE_GREEN_SIZE
:
1087 case GL_TEXTURE_BLUE_SIZE
:
1088 case GL_TEXTURE_ALPHA_SIZE
:
1089 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1090 *params
= _mesa_get_format_bits(texFormat
, pname
);
1094 case GL_TEXTURE_INTENSITY_SIZE
:
1095 case GL_TEXTURE_LUMINANCE_SIZE
:
1096 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1097 *params
= _mesa_get_format_bits(texFormat
, pname
);
1099 /* intensity or luminance is probably stored as RGB[A] */
1100 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1101 GL_TEXTURE_RED_SIZE
),
1102 _mesa_get_format_bits(texFormat
,
1103 GL_TEXTURE_GREEN_SIZE
));
1110 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1111 if (!ctx
->Extensions
.ARB_depth_texture
)
1113 *params
= _mesa_get_format_bits(texFormat
, pname
);
1115 case GL_TEXTURE_STENCIL_SIZE
:
1116 *params
= _mesa_get_format_bits(texFormat
, pname
);
1118 case GL_TEXTURE_SHARED_SIZE
:
1119 if (ctx
->Version
< 30 &&
1120 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1122 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1125 /* GL_ARB_texture_compression */
1126 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1127 if (_mesa_is_format_compressed(texFormat
) &&
1128 !_mesa_is_proxy_texture(target
)) {
1129 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1130 img
->Height
, img
->Depth
);
1133 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1134 "glGetTexLevelParameter[if]v(pname)");
1137 case GL_TEXTURE_COMPRESSED
:
1138 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1141 /* GL_ARB_texture_float */
1142 case GL_TEXTURE_RED_TYPE_ARB
:
1143 case GL_TEXTURE_GREEN_TYPE_ARB
:
1144 case GL_TEXTURE_BLUE_TYPE_ARB
:
1145 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1146 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1147 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1148 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1149 if (!ctx
->Extensions
.ARB_texture_float
)
1151 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1152 *params
= _mesa_get_format_datatype(texFormat
);
1157 /* GL_ARB_texture_multisample */
1158 case GL_TEXTURE_SAMPLES
:
1159 if (!ctx
->Extensions
.ARB_texture_multisample
)
1161 *params
= img
->NumSamples
;
1164 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1165 if (!ctx
->Extensions
.ARB_texture_multisample
)
1167 *params
= img
->FixedSampleLocations
;
1174 /* no error if we get here */
1178 _mesa_error(ctx
, GL_INVALID_ENUM
,
1179 "glGetTexLevelParameter[if]v(pname=%s)",
1180 _mesa_lookup_enum_by_nr(pname
));
1185 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1186 const struct gl_texture_object
*texObj
,
1187 GLenum pname
, GLint
*params
)
1189 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1190 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1191 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1192 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1195 /* undefined texture buffer object */
1196 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1201 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1204 case GL_TEXTURE_WIDTH
:
1207 case GL_TEXTURE_HEIGHT
:
1208 case GL_TEXTURE_DEPTH
:
1209 case GL_TEXTURE_BORDER
:
1210 case GL_TEXTURE_SHARED_SIZE
:
1211 case GL_TEXTURE_COMPRESSED
:
1214 case GL_TEXTURE_INTERNAL_FORMAT
:
1215 *params
= internalFormat
;
1217 case GL_TEXTURE_RED_SIZE
:
1218 case GL_TEXTURE_GREEN_SIZE
:
1219 case GL_TEXTURE_BLUE_SIZE
:
1220 case GL_TEXTURE_ALPHA_SIZE
:
1221 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1222 *params
= _mesa_get_format_bits(texFormat
, pname
);
1226 case GL_TEXTURE_INTENSITY_SIZE
:
1227 case GL_TEXTURE_LUMINANCE_SIZE
:
1228 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1229 *params
= _mesa_get_format_bits(texFormat
, pname
);
1231 /* intensity or luminance is probably stored as RGB[A] */
1232 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1233 GL_TEXTURE_RED_SIZE
),
1234 _mesa_get_format_bits(texFormat
,
1235 GL_TEXTURE_GREEN_SIZE
));
1241 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1242 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1243 *params
= _mesa_get_format_bits(texFormat
, pname
);
1246 /* GL_ARB_texture_buffer_range */
1247 case GL_TEXTURE_BUFFER_OFFSET
:
1248 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1250 *params
= texObj
->BufferOffset
;
1252 case GL_TEXTURE_BUFFER_SIZE
:
1253 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1255 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1258 /* GL_ARB_texture_compression */
1259 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1260 /* Always illegal for GL_TEXTURE_BUFFER */
1261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1262 "glGetTexLevelParameter[if]v(pname)");
1265 /* GL_ARB_texture_float */
1266 case GL_TEXTURE_RED_TYPE_ARB
:
1267 case GL_TEXTURE_GREEN_TYPE_ARB
:
1268 case GL_TEXTURE_BLUE_TYPE_ARB
:
1269 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1270 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1271 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1272 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1273 if (!ctx
->Extensions
.ARB_texture_float
)
1275 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1276 *params
= _mesa_get_format_datatype(texFormat
);
1285 /* no error if we get here */
1289 _mesa_error(ctx
, GL_INVALID_ENUM
,
1290 "glGetTexLevelParameter[if]v(pname=%s)",
1291 _mesa_lookup_enum_by_nr(pname
));
1296 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1297 GLenum pname
, GLfloat
*params
)
1300 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1301 *params
= (GLfloat
) iparam
;
1306 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1307 GLenum pname
, GLint
*params
)
1309 struct gl_texture_object
*texObj
;
1311 GET_CURRENT_CONTEXT(ctx
);
1313 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1314 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1315 "glGetTexLevelParameteriv(current unit)");
1319 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1320 _mesa_error(ctx
, GL_INVALID_ENUM
,
1321 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1325 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1326 assert(maxLevels
!= 0);
1328 if (level
< 0 || level
>= maxLevels
) {
1329 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1333 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1335 if (target
== GL_TEXTURE_BUFFER
)
1336 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1338 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1343 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1345 struct gl_texture_object
*obj
;
1346 GET_CURRENT_CONTEXT(ctx
);
1348 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1352 _mesa_lock_texture(ctx
, obj
);
1354 case GL_TEXTURE_MAG_FILTER
:
1355 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1357 case GL_TEXTURE_MIN_FILTER
:
1358 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1360 case GL_TEXTURE_WRAP_S
:
1361 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1363 case GL_TEXTURE_WRAP_T
:
1364 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1366 case GL_TEXTURE_WRAP_R
:
1367 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1369 case GL_TEXTURE_BORDER_COLOR
:
1370 if (!_mesa_is_desktop_gl(ctx
))
1373 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1374 _mesa_update_state_locked(ctx
);
1375 if (_mesa_get_clamp_fragment_color(ctx
)) {
1376 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1377 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1378 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1379 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1382 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1383 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1384 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1385 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1388 case GL_TEXTURE_RESIDENT
:
1389 if (ctx
->API
!= API_OPENGL_COMPAT
)
1394 case GL_TEXTURE_PRIORITY
:
1395 if (ctx
->API
!= API_OPENGL_COMPAT
)
1398 *params
= obj
->Priority
;
1400 case GL_TEXTURE_MIN_LOD
:
1401 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1404 *params
= obj
->Sampler
.MinLod
;
1406 case GL_TEXTURE_MAX_LOD
:
1407 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1410 *params
= obj
->Sampler
.MaxLod
;
1412 case GL_TEXTURE_BASE_LEVEL
:
1413 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1416 *params
= (GLfloat
) obj
->BaseLevel
;
1418 case GL_TEXTURE_MAX_LEVEL
:
1419 *params
= (GLfloat
) obj
->MaxLevel
;
1421 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1422 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1424 *params
= obj
->Sampler
.MaxAnisotropy
;
1426 case GL_GENERATE_MIPMAP_SGIS
:
1427 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1430 *params
= (GLfloat
) obj
->GenerateMipmap
;
1432 case GL_TEXTURE_COMPARE_MODE_ARB
:
1433 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1434 && !_mesa_is_gles3(ctx
))
1436 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1438 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1439 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1440 && !_mesa_is_gles3(ctx
))
1442 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1444 case GL_DEPTH_TEXTURE_MODE_ARB
:
1445 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1446 * never existed in OpenGL ES.
1448 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1450 *params
= (GLfloat
) obj
->DepthMode
;
1452 case GL_TEXTURE_LOD_BIAS
:
1453 if (_mesa_is_gles(ctx
))
1456 *params
= obj
->Sampler
.LodBias
;
1458 case GL_TEXTURE_CROP_RECT_OES
:
1459 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1462 params
[0] = (GLfloat
) obj
->CropRect
[0];
1463 params
[1] = (GLfloat
) obj
->CropRect
[1];
1464 params
[2] = (GLfloat
) obj
->CropRect
[2];
1465 params
[3] = (GLfloat
) obj
->CropRect
[3];
1468 case GL_TEXTURE_SWIZZLE_R_EXT
:
1469 case GL_TEXTURE_SWIZZLE_G_EXT
:
1470 case GL_TEXTURE_SWIZZLE_B_EXT
:
1471 case GL_TEXTURE_SWIZZLE_A_EXT
:
1472 if ((!_mesa_is_desktop_gl(ctx
)
1473 || !ctx
->Extensions
.EXT_texture_swizzle
)
1474 && !_mesa_is_gles3(ctx
))
1476 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1479 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1480 if ((!_mesa_is_desktop_gl(ctx
)
1481 || !ctx
->Extensions
.EXT_texture_swizzle
)
1482 && !_mesa_is_gles3(ctx
)) {
1487 for (comp
= 0; comp
< 4; comp
++) {
1488 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1493 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1494 if (!_mesa_is_desktop_gl(ctx
)
1495 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1497 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1500 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1501 *params
= (GLfloat
) obj
->Immutable
;
1504 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1505 if (_mesa_is_gles3(ctx
) ||
1506 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1507 *params
= (GLfloat
) obj
->ImmutableLevels
;
1512 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1513 if (!ctx
->Extensions
.ARB_texture_view
)
1515 *params
= (GLfloat
) obj
->MinLevel
;
1518 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1519 if (!ctx
->Extensions
.ARB_texture_view
)
1521 *params
= (GLfloat
) obj
->NumLevels
;
1524 case GL_TEXTURE_VIEW_MIN_LAYER
:
1525 if (!ctx
->Extensions
.ARB_texture_view
)
1527 *params
= (GLfloat
) obj
->MinLayer
;
1530 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1531 if (!ctx
->Extensions
.ARB_texture_view
)
1533 *params
= (GLfloat
) obj
->NumLayers
;
1536 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1537 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1539 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1542 case GL_TEXTURE_SRGB_DECODE_EXT
:
1543 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1545 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1552 /* no error if we get here */
1553 _mesa_unlock_texture(ctx
, obj
);
1557 _mesa_unlock_texture(ctx
, obj
);
1558 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1563 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1565 struct gl_texture_object
*obj
;
1566 GET_CURRENT_CONTEXT(ctx
);
1568 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1572 _mesa_lock_texture(ctx
, obj
);
1574 case GL_TEXTURE_MAG_FILTER
:
1575 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1577 case GL_TEXTURE_MIN_FILTER
:
1578 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1580 case GL_TEXTURE_WRAP_S
:
1581 *params
= (GLint
) obj
->Sampler
.WrapS
;
1583 case GL_TEXTURE_WRAP_T
:
1584 *params
= (GLint
) obj
->Sampler
.WrapT
;
1586 case GL_TEXTURE_WRAP_R
:
1587 *params
= (GLint
) obj
->Sampler
.WrapR
;
1589 case GL_TEXTURE_BORDER_COLOR
:
1590 if (!_mesa_is_desktop_gl(ctx
))
1595 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1596 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1597 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1598 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1599 params
[0] = FLOAT_TO_INT(b
[0]);
1600 params
[1] = FLOAT_TO_INT(b
[1]);
1601 params
[2] = FLOAT_TO_INT(b
[2]);
1602 params
[3] = FLOAT_TO_INT(b
[3]);
1605 case GL_TEXTURE_RESIDENT
:
1606 if (ctx
->API
!= API_OPENGL_COMPAT
)
1611 case GL_TEXTURE_PRIORITY
:
1612 if (ctx
->API
!= API_OPENGL_COMPAT
)
1615 *params
= FLOAT_TO_INT(obj
->Priority
);
1617 case GL_TEXTURE_MIN_LOD
:
1618 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1621 *params
= (GLint
) obj
->Sampler
.MinLod
;
1623 case GL_TEXTURE_MAX_LOD
:
1624 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1627 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1629 case GL_TEXTURE_BASE_LEVEL
:
1630 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1633 *params
= obj
->BaseLevel
;
1635 case GL_TEXTURE_MAX_LEVEL
:
1636 *params
= obj
->MaxLevel
;
1638 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1639 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1641 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1643 case GL_GENERATE_MIPMAP_SGIS
:
1644 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1647 *params
= (GLint
) obj
->GenerateMipmap
;
1649 case GL_TEXTURE_COMPARE_MODE_ARB
:
1650 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1651 && !_mesa_is_gles3(ctx
))
1653 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1655 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1656 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1657 && !_mesa_is_gles3(ctx
))
1659 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1661 case GL_DEPTH_TEXTURE_MODE_ARB
:
1662 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1664 *params
= (GLint
) obj
->DepthMode
;
1666 case GL_TEXTURE_LOD_BIAS
:
1667 if (_mesa_is_gles(ctx
))
1670 /* GL spec 'Data Conversions' section specifies that floating-point
1671 * value in integer Get function is rounded to nearest integer
1673 *params
= IROUND(obj
->Sampler
.LodBias
);
1675 case GL_TEXTURE_CROP_RECT_OES
:
1676 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1679 params
[0] = obj
->CropRect
[0];
1680 params
[1] = obj
->CropRect
[1];
1681 params
[2] = obj
->CropRect
[2];
1682 params
[3] = obj
->CropRect
[3];
1684 case GL_TEXTURE_SWIZZLE_R_EXT
:
1685 case GL_TEXTURE_SWIZZLE_G_EXT
:
1686 case GL_TEXTURE_SWIZZLE_B_EXT
:
1687 case GL_TEXTURE_SWIZZLE_A_EXT
:
1688 if ((!_mesa_is_desktop_gl(ctx
)
1689 || !ctx
->Extensions
.EXT_texture_swizzle
)
1690 && !_mesa_is_gles3(ctx
))
1692 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1695 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1696 if ((!_mesa_is_desktop_gl(ctx
)
1697 || !ctx
->Extensions
.EXT_texture_swizzle
)
1698 && !_mesa_is_gles3(ctx
))
1700 COPY_4V(params
, obj
->Swizzle
);
1703 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1704 if (!_mesa_is_desktop_gl(ctx
)
1705 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1707 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1710 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1711 *params
= (GLint
) obj
->Immutable
;
1714 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1715 if (_mesa_is_gles3(ctx
) ||
1716 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1717 *params
= obj
->ImmutableLevels
;
1722 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1723 if (!ctx
->Extensions
.ARB_texture_view
)
1725 *params
= (GLint
) obj
->MinLevel
;
1728 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1729 if (!ctx
->Extensions
.ARB_texture_view
)
1731 *params
= (GLint
) obj
->NumLevels
;
1734 case GL_TEXTURE_VIEW_MIN_LAYER
:
1735 if (!ctx
->Extensions
.ARB_texture_view
)
1737 *params
= (GLint
) obj
->MinLayer
;
1740 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1741 if (!ctx
->Extensions
.ARB_texture_view
)
1743 *params
= (GLint
) obj
->NumLayers
;
1746 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1747 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1749 *params
= obj
->RequiredTextureImageUnits
;
1752 case GL_TEXTURE_SRGB_DECODE_EXT
:
1753 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1755 *params
= obj
->Sampler
.sRGBDecode
;
1758 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1759 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1761 *params
= obj
->ImageFormatCompatibilityType
;
1768 /* no error if we get here */
1769 _mesa_unlock_texture(ctx
, obj
);
1773 _mesa_unlock_texture(ctx
, obj
);
1774 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1778 /** New in GL 3.0 */
1780 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1782 struct gl_texture_object
*texObj
;
1783 GET_CURRENT_CONTEXT(ctx
);
1785 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1790 case GL_TEXTURE_BORDER_COLOR
:
1791 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1794 _mesa_GetTexParameteriv(target
, pname
, params
);
1799 /** New in GL 3.0 */
1801 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1803 struct gl_texture_object
*texObj
;
1804 GET_CURRENT_CONTEXT(ctx
);
1806 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1811 case GL_TEXTURE_BORDER_COLOR
:
1812 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1817 _mesa_GetTexParameteriv(target
, pname
, ip
);
1819 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1820 pname
== GL_TEXTURE_CROP_RECT_OES
) {