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/context.h"
36 #include "main/enums.h"
37 #include "main/formats.h"
38 #include "main/glformats.h"
39 #include "main/macros.h"
40 #include "main/mtypes.h"
41 #include "main/state.h"
42 #include "main/texcompress.h"
43 #include "main/texobj.h"
44 #include "main/texparam.h"
45 #include "main/teximage.h"
46 #include "main/texstate.h"
47 #include "program/prog_instruction.h"
51 * Check if a coordinate wrap mode is supported for the texture target.
52 * \return GL_TRUE if legal, GL_FALSE otherwise
55 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
57 const struct gl_extensions
* const e
= & ctx
->Extensions
;
58 const bool is_desktop_gl
= _mesa_is_desktop_gl(ctx
);
63 /* GL_CLAMP was removed in the core profile, and it has never existed in
66 supported
= (ctx
->API
== API_OPENGL_COMPAT
)
67 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
70 case GL_CLAMP_TO_EDGE
:
74 case GL_CLAMP_TO_BORDER
:
75 supported
= ctx
->API
!= API_OPENGLES
&& e
->ARB_texture_border_clamp
76 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
80 case GL_MIRRORED_REPEAT
:
81 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
82 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
85 case GL_MIRROR_CLAMP_EXT
:
86 supported
= is_desktop_gl
87 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
88 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
89 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
92 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
93 supported
= is_desktop_gl
94 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
)
95 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
96 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
99 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
100 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
101 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
102 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
111 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
118 * Get current texture object for given target.
119 * Return NULL if any error (and record the error).
120 * Note that this is different from _mesa_get_current_tex_object() in that
121 * proxy targets are not accepted.
122 * Only the glGetTexLevelParameter() functions accept proxy targets.
124 static struct gl_texture_object
*
125 get_texobj_by_target(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
127 struct gl_texture_unit
*texUnit
;
130 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
131 _mesa_error(ctx
, GL_INVALID_OPERATION
,
132 "gl%sTexParameter(current unit)", get
? "Get" : "");
136 texUnit
= _mesa_get_current_tex_unit(ctx
);
138 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
139 if (targetIndex
< 0 || targetIndex
== TEXTURE_BUFFER_INDEX
) {
140 _mesa_error(ctx
, GL_INVALID_ENUM
,
141 "gl%sTexParameter(target)", get
? "Get" : "");
144 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
146 return texUnit
->CurrentTex
[targetIndex
];
150 * Get current texture object for given name.
151 * Return NULL if any error (and record the error).
152 * Note that proxy targets are not accepted.
153 * Only the glGetTexLevelParameter() functions accept proxy targets.
155 static struct gl_texture_object
*
156 get_texobj_by_name(struct gl_context
*ctx
, GLuint texture
, GLboolean get
)
158 struct gl_texture_object
*texObj
;
160 texObj
= _mesa_lookup_texture(ctx
, texture
);
163 * User passed a non-generated name.
164 * Throw the error in the caller.
169 switch (texObj
->Target
) {
171 case GL_TEXTURE_1D_ARRAY
:
173 case GL_TEXTURE_2D_ARRAY
:
174 case GL_TEXTURE_2D_MULTISAMPLE
:
175 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
177 case GL_TEXTURE_CUBE_MAP
:
178 case GL_TEXTURE_CUBE_MAP_ARRAY
:
179 case GL_TEXTURE_RECTANGLE
:
182 _mesa_error(ctx
, GL_INVALID_ENUM
,
183 "gl%sTextureParameter(target)", get
? "Get" : "");
191 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
192 * \return -1 if error.
195 comp_to_swizzle(GLenum comp
)
217 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
220 assert(swz
<= SWIZZLE_NIL
);
222 GLuint mask
= 0x7 << (3 * comp
);
223 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
230 * This is called just prior to changing any texture object state which
231 * will not affect texture completeness.
234 flush(struct gl_context
*ctx
)
236 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
241 * This is called just prior to changing any texture object state which
242 * could affect texture completeness (texture base level, max level).
243 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
244 * state flag and then mark the texture object as 'incomplete' so that any
245 * per-texture derived state gets recomputed.
248 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
250 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
251 _mesa_dirty_texobj(ctx
, texObj
);
256 _mesa_target_allows_setting_sampler_parameters(GLenum target
)
259 case GL_TEXTURE_2D_MULTISAMPLE
:
260 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
270 * Set an integer-valued texture parameter
271 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
274 set_tex_parameteri(struct gl_context
*ctx
,
275 struct gl_texture_object
*texObj
,
276 GLenum pname
, const GLint
*params
, bool dsa
)
278 const char *suffix
= dsa
? "ture" : "";
281 case GL_TEXTURE_MIN_FILTER
:
282 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
285 if (texObj
->Sampler
.MinFilter
== params
[0])
291 texObj
->Sampler
.MinFilter
= params
[0];
293 case GL_NEAREST_MIPMAP_NEAREST
:
294 case GL_LINEAR_MIPMAP_NEAREST
:
295 case GL_NEAREST_MIPMAP_LINEAR
:
296 case GL_LINEAR_MIPMAP_LINEAR
:
297 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
298 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
300 texObj
->Sampler
.MinFilter
= params
[0];
309 case GL_TEXTURE_MAG_FILTER
:
310 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
313 if (texObj
->Sampler
.MagFilter
== params
[0])
318 flush(ctx
); /* does not effect completeness */
319 texObj
->Sampler
.MagFilter
= params
[0];
326 case GL_TEXTURE_WRAP_S
:
327 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
330 if (texObj
->Sampler
.WrapS
== params
[0])
332 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
334 texObj
->Sampler
.WrapS
= params
[0];
339 case GL_TEXTURE_WRAP_T
:
340 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
343 if (texObj
->Sampler
.WrapT
== params
[0])
345 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
347 texObj
->Sampler
.WrapT
= params
[0];
352 case GL_TEXTURE_WRAP_R
:
353 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
356 if (texObj
->Sampler
.WrapR
== params
[0])
358 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
360 texObj
->Sampler
.WrapR
= params
[0];
365 case GL_TEXTURE_BASE_LEVEL
:
366 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
369 if (texObj
->BaseLevel
== params
[0])
372 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
373 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
374 goto invalid_operation
;
377 _mesa_error(ctx
, GL_INVALID_VALUE
,
378 "glTex%sParameter(param=%d)", suffix
, params
[0]);
381 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0) {
382 _mesa_error(ctx
, GL_INVALID_OPERATION
,
383 "glTex%sParameter(target=%s, param=%d)", suffix
,
384 _mesa_enum_to_string(texObj
->Target
), params
[0]);
387 incomplete(ctx
, texObj
);
389 /** See note about ARB_texture_storage below */
390 if (texObj
->Immutable
)
391 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
393 texObj
->BaseLevel
= params
[0];
397 case GL_TEXTURE_MAX_LEVEL
:
398 if (texObj
->MaxLevel
== params
[0])
402 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
403 _mesa_error(ctx
, GL_INVALID_VALUE
,
404 "glTex%sParameter(param=%d)", suffix
,
408 incomplete(ctx
, texObj
);
410 /** From ARB_texture_storage:
411 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
412 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
413 * the range [level_base, <levels> - 1], where <levels> is the parameter
414 * passed the call to TexStorage* for the texture object.
416 if (texObj
->Immutable
)
417 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
418 texObj
->ImmutableLevels
- 1);
420 texObj
->MaxLevel
= params
[0];
424 case GL_GENERATE_MIPMAP_SGIS
:
425 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
428 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
430 if (texObj
->GenerateMipmap
!= params
[0]) {
432 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
437 case GL_TEXTURE_COMPARE_MODE_ARB
:
438 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
439 || _mesa_is_gles3(ctx
)) {
441 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
444 if (texObj
->Sampler
.CompareMode
== params
[0])
446 if (params
[0] == GL_NONE
||
447 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
449 texObj
->Sampler
.CompareMode
= params
[0];
456 case GL_TEXTURE_COMPARE_FUNC_ARB
:
457 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
458 || _mesa_is_gles3(ctx
)) {
460 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
463 if (texObj
->Sampler
.CompareFunc
== params
[0])
475 texObj
->Sampler
.CompareFunc
= params
[0];
483 case GL_DEPTH_TEXTURE_MODE_ARB
:
484 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
485 * existed in OpenGL ES.
487 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
488 if (texObj
->DepthMode
== params
[0])
490 if (params
[0] == GL_LUMINANCE
||
491 params
[0] == GL_INTENSITY
||
492 params
[0] == GL_ALPHA
||
493 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
495 texObj
->DepthMode
= params
[0];
502 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
503 if (_mesa_has_ARB_stencil_texturing(ctx
) || _mesa_is_gles31(ctx
)) {
504 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
505 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
508 if (texObj
->StencilSampling
== stencil
)
511 texObj
->StencilSampling
= stencil
;
516 case GL_TEXTURE_CROP_RECT_OES
:
517 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
520 texObj
->CropRect
[0] = params
[0];
521 texObj
->CropRect
[1] = params
[1];
522 texObj
->CropRect
[2] = params
[2];
523 texObj
->CropRect
[3] = params
[3];
526 case GL_TEXTURE_SWIZZLE_R_EXT
:
527 case GL_TEXTURE_SWIZZLE_G_EXT
:
528 case GL_TEXTURE_SWIZZLE_B_EXT
:
529 case GL_TEXTURE_SWIZZLE_A_EXT
:
530 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
531 || _mesa_is_gles3(ctx
)) {
532 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
533 const GLint swz
= comp_to_swizzle(params
[0]);
535 _mesa_error(ctx
, GL_INVALID_ENUM
,
536 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
542 texObj
->Swizzle
[comp
] = params
[0];
543 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
548 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
549 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
550 || _mesa_is_gles3(ctx
)) {
553 for (comp
= 0; comp
< 4; comp
++) {
554 const GLint swz
= comp_to_swizzle(params
[comp
]);
556 texObj
->Swizzle
[comp
] = params
[comp
];
557 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
560 _mesa_error(ctx
, GL_INVALID_ENUM
,
561 "glTex%sParameter(swizzle 0x%x)",
562 suffix
, params
[comp
]);
570 case GL_TEXTURE_SRGB_DECODE_EXT
:
571 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
572 GLenum decode
= params
[0];
574 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
577 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
578 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
580 texObj
->Sampler
.sRGBDecode
= decode
;
587 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
588 if (_mesa_is_desktop_gl(ctx
)
589 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
590 GLenum param
= params
[0];
592 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
595 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
598 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
600 texObj
->Sampler
.CubeMapSeamless
= param
;
611 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
612 suffix
, _mesa_enum_to_string(pname
));
616 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
617 suffix
, _mesa_enum_to_string(params
[0]));
621 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
622 suffix
, _mesa_enum_to_string(pname
));
626 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
627 suffix
, _mesa_enum_to_string(pname
));
633 * Set a float-valued texture parameter
634 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
637 set_tex_parameterf(struct gl_context
*ctx
,
638 struct gl_texture_object
*texObj
,
639 GLenum pname
, const GLfloat
*params
, bool dsa
)
641 const char *suffix
= dsa
? "ture" : "";
644 case GL_TEXTURE_MIN_LOD
:
645 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
648 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
651 if (texObj
->Sampler
.MinLod
== params
[0])
654 texObj
->Sampler
.MinLod
= params
[0];
657 case GL_TEXTURE_MAX_LOD
:
658 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
661 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
664 if (texObj
->Sampler
.MaxLod
== params
[0])
667 texObj
->Sampler
.MaxLod
= params
[0];
670 case GL_TEXTURE_PRIORITY
:
671 if (ctx
->API
!= API_OPENGL_COMPAT
)
675 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
678 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
679 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
680 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
683 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
685 if (params
[0] < 1.0F
) {
686 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
691 /* clamp to max, that's what NVIDIA does */
692 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
693 ctx
->Const
.MaxTextureMaxAnisotropy
);
697 static GLuint count
= 0;
703 case GL_TEXTURE_LOD_BIAS
:
704 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
705 if (_mesa_is_gles(ctx
))
708 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
711 if (texObj
->Sampler
.LodBias
!= params
[0]) {
713 texObj
->Sampler
.LodBias
= params
[0];
718 case GL_TEXTURE_BORDER_COLOR
:
719 if (ctx
->API
== API_OPENGLES
||
720 !ctx
->Extensions
.ARB_texture_border_clamp
)
723 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
727 /* ARB_texture_float disables clamping */
728 if (ctx
->Extensions
.ARB_texture_float
) {
729 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
730 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
731 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
732 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
734 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
735 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
736 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
737 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
747 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
748 suffix
, _mesa_enum_to_string(pname
));
752 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
753 suffix
, _mesa_enum_to_string(pname
));
759 _mesa_texture_parameterf(struct gl_context
*ctx
,
760 struct gl_texture_object
*texObj
,
761 GLenum pname
, GLfloat param
, bool dsa
)
763 GLboolean need_update
;
766 case GL_TEXTURE_MIN_FILTER
:
767 case GL_TEXTURE_MAG_FILTER
:
768 case GL_TEXTURE_WRAP_S
:
769 case GL_TEXTURE_WRAP_T
:
770 case GL_TEXTURE_WRAP_R
:
771 case GL_TEXTURE_BASE_LEVEL
:
772 case GL_TEXTURE_MAX_LEVEL
:
773 case GL_GENERATE_MIPMAP_SGIS
:
774 case GL_TEXTURE_COMPARE_MODE_ARB
:
775 case GL_TEXTURE_COMPARE_FUNC_ARB
:
776 case GL_DEPTH_TEXTURE_MODE_ARB
:
777 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
778 case GL_TEXTURE_SRGB_DECODE_EXT
:
779 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
780 case GL_TEXTURE_SWIZZLE_R_EXT
:
781 case GL_TEXTURE_SWIZZLE_G_EXT
:
782 case GL_TEXTURE_SWIZZLE_B_EXT
:
783 case GL_TEXTURE_SWIZZLE_A_EXT
:
787 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
788 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
790 p
[1] = p
[2] = p
[3] = 0;
791 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
794 case GL_TEXTURE_BORDER_COLOR
:
795 case GL_TEXTURE_SWIZZLE_RGBA
:
796 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
801 /* this will generate an error if pname is illegal */
804 p
[1] = p
[2] = p
[3] = 0.0F
;
805 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
809 if (ctx
->Driver
.TexParameter
&& need_update
) {
810 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
816 _mesa_texture_parameterfv(struct gl_context
*ctx
,
817 struct gl_texture_object
*texObj
,
818 GLenum pname
, const GLfloat
*params
, bool dsa
)
820 GLboolean need_update
;
822 case GL_TEXTURE_MIN_FILTER
:
823 case GL_TEXTURE_MAG_FILTER
:
824 case GL_TEXTURE_WRAP_S
:
825 case GL_TEXTURE_WRAP_T
:
826 case GL_TEXTURE_WRAP_R
:
827 case GL_TEXTURE_BASE_LEVEL
:
828 case GL_TEXTURE_MAX_LEVEL
:
829 case GL_GENERATE_MIPMAP_SGIS
:
830 case GL_TEXTURE_COMPARE_MODE_ARB
:
831 case GL_TEXTURE_COMPARE_FUNC_ARB
:
832 case GL_DEPTH_TEXTURE_MODE_ARB
:
833 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
834 case GL_TEXTURE_SRGB_DECODE_EXT
:
835 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
837 /* convert float param to int */
839 p
[0] = (GLint
) params
[0];
840 p
[1] = p
[2] = p
[3] = 0;
841 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
844 case GL_TEXTURE_CROP_RECT_OES
:
846 /* convert float params to int */
848 iparams
[0] = (GLint
) params
[0];
849 iparams
[1] = (GLint
) params
[1];
850 iparams
[2] = (GLint
) params
[2];
851 iparams
[3] = (GLint
) params
[3];
852 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
855 case GL_TEXTURE_SWIZZLE_R_EXT
:
856 case GL_TEXTURE_SWIZZLE_G_EXT
:
857 case GL_TEXTURE_SWIZZLE_B_EXT
:
858 case GL_TEXTURE_SWIZZLE_A_EXT
:
859 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
861 GLint p
[4] = {0, 0, 0, 0};
862 p
[0] = (GLint
) params
[0];
863 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
864 p
[1] = (GLint
) params
[1];
865 p
[2] = (GLint
) params
[2];
866 p
[3] = (GLint
) params
[3];
868 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
872 /* this will generate an error if pname is illegal */
873 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
876 if (ctx
->Driver
.TexParameter
&& need_update
) {
877 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
883 _mesa_texture_parameteri(struct gl_context
*ctx
,
884 struct gl_texture_object
*texObj
,
885 GLenum pname
, GLint param
, bool dsa
)
887 GLboolean need_update
;
889 case GL_TEXTURE_MIN_LOD
:
890 case GL_TEXTURE_MAX_LOD
:
891 case GL_TEXTURE_PRIORITY
:
892 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
893 case GL_TEXTURE_LOD_BIAS
:
894 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
897 fparam
[0] = (GLfloat
) param
;
898 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
899 /* convert int param to float */
900 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
903 case GL_TEXTURE_BORDER_COLOR
:
904 case GL_TEXTURE_SWIZZLE_RGBA
:
906 _mesa_error(ctx
, GL_INVALID_ENUM
,
907 "glTex%sParameteri(non-scalar pname)",
912 /* this will generate an error if pname is illegal */
916 iparam
[1] = iparam
[2] = iparam
[3] = 0;
917 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
921 if (ctx
->Driver
.TexParameter
&& need_update
) {
922 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
928 _mesa_texture_parameteriv(struct gl_context
*ctx
,
929 struct gl_texture_object
*texObj
,
930 GLenum pname
, const GLint
*params
, bool dsa
)
932 GLboolean need_update
;
935 case GL_TEXTURE_BORDER_COLOR
:
937 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
938 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameteriv(texture)");
941 /* convert int params to float */
943 fparams
[0] = INT_TO_FLOAT(params
[0]);
944 fparams
[1] = INT_TO_FLOAT(params
[1]);
945 fparams
[2] = INT_TO_FLOAT(params
[2]);
946 fparams
[3] = INT_TO_FLOAT(params
[3]);
947 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
950 case GL_TEXTURE_MIN_LOD
:
951 case GL_TEXTURE_MAX_LOD
:
952 case GL_TEXTURE_PRIORITY
:
953 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
954 case GL_TEXTURE_LOD_BIAS
:
955 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
957 /* convert int param to float */
959 fparams
[0] = (GLfloat
) params
[0];
960 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
961 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
965 /* this will generate an error if pname is illegal */
966 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
969 if (ctx
->Driver
.TexParameter
&& need_update
) {
970 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
975 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
976 struct gl_texture_object
*texObj
,
977 GLenum pname
, const GLint
*params
, bool dsa
)
980 case GL_TEXTURE_BORDER_COLOR
:
981 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
982 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIiv(texture)");
985 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
986 /* set the integer-valued border color */
987 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
990 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
993 /* XXX no driver hook for TexParameterIiv() yet */
997 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
998 struct gl_texture_object
*texObj
,
999 GLenum pname
, const GLuint
*params
, bool dsa
)
1002 case GL_TEXTURE_BORDER_COLOR
:
1003 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1004 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIuiv(texture)");
1007 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1008 /* set the unsigned integer-valued border color */
1009 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1012 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1016 /* XXX no driver hook for TexParameterIuiv() yet */
1020 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1022 struct gl_texture_object
*texObj
;
1023 GET_CURRENT_CONTEXT(ctx
);
1025 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1029 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1033 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1035 struct gl_texture_object
*texObj
;
1036 GET_CURRENT_CONTEXT(ctx
);
1038 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1042 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1046 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1048 struct gl_texture_object
*texObj
;
1049 GET_CURRENT_CONTEXT(ctx
);
1051 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1055 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1059 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1061 struct gl_texture_object
*texObj
;
1062 GET_CURRENT_CONTEXT(ctx
);
1064 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1068 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1072 * Set tex parameter to integer value(s). Primarily intended to set
1073 * integer-valued texture border color (for integer-valued textures).
1077 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1079 struct gl_texture_object
*texObj
;
1080 GET_CURRENT_CONTEXT(ctx
);
1082 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1086 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1090 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1091 * uint-valued texture border color (for integer-valued textures).
1095 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1097 struct gl_texture_object
*texObj
;
1098 GET_CURRENT_CONTEXT(ctx
);
1100 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1104 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1109 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1111 struct gl_texture_object
*texObj
;
1112 GET_CURRENT_CONTEXT(ctx
);
1114 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1116 /* User passed a non-generated name. */
1117 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterfv(texture)");
1121 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1125 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1127 struct gl_texture_object
*texObj
;
1128 GET_CURRENT_CONTEXT(ctx
);
1130 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1132 /* User passed a non-generated name. */
1133 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterf(texture)");
1137 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1141 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1143 struct gl_texture_object
*texObj
;
1144 GET_CURRENT_CONTEXT(ctx
);
1146 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1148 /* User passed a non-generated name. */
1149 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteri(texture)");
1153 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1157 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1158 const GLint
*params
)
1160 struct gl_texture_object
*texObj
;
1161 GET_CURRENT_CONTEXT(ctx
);
1163 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1165 /* User passed a non-generated name. */
1166 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteriv(texture)");
1170 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1175 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1177 struct gl_texture_object
*texObj
;
1178 GET_CURRENT_CONTEXT(ctx
);
1180 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1182 /* User passed a non-generated name. */
1183 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1184 "glTextureParameterIiv(texture)");
1188 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1192 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1194 struct gl_texture_object
*texObj
;
1195 GET_CURRENT_CONTEXT(ctx
);
1197 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1199 /* User passed a non-generated name. */
1200 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1201 "glTextureParameterIuiv(texture)");
1205 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1209 _mesa_legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1212 /* Common targets for desktop GL and GLES 3.1. */
1217 case GL_TEXTURE_2D_ARRAY_EXT
:
1218 return ctx
->Extensions
.EXT_texture_array
;
1219 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1220 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1221 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1222 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1223 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1224 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1225 return ctx
->Extensions
.ARB_texture_cube_map
;
1226 case GL_TEXTURE_2D_MULTISAMPLE
:
1227 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1228 return ctx
->Extensions
.ARB_texture_multisample
;
1229 case GL_TEXTURE_BUFFER
:
1230 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1231 * but not in earlier versions that expose ARB_texture_buffer_object.
1233 * From the ARB_texture_buffer_object spec:
1234 * "(7) Do buffer textures support texture parameters (TexParameter) or
1235 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1237 * RESOLVED: No. [...] Note that the spec edits above don't add
1238 * explicit error language for any of these cases. That is because
1239 * each of the functions enumerate the set of valid <target>
1240 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1241 * these cases means that target is not legal, and an INVALID_ENUM
1242 * error should be generated."
1244 * From the OpenGL 3.1 spec:
1245 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1247 return (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31) ||
1248 _mesa_has_OES_texture_buffer(ctx
);
1249 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1250 return _mesa_has_texture_cube_map_array(ctx
);
1253 if (!_mesa_is_desktop_gl(ctx
))
1256 /* Rest of the desktop GL targets. */
1259 case GL_PROXY_TEXTURE_1D
:
1260 case GL_PROXY_TEXTURE_2D
:
1261 case GL_PROXY_TEXTURE_3D
:
1263 case GL_PROXY_TEXTURE_CUBE_MAP
:
1264 return ctx
->Extensions
.ARB_texture_cube_map
;
1265 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1266 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1267 case GL_TEXTURE_RECTANGLE_NV
:
1268 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1269 return ctx
->Extensions
.NV_texture_rectangle
;
1270 case GL_TEXTURE_1D_ARRAY_EXT
:
1271 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1272 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1273 return ctx
->Extensions
.EXT_texture_array
;
1274 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1275 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1276 return ctx
->Extensions
.ARB_texture_multisample
;
1278 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1279 * (30.10.2014) Section 8.11 Texture Queries says:
1280 * "For GetTextureLevelParameter* only, texture may also be a cube
1281 * map texture object. In this case the query is always performed
1282 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1283 * is no way to specify another face."
1285 case GL_TEXTURE_CUBE_MAP
:
1294 get_tex_level_parameter_image(struct gl_context
*ctx
,
1295 const struct gl_texture_object
*texObj
,
1296 GLenum target
, GLint level
,
1297 GLenum pname
, GLint
*params
,
1300 const struct gl_texture_image
*img
= NULL
;
1301 struct gl_texture_image dummy_image
;
1302 mesa_format texFormat
;
1303 const char *suffix
= dsa
? "ture" : "";
1305 img
= _mesa_select_tex_image(texObj
, target
, level
);
1306 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1307 /* In case of undefined texture image return the default values.
1309 * From OpenGL 4.0 spec, page 398:
1310 * "The initial internal format of a texel array is RGBA
1311 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1312 * use TEXTURE_INTERNAL_FORMAT."
1314 memset(&dummy_image
, 0, sizeof(dummy_image
));
1315 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1316 dummy_image
.InternalFormat
= GL_RGBA
;
1317 dummy_image
._BaseFormat
= GL_NONE
;
1318 dummy_image
.FixedSampleLocations
= GL_TRUE
;
1323 texFormat
= img
->TexFormat
;
1326 case GL_TEXTURE_WIDTH
:
1327 *params
= img
->Width
;
1329 case GL_TEXTURE_HEIGHT
:
1330 *params
= img
->Height
;
1332 case GL_TEXTURE_DEPTH
:
1333 *params
= img
->Depth
;
1335 case GL_TEXTURE_INTERNAL_FORMAT
:
1336 if (_mesa_is_format_compressed(texFormat
)) {
1337 /* need to return the actual compressed format */
1338 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1341 /* If the true internal format is not compressed but the user
1342 * requested a generic compressed format, we have to return the
1343 * generic base format that matches.
1345 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1347 * "If no specific compressed format is available,
1348 * internalformat is instead replaced by the corresponding base
1351 * Otherwise just return the user's requested internal format
1354 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1356 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1359 case GL_TEXTURE_BORDER
:
1360 if (ctx
->API
!= API_OPENGL_COMPAT
)
1362 *params
= img
->Border
;
1364 case GL_TEXTURE_RED_SIZE
:
1365 case GL_TEXTURE_GREEN_SIZE
:
1366 case GL_TEXTURE_BLUE_SIZE
:
1367 case GL_TEXTURE_ALPHA_SIZE
:
1368 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1369 *params
= _mesa_get_format_bits(texFormat
, pname
);
1373 case GL_TEXTURE_INTENSITY_SIZE
:
1374 case GL_TEXTURE_LUMINANCE_SIZE
:
1375 if (ctx
->API
!= API_OPENGL_COMPAT
)
1377 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1378 *params
= _mesa_get_format_bits(texFormat
, pname
);
1380 /* intensity or luminance is probably stored as RGB[A] */
1381 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1382 GL_TEXTURE_RED_SIZE
),
1383 _mesa_get_format_bits(texFormat
,
1384 GL_TEXTURE_GREEN_SIZE
));
1391 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1392 if (!ctx
->Extensions
.ARB_depth_texture
)
1394 *params
= _mesa_get_format_bits(texFormat
, pname
);
1396 case GL_TEXTURE_STENCIL_SIZE
:
1397 *params
= _mesa_get_format_bits(texFormat
, pname
);
1399 case GL_TEXTURE_SHARED_SIZE
:
1400 if (ctx
->Version
< 30 &&
1401 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1403 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1406 /* GL_ARB_texture_compression */
1407 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1408 if (_mesa_is_format_compressed(texFormat
) &&
1409 !_mesa_is_proxy_texture(target
)) {
1410 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1411 img
->Height
, img
->Depth
);
1414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1415 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1416 _mesa_enum_to_string(pname
));
1419 case GL_TEXTURE_COMPRESSED
:
1420 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1423 /* GL_ARB_texture_float */
1424 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1425 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1426 if (ctx
->API
!= API_OPENGL_COMPAT
)
1429 case GL_TEXTURE_RED_TYPE_ARB
:
1430 case GL_TEXTURE_GREEN_TYPE_ARB
:
1431 case GL_TEXTURE_BLUE_TYPE_ARB
:
1432 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1433 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1434 if (!ctx
->Extensions
.ARB_texture_float
)
1436 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1437 *params
= _mesa_get_format_datatype(texFormat
);
1442 /* GL_ARB_texture_multisample */
1443 case GL_TEXTURE_SAMPLES
:
1444 if (!ctx
->Extensions
.ARB_texture_multisample
)
1446 *params
= img
->NumSamples
;
1449 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1450 if (!ctx
->Extensions
.ARB_texture_multisample
)
1452 *params
= img
->FixedSampleLocations
;
1455 /* There is never a buffer data store here, but these pnames still have
1459 /* GL_ARB_texture_buffer_object */
1460 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1461 if (!ctx
->Extensions
.ARB_texture_buffer_object
)
1466 /* GL_ARB_texture_buffer_range */
1467 case GL_TEXTURE_BUFFER_OFFSET
:
1468 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1472 case GL_TEXTURE_BUFFER_SIZE
:
1473 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1482 /* no error if we get here */
1486 _mesa_error(ctx
, GL_INVALID_ENUM
,
1487 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1488 _mesa_enum_to_string(pname
));
1493 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1496 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1497 const struct gl_texture_object
*texObj
,
1498 GLenum pname
, GLint
*params
, bool dsa
)
1500 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1501 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1502 int bytes
= MAX2(1, _mesa_get_format_bytes(texFormat
));
1503 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1504 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1505 const char *suffix
= dsa
? "ture" : "";
1507 assert(texObj
->Target
== GL_TEXTURE_BUFFER
);
1510 /* undefined texture buffer object */
1512 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1515 case GL_TEXTURE_INTERNAL_FORMAT
:
1516 *params
= internalFormat
;
1526 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1529 case GL_TEXTURE_WIDTH
:
1530 *params
= ((texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
)
1533 case GL_TEXTURE_HEIGHT
:
1534 case GL_TEXTURE_DEPTH
:
1537 case GL_TEXTURE_BORDER
:
1538 case GL_TEXTURE_SHARED_SIZE
:
1539 case GL_TEXTURE_COMPRESSED
:
1542 case GL_TEXTURE_INTERNAL_FORMAT
:
1543 *params
= internalFormat
;
1545 case GL_TEXTURE_RED_SIZE
:
1546 case GL_TEXTURE_GREEN_SIZE
:
1547 case GL_TEXTURE_BLUE_SIZE
:
1548 case GL_TEXTURE_ALPHA_SIZE
:
1549 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1550 *params
= _mesa_get_format_bits(texFormat
, pname
);
1554 case GL_TEXTURE_INTENSITY_SIZE
:
1555 case GL_TEXTURE_LUMINANCE_SIZE
:
1556 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1557 *params
= _mesa_get_format_bits(texFormat
, pname
);
1559 /* intensity or luminance is probably stored as RGB[A] */
1560 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1561 GL_TEXTURE_RED_SIZE
),
1562 _mesa_get_format_bits(texFormat
,
1563 GL_TEXTURE_GREEN_SIZE
));
1569 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1570 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1571 *params
= _mesa_get_format_bits(texFormat
, pname
);
1574 /* GL_ARB_texture_buffer_range */
1575 case GL_TEXTURE_BUFFER_OFFSET
:
1576 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1578 *params
= texObj
->BufferOffset
;
1580 case GL_TEXTURE_BUFFER_SIZE
:
1581 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1583 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1586 /* GL_ARB_texture_multisample */
1587 case GL_TEXTURE_SAMPLES
:
1588 if (!ctx
->Extensions
.ARB_texture_multisample
)
1593 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1594 if (!ctx
->Extensions
.ARB_texture_multisample
)
1599 /* GL_ARB_texture_compression */
1600 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1601 /* Always illegal for GL_TEXTURE_BUFFER */
1602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1603 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1604 _mesa_enum_to_string(pname
));
1607 /* GL_ARB_texture_float */
1608 case GL_TEXTURE_RED_TYPE_ARB
:
1609 case GL_TEXTURE_GREEN_TYPE_ARB
:
1610 case GL_TEXTURE_BLUE_TYPE_ARB
:
1611 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1612 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1613 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1614 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1615 if (!ctx
->Extensions
.ARB_texture_float
)
1617 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1618 *params
= _mesa_get_format_datatype(texFormat
);
1627 /* no error if we get here */
1631 _mesa_error(ctx
, GL_INVALID_ENUM
,
1632 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1633 _mesa_enum_to_string(pname
));
1637 valid_tex_level_parameteriv_target(struct gl_context
*ctx
, GLenum target
,
1640 const char *suffix
= dsa
? "ture" : "";
1641 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1642 _mesa_error(ctx
, GL_INVALID_ENUM
,
1643 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1644 _mesa_enum_to_string(target
));
1651 * This isn't exposed to the rest of the driver because it is a part of the
1652 * OpenGL API that is rarely used.
1655 get_tex_level_parameteriv(struct gl_context
*ctx
,
1656 struct gl_texture_object
*texObj
,
1657 GLenum target
, GLint level
,
1658 GLenum pname
, GLint
*params
,
1662 const char *suffix
= dsa
? "ture" : "";
1664 /* Check for errors */
1665 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1667 "glGetTex%sLevelParameter[if]v("
1668 "current unit >= max combined texture units)", suffix
);
1672 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1673 assert(maxLevels
!= 0);
1675 if (level
< 0 || level
>= maxLevels
) {
1676 _mesa_error(ctx
, GL_INVALID_VALUE
,
1677 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1681 /* Get the level parameter */
1682 if (target
== GL_TEXTURE_BUFFER
) {
1683 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1686 get_tex_level_parameter_image(ctx
, texObj
, target
,
1687 level
, pname
, params
, dsa
);
1692 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1693 GLenum pname
, GLfloat
*params
)
1695 struct gl_texture_object
*texObj
;
1697 GET_CURRENT_CONTEXT(ctx
);
1699 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1702 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1706 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1707 pname
, &iparam
, false);
1709 *params
= (GLfloat
) iparam
;
1713 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1714 GLenum pname
, GLint
*params
)
1716 struct gl_texture_object
*texObj
;
1717 GET_CURRENT_CONTEXT(ctx
);
1719 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1722 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1726 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1727 pname
, params
, false);
1731 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1732 GLenum pname
, GLfloat
*params
)
1734 struct gl_texture_object
*texObj
;
1736 GET_CURRENT_CONTEXT(ctx
);
1738 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1739 "glGetTextureLevelParameterfv");
1743 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1746 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1747 pname
, &iparam
, true);
1749 *params
= (GLfloat
) iparam
;
1753 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1754 GLenum pname
, GLint
*params
)
1756 struct gl_texture_object
*texObj
;
1757 GET_CURRENT_CONTEXT(ctx
);
1759 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1760 "glGetTextureLevelParameteriv");
1764 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1767 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1768 pname
, params
, true);
1772 * This isn't exposed to the rest of the driver because it is a part of the
1773 * OpenGL API that is rarely used.
1776 get_tex_parameterfv(struct gl_context
*ctx
,
1777 struct gl_texture_object
*obj
,
1778 GLenum pname
, GLfloat
*params
, bool dsa
)
1780 _mesa_lock_context_textures(ctx
);
1782 case GL_TEXTURE_MAG_FILTER
:
1783 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1785 case GL_TEXTURE_MIN_FILTER
:
1786 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1788 case GL_TEXTURE_WRAP_S
:
1789 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1791 case GL_TEXTURE_WRAP_T
:
1792 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1794 case GL_TEXTURE_WRAP_R
:
1795 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1797 case GL_TEXTURE_BORDER_COLOR
:
1798 if (ctx
->API
== API_OPENGLES
||
1799 !ctx
->Extensions
.ARB_texture_border_clamp
)
1802 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1803 _mesa_update_state_locked(ctx
);
1804 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
1805 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1806 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1807 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1808 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1811 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1812 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1813 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1814 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1817 case GL_TEXTURE_RESIDENT
:
1818 if (ctx
->API
!= API_OPENGL_COMPAT
)
1823 case GL_TEXTURE_PRIORITY
:
1824 if (ctx
->API
!= API_OPENGL_COMPAT
)
1827 *params
= obj
->Priority
;
1829 case GL_TEXTURE_MIN_LOD
:
1830 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1833 *params
= obj
->Sampler
.MinLod
;
1835 case GL_TEXTURE_MAX_LOD
:
1836 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1839 *params
= obj
->Sampler
.MaxLod
;
1841 case GL_TEXTURE_BASE_LEVEL
:
1842 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1845 *params
= (GLfloat
) obj
->BaseLevel
;
1847 case GL_TEXTURE_MAX_LEVEL
:
1848 *params
= (GLfloat
) obj
->MaxLevel
;
1850 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1851 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1853 *params
= obj
->Sampler
.MaxAnisotropy
;
1855 case GL_GENERATE_MIPMAP_SGIS
:
1856 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1859 *params
= (GLfloat
) obj
->GenerateMipmap
;
1861 case GL_TEXTURE_COMPARE_MODE_ARB
:
1862 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1863 && !_mesa_is_gles3(ctx
))
1865 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1867 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1868 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1869 && !_mesa_is_gles3(ctx
))
1871 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1873 case GL_DEPTH_TEXTURE_MODE_ARB
:
1874 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1875 * never existed in OpenGL ES.
1877 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1879 *params
= (GLfloat
) obj
->DepthMode
;
1881 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1882 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
1885 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1887 case GL_TEXTURE_LOD_BIAS
:
1888 if (_mesa_is_gles(ctx
))
1891 *params
= obj
->Sampler
.LodBias
;
1893 case GL_TEXTURE_CROP_RECT_OES
:
1894 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1897 params
[0] = (GLfloat
) obj
->CropRect
[0];
1898 params
[1] = (GLfloat
) obj
->CropRect
[1];
1899 params
[2] = (GLfloat
) obj
->CropRect
[2];
1900 params
[3] = (GLfloat
) obj
->CropRect
[3];
1903 case GL_TEXTURE_SWIZZLE_R_EXT
:
1904 case GL_TEXTURE_SWIZZLE_G_EXT
:
1905 case GL_TEXTURE_SWIZZLE_B_EXT
:
1906 case GL_TEXTURE_SWIZZLE_A_EXT
:
1907 if ((!_mesa_is_desktop_gl(ctx
)
1908 || !ctx
->Extensions
.EXT_texture_swizzle
)
1909 && !_mesa_is_gles3(ctx
))
1911 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1914 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1915 if ((!_mesa_is_desktop_gl(ctx
)
1916 || !ctx
->Extensions
.EXT_texture_swizzle
)
1917 && !_mesa_is_gles3(ctx
)) {
1922 for (comp
= 0; comp
< 4; comp
++) {
1923 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1928 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1929 if (!_mesa_is_desktop_gl(ctx
)
1930 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1932 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1935 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1936 *params
= (GLfloat
) obj
->Immutable
;
1939 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1940 if (_mesa_is_gles3(ctx
) ||
1941 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1942 *params
= (GLfloat
) obj
->ImmutableLevels
;
1947 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1948 if (!ctx
->Extensions
.ARB_texture_view
)
1950 *params
= (GLfloat
) obj
->MinLevel
;
1953 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1954 if (!ctx
->Extensions
.ARB_texture_view
)
1956 *params
= (GLfloat
) obj
->NumLevels
;
1959 case GL_TEXTURE_VIEW_MIN_LAYER
:
1960 if (!ctx
->Extensions
.ARB_texture_view
)
1962 *params
= (GLfloat
) obj
->MinLayer
;
1965 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1966 if (!ctx
->Extensions
.ARB_texture_view
)
1968 *params
= (GLfloat
) obj
->NumLayers
;
1971 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1972 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1974 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1977 case GL_TEXTURE_SRGB_DECODE_EXT
:
1978 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1980 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1983 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1984 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1986 *params
= (GLfloat
) obj
->ImageFormatCompatibilityType
;
1989 case GL_TEXTURE_TARGET
:
1990 if (ctx
->API
!= API_OPENGL_CORE
)
1992 *params
= ENUM_TO_FLOAT(obj
->Target
);
1999 /* no error if we get here */
2000 _mesa_unlock_context_textures(ctx
);
2004 _mesa_unlock_context_textures(ctx
);
2005 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
2006 dsa
? "ture" : "", pname
);
2011 get_tex_parameteriv(struct gl_context
*ctx
,
2012 struct gl_texture_object
*obj
,
2013 GLenum pname
, GLint
*params
, bool dsa
)
2015 _mesa_lock_texture(ctx
, obj
);
2017 case GL_TEXTURE_MAG_FILTER
:
2018 *params
= (GLint
) obj
->Sampler
.MagFilter
;
2020 case GL_TEXTURE_MIN_FILTER
:
2021 *params
= (GLint
) obj
->Sampler
.MinFilter
;
2023 case GL_TEXTURE_WRAP_S
:
2024 *params
= (GLint
) obj
->Sampler
.WrapS
;
2026 case GL_TEXTURE_WRAP_T
:
2027 *params
= (GLint
) obj
->Sampler
.WrapT
;
2029 case GL_TEXTURE_WRAP_R
:
2030 *params
= (GLint
) obj
->Sampler
.WrapR
;
2032 case GL_TEXTURE_BORDER_COLOR
:
2033 if (ctx
->API
== API_OPENGLES
||
2034 !ctx
->Extensions
.ARB_texture_border_clamp
)
2039 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
2040 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
2041 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
2042 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
2043 params
[0] = FLOAT_TO_INT(b
[0]);
2044 params
[1] = FLOAT_TO_INT(b
[1]);
2045 params
[2] = FLOAT_TO_INT(b
[2]);
2046 params
[3] = FLOAT_TO_INT(b
[3]);
2049 case GL_TEXTURE_RESIDENT
:
2050 if (ctx
->API
!= API_OPENGL_COMPAT
)
2055 case GL_TEXTURE_PRIORITY
:
2056 if (ctx
->API
!= API_OPENGL_COMPAT
)
2059 *params
= FLOAT_TO_INT(obj
->Priority
);
2061 case GL_TEXTURE_MIN_LOD
:
2062 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2064 /* GL spec 'Data Conversions' section specifies that floating-point
2065 * value in integer Get function is rounded to nearest integer
2067 *params
= IROUND(obj
->Sampler
.MinLod
);
2069 case GL_TEXTURE_MAX_LOD
:
2070 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2072 /* GL spec 'Data Conversions' section specifies that floating-point
2073 * value in integer Get function is rounded to nearest integer
2075 *params
= IROUND(obj
->Sampler
.MaxLod
);
2077 case GL_TEXTURE_BASE_LEVEL
:
2078 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2081 *params
= obj
->BaseLevel
;
2083 case GL_TEXTURE_MAX_LEVEL
:
2084 *params
= obj
->MaxLevel
;
2086 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2087 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2089 /* GL spec 'Data Conversions' section specifies that floating-point
2090 * value in integer Get function is rounded to nearest integer
2092 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
2094 case GL_GENERATE_MIPMAP_SGIS
:
2095 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2098 *params
= (GLint
) obj
->GenerateMipmap
;
2100 case GL_TEXTURE_COMPARE_MODE_ARB
:
2101 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2102 && !_mesa_is_gles3(ctx
))
2104 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2106 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2107 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2108 && !_mesa_is_gles3(ctx
))
2110 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2112 case GL_DEPTH_TEXTURE_MODE_ARB
:
2113 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2115 *params
= (GLint
) obj
->DepthMode
;
2117 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2118 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
2121 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2123 case GL_TEXTURE_LOD_BIAS
:
2124 if (_mesa_is_gles(ctx
))
2127 /* GL spec 'Data Conversions' section specifies that floating-point
2128 * value in integer Get function is rounded to nearest integer
2130 *params
= IROUND(obj
->Sampler
.LodBias
);
2132 case GL_TEXTURE_CROP_RECT_OES
:
2133 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2136 params
[0] = obj
->CropRect
[0];
2137 params
[1] = obj
->CropRect
[1];
2138 params
[2] = obj
->CropRect
[2];
2139 params
[3] = obj
->CropRect
[3];
2141 case GL_TEXTURE_SWIZZLE_R_EXT
:
2142 case GL_TEXTURE_SWIZZLE_G_EXT
:
2143 case GL_TEXTURE_SWIZZLE_B_EXT
:
2144 case GL_TEXTURE_SWIZZLE_A_EXT
:
2145 if ((!_mesa_is_desktop_gl(ctx
)
2146 || !ctx
->Extensions
.EXT_texture_swizzle
)
2147 && !_mesa_is_gles3(ctx
))
2149 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2152 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2153 if ((!_mesa_is_desktop_gl(ctx
)
2154 || !ctx
->Extensions
.EXT_texture_swizzle
)
2155 && !_mesa_is_gles3(ctx
))
2157 COPY_4V(params
, obj
->Swizzle
);
2160 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2161 if (!_mesa_is_desktop_gl(ctx
)
2162 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2164 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2167 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2168 *params
= (GLint
) obj
->Immutable
;
2171 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2172 if (_mesa_is_gles3(ctx
) ||
2173 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2174 *params
= obj
->ImmutableLevels
;
2179 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2180 if (!ctx
->Extensions
.ARB_texture_view
)
2182 *params
= (GLint
) obj
->MinLevel
;
2185 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2186 if (!ctx
->Extensions
.ARB_texture_view
)
2188 *params
= (GLint
) obj
->NumLevels
;
2191 case GL_TEXTURE_VIEW_MIN_LAYER
:
2192 if (!ctx
->Extensions
.ARB_texture_view
)
2194 *params
= (GLint
) obj
->MinLayer
;
2197 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2198 if (!ctx
->Extensions
.ARB_texture_view
)
2200 *params
= (GLint
) obj
->NumLayers
;
2203 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2204 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2206 *params
= obj
->RequiredTextureImageUnits
;
2209 case GL_TEXTURE_SRGB_DECODE_EXT
:
2210 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2212 *params
= obj
->Sampler
.sRGBDecode
;
2215 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2216 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2218 *params
= obj
->ImageFormatCompatibilityType
;
2221 case GL_TEXTURE_TARGET
:
2222 if (ctx
->API
!= API_OPENGL_CORE
)
2224 *params
= (GLint
) obj
->Target
;
2231 /* no error if we get here */
2232 _mesa_unlock_texture(ctx
, obj
);
2236 _mesa_unlock_texture(ctx
, obj
);
2237 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2238 dsa
? "ture" : "", pname
);
2242 get_tex_parameterIiv(struct gl_context
*ctx
,
2243 struct gl_texture_object
*obj
,
2244 GLenum pname
, GLint
*params
, bool dsa
)
2247 case GL_TEXTURE_BORDER_COLOR
:
2248 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2251 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2256 get_tex_parameterIuiv(struct gl_context
*ctx
,
2257 struct gl_texture_object
*obj
,
2258 GLenum pname
, GLuint
*params
, bool dsa
)
2261 case GL_TEXTURE_BORDER_COLOR
:
2262 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2267 get_tex_parameteriv(ctx
, obj
, pname
, ip
, dsa
);
2269 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
2270 pname
== GL_TEXTURE_CROP_RECT_OES
) {
2280 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2282 struct gl_texture_object
*obj
;
2283 GET_CURRENT_CONTEXT(ctx
);
2285 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2289 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2293 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2295 struct gl_texture_object
*obj
;
2296 GET_CURRENT_CONTEXT(ctx
);
2298 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2302 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2305 /** New in GL 3.0 */
2307 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
2309 struct gl_texture_object
*texObj
;
2310 GET_CURRENT_CONTEXT(ctx
);
2312 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2316 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, false);
2320 /** New in GL 3.0 */
2322 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2324 struct gl_texture_object
*texObj
;
2325 GET_CURRENT_CONTEXT(ctx
);
2327 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2331 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, false);
2336 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2338 struct gl_texture_object
*obj
;
2339 GET_CURRENT_CONTEXT(ctx
);
2341 obj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2343 /* User passed a non-generated name. */
2344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2345 "glGetTextureParameterfv(texture)");
2349 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2353 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2355 struct gl_texture_object
*obj
;
2356 GET_CURRENT_CONTEXT(ctx
);
2358 obj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2360 /* User passed a non-generated name. */
2361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2362 "glGetTextureParameteriv(texture)");
2366 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2370 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2372 struct gl_texture_object
*texObj
;
2373 GET_CURRENT_CONTEXT(ctx
);
2375 texObj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2377 /* User passed a non-generated name. */
2378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2379 "glGetTextureParameterIiv(texture)");
2383 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2388 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2390 struct gl_texture_object
*texObj
;
2391 GET_CURRENT_CONTEXT(ctx
);
2393 texObj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2395 /* User passed a non-generated name. */
2396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2397 "glGetTextureParameterIuiv(texture)");
2401 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, true);