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_by_target(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
];
151 * Get current texture object for given name.
152 * Return NULL if any error (and record the error).
153 * Note that proxy targets are not accepted.
154 * Only the glGetTexLevelParameter() functions accept proxy targets.
156 static struct gl_texture_object
*
157 get_texobj_by_name(struct gl_context
*ctx
, GLuint texture
, GLboolean get
)
159 struct gl_texture_object
*texObj
;
161 texObj
= _mesa_lookup_texture(ctx
, texture
);
164 * User passed a non-generated name.
165 * Throw the error in the caller.
170 switch (texObj
->Target
) {
172 case GL_TEXTURE_1D_ARRAY
:
174 case GL_TEXTURE_2D_ARRAY
:
175 case GL_TEXTURE_2D_MULTISAMPLE
:
176 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
178 case GL_TEXTURE_CUBE_MAP
:
179 case GL_TEXTURE_CUBE_MAP_ARRAY
:
180 case GL_TEXTURE_RECTANGLE
:
183 _mesa_error(ctx
, GL_INVALID_ENUM
,
184 "gl%sTextureParameter(target)", get
? "Get" : "");
192 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
193 * \return -1 if error.
196 comp_to_swizzle(GLenum comp
)
218 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
221 ASSERT(swz
<= SWIZZLE_NIL
);
223 GLuint mask
= 0x7 << (3 * comp
);
224 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
231 * This is called just prior to changing any texture object state which
232 * will not affect texture completeness.
235 flush(struct gl_context
*ctx
)
237 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
242 * This is called just prior to changing any texture object state which
243 * could affect texture completeness (texture base level, max level).
244 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
245 * state flag and then mark the texture object as 'incomplete' so that any
246 * per-texture derived state gets recomputed.
249 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
251 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
252 _mesa_dirty_texobj(ctx
, texObj
);
257 target_allows_setting_sampler_parameters(GLenum target
)
260 case GL_TEXTURE_2D_MULTISAMPLE
:
261 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
271 * Set an integer-valued texture parameter
272 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
275 set_tex_parameteri(struct gl_context
*ctx
,
276 struct gl_texture_object
*texObj
,
277 GLenum pname
, const GLint
*params
, bool dsa
)
279 const char *suffix
= dsa
? "ture" : "";
282 case GL_TEXTURE_MIN_FILTER
:
283 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
286 if (texObj
->Sampler
.MinFilter
== params
[0])
292 texObj
->Sampler
.MinFilter
= params
[0];
294 case GL_NEAREST_MIPMAP_NEAREST
:
295 case GL_LINEAR_MIPMAP_NEAREST
:
296 case GL_NEAREST_MIPMAP_LINEAR
:
297 case GL_LINEAR_MIPMAP_LINEAR
:
298 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
299 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
301 texObj
->Sampler
.MinFilter
= params
[0];
310 case GL_TEXTURE_MAG_FILTER
:
311 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
314 if (texObj
->Sampler
.MagFilter
== params
[0])
319 flush(ctx
); /* does not effect completeness */
320 texObj
->Sampler
.MagFilter
= params
[0];
327 case GL_TEXTURE_WRAP_S
:
328 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
331 if (texObj
->Sampler
.WrapS
== params
[0])
333 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
335 texObj
->Sampler
.WrapS
= params
[0];
340 case GL_TEXTURE_WRAP_T
:
341 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
344 if (texObj
->Sampler
.WrapT
== params
[0])
346 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
348 texObj
->Sampler
.WrapT
= params
[0];
353 case GL_TEXTURE_WRAP_R
:
354 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
357 if (texObj
->Sampler
.WrapR
== params
[0])
359 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
361 texObj
->Sampler
.WrapR
= params
[0];
366 case GL_TEXTURE_BASE_LEVEL
:
367 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
370 if (texObj
->BaseLevel
== params
[0])
373 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
374 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
375 goto invalid_operation
;
378 _mesa_error(ctx
, GL_INVALID_VALUE
,
379 "glTex%sParameter(param=%d)", suffix
, params
[0]);
382 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0) {
383 _mesa_error(ctx
, GL_INVALID_OPERATION
,
384 "glTex%sParameter(target=%s, param=%d)", suffix
,
385 _mesa_lookup_enum_by_nr(texObj
->Target
), params
[0]);
388 incomplete(ctx
, texObj
);
390 /** See note about ARB_texture_storage below */
391 if (texObj
->Immutable
)
392 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
394 texObj
->BaseLevel
= params
[0];
398 case GL_TEXTURE_MAX_LEVEL
:
399 if (texObj
->MaxLevel
== params
[0])
403 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
404 _mesa_error(ctx
, GL_INVALID_VALUE
,
405 "glTex%sParameter(param=%d)", suffix
,
409 incomplete(ctx
, texObj
);
411 /** From ARB_texture_storage:
412 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
413 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
414 * the range [level_base, <levels> - 1], where <levels> is the parameter
415 * passed the call to TexStorage* for the texture object.
417 if (texObj
->Immutable
)
418 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
419 texObj
->ImmutableLevels
- 1);
421 texObj
->MaxLevel
= params
[0];
425 case GL_GENERATE_MIPMAP_SGIS
:
426 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
429 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
431 if (texObj
->GenerateMipmap
!= params
[0]) {
433 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
438 case GL_TEXTURE_COMPARE_MODE_ARB
:
439 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
440 || _mesa_is_gles3(ctx
)) {
442 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
445 if (texObj
->Sampler
.CompareMode
== params
[0])
447 if (params
[0] == GL_NONE
||
448 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
450 texObj
->Sampler
.CompareMode
= params
[0];
457 case GL_TEXTURE_COMPARE_FUNC_ARB
:
458 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
459 || _mesa_is_gles3(ctx
)) {
461 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
464 if (texObj
->Sampler
.CompareFunc
== params
[0])
476 texObj
->Sampler
.CompareFunc
= params
[0];
484 case GL_DEPTH_TEXTURE_MODE_ARB
:
485 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
486 * existed in OpenGL ES.
488 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
489 if (texObj
->DepthMode
== params
[0])
491 if (params
[0] == GL_LUMINANCE
||
492 params
[0] == GL_INTENSITY
||
493 params
[0] == GL_ALPHA
||
494 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
496 texObj
->DepthMode
= params
[0];
503 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
504 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_stencil_texturing
) {
505 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
506 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
509 if (texObj
->StencilSampling
== stencil
)
512 texObj
->StencilSampling
= stencil
;
517 case GL_TEXTURE_CROP_RECT_OES
:
518 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
521 texObj
->CropRect
[0] = params
[0];
522 texObj
->CropRect
[1] = params
[1];
523 texObj
->CropRect
[2] = params
[2];
524 texObj
->CropRect
[3] = params
[3];
527 case GL_TEXTURE_SWIZZLE_R_EXT
:
528 case GL_TEXTURE_SWIZZLE_G_EXT
:
529 case GL_TEXTURE_SWIZZLE_B_EXT
:
530 case GL_TEXTURE_SWIZZLE_A_EXT
:
531 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
532 || _mesa_is_gles3(ctx
)) {
533 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
534 const GLint swz
= comp_to_swizzle(params
[0]);
536 _mesa_error(ctx
, GL_INVALID_ENUM
,
537 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
543 texObj
->Swizzle
[comp
] = params
[0];
544 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
549 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
550 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
551 || _mesa_is_gles3(ctx
)) {
554 for (comp
= 0; comp
< 4; comp
++) {
555 const GLint swz
= comp_to_swizzle(params
[comp
]);
557 texObj
->Swizzle
[comp
] = params
[comp
];
558 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
561 _mesa_error(ctx
, GL_INVALID_ENUM
,
562 "glTex%sParameter(swizzle 0x%x)",
563 suffix
, params
[comp
]);
571 case GL_TEXTURE_SRGB_DECODE_EXT
:
572 if (_mesa_is_desktop_gl(ctx
)
573 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
574 GLenum decode
= params
[0];
576 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
579 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
580 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
582 texObj
->Sampler
.sRGBDecode
= decode
;
589 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
590 if (_mesa_is_desktop_gl(ctx
)
591 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
592 GLenum param
= params
[0];
594 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
597 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
600 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
602 texObj
->Sampler
.CubeMapSeamless
= param
;
613 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
614 suffix
, _mesa_lookup_enum_by_nr(pname
));
618 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
619 suffix
, _mesa_lookup_enum_by_nr(params
[0]));
623 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
624 suffix
, _mesa_lookup_enum_by_nr(pname
));
628 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
629 suffix
, _mesa_lookup_enum_by_nr(pname
));
635 * Set a float-valued texture parameter
636 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
639 set_tex_parameterf(struct gl_context
*ctx
,
640 struct gl_texture_object
*texObj
,
641 GLenum pname
, const GLfloat
*params
, bool dsa
)
643 const char *suffix
= dsa
? "ture" : "";
646 case GL_TEXTURE_MIN_LOD
:
647 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
650 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
653 if (texObj
->Sampler
.MinLod
== params
[0])
656 texObj
->Sampler
.MinLod
= params
[0];
659 case GL_TEXTURE_MAX_LOD
:
660 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
663 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
666 if (texObj
->Sampler
.MaxLod
== params
[0])
669 texObj
->Sampler
.MaxLod
= params
[0];
672 case GL_TEXTURE_PRIORITY
:
673 if (ctx
->API
!= API_OPENGL_COMPAT
)
677 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
680 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
681 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
682 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
685 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
687 if (params
[0] < 1.0) {
688 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
693 /* clamp to max, that's what NVIDIA does */
694 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
695 ctx
->Const
.MaxTextureMaxAnisotropy
);
699 static GLuint count
= 0;
705 case GL_TEXTURE_LOD_BIAS
:
706 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
707 if (_mesa_is_gles(ctx
))
710 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
713 if (texObj
->Sampler
.LodBias
!= params
[0]) {
715 texObj
->Sampler
.LodBias
= params
[0];
720 case GL_TEXTURE_BORDER_COLOR
:
721 if (!_mesa_is_desktop_gl(ctx
))
724 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
728 /* ARB_texture_float disables clamping */
729 if (ctx
->Extensions
.ARB_texture_float
) {
730 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
731 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
732 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
733 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
735 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
736 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
737 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
738 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
748 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
749 suffix
, _mesa_lookup_enum_by_nr(pname
));
753 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
754 suffix
, _mesa_lookup_enum_by_nr(pname
));
760 _mesa_texture_parameterf(struct gl_context
*ctx
,
761 struct gl_texture_object
*texObj
,
762 GLenum pname
, GLfloat param
, bool dsa
)
764 GLboolean need_update
;
767 case GL_TEXTURE_MIN_FILTER
:
768 case GL_TEXTURE_MAG_FILTER
:
769 case GL_TEXTURE_WRAP_S
:
770 case GL_TEXTURE_WRAP_T
:
771 case GL_TEXTURE_WRAP_R
:
772 case GL_TEXTURE_BASE_LEVEL
:
773 case GL_TEXTURE_MAX_LEVEL
:
774 case GL_GENERATE_MIPMAP_SGIS
:
775 case GL_TEXTURE_COMPARE_MODE_ARB
:
776 case GL_TEXTURE_COMPARE_FUNC_ARB
:
777 case GL_DEPTH_TEXTURE_MODE_ARB
:
778 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
779 case GL_TEXTURE_SRGB_DECODE_EXT
:
780 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
781 case GL_TEXTURE_SWIZZLE_R_EXT
:
782 case GL_TEXTURE_SWIZZLE_G_EXT
:
783 case GL_TEXTURE_SWIZZLE_B_EXT
:
784 case GL_TEXTURE_SWIZZLE_A_EXT
:
788 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
789 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
791 p
[1] = p
[2] = p
[3] = 0;
792 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
795 case GL_TEXTURE_BORDER_COLOR
:
796 case GL_TEXTURE_SWIZZLE_RGBA
:
797 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
802 /* this will generate an error if pname is illegal */
805 p
[1] = p
[2] = p
[3] = 0.0F
;
806 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
810 if (ctx
->Driver
.TexParameter
&& need_update
) {
811 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, ¶m
);
817 _mesa_texture_parameterfv(struct gl_context
*ctx
,
818 struct gl_texture_object
*texObj
,
819 GLenum pname
, const GLfloat
*params
, bool dsa
)
821 GLboolean need_update
;
823 case GL_TEXTURE_MIN_FILTER
:
824 case GL_TEXTURE_MAG_FILTER
:
825 case GL_TEXTURE_WRAP_S
:
826 case GL_TEXTURE_WRAP_T
:
827 case GL_TEXTURE_WRAP_R
:
828 case GL_TEXTURE_BASE_LEVEL
:
829 case GL_TEXTURE_MAX_LEVEL
:
830 case GL_GENERATE_MIPMAP_SGIS
:
831 case GL_TEXTURE_COMPARE_MODE_ARB
:
832 case GL_TEXTURE_COMPARE_FUNC_ARB
:
833 case GL_DEPTH_TEXTURE_MODE_ARB
:
834 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
835 case GL_TEXTURE_SRGB_DECODE_EXT
:
836 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
838 /* convert float param to int */
840 p
[0] = (GLint
) params
[0];
841 p
[1] = p
[2] = p
[3] = 0;
842 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
845 case GL_TEXTURE_CROP_RECT_OES
:
847 /* convert float params to int */
849 iparams
[0] = (GLint
) params
[0];
850 iparams
[1] = (GLint
) params
[1];
851 iparams
[2] = (GLint
) params
[2];
852 iparams
[3] = (GLint
) params
[3];
853 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
856 case GL_TEXTURE_SWIZZLE_R_EXT
:
857 case GL_TEXTURE_SWIZZLE_G_EXT
:
858 case GL_TEXTURE_SWIZZLE_B_EXT
:
859 case GL_TEXTURE_SWIZZLE_A_EXT
:
860 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
862 GLint p
[4] = {0, 0, 0, 0};
863 p
[0] = (GLint
) params
[0];
864 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
865 p
[1] = (GLint
) params
[1];
866 p
[2] = (GLint
) params
[2];
867 p
[3] = (GLint
) params
[3];
869 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
873 /* this will generate an error if pname is illegal */
874 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
877 if (ctx
->Driver
.TexParameter
&& need_update
) {
878 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, params
);
884 _mesa_texture_parameteri(struct gl_context
*ctx
,
885 struct gl_texture_object
*texObj
,
886 GLenum pname
, GLint param
, bool dsa
)
888 GLboolean need_update
;
890 case GL_TEXTURE_MIN_LOD
:
891 case GL_TEXTURE_MAX_LOD
:
892 case GL_TEXTURE_PRIORITY
:
893 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
894 case GL_TEXTURE_LOD_BIAS
:
895 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
898 fparam
[0] = (GLfloat
) param
;
899 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
900 /* convert int param to float */
901 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
904 case GL_TEXTURE_BORDER_COLOR
:
905 case GL_TEXTURE_SWIZZLE_RGBA
:
907 _mesa_error(ctx
, GL_INVALID_ENUM
,
908 "glTex%sParameteri(non-scalar pname)",
913 /* this will generate an error if pname is illegal */
917 iparam
[1] = iparam
[2] = iparam
[3] = 0;
918 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
922 if (ctx
->Driver
.TexParameter
&& need_update
) {
923 GLfloat fparam
= (GLfloat
) param
;
924 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, &fparam
);
930 _mesa_texture_parameteriv(struct gl_context
*ctx
,
931 struct gl_texture_object
*texObj
,
932 GLenum pname
, const GLint
*params
, bool dsa
)
934 GLboolean need_update
;
937 case GL_TEXTURE_BORDER_COLOR
:
939 /* convert int params to float */
941 fparams
[0] = INT_TO_FLOAT(params
[0]);
942 fparams
[1] = INT_TO_FLOAT(params
[1]);
943 fparams
[2] = INT_TO_FLOAT(params
[2]);
944 fparams
[3] = INT_TO_FLOAT(params
[3]);
945 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
948 case GL_TEXTURE_MIN_LOD
:
949 case GL_TEXTURE_MAX_LOD
:
950 case GL_TEXTURE_PRIORITY
:
951 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
952 case GL_TEXTURE_LOD_BIAS
:
953 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
955 /* convert int param to float */
957 fparams
[0] = (GLfloat
) params
[0];
958 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
959 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
963 /* this will generate an error if pname is illegal */
964 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
967 if (ctx
->Driver
.TexParameter
&& need_update
) {
969 fparams
[0] = INT_TO_FLOAT(params
[0]);
970 if (pname
== GL_TEXTURE_BORDER_COLOR
||
971 pname
== GL_TEXTURE_CROP_RECT_OES
) {
972 fparams
[1] = INT_TO_FLOAT(params
[1]);
973 fparams
[2] = INT_TO_FLOAT(params
[2]);
974 fparams
[3] = INT_TO_FLOAT(params
[3]);
976 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, fparams
);
981 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
982 struct gl_texture_object
*texObj
,
983 GLenum pname
, const GLint
*params
, bool dsa
)
986 case GL_TEXTURE_BORDER_COLOR
:
987 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
988 /* set the integer-valued border color */
989 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
992 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
995 /* XXX no driver hook for TexParameterIiv() yet */
999 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
1000 struct gl_texture_object
*texObj
,
1001 GLenum pname
, const GLuint
*params
, bool dsa
)
1004 case GL_TEXTURE_BORDER_COLOR
:
1005 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1006 /* set the unsigned integer-valued border color */
1007 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1010 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1014 /* XXX no driver hook for TexParameterIuiv() yet */
1018 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1020 struct gl_texture_object
*texObj
;
1021 GET_CURRENT_CONTEXT(ctx
);
1023 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1027 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1031 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1033 struct gl_texture_object
*texObj
;
1034 GET_CURRENT_CONTEXT(ctx
);
1036 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1040 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1044 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1046 struct gl_texture_object
*texObj
;
1047 GET_CURRENT_CONTEXT(ctx
);
1049 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1053 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1057 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1059 struct gl_texture_object
*texObj
;
1060 GET_CURRENT_CONTEXT(ctx
);
1062 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1066 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1070 * Set tex parameter to integer value(s). Primarily intended to set
1071 * integer-valued texture border color (for integer-valued textures).
1075 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1077 struct gl_texture_object
*texObj
;
1078 GET_CURRENT_CONTEXT(ctx
);
1080 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1084 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1088 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1089 * uint-valued texture border color (for integer-valued textures).
1093 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1095 struct gl_texture_object
*texObj
;
1096 GET_CURRENT_CONTEXT(ctx
);
1098 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1102 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1107 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1109 struct gl_texture_object
*texObj
;
1110 GET_CURRENT_CONTEXT(ctx
);
1112 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1114 /* User passed a non-generated name. */
1115 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterfv(texture)");
1119 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1123 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1125 struct gl_texture_object
*texObj
;
1126 GET_CURRENT_CONTEXT(ctx
);
1128 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1130 /* User passed a non-generated name. */
1131 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterf(texture)");
1135 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1139 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1141 struct gl_texture_object
*texObj
;
1142 GET_CURRENT_CONTEXT(ctx
);
1144 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1146 /* User passed a non-generated name. */
1147 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteri(texture)");
1151 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1155 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1156 const GLint
*params
)
1158 struct gl_texture_object
*texObj
;
1159 GET_CURRENT_CONTEXT(ctx
);
1161 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1163 /* User passed a non-generated name. */
1164 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteriv(texture)");
1168 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1173 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1175 struct gl_texture_object
*texObj
;
1176 GET_CURRENT_CONTEXT(ctx
);
1178 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1180 /* User passed a non-generated name. */
1181 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1182 "glTextureParameterIiv(texture)");
1186 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1190 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1192 struct gl_texture_object
*texObj
;
1193 GET_CURRENT_CONTEXT(ctx
);
1195 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1197 /* User passed a non-generated name. */
1198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1199 "glTextureParameterIuiv(texture)");
1203 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1207 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1212 case GL_PROXY_TEXTURE_1D
:
1214 case GL_PROXY_TEXTURE_2D
:
1216 case GL_PROXY_TEXTURE_3D
:
1218 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1219 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1220 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1221 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1222 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1223 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1224 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1225 return ctx
->Extensions
.ARB_texture_cube_map
;
1226 case GL_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1227 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1228 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1229 case GL_TEXTURE_RECTANGLE_NV
:
1230 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1231 return ctx
->Extensions
.NV_texture_rectangle
;
1232 case GL_TEXTURE_1D_ARRAY_EXT
:
1233 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1234 case GL_TEXTURE_2D_ARRAY_EXT
:
1235 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1236 return ctx
->Extensions
.EXT_texture_array
;
1237 case GL_TEXTURE_BUFFER
:
1238 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1239 * but not in earlier versions that expose ARB_texture_buffer_object.
1241 * From the ARB_texture_buffer_object spec:
1242 * "(7) Do buffer textures support texture parameters (TexParameter) or
1243 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1245 * RESOLVED: No. [...] Note that the spec edits above don't add
1246 * explicit error language for any of these cases. That is because
1247 * each of the functions enumerate the set of valid <target>
1248 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1249 * these cases means that target is not legal, and an INVALID_ENUM
1250 * error should be generated."
1252 * From the OpenGL 3.1 spec:
1253 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1255 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1256 case GL_TEXTURE_2D_MULTISAMPLE
:
1257 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1258 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1259 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1260 return ctx
->Extensions
.ARB_texture_multisample
;
1262 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1263 * (30.10.2014) Section 8.11 Texture Queries says:
1264 * "For GetTextureLevelParameter* only, texture may also be a cube
1265 * map texture object. In this case the query is always performed
1266 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1267 * is no way to specify another face."
1269 case GL_TEXTURE_CUBE_MAP
:
1278 get_tex_level_parameter_image(struct gl_context
*ctx
,
1279 const struct gl_texture_object
*texObj
,
1280 GLenum target
, GLint level
,
1281 GLenum pname
, GLint
*params
,
1284 const struct gl_texture_image
*img
= NULL
;
1285 struct gl_texture_image dummy_image
;
1286 mesa_format texFormat
;
1287 const char *suffix
= dsa
? "ture" : "";
1289 img
= _mesa_select_tex_image(texObj
, target
, level
);
1290 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1291 /* In case of undefined texture image return the default values.
1293 * From OpenGL 4.0 spec, page 398:
1294 * "The initial internal format of a texel array is RGBA
1295 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1296 * use TEXTURE_INTERNAL_FORMAT."
1298 memset(&dummy_image
, 0, sizeof(dummy_image
));
1299 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1300 dummy_image
.InternalFormat
= GL_RGBA
;
1301 dummy_image
._BaseFormat
= GL_NONE
;
1306 texFormat
= img
->TexFormat
;
1309 case GL_TEXTURE_WIDTH
:
1310 *params
= img
->Width
;
1312 case GL_TEXTURE_HEIGHT
:
1313 *params
= img
->Height
;
1315 case GL_TEXTURE_DEPTH
:
1316 *params
= img
->Depth
;
1318 case GL_TEXTURE_INTERNAL_FORMAT
:
1319 if (_mesa_is_format_compressed(texFormat
)) {
1320 /* need to return the actual compressed format */
1321 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1324 /* If the true internal format is not compressed but the user
1325 * requested a generic compressed format, we have to return the
1326 * generic base format that matches.
1328 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1330 * "If no specific compressed format is available,
1331 * internalformat is instead replaced by the corresponding base
1334 * Otherwise just return the user's requested internal format
1337 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1339 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1342 case GL_TEXTURE_BORDER
:
1343 if (ctx
->API
!= API_OPENGL_COMPAT
)
1345 *params
= img
->Border
;
1347 case GL_TEXTURE_RED_SIZE
:
1348 case GL_TEXTURE_GREEN_SIZE
:
1349 case GL_TEXTURE_BLUE_SIZE
:
1350 case GL_TEXTURE_ALPHA_SIZE
:
1351 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1352 *params
= _mesa_get_format_bits(texFormat
, pname
);
1356 case GL_TEXTURE_INTENSITY_SIZE
:
1357 case GL_TEXTURE_LUMINANCE_SIZE
:
1358 if (ctx
->API
!= API_OPENGL_COMPAT
)
1360 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1361 *params
= _mesa_get_format_bits(texFormat
, pname
);
1363 /* intensity or luminance is probably stored as RGB[A] */
1364 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1365 GL_TEXTURE_RED_SIZE
),
1366 _mesa_get_format_bits(texFormat
,
1367 GL_TEXTURE_GREEN_SIZE
));
1374 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1375 if (!ctx
->Extensions
.ARB_depth_texture
)
1377 *params
= _mesa_get_format_bits(texFormat
, pname
);
1379 case GL_TEXTURE_STENCIL_SIZE
:
1380 *params
= _mesa_get_format_bits(texFormat
, pname
);
1382 case GL_TEXTURE_SHARED_SIZE
:
1383 if (ctx
->Version
< 30 &&
1384 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1386 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1389 /* GL_ARB_texture_compression */
1390 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1391 if (_mesa_is_format_compressed(texFormat
) &&
1392 !_mesa_is_proxy_texture(target
)) {
1393 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1394 img
->Height
, img
->Depth
);
1397 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1398 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1399 _mesa_lookup_enum_by_nr(pname
));
1402 case GL_TEXTURE_COMPRESSED
:
1403 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1406 /* GL_ARB_texture_float */
1407 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1408 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1409 if (ctx
->API
!= API_OPENGL_COMPAT
)
1412 case GL_TEXTURE_RED_TYPE_ARB
:
1413 case GL_TEXTURE_GREEN_TYPE_ARB
:
1414 case GL_TEXTURE_BLUE_TYPE_ARB
:
1415 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1416 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1417 if (!ctx
->Extensions
.ARB_texture_float
)
1419 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1420 *params
= _mesa_get_format_datatype(texFormat
);
1425 /* GL_ARB_texture_multisample */
1426 case GL_TEXTURE_SAMPLES
:
1427 if (!ctx
->Extensions
.ARB_texture_multisample
)
1429 *params
= img
->NumSamples
;
1432 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1433 if (!ctx
->Extensions
.ARB_texture_multisample
)
1435 *params
= img
->FixedSampleLocations
;
1442 /* no error if we get here */
1446 _mesa_error(ctx
, GL_INVALID_ENUM
,
1447 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1448 _mesa_lookup_enum_by_nr(pname
));
1453 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1454 const struct gl_texture_object
*texObj
,
1455 GLenum pname
, GLint
*params
, bool dsa
)
1457 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1458 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1459 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1460 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1461 const char *suffix
= dsa
? "ture" : "";
1464 /* undefined texture buffer object */
1465 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1470 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1473 case GL_TEXTURE_WIDTH
:
1476 case GL_TEXTURE_HEIGHT
:
1477 case GL_TEXTURE_DEPTH
:
1478 case GL_TEXTURE_BORDER
:
1479 case GL_TEXTURE_SHARED_SIZE
:
1480 case GL_TEXTURE_COMPRESSED
:
1483 case GL_TEXTURE_INTERNAL_FORMAT
:
1484 *params
= internalFormat
;
1486 case GL_TEXTURE_RED_SIZE
:
1487 case GL_TEXTURE_GREEN_SIZE
:
1488 case GL_TEXTURE_BLUE_SIZE
:
1489 case GL_TEXTURE_ALPHA_SIZE
:
1490 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1491 *params
= _mesa_get_format_bits(texFormat
, pname
);
1495 case GL_TEXTURE_INTENSITY_SIZE
:
1496 case GL_TEXTURE_LUMINANCE_SIZE
:
1497 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1498 *params
= _mesa_get_format_bits(texFormat
, pname
);
1500 /* intensity or luminance is probably stored as RGB[A] */
1501 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1502 GL_TEXTURE_RED_SIZE
),
1503 _mesa_get_format_bits(texFormat
,
1504 GL_TEXTURE_GREEN_SIZE
));
1510 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1511 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1512 *params
= _mesa_get_format_bits(texFormat
, pname
);
1515 /* GL_ARB_texture_buffer_range */
1516 case GL_TEXTURE_BUFFER_OFFSET
:
1517 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1519 *params
= texObj
->BufferOffset
;
1521 case GL_TEXTURE_BUFFER_SIZE
:
1522 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1524 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1527 /* GL_ARB_texture_compression */
1528 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1529 /* Always illegal for GL_TEXTURE_BUFFER */
1530 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1531 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1532 _mesa_lookup_enum_by_nr(pname
));
1535 /* GL_ARB_texture_float */
1536 case GL_TEXTURE_RED_TYPE_ARB
:
1537 case GL_TEXTURE_GREEN_TYPE_ARB
:
1538 case GL_TEXTURE_BLUE_TYPE_ARB
:
1539 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1540 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1541 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1542 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1543 if (!ctx
->Extensions
.ARB_texture_float
)
1545 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1546 *params
= _mesa_get_format_datatype(texFormat
);
1555 /* no error if we get here */
1559 _mesa_error(ctx
, GL_INVALID_ENUM
,
1560 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1561 _mesa_lookup_enum_by_nr(pname
));
1566 * This isn't exposed to the rest of the driver because it is a part of the
1567 * OpenGL API that is rarely used.
1570 get_tex_level_parameteriv(struct gl_context
*ctx
,
1571 struct gl_texture_object
*texObj
,
1572 GLenum target
, GLint level
,
1573 GLenum pname
, GLint
*params
,
1577 const char *suffix
= dsa
? "ture" : "";
1579 /* Check for errors */
1580 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1581 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1582 "glGetTex%sLevelParameter[if]v("
1583 "current unit >= max combined texture units)", suffix
);
1587 if (!legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1588 _mesa_error(ctx
, GL_INVALID_ENUM
,
1589 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1590 _mesa_lookup_enum_by_nr(target
));
1594 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1595 assert(maxLevels
!= 0);
1597 if (level
< 0 || level
>= maxLevels
) {
1598 _mesa_error(ctx
, GL_INVALID_VALUE
,
1599 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1603 /* Get the level parameter */
1604 if (target
== GL_TEXTURE_BUFFER
) {
1605 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1608 get_tex_level_parameter_image(ctx
, texObj
, target
,
1609 level
, pname
, params
, dsa
);
1614 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1615 GLenum pname
, GLfloat
*params
)
1617 struct gl_texture_object
*texObj
;
1619 GET_CURRENT_CONTEXT(ctx
);
1621 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1625 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1626 pname
, &iparam
, false);
1628 *params
= (GLfloat
) iparam
;
1632 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1633 GLenum pname
, GLint
*params
)
1635 struct gl_texture_object
*texObj
;
1636 GET_CURRENT_CONTEXT(ctx
);
1638 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1642 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1643 pname
, params
, false);
1647 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1648 GLenum pname
, GLfloat
*params
)
1650 struct gl_texture_object
*texObj
;
1652 GET_CURRENT_CONTEXT(ctx
);
1654 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1655 "glGetTextureLevelParameterfv");
1659 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1660 pname
, &iparam
, true);
1662 *params
= (GLfloat
) iparam
;
1666 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1667 GLenum pname
, GLint
*params
)
1669 struct gl_texture_object
*texObj
;
1670 GET_CURRENT_CONTEXT(ctx
);
1672 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1673 "glGetTextureLevelParameteriv");
1677 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1678 pname
, params
, true);
1682 * This isn't exposed to the rest of the driver because it is a part of the
1683 * OpenGL API that is rarely used.
1686 get_tex_parameterfv(struct gl_context
*ctx
,
1687 struct gl_texture_object
*obj
,
1688 GLenum pname
, GLfloat
*params
, bool dsa
)
1690 _mesa_lock_context_textures(ctx
);
1692 case GL_TEXTURE_MAG_FILTER
:
1693 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1695 case GL_TEXTURE_MIN_FILTER
:
1696 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1698 case GL_TEXTURE_WRAP_S
:
1699 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1701 case GL_TEXTURE_WRAP_T
:
1702 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1704 case GL_TEXTURE_WRAP_R
:
1705 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1707 case GL_TEXTURE_BORDER_COLOR
:
1708 if (!_mesa_is_desktop_gl(ctx
))
1711 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1712 _mesa_update_state_locked(ctx
);
1713 if (_mesa_get_clamp_fragment_color(ctx
)) {
1714 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1715 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1716 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1717 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1720 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1721 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1722 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1723 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1726 case GL_TEXTURE_RESIDENT
:
1727 if (ctx
->API
!= API_OPENGL_COMPAT
)
1732 case GL_TEXTURE_PRIORITY
:
1733 if (ctx
->API
!= API_OPENGL_COMPAT
)
1736 *params
= obj
->Priority
;
1738 case GL_TEXTURE_MIN_LOD
:
1739 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1742 *params
= obj
->Sampler
.MinLod
;
1744 case GL_TEXTURE_MAX_LOD
:
1745 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1748 *params
= obj
->Sampler
.MaxLod
;
1750 case GL_TEXTURE_BASE_LEVEL
:
1751 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1754 *params
= (GLfloat
) obj
->BaseLevel
;
1756 case GL_TEXTURE_MAX_LEVEL
:
1757 *params
= (GLfloat
) obj
->MaxLevel
;
1759 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1760 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1762 *params
= obj
->Sampler
.MaxAnisotropy
;
1764 case GL_GENERATE_MIPMAP_SGIS
:
1765 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1768 *params
= (GLfloat
) obj
->GenerateMipmap
;
1770 case GL_TEXTURE_COMPARE_MODE_ARB
:
1771 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1772 && !_mesa_is_gles3(ctx
))
1774 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1776 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1777 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1778 && !_mesa_is_gles3(ctx
))
1780 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1782 case GL_DEPTH_TEXTURE_MODE_ARB
:
1783 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1784 * never existed in OpenGL ES.
1786 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1788 *params
= (GLfloat
) obj
->DepthMode
;
1790 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1791 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
1794 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1796 case GL_TEXTURE_LOD_BIAS
:
1797 if (_mesa_is_gles(ctx
))
1800 *params
= obj
->Sampler
.LodBias
;
1802 case GL_TEXTURE_CROP_RECT_OES
:
1803 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1806 params
[0] = (GLfloat
) obj
->CropRect
[0];
1807 params
[1] = (GLfloat
) obj
->CropRect
[1];
1808 params
[2] = (GLfloat
) obj
->CropRect
[2];
1809 params
[3] = (GLfloat
) obj
->CropRect
[3];
1812 case GL_TEXTURE_SWIZZLE_R_EXT
:
1813 case GL_TEXTURE_SWIZZLE_G_EXT
:
1814 case GL_TEXTURE_SWIZZLE_B_EXT
:
1815 case GL_TEXTURE_SWIZZLE_A_EXT
:
1816 if ((!_mesa_is_desktop_gl(ctx
)
1817 || !ctx
->Extensions
.EXT_texture_swizzle
)
1818 && !_mesa_is_gles3(ctx
))
1820 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1823 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1824 if ((!_mesa_is_desktop_gl(ctx
)
1825 || !ctx
->Extensions
.EXT_texture_swizzle
)
1826 && !_mesa_is_gles3(ctx
)) {
1831 for (comp
= 0; comp
< 4; comp
++) {
1832 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1837 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1838 if (!_mesa_is_desktop_gl(ctx
)
1839 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1841 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1844 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1845 *params
= (GLfloat
) obj
->Immutable
;
1848 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1849 if (_mesa_is_gles3(ctx
) ||
1850 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1851 *params
= (GLfloat
) obj
->ImmutableLevels
;
1856 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1857 if (!ctx
->Extensions
.ARB_texture_view
)
1859 *params
= (GLfloat
) obj
->MinLevel
;
1862 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1863 if (!ctx
->Extensions
.ARB_texture_view
)
1865 *params
= (GLfloat
) obj
->NumLevels
;
1868 case GL_TEXTURE_VIEW_MIN_LAYER
:
1869 if (!ctx
->Extensions
.ARB_texture_view
)
1871 *params
= (GLfloat
) obj
->MinLayer
;
1874 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1875 if (!ctx
->Extensions
.ARB_texture_view
)
1877 *params
= (GLfloat
) obj
->NumLayers
;
1880 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1881 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1883 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1886 case GL_TEXTURE_SRGB_DECODE_EXT
:
1887 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1889 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1896 /* no error if we get here */
1897 _mesa_unlock_context_textures(ctx
);
1901 _mesa_unlock_context_textures(ctx
);
1902 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
1903 dsa
? "ture" : "", pname
);
1908 get_tex_parameteriv(struct gl_context
*ctx
,
1909 struct gl_texture_object
*obj
,
1910 GLenum pname
, GLint
*params
, bool dsa
)
1912 _mesa_lock_texture(ctx
, obj
);
1914 case GL_TEXTURE_MAG_FILTER
:
1915 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1917 case GL_TEXTURE_MIN_FILTER
:
1918 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1920 case GL_TEXTURE_WRAP_S
:
1921 *params
= (GLint
) obj
->Sampler
.WrapS
;
1923 case GL_TEXTURE_WRAP_T
:
1924 *params
= (GLint
) obj
->Sampler
.WrapT
;
1926 case GL_TEXTURE_WRAP_R
:
1927 *params
= (GLint
) obj
->Sampler
.WrapR
;
1929 case GL_TEXTURE_BORDER_COLOR
:
1930 if (!_mesa_is_desktop_gl(ctx
))
1935 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1936 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1937 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1938 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1939 params
[0] = FLOAT_TO_INT(b
[0]);
1940 params
[1] = FLOAT_TO_INT(b
[1]);
1941 params
[2] = FLOAT_TO_INT(b
[2]);
1942 params
[3] = FLOAT_TO_INT(b
[3]);
1945 case GL_TEXTURE_RESIDENT
:
1946 if (ctx
->API
!= API_OPENGL_COMPAT
)
1951 case GL_TEXTURE_PRIORITY
:
1952 if (ctx
->API
!= API_OPENGL_COMPAT
)
1955 *params
= FLOAT_TO_INT(obj
->Priority
);
1957 case GL_TEXTURE_MIN_LOD
:
1958 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1960 /* GL spec 'Data Conversions' section specifies that floating-point
1961 * value in integer Get function is rounded to nearest integer
1963 *params
= IROUND(obj
->Sampler
.MinLod
);
1965 case GL_TEXTURE_MAX_LOD
:
1966 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1968 /* GL spec 'Data Conversions' section specifies that floating-point
1969 * value in integer Get function is rounded to nearest integer
1971 *params
= IROUND(obj
->Sampler
.MaxLod
);
1973 case GL_TEXTURE_BASE_LEVEL
:
1974 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1977 *params
= obj
->BaseLevel
;
1979 case GL_TEXTURE_MAX_LEVEL
:
1980 *params
= obj
->MaxLevel
;
1982 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1983 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1985 /* GL spec 'Data Conversions' section specifies that floating-point
1986 * value in integer Get function is rounded to nearest integer
1988 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
1990 case GL_GENERATE_MIPMAP_SGIS
:
1991 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1994 *params
= (GLint
) obj
->GenerateMipmap
;
1996 case GL_TEXTURE_COMPARE_MODE_ARB
:
1997 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1998 && !_mesa_is_gles3(ctx
))
2000 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2002 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2003 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2004 && !_mesa_is_gles3(ctx
))
2006 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2008 case GL_DEPTH_TEXTURE_MODE_ARB
:
2009 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2011 *params
= (GLint
) obj
->DepthMode
;
2013 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2014 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
2017 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2019 case GL_TEXTURE_LOD_BIAS
:
2020 if (_mesa_is_gles(ctx
))
2023 /* GL spec 'Data Conversions' section specifies that floating-point
2024 * value in integer Get function is rounded to nearest integer
2026 *params
= IROUND(obj
->Sampler
.LodBias
);
2028 case GL_TEXTURE_CROP_RECT_OES
:
2029 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2032 params
[0] = obj
->CropRect
[0];
2033 params
[1] = obj
->CropRect
[1];
2034 params
[2] = obj
->CropRect
[2];
2035 params
[3] = obj
->CropRect
[3];
2037 case GL_TEXTURE_SWIZZLE_R_EXT
:
2038 case GL_TEXTURE_SWIZZLE_G_EXT
:
2039 case GL_TEXTURE_SWIZZLE_B_EXT
:
2040 case GL_TEXTURE_SWIZZLE_A_EXT
:
2041 if ((!_mesa_is_desktop_gl(ctx
)
2042 || !ctx
->Extensions
.EXT_texture_swizzle
)
2043 && !_mesa_is_gles3(ctx
))
2045 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2048 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2049 if ((!_mesa_is_desktop_gl(ctx
)
2050 || !ctx
->Extensions
.EXT_texture_swizzle
)
2051 && !_mesa_is_gles3(ctx
))
2053 COPY_4V(params
, obj
->Swizzle
);
2056 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2057 if (!_mesa_is_desktop_gl(ctx
)
2058 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2060 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2063 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2064 *params
= (GLint
) obj
->Immutable
;
2067 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2068 if (_mesa_is_gles3(ctx
) ||
2069 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2070 *params
= obj
->ImmutableLevels
;
2075 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2076 if (!ctx
->Extensions
.ARB_texture_view
)
2078 *params
= (GLint
) obj
->MinLevel
;
2081 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2082 if (!ctx
->Extensions
.ARB_texture_view
)
2084 *params
= (GLint
) obj
->NumLevels
;
2087 case GL_TEXTURE_VIEW_MIN_LAYER
:
2088 if (!ctx
->Extensions
.ARB_texture_view
)
2090 *params
= (GLint
) obj
->MinLayer
;
2093 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2094 if (!ctx
->Extensions
.ARB_texture_view
)
2096 *params
= (GLint
) obj
->NumLayers
;
2099 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2100 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2102 *params
= obj
->RequiredTextureImageUnits
;
2105 case GL_TEXTURE_SRGB_DECODE_EXT
:
2106 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2108 *params
= obj
->Sampler
.sRGBDecode
;
2111 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2112 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2114 *params
= obj
->ImageFormatCompatibilityType
;
2121 /* no error if we get here */
2122 _mesa_unlock_texture(ctx
, obj
);
2126 _mesa_unlock_texture(ctx
, obj
);
2127 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2128 dsa
? "ture" : "", pname
);
2132 get_tex_parameterIiv(struct gl_context
*ctx
,
2133 struct gl_texture_object
*obj
,
2134 GLenum pname
, GLint
*params
, bool dsa
)
2137 case GL_TEXTURE_BORDER_COLOR
:
2138 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2141 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2146 get_tex_parameterIuiv(struct gl_context
*ctx
,
2147 struct gl_texture_object
*obj
,
2148 GLenum pname
, GLuint
*params
, bool dsa
)
2151 case GL_TEXTURE_BORDER_COLOR
:
2152 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2157 get_tex_parameteriv(ctx
, obj
, pname
, ip
, dsa
);
2159 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
2160 pname
== GL_TEXTURE_CROP_RECT_OES
) {
2170 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2172 struct gl_texture_object
*obj
;
2173 GET_CURRENT_CONTEXT(ctx
);
2175 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2179 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2183 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2185 struct gl_texture_object
*obj
;
2186 GET_CURRENT_CONTEXT(ctx
);
2188 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2192 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2195 /** New in GL 3.0 */
2197 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
2199 struct gl_texture_object
*texObj
;
2200 GET_CURRENT_CONTEXT(ctx
);
2202 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2206 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, false);
2210 /** New in GL 3.0 */
2212 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2214 struct gl_texture_object
*texObj
;
2215 GET_CURRENT_CONTEXT(ctx
);
2217 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2221 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, false);
2226 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2228 struct gl_texture_object
*obj
;
2229 GET_CURRENT_CONTEXT(ctx
);
2231 obj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2233 /* User passed a non-generated name. */
2234 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2235 "glGetTextureParameterfv(texture)");
2239 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2243 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2245 struct gl_texture_object
*obj
;
2246 GET_CURRENT_CONTEXT(ctx
);
2248 obj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2250 /* User passed a non-generated name. */
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2252 "glGetTextureParameteriv(texture)");
2256 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2260 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2262 struct gl_texture_object
*texObj
;
2263 GET_CURRENT_CONTEXT(ctx
);
2265 texObj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2267 /* User passed a non-generated name. */
2268 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2269 "glGetTextureParameterIiv(texture)");
2273 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2278 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2280 struct gl_texture_object
*texObj
;
2281 GET_CURRENT_CONTEXT(ctx
);
2283 texObj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2285 /* User passed a non-generated name. */
2286 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2287 "glGetTextureParameterIuiv(texture)");
2291 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, true);