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
= is_desktop_gl
&& e
->ARB_texture_border_clamp
76 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
80 case GL_MIRRORED_REPEAT
:
81 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
82 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
85 case GL_MIRROR_CLAMP_EXT
:
86 supported
= is_desktop_gl
87 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
88 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
89 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
92 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
93 supported
= is_desktop_gl
94 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
)
95 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
96 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
99 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
100 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
101 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
102 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
111 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
118 * Get current texture object for given target.
119 * Return NULL if any error (and record the error).
120 * Note that this is different from _mesa_get_current_tex_object() in that
121 * proxy targets are not accepted.
122 * Only the glGetTexLevelParameter() functions accept proxy targets.
124 static struct gl_texture_object
*
125 get_texobj_by_target(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
127 struct gl_texture_unit
*texUnit
;
130 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
131 _mesa_error(ctx
, GL_INVALID_OPERATION
,
132 "gl%sTexParameter(current unit)", get
? "Get" : "");
136 texUnit
= _mesa_get_current_tex_unit(ctx
);
138 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
139 if (targetIndex
< 0 || targetIndex
== TEXTURE_BUFFER_INDEX
) {
140 _mesa_error(ctx
, GL_INVALID_ENUM
,
141 "gl%sTexParameter(target)", get
? "Get" : "");
144 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
146 return texUnit
->CurrentTex
[targetIndex
];
150 * Get current texture object for given name.
151 * Return NULL if any error (and record the error).
152 * Note that proxy targets are not accepted.
153 * Only the glGetTexLevelParameter() functions accept proxy targets.
155 static struct gl_texture_object
*
156 get_texobj_by_name(struct gl_context
*ctx
, GLuint texture
, GLboolean get
)
158 struct gl_texture_object
*texObj
;
160 texObj
= _mesa_lookup_texture(ctx
, texture
);
163 * User passed a non-generated name.
164 * Throw the error in the caller.
169 switch (texObj
->Target
) {
171 case GL_TEXTURE_1D_ARRAY
:
173 case GL_TEXTURE_2D_ARRAY
:
174 case GL_TEXTURE_2D_MULTISAMPLE
:
175 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
177 case GL_TEXTURE_CUBE_MAP
:
178 case GL_TEXTURE_CUBE_MAP_ARRAY
:
179 case GL_TEXTURE_RECTANGLE
:
182 _mesa_error(ctx
, GL_INVALID_ENUM
,
183 "gl%sTextureParameter(target)", get
? "Get" : "");
191 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
192 * \return -1 if error.
195 comp_to_swizzle(GLenum comp
)
217 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
220 assert(swz
<= SWIZZLE_NIL
);
222 GLuint mask
= 0x7 << (3 * comp
);
223 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
230 * This is called just prior to changing any texture object state which
231 * will not affect texture completeness.
234 flush(struct gl_context
*ctx
)
236 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
241 * This is called just prior to changing any texture object state which
242 * could affect texture completeness (texture base level, max level).
243 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
244 * state flag and then mark the texture object as 'incomplete' so that any
245 * per-texture derived state gets recomputed.
248 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
250 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
251 _mesa_dirty_texobj(ctx
, texObj
);
256 target_allows_setting_sampler_parameters(GLenum target
)
259 case GL_TEXTURE_2D_MULTISAMPLE
:
260 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
270 * Set an integer-valued texture parameter
271 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
274 set_tex_parameteri(struct gl_context
*ctx
,
275 struct gl_texture_object
*texObj
,
276 GLenum pname
, const GLint
*params
, bool dsa
)
278 const char *suffix
= dsa
? "ture" : "";
281 case GL_TEXTURE_MIN_FILTER
:
282 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
285 if (texObj
->Sampler
.MinFilter
== params
[0])
291 texObj
->Sampler
.MinFilter
= params
[0];
293 case GL_NEAREST_MIPMAP_NEAREST
:
294 case GL_LINEAR_MIPMAP_NEAREST
:
295 case GL_NEAREST_MIPMAP_LINEAR
:
296 case GL_LINEAR_MIPMAP_LINEAR
:
297 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
298 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
300 texObj
->Sampler
.MinFilter
= params
[0];
309 case GL_TEXTURE_MAG_FILTER
:
310 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
313 if (texObj
->Sampler
.MagFilter
== params
[0])
318 flush(ctx
); /* does not effect completeness */
319 texObj
->Sampler
.MagFilter
= params
[0];
326 case GL_TEXTURE_WRAP_S
:
327 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
330 if (texObj
->Sampler
.WrapS
== params
[0])
332 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
334 texObj
->Sampler
.WrapS
= params
[0];
339 case GL_TEXTURE_WRAP_T
:
340 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
343 if (texObj
->Sampler
.WrapT
== params
[0])
345 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
347 texObj
->Sampler
.WrapT
= params
[0];
352 case GL_TEXTURE_WRAP_R
:
353 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
356 if (texObj
->Sampler
.WrapR
== params
[0])
358 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
360 texObj
->Sampler
.WrapR
= params
[0];
365 case GL_TEXTURE_BASE_LEVEL
:
366 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
369 if (texObj
->BaseLevel
== params
[0])
372 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
373 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
374 goto invalid_operation
;
377 _mesa_error(ctx
, GL_INVALID_VALUE
,
378 "glTex%sParameter(param=%d)", suffix
, params
[0]);
381 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0) {
382 _mesa_error(ctx
, GL_INVALID_OPERATION
,
383 "glTex%sParameter(target=%s, param=%d)", suffix
,
384 _mesa_enum_to_string(texObj
->Target
), params
[0]);
387 incomplete(ctx
, texObj
);
389 /** See note about ARB_texture_storage below */
390 if (texObj
->Immutable
)
391 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
393 texObj
->BaseLevel
= params
[0];
397 case GL_TEXTURE_MAX_LEVEL
:
398 if (texObj
->MaxLevel
== params
[0])
402 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
403 _mesa_error(ctx
, GL_INVALID_VALUE
,
404 "glTex%sParameter(param=%d)", suffix
,
408 incomplete(ctx
, texObj
);
410 /** From ARB_texture_storage:
411 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
412 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
413 * the range [level_base, <levels> - 1], where <levels> is the parameter
414 * passed the call to TexStorage* for the texture object.
416 if (texObj
->Immutable
)
417 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
418 texObj
->ImmutableLevels
- 1);
420 texObj
->MaxLevel
= params
[0];
424 case GL_GENERATE_MIPMAP_SGIS
:
425 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
428 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
430 if (texObj
->GenerateMipmap
!= params
[0]) {
432 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
437 case GL_TEXTURE_COMPARE_MODE_ARB
:
438 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
439 || _mesa_is_gles3(ctx
)) {
441 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
444 if (texObj
->Sampler
.CompareMode
== params
[0])
446 if (params
[0] == GL_NONE
||
447 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
449 texObj
->Sampler
.CompareMode
= params
[0];
456 case GL_TEXTURE_COMPARE_FUNC_ARB
:
457 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
458 || _mesa_is_gles3(ctx
)) {
460 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
463 if (texObj
->Sampler
.CompareFunc
== params
[0])
475 texObj
->Sampler
.CompareFunc
= params
[0];
483 case GL_DEPTH_TEXTURE_MODE_ARB
:
484 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
485 * existed in OpenGL ES.
487 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
488 if (texObj
->DepthMode
== params
[0])
490 if (params
[0] == GL_LUMINANCE
||
491 params
[0] == GL_INTENSITY
||
492 params
[0] == GL_ALPHA
||
493 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
495 texObj
->DepthMode
= params
[0];
502 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
503 if ((_mesa_is_desktop_gl(ctx
) &&
504 ctx
->Extensions
.ARB_stencil_texturing
) ||
505 _mesa_is_gles31(ctx
)) {
506 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
507 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
510 if (texObj
->StencilSampling
== stencil
)
513 texObj
->StencilSampling
= stencil
;
518 case GL_TEXTURE_CROP_RECT_OES
:
519 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
522 texObj
->CropRect
[0] = params
[0];
523 texObj
->CropRect
[1] = params
[1];
524 texObj
->CropRect
[2] = params
[2];
525 texObj
->CropRect
[3] = params
[3];
528 case GL_TEXTURE_SWIZZLE_R_EXT
:
529 case GL_TEXTURE_SWIZZLE_G_EXT
:
530 case GL_TEXTURE_SWIZZLE_B_EXT
:
531 case GL_TEXTURE_SWIZZLE_A_EXT
:
532 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
533 || _mesa_is_gles3(ctx
)) {
534 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
535 const GLint swz
= comp_to_swizzle(params
[0]);
537 _mesa_error(ctx
, GL_INVALID_ENUM
,
538 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
544 texObj
->Swizzle
[comp
] = params
[0];
545 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
550 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
551 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
552 || _mesa_is_gles3(ctx
)) {
555 for (comp
= 0; comp
< 4; comp
++) {
556 const GLint swz
= comp_to_swizzle(params
[comp
]);
558 texObj
->Swizzle
[comp
] = params
[comp
];
559 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
562 _mesa_error(ctx
, GL_INVALID_ENUM
,
563 "glTex%sParameter(swizzle 0x%x)",
564 suffix
, params
[comp
]);
572 case GL_TEXTURE_SRGB_DECODE_EXT
:
573 if (_mesa_is_desktop_gl(ctx
)
574 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
575 GLenum decode
= params
[0];
577 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
580 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
581 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
583 texObj
->Sampler
.sRGBDecode
= decode
;
590 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
591 if (_mesa_is_desktop_gl(ctx
)
592 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
593 GLenum param
= params
[0];
595 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
598 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
601 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
603 texObj
->Sampler
.CubeMapSeamless
= param
;
614 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
615 suffix
, _mesa_enum_to_string(pname
));
619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
620 suffix
, _mesa_enum_to_string(params
[0]));
624 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
625 suffix
, _mesa_enum_to_string(pname
));
629 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
630 suffix
, _mesa_enum_to_string(pname
));
636 * Set a float-valued texture parameter
637 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
640 set_tex_parameterf(struct gl_context
*ctx
,
641 struct gl_texture_object
*texObj
,
642 GLenum pname
, const GLfloat
*params
, bool dsa
)
644 const char *suffix
= dsa
? "ture" : "";
647 case GL_TEXTURE_MIN_LOD
:
648 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
651 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
654 if (texObj
->Sampler
.MinLod
== params
[0])
657 texObj
->Sampler
.MinLod
= params
[0];
660 case GL_TEXTURE_MAX_LOD
:
661 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
664 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
667 if (texObj
->Sampler
.MaxLod
== params
[0])
670 texObj
->Sampler
.MaxLod
= params
[0];
673 case GL_TEXTURE_PRIORITY
:
674 if (ctx
->API
!= API_OPENGL_COMPAT
)
678 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
681 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
682 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
683 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
686 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
688 if (params
[0] < 1.0F
) {
689 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
694 /* clamp to max, that's what NVIDIA does */
695 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
696 ctx
->Const
.MaxTextureMaxAnisotropy
);
700 static GLuint count
= 0;
706 case GL_TEXTURE_LOD_BIAS
:
707 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
708 if (_mesa_is_gles(ctx
))
711 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
714 if (texObj
->Sampler
.LodBias
!= params
[0]) {
716 texObj
->Sampler
.LodBias
= params
[0];
721 case GL_TEXTURE_BORDER_COLOR
:
722 if (!_mesa_is_desktop_gl(ctx
))
725 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
729 /* ARB_texture_float disables clamping */
730 if (ctx
->Extensions
.ARB_texture_float
) {
731 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
732 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
733 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
734 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
736 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
737 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
738 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
739 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
749 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
750 suffix
, _mesa_enum_to_string(pname
));
754 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
755 suffix
, _mesa_enum_to_string(pname
));
761 _mesa_texture_parameterf(struct gl_context
*ctx
,
762 struct gl_texture_object
*texObj
,
763 GLenum pname
, GLfloat param
, bool dsa
)
765 GLboolean need_update
;
768 case GL_TEXTURE_MIN_FILTER
:
769 case GL_TEXTURE_MAG_FILTER
:
770 case GL_TEXTURE_WRAP_S
:
771 case GL_TEXTURE_WRAP_T
:
772 case GL_TEXTURE_WRAP_R
:
773 case GL_TEXTURE_BASE_LEVEL
:
774 case GL_TEXTURE_MAX_LEVEL
:
775 case GL_GENERATE_MIPMAP_SGIS
:
776 case GL_TEXTURE_COMPARE_MODE_ARB
:
777 case GL_TEXTURE_COMPARE_FUNC_ARB
:
778 case GL_DEPTH_TEXTURE_MODE_ARB
:
779 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
780 case GL_TEXTURE_SRGB_DECODE_EXT
:
781 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
782 case GL_TEXTURE_SWIZZLE_R_EXT
:
783 case GL_TEXTURE_SWIZZLE_G_EXT
:
784 case GL_TEXTURE_SWIZZLE_B_EXT
:
785 case GL_TEXTURE_SWIZZLE_A_EXT
:
789 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
790 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
792 p
[1] = p
[2] = p
[3] = 0;
793 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
796 case GL_TEXTURE_BORDER_COLOR
:
797 case GL_TEXTURE_SWIZZLE_RGBA
:
798 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
803 /* this will generate an error if pname is illegal */
806 p
[1] = p
[2] = p
[3] = 0.0F
;
807 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
811 if (ctx
->Driver
.TexParameter
&& need_update
) {
812 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, ¶m
);
818 _mesa_texture_parameterfv(struct gl_context
*ctx
,
819 struct gl_texture_object
*texObj
,
820 GLenum pname
, const GLfloat
*params
, bool dsa
)
822 GLboolean need_update
;
824 case GL_TEXTURE_MIN_FILTER
:
825 case GL_TEXTURE_MAG_FILTER
:
826 case GL_TEXTURE_WRAP_S
:
827 case GL_TEXTURE_WRAP_T
:
828 case GL_TEXTURE_WRAP_R
:
829 case GL_TEXTURE_BASE_LEVEL
:
830 case GL_TEXTURE_MAX_LEVEL
:
831 case GL_GENERATE_MIPMAP_SGIS
:
832 case GL_TEXTURE_COMPARE_MODE_ARB
:
833 case GL_TEXTURE_COMPARE_FUNC_ARB
:
834 case GL_DEPTH_TEXTURE_MODE_ARB
:
835 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
836 case GL_TEXTURE_SRGB_DECODE_EXT
:
837 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
839 /* convert float param to int */
841 p
[0] = (GLint
) params
[0];
842 p
[1] = p
[2] = p
[3] = 0;
843 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
846 case GL_TEXTURE_CROP_RECT_OES
:
848 /* convert float params to int */
850 iparams
[0] = (GLint
) params
[0];
851 iparams
[1] = (GLint
) params
[1];
852 iparams
[2] = (GLint
) params
[2];
853 iparams
[3] = (GLint
) params
[3];
854 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
857 case GL_TEXTURE_SWIZZLE_R_EXT
:
858 case GL_TEXTURE_SWIZZLE_G_EXT
:
859 case GL_TEXTURE_SWIZZLE_B_EXT
:
860 case GL_TEXTURE_SWIZZLE_A_EXT
:
861 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
863 GLint p
[4] = {0, 0, 0, 0};
864 p
[0] = (GLint
) params
[0];
865 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
866 p
[1] = (GLint
) params
[1];
867 p
[2] = (GLint
) params
[2];
868 p
[3] = (GLint
) params
[3];
870 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
874 /* this will generate an error if pname is illegal */
875 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
878 if (ctx
->Driver
.TexParameter
&& need_update
) {
879 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, params
);
885 _mesa_texture_parameteri(struct gl_context
*ctx
,
886 struct gl_texture_object
*texObj
,
887 GLenum pname
, GLint param
, bool dsa
)
889 GLboolean need_update
;
891 case GL_TEXTURE_MIN_LOD
:
892 case GL_TEXTURE_MAX_LOD
:
893 case GL_TEXTURE_PRIORITY
:
894 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
895 case GL_TEXTURE_LOD_BIAS
:
896 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
899 fparam
[0] = (GLfloat
) param
;
900 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
901 /* convert int param to float */
902 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
905 case GL_TEXTURE_BORDER_COLOR
:
906 case GL_TEXTURE_SWIZZLE_RGBA
:
908 _mesa_error(ctx
, GL_INVALID_ENUM
,
909 "glTex%sParameteri(non-scalar pname)",
914 /* this will generate an error if pname is illegal */
918 iparam
[1] = iparam
[2] = iparam
[3] = 0;
919 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
923 if (ctx
->Driver
.TexParameter
&& need_update
) {
924 GLfloat fparam
= (GLfloat
) param
;
925 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, &fparam
);
931 _mesa_texture_parameteriv(struct gl_context
*ctx
,
932 struct gl_texture_object
*texObj
,
933 GLenum pname
, const GLint
*params
, bool dsa
)
935 GLboolean need_update
;
938 case GL_TEXTURE_BORDER_COLOR
:
940 /* convert int params to float */
942 fparams
[0] = INT_TO_FLOAT(params
[0]);
943 fparams
[1] = INT_TO_FLOAT(params
[1]);
944 fparams
[2] = INT_TO_FLOAT(params
[2]);
945 fparams
[3] = INT_TO_FLOAT(params
[3]);
946 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
949 case GL_TEXTURE_MIN_LOD
:
950 case GL_TEXTURE_MAX_LOD
:
951 case GL_TEXTURE_PRIORITY
:
952 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
953 case GL_TEXTURE_LOD_BIAS
:
954 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
956 /* convert int param to float */
958 fparams
[0] = (GLfloat
) params
[0];
959 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
960 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
964 /* this will generate an error if pname is illegal */
965 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
968 if (ctx
->Driver
.TexParameter
&& need_update
) {
970 fparams
[0] = INT_TO_FLOAT(params
[0]);
971 if (pname
== GL_TEXTURE_BORDER_COLOR
||
972 pname
== GL_TEXTURE_CROP_RECT_OES
) {
973 fparams
[1] = INT_TO_FLOAT(params
[1]);
974 fparams
[2] = INT_TO_FLOAT(params
[2]);
975 fparams
[3] = INT_TO_FLOAT(params
[3]);
977 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, fparams
);
982 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
983 struct gl_texture_object
*texObj
,
984 GLenum pname
, const GLint
*params
, bool dsa
)
987 case GL_TEXTURE_BORDER_COLOR
:
988 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
989 /* set the integer-valued border color */
990 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
993 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
996 /* XXX no driver hook for TexParameterIiv() yet */
1000 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
1001 struct gl_texture_object
*texObj
,
1002 GLenum pname
, const GLuint
*params
, bool dsa
)
1005 case GL_TEXTURE_BORDER_COLOR
:
1006 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1007 /* set the unsigned integer-valued border color */
1008 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1011 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1015 /* XXX no driver hook for TexParameterIuiv() yet */
1019 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1021 struct gl_texture_object
*texObj
;
1022 GET_CURRENT_CONTEXT(ctx
);
1024 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1028 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1032 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1034 struct gl_texture_object
*texObj
;
1035 GET_CURRENT_CONTEXT(ctx
);
1037 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1041 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1045 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1047 struct gl_texture_object
*texObj
;
1048 GET_CURRENT_CONTEXT(ctx
);
1050 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1054 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1058 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1060 struct gl_texture_object
*texObj
;
1061 GET_CURRENT_CONTEXT(ctx
);
1063 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1067 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1071 * Set tex parameter to integer value(s). Primarily intended to set
1072 * integer-valued texture border color (for integer-valued textures).
1076 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1078 struct gl_texture_object
*texObj
;
1079 GET_CURRENT_CONTEXT(ctx
);
1081 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1085 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1089 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1090 * uint-valued texture border color (for integer-valued textures).
1094 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1096 struct gl_texture_object
*texObj
;
1097 GET_CURRENT_CONTEXT(ctx
);
1099 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1103 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1108 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1110 struct gl_texture_object
*texObj
;
1111 GET_CURRENT_CONTEXT(ctx
);
1113 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1115 /* User passed a non-generated name. */
1116 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterfv(texture)");
1120 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1124 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1126 struct gl_texture_object
*texObj
;
1127 GET_CURRENT_CONTEXT(ctx
);
1129 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1131 /* User passed a non-generated name. */
1132 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameterf(texture)");
1136 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1140 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1142 struct gl_texture_object
*texObj
;
1143 GET_CURRENT_CONTEXT(ctx
);
1145 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1147 /* User passed a non-generated name. */
1148 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteri(texture)");
1152 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1156 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1157 const GLint
*params
)
1159 struct gl_texture_object
*texObj
;
1160 GET_CURRENT_CONTEXT(ctx
);
1162 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1164 /* User passed a non-generated name. */
1165 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureParameteriv(texture)");
1169 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1174 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1176 struct gl_texture_object
*texObj
;
1177 GET_CURRENT_CONTEXT(ctx
);
1179 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1181 /* User passed a non-generated name. */
1182 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1183 "glTextureParameterIiv(texture)");
1187 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1191 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1193 struct gl_texture_object
*texObj
;
1194 GET_CURRENT_CONTEXT(ctx
);
1196 texObj
= get_texobj_by_name(ctx
, texture
, GL_FALSE
);
1198 /* User passed a non-generated name. */
1199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1200 "glTextureParameterIuiv(texture)");
1204 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1208 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1211 /* Common targets for desktop GL and GLES 3.1. */
1216 case GL_TEXTURE_2D_ARRAY_EXT
:
1217 return ctx
->Extensions
.EXT_texture_array
;
1218 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1219 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1220 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1221 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1222 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1223 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1224 return ctx
->Extensions
.ARB_texture_cube_map
;
1225 case GL_TEXTURE_2D_MULTISAMPLE
:
1226 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1227 return ctx
->Extensions
.ARB_texture_multisample
;
1230 if (!_mesa_is_desktop_gl(ctx
))
1233 /* Rest of the desktop GL targets. */
1236 case GL_PROXY_TEXTURE_1D
:
1237 case GL_PROXY_TEXTURE_2D
:
1238 case GL_PROXY_TEXTURE_3D
:
1240 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1241 return ctx
->Extensions
.ARB_texture_cube_map
;
1242 case GL_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1243 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1244 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1245 case GL_TEXTURE_RECTANGLE_NV
:
1246 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1247 return ctx
->Extensions
.NV_texture_rectangle
;
1248 case GL_TEXTURE_1D_ARRAY_EXT
:
1249 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1250 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1251 return ctx
->Extensions
.EXT_texture_array
;
1252 case GL_TEXTURE_BUFFER
:
1253 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1254 * but not in earlier versions that expose ARB_texture_buffer_object.
1256 * From the ARB_texture_buffer_object spec:
1257 * "(7) Do buffer textures support texture parameters (TexParameter) or
1258 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1260 * RESOLVED: No. [...] Note that the spec edits above don't add
1261 * explicit error language for any of these cases. That is because
1262 * each of the functions enumerate the set of valid <target>
1263 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1264 * these cases means that target is not legal, and an INVALID_ENUM
1265 * error should be generated."
1267 * From the OpenGL 3.1 spec:
1268 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1270 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1271 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1272 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1273 return ctx
->Extensions
.ARB_texture_multisample
;
1275 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1276 * (30.10.2014) Section 8.11 Texture Queries says:
1277 * "For GetTextureLevelParameter* only, texture may also be a cube
1278 * map texture object. In this case the query is always performed
1279 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1280 * is no way to specify another face."
1282 case GL_TEXTURE_CUBE_MAP
:
1291 get_tex_level_parameter_image(struct gl_context
*ctx
,
1292 const struct gl_texture_object
*texObj
,
1293 GLenum target
, GLint level
,
1294 GLenum pname
, GLint
*params
,
1297 const struct gl_texture_image
*img
= NULL
;
1298 struct gl_texture_image dummy_image
;
1299 mesa_format texFormat
;
1300 const char *suffix
= dsa
? "ture" : "";
1302 img
= _mesa_select_tex_image(texObj
, target
, level
);
1303 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1304 /* In case of undefined texture image return the default values.
1306 * From OpenGL 4.0 spec, page 398:
1307 * "The initial internal format of a texel array is RGBA
1308 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1309 * use TEXTURE_INTERNAL_FORMAT."
1311 memset(&dummy_image
, 0, sizeof(dummy_image
));
1312 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1313 dummy_image
.InternalFormat
= GL_RGBA
;
1314 dummy_image
._BaseFormat
= GL_NONE
;
1319 texFormat
= img
->TexFormat
;
1322 case GL_TEXTURE_WIDTH
:
1323 *params
= img
->Width
;
1325 case GL_TEXTURE_HEIGHT
:
1326 *params
= img
->Height
;
1328 case GL_TEXTURE_DEPTH
:
1329 *params
= img
->Depth
;
1331 case GL_TEXTURE_INTERNAL_FORMAT
:
1332 if (_mesa_is_format_compressed(texFormat
)) {
1333 /* need to return the actual compressed format */
1334 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1337 /* If the true internal format is not compressed but the user
1338 * requested a generic compressed format, we have to return the
1339 * generic base format that matches.
1341 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1343 * "If no specific compressed format is available,
1344 * internalformat is instead replaced by the corresponding base
1347 * Otherwise just return the user's requested internal format
1350 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1352 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1355 case GL_TEXTURE_BORDER
:
1356 if (ctx
->API
!= API_OPENGL_COMPAT
)
1358 *params
= img
->Border
;
1360 case GL_TEXTURE_RED_SIZE
:
1361 case GL_TEXTURE_GREEN_SIZE
:
1362 case GL_TEXTURE_BLUE_SIZE
:
1363 case GL_TEXTURE_ALPHA_SIZE
:
1364 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1365 *params
= _mesa_get_format_bits(texFormat
, pname
);
1369 case GL_TEXTURE_INTENSITY_SIZE
:
1370 case GL_TEXTURE_LUMINANCE_SIZE
:
1371 if (ctx
->API
!= API_OPENGL_COMPAT
)
1373 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1374 *params
= _mesa_get_format_bits(texFormat
, pname
);
1376 /* intensity or luminance is probably stored as RGB[A] */
1377 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1378 GL_TEXTURE_RED_SIZE
),
1379 _mesa_get_format_bits(texFormat
,
1380 GL_TEXTURE_GREEN_SIZE
));
1387 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1388 if (!ctx
->Extensions
.ARB_depth_texture
)
1390 *params
= _mesa_get_format_bits(texFormat
, pname
);
1392 case GL_TEXTURE_STENCIL_SIZE
:
1393 *params
= _mesa_get_format_bits(texFormat
, pname
);
1395 case GL_TEXTURE_SHARED_SIZE
:
1396 if (ctx
->Version
< 30 &&
1397 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1399 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1402 /* GL_ARB_texture_compression */
1403 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1404 if (_mesa_is_format_compressed(texFormat
) &&
1405 !_mesa_is_proxy_texture(target
)) {
1406 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1407 img
->Height
, img
->Depth
);
1410 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1411 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1412 _mesa_enum_to_string(pname
));
1415 case GL_TEXTURE_COMPRESSED
:
1416 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1419 /* GL_ARB_texture_float */
1420 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1421 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1422 if (ctx
->API
!= API_OPENGL_COMPAT
)
1425 case GL_TEXTURE_RED_TYPE_ARB
:
1426 case GL_TEXTURE_GREEN_TYPE_ARB
:
1427 case GL_TEXTURE_BLUE_TYPE_ARB
:
1428 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1429 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1430 if (!ctx
->Extensions
.ARB_texture_float
)
1432 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1433 *params
= _mesa_get_format_datatype(texFormat
);
1438 /* GL_ARB_texture_multisample */
1439 case GL_TEXTURE_SAMPLES
:
1440 if (!ctx
->Extensions
.ARB_texture_multisample
)
1442 *params
= img
->NumSamples
;
1445 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1446 if (!ctx
->Extensions
.ARB_texture_multisample
)
1448 *params
= img
->FixedSampleLocations
;
1455 /* no error if we get here */
1459 _mesa_error(ctx
, GL_INVALID_ENUM
,
1460 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1461 _mesa_enum_to_string(pname
));
1466 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1467 const struct gl_texture_object
*texObj
,
1468 GLenum pname
, GLint
*params
, bool dsa
)
1470 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1471 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1472 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1473 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1474 const char *suffix
= dsa
? "ture" : "";
1477 /* undefined texture buffer object */
1478 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1483 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1486 case GL_TEXTURE_WIDTH
:
1489 case GL_TEXTURE_HEIGHT
:
1490 case GL_TEXTURE_DEPTH
:
1491 case GL_TEXTURE_BORDER
:
1492 case GL_TEXTURE_SHARED_SIZE
:
1493 case GL_TEXTURE_COMPRESSED
:
1496 case GL_TEXTURE_INTERNAL_FORMAT
:
1497 *params
= internalFormat
;
1499 case GL_TEXTURE_RED_SIZE
:
1500 case GL_TEXTURE_GREEN_SIZE
:
1501 case GL_TEXTURE_BLUE_SIZE
:
1502 case GL_TEXTURE_ALPHA_SIZE
:
1503 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1504 *params
= _mesa_get_format_bits(texFormat
, pname
);
1508 case GL_TEXTURE_INTENSITY_SIZE
:
1509 case GL_TEXTURE_LUMINANCE_SIZE
:
1510 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1511 *params
= _mesa_get_format_bits(texFormat
, pname
);
1513 /* intensity or luminance is probably stored as RGB[A] */
1514 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1515 GL_TEXTURE_RED_SIZE
),
1516 _mesa_get_format_bits(texFormat
,
1517 GL_TEXTURE_GREEN_SIZE
));
1523 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1524 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1525 *params
= _mesa_get_format_bits(texFormat
, pname
);
1528 /* GL_ARB_texture_buffer_range */
1529 case GL_TEXTURE_BUFFER_OFFSET
:
1530 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1532 *params
= texObj
->BufferOffset
;
1534 case GL_TEXTURE_BUFFER_SIZE
:
1535 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1537 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1540 /* GL_ARB_texture_compression */
1541 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1542 /* Always illegal for GL_TEXTURE_BUFFER */
1543 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1544 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1545 _mesa_enum_to_string(pname
));
1548 /* GL_ARB_texture_float */
1549 case GL_TEXTURE_RED_TYPE_ARB
:
1550 case GL_TEXTURE_GREEN_TYPE_ARB
:
1551 case GL_TEXTURE_BLUE_TYPE_ARB
:
1552 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1553 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1554 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1555 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1556 if (!ctx
->Extensions
.ARB_texture_float
)
1558 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1559 *params
= _mesa_get_format_datatype(texFormat
);
1568 /* no error if we get here */
1572 _mesa_error(ctx
, GL_INVALID_ENUM
,
1573 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1574 _mesa_enum_to_string(pname
));
1578 valid_tex_level_parameteriv_target(struct gl_context
*ctx
, GLenum target
,
1581 const char *suffix
= dsa
? "ture" : "";
1582 if (!legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1583 _mesa_error(ctx
, GL_INVALID_ENUM
,
1584 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1585 _mesa_enum_to_string(target
));
1592 * This isn't exposed to the rest of the driver because it is a part of the
1593 * OpenGL API that is rarely used.
1596 get_tex_level_parameteriv(struct gl_context
*ctx
,
1597 struct gl_texture_object
*texObj
,
1598 GLenum target
, GLint level
,
1599 GLenum pname
, GLint
*params
,
1603 const char *suffix
= dsa
? "ture" : "";
1605 /* Check for errors */
1606 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1607 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1608 "glGetTex%sLevelParameter[if]v("
1609 "current unit >= max combined texture units)", suffix
);
1613 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1614 assert(maxLevels
!= 0);
1616 if (level
< 0 || level
>= maxLevels
) {
1617 _mesa_error(ctx
, GL_INVALID_VALUE
,
1618 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1622 /* Get the level parameter */
1623 if (target
== GL_TEXTURE_BUFFER
) {
1624 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1627 get_tex_level_parameter_image(ctx
, texObj
, target
,
1628 level
, pname
, params
, dsa
);
1633 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1634 GLenum pname
, GLfloat
*params
)
1636 struct gl_texture_object
*texObj
;
1638 GET_CURRENT_CONTEXT(ctx
);
1640 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1643 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1647 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1648 pname
, &iparam
, false);
1650 *params
= (GLfloat
) iparam
;
1654 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1655 GLenum pname
, GLint
*params
)
1657 struct gl_texture_object
*texObj
;
1658 GET_CURRENT_CONTEXT(ctx
);
1660 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1663 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1667 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1668 pname
, params
, false);
1672 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1673 GLenum pname
, GLfloat
*params
)
1675 struct gl_texture_object
*texObj
;
1677 GET_CURRENT_CONTEXT(ctx
);
1679 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1680 "glGetTextureLevelParameterfv");
1684 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1687 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1688 pname
, &iparam
, true);
1690 *params
= (GLfloat
) iparam
;
1694 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1695 GLenum pname
, GLint
*params
)
1697 struct gl_texture_object
*texObj
;
1698 GET_CURRENT_CONTEXT(ctx
);
1700 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1701 "glGetTextureLevelParameteriv");
1705 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1708 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1709 pname
, params
, true);
1713 * This isn't exposed to the rest of the driver because it is a part of the
1714 * OpenGL API that is rarely used.
1717 get_tex_parameterfv(struct gl_context
*ctx
,
1718 struct gl_texture_object
*obj
,
1719 GLenum pname
, GLfloat
*params
, bool dsa
)
1721 _mesa_lock_context_textures(ctx
);
1723 case GL_TEXTURE_MAG_FILTER
:
1724 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1726 case GL_TEXTURE_MIN_FILTER
:
1727 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1729 case GL_TEXTURE_WRAP_S
:
1730 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1732 case GL_TEXTURE_WRAP_T
:
1733 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1735 case GL_TEXTURE_WRAP_R
:
1736 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1738 case GL_TEXTURE_BORDER_COLOR
:
1739 if (!_mesa_is_desktop_gl(ctx
))
1742 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1743 _mesa_update_state_locked(ctx
);
1744 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
1745 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1746 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1747 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1748 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1751 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1752 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1753 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1754 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1757 case GL_TEXTURE_RESIDENT
:
1758 if (ctx
->API
!= API_OPENGL_COMPAT
)
1763 case GL_TEXTURE_PRIORITY
:
1764 if (ctx
->API
!= API_OPENGL_COMPAT
)
1767 *params
= obj
->Priority
;
1769 case GL_TEXTURE_MIN_LOD
:
1770 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1773 *params
= obj
->Sampler
.MinLod
;
1775 case GL_TEXTURE_MAX_LOD
:
1776 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1779 *params
= obj
->Sampler
.MaxLod
;
1781 case GL_TEXTURE_BASE_LEVEL
:
1782 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1785 *params
= (GLfloat
) obj
->BaseLevel
;
1787 case GL_TEXTURE_MAX_LEVEL
:
1788 *params
= (GLfloat
) obj
->MaxLevel
;
1790 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1791 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1793 *params
= obj
->Sampler
.MaxAnisotropy
;
1795 case GL_GENERATE_MIPMAP_SGIS
:
1796 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1799 *params
= (GLfloat
) obj
->GenerateMipmap
;
1801 case GL_TEXTURE_COMPARE_MODE_ARB
:
1802 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1803 && !_mesa_is_gles3(ctx
))
1805 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1807 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1808 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1809 && !_mesa_is_gles3(ctx
))
1811 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1813 case GL_DEPTH_TEXTURE_MODE_ARB
:
1814 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1815 * never existed in OpenGL ES.
1817 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1819 *params
= (GLfloat
) obj
->DepthMode
;
1821 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1822 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
1825 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1827 case GL_TEXTURE_LOD_BIAS
:
1828 if (_mesa_is_gles(ctx
))
1831 *params
= obj
->Sampler
.LodBias
;
1833 case GL_TEXTURE_CROP_RECT_OES
:
1834 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1837 params
[0] = (GLfloat
) obj
->CropRect
[0];
1838 params
[1] = (GLfloat
) obj
->CropRect
[1];
1839 params
[2] = (GLfloat
) obj
->CropRect
[2];
1840 params
[3] = (GLfloat
) obj
->CropRect
[3];
1843 case GL_TEXTURE_SWIZZLE_R_EXT
:
1844 case GL_TEXTURE_SWIZZLE_G_EXT
:
1845 case GL_TEXTURE_SWIZZLE_B_EXT
:
1846 case GL_TEXTURE_SWIZZLE_A_EXT
:
1847 if ((!_mesa_is_desktop_gl(ctx
)
1848 || !ctx
->Extensions
.EXT_texture_swizzle
)
1849 && !_mesa_is_gles3(ctx
))
1851 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1854 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1855 if ((!_mesa_is_desktop_gl(ctx
)
1856 || !ctx
->Extensions
.EXT_texture_swizzle
)
1857 && !_mesa_is_gles3(ctx
)) {
1862 for (comp
= 0; comp
< 4; comp
++) {
1863 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1868 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1869 if (!_mesa_is_desktop_gl(ctx
)
1870 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1872 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1875 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1876 *params
= (GLfloat
) obj
->Immutable
;
1879 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1880 if (_mesa_is_gles3(ctx
) ||
1881 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1882 *params
= (GLfloat
) obj
->ImmutableLevels
;
1887 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1888 if (!ctx
->Extensions
.ARB_texture_view
)
1890 *params
= (GLfloat
) obj
->MinLevel
;
1893 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1894 if (!ctx
->Extensions
.ARB_texture_view
)
1896 *params
= (GLfloat
) obj
->NumLevels
;
1899 case GL_TEXTURE_VIEW_MIN_LAYER
:
1900 if (!ctx
->Extensions
.ARB_texture_view
)
1902 *params
= (GLfloat
) obj
->MinLayer
;
1905 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1906 if (!ctx
->Extensions
.ARB_texture_view
)
1908 *params
= (GLfloat
) obj
->NumLayers
;
1911 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1912 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1914 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1917 case GL_TEXTURE_SRGB_DECODE_EXT
:
1918 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1920 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1923 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1924 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1926 *params
= (GLfloat
) obj
->ImageFormatCompatibilityType
;
1929 case GL_TEXTURE_TARGET
:
1930 if (ctx
->API
!= API_OPENGL_CORE
)
1932 *params
= ENUM_TO_FLOAT(obj
->Target
);
1939 /* no error if we get here */
1940 _mesa_unlock_context_textures(ctx
);
1944 _mesa_unlock_context_textures(ctx
);
1945 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
1946 dsa
? "ture" : "", pname
);
1951 get_tex_parameteriv(struct gl_context
*ctx
,
1952 struct gl_texture_object
*obj
,
1953 GLenum pname
, GLint
*params
, bool dsa
)
1955 _mesa_lock_texture(ctx
, obj
);
1957 case GL_TEXTURE_MAG_FILTER
:
1958 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1960 case GL_TEXTURE_MIN_FILTER
:
1961 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1963 case GL_TEXTURE_WRAP_S
:
1964 *params
= (GLint
) obj
->Sampler
.WrapS
;
1966 case GL_TEXTURE_WRAP_T
:
1967 *params
= (GLint
) obj
->Sampler
.WrapT
;
1969 case GL_TEXTURE_WRAP_R
:
1970 *params
= (GLint
) obj
->Sampler
.WrapR
;
1972 case GL_TEXTURE_BORDER_COLOR
:
1973 if (!_mesa_is_desktop_gl(ctx
))
1978 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1979 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1980 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1981 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1982 params
[0] = FLOAT_TO_INT(b
[0]);
1983 params
[1] = FLOAT_TO_INT(b
[1]);
1984 params
[2] = FLOAT_TO_INT(b
[2]);
1985 params
[3] = FLOAT_TO_INT(b
[3]);
1988 case GL_TEXTURE_RESIDENT
:
1989 if (ctx
->API
!= API_OPENGL_COMPAT
)
1994 case GL_TEXTURE_PRIORITY
:
1995 if (ctx
->API
!= API_OPENGL_COMPAT
)
1998 *params
= FLOAT_TO_INT(obj
->Priority
);
2000 case GL_TEXTURE_MIN_LOD
:
2001 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2003 /* GL spec 'Data Conversions' section specifies that floating-point
2004 * value in integer Get function is rounded to nearest integer
2006 *params
= IROUND(obj
->Sampler
.MinLod
);
2008 case GL_TEXTURE_MAX_LOD
:
2009 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2011 /* GL spec 'Data Conversions' section specifies that floating-point
2012 * value in integer Get function is rounded to nearest integer
2014 *params
= IROUND(obj
->Sampler
.MaxLod
);
2016 case GL_TEXTURE_BASE_LEVEL
:
2017 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2020 *params
= obj
->BaseLevel
;
2022 case GL_TEXTURE_MAX_LEVEL
:
2023 *params
= obj
->MaxLevel
;
2025 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2026 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2028 /* GL spec 'Data Conversions' section specifies that floating-point
2029 * value in integer Get function is rounded to nearest integer
2031 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
2033 case GL_GENERATE_MIPMAP_SGIS
:
2034 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2037 *params
= (GLint
) obj
->GenerateMipmap
;
2039 case GL_TEXTURE_COMPARE_MODE_ARB
:
2040 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2041 && !_mesa_is_gles3(ctx
))
2043 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2045 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2046 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2047 && !_mesa_is_gles3(ctx
))
2049 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2051 case GL_DEPTH_TEXTURE_MODE_ARB
:
2052 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2054 *params
= (GLint
) obj
->DepthMode
;
2056 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2057 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
2060 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2062 case GL_TEXTURE_LOD_BIAS
:
2063 if (_mesa_is_gles(ctx
))
2066 /* GL spec 'Data Conversions' section specifies that floating-point
2067 * value in integer Get function is rounded to nearest integer
2069 *params
= IROUND(obj
->Sampler
.LodBias
);
2071 case GL_TEXTURE_CROP_RECT_OES
:
2072 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2075 params
[0] = obj
->CropRect
[0];
2076 params
[1] = obj
->CropRect
[1];
2077 params
[2] = obj
->CropRect
[2];
2078 params
[3] = obj
->CropRect
[3];
2080 case GL_TEXTURE_SWIZZLE_R_EXT
:
2081 case GL_TEXTURE_SWIZZLE_G_EXT
:
2082 case GL_TEXTURE_SWIZZLE_B_EXT
:
2083 case GL_TEXTURE_SWIZZLE_A_EXT
:
2084 if ((!_mesa_is_desktop_gl(ctx
)
2085 || !ctx
->Extensions
.EXT_texture_swizzle
)
2086 && !_mesa_is_gles3(ctx
))
2088 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2091 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2092 if ((!_mesa_is_desktop_gl(ctx
)
2093 || !ctx
->Extensions
.EXT_texture_swizzle
)
2094 && !_mesa_is_gles3(ctx
))
2096 COPY_4V(params
, obj
->Swizzle
);
2099 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2100 if (!_mesa_is_desktop_gl(ctx
)
2101 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2103 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2106 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2107 *params
= (GLint
) obj
->Immutable
;
2110 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2111 if (_mesa_is_gles3(ctx
) ||
2112 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2113 *params
= obj
->ImmutableLevels
;
2118 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2119 if (!ctx
->Extensions
.ARB_texture_view
)
2121 *params
= (GLint
) obj
->MinLevel
;
2124 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2125 if (!ctx
->Extensions
.ARB_texture_view
)
2127 *params
= (GLint
) obj
->NumLevels
;
2130 case GL_TEXTURE_VIEW_MIN_LAYER
:
2131 if (!ctx
->Extensions
.ARB_texture_view
)
2133 *params
= (GLint
) obj
->MinLayer
;
2136 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2137 if (!ctx
->Extensions
.ARB_texture_view
)
2139 *params
= (GLint
) obj
->NumLayers
;
2142 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2143 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2145 *params
= obj
->RequiredTextureImageUnits
;
2148 case GL_TEXTURE_SRGB_DECODE_EXT
:
2149 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2151 *params
= obj
->Sampler
.sRGBDecode
;
2154 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2155 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2157 *params
= obj
->ImageFormatCompatibilityType
;
2160 case GL_TEXTURE_TARGET
:
2161 if (ctx
->API
!= API_OPENGL_CORE
)
2163 *params
= (GLint
) obj
->Target
;
2170 /* no error if we get here */
2171 _mesa_unlock_texture(ctx
, obj
);
2175 _mesa_unlock_texture(ctx
, obj
);
2176 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2177 dsa
? "ture" : "", pname
);
2181 get_tex_parameterIiv(struct gl_context
*ctx
,
2182 struct gl_texture_object
*obj
,
2183 GLenum pname
, GLint
*params
, bool dsa
)
2186 case GL_TEXTURE_BORDER_COLOR
:
2187 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2190 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2195 get_tex_parameterIuiv(struct gl_context
*ctx
,
2196 struct gl_texture_object
*obj
,
2197 GLenum pname
, GLuint
*params
, bool dsa
)
2200 case GL_TEXTURE_BORDER_COLOR
:
2201 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2206 get_tex_parameteriv(ctx
, obj
, pname
, ip
, dsa
);
2208 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
2209 pname
== GL_TEXTURE_CROP_RECT_OES
) {
2219 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2221 struct gl_texture_object
*obj
;
2222 GET_CURRENT_CONTEXT(ctx
);
2224 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2228 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2232 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2234 struct gl_texture_object
*obj
;
2235 GET_CURRENT_CONTEXT(ctx
);
2237 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2241 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2244 /** New in GL 3.0 */
2246 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
2248 struct gl_texture_object
*texObj
;
2249 GET_CURRENT_CONTEXT(ctx
);
2251 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2255 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, false);
2259 /** New in GL 3.0 */
2261 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2263 struct gl_texture_object
*texObj
;
2264 GET_CURRENT_CONTEXT(ctx
);
2266 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2270 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, false);
2275 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2277 struct gl_texture_object
*obj
;
2278 GET_CURRENT_CONTEXT(ctx
);
2280 obj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2282 /* User passed a non-generated name. */
2283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2284 "glGetTextureParameterfv(texture)");
2288 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2292 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2294 struct gl_texture_object
*obj
;
2295 GET_CURRENT_CONTEXT(ctx
);
2297 obj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2299 /* User passed a non-generated name. */
2300 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2301 "glGetTextureParameteriv(texture)");
2305 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2309 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2311 struct gl_texture_object
*texObj
;
2312 GET_CURRENT_CONTEXT(ctx
);
2314 texObj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2316 /* User passed a non-generated name. */
2317 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2318 "glGetTextureParameterIiv(texture)");
2322 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2327 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2329 struct gl_texture_object
*texObj
;
2330 GET_CURRENT_CONTEXT(ctx
);
2332 texObj
= get_texobj_by_name(ctx
, texture
, GL_TRUE
);
2334 /* User passed a non-generated name. */
2335 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2336 "glGetTextureParameterIuiv(texture)");
2340 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, true);