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_OPERATION
, "%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(GLushort
*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 /* Section 8.10 (Texture Parameters) of the OpenGL 4.5 Core Profile spec
382 * An INVALID_OPERATION error is generated if the effective target is
383 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY, or
384 * TEXTURE_RECTANGLE, and pname TEXTURE_BASE_LEVEL is set to a value
387 * Note that section 3.8.8 (Texture Parameters) of the OpenGL 3.3 Core
390 * The error INVALID_VALUE is generated if TEXTURE_BASE_LEVEL is set
391 * to any value other than zero.
393 * We take the 4.5 language as a correction to 3.3, and we implement
394 * that on all GL versions.
396 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
397 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
||
398 texObj
->Target
== GL_TEXTURE_RECTANGLE
) && params
[0] != 0)
399 goto invalid_operation
;
402 _mesa_error(ctx
, GL_INVALID_VALUE
,
403 "glTex%sParameter(param=%d)", suffix
, params
[0]);
406 incomplete(ctx
, texObj
);
408 /** See note about ARB_texture_storage below */
409 if (texObj
->Immutable
)
410 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
412 texObj
->BaseLevel
= params
[0];
416 case GL_TEXTURE_MAX_LEVEL
:
417 if (texObj
->MaxLevel
== params
[0])
421 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
422 _mesa_error(ctx
, GL_INVALID_VALUE
,
423 "glTex%sParameter(param=%d)", suffix
,
427 incomplete(ctx
, texObj
);
429 /** From ARB_texture_storage:
430 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
431 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
432 * the range [level_base, <levels> - 1], where <levels> is the parameter
433 * passed the call to TexStorage* for the texture object.
435 if (texObj
->Immutable
)
436 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
437 texObj
->ImmutableLevels
- 1);
439 texObj
->MaxLevel
= params
[0];
443 case GL_GENERATE_MIPMAP_SGIS
:
444 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
447 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
449 if (texObj
->GenerateMipmap
!= params
[0]) {
451 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
456 case GL_TEXTURE_COMPARE_MODE_ARB
:
457 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
458 || _mesa_is_gles3(ctx
)) {
460 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
463 if (texObj
->Sampler
.CompareMode
== params
[0])
465 if (params
[0] == GL_NONE
||
466 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
468 texObj
->Sampler
.CompareMode
= params
[0];
475 case GL_TEXTURE_COMPARE_FUNC_ARB
:
476 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
477 || _mesa_is_gles3(ctx
)) {
479 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
482 if (texObj
->Sampler
.CompareFunc
== params
[0])
494 texObj
->Sampler
.CompareFunc
= params
[0];
502 case GL_DEPTH_TEXTURE_MODE_ARB
:
503 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
504 * existed in OpenGL ES.
506 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
507 if (texObj
->DepthMode
== params
[0])
509 if (params
[0] == GL_LUMINANCE
||
510 params
[0] == GL_INTENSITY
||
511 params
[0] == GL_ALPHA
||
512 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
514 texObj
->DepthMode
= params
[0];
521 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
522 if (_mesa_has_ARB_stencil_texturing(ctx
) || _mesa_is_gles31(ctx
)) {
523 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
524 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
527 if (texObj
->StencilSampling
== stencil
)
530 texObj
->StencilSampling
= stencil
;
535 case GL_TEXTURE_CROP_RECT_OES
:
536 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
539 texObj
->CropRect
[0] = params
[0];
540 texObj
->CropRect
[1] = params
[1];
541 texObj
->CropRect
[2] = params
[2];
542 texObj
->CropRect
[3] = params
[3];
545 case GL_TEXTURE_SWIZZLE_R_EXT
:
546 case GL_TEXTURE_SWIZZLE_G_EXT
:
547 case GL_TEXTURE_SWIZZLE_B_EXT
:
548 case GL_TEXTURE_SWIZZLE_A_EXT
:
549 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
550 || _mesa_is_gles3(ctx
)) {
551 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
552 const GLint swz
= comp_to_swizzle(params
[0]);
554 _mesa_error(ctx
, GL_INVALID_ENUM
,
555 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
561 texObj
->Swizzle
[comp
] = params
[0];
562 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
567 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
568 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
569 || _mesa_is_gles3(ctx
)) {
572 for (comp
= 0; comp
< 4; comp
++) {
573 const GLint swz
= comp_to_swizzle(params
[comp
]);
575 texObj
->Swizzle
[comp
] = params
[comp
];
576 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
579 _mesa_error(ctx
, GL_INVALID_ENUM
,
580 "glTex%sParameter(swizzle 0x%x)",
581 suffix
, params
[comp
]);
589 case GL_TEXTURE_SRGB_DECODE_EXT
:
590 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
591 GLenum decode
= params
[0];
593 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
596 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
597 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
599 texObj
->Sampler
.sRGBDecode
= decode
;
606 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
607 if (_mesa_is_desktop_gl(ctx
)
608 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
609 GLenum param
= params
[0];
611 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
614 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
617 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
619 texObj
->Sampler
.CubeMapSeamless
= param
;
625 case GL_TEXTURE_TILING_EXT
:
626 if (ctx
->Extensions
.EXT_memory_object
) {
627 texObj
->TextureTiling
= params
[0];
638 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
639 suffix
, _mesa_enum_to_string(pname
));
643 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
644 suffix
, _mesa_enum_to_string(params
[0]));
648 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
649 suffix
, _mesa_enum_to_string(pname
));
653 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
654 suffix
, _mesa_enum_to_string(pname
));
660 * Set a float-valued texture parameter
661 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
664 set_tex_parameterf(struct gl_context
*ctx
,
665 struct gl_texture_object
*texObj
,
666 GLenum pname
, const GLfloat
*params
, bool dsa
)
668 const char *suffix
= dsa
? "ture" : "";
670 if (texObj
->HandleAllocated
) {
671 /* The ARB_bindless_texture spec says:
673 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
674 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
675 * functions defined in terms of these, if the texture object to be
676 * modified is referenced by one or more texture or image handles."
678 _mesa_error(ctx
, GL_INVALID_OPERATION
,
679 "glTex%sParameter(immutable texture)", suffix
);
684 case GL_TEXTURE_MIN_LOD
:
685 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
688 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
691 if (texObj
->Sampler
.MinLod
== params
[0])
694 texObj
->Sampler
.MinLod
= params
[0];
697 case GL_TEXTURE_MAX_LOD
:
698 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
701 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
704 if (texObj
->Sampler
.MaxLod
== params
[0])
707 texObj
->Sampler
.MaxLod
= params
[0];
710 case GL_TEXTURE_PRIORITY
:
711 if (ctx
->API
!= API_OPENGL_COMPAT
)
715 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
718 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
719 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
720 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
723 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
725 if (params
[0] < 1.0F
) {
726 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
731 /* clamp to max, that's what NVIDIA does */
732 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
733 ctx
->Const
.MaxTextureMaxAnisotropy
);
737 static GLuint count
= 0;
743 case GL_TEXTURE_LOD_BIAS
:
744 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
745 if (_mesa_is_gles(ctx
))
748 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
751 if (texObj
->Sampler
.LodBias
!= params
[0]) {
753 texObj
->Sampler
.LodBias
= params
[0];
758 case GL_TEXTURE_BORDER_COLOR
:
759 /* Border color exists in desktop OpenGL since 1.0 for GL_CLAMP. In
760 * OpenGL ES 2.0+, it only exists in when GL_OES_texture_border_clamp is
761 * enabled. It is never available in OpenGL ES 1.x.
763 * FIXME: Every driver that supports GLES2 has this extension. Elide
766 if (ctx
->API
== API_OPENGLES
||
767 (ctx
->API
== API_OPENGLES2
&&
768 !ctx
->Extensions
.ARB_texture_border_clamp
))
771 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
775 /* ARB_texture_float disables clamping */
776 if (ctx
->Extensions
.ARB_texture_float
) {
777 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
778 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
779 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
780 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
782 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
783 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
784 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
785 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
789 case GL_TEXTURE_TILING_EXT
:
790 if (ctx
->Extensions
.EXT_memory_object
) {
791 texObj
->TextureTiling
= params
[0];
802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
803 suffix
, _mesa_enum_to_string(pname
));
807 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
808 suffix
, _mesa_enum_to_string(pname
));
814 _mesa_texture_parameterf(struct gl_context
*ctx
,
815 struct gl_texture_object
*texObj
,
816 GLenum pname
, GLfloat param
, bool dsa
)
818 GLboolean need_update
;
821 case GL_TEXTURE_MIN_FILTER
:
822 case GL_TEXTURE_MAG_FILTER
:
823 case GL_TEXTURE_WRAP_S
:
824 case GL_TEXTURE_WRAP_T
:
825 case GL_TEXTURE_WRAP_R
:
826 case GL_TEXTURE_BASE_LEVEL
:
827 case GL_TEXTURE_MAX_LEVEL
:
828 case GL_GENERATE_MIPMAP_SGIS
:
829 case GL_TEXTURE_COMPARE_MODE_ARB
:
830 case GL_TEXTURE_COMPARE_FUNC_ARB
:
831 case GL_DEPTH_TEXTURE_MODE_ARB
:
832 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
833 case GL_TEXTURE_SRGB_DECODE_EXT
:
834 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
835 case GL_TEXTURE_SWIZZLE_R_EXT
:
836 case GL_TEXTURE_SWIZZLE_G_EXT
:
837 case GL_TEXTURE_SWIZZLE_B_EXT
:
838 case GL_TEXTURE_SWIZZLE_A_EXT
:
842 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
843 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
845 p
[1] = p
[2] = p
[3] = 0;
846 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
849 case GL_TEXTURE_BORDER_COLOR
:
850 case GL_TEXTURE_SWIZZLE_RGBA
:
851 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
856 /* this will generate an error if pname is illegal */
859 p
[1] = p
[2] = p
[3] = 0.0F
;
860 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
864 if (ctx
->Driver
.TexParameter
&& need_update
) {
865 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
871 _mesa_texture_parameterfv(struct gl_context
*ctx
,
872 struct gl_texture_object
*texObj
,
873 GLenum pname
, const GLfloat
*params
, bool dsa
)
875 GLboolean need_update
;
877 case GL_TEXTURE_MIN_FILTER
:
878 case GL_TEXTURE_MAG_FILTER
:
879 case GL_TEXTURE_WRAP_S
:
880 case GL_TEXTURE_WRAP_T
:
881 case GL_TEXTURE_WRAP_R
:
882 case GL_TEXTURE_BASE_LEVEL
:
883 case GL_TEXTURE_MAX_LEVEL
:
884 case GL_GENERATE_MIPMAP_SGIS
:
885 case GL_TEXTURE_COMPARE_MODE_ARB
:
886 case GL_TEXTURE_COMPARE_FUNC_ARB
:
887 case GL_DEPTH_TEXTURE_MODE_ARB
:
888 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
889 case GL_TEXTURE_SRGB_DECODE_EXT
:
890 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
892 /* convert float param to int */
894 p
[0] = (GLint
) params
[0];
895 p
[1] = p
[2] = p
[3] = 0;
896 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
899 case GL_TEXTURE_CROP_RECT_OES
:
901 /* convert float params to int */
903 iparams
[0] = (GLint
) params
[0];
904 iparams
[1] = (GLint
) params
[1];
905 iparams
[2] = (GLint
) params
[2];
906 iparams
[3] = (GLint
) params
[3];
907 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
910 case GL_TEXTURE_SWIZZLE_R_EXT
:
911 case GL_TEXTURE_SWIZZLE_G_EXT
:
912 case GL_TEXTURE_SWIZZLE_B_EXT
:
913 case GL_TEXTURE_SWIZZLE_A_EXT
:
914 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
916 GLint p
[4] = {0, 0, 0, 0};
917 p
[0] = (GLint
) params
[0];
918 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
919 p
[1] = (GLint
) params
[1];
920 p
[2] = (GLint
) params
[2];
921 p
[3] = (GLint
) params
[3];
923 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
927 /* this will generate an error if pname is illegal */
928 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
931 if (ctx
->Driver
.TexParameter
&& need_update
) {
932 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
938 _mesa_texture_parameteri(struct gl_context
*ctx
,
939 struct gl_texture_object
*texObj
,
940 GLenum pname
, GLint param
, bool dsa
)
942 GLboolean need_update
;
944 case GL_TEXTURE_MIN_LOD
:
945 case GL_TEXTURE_MAX_LOD
:
946 case GL_TEXTURE_PRIORITY
:
947 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
948 case GL_TEXTURE_LOD_BIAS
:
949 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
952 fparam
[0] = (GLfloat
) param
;
953 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
954 /* convert int param to float */
955 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
958 case GL_TEXTURE_BORDER_COLOR
:
959 case GL_TEXTURE_SWIZZLE_RGBA
:
961 _mesa_error(ctx
, GL_INVALID_ENUM
,
962 "glTex%sParameteri(non-scalar pname)",
967 /* this will generate an error if pname is illegal */
971 iparam
[1] = iparam
[2] = iparam
[3] = 0;
972 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
976 if (ctx
->Driver
.TexParameter
&& need_update
) {
977 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
983 _mesa_texture_parameteriv(struct gl_context
*ctx
,
984 struct gl_texture_object
*texObj
,
985 GLenum pname
, const GLint
*params
, bool dsa
)
987 GLboolean need_update
;
990 case GL_TEXTURE_BORDER_COLOR
:
992 /* convert int params to float */
994 fparams
[0] = INT_TO_FLOAT(params
[0]);
995 fparams
[1] = INT_TO_FLOAT(params
[1]);
996 fparams
[2] = INT_TO_FLOAT(params
[2]);
997 fparams
[3] = INT_TO_FLOAT(params
[3]);
998 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
1001 case GL_TEXTURE_MIN_LOD
:
1002 case GL_TEXTURE_MAX_LOD
:
1003 case GL_TEXTURE_PRIORITY
:
1004 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1005 case GL_TEXTURE_LOD_BIAS
:
1006 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1008 /* convert int param to float */
1010 fparams
[0] = (GLfloat
) params
[0];
1011 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
1012 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
1016 /* this will generate an error if pname is illegal */
1017 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
1020 if (ctx
->Driver
.TexParameter
&& need_update
) {
1021 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
1026 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
1027 struct gl_texture_object
*texObj
,
1028 GLenum pname
, const GLint
*params
, bool dsa
)
1031 case GL_TEXTURE_BORDER_COLOR
:
1032 if (texObj
->HandleAllocated
) {
1033 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1034 "glTextureParameterIiv(immutable texture)");
1038 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1039 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIiv(texture)");
1042 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1043 /* set the integer-valued border color */
1044 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
1047 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
1050 /* XXX no driver hook for TexParameterIiv() yet */
1054 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
1055 struct gl_texture_object
*texObj
,
1056 GLenum pname
, const GLuint
*params
, bool dsa
)
1059 case GL_TEXTURE_BORDER_COLOR
:
1060 if (texObj
->HandleAllocated
) {
1061 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1062 "glTextureParameterIuiv(immutable texture)");
1066 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1067 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIuiv(texture)");
1070 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1071 /* set the unsigned integer-valued border color */
1072 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1075 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1079 /* XXX no driver hook for TexParameterIuiv() yet */
1083 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1085 struct gl_texture_object
*texObj
;
1086 GET_CURRENT_CONTEXT(ctx
);
1088 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1092 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1096 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1098 struct gl_texture_object
*texObj
;
1099 GET_CURRENT_CONTEXT(ctx
);
1101 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1105 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1109 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1111 struct gl_texture_object
*texObj
;
1112 GET_CURRENT_CONTEXT(ctx
);
1114 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1118 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1122 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1124 struct gl_texture_object
*texObj
;
1125 GET_CURRENT_CONTEXT(ctx
);
1127 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1131 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1135 * Set tex parameter to integer value(s). Primarily intended to set
1136 * integer-valued texture border color (for integer-valued textures).
1140 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1142 struct gl_texture_object
*texObj
;
1143 GET_CURRENT_CONTEXT(ctx
);
1145 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1149 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1153 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1154 * uint-valued texture border color (for integer-valued textures).
1158 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1160 struct gl_texture_object
*texObj
;
1161 GET_CURRENT_CONTEXT(ctx
);
1163 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1167 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1172 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1174 struct gl_texture_object
*texObj
;
1175 GET_CURRENT_CONTEXT(ctx
);
1177 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterfv");
1181 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1185 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1187 struct gl_texture_object
*texObj
;
1188 GET_CURRENT_CONTEXT(ctx
);
1190 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterf");
1194 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1198 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1200 struct gl_texture_object
*texObj
;
1201 GET_CURRENT_CONTEXT(ctx
);
1203 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteri");
1207 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1211 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1212 const GLint
*params
)
1214 struct gl_texture_object
*texObj
;
1215 GET_CURRENT_CONTEXT(ctx
);
1217 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteriv");
1221 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1226 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1228 struct gl_texture_object
*texObj
;
1229 GET_CURRENT_CONTEXT(ctx
);
1231 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIiv");
1235 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1239 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1241 struct gl_texture_object
*texObj
;
1242 GET_CURRENT_CONTEXT(ctx
);
1244 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIuiv");
1248 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1252 _mesa_legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1255 /* Common targets for desktop GL and GLES 3.1. */
1260 case GL_TEXTURE_2D_ARRAY_EXT
:
1261 return ctx
->Extensions
.EXT_texture_array
;
1262 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1263 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1264 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1265 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1266 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1267 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1268 return ctx
->Extensions
.ARB_texture_cube_map
;
1269 case GL_TEXTURE_2D_MULTISAMPLE
:
1270 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1271 return ctx
->Extensions
.ARB_texture_multisample
;
1272 case GL_TEXTURE_BUFFER
:
1273 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1274 * but not in earlier versions that expose ARB_texture_buffer_object.
1276 * From the ARB_texture_buffer_object spec:
1277 * "(7) Do buffer textures support texture parameters (TexParameter) or
1278 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1280 * RESOLVED: No. [...] Note that the spec edits above don't add
1281 * explicit error language for any of these cases. That is because
1282 * each of the functions enumerate the set of valid <target>
1283 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1284 * these cases means that target is not legal, and an INVALID_ENUM
1285 * error should be generated."
1287 * From the OpenGL 3.1 spec:
1288 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1290 return (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 31) ||
1291 _mesa_has_OES_texture_buffer(ctx
);
1292 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1293 return _mesa_has_texture_cube_map_array(ctx
);
1296 if (!_mesa_is_desktop_gl(ctx
))
1299 /* Rest of the desktop GL targets. */
1302 case GL_PROXY_TEXTURE_1D
:
1303 case GL_PROXY_TEXTURE_2D
:
1304 case GL_PROXY_TEXTURE_3D
:
1306 case GL_PROXY_TEXTURE_CUBE_MAP
:
1307 return ctx
->Extensions
.ARB_texture_cube_map
;
1308 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1309 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1310 case GL_TEXTURE_RECTANGLE_NV
:
1311 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1312 return ctx
->Extensions
.NV_texture_rectangle
;
1313 case GL_TEXTURE_1D_ARRAY_EXT
:
1314 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1315 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1316 return ctx
->Extensions
.EXT_texture_array
;
1317 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1318 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1319 return ctx
->Extensions
.ARB_texture_multisample
;
1321 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1322 * (30.10.2014) Section 8.11 Texture Queries says:
1323 * "For GetTextureLevelParameter* only, texture may also be a cube
1324 * map texture object. In this case the query is always performed
1325 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1326 * is no way to specify another face."
1328 case GL_TEXTURE_CUBE_MAP
:
1337 get_tex_level_parameter_image(struct gl_context
*ctx
,
1338 const struct gl_texture_object
*texObj
,
1339 GLenum target
, GLint level
,
1340 GLenum pname
, GLint
*params
,
1343 const struct gl_texture_image
*img
= NULL
;
1344 struct gl_texture_image dummy_image
;
1345 mesa_format texFormat
;
1346 const char *suffix
= dsa
? "ture" : "";
1348 img
= _mesa_select_tex_image(texObj
, target
, level
);
1349 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1350 /* In case of undefined texture image return the default values.
1352 * From OpenGL 4.0 spec, page 398:
1353 * "The initial internal format of a texel array is RGBA
1354 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1355 * use TEXTURE_INTERNAL_FORMAT."
1357 memset(&dummy_image
, 0, sizeof(dummy_image
));
1358 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1359 dummy_image
.InternalFormat
= GL_RGBA
;
1360 dummy_image
._BaseFormat
= GL_NONE
;
1361 dummy_image
.FixedSampleLocations
= GL_TRUE
;
1366 texFormat
= img
->TexFormat
;
1369 case GL_TEXTURE_WIDTH
:
1370 *params
= img
->Width
;
1372 case GL_TEXTURE_HEIGHT
:
1373 *params
= img
->Height
;
1375 case GL_TEXTURE_DEPTH
:
1376 *params
= img
->Depth
;
1378 case GL_TEXTURE_INTERNAL_FORMAT
:
1379 if (_mesa_is_format_compressed(texFormat
)) {
1380 /* need to return the actual compressed format */
1381 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1384 /* If the true internal format is not compressed but the user
1385 * requested a generic compressed format, we have to return the
1386 * generic base format that matches.
1388 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1390 * "If no specific compressed format is available,
1391 * internalformat is instead replaced by the corresponding base
1394 * Otherwise just return the user's requested internal format
1397 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1399 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1402 case GL_TEXTURE_BORDER
:
1403 if (ctx
->API
!= API_OPENGL_COMPAT
)
1405 *params
= img
->Border
;
1407 case GL_TEXTURE_RED_SIZE
:
1408 case GL_TEXTURE_GREEN_SIZE
:
1409 case GL_TEXTURE_BLUE_SIZE
:
1410 case GL_TEXTURE_ALPHA_SIZE
:
1411 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1412 *params
= _mesa_get_format_bits(texFormat
, pname
);
1416 case GL_TEXTURE_INTENSITY_SIZE
:
1417 case GL_TEXTURE_LUMINANCE_SIZE
:
1418 if (ctx
->API
!= API_OPENGL_COMPAT
)
1420 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1421 *params
= _mesa_get_format_bits(texFormat
, pname
);
1423 /* intensity or luminance is probably stored as RGB[A] */
1424 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1425 GL_TEXTURE_RED_SIZE
),
1426 _mesa_get_format_bits(texFormat
,
1427 GL_TEXTURE_GREEN_SIZE
));
1429 if (*params
== 0 && pname
== GL_TEXTURE_INTENSITY_SIZE
) {
1430 /* Gallium may store intensity as LA */
1431 *params
= _mesa_get_format_bits(texFormat
,
1432 GL_TEXTURE_ALPHA_SIZE
);
1439 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1440 if (!ctx
->Extensions
.ARB_depth_texture
)
1442 *params
= _mesa_get_format_bits(texFormat
, pname
);
1444 case GL_TEXTURE_STENCIL_SIZE
:
1445 *params
= _mesa_get_format_bits(texFormat
, pname
);
1447 case GL_TEXTURE_SHARED_SIZE
:
1448 if (ctx
->Version
< 30 &&
1449 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1451 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1454 /* GL_ARB_texture_compression */
1455 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1456 if (_mesa_is_format_compressed(texFormat
) &&
1457 !_mesa_is_proxy_texture(target
)) {
1458 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1459 img
->Height
, img
->Depth
);
1461 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1462 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1463 _mesa_enum_to_string(pname
));
1466 case GL_TEXTURE_COMPRESSED
:
1467 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1470 /* GL_ARB_texture_float */
1471 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1472 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1473 if (ctx
->API
!= API_OPENGL_COMPAT
)
1476 case GL_TEXTURE_RED_TYPE_ARB
:
1477 case GL_TEXTURE_GREEN_TYPE_ARB
:
1478 case GL_TEXTURE_BLUE_TYPE_ARB
:
1479 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1480 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1481 if (!ctx
->Extensions
.ARB_texture_float
)
1483 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1484 *params
= _mesa_get_format_datatype(texFormat
);
1489 /* GL_ARB_texture_multisample */
1490 case GL_TEXTURE_SAMPLES
:
1491 if (!ctx
->Extensions
.ARB_texture_multisample
)
1493 *params
= img
->NumSamples
;
1496 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1497 if (!ctx
->Extensions
.ARB_texture_multisample
)
1499 *params
= img
->FixedSampleLocations
;
1502 /* There is never a buffer data store here, but these pnames still have
1506 /* GL_ARB_texture_buffer_object */
1507 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1508 if (!ctx
->Extensions
.ARB_texture_buffer_object
)
1513 /* GL_ARB_texture_buffer_range */
1514 case GL_TEXTURE_BUFFER_OFFSET
:
1515 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1519 case GL_TEXTURE_BUFFER_SIZE
:
1520 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1529 /* no error if we get here */
1533 _mesa_error(ctx
, GL_INVALID_ENUM
,
1534 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1535 _mesa_enum_to_string(pname
));
1540 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1543 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1544 const struct gl_texture_object
*texObj
,
1545 GLenum pname
, GLint
*params
, bool dsa
)
1547 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1548 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1549 int bytes
= MAX2(1, _mesa_get_format_bytes(texFormat
));
1550 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1551 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1552 const char *suffix
= dsa
? "ture" : "";
1554 assert(texObj
->Target
== GL_TEXTURE_BUFFER
);
1557 /* undefined texture buffer object */
1559 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1562 case GL_TEXTURE_INTERNAL_FORMAT
:
1563 *params
= internalFormat
;
1573 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1576 case GL_TEXTURE_WIDTH
:
1577 *params
= ((texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
)
1580 case GL_TEXTURE_HEIGHT
:
1581 case GL_TEXTURE_DEPTH
:
1584 case GL_TEXTURE_BORDER
:
1585 case GL_TEXTURE_SHARED_SIZE
:
1586 case GL_TEXTURE_COMPRESSED
:
1589 case GL_TEXTURE_INTERNAL_FORMAT
:
1590 *params
= internalFormat
;
1592 case GL_TEXTURE_RED_SIZE
:
1593 case GL_TEXTURE_GREEN_SIZE
:
1594 case GL_TEXTURE_BLUE_SIZE
:
1595 case GL_TEXTURE_ALPHA_SIZE
:
1596 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1597 *params
= _mesa_get_format_bits(texFormat
, pname
);
1601 case GL_TEXTURE_INTENSITY_SIZE
:
1602 case GL_TEXTURE_LUMINANCE_SIZE
:
1603 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1604 *params
= _mesa_get_format_bits(texFormat
, pname
);
1606 /* intensity or luminance is probably stored as RGB[A] */
1607 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1608 GL_TEXTURE_RED_SIZE
),
1609 _mesa_get_format_bits(texFormat
,
1610 GL_TEXTURE_GREEN_SIZE
));
1616 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1617 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1618 *params
= _mesa_get_format_bits(texFormat
, pname
);
1621 /* GL_ARB_texture_buffer_range */
1622 case GL_TEXTURE_BUFFER_OFFSET
:
1623 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1625 *params
= texObj
->BufferOffset
;
1627 case GL_TEXTURE_BUFFER_SIZE
:
1628 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1630 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1633 /* GL_ARB_texture_multisample */
1634 case GL_TEXTURE_SAMPLES
:
1635 if (!ctx
->Extensions
.ARB_texture_multisample
)
1640 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1641 if (!ctx
->Extensions
.ARB_texture_multisample
)
1646 /* GL_ARB_texture_compression */
1647 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1648 /* Always illegal for GL_TEXTURE_BUFFER */
1649 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1650 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1651 _mesa_enum_to_string(pname
));
1654 /* GL_ARB_texture_float */
1655 case GL_TEXTURE_RED_TYPE_ARB
:
1656 case GL_TEXTURE_GREEN_TYPE_ARB
:
1657 case GL_TEXTURE_BLUE_TYPE_ARB
:
1658 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1659 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1660 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1661 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1662 if (!ctx
->Extensions
.ARB_texture_float
)
1664 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1665 *params
= _mesa_get_format_datatype(texFormat
);
1674 /* no error if we get here */
1678 _mesa_error(ctx
, GL_INVALID_ENUM
,
1679 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1680 _mesa_enum_to_string(pname
));
1684 valid_tex_level_parameteriv_target(struct gl_context
*ctx
, GLenum target
,
1687 const char *suffix
= dsa
? "ture" : "";
1688 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1689 _mesa_error(ctx
, GL_INVALID_ENUM
,
1690 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1691 _mesa_enum_to_string(target
));
1698 * This isn't exposed to the rest of the driver because it is a part of the
1699 * OpenGL API that is rarely used.
1702 get_tex_level_parameteriv(struct gl_context
*ctx
,
1703 struct gl_texture_object
*texObj
,
1704 GLenum target
, GLint level
,
1705 GLenum pname
, GLint
*params
,
1709 const char *suffix
= dsa
? "ture" : "";
1711 /* Check for errors */
1712 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1714 "glGetTex%sLevelParameter[if]v("
1715 "current unit >= max combined texture units)", suffix
);
1719 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1720 assert(maxLevels
!= 0);
1722 if (level
< 0 || level
>= maxLevels
) {
1723 _mesa_error(ctx
, GL_INVALID_VALUE
,
1724 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1728 /* Get the level parameter */
1729 if (target
== GL_TEXTURE_BUFFER
) {
1730 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1733 get_tex_level_parameter_image(ctx
, texObj
, target
,
1734 level
, pname
, params
, dsa
);
1739 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1740 GLenum pname
, GLfloat
*params
)
1742 struct gl_texture_object
*texObj
;
1744 GET_CURRENT_CONTEXT(ctx
);
1746 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1749 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1753 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1754 pname
, &iparam
, false);
1756 *params
= (GLfloat
) iparam
;
1760 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1761 GLenum pname
, GLint
*params
)
1763 struct gl_texture_object
*texObj
;
1764 GET_CURRENT_CONTEXT(ctx
);
1766 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1769 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1773 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1774 pname
, params
, false);
1778 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1779 GLenum pname
, GLfloat
*params
)
1781 struct gl_texture_object
*texObj
;
1783 GET_CURRENT_CONTEXT(ctx
);
1785 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1786 "glGetTextureLevelParameterfv");
1790 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1793 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1794 pname
, &iparam
, true);
1796 *params
= (GLfloat
) iparam
;
1800 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1801 GLenum pname
, GLint
*params
)
1803 struct gl_texture_object
*texObj
;
1804 GET_CURRENT_CONTEXT(ctx
);
1806 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1807 "glGetTextureLevelParameteriv");
1811 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1814 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1815 pname
, params
, true);
1819 * This isn't exposed to the rest of the driver because it is a part of the
1820 * OpenGL API that is rarely used.
1823 get_tex_parameterfv(struct gl_context
*ctx
,
1824 struct gl_texture_object
*obj
,
1825 GLenum pname
, GLfloat
*params
, bool dsa
)
1827 _mesa_lock_context_textures(ctx
);
1829 case GL_TEXTURE_MAG_FILTER
:
1830 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1832 case GL_TEXTURE_MIN_FILTER
:
1833 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1835 case GL_TEXTURE_WRAP_S
:
1836 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1838 case GL_TEXTURE_WRAP_T
:
1839 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1841 case GL_TEXTURE_WRAP_R
:
1842 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1844 case GL_TEXTURE_BORDER_COLOR
:
1845 if (ctx
->API
== API_OPENGLES
||
1846 !ctx
->Extensions
.ARB_texture_border_clamp
)
1849 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1850 _mesa_update_state_locked(ctx
);
1851 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
1852 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1853 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1854 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1855 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1858 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1859 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1860 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1861 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1864 case GL_TEXTURE_RESIDENT
:
1865 if (ctx
->API
!= API_OPENGL_COMPAT
)
1870 case GL_TEXTURE_PRIORITY
:
1871 if (ctx
->API
!= API_OPENGL_COMPAT
)
1874 *params
= obj
->Priority
;
1876 case GL_TEXTURE_MIN_LOD
:
1877 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1880 *params
= obj
->Sampler
.MinLod
;
1882 case GL_TEXTURE_MAX_LOD
:
1883 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1886 *params
= obj
->Sampler
.MaxLod
;
1888 case GL_TEXTURE_BASE_LEVEL
:
1889 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1892 *params
= (GLfloat
) obj
->BaseLevel
;
1894 case GL_TEXTURE_MAX_LEVEL
:
1895 *params
= (GLfloat
) obj
->MaxLevel
;
1897 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1898 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1900 *params
= obj
->Sampler
.MaxAnisotropy
;
1902 case GL_GENERATE_MIPMAP_SGIS
:
1903 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1906 *params
= (GLfloat
) obj
->GenerateMipmap
;
1908 case GL_TEXTURE_COMPARE_MODE_ARB
:
1909 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1910 && !_mesa_is_gles3(ctx
))
1912 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1914 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1915 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1916 && !_mesa_is_gles3(ctx
))
1918 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1920 case GL_DEPTH_TEXTURE_MODE_ARB
:
1921 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1922 * never existed in OpenGL ES.
1924 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1926 *params
= (GLfloat
) obj
->DepthMode
;
1928 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1929 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
1932 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1934 case GL_TEXTURE_LOD_BIAS
:
1935 if (_mesa_is_gles(ctx
))
1938 *params
= obj
->Sampler
.LodBias
;
1940 case GL_TEXTURE_CROP_RECT_OES
:
1941 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1944 params
[0] = (GLfloat
) obj
->CropRect
[0];
1945 params
[1] = (GLfloat
) obj
->CropRect
[1];
1946 params
[2] = (GLfloat
) obj
->CropRect
[2];
1947 params
[3] = (GLfloat
) obj
->CropRect
[3];
1950 case GL_TEXTURE_SWIZZLE_R_EXT
:
1951 case GL_TEXTURE_SWIZZLE_G_EXT
:
1952 case GL_TEXTURE_SWIZZLE_B_EXT
:
1953 case GL_TEXTURE_SWIZZLE_A_EXT
:
1954 if ((!_mesa_is_desktop_gl(ctx
)
1955 || !ctx
->Extensions
.EXT_texture_swizzle
)
1956 && !_mesa_is_gles3(ctx
))
1958 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1961 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1962 if ((!_mesa_is_desktop_gl(ctx
)
1963 || !ctx
->Extensions
.EXT_texture_swizzle
)
1964 && !_mesa_is_gles3(ctx
)) {
1969 for (comp
= 0; comp
< 4; comp
++) {
1970 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1975 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1976 if (!_mesa_is_desktop_gl(ctx
)
1977 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1979 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1982 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1983 *params
= (GLfloat
) obj
->Immutable
;
1986 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1987 if (_mesa_is_gles3(ctx
) || _mesa_has_texture_view(ctx
))
1988 *params
= (GLfloat
) obj
->ImmutableLevels
;
1993 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1994 if (!_mesa_has_texture_view(ctx
))
1996 *params
= (GLfloat
) obj
->MinLevel
;
1999 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2000 if (!_mesa_has_texture_view(ctx
))
2002 *params
= (GLfloat
) obj
->NumLevels
;
2005 case GL_TEXTURE_VIEW_MIN_LAYER
:
2006 if (!_mesa_has_texture_view(ctx
))
2008 *params
= (GLfloat
) obj
->MinLayer
;
2011 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2012 if (!_mesa_has_texture_view(ctx
))
2014 *params
= (GLfloat
) obj
->NumLayers
;
2017 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2018 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2020 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
2023 case GL_TEXTURE_SRGB_DECODE_EXT
:
2024 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2026 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
2029 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2030 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2032 *params
= (GLfloat
) obj
->ImageFormatCompatibilityType
;
2035 case GL_TEXTURE_TARGET
:
2036 if (ctx
->API
!= API_OPENGL_CORE
)
2038 *params
= ENUM_TO_FLOAT(obj
->Target
);
2041 case GL_TEXTURE_TILING_EXT
:
2042 if (!ctx
->Extensions
.EXT_memory_object
)
2044 *params
= ENUM_TO_FLOAT(obj
->TextureTiling
);
2051 /* no error if we get here */
2052 _mesa_unlock_context_textures(ctx
);
2056 _mesa_unlock_context_textures(ctx
);
2057 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
2058 dsa
? "ture" : "", pname
);
2063 get_tex_parameteriv(struct gl_context
*ctx
,
2064 struct gl_texture_object
*obj
,
2065 GLenum pname
, GLint
*params
, bool dsa
)
2067 _mesa_lock_texture(ctx
, obj
);
2069 case GL_TEXTURE_MAG_FILTER
:
2070 *params
= (GLint
) obj
->Sampler
.MagFilter
;
2072 case GL_TEXTURE_MIN_FILTER
:
2073 *params
= (GLint
) obj
->Sampler
.MinFilter
;
2075 case GL_TEXTURE_WRAP_S
:
2076 *params
= (GLint
) obj
->Sampler
.WrapS
;
2078 case GL_TEXTURE_WRAP_T
:
2079 *params
= (GLint
) obj
->Sampler
.WrapT
;
2081 case GL_TEXTURE_WRAP_R
:
2082 *params
= (GLint
) obj
->Sampler
.WrapR
;
2084 case GL_TEXTURE_BORDER_COLOR
:
2085 if (ctx
->API
== API_OPENGLES
||
2086 !ctx
->Extensions
.ARB_texture_border_clamp
)
2091 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
2092 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
2093 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
2094 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
2095 params
[0] = FLOAT_TO_INT(b
[0]);
2096 params
[1] = FLOAT_TO_INT(b
[1]);
2097 params
[2] = FLOAT_TO_INT(b
[2]);
2098 params
[3] = FLOAT_TO_INT(b
[3]);
2101 case GL_TEXTURE_RESIDENT
:
2102 if (ctx
->API
!= API_OPENGL_COMPAT
)
2107 case GL_TEXTURE_PRIORITY
:
2108 if (ctx
->API
!= API_OPENGL_COMPAT
)
2111 *params
= FLOAT_TO_INT(obj
->Priority
);
2113 case GL_TEXTURE_MIN_LOD
:
2114 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2116 /* GL spec 'Data Conversions' section specifies that floating-point
2117 * value in integer Get function is rounded to nearest integer
2119 *params
= IROUND(obj
->Sampler
.MinLod
);
2121 case GL_TEXTURE_MAX_LOD
:
2122 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2124 /* GL spec 'Data Conversions' section specifies that floating-point
2125 * value in integer Get function is rounded to nearest integer
2127 *params
= IROUND(obj
->Sampler
.MaxLod
);
2129 case GL_TEXTURE_BASE_LEVEL
:
2130 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2133 *params
= obj
->BaseLevel
;
2135 case GL_TEXTURE_MAX_LEVEL
:
2136 *params
= obj
->MaxLevel
;
2138 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2139 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2141 /* GL spec 'Data Conversions' section specifies that floating-point
2142 * value in integer Get function is rounded to nearest integer
2144 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
2146 case GL_GENERATE_MIPMAP_SGIS
:
2147 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2150 *params
= (GLint
) obj
->GenerateMipmap
;
2152 case GL_TEXTURE_COMPARE_MODE_ARB
:
2153 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2154 && !_mesa_is_gles3(ctx
))
2156 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2158 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2159 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2160 && !_mesa_is_gles3(ctx
))
2162 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2164 case GL_DEPTH_TEXTURE_MODE_ARB
:
2165 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2167 *params
= (GLint
) obj
->DepthMode
;
2169 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2170 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
2173 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2175 case GL_TEXTURE_LOD_BIAS
:
2176 if (_mesa_is_gles(ctx
))
2179 /* GL spec 'Data Conversions' section specifies that floating-point
2180 * value in integer Get function is rounded to nearest integer
2182 *params
= IROUND(obj
->Sampler
.LodBias
);
2184 case GL_TEXTURE_CROP_RECT_OES
:
2185 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2188 params
[0] = obj
->CropRect
[0];
2189 params
[1] = obj
->CropRect
[1];
2190 params
[2] = obj
->CropRect
[2];
2191 params
[3] = obj
->CropRect
[3];
2193 case GL_TEXTURE_SWIZZLE_R_EXT
:
2194 case GL_TEXTURE_SWIZZLE_G_EXT
:
2195 case GL_TEXTURE_SWIZZLE_B_EXT
:
2196 case GL_TEXTURE_SWIZZLE_A_EXT
:
2197 if ((!_mesa_is_desktop_gl(ctx
)
2198 || !ctx
->Extensions
.EXT_texture_swizzle
)
2199 && !_mesa_is_gles3(ctx
))
2201 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2204 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2205 if ((!_mesa_is_desktop_gl(ctx
)
2206 || !ctx
->Extensions
.EXT_texture_swizzle
)
2207 && !_mesa_is_gles3(ctx
))
2209 COPY_4V(params
, obj
->Swizzle
);
2212 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2213 if (!_mesa_is_desktop_gl(ctx
)
2214 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2216 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2219 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2220 *params
= (GLint
) obj
->Immutable
;
2223 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2224 if (_mesa_is_gles3(ctx
) ||
2225 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2226 *params
= obj
->ImmutableLevels
;
2231 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2232 if (!ctx
->Extensions
.ARB_texture_view
)
2234 *params
= (GLint
) obj
->MinLevel
;
2237 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2238 if (!ctx
->Extensions
.ARB_texture_view
)
2240 *params
= (GLint
) obj
->NumLevels
;
2243 case GL_TEXTURE_VIEW_MIN_LAYER
:
2244 if (!ctx
->Extensions
.ARB_texture_view
)
2246 *params
= (GLint
) obj
->MinLayer
;
2249 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2250 if (!ctx
->Extensions
.ARB_texture_view
)
2252 *params
= (GLint
) obj
->NumLayers
;
2255 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2256 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2258 *params
= obj
->RequiredTextureImageUnits
;
2261 case GL_TEXTURE_SRGB_DECODE_EXT
:
2262 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2264 *params
= obj
->Sampler
.sRGBDecode
;
2267 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2268 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2270 *params
= obj
->ImageFormatCompatibilityType
;
2273 case GL_TEXTURE_TARGET
:
2274 if (ctx
->API
!= API_OPENGL_CORE
)
2276 *params
= (GLint
) obj
->Target
;
2279 case GL_TEXTURE_TILING_EXT
:
2280 if (!ctx
->Extensions
.EXT_memory_object
)
2282 *params
= (GLint
) obj
->TextureTiling
;
2289 /* no error if we get here */
2290 _mesa_unlock_texture(ctx
, obj
);
2294 _mesa_unlock_texture(ctx
, obj
);
2295 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2296 dsa
? "ture" : "", pname
);
2300 get_tex_parameterIiv(struct gl_context
*ctx
,
2301 struct gl_texture_object
*obj
,
2302 GLenum pname
, GLint
*params
, bool dsa
)
2305 case GL_TEXTURE_BORDER_COLOR
:
2306 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2309 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2314 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2316 struct gl_texture_object
*obj
;
2317 GET_CURRENT_CONTEXT(ctx
);
2319 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2323 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2327 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2329 struct gl_texture_object
*obj
;
2330 GET_CURRENT_CONTEXT(ctx
);
2332 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2336 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2339 /** New in GL 3.0 */
2341 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*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_parameterIiv(ctx
, texObj
, pname
, params
, false);
2354 /** New in GL 3.0 */
2356 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2358 struct gl_texture_object
*texObj
;
2359 GET_CURRENT_CONTEXT(ctx
);
2361 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2365 get_tex_parameterIiv(ctx
, texObj
, pname
, (GLint
*) params
, false);
2370 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2372 struct gl_texture_object
*obj
;
2373 GET_CURRENT_CONTEXT(ctx
);
2375 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterfv");
2379 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2383 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2385 struct gl_texture_object
*obj
;
2386 GET_CURRENT_CONTEXT(ctx
);
2388 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameteriv");
2392 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2396 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2398 struct gl_texture_object
*texObj
;
2399 GET_CURRENT_CONTEXT(ctx
);
2401 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIiv");
2405 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2410 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2412 struct gl_texture_object
*texObj
;
2413 GET_CURRENT_CONTEXT(ctx
);
2415 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIuiv");
2419 get_tex_parameterIiv(ctx
, texObj
, pname
, (GLint
*) params
, true);