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
, const char *name
)
158 struct gl_texture_object
*texObj
;
160 texObj
= _mesa_lookup_texture_err(ctx
, texture
, name
);
164 switch (texObj
->Target
) {
166 case GL_TEXTURE_1D_ARRAY
:
168 case GL_TEXTURE_2D_ARRAY
:
169 case GL_TEXTURE_2D_MULTISAMPLE
:
170 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
172 case GL_TEXTURE_CUBE_MAP
:
173 case GL_TEXTURE_CUBE_MAP_ARRAY
:
174 case GL_TEXTURE_RECTANGLE
:
177 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
185 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
186 * \return -1 if error.
189 comp_to_swizzle(GLenum comp
)
211 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
214 assert(swz
<= SWIZZLE_NIL
);
216 GLuint mask
= 0x7 << (3 * comp
);
217 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
224 * This is called just prior to changing any texture object state which
225 * will not affect texture completeness.
228 flush(struct gl_context
*ctx
)
230 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
235 * This is called just prior to changing any texture object state which
236 * could affect texture completeness (texture base level, max level).
237 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE_OBJECT
238 * state flag and then mark the texture object as 'incomplete' so that any
239 * per-texture derived state gets recomputed.
242 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
244 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
245 _mesa_dirty_texobj(ctx
, texObj
);
250 _mesa_target_allows_setting_sampler_parameters(GLenum target
)
253 case GL_TEXTURE_2D_MULTISAMPLE
:
254 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
264 * Set an integer-valued texture parameter
265 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
268 set_tex_parameteri(struct gl_context
*ctx
,
269 struct gl_texture_object
*texObj
,
270 GLenum pname
, const GLint
*params
, bool dsa
)
272 const char *suffix
= dsa
? "ture" : "";
274 if (texObj
->HandleAllocated
) {
275 /* The ARB_bindless_texture spec says:
277 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
278 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
279 * functions defined in terms of these, if the texture object to be
280 * modified is referenced by one or more texture or image handles."
282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
283 "glTex%sParameter(immutable texture)", suffix
);
288 case GL_TEXTURE_MIN_FILTER
:
289 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
292 if (texObj
->Sampler
.MinFilter
== params
[0])
298 texObj
->Sampler
.MinFilter
= params
[0];
300 case GL_NEAREST_MIPMAP_NEAREST
:
301 case GL_LINEAR_MIPMAP_NEAREST
:
302 case GL_NEAREST_MIPMAP_LINEAR
:
303 case GL_LINEAR_MIPMAP_LINEAR
:
304 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
305 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
307 texObj
->Sampler
.MinFilter
= params
[0];
316 case GL_TEXTURE_MAG_FILTER
:
317 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
320 if (texObj
->Sampler
.MagFilter
== params
[0])
325 flush(ctx
); /* does not effect completeness */
326 texObj
->Sampler
.MagFilter
= params
[0];
333 case GL_TEXTURE_WRAP_S
:
334 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
337 if (texObj
->Sampler
.WrapS
== params
[0])
339 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
341 texObj
->Sampler
.WrapS
= params
[0];
346 case GL_TEXTURE_WRAP_T
:
347 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
350 if (texObj
->Sampler
.WrapT
== params
[0])
352 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
354 texObj
->Sampler
.WrapT
= params
[0];
359 case GL_TEXTURE_WRAP_R
:
360 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
363 if (texObj
->Sampler
.WrapR
== params
[0])
365 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
367 texObj
->Sampler
.WrapR
= params
[0];
372 case GL_TEXTURE_BASE_LEVEL
:
373 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
376 if (texObj
->BaseLevel
== params
[0])
379 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
380 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
381 goto invalid_operation
;
384 _mesa_error(ctx
, GL_INVALID_VALUE
,
385 "glTex%sParameter(param=%d)", suffix
, params
[0]);
388 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0) {
389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
390 "glTex%sParameter(target=%s, param=%d)", suffix
,
391 _mesa_enum_to_string(texObj
->Target
), params
[0]);
394 incomplete(ctx
, texObj
);
396 /** See note about ARB_texture_storage below */
397 if (texObj
->Immutable
)
398 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
400 texObj
->BaseLevel
= params
[0];
404 case GL_TEXTURE_MAX_LEVEL
:
405 if (texObj
->MaxLevel
== params
[0])
409 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
410 _mesa_error(ctx
, GL_INVALID_VALUE
,
411 "glTex%sParameter(param=%d)", suffix
,
415 incomplete(ctx
, texObj
);
417 /** From ARB_texture_storage:
418 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
419 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
420 * the range [level_base, <levels> - 1], where <levels> is the parameter
421 * passed the call to TexStorage* for the texture object.
423 if (texObj
->Immutable
)
424 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
425 texObj
->ImmutableLevels
- 1);
427 texObj
->MaxLevel
= params
[0];
431 case GL_GENERATE_MIPMAP_SGIS
:
432 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
435 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
437 if (texObj
->GenerateMipmap
!= params
[0]) {
439 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
444 case GL_TEXTURE_COMPARE_MODE_ARB
:
445 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
446 || _mesa_is_gles3(ctx
)) {
448 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
451 if (texObj
->Sampler
.CompareMode
== params
[0])
453 if (params
[0] == GL_NONE
||
454 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
456 texObj
->Sampler
.CompareMode
= params
[0];
463 case GL_TEXTURE_COMPARE_FUNC_ARB
:
464 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
465 || _mesa_is_gles3(ctx
)) {
467 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
470 if (texObj
->Sampler
.CompareFunc
== params
[0])
482 texObj
->Sampler
.CompareFunc
= params
[0];
490 case GL_DEPTH_TEXTURE_MODE_ARB
:
491 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
492 * existed in OpenGL ES.
494 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
495 if (texObj
->DepthMode
== params
[0])
497 if (params
[0] == GL_LUMINANCE
||
498 params
[0] == GL_INTENSITY
||
499 params
[0] == GL_ALPHA
||
500 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
502 texObj
->DepthMode
= params
[0];
509 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
510 if (_mesa_has_ARB_stencil_texturing(ctx
) || _mesa_is_gles31(ctx
)) {
511 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
512 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
515 if (texObj
->StencilSampling
== stencil
)
518 texObj
->StencilSampling
= stencil
;
523 case GL_TEXTURE_CROP_RECT_OES
:
524 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
527 texObj
->CropRect
[0] = params
[0];
528 texObj
->CropRect
[1] = params
[1];
529 texObj
->CropRect
[2] = params
[2];
530 texObj
->CropRect
[3] = params
[3];
533 case GL_TEXTURE_SWIZZLE_R_EXT
:
534 case GL_TEXTURE_SWIZZLE_G_EXT
:
535 case GL_TEXTURE_SWIZZLE_B_EXT
:
536 case GL_TEXTURE_SWIZZLE_A_EXT
:
537 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
538 || _mesa_is_gles3(ctx
)) {
539 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
540 const GLint swz
= comp_to_swizzle(params
[0]);
542 _mesa_error(ctx
, GL_INVALID_ENUM
,
543 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
549 texObj
->Swizzle
[comp
] = params
[0];
550 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
555 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
556 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
557 || _mesa_is_gles3(ctx
)) {
560 for (comp
= 0; comp
< 4; comp
++) {
561 const GLint swz
= comp_to_swizzle(params
[comp
]);
563 texObj
->Swizzle
[comp
] = params
[comp
];
564 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
567 _mesa_error(ctx
, GL_INVALID_ENUM
,
568 "glTex%sParameter(swizzle 0x%x)",
569 suffix
, params
[comp
]);
577 case GL_TEXTURE_SRGB_DECODE_EXT
:
578 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
579 GLenum decode
= params
[0];
581 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
584 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
585 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
587 texObj
->Sampler
.sRGBDecode
= decode
;
594 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
595 if (_mesa_is_desktop_gl(ctx
)
596 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
597 GLenum param
= params
[0];
599 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
602 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
605 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
607 texObj
->Sampler
.CubeMapSeamless
= param
;
618 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
619 suffix
, _mesa_enum_to_string(pname
));
623 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
624 suffix
, _mesa_enum_to_string(params
[0]));
628 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
629 suffix
, _mesa_enum_to_string(pname
));
633 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
634 suffix
, _mesa_enum_to_string(pname
));
640 * Set a float-valued texture parameter
641 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
644 set_tex_parameterf(struct gl_context
*ctx
,
645 struct gl_texture_object
*texObj
,
646 GLenum pname
, const GLfloat
*params
, bool dsa
)
648 const char *suffix
= dsa
? "ture" : "";
650 if (texObj
->HandleAllocated
) {
651 /* The ARB_bindless_texture spec says:
653 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
654 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
655 * functions defined in terms of these, if the texture object to be
656 * modified is referenced by one or more texture or image handles."
658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
659 "glTex%sParameter(immutable texture)", suffix
);
664 case GL_TEXTURE_MIN_LOD
:
665 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
668 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
671 if (texObj
->Sampler
.MinLod
== params
[0])
674 texObj
->Sampler
.MinLod
= params
[0];
677 case GL_TEXTURE_MAX_LOD
:
678 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
681 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
684 if (texObj
->Sampler
.MaxLod
== params
[0])
687 texObj
->Sampler
.MaxLod
= params
[0];
690 case GL_TEXTURE_PRIORITY
:
691 if (ctx
->API
!= API_OPENGL_COMPAT
)
695 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
698 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
699 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
700 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
703 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
705 if (params
[0] < 1.0F
) {
706 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
711 /* clamp to max, that's what NVIDIA does */
712 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
713 ctx
->Const
.MaxTextureMaxAnisotropy
);
717 static GLuint count
= 0;
723 case GL_TEXTURE_LOD_BIAS
:
724 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
725 if (_mesa_is_gles(ctx
))
728 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
731 if (texObj
->Sampler
.LodBias
!= params
[0]) {
733 texObj
->Sampler
.LodBias
= params
[0];
738 case GL_TEXTURE_BORDER_COLOR
:
739 /* Border color exists in desktop OpenGL since 1.0 for GL_CLAMP. In
740 * OpenGL ES 2.0+, it only exists in when GL_OES_texture_border_clamp is
741 * enabled. It is never available in OpenGL ES 1.x.
743 * FIXME: Every driver that supports GLES2 has this extension. Elide
746 if (ctx
->API
== API_OPENGLES
||
747 (ctx
->API
== API_OPENGLES2
&&
748 !ctx
->Extensions
.ARB_texture_border_clamp
))
751 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
755 /* ARB_texture_float disables clamping */
756 if (ctx
->Extensions
.ARB_texture_float
) {
757 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
758 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
759 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
760 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
762 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
763 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
764 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
765 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
775 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
776 suffix
, _mesa_enum_to_string(pname
));
780 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
781 suffix
, _mesa_enum_to_string(pname
));
787 _mesa_texture_parameterf(struct gl_context
*ctx
,
788 struct gl_texture_object
*texObj
,
789 GLenum pname
, GLfloat param
, bool dsa
)
791 GLboolean need_update
;
794 case GL_TEXTURE_MIN_FILTER
:
795 case GL_TEXTURE_MAG_FILTER
:
796 case GL_TEXTURE_WRAP_S
:
797 case GL_TEXTURE_WRAP_T
:
798 case GL_TEXTURE_WRAP_R
:
799 case GL_TEXTURE_BASE_LEVEL
:
800 case GL_TEXTURE_MAX_LEVEL
:
801 case GL_GENERATE_MIPMAP_SGIS
:
802 case GL_TEXTURE_COMPARE_MODE_ARB
:
803 case GL_TEXTURE_COMPARE_FUNC_ARB
:
804 case GL_DEPTH_TEXTURE_MODE_ARB
:
805 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
806 case GL_TEXTURE_SRGB_DECODE_EXT
:
807 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
808 case GL_TEXTURE_SWIZZLE_R_EXT
:
809 case GL_TEXTURE_SWIZZLE_G_EXT
:
810 case GL_TEXTURE_SWIZZLE_B_EXT
:
811 case GL_TEXTURE_SWIZZLE_A_EXT
:
815 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
816 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
818 p
[1] = p
[2] = p
[3] = 0;
819 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
822 case GL_TEXTURE_BORDER_COLOR
:
823 case GL_TEXTURE_SWIZZLE_RGBA
:
824 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
829 /* this will generate an error if pname is illegal */
832 p
[1] = p
[2] = p
[3] = 0.0F
;
833 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
837 if (ctx
->Driver
.TexParameter
&& need_update
) {
838 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
844 _mesa_texture_parameterfv(struct gl_context
*ctx
,
845 struct gl_texture_object
*texObj
,
846 GLenum pname
, const GLfloat
*params
, bool dsa
)
848 GLboolean need_update
;
850 case GL_TEXTURE_MIN_FILTER
:
851 case GL_TEXTURE_MAG_FILTER
:
852 case GL_TEXTURE_WRAP_S
:
853 case GL_TEXTURE_WRAP_T
:
854 case GL_TEXTURE_WRAP_R
:
855 case GL_TEXTURE_BASE_LEVEL
:
856 case GL_TEXTURE_MAX_LEVEL
:
857 case GL_GENERATE_MIPMAP_SGIS
:
858 case GL_TEXTURE_COMPARE_MODE_ARB
:
859 case GL_TEXTURE_COMPARE_FUNC_ARB
:
860 case GL_DEPTH_TEXTURE_MODE_ARB
:
861 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
862 case GL_TEXTURE_SRGB_DECODE_EXT
:
863 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
865 /* convert float param to int */
867 p
[0] = (GLint
) params
[0];
868 p
[1] = p
[2] = p
[3] = 0;
869 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
872 case GL_TEXTURE_CROP_RECT_OES
:
874 /* convert float params to int */
876 iparams
[0] = (GLint
) params
[0];
877 iparams
[1] = (GLint
) params
[1];
878 iparams
[2] = (GLint
) params
[2];
879 iparams
[3] = (GLint
) params
[3];
880 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
883 case GL_TEXTURE_SWIZZLE_R_EXT
:
884 case GL_TEXTURE_SWIZZLE_G_EXT
:
885 case GL_TEXTURE_SWIZZLE_B_EXT
:
886 case GL_TEXTURE_SWIZZLE_A_EXT
:
887 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
889 GLint p
[4] = {0, 0, 0, 0};
890 p
[0] = (GLint
) params
[0];
891 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
892 p
[1] = (GLint
) params
[1];
893 p
[2] = (GLint
) params
[2];
894 p
[3] = (GLint
) params
[3];
896 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
900 /* this will generate an error if pname is illegal */
901 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
904 if (ctx
->Driver
.TexParameter
&& need_update
) {
905 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
911 _mesa_texture_parameteri(struct gl_context
*ctx
,
912 struct gl_texture_object
*texObj
,
913 GLenum pname
, GLint param
, bool dsa
)
915 GLboolean need_update
;
917 case GL_TEXTURE_MIN_LOD
:
918 case GL_TEXTURE_MAX_LOD
:
919 case GL_TEXTURE_PRIORITY
:
920 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
921 case GL_TEXTURE_LOD_BIAS
:
922 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
925 fparam
[0] = (GLfloat
) param
;
926 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
927 /* convert int param to float */
928 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
931 case GL_TEXTURE_BORDER_COLOR
:
932 case GL_TEXTURE_SWIZZLE_RGBA
:
934 _mesa_error(ctx
, GL_INVALID_ENUM
,
935 "glTex%sParameteri(non-scalar pname)",
940 /* this will generate an error if pname is illegal */
944 iparam
[1] = iparam
[2] = iparam
[3] = 0;
945 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
949 if (ctx
->Driver
.TexParameter
&& need_update
) {
950 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
956 _mesa_texture_parameteriv(struct gl_context
*ctx
,
957 struct gl_texture_object
*texObj
,
958 GLenum pname
, const GLint
*params
, bool dsa
)
960 GLboolean need_update
;
963 case GL_TEXTURE_BORDER_COLOR
:
965 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
966 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameteriv(texture)");
969 /* convert int params to float */
971 fparams
[0] = INT_TO_FLOAT(params
[0]);
972 fparams
[1] = INT_TO_FLOAT(params
[1]);
973 fparams
[2] = INT_TO_FLOAT(params
[2]);
974 fparams
[3] = INT_TO_FLOAT(params
[3]);
975 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
978 case GL_TEXTURE_MIN_LOD
:
979 case GL_TEXTURE_MAX_LOD
:
980 case GL_TEXTURE_PRIORITY
:
981 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
982 case GL_TEXTURE_LOD_BIAS
:
983 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
985 /* convert int param to float */
987 fparams
[0] = (GLfloat
) params
[0];
988 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
989 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
993 /* this will generate an error if pname is illegal */
994 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
997 if (ctx
->Driver
.TexParameter
&& need_update
) {
998 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
1003 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
1004 struct gl_texture_object
*texObj
,
1005 GLenum pname
, const GLint
*params
, bool dsa
)
1008 case GL_TEXTURE_BORDER_COLOR
:
1009 if (texObj
->HandleAllocated
) {
1010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1011 "glTextureParameterIiv(immutable texture)");
1015 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1016 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIiv(texture)");
1019 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1020 /* set the integer-valued border color */
1021 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
1024 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
1027 /* XXX no driver hook for TexParameterIiv() yet */
1031 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
1032 struct gl_texture_object
*texObj
,
1033 GLenum pname
, const GLuint
*params
, bool dsa
)
1036 case GL_TEXTURE_BORDER_COLOR
:
1037 if (texObj
->HandleAllocated
) {
1038 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1039 "glTextureParameterIuiv(immutable texture)");
1043 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1044 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIuiv(texture)");
1047 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1048 /* set the unsigned integer-valued border color */
1049 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1052 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1056 /* XXX no driver hook for TexParameterIuiv() yet */
1060 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1062 struct gl_texture_object
*texObj
;
1063 GET_CURRENT_CONTEXT(ctx
);
1065 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1069 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1073 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1075 struct gl_texture_object
*texObj
;
1076 GET_CURRENT_CONTEXT(ctx
);
1078 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1082 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1086 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1088 struct gl_texture_object
*texObj
;
1089 GET_CURRENT_CONTEXT(ctx
);
1091 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1095 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1099 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1101 struct gl_texture_object
*texObj
;
1102 GET_CURRENT_CONTEXT(ctx
);
1104 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1108 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1112 * Set tex parameter to integer value(s). Primarily intended to set
1113 * integer-valued texture border color (for integer-valued textures).
1117 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1119 struct gl_texture_object
*texObj
;
1120 GET_CURRENT_CONTEXT(ctx
);
1122 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1126 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1130 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1131 * uint-valued texture border color (for integer-valued textures).
1135 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1137 struct gl_texture_object
*texObj
;
1138 GET_CURRENT_CONTEXT(ctx
);
1140 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1144 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1149 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1151 struct gl_texture_object
*texObj
;
1152 GET_CURRENT_CONTEXT(ctx
);
1154 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterfv");
1158 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1162 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1164 struct gl_texture_object
*texObj
;
1165 GET_CURRENT_CONTEXT(ctx
);
1167 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterf");
1171 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1175 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1177 struct gl_texture_object
*texObj
;
1178 GET_CURRENT_CONTEXT(ctx
);
1180 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteri");
1184 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1188 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1189 const GLint
*params
)
1191 struct gl_texture_object
*texObj
;
1192 GET_CURRENT_CONTEXT(ctx
);
1194 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteriv");
1198 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1203 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1205 struct gl_texture_object
*texObj
;
1206 GET_CURRENT_CONTEXT(ctx
);
1208 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIiv");
1212 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1216 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1218 struct gl_texture_object
*texObj
;
1219 GET_CURRENT_CONTEXT(ctx
);
1221 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIuiv");
1225 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1229 _mesa_legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1232 /* Common targets for desktop GL and GLES 3.1. */
1237 case GL_TEXTURE_2D_ARRAY_EXT
:
1238 return ctx
->Extensions
.EXT_texture_array
;
1239 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1240 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1241 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1242 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1243 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1244 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1245 return ctx
->Extensions
.ARB_texture_cube_map
;
1246 case GL_TEXTURE_2D_MULTISAMPLE
:
1247 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1248 return ctx
->Extensions
.ARB_texture_multisample
;
1249 case GL_TEXTURE_BUFFER
:
1250 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1251 * but not in earlier versions that expose ARB_texture_buffer_object.
1253 * From the ARB_texture_buffer_object spec:
1254 * "(7) Do buffer textures support texture parameters (TexParameter) or
1255 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1257 * RESOLVED: No. [...] Note that the spec edits above don't add
1258 * explicit error language for any of these cases. That is because
1259 * each of the functions enumerate the set of valid <target>
1260 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1261 * these cases means that target is not legal, and an INVALID_ENUM
1262 * error should be generated."
1264 * From the OpenGL 3.1 spec:
1265 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1267 return (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31) ||
1268 _mesa_has_OES_texture_buffer(ctx
);
1269 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1270 return _mesa_has_texture_cube_map_array(ctx
);
1273 if (!_mesa_is_desktop_gl(ctx
))
1276 /* Rest of the desktop GL targets. */
1279 case GL_PROXY_TEXTURE_1D
:
1280 case GL_PROXY_TEXTURE_2D
:
1281 case GL_PROXY_TEXTURE_3D
:
1283 case GL_PROXY_TEXTURE_CUBE_MAP
:
1284 return ctx
->Extensions
.ARB_texture_cube_map
;
1285 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1286 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1287 case GL_TEXTURE_RECTANGLE_NV
:
1288 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1289 return ctx
->Extensions
.NV_texture_rectangle
;
1290 case GL_TEXTURE_1D_ARRAY_EXT
:
1291 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1292 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1293 return ctx
->Extensions
.EXT_texture_array
;
1294 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1295 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1296 return ctx
->Extensions
.ARB_texture_multisample
;
1298 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1299 * (30.10.2014) Section 8.11 Texture Queries says:
1300 * "For GetTextureLevelParameter* only, texture may also be a cube
1301 * map texture object. In this case the query is always performed
1302 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1303 * is no way to specify another face."
1305 case GL_TEXTURE_CUBE_MAP
:
1314 get_tex_level_parameter_image(struct gl_context
*ctx
,
1315 const struct gl_texture_object
*texObj
,
1316 GLenum target
, GLint level
,
1317 GLenum pname
, GLint
*params
,
1320 const struct gl_texture_image
*img
= NULL
;
1321 struct gl_texture_image dummy_image
;
1322 mesa_format texFormat
;
1323 const char *suffix
= dsa
? "ture" : "";
1325 img
= _mesa_select_tex_image(texObj
, target
, level
);
1326 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1327 /* In case of undefined texture image return the default values.
1329 * From OpenGL 4.0 spec, page 398:
1330 * "The initial internal format of a texel array is RGBA
1331 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1332 * use TEXTURE_INTERNAL_FORMAT."
1334 memset(&dummy_image
, 0, sizeof(dummy_image
));
1335 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1336 dummy_image
.InternalFormat
= GL_RGBA
;
1337 dummy_image
._BaseFormat
= GL_NONE
;
1338 dummy_image
.FixedSampleLocations
= GL_TRUE
;
1343 texFormat
= img
->TexFormat
;
1346 case GL_TEXTURE_WIDTH
:
1347 *params
= img
->Width
;
1349 case GL_TEXTURE_HEIGHT
:
1350 *params
= img
->Height
;
1352 case GL_TEXTURE_DEPTH
:
1353 *params
= img
->Depth
;
1355 case GL_TEXTURE_INTERNAL_FORMAT
:
1356 if (_mesa_is_format_compressed(texFormat
)) {
1357 /* need to return the actual compressed format */
1358 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1361 /* If the true internal format is not compressed but the user
1362 * requested a generic compressed format, we have to return the
1363 * generic base format that matches.
1365 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1367 * "If no specific compressed format is available,
1368 * internalformat is instead replaced by the corresponding base
1371 * Otherwise just return the user's requested internal format
1374 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1376 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1379 case GL_TEXTURE_BORDER
:
1380 if (ctx
->API
!= API_OPENGL_COMPAT
)
1382 *params
= img
->Border
;
1384 case GL_TEXTURE_RED_SIZE
:
1385 case GL_TEXTURE_GREEN_SIZE
:
1386 case GL_TEXTURE_BLUE_SIZE
:
1387 case GL_TEXTURE_ALPHA_SIZE
:
1388 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1389 *params
= _mesa_get_format_bits(texFormat
, pname
);
1393 case GL_TEXTURE_INTENSITY_SIZE
:
1394 case GL_TEXTURE_LUMINANCE_SIZE
:
1395 if (ctx
->API
!= API_OPENGL_COMPAT
)
1397 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1398 *params
= _mesa_get_format_bits(texFormat
, pname
);
1400 /* intensity or luminance is probably stored as RGB[A] */
1401 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1402 GL_TEXTURE_RED_SIZE
),
1403 _mesa_get_format_bits(texFormat
,
1404 GL_TEXTURE_GREEN_SIZE
));
1411 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1412 if (!ctx
->Extensions
.ARB_depth_texture
)
1414 *params
= _mesa_get_format_bits(texFormat
, pname
);
1416 case GL_TEXTURE_STENCIL_SIZE
:
1417 *params
= _mesa_get_format_bits(texFormat
, pname
);
1419 case GL_TEXTURE_SHARED_SIZE
:
1420 if (ctx
->Version
< 30 &&
1421 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1423 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1426 /* GL_ARB_texture_compression */
1427 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1428 if (_mesa_is_format_compressed(texFormat
) &&
1429 !_mesa_is_proxy_texture(target
)) {
1430 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1431 img
->Height
, img
->Depth
);
1433 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1434 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1435 _mesa_enum_to_string(pname
));
1438 case GL_TEXTURE_COMPRESSED
:
1439 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1442 /* GL_ARB_texture_float */
1443 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1444 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1445 if (ctx
->API
!= API_OPENGL_COMPAT
)
1448 case GL_TEXTURE_RED_TYPE_ARB
:
1449 case GL_TEXTURE_GREEN_TYPE_ARB
:
1450 case GL_TEXTURE_BLUE_TYPE_ARB
:
1451 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1452 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1453 if (!ctx
->Extensions
.ARB_texture_float
)
1455 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1456 *params
= _mesa_get_format_datatype(texFormat
);
1461 /* GL_ARB_texture_multisample */
1462 case GL_TEXTURE_SAMPLES
:
1463 if (!ctx
->Extensions
.ARB_texture_multisample
)
1465 *params
= img
->NumSamples
;
1468 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1469 if (!ctx
->Extensions
.ARB_texture_multisample
)
1471 *params
= img
->FixedSampleLocations
;
1474 /* There is never a buffer data store here, but these pnames still have
1478 /* GL_ARB_texture_buffer_object */
1479 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1480 if (!ctx
->Extensions
.ARB_texture_buffer_object
)
1485 /* GL_ARB_texture_buffer_range */
1486 case GL_TEXTURE_BUFFER_OFFSET
:
1487 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1491 case GL_TEXTURE_BUFFER_SIZE
:
1492 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1501 /* no error if we get here */
1505 _mesa_error(ctx
, GL_INVALID_ENUM
,
1506 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1507 _mesa_enum_to_string(pname
));
1512 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1515 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1516 const struct gl_texture_object
*texObj
,
1517 GLenum pname
, GLint
*params
, bool dsa
)
1519 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1520 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1521 int bytes
= MAX2(1, _mesa_get_format_bytes(texFormat
));
1522 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1523 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1524 const char *suffix
= dsa
? "ture" : "";
1526 assert(texObj
->Target
== GL_TEXTURE_BUFFER
);
1529 /* undefined texture buffer object */
1531 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1534 case GL_TEXTURE_INTERNAL_FORMAT
:
1535 *params
= internalFormat
;
1545 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1548 case GL_TEXTURE_WIDTH
:
1549 *params
= ((texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
)
1552 case GL_TEXTURE_HEIGHT
:
1553 case GL_TEXTURE_DEPTH
:
1556 case GL_TEXTURE_BORDER
:
1557 case GL_TEXTURE_SHARED_SIZE
:
1558 case GL_TEXTURE_COMPRESSED
:
1561 case GL_TEXTURE_INTERNAL_FORMAT
:
1562 *params
= internalFormat
;
1564 case GL_TEXTURE_RED_SIZE
:
1565 case GL_TEXTURE_GREEN_SIZE
:
1566 case GL_TEXTURE_BLUE_SIZE
:
1567 case GL_TEXTURE_ALPHA_SIZE
:
1568 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1569 *params
= _mesa_get_format_bits(texFormat
, pname
);
1573 case GL_TEXTURE_INTENSITY_SIZE
:
1574 case GL_TEXTURE_LUMINANCE_SIZE
:
1575 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1576 *params
= _mesa_get_format_bits(texFormat
, pname
);
1578 /* intensity or luminance is probably stored as RGB[A] */
1579 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1580 GL_TEXTURE_RED_SIZE
),
1581 _mesa_get_format_bits(texFormat
,
1582 GL_TEXTURE_GREEN_SIZE
));
1588 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1589 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1590 *params
= _mesa_get_format_bits(texFormat
, pname
);
1593 /* GL_ARB_texture_buffer_range */
1594 case GL_TEXTURE_BUFFER_OFFSET
:
1595 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1597 *params
= texObj
->BufferOffset
;
1599 case GL_TEXTURE_BUFFER_SIZE
:
1600 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1602 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1605 /* GL_ARB_texture_multisample */
1606 case GL_TEXTURE_SAMPLES
:
1607 if (!ctx
->Extensions
.ARB_texture_multisample
)
1612 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1613 if (!ctx
->Extensions
.ARB_texture_multisample
)
1618 /* GL_ARB_texture_compression */
1619 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1620 /* Always illegal for GL_TEXTURE_BUFFER */
1621 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1622 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1623 _mesa_enum_to_string(pname
));
1626 /* GL_ARB_texture_float */
1627 case GL_TEXTURE_RED_TYPE_ARB
:
1628 case GL_TEXTURE_GREEN_TYPE_ARB
:
1629 case GL_TEXTURE_BLUE_TYPE_ARB
:
1630 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1631 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1632 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1633 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1634 if (!ctx
->Extensions
.ARB_texture_float
)
1636 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1637 *params
= _mesa_get_format_datatype(texFormat
);
1646 /* no error if we get here */
1650 _mesa_error(ctx
, GL_INVALID_ENUM
,
1651 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1652 _mesa_enum_to_string(pname
));
1656 valid_tex_level_parameteriv_target(struct gl_context
*ctx
, GLenum target
,
1659 const char *suffix
= dsa
? "ture" : "";
1660 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1661 _mesa_error(ctx
, GL_INVALID_ENUM
,
1662 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1663 _mesa_enum_to_string(target
));
1670 * This isn't exposed to the rest of the driver because it is a part of the
1671 * OpenGL API that is rarely used.
1674 get_tex_level_parameteriv(struct gl_context
*ctx
,
1675 struct gl_texture_object
*texObj
,
1676 GLenum target
, GLint level
,
1677 GLenum pname
, GLint
*params
,
1681 const char *suffix
= dsa
? "ture" : "";
1683 /* Check for errors */
1684 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1685 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1686 "glGetTex%sLevelParameter[if]v("
1687 "current unit >= max combined texture units)", suffix
);
1691 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1692 assert(maxLevels
!= 0);
1694 if (level
< 0 || level
>= maxLevels
) {
1695 _mesa_error(ctx
, GL_INVALID_VALUE
,
1696 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1700 /* Get the level parameter */
1701 if (target
== GL_TEXTURE_BUFFER
) {
1702 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1705 get_tex_level_parameter_image(ctx
, texObj
, target
,
1706 level
, pname
, params
, dsa
);
1711 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1712 GLenum pname
, GLfloat
*params
)
1714 struct gl_texture_object
*texObj
;
1716 GET_CURRENT_CONTEXT(ctx
);
1718 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1721 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1725 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1726 pname
, &iparam
, false);
1728 *params
= (GLfloat
) iparam
;
1732 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1733 GLenum pname
, GLint
*params
)
1735 struct gl_texture_object
*texObj
;
1736 GET_CURRENT_CONTEXT(ctx
);
1738 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1741 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1745 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1746 pname
, params
, false);
1750 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1751 GLenum pname
, GLfloat
*params
)
1753 struct gl_texture_object
*texObj
;
1755 GET_CURRENT_CONTEXT(ctx
);
1757 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1758 "glGetTextureLevelParameterfv");
1762 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1765 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1766 pname
, &iparam
, true);
1768 *params
= (GLfloat
) iparam
;
1772 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1773 GLenum pname
, GLint
*params
)
1775 struct gl_texture_object
*texObj
;
1776 GET_CURRENT_CONTEXT(ctx
);
1778 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1779 "glGetTextureLevelParameteriv");
1783 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1786 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1787 pname
, params
, true);
1791 * This isn't exposed to the rest of the driver because it is a part of the
1792 * OpenGL API that is rarely used.
1795 get_tex_parameterfv(struct gl_context
*ctx
,
1796 struct gl_texture_object
*obj
,
1797 GLenum pname
, GLfloat
*params
, bool dsa
)
1799 _mesa_lock_context_textures(ctx
);
1801 case GL_TEXTURE_MAG_FILTER
:
1802 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1804 case GL_TEXTURE_MIN_FILTER
:
1805 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1807 case GL_TEXTURE_WRAP_S
:
1808 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1810 case GL_TEXTURE_WRAP_T
:
1811 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1813 case GL_TEXTURE_WRAP_R
:
1814 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1816 case GL_TEXTURE_BORDER_COLOR
:
1817 if (ctx
->API
== API_OPENGLES
||
1818 !ctx
->Extensions
.ARB_texture_border_clamp
)
1821 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1822 _mesa_update_state_locked(ctx
);
1823 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
1824 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1825 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1826 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1827 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1830 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1831 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1832 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1833 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1836 case GL_TEXTURE_RESIDENT
:
1837 if (ctx
->API
!= API_OPENGL_COMPAT
)
1842 case GL_TEXTURE_PRIORITY
:
1843 if (ctx
->API
!= API_OPENGL_COMPAT
)
1846 *params
= obj
->Priority
;
1848 case GL_TEXTURE_MIN_LOD
:
1849 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1852 *params
= obj
->Sampler
.MinLod
;
1854 case GL_TEXTURE_MAX_LOD
:
1855 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1858 *params
= obj
->Sampler
.MaxLod
;
1860 case GL_TEXTURE_BASE_LEVEL
:
1861 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1864 *params
= (GLfloat
) obj
->BaseLevel
;
1866 case GL_TEXTURE_MAX_LEVEL
:
1867 *params
= (GLfloat
) obj
->MaxLevel
;
1869 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1870 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1872 *params
= obj
->Sampler
.MaxAnisotropy
;
1874 case GL_GENERATE_MIPMAP_SGIS
:
1875 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1878 *params
= (GLfloat
) obj
->GenerateMipmap
;
1880 case GL_TEXTURE_COMPARE_MODE_ARB
:
1881 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1882 && !_mesa_is_gles3(ctx
))
1884 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1886 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1887 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1888 && !_mesa_is_gles3(ctx
))
1890 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1892 case GL_DEPTH_TEXTURE_MODE_ARB
:
1893 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1894 * never existed in OpenGL ES.
1896 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1898 *params
= (GLfloat
) obj
->DepthMode
;
1900 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1901 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
1904 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1906 case GL_TEXTURE_LOD_BIAS
:
1907 if (_mesa_is_gles(ctx
))
1910 *params
= obj
->Sampler
.LodBias
;
1912 case GL_TEXTURE_CROP_RECT_OES
:
1913 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1916 params
[0] = (GLfloat
) obj
->CropRect
[0];
1917 params
[1] = (GLfloat
) obj
->CropRect
[1];
1918 params
[2] = (GLfloat
) obj
->CropRect
[2];
1919 params
[3] = (GLfloat
) obj
->CropRect
[3];
1922 case GL_TEXTURE_SWIZZLE_R_EXT
:
1923 case GL_TEXTURE_SWIZZLE_G_EXT
:
1924 case GL_TEXTURE_SWIZZLE_B_EXT
:
1925 case GL_TEXTURE_SWIZZLE_A_EXT
:
1926 if ((!_mesa_is_desktop_gl(ctx
)
1927 || !ctx
->Extensions
.EXT_texture_swizzle
)
1928 && !_mesa_is_gles3(ctx
))
1930 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1933 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1934 if ((!_mesa_is_desktop_gl(ctx
)
1935 || !ctx
->Extensions
.EXT_texture_swizzle
)
1936 && !_mesa_is_gles3(ctx
)) {
1941 for (comp
= 0; comp
< 4; comp
++) {
1942 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1947 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1948 if (!_mesa_is_desktop_gl(ctx
)
1949 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1951 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1954 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1955 *params
= (GLfloat
) obj
->Immutable
;
1958 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1959 if (_mesa_is_gles3(ctx
) ||
1960 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1961 *params
= (GLfloat
) obj
->ImmutableLevels
;
1966 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1967 if (!ctx
->Extensions
.ARB_texture_view
)
1969 *params
= (GLfloat
) obj
->MinLevel
;
1972 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1973 if (!ctx
->Extensions
.ARB_texture_view
)
1975 *params
= (GLfloat
) obj
->NumLevels
;
1978 case GL_TEXTURE_VIEW_MIN_LAYER
:
1979 if (!ctx
->Extensions
.ARB_texture_view
)
1981 *params
= (GLfloat
) obj
->MinLayer
;
1984 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1985 if (!ctx
->Extensions
.ARB_texture_view
)
1987 *params
= (GLfloat
) obj
->NumLayers
;
1990 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1991 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1993 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1996 case GL_TEXTURE_SRGB_DECODE_EXT
:
1997 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1999 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
2002 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2003 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2005 *params
= (GLfloat
) obj
->ImageFormatCompatibilityType
;
2008 case GL_TEXTURE_TARGET
:
2009 if (ctx
->API
!= API_OPENGL_CORE
)
2011 *params
= ENUM_TO_FLOAT(obj
->Target
);
2018 /* no error if we get here */
2019 _mesa_unlock_context_textures(ctx
);
2023 _mesa_unlock_context_textures(ctx
);
2024 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
2025 dsa
? "ture" : "", pname
);
2030 get_tex_parameteriv(struct gl_context
*ctx
,
2031 struct gl_texture_object
*obj
,
2032 GLenum pname
, GLint
*params
, bool dsa
)
2034 _mesa_lock_texture(ctx
, obj
);
2036 case GL_TEXTURE_MAG_FILTER
:
2037 *params
= (GLint
) obj
->Sampler
.MagFilter
;
2039 case GL_TEXTURE_MIN_FILTER
:
2040 *params
= (GLint
) obj
->Sampler
.MinFilter
;
2042 case GL_TEXTURE_WRAP_S
:
2043 *params
= (GLint
) obj
->Sampler
.WrapS
;
2045 case GL_TEXTURE_WRAP_T
:
2046 *params
= (GLint
) obj
->Sampler
.WrapT
;
2048 case GL_TEXTURE_WRAP_R
:
2049 *params
= (GLint
) obj
->Sampler
.WrapR
;
2051 case GL_TEXTURE_BORDER_COLOR
:
2052 if (ctx
->API
== API_OPENGLES
||
2053 !ctx
->Extensions
.ARB_texture_border_clamp
)
2058 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
2059 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
2060 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
2061 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
2062 params
[0] = FLOAT_TO_INT(b
[0]);
2063 params
[1] = FLOAT_TO_INT(b
[1]);
2064 params
[2] = FLOAT_TO_INT(b
[2]);
2065 params
[3] = FLOAT_TO_INT(b
[3]);
2068 case GL_TEXTURE_RESIDENT
:
2069 if (ctx
->API
!= API_OPENGL_COMPAT
)
2074 case GL_TEXTURE_PRIORITY
:
2075 if (ctx
->API
!= API_OPENGL_COMPAT
)
2078 *params
= FLOAT_TO_INT(obj
->Priority
);
2080 case GL_TEXTURE_MIN_LOD
:
2081 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2083 /* GL spec 'Data Conversions' section specifies that floating-point
2084 * value in integer Get function is rounded to nearest integer
2086 *params
= IROUND(obj
->Sampler
.MinLod
);
2088 case GL_TEXTURE_MAX_LOD
:
2089 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2091 /* GL spec 'Data Conversions' section specifies that floating-point
2092 * value in integer Get function is rounded to nearest integer
2094 *params
= IROUND(obj
->Sampler
.MaxLod
);
2096 case GL_TEXTURE_BASE_LEVEL
:
2097 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2100 *params
= obj
->BaseLevel
;
2102 case GL_TEXTURE_MAX_LEVEL
:
2103 *params
= obj
->MaxLevel
;
2105 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2106 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2108 /* GL spec 'Data Conversions' section specifies that floating-point
2109 * value in integer Get function is rounded to nearest integer
2111 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
2113 case GL_GENERATE_MIPMAP_SGIS
:
2114 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2117 *params
= (GLint
) obj
->GenerateMipmap
;
2119 case GL_TEXTURE_COMPARE_MODE_ARB
:
2120 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2121 && !_mesa_is_gles3(ctx
))
2123 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2125 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2126 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2127 && !_mesa_is_gles3(ctx
))
2129 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2131 case GL_DEPTH_TEXTURE_MODE_ARB
:
2132 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2134 *params
= (GLint
) obj
->DepthMode
;
2136 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2137 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
2140 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2142 case GL_TEXTURE_LOD_BIAS
:
2143 if (_mesa_is_gles(ctx
))
2146 /* GL spec 'Data Conversions' section specifies that floating-point
2147 * value in integer Get function is rounded to nearest integer
2149 *params
= IROUND(obj
->Sampler
.LodBias
);
2151 case GL_TEXTURE_CROP_RECT_OES
:
2152 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2155 params
[0] = obj
->CropRect
[0];
2156 params
[1] = obj
->CropRect
[1];
2157 params
[2] = obj
->CropRect
[2];
2158 params
[3] = obj
->CropRect
[3];
2160 case GL_TEXTURE_SWIZZLE_R_EXT
:
2161 case GL_TEXTURE_SWIZZLE_G_EXT
:
2162 case GL_TEXTURE_SWIZZLE_B_EXT
:
2163 case GL_TEXTURE_SWIZZLE_A_EXT
:
2164 if ((!_mesa_is_desktop_gl(ctx
)
2165 || !ctx
->Extensions
.EXT_texture_swizzle
)
2166 && !_mesa_is_gles3(ctx
))
2168 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2171 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2172 if ((!_mesa_is_desktop_gl(ctx
)
2173 || !ctx
->Extensions
.EXT_texture_swizzle
)
2174 && !_mesa_is_gles3(ctx
))
2176 COPY_4V(params
, obj
->Swizzle
);
2179 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2180 if (!_mesa_is_desktop_gl(ctx
)
2181 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2183 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2186 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2187 *params
= (GLint
) obj
->Immutable
;
2190 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2191 if (_mesa_is_gles3(ctx
) ||
2192 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2193 *params
= obj
->ImmutableLevels
;
2198 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2199 if (!ctx
->Extensions
.ARB_texture_view
)
2201 *params
= (GLint
) obj
->MinLevel
;
2204 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2205 if (!ctx
->Extensions
.ARB_texture_view
)
2207 *params
= (GLint
) obj
->NumLevels
;
2210 case GL_TEXTURE_VIEW_MIN_LAYER
:
2211 if (!ctx
->Extensions
.ARB_texture_view
)
2213 *params
= (GLint
) obj
->MinLayer
;
2216 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2217 if (!ctx
->Extensions
.ARB_texture_view
)
2219 *params
= (GLint
) obj
->NumLayers
;
2222 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2223 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2225 *params
= obj
->RequiredTextureImageUnits
;
2228 case GL_TEXTURE_SRGB_DECODE_EXT
:
2229 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2231 *params
= obj
->Sampler
.sRGBDecode
;
2234 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2235 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2237 *params
= obj
->ImageFormatCompatibilityType
;
2240 case GL_TEXTURE_TARGET
:
2241 if (ctx
->API
!= API_OPENGL_CORE
)
2243 *params
= (GLint
) obj
->Target
;
2250 /* no error if we get here */
2251 _mesa_unlock_texture(ctx
, obj
);
2255 _mesa_unlock_texture(ctx
, obj
);
2256 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2257 dsa
? "ture" : "", pname
);
2261 get_tex_parameterIiv(struct gl_context
*ctx
,
2262 struct gl_texture_object
*obj
,
2263 GLenum pname
, GLint
*params
, bool dsa
)
2266 case GL_TEXTURE_BORDER_COLOR
:
2267 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2270 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2275 get_tex_parameterIuiv(struct gl_context
*ctx
,
2276 struct gl_texture_object
*obj
,
2277 GLenum pname
, GLuint
*params
, bool dsa
)
2280 case GL_TEXTURE_BORDER_COLOR
:
2281 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2286 get_tex_parameteriv(ctx
, obj
, pname
, ip
, dsa
);
2288 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
2289 pname
== GL_TEXTURE_CROP_RECT_OES
) {
2299 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2301 struct gl_texture_object
*obj
;
2302 GET_CURRENT_CONTEXT(ctx
);
2304 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2308 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2312 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2314 struct gl_texture_object
*obj
;
2315 GET_CURRENT_CONTEXT(ctx
);
2317 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2321 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2324 /** New in GL 3.0 */
2326 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
2328 struct gl_texture_object
*texObj
;
2329 GET_CURRENT_CONTEXT(ctx
);
2331 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2335 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, false);
2339 /** New in GL 3.0 */
2341 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2343 struct gl_texture_object
*texObj
;
2344 GET_CURRENT_CONTEXT(ctx
);
2346 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2350 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, false);
2355 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2357 struct gl_texture_object
*obj
;
2358 GET_CURRENT_CONTEXT(ctx
);
2360 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterfv");
2364 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2368 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2370 struct gl_texture_object
*obj
;
2371 GET_CURRENT_CONTEXT(ctx
);
2373 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameteriv");
2377 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2381 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2383 struct gl_texture_object
*texObj
;
2384 GET_CURRENT_CONTEXT(ctx
);
2386 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIiv");
2390 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2395 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2397 struct gl_texture_object
*texObj
;
2398 GET_CURRENT_CONTEXT(ctx
);
2400 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIuiv");
2404 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, true);