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
];
151 is_texparameteri_target_valid(GLenum target
)
155 case GL_TEXTURE_1D_ARRAY
:
157 case GL_TEXTURE_2D_ARRAY
:
158 case GL_TEXTURE_2D_MULTISAMPLE
:
159 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
161 case GL_TEXTURE_CUBE_MAP
:
162 case GL_TEXTURE_CUBE_MAP_ARRAY
:
163 case GL_TEXTURE_RECTANGLE
:
172 * Get current texture object for given name.
173 * Return NULL if any error (and record the error).
174 * Note that proxy targets are not accepted.
175 * Only the glGetTexLevelParameter() functions accept proxy targets.
177 static struct gl_texture_object
*
178 get_texobj_by_name(struct gl_context
*ctx
, GLuint texture
, const char *name
)
180 struct gl_texture_object
*texObj
;
182 texObj
= _mesa_lookup_texture_err(ctx
, texture
, name
);
186 if (!is_texparameteri_target_valid(texObj
->Target
)) {
187 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", name
);
196 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
197 * \return -1 if error.
200 comp_to_swizzle(GLenum comp
)
222 set_swizzle_component(GLushort
*swizzle
, GLuint comp
, GLuint swz
)
225 assert(swz
<= SWIZZLE_NIL
);
227 GLuint mask
= 0x7 << (3 * comp
);
228 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
235 * This is called just prior to changing any texture object state which
236 * will not affect texture completeness.
239 flush(struct gl_context
*ctx
)
241 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
246 * This is called just prior to changing any texture object state which
247 * could affect texture completeness (texture base level, max level).
248 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE_OBJECT
249 * state flag and then mark the texture object as 'incomplete' so that any
250 * per-texture derived state gets recomputed.
253 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
255 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
256 _mesa_dirty_texobj(ctx
, texObj
);
261 _mesa_target_allows_setting_sampler_parameters(GLenum target
)
264 case GL_TEXTURE_2D_MULTISAMPLE
:
265 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
275 * Set an integer-valued texture parameter
276 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
279 set_tex_parameteri(struct gl_context
*ctx
,
280 struct gl_texture_object
*texObj
,
281 GLenum pname
, const GLint
*params
, bool dsa
)
283 const char *suffix
= dsa
? "ture" : "";
285 if (texObj
->HandleAllocated
) {
286 /* The ARB_bindless_texture spec says:
288 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
289 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
290 * functions defined in terms of these, if the texture object to be
291 * modified is referenced by one or more texture or image handles."
293 _mesa_error(ctx
, GL_INVALID_OPERATION
,
294 "glTex%sParameter(immutable texture)", suffix
);
299 case GL_TEXTURE_MIN_FILTER
:
300 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
303 if (texObj
->Sampler
.MinFilter
== params
[0])
309 texObj
->Sampler
.MinFilter
= params
[0];
311 case GL_NEAREST_MIPMAP_NEAREST
:
312 case GL_LINEAR_MIPMAP_NEAREST
:
313 case GL_NEAREST_MIPMAP_LINEAR
:
314 case GL_LINEAR_MIPMAP_LINEAR
:
315 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
316 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
318 texObj
->Sampler
.MinFilter
= params
[0];
327 case GL_TEXTURE_MAG_FILTER
:
328 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
331 if (texObj
->Sampler
.MagFilter
== params
[0])
336 flush(ctx
); /* does not effect completeness */
337 texObj
->Sampler
.MagFilter
= params
[0];
344 case GL_TEXTURE_WRAP_S
:
345 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
348 if (texObj
->Sampler
.WrapS
== params
[0])
350 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
352 texObj
->Sampler
.WrapS
= params
[0];
357 case GL_TEXTURE_WRAP_T
:
358 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
361 if (texObj
->Sampler
.WrapT
== params
[0])
363 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
365 texObj
->Sampler
.WrapT
= params
[0];
370 case GL_TEXTURE_WRAP_R
:
371 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
374 if (texObj
->Sampler
.WrapR
== params
[0])
376 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
378 texObj
->Sampler
.WrapR
= params
[0];
383 case GL_TEXTURE_BASE_LEVEL
:
384 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
387 if (texObj
->BaseLevel
== params
[0])
390 /* Section 8.10 (Texture Parameters) of the OpenGL 4.5 Core Profile spec
393 * An INVALID_OPERATION error is generated if the effective target is
394 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY, or
395 * TEXTURE_RECTANGLE, and pname TEXTURE_BASE_LEVEL is set to a value
398 * Note that section 3.8.8 (Texture Parameters) of the OpenGL 3.3 Core
401 * The error INVALID_VALUE is generated if TEXTURE_BASE_LEVEL is set
402 * to any value other than zero.
404 * We take the 4.5 language as a correction to 3.3, and we implement
405 * that on all GL versions.
407 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
408 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
||
409 texObj
->Target
== GL_TEXTURE_RECTANGLE
) && params
[0] != 0)
410 goto invalid_operation
;
413 _mesa_error(ctx
, GL_INVALID_VALUE
,
414 "glTex%sParameter(param=%d)", suffix
, params
[0]);
417 incomplete(ctx
, texObj
);
419 /** See note about ARB_texture_storage below */
420 if (texObj
->Immutable
)
421 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
423 texObj
->BaseLevel
= params
[0];
427 case GL_TEXTURE_MAX_LEVEL
:
428 if (texObj
->MaxLevel
== params
[0])
432 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
433 _mesa_error(ctx
, GL_INVALID_VALUE
,
434 "glTex%sParameter(param=%d)", suffix
,
438 incomplete(ctx
, texObj
);
440 /** From ARB_texture_storage:
441 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
442 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
443 * the range [level_base, <levels> - 1], where <levels> is the parameter
444 * passed the call to TexStorage* for the texture object.
446 if (texObj
->Immutable
)
447 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
448 texObj
->ImmutableLevels
- 1);
450 texObj
->MaxLevel
= params
[0];
454 case GL_GENERATE_MIPMAP_SGIS
:
455 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
458 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
460 if (texObj
->GenerateMipmap
!= params
[0]) {
462 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
467 case GL_TEXTURE_COMPARE_MODE_ARB
:
468 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
469 || _mesa_is_gles3(ctx
)) {
471 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
474 if (texObj
->Sampler
.CompareMode
== params
[0])
476 if (params
[0] == GL_NONE
||
477 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
479 texObj
->Sampler
.CompareMode
= params
[0];
486 case GL_TEXTURE_COMPARE_FUNC_ARB
:
487 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
488 || _mesa_is_gles3(ctx
)) {
490 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
493 if (texObj
->Sampler
.CompareFunc
== params
[0])
505 texObj
->Sampler
.CompareFunc
= params
[0];
513 case GL_DEPTH_TEXTURE_MODE_ARB
:
514 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
515 * existed in OpenGL ES.
517 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
518 if (texObj
->DepthMode
== params
[0])
520 if (params
[0] == GL_LUMINANCE
||
521 params
[0] == GL_INTENSITY
||
522 params
[0] == GL_ALPHA
||
523 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
525 texObj
->DepthMode
= params
[0];
532 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
533 if (_mesa_has_ARB_stencil_texturing(ctx
) || _mesa_is_gles31(ctx
)) {
534 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
535 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
538 if (texObj
->StencilSampling
== stencil
)
541 texObj
->StencilSampling
= stencil
;
546 case GL_TEXTURE_CROP_RECT_OES
:
547 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
550 texObj
->CropRect
[0] = params
[0];
551 texObj
->CropRect
[1] = params
[1];
552 texObj
->CropRect
[2] = params
[2];
553 texObj
->CropRect
[3] = params
[3];
556 case GL_TEXTURE_SWIZZLE_R_EXT
:
557 case GL_TEXTURE_SWIZZLE_G_EXT
:
558 case GL_TEXTURE_SWIZZLE_B_EXT
:
559 case GL_TEXTURE_SWIZZLE_A_EXT
:
560 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
561 || _mesa_is_gles3(ctx
)) {
562 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
563 const GLint swz
= comp_to_swizzle(params
[0]);
565 _mesa_error(ctx
, GL_INVALID_ENUM
,
566 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
572 texObj
->Swizzle
[comp
] = params
[0];
573 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
578 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
579 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
580 || _mesa_is_gles3(ctx
)) {
583 for (comp
= 0; comp
< 4; comp
++) {
584 const GLint swz
= comp_to_swizzle(params
[comp
]);
586 texObj
->Swizzle
[comp
] = params
[comp
];
587 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
590 _mesa_error(ctx
, GL_INVALID_ENUM
,
591 "glTex%sParameter(swizzle 0x%x)",
592 suffix
, params
[comp
]);
600 case GL_TEXTURE_SRGB_DECODE_EXT
:
601 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
602 GLenum decode
= params
[0];
604 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
607 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
608 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
610 texObj
->Sampler
.sRGBDecode
= decode
;
617 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
618 if (_mesa_is_desktop_gl(ctx
)
619 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
620 GLenum param
= params
[0];
622 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
625 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
628 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
630 texObj
->Sampler
.CubeMapSeamless
= param
;
636 case GL_TEXTURE_TILING_EXT
:
637 if (ctx
->Extensions
.EXT_memory_object
) {
638 texObj
->TextureTiling
= params
[0];
649 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
650 suffix
, _mesa_enum_to_string(pname
));
654 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
655 suffix
, _mesa_enum_to_string(params
[0]));
659 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
660 suffix
, _mesa_enum_to_string(pname
));
664 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
665 suffix
, _mesa_enum_to_string(pname
));
671 * Set a float-valued texture parameter
672 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
675 set_tex_parameterf(struct gl_context
*ctx
,
676 struct gl_texture_object
*texObj
,
677 GLenum pname
, const GLfloat
*params
, bool dsa
)
679 const char *suffix
= dsa
? "ture" : "";
681 if (texObj
->HandleAllocated
) {
682 /* The ARB_bindless_texture spec says:
684 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
685 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
686 * functions defined in terms of these, if the texture object to be
687 * modified is referenced by one or more texture or image handles."
689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
690 "glTex%sParameter(immutable texture)", suffix
);
695 case GL_TEXTURE_MIN_LOD
:
696 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
699 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
702 if (texObj
->Sampler
.MinLod
== params
[0])
705 texObj
->Sampler
.MinLod
= params
[0];
708 case GL_TEXTURE_MAX_LOD
:
709 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
712 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
715 if (texObj
->Sampler
.MaxLod
== params
[0])
718 texObj
->Sampler
.MaxLod
= params
[0];
721 case GL_TEXTURE_PRIORITY
:
722 if (ctx
->API
!= API_OPENGL_COMPAT
)
726 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
729 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
730 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
731 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
734 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
736 if (params
[0] < 1.0F
) {
737 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
742 /* clamp to max, that's what NVIDIA does */
743 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
744 ctx
->Const
.MaxTextureMaxAnisotropy
);
748 static GLuint count
= 0;
754 case GL_TEXTURE_LOD_BIAS
:
755 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
756 if (_mesa_is_gles(ctx
))
759 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
762 if (texObj
->Sampler
.LodBias
!= params
[0]) {
764 texObj
->Sampler
.LodBias
= params
[0];
769 case GL_TEXTURE_BORDER_COLOR
:
770 /* Border color exists in desktop OpenGL since 1.0 for GL_CLAMP. In
771 * OpenGL ES 2.0+, it only exists in when GL_OES_texture_border_clamp is
772 * enabled. It is never available in OpenGL ES 1.x.
774 * FIXME: Every driver that supports GLES2 has this extension. Elide
777 if (ctx
->API
== API_OPENGLES
||
778 (ctx
->API
== API_OPENGLES2
&&
779 !ctx
->Extensions
.ARB_texture_border_clamp
))
782 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
786 /* ARB_texture_float disables clamping */
787 if (ctx
->Extensions
.ARB_texture_float
) {
788 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
789 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
790 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
791 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
793 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
794 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
795 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
796 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
800 case GL_TEXTURE_TILING_EXT
:
801 if (ctx
->Extensions
.EXT_memory_object
) {
802 texObj
->TextureTiling
= params
[0];
813 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
814 suffix
, _mesa_enum_to_string(pname
));
818 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
819 suffix
, _mesa_enum_to_string(pname
));
825 _mesa_texture_parameterf(struct gl_context
*ctx
,
826 struct gl_texture_object
*texObj
,
827 GLenum pname
, GLfloat param
, bool dsa
)
829 GLboolean need_update
;
832 case GL_TEXTURE_MIN_FILTER
:
833 case GL_TEXTURE_MAG_FILTER
:
834 case GL_TEXTURE_WRAP_S
:
835 case GL_TEXTURE_WRAP_T
:
836 case GL_TEXTURE_WRAP_R
:
837 case GL_TEXTURE_BASE_LEVEL
:
838 case GL_TEXTURE_MAX_LEVEL
:
839 case GL_GENERATE_MIPMAP_SGIS
:
840 case GL_TEXTURE_COMPARE_MODE_ARB
:
841 case GL_TEXTURE_COMPARE_FUNC_ARB
:
842 case GL_DEPTH_TEXTURE_MODE_ARB
:
843 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
844 case GL_TEXTURE_SRGB_DECODE_EXT
:
845 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
846 case GL_TEXTURE_SWIZZLE_R_EXT
:
847 case GL_TEXTURE_SWIZZLE_G_EXT
:
848 case GL_TEXTURE_SWIZZLE_B_EXT
:
849 case GL_TEXTURE_SWIZZLE_A_EXT
:
853 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
854 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
856 p
[1] = p
[2] = p
[3] = 0;
857 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
860 case GL_TEXTURE_BORDER_COLOR
:
861 case GL_TEXTURE_SWIZZLE_RGBA
:
862 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
867 /* this will generate an error if pname is illegal */
870 p
[1] = p
[2] = p
[3] = 0.0F
;
871 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
875 if (ctx
->Driver
.TexParameter
&& need_update
) {
876 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
882 _mesa_texture_parameterfv(struct gl_context
*ctx
,
883 struct gl_texture_object
*texObj
,
884 GLenum pname
, const GLfloat
*params
, bool dsa
)
886 GLboolean need_update
;
888 case GL_TEXTURE_MIN_FILTER
:
889 case GL_TEXTURE_MAG_FILTER
:
890 case GL_TEXTURE_WRAP_S
:
891 case GL_TEXTURE_WRAP_T
:
892 case GL_TEXTURE_WRAP_R
:
893 case GL_TEXTURE_BASE_LEVEL
:
894 case GL_TEXTURE_MAX_LEVEL
:
895 case GL_GENERATE_MIPMAP_SGIS
:
896 case GL_TEXTURE_COMPARE_MODE_ARB
:
897 case GL_TEXTURE_COMPARE_FUNC_ARB
:
898 case GL_DEPTH_TEXTURE_MODE_ARB
:
899 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
900 case GL_TEXTURE_SRGB_DECODE_EXT
:
901 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
903 /* convert float param to int */
905 p
[0] = (GLint
) params
[0];
906 p
[1] = p
[2] = p
[3] = 0;
907 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
910 case GL_TEXTURE_CROP_RECT_OES
:
912 /* convert float params to int */
914 iparams
[0] = (GLint
) params
[0];
915 iparams
[1] = (GLint
) params
[1];
916 iparams
[2] = (GLint
) params
[2];
917 iparams
[3] = (GLint
) params
[3];
918 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
921 case GL_TEXTURE_SWIZZLE_R_EXT
:
922 case GL_TEXTURE_SWIZZLE_G_EXT
:
923 case GL_TEXTURE_SWIZZLE_B_EXT
:
924 case GL_TEXTURE_SWIZZLE_A_EXT
:
925 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
927 GLint p
[4] = {0, 0, 0, 0};
928 p
[0] = (GLint
) params
[0];
929 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
930 p
[1] = (GLint
) params
[1];
931 p
[2] = (GLint
) params
[2];
932 p
[3] = (GLint
) params
[3];
934 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
938 /* this will generate an error if pname is illegal */
939 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
942 if (ctx
->Driver
.TexParameter
&& need_update
) {
943 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
949 _mesa_texture_parameteri(struct gl_context
*ctx
,
950 struct gl_texture_object
*texObj
,
951 GLenum pname
, GLint param
, bool dsa
)
953 GLboolean need_update
;
955 case GL_TEXTURE_MIN_LOD
:
956 case GL_TEXTURE_MAX_LOD
:
957 case GL_TEXTURE_PRIORITY
:
958 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
959 case GL_TEXTURE_LOD_BIAS
:
960 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
963 fparam
[0] = (GLfloat
) param
;
964 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
965 /* convert int param to float */
966 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
969 case GL_TEXTURE_BORDER_COLOR
:
970 case GL_TEXTURE_SWIZZLE_RGBA
:
972 _mesa_error(ctx
, GL_INVALID_ENUM
,
973 "glTex%sParameteri(non-scalar pname)",
978 /* this will generate an error if pname is illegal */
982 iparam
[1] = iparam
[2] = iparam
[3] = 0;
983 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
987 if (ctx
->Driver
.TexParameter
&& need_update
) {
988 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
994 _mesa_texture_parameteriv(struct gl_context
*ctx
,
995 struct gl_texture_object
*texObj
,
996 GLenum pname
, const GLint
*params
, bool dsa
)
998 GLboolean need_update
;
1001 case GL_TEXTURE_BORDER_COLOR
:
1003 /* convert int params to float */
1005 fparams
[0] = INT_TO_FLOAT(params
[0]);
1006 fparams
[1] = INT_TO_FLOAT(params
[1]);
1007 fparams
[2] = INT_TO_FLOAT(params
[2]);
1008 fparams
[3] = INT_TO_FLOAT(params
[3]);
1009 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
1012 case GL_TEXTURE_MIN_LOD
:
1013 case GL_TEXTURE_MAX_LOD
:
1014 case GL_TEXTURE_PRIORITY
:
1015 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1016 case GL_TEXTURE_LOD_BIAS
:
1017 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1019 /* convert int param to float */
1021 fparams
[0] = (GLfloat
) params
[0];
1022 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
1023 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
1027 /* this will generate an error if pname is illegal */
1028 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
1031 if (ctx
->Driver
.TexParameter
&& need_update
) {
1032 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
1037 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
1038 struct gl_texture_object
*texObj
,
1039 GLenum pname
, const GLint
*params
, bool dsa
)
1042 case GL_TEXTURE_BORDER_COLOR
:
1043 if (texObj
->HandleAllocated
) {
1044 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1045 "glTextureParameterIiv(immutable texture)");
1049 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1050 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIiv(texture)");
1053 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1054 /* set the integer-valued border color */
1055 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
1058 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
1061 /* XXX no driver hook for TexParameterIiv() yet */
1065 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
1066 struct gl_texture_object
*texObj
,
1067 GLenum pname
, const GLuint
*params
, bool dsa
)
1070 case GL_TEXTURE_BORDER_COLOR
:
1071 if (texObj
->HandleAllocated
) {
1072 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1073 "glTextureParameterIuiv(immutable texture)");
1077 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1078 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIuiv(texture)");
1081 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1082 /* set the unsigned integer-valued border color */
1083 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1086 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1090 /* XXX no driver hook for TexParameterIuiv() yet */
1094 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1096 struct gl_texture_object
*texObj
;
1097 GET_CURRENT_CONTEXT(ctx
);
1099 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1103 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1107 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1109 struct gl_texture_object
*texObj
;
1110 GET_CURRENT_CONTEXT(ctx
);
1112 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1116 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1120 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1122 struct gl_texture_object
*texObj
;
1123 GET_CURRENT_CONTEXT(ctx
);
1125 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1129 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1133 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1135 struct gl_texture_object
*texObj
;
1136 GET_CURRENT_CONTEXT(ctx
);
1138 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1142 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1146 * Set tex parameter to integer value(s). Primarily intended to set
1147 * integer-valued texture border color (for integer-valued textures).
1151 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1153 struct gl_texture_object
*texObj
;
1154 GET_CURRENT_CONTEXT(ctx
);
1156 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1160 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1164 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1165 * uint-valued texture border color (for integer-valued textures).
1169 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1171 struct gl_texture_object
*texObj
;
1172 GET_CURRENT_CONTEXT(ctx
);
1174 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1178 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1182 _mesa_TextureParameterfvEXT(GLuint texture
, GLenum target
, GLenum pname
, const GLfloat
*params
)
1184 struct gl_texture_object
*texObj
;
1185 GET_CURRENT_CONTEXT(ctx
);
1187 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
1188 "glTextureParameterfvEXT");
1192 if (!is_texparameteri_target_valid(texObj
->Target
)) {
1193 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterfvEXT");
1197 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1201 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1203 struct gl_texture_object
*texObj
;
1204 GET_CURRENT_CONTEXT(ctx
);
1206 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterfv");
1210 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1214 _mesa_TextureParameterfEXT(GLuint texture
, GLenum target
, GLenum pname
, GLfloat param
)
1216 struct gl_texture_object
*texObj
;
1217 GET_CURRENT_CONTEXT(ctx
);
1219 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
1220 "glTextureParameterfEXT");
1224 if (!is_texparameteri_target_valid(texObj
->Target
)) {
1225 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterfEXT");
1229 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1233 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1235 struct gl_texture_object
*texObj
;
1236 GET_CURRENT_CONTEXT(ctx
);
1238 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterf");
1242 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1246 _mesa_TextureParameteriEXT(GLuint texture
, GLenum target
, GLenum pname
, GLint param
)
1248 struct gl_texture_object
*texObj
;
1249 GET_CURRENT_CONTEXT(ctx
);
1251 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
1252 "glTextureParameteriEXT");
1256 if (!is_texparameteri_target_valid(texObj
->Target
)) {
1257 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteriEXT(target)");
1261 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1265 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1267 struct gl_texture_object
*texObj
;
1268 GET_CURRENT_CONTEXT(ctx
);
1270 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteri");
1274 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1278 _mesa_TextureParameterivEXT(GLuint texture
, GLenum target
, GLenum pname
,
1279 const GLint
*params
)
1281 struct gl_texture_object
*texObj
;
1282 GET_CURRENT_CONTEXT(ctx
);
1284 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
1285 "glTextureParameterivEXT");
1289 if (!is_texparameteri_target_valid(texObj
->Target
)) {
1290 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterivEXT(target)");
1294 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1298 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1299 const GLint
*params
)
1301 struct gl_texture_object
*texObj
;
1302 GET_CURRENT_CONTEXT(ctx
);
1304 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteriv");
1308 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1313 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1315 struct gl_texture_object
*texObj
;
1316 GET_CURRENT_CONTEXT(ctx
);
1318 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIiv");
1322 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1326 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1328 struct gl_texture_object
*texObj
;
1329 GET_CURRENT_CONTEXT(ctx
);
1331 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIuiv");
1335 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1339 _mesa_legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1342 /* Common targets for desktop GL and GLES 3.1. */
1347 case GL_TEXTURE_2D_ARRAY_EXT
:
1348 return ctx
->Extensions
.EXT_texture_array
;
1349 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1350 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1351 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1352 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1353 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1354 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1355 return ctx
->Extensions
.ARB_texture_cube_map
;
1356 case GL_TEXTURE_2D_MULTISAMPLE
:
1357 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1358 return ctx
->Extensions
.ARB_texture_multisample
;
1359 case GL_TEXTURE_BUFFER
:
1360 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1361 * but not in earlier versions that expose ARB_texture_buffer_object.
1363 * From the ARB_texture_buffer_object spec:
1364 * "(7) Do buffer textures support texture parameters (TexParameter) or
1365 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1367 * RESOLVED: No. [...] Note that the spec edits above don't add
1368 * explicit error language for any of these cases. That is because
1369 * each of the functions enumerate the set of valid <target>
1370 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1371 * these cases means that target is not legal, and an INVALID_ENUM
1372 * error should be generated."
1374 * From the OpenGL 3.1 spec:
1375 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1377 return (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 31) ||
1378 _mesa_has_OES_texture_buffer(ctx
);
1379 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1380 return _mesa_has_texture_cube_map_array(ctx
);
1383 if (!_mesa_is_desktop_gl(ctx
))
1386 /* Rest of the desktop GL targets. */
1389 case GL_PROXY_TEXTURE_1D
:
1390 case GL_PROXY_TEXTURE_2D
:
1391 case GL_PROXY_TEXTURE_3D
:
1393 case GL_PROXY_TEXTURE_CUBE_MAP
:
1394 return ctx
->Extensions
.ARB_texture_cube_map
;
1395 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1396 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1397 case GL_TEXTURE_RECTANGLE_NV
:
1398 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1399 return ctx
->Extensions
.NV_texture_rectangle
;
1400 case GL_TEXTURE_1D_ARRAY_EXT
:
1401 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1402 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1403 return ctx
->Extensions
.EXT_texture_array
;
1404 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1405 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1406 return ctx
->Extensions
.ARB_texture_multisample
;
1408 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1409 * (30.10.2014) Section 8.11 Texture Queries says:
1410 * "For GetTextureLevelParameter* only, texture may also be a cube
1411 * map texture object. In this case the query is always performed
1412 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1413 * is no way to specify another face."
1415 case GL_TEXTURE_CUBE_MAP
:
1424 get_tex_level_parameter_image(struct gl_context
*ctx
,
1425 const struct gl_texture_object
*texObj
,
1426 GLenum target
, GLint level
,
1427 GLenum pname
, GLint
*params
,
1430 const struct gl_texture_image
*img
= NULL
;
1431 struct gl_texture_image dummy_image
;
1432 mesa_format texFormat
;
1433 const char *suffix
= dsa
? "ture" : "";
1435 img
= _mesa_select_tex_image(texObj
, target
, level
);
1436 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1437 /* In case of undefined texture image return the default values.
1439 * From OpenGL 4.0 spec, page 398:
1440 * "The initial internal format of a texel array is RGBA
1441 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1442 * use TEXTURE_INTERNAL_FORMAT."
1444 memset(&dummy_image
, 0, sizeof(dummy_image
));
1445 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1446 dummy_image
.InternalFormat
= GL_RGBA
;
1447 dummy_image
._BaseFormat
= GL_NONE
;
1448 dummy_image
.FixedSampleLocations
= GL_TRUE
;
1453 texFormat
= img
->TexFormat
;
1456 case GL_TEXTURE_WIDTH
:
1457 *params
= img
->Width
;
1459 case GL_TEXTURE_HEIGHT
:
1460 *params
= img
->Height
;
1462 case GL_TEXTURE_DEPTH
:
1463 *params
= img
->Depth
;
1465 case GL_TEXTURE_INTERNAL_FORMAT
:
1466 if (_mesa_is_format_compressed(texFormat
)) {
1467 /* need to return the actual compressed format */
1468 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1471 /* If the true internal format is not compressed but the user
1472 * requested a generic compressed format, we have to return the
1473 * generic base format that matches.
1475 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1477 * "If no specific compressed format is available,
1478 * internalformat is instead replaced by the corresponding base
1481 * Otherwise just return the user's requested internal format
1484 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1486 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1489 case GL_TEXTURE_BORDER
:
1490 if (ctx
->API
!= API_OPENGL_COMPAT
)
1492 *params
= img
->Border
;
1494 case GL_TEXTURE_RED_SIZE
:
1495 case GL_TEXTURE_GREEN_SIZE
:
1496 case GL_TEXTURE_BLUE_SIZE
:
1497 case GL_TEXTURE_ALPHA_SIZE
:
1498 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1499 *params
= _mesa_get_format_bits(texFormat
, pname
);
1503 case GL_TEXTURE_INTENSITY_SIZE
:
1504 case GL_TEXTURE_LUMINANCE_SIZE
:
1505 if (ctx
->API
!= API_OPENGL_COMPAT
)
1507 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1508 *params
= _mesa_get_format_bits(texFormat
, pname
);
1510 /* intensity or luminance is probably stored as RGB[A] */
1511 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1512 GL_TEXTURE_RED_SIZE
),
1513 _mesa_get_format_bits(texFormat
,
1514 GL_TEXTURE_GREEN_SIZE
));
1516 if (*params
== 0 && pname
== GL_TEXTURE_INTENSITY_SIZE
) {
1517 /* Gallium may store intensity as LA */
1518 *params
= _mesa_get_format_bits(texFormat
,
1519 GL_TEXTURE_ALPHA_SIZE
);
1526 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1527 if (!ctx
->Extensions
.ARB_depth_texture
)
1529 *params
= _mesa_get_format_bits(texFormat
, pname
);
1531 case GL_TEXTURE_STENCIL_SIZE
:
1532 *params
= _mesa_get_format_bits(texFormat
, pname
);
1534 case GL_TEXTURE_SHARED_SIZE
:
1535 if (ctx
->Version
< 30 &&
1536 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1538 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1541 /* GL_ARB_texture_compression */
1542 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1543 if (_mesa_is_format_compressed(texFormat
) &&
1544 !_mesa_is_proxy_texture(target
)) {
1545 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1546 img
->Height
, img
->Depth
);
1548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1549 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1550 _mesa_enum_to_string(pname
));
1553 case GL_TEXTURE_COMPRESSED
:
1554 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1557 /* GL_ARB_texture_float */
1558 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1559 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1560 if (ctx
->API
!= API_OPENGL_COMPAT
)
1563 case GL_TEXTURE_RED_TYPE_ARB
:
1564 case GL_TEXTURE_GREEN_TYPE_ARB
:
1565 case GL_TEXTURE_BLUE_TYPE_ARB
:
1566 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1567 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1568 if (!ctx
->Extensions
.ARB_texture_float
)
1570 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1571 *params
= _mesa_get_format_datatype(texFormat
);
1576 /* GL_ARB_texture_multisample */
1577 case GL_TEXTURE_SAMPLES
:
1578 if (!ctx
->Extensions
.ARB_texture_multisample
)
1580 *params
= img
->NumSamples
;
1583 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1584 if (!ctx
->Extensions
.ARB_texture_multisample
)
1586 *params
= img
->FixedSampleLocations
;
1589 /* There is never a buffer data store here, but these pnames still have
1593 /* GL_ARB_texture_buffer_object */
1594 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1595 if (!ctx
->Extensions
.ARB_texture_buffer_object
)
1600 /* GL_ARB_texture_buffer_range */
1601 case GL_TEXTURE_BUFFER_OFFSET
:
1602 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1606 case GL_TEXTURE_BUFFER_SIZE
:
1607 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1616 /* no error if we get here */
1620 _mesa_error(ctx
, GL_INVALID_ENUM
,
1621 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1622 _mesa_enum_to_string(pname
));
1627 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1630 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1631 const struct gl_texture_object
*texObj
,
1632 GLenum pname
, GLint
*params
, bool dsa
)
1634 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1635 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1636 int bytes
= MAX2(1, _mesa_get_format_bytes(texFormat
));
1637 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1638 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1639 const char *suffix
= dsa
? "ture" : "";
1641 assert(texObj
->Target
== GL_TEXTURE_BUFFER
);
1644 /* undefined texture buffer object */
1646 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1649 case GL_TEXTURE_INTERNAL_FORMAT
:
1650 *params
= internalFormat
;
1660 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1663 case GL_TEXTURE_WIDTH
:
1664 *params
= ((texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
)
1667 case GL_TEXTURE_HEIGHT
:
1668 case GL_TEXTURE_DEPTH
:
1671 case GL_TEXTURE_BORDER
:
1672 case GL_TEXTURE_SHARED_SIZE
:
1673 case GL_TEXTURE_COMPRESSED
:
1676 case GL_TEXTURE_INTERNAL_FORMAT
:
1677 *params
= internalFormat
;
1679 case GL_TEXTURE_RED_SIZE
:
1680 case GL_TEXTURE_GREEN_SIZE
:
1681 case GL_TEXTURE_BLUE_SIZE
:
1682 case GL_TEXTURE_ALPHA_SIZE
:
1683 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1684 *params
= _mesa_get_format_bits(texFormat
, pname
);
1688 case GL_TEXTURE_INTENSITY_SIZE
:
1689 case GL_TEXTURE_LUMINANCE_SIZE
:
1690 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1691 *params
= _mesa_get_format_bits(texFormat
, pname
);
1693 /* intensity or luminance is probably stored as RGB[A] */
1694 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1695 GL_TEXTURE_RED_SIZE
),
1696 _mesa_get_format_bits(texFormat
,
1697 GL_TEXTURE_GREEN_SIZE
));
1703 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1704 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1705 *params
= _mesa_get_format_bits(texFormat
, pname
);
1708 /* GL_ARB_texture_buffer_range */
1709 case GL_TEXTURE_BUFFER_OFFSET
:
1710 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1712 *params
= texObj
->BufferOffset
;
1714 case GL_TEXTURE_BUFFER_SIZE
:
1715 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1717 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1720 /* GL_ARB_texture_multisample */
1721 case GL_TEXTURE_SAMPLES
:
1722 if (!ctx
->Extensions
.ARB_texture_multisample
)
1727 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1728 if (!ctx
->Extensions
.ARB_texture_multisample
)
1733 /* GL_ARB_texture_compression */
1734 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1735 /* Always illegal for GL_TEXTURE_BUFFER */
1736 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1737 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1738 _mesa_enum_to_string(pname
));
1741 /* GL_ARB_texture_float */
1742 case GL_TEXTURE_RED_TYPE_ARB
:
1743 case GL_TEXTURE_GREEN_TYPE_ARB
:
1744 case GL_TEXTURE_BLUE_TYPE_ARB
:
1745 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1746 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1747 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1748 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1749 if (!ctx
->Extensions
.ARB_texture_float
)
1751 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1752 *params
= _mesa_get_format_datatype(texFormat
);
1761 /* no error if we get here */
1765 _mesa_error(ctx
, GL_INVALID_ENUM
,
1766 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1767 _mesa_enum_to_string(pname
));
1771 valid_tex_level_parameteriv_target(struct gl_context
*ctx
, GLenum target
,
1774 const char *suffix
= dsa
? "ture" : "";
1775 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1776 _mesa_error(ctx
, GL_INVALID_ENUM
,
1777 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1778 _mesa_enum_to_string(target
));
1785 * This isn't exposed to the rest of the driver because it is a part of the
1786 * OpenGL API that is rarely used.
1789 get_tex_level_parameteriv(struct gl_context
*ctx
,
1790 struct gl_texture_object
*texObj
,
1791 GLenum target
, GLint level
,
1792 GLenum pname
, GLint
*params
,
1796 const char *suffix
= dsa
? "ture" : "";
1798 /* Check for errors */
1799 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1800 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1801 "glGetTex%sLevelParameter[if]v("
1802 "current unit >= max combined texture units)", suffix
);
1806 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1807 assert(maxLevels
!= 0);
1809 if (level
< 0 || level
>= maxLevels
) {
1810 _mesa_error(ctx
, GL_INVALID_VALUE
,
1811 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1815 /* Get the level parameter */
1816 if (target
== GL_TEXTURE_BUFFER
) {
1817 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1820 get_tex_level_parameter_image(ctx
, texObj
, target
,
1821 level
, pname
, params
, dsa
);
1826 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1827 GLenum pname
, GLfloat
*params
)
1829 struct gl_texture_object
*texObj
;
1831 GET_CURRENT_CONTEXT(ctx
);
1833 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1836 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1840 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1841 pname
, &iparam
, false);
1843 *params
= (GLfloat
) iparam
;
1847 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1848 GLenum pname
, GLint
*params
)
1850 struct gl_texture_object
*texObj
;
1851 GET_CURRENT_CONTEXT(ctx
);
1853 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1856 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1860 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1861 pname
, params
, false);
1865 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1866 GLenum pname
, GLfloat
*params
)
1868 struct gl_texture_object
*texObj
;
1870 GET_CURRENT_CONTEXT(ctx
);
1872 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1873 "glGetTextureLevelParameterfv");
1877 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1880 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1881 pname
, &iparam
, true);
1883 *params
= (GLfloat
) iparam
;
1887 _mesa_GetTextureLevelParameterfvEXT(GLuint texture
, GLenum target
, GLint level
,
1888 GLenum pname
, GLfloat
*params
)
1890 struct gl_texture_object
*texObj
;
1892 GET_CURRENT_CONTEXT(ctx
);
1894 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
1895 "glGetTextureLevelParameterfvEXT");
1899 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1902 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1903 pname
, &iparam
, true);
1905 *params
= (GLfloat
) iparam
;
1909 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1910 GLenum pname
, GLint
*params
)
1912 struct gl_texture_object
*texObj
;
1913 GET_CURRENT_CONTEXT(ctx
);
1915 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1916 "glGetTextureLevelParameteriv");
1920 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1923 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1924 pname
, params
, true);
1928 _mesa_GetTextureLevelParameterivEXT(GLuint texture
, GLenum target
, GLint level
,
1929 GLenum pname
, GLint
*params
)
1931 struct gl_texture_object
*texObj
;
1932 GET_CURRENT_CONTEXT(ctx
);
1934 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
1935 "glGetTextureLevelParameterivEXT");
1939 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1942 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1943 pname
, params
, true);
1948 * This isn't exposed to the rest of the driver because it is a part of the
1949 * OpenGL API that is rarely used.
1952 get_tex_parameterfv(struct gl_context
*ctx
,
1953 struct gl_texture_object
*obj
,
1954 GLenum pname
, GLfloat
*params
, bool dsa
)
1956 _mesa_lock_context_textures(ctx
);
1958 case GL_TEXTURE_MAG_FILTER
:
1959 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1961 case GL_TEXTURE_MIN_FILTER
:
1962 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1964 case GL_TEXTURE_WRAP_S
:
1965 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1967 case GL_TEXTURE_WRAP_T
:
1968 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1970 case GL_TEXTURE_WRAP_R
:
1971 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1973 case GL_TEXTURE_BORDER_COLOR
:
1974 if (ctx
->API
== API_OPENGLES
||
1975 !ctx
->Extensions
.ARB_texture_border_clamp
)
1978 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1979 _mesa_update_state_locked(ctx
);
1980 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
1981 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1982 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1983 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1984 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1987 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1988 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1989 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1990 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1993 case GL_TEXTURE_RESIDENT
:
1994 if (ctx
->API
!= API_OPENGL_COMPAT
)
1999 case GL_TEXTURE_PRIORITY
:
2000 if (ctx
->API
!= API_OPENGL_COMPAT
)
2003 *params
= obj
->Priority
;
2005 case GL_TEXTURE_MIN_LOD
:
2006 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2009 *params
= obj
->Sampler
.MinLod
;
2011 case GL_TEXTURE_MAX_LOD
:
2012 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2015 *params
= obj
->Sampler
.MaxLod
;
2017 case GL_TEXTURE_BASE_LEVEL
:
2018 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2021 *params
= (GLfloat
) obj
->BaseLevel
;
2023 case GL_TEXTURE_MAX_LEVEL
:
2024 *params
= (GLfloat
) obj
->MaxLevel
;
2026 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2027 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2029 *params
= obj
->Sampler
.MaxAnisotropy
;
2031 case GL_GENERATE_MIPMAP_SGIS
:
2032 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2035 *params
= (GLfloat
) obj
->GenerateMipmap
;
2037 case GL_TEXTURE_COMPARE_MODE_ARB
:
2038 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2039 && !_mesa_is_gles3(ctx
))
2041 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
2043 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2044 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2045 && !_mesa_is_gles3(ctx
))
2047 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
2049 case GL_DEPTH_TEXTURE_MODE_ARB
:
2050 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2051 * never existed in OpenGL ES.
2053 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2055 *params
= (GLfloat
) obj
->DepthMode
;
2057 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2058 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
2061 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2063 case GL_TEXTURE_LOD_BIAS
:
2064 if (_mesa_is_gles(ctx
))
2067 *params
= obj
->Sampler
.LodBias
;
2069 case GL_TEXTURE_CROP_RECT_OES
:
2070 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2073 params
[0] = (GLfloat
) obj
->CropRect
[0];
2074 params
[1] = (GLfloat
) obj
->CropRect
[1];
2075 params
[2] = (GLfloat
) obj
->CropRect
[2];
2076 params
[3] = (GLfloat
) obj
->CropRect
[3];
2079 case GL_TEXTURE_SWIZZLE_R_EXT
:
2080 case GL_TEXTURE_SWIZZLE_G_EXT
:
2081 case GL_TEXTURE_SWIZZLE_B_EXT
:
2082 case GL_TEXTURE_SWIZZLE_A_EXT
:
2083 if ((!_mesa_is_desktop_gl(ctx
)
2084 || !ctx
->Extensions
.EXT_texture_swizzle
)
2085 && !_mesa_is_gles3(ctx
))
2087 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2090 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2091 if ((!_mesa_is_desktop_gl(ctx
)
2092 || !ctx
->Extensions
.EXT_texture_swizzle
)
2093 && !_mesa_is_gles3(ctx
)) {
2098 for (comp
= 0; comp
< 4; comp
++) {
2099 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
2104 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2105 if (!_mesa_is_desktop_gl(ctx
)
2106 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2108 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
2111 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2112 *params
= (GLfloat
) obj
->Immutable
;
2115 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2116 if (_mesa_is_gles3(ctx
) || _mesa_has_texture_view(ctx
))
2117 *params
= (GLfloat
) obj
->ImmutableLevels
;
2122 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2123 if (!_mesa_has_texture_view(ctx
))
2125 *params
= (GLfloat
) obj
->MinLevel
;
2128 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2129 if (!_mesa_has_texture_view(ctx
))
2131 *params
= (GLfloat
) obj
->NumLevels
;
2134 case GL_TEXTURE_VIEW_MIN_LAYER
:
2135 if (!_mesa_has_texture_view(ctx
))
2137 *params
= (GLfloat
) obj
->MinLayer
;
2140 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2141 if (!_mesa_has_texture_view(ctx
))
2143 *params
= (GLfloat
) obj
->NumLayers
;
2146 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2147 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2149 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
2152 case GL_TEXTURE_SRGB_DECODE_EXT
:
2153 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2155 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
2158 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2159 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2161 *params
= (GLfloat
) obj
->ImageFormatCompatibilityType
;
2164 case GL_TEXTURE_TARGET
:
2165 if (ctx
->API
!= API_OPENGL_CORE
)
2167 *params
= ENUM_TO_FLOAT(obj
->Target
);
2170 case GL_TEXTURE_TILING_EXT
:
2171 if (!ctx
->Extensions
.EXT_memory_object
)
2173 *params
= ENUM_TO_FLOAT(obj
->TextureTiling
);
2180 /* no error if we get here */
2181 _mesa_unlock_context_textures(ctx
);
2185 _mesa_unlock_context_textures(ctx
);
2186 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
2187 dsa
? "ture" : "", pname
);
2192 get_tex_parameteriv(struct gl_context
*ctx
,
2193 struct gl_texture_object
*obj
,
2194 GLenum pname
, GLint
*params
, bool dsa
)
2196 _mesa_lock_texture(ctx
, obj
);
2198 case GL_TEXTURE_MAG_FILTER
:
2199 *params
= (GLint
) obj
->Sampler
.MagFilter
;
2201 case GL_TEXTURE_MIN_FILTER
:
2202 *params
= (GLint
) obj
->Sampler
.MinFilter
;
2204 case GL_TEXTURE_WRAP_S
:
2205 *params
= (GLint
) obj
->Sampler
.WrapS
;
2207 case GL_TEXTURE_WRAP_T
:
2208 *params
= (GLint
) obj
->Sampler
.WrapT
;
2210 case GL_TEXTURE_WRAP_R
:
2211 *params
= (GLint
) obj
->Sampler
.WrapR
;
2213 case GL_TEXTURE_BORDER_COLOR
:
2214 if (ctx
->API
== API_OPENGLES
||
2215 !ctx
->Extensions
.ARB_texture_border_clamp
)
2220 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
2221 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
2222 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
2223 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
2224 params
[0] = FLOAT_TO_INT(b
[0]);
2225 params
[1] = FLOAT_TO_INT(b
[1]);
2226 params
[2] = FLOAT_TO_INT(b
[2]);
2227 params
[3] = FLOAT_TO_INT(b
[3]);
2230 case GL_TEXTURE_RESIDENT
:
2231 if (ctx
->API
!= API_OPENGL_COMPAT
)
2236 case GL_TEXTURE_PRIORITY
:
2237 if (ctx
->API
!= API_OPENGL_COMPAT
)
2240 *params
= FLOAT_TO_INT(obj
->Priority
);
2242 case GL_TEXTURE_MIN_LOD
:
2243 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2245 /* GL spec 'Data Conversions' section specifies that floating-point
2246 * value in integer Get function is rounded to nearest integer
2248 *params
= IROUND(obj
->Sampler
.MinLod
);
2250 case GL_TEXTURE_MAX_LOD
:
2251 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2253 /* GL spec 'Data Conversions' section specifies that floating-point
2254 * value in integer Get function is rounded to nearest integer
2256 *params
= IROUND(obj
->Sampler
.MaxLod
);
2258 case GL_TEXTURE_BASE_LEVEL
:
2259 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2262 *params
= obj
->BaseLevel
;
2264 case GL_TEXTURE_MAX_LEVEL
:
2265 *params
= obj
->MaxLevel
;
2267 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2268 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2270 /* GL spec 'Data Conversions' section specifies that floating-point
2271 * value in integer Get function is rounded to nearest integer
2273 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
2275 case GL_GENERATE_MIPMAP_SGIS
:
2276 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2279 *params
= (GLint
) obj
->GenerateMipmap
;
2281 case GL_TEXTURE_COMPARE_MODE_ARB
:
2282 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2283 && !_mesa_is_gles3(ctx
))
2285 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2287 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2288 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2289 && !_mesa_is_gles3(ctx
))
2291 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2293 case GL_DEPTH_TEXTURE_MODE_ARB
:
2294 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2296 *params
= (GLint
) obj
->DepthMode
;
2298 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2299 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
2302 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2304 case GL_TEXTURE_LOD_BIAS
:
2305 if (_mesa_is_gles(ctx
))
2308 /* GL spec 'Data Conversions' section specifies that floating-point
2309 * value in integer Get function is rounded to nearest integer
2311 *params
= IROUND(obj
->Sampler
.LodBias
);
2313 case GL_TEXTURE_CROP_RECT_OES
:
2314 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2317 params
[0] = obj
->CropRect
[0];
2318 params
[1] = obj
->CropRect
[1];
2319 params
[2] = obj
->CropRect
[2];
2320 params
[3] = obj
->CropRect
[3];
2322 case GL_TEXTURE_SWIZZLE_R_EXT
:
2323 case GL_TEXTURE_SWIZZLE_G_EXT
:
2324 case GL_TEXTURE_SWIZZLE_B_EXT
:
2325 case GL_TEXTURE_SWIZZLE_A_EXT
:
2326 if ((!_mesa_is_desktop_gl(ctx
)
2327 || !ctx
->Extensions
.EXT_texture_swizzle
)
2328 && !_mesa_is_gles3(ctx
))
2330 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2333 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2334 if ((!_mesa_is_desktop_gl(ctx
)
2335 || !ctx
->Extensions
.EXT_texture_swizzle
)
2336 && !_mesa_is_gles3(ctx
))
2338 COPY_4V(params
, obj
->Swizzle
);
2341 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2342 if (!_mesa_is_desktop_gl(ctx
)
2343 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2345 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2348 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2349 *params
= (GLint
) obj
->Immutable
;
2352 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2353 if (_mesa_is_gles3(ctx
) ||
2354 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2355 *params
= obj
->ImmutableLevels
;
2360 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2361 if (!ctx
->Extensions
.ARB_texture_view
)
2363 *params
= (GLint
) obj
->MinLevel
;
2366 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2367 if (!ctx
->Extensions
.ARB_texture_view
)
2369 *params
= (GLint
) obj
->NumLevels
;
2372 case GL_TEXTURE_VIEW_MIN_LAYER
:
2373 if (!ctx
->Extensions
.ARB_texture_view
)
2375 *params
= (GLint
) obj
->MinLayer
;
2378 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2379 if (!ctx
->Extensions
.ARB_texture_view
)
2381 *params
= (GLint
) obj
->NumLayers
;
2384 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2385 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2387 *params
= obj
->RequiredTextureImageUnits
;
2390 case GL_TEXTURE_SRGB_DECODE_EXT
:
2391 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2393 *params
= obj
->Sampler
.sRGBDecode
;
2396 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2397 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2399 *params
= obj
->ImageFormatCompatibilityType
;
2402 case GL_TEXTURE_TARGET
:
2403 if (ctx
->API
!= API_OPENGL_CORE
)
2405 *params
= (GLint
) obj
->Target
;
2408 case GL_TEXTURE_TILING_EXT
:
2409 if (!ctx
->Extensions
.EXT_memory_object
)
2411 *params
= (GLint
) obj
->TextureTiling
;
2418 /* no error if we get here */
2419 _mesa_unlock_texture(ctx
, obj
);
2423 _mesa_unlock_texture(ctx
, obj
);
2424 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2425 dsa
? "ture" : "", pname
);
2429 get_tex_parameterIiv(struct gl_context
*ctx
,
2430 struct gl_texture_object
*obj
,
2431 GLenum pname
, GLint
*params
, bool dsa
)
2434 case GL_TEXTURE_BORDER_COLOR
:
2435 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2438 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2443 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2445 struct gl_texture_object
*obj
;
2446 GET_CURRENT_CONTEXT(ctx
);
2448 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2452 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2456 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2458 struct gl_texture_object
*obj
;
2459 GET_CURRENT_CONTEXT(ctx
);
2461 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2465 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2468 /** New in GL 3.0 */
2470 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
2472 struct gl_texture_object
*texObj
;
2473 GET_CURRENT_CONTEXT(ctx
);
2475 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2479 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, false);
2483 /** New in GL 3.0 */
2485 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2487 struct gl_texture_object
*texObj
;
2488 GET_CURRENT_CONTEXT(ctx
);
2490 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2494 get_tex_parameterIiv(ctx
, texObj
, pname
, (GLint
*) params
, false);
2498 _mesa_GetTextureParameterfvEXT(GLuint texture
, GLenum target
, GLenum pname
, GLfloat
*params
)
2500 struct gl_texture_object
*texObj
;
2501 GET_CURRENT_CONTEXT(ctx
);
2503 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
2504 "glGetTextureParameterfvEXT");
2508 if (!is_texparameteri_target_valid(texObj
->Target
)) {
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTextureParameterfvEXT");
2513 get_tex_parameterfv(ctx
, texObj
, pname
, params
, true);
2517 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2519 struct gl_texture_object
*obj
;
2520 GET_CURRENT_CONTEXT(ctx
);
2522 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterfv");
2526 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2530 _mesa_GetTextureParameterivEXT(GLuint texture
, GLenum target
, GLenum pname
, GLint
*params
)
2532 struct gl_texture_object
*texObj
;
2533 GET_CURRENT_CONTEXT(ctx
);
2535 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
2536 "glGetTextureParameterivEXT");
2540 if (!is_texparameteri_target_valid(texObj
->Target
)) {
2541 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTextureParameterivEXT");
2544 get_tex_parameteriv(ctx
, texObj
, pname
, params
, true);
2548 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2550 struct gl_texture_object
*obj
;
2551 GET_CURRENT_CONTEXT(ctx
);
2553 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameteriv");
2557 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2561 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2563 struct gl_texture_object
*texObj
;
2564 GET_CURRENT_CONTEXT(ctx
);
2566 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIiv");
2570 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2575 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2577 struct gl_texture_object
*texObj
;
2578 GET_CURRENT_CONTEXT(ctx
);
2580 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIuiv");
2584 get_tex_parameterIiv(ctx
, texObj
, pname
, (GLint
*) params
, true);