2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * glTexParameter-related functions
33 #include "main/glheader.h"
34 #include "main/blend.h"
35 #include "main/context.h"
36 #include "main/enums.h"
37 #include "main/formats.h"
38 #include "main/glformats.h"
39 #include "main/macros.h"
40 #include "main/mtypes.h"
41 #include "main/state.h"
42 #include "main/texcompress.h"
43 #include "main/texobj.h"
44 #include "main/texparam.h"
45 #include "main/teximage.h"
46 #include "main/texstate.h"
47 #include "program/prog_instruction.h"
51 * Check if a coordinate wrap mode is supported for the texture target.
52 * \return GL_TRUE if legal, GL_FALSE otherwise
55 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
57 const struct gl_extensions
* const e
= & ctx
->Extensions
;
58 const bool is_desktop_gl
= _mesa_is_desktop_gl(ctx
);
63 /* GL_CLAMP was removed in the core profile, and it has never existed in
66 supported
= (ctx
->API
== API_OPENGL_COMPAT
)
67 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
70 case GL_CLAMP_TO_EDGE
:
74 case GL_CLAMP_TO_BORDER
:
75 supported
= ctx
->API
!= API_OPENGLES
&& e
->ARB_texture_border_clamp
76 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
80 case GL_MIRRORED_REPEAT
:
81 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
82 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
85 case GL_MIRROR_CLAMP_EXT
:
86 supported
= is_desktop_gl
87 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
88 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
89 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
92 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
93 supported
= is_desktop_gl
94 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
)
95 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
96 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
99 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
100 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
101 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
102 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
111 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
118 * Get current texture object for given target.
119 * Return NULL if any error (and record the error).
120 * Note that this is different from _mesa_get_current_tex_object() in that
121 * proxy targets are not accepted.
122 * Only the glGetTexLevelParameter() functions accept proxy targets.
124 static struct gl_texture_object
*
125 get_texobj_by_target(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
127 struct gl_texture_unit
*texUnit
;
130 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
131 _mesa_error(ctx
, GL_INVALID_OPERATION
,
132 "gl%sTexParameter(current unit)", get
? "Get" : "");
136 texUnit
= _mesa_get_current_tex_unit(ctx
);
138 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
139 if (targetIndex
< 0 || targetIndex
== TEXTURE_BUFFER_INDEX
) {
140 _mesa_error(ctx
, GL_INVALID_ENUM
,
141 "gl%sTexParameter(target)", get
? "Get" : "");
144 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
146 return texUnit
->CurrentTex
[targetIndex
];
150 * Get current texture object for given name.
151 * Return NULL if any error (and record the error).
152 * Note that proxy targets are not accepted.
153 * Only the glGetTexLevelParameter() functions accept proxy targets.
155 static struct gl_texture_object
*
156 get_texobj_by_name(struct gl_context
*ctx
, GLuint texture
, const char *name
)
158 struct gl_texture_object
*texObj
;
160 texObj
= _mesa_lookup_texture(ctx
, texture
);
162 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture)", name
);
166 switch (texObj
->Target
) {
168 case GL_TEXTURE_1D_ARRAY
:
170 case GL_TEXTURE_2D_ARRAY
:
171 case GL_TEXTURE_2D_MULTISAMPLE
:
172 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
174 case GL_TEXTURE_CUBE_MAP
:
175 case GL_TEXTURE_CUBE_MAP_ARRAY
:
176 case GL_TEXTURE_RECTANGLE
:
179 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
187 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
188 * \return -1 if error.
191 comp_to_swizzle(GLenum comp
)
213 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
216 assert(swz
<= SWIZZLE_NIL
);
218 GLuint mask
= 0x7 << (3 * comp
);
219 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
226 * This is called just prior to changing any texture object state which
227 * will not affect texture completeness.
230 flush(struct gl_context
*ctx
)
232 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
237 * This is called just prior to changing any texture object state which
238 * could affect texture completeness (texture base level, max level).
239 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE_OBJECT
240 * state flag and then mark the texture object as 'incomplete' so that any
241 * per-texture derived state gets recomputed.
244 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
246 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
247 _mesa_dirty_texobj(ctx
, texObj
);
252 _mesa_target_allows_setting_sampler_parameters(GLenum target
)
255 case GL_TEXTURE_2D_MULTISAMPLE
:
256 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
266 * Set an integer-valued texture parameter
267 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
270 set_tex_parameteri(struct gl_context
*ctx
,
271 struct gl_texture_object
*texObj
,
272 GLenum pname
, const GLint
*params
, bool dsa
)
274 const char *suffix
= dsa
? "ture" : "";
277 case GL_TEXTURE_MIN_FILTER
:
278 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
281 if (texObj
->Sampler
.MinFilter
== params
[0])
287 texObj
->Sampler
.MinFilter
= params
[0];
289 case GL_NEAREST_MIPMAP_NEAREST
:
290 case GL_LINEAR_MIPMAP_NEAREST
:
291 case GL_NEAREST_MIPMAP_LINEAR
:
292 case GL_LINEAR_MIPMAP_LINEAR
:
293 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
294 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
296 texObj
->Sampler
.MinFilter
= params
[0];
305 case GL_TEXTURE_MAG_FILTER
:
306 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
309 if (texObj
->Sampler
.MagFilter
== params
[0])
314 flush(ctx
); /* does not effect completeness */
315 texObj
->Sampler
.MagFilter
= params
[0];
322 case GL_TEXTURE_WRAP_S
:
323 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
326 if (texObj
->Sampler
.WrapS
== params
[0])
328 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
330 texObj
->Sampler
.WrapS
= params
[0];
335 case GL_TEXTURE_WRAP_T
:
336 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
339 if (texObj
->Sampler
.WrapT
== params
[0])
341 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
343 texObj
->Sampler
.WrapT
= params
[0];
348 case GL_TEXTURE_WRAP_R
:
349 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
352 if (texObj
->Sampler
.WrapR
== params
[0])
354 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
356 texObj
->Sampler
.WrapR
= params
[0];
361 case GL_TEXTURE_BASE_LEVEL
:
362 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
365 if (texObj
->BaseLevel
== params
[0])
368 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
369 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
370 goto invalid_operation
;
373 _mesa_error(ctx
, GL_INVALID_VALUE
,
374 "glTex%sParameter(param=%d)", suffix
, params
[0]);
377 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0) {
378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
379 "glTex%sParameter(target=%s, param=%d)", suffix
,
380 _mesa_enum_to_string(texObj
->Target
), params
[0]);
383 incomplete(ctx
, texObj
);
385 /** See note about ARB_texture_storage below */
386 if (texObj
->Immutable
)
387 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
389 texObj
->BaseLevel
= params
[0];
393 case GL_TEXTURE_MAX_LEVEL
:
394 if (texObj
->MaxLevel
== params
[0])
398 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
399 _mesa_error(ctx
, GL_INVALID_VALUE
,
400 "glTex%sParameter(param=%d)", suffix
,
404 incomplete(ctx
, texObj
);
406 /** From ARB_texture_storage:
407 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
408 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
409 * the range [level_base, <levels> - 1], where <levels> is the parameter
410 * passed the call to TexStorage* for the texture object.
412 if (texObj
->Immutable
)
413 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
414 texObj
->ImmutableLevels
- 1);
416 texObj
->MaxLevel
= params
[0];
420 case GL_GENERATE_MIPMAP_SGIS
:
421 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
424 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
426 if (texObj
->GenerateMipmap
!= params
[0]) {
428 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
433 case GL_TEXTURE_COMPARE_MODE_ARB
:
434 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
435 || _mesa_is_gles3(ctx
)) {
437 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
440 if (texObj
->Sampler
.CompareMode
== params
[0])
442 if (params
[0] == GL_NONE
||
443 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
445 texObj
->Sampler
.CompareMode
= params
[0];
452 case GL_TEXTURE_COMPARE_FUNC_ARB
:
453 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
454 || _mesa_is_gles3(ctx
)) {
456 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
459 if (texObj
->Sampler
.CompareFunc
== params
[0])
471 texObj
->Sampler
.CompareFunc
= params
[0];
479 case GL_DEPTH_TEXTURE_MODE_ARB
:
480 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
481 * existed in OpenGL ES.
483 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
484 if (texObj
->DepthMode
== params
[0])
486 if (params
[0] == GL_LUMINANCE
||
487 params
[0] == GL_INTENSITY
||
488 params
[0] == GL_ALPHA
||
489 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
491 texObj
->DepthMode
= params
[0];
498 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
499 if (_mesa_has_ARB_stencil_texturing(ctx
) || _mesa_is_gles31(ctx
)) {
500 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
501 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
504 if (texObj
->StencilSampling
== stencil
)
507 texObj
->StencilSampling
= stencil
;
512 case GL_TEXTURE_CROP_RECT_OES
:
513 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
516 texObj
->CropRect
[0] = params
[0];
517 texObj
->CropRect
[1] = params
[1];
518 texObj
->CropRect
[2] = params
[2];
519 texObj
->CropRect
[3] = params
[3];
522 case GL_TEXTURE_SWIZZLE_R_EXT
:
523 case GL_TEXTURE_SWIZZLE_G_EXT
:
524 case GL_TEXTURE_SWIZZLE_B_EXT
:
525 case GL_TEXTURE_SWIZZLE_A_EXT
:
526 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
527 || _mesa_is_gles3(ctx
)) {
528 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
529 const GLint swz
= comp_to_swizzle(params
[0]);
531 _mesa_error(ctx
, GL_INVALID_ENUM
,
532 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
538 texObj
->Swizzle
[comp
] = params
[0];
539 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
544 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
545 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
546 || _mesa_is_gles3(ctx
)) {
549 for (comp
= 0; comp
< 4; comp
++) {
550 const GLint swz
= comp_to_swizzle(params
[comp
]);
552 texObj
->Swizzle
[comp
] = params
[comp
];
553 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
556 _mesa_error(ctx
, GL_INVALID_ENUM
,
557 "glTex%sParameter(swizzle 0x%x)",
558 suffix
, params
[comp
]);
566 case GL_TEXTURE_SRGB_DECODE_EXT
:
567 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
568 GLenum decode
= params
[0];
570 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
573 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
574 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
576 texObj
->Sampler
.sRGBDecode
= decode
;
583 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
584 if (_mesa_is_desktop_gl(ctx
)
585 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
586 GLenum param
= params
[0];
588 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
591 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
594 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
596 texObj
->Sampler
.CubeMapSeamless
= param
;
607 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
608 suffix
, _mesa_enum_to_string(pname
));
612 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
613 suffix
, _mesa_enum_to_string(params
[0]));
617 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
618 suffix
, _mesa_enum_to_string(pname
));
622 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
623 suffix
, _mesa_enum_to_string(pname
));
629 * Set a float-valued texture parameter
630 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
633 set_tex_parameterf(struct gl_context
*ctx
,
634 struct gl_texture_object
*texObj
,
635 GLenum pname
, const GLfloat
*params
, bool dsa
)
637 const char *suffix
= dsa
? "ture" : "";
640 case GL_TEXTURE_MIN_LOD
:
641 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
644 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
647 if (texObj
->Sampler
.MinLod
== params
[0])
650 texObj
->Sampler
.MinLod
= params
[0];
653 case GL_TEXTURE_MAX_LOD
:
654 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
657 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
660 if (texObj
->Sampler
.MaxLod
== params
[0])
663 texObj
->Sampler
.MaxLod
= params
[0];
666 case GL_TEXTURE_PRIORITY
:
667 if (ctx
->API
!= API_OPENGL_COMPAT
)
671 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
674 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
675 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
676 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
679 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
681 if (params
[0] < 1.0F
) {
682 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
687 /* clamp to max, that's what NVIDIA does */
688 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
689 ctx
->Const
.MaxTextureMaxAnisotropy
);
693 static GLuint count
= 0;
699 case GL_TEXTURE_LOD_BIAS
:
700 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
701 if (_mesa_is_gles(ctx
))
704 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
707 if (texObj
->Sampler
.LodBias
!= params
[0]) {
709 texObj
->Sampler
.LodBias
= params
[0];
714 case GL_TEXTURE_BORDER_COLOR
:
715 if (ctx
->API
== API_OPENGLES
||
716 !ctx
->Extensions
.ARB_texture_border_clamp
)
719 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
))
723 /* ARB_texture_float disables clamping */
724 if (ctx
->Extensions
.ARB_texture_float
) {
725 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
726 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
727 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
728 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
730 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
731 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
732 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
733 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
743 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
744 suffix
, _mesa_enum_to_string(pname
));
748 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
749 suffix
, _mesa_enum_to_string(pname
));
755 _mesa_texture_parameterf(struct gl_context
*ctx
,
756 struct gl_texture_object
*texObj
,
757 GLenum pname
, GLfloat param
, bool dsa
)
759 GLboolean need_update
;
762 case GL_TEXTURE_MIN_FILTER
:
763 case GL_TEXTURE_MAG_FILTER
:
764 case GL_TEXTURE_WRAP_S
:
765 case GL_TEXTURE_WRAP_T
:
766 case GL_TEXTURE_WRAP_R
:
767 case GL_TEXTURE_BASE_LEVEL
:
768 case GL_TEXTURE_MAX_LEVEL
:
769 case GL_GENERATE_MIPMAP_SGIS
:
770 case GL_TEXTURE_COMPARE_MODE_ARB
:
771 case GL_TEXTURE_COMPARE_FUNC_ARB
:
772 case GL_DEPTH_TEXTURE_MODE_ARB
:
773 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
774 case GL_TEXTURE_SRGB_DECODE_EXT
:
775 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
776 case GL_TEXTURE_SWIZZLE_R_EXT
:
777 case GL_TEXTURE_SWIZZLE_G_EXT
:
778 case GL_TEXTURE_SWIZZLE_B_EXT
:
779 case GL_TEXTURE_SWIZZLE_A_EXT
:
783 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
784 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
786 p
[1] = p
[2] = p
[3] = 0;
787 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
790 case GL_TEXTURE_BORDER_COLOR
:
791 case GL_TEXTURE_SWIZZLE_RGBA
:
792 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameterf(non-scalar pname)",
797 /* this will generate an error if pname is illegal */
800 p
[1] = p
[2] = p
[3] = 0.0F
;
801 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, dsa
);
805 if (ctx
->Driver
.TexParameter
&& need_update
) {
806 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
812 _mesa_texture_parameterfv(struct gl_context
*ctx
,
813 struct gl_texture_object
*texObj
,
814 GLenum pname
, const GLfloat
*params
, bool dsa
)
816 GLboolean need_update
;
818 case GL_TEXTURE_MIN_FILTER
:
819 case GL_TEXTURE_MAG_FILTER
:
820 case GL_TEXTURE_WRAP_S
:
821 case GL_TEXTURE_WRAP_T
:
822 case GL_TEXTURE_WRAP_R
:
823 case GL_TEXTURE_BASE_LEVEL
:
824 case GL_TEXTURE_MAX_LEVEL
:
825 case GL_GENERATE_MIPMAP_SGIS
:
826 case GL_TEXTURE_COMPARE_MODE_ARB
:
827 case GL_TEXTURE_COMPARE_FUNC_ARB
:
828 case GL_DEPTH_TEXTURE_MODE_ARB
:
829 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
830 case GL_TEXTURE_SRGB_DECODE_EXT
:
831 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
833 /* convert float param to int */
835 p
[0] = (GLint
) params
[0];
836 p
[1] = p
[2] = p
[3] = 0;
837 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
840 case GL_TEXTURE_CROP_RECT_OES
:
842 /* convert float params to int */
844 iparams
[0] = (GLint
) params
[0];
845 iparams
[1] = (GLint
) params
[1];
846 iparams
[2] = (GLint
) params
[2];
847 iparams
[3] = (GLint
) params
[3];
848 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, dsa
);
851 case GL_TEXTURE_SWIZZLE_R_EXT
:
852 case GL_TEXTURE_SWIZZLE_G_EXT
:
853 case GL_TEXTURE_SWIZZLE_B_EXT
:
854 case GL_TEXTURE_SWIZZLE_A_EXT
:
855 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
857 GLint p
[4] = {0, 0, 0, 0};
858 p
[0] = (GLint
) params
[0];
859 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
860 p
[1] = (GLint
) params
[1];
861 p
[2] = (GLint
) params
[2];
862 p
[3] = (GLint
) params
[3];
864 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, dsa
);
868 /* this will generate an error if pname is illegal */
869 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, dsa
);
872 if (ctx
->Driver
.TexParameter
&& need_update
) {
873 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
879 _mesa_texture_parameteri(struct gl_context
*ctx
,
880 struct gl_texture_object
*texObj
,
881 GLenum pname
, GLint param
, bool dsa
)
883 GLboolean need_update
;
885 case GL_TEXTURE_MIN_LOD
:
886 case GL_TEXTURE_MAX_LOD
:
887 case GL_TEXTURE_PRIORITY
:
888 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
889 case GL_TEXTURE_LOD_BIAS
:
890 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
893 fparam
[0] = (GLfloat
) param
;
894 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
895 /* convert int param to float */
896 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, dsa
);
899 case GL_TEXTURE_BORDER_COLOR
:
900 case GL_TEXTURE_SWIZZLE_RGBA
:
902 _mesa_error(ctx
, GL_INVALID_ENUM
,
903 "glTex%sParameteri(non-scalar pname)",
908 /* this will generate an error if pname is illegal */
912 iparam
[1] = iparam
[2] = iparam
[3] = 0;
913 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
, dsa
);
917 if (ctx
->Driver
.TexParameter
&& need_update
) {
918 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
924 _mesa_texture_parameteriv(struct gl_context
*ctx
,
925 struct gl_texture_object
*texObj
,
926 GLenum pname
, const GLint
*params
, bool dsa
)
928 GLboolean need_update
;
931 case GL_TEXTURE_BORDER_COLOR
:
933 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
934 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameteriv(texture)");
937 /* convert int params to float */
939 fparams
[0] = INT_TO_FLOAT(params
[0]);
940 fparams
[1] = INT_TO_FLOAT(params
[1]);
941 fparams
[2] = INT_TO_FLOAT(params
[2]);
942 fparams
[3] = INT_TO_FLOAT(params
[3]);
943 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
946 case GL_TEXTURE_MIN_LOD
:
947 case GL_TEXTURE_MAX_LOD
:
948 case GL_TEXTURE_PRIORITY
:
949 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
950 case GL_TEXTURE_LOD_BIAS
:
951 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
953 /* convert int param to float */
955 fparams
[0] = (GLfloat
) params
[0];
956 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
957 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, dsa
);
961 /* this will generate an error if pname is illegal */
962 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, dsa
);
965 if (ctx
->Driver
.TexParameter
&& need_update
) {
966 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
);
971 _mesa_texture_parameterIiv(struct gl_context
*ctx
,
972 struct gl_texture_object
*texObj
,
973 GLenum pname
, const GLint
*params
, bool dsa
)
976 case GL_TEXTURE_BORDER_COLOR
:
977 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
978 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIiv(texture)");
981 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
982 /* set the integer-valued border color */
983 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
986 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, dsa
);
989 /* XXX no driver hook for TexParameterIiv() yet */
993 _mesa_texture_parameterIuiv(struct gl_context
*ctx
,
994 struct gl_texture_object
*texObj
,
995 GLenum pname
, const GLuint
*params
, bool dsa
)
998 case GL_TEXTURE_BORDER_COLOR
:
999 if (!_mesa_target_allows_setting_sampler_parameters(texObj
->Target
)) {
1000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureParameterIuiv(texture)");
1003 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1004 /* set the unsigned integer-valued border color */
1005 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1008 _mesa_texture_parameteriv(ctx
, texObj
, pname
, (const GLint
*) params
,
1012 /* XXX no driver hook for TexParameterIuiv() yet */
1016 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
1018 struct gl_texture_object
*texObj
;
1019 GET_CURRENT_CONTEXT(ctx
);
1021 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1025 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, false);
1029 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
1031 struct gl_texture_object
*texObj
;
1032 GET_CURRENT_CONTEXT(ctx
);
1034 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1038 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, false);
1042 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
1044 struct gl_texture_object
*texObj
;
1045 GET_CURRENT_CONTEXT(ctx
);
1047 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1051 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, false);
1055 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
1057 struct gl_texture_object
*texObj
;
1058 GET_CURRENT_CONTEXT(ctx
);
1060 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1064 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, false);
1068 * Set tex parameter to integer value(s). Primarily intended to set
1069 * integer-valued texture border color (for integer-valued textures).
1073 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
1075 struct gl_texture_object
*texObj
;
1076 GET_CURRENT_CONTEXT(ctx
);
1078 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1082 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, false);
1086 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1087 * uint-valued texture border color (for integer-valued textures).
1091 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1093 struct gl_texture_object
*texObj
;
1094 GET_CURRENT_CONTEXT(ctx
);
1096 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1100 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, false);
1105 _mesa_TextureParameterfv(GLuint texture
, GLenum pname
, const GLfloat
*params
)
1107 struct gl_texture_object
*texObj
;
1108 GET_CURRENT_CONTEXT(ctx
);
1110 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterfv");
1114 _mesa_texture_parameterfv(ctx
, texObj
, pname
, params
, true);
1118 _mesa_TextureParameterf(GLuint texture
, GLenum pname
, GLfloat param
)
1120 struct gl_texture_object
*texObj
;
1121 GET_CURRENT_CONTEXT(ctx
);
1123 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterf");
1127 _mesa_texture_parameterf(ctx
, texObj
, pname
, param
, true);
1131 _mesa_TextureParameteri(GLuint texture
, GLenum pname
, GLint param
)
1133 struct gl_texture_object
*texObj
;
1134 GET_CURRENT_CONTEXT(ctx
);
1136 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteri");
1140 _mesa_texture_parameteri(ctx
, texObj
, pname
, param
, true);
1144 _mesa_TextureParameteriv(GLuint texture
, GLenum pname
,
1145 const GLint
*params
)
1147 struct gl_texture_object
*texObj
;
1148 GET_CURRENT_CONTEXT(ctx
);
1150 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameteriv");
1154 _mesa_texture_parameteriv(ctx
, texObj
, pname
, params
, true);
1159 _mesa_TextureParameterIiv(GLuint texture
, GLenum pname
, const GLint
*params
)
1161 struct gl_texture_object
*texObj
;
1162 GET_CURRENT_CONTEXT(ctx
);
1164 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIiv");
1168 _mesa_texture_parameterIiv(ctx
, texObj
, pname
, params
, true);
1172 _mesa_TextureParameterIuiv(GLuint texture
, GLenum pname
, const GLuint
*params
)
1174 struct gl_texture_object
*texObj
;
1175 GET_CURRENT_CONTEXT(ctx
);
1177 texObj
= get_texobj_by_name(ctx
, texture
, "glTextureParameterIuiv");
1181 _mesa_texture_parameterIuiv(ctx
, texObj
, pname
, params
, true);
1185 _mesa_legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
,
1188 /* Common targets for desktop GL and GLES 3.1. */
1193 case GL_TEXTURE_2D_ARRAY_EXT
:
1194 return ctx
->Extensions
.EXT_texture_array
;
1195 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1196 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1197 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1198 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1199 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1200 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1201 return ctx
->Extensions
.ARB_texture_cube_map
;
1202 case GL_TEXTURE_2D_MULTISAMPLE
:
1203 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1204 return ctx
->Extensions
.ARB_texture_multisample
;
1205 case GL_TEXTURE_BUFFER
:
1206 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1207 * but not in earlier versions that expose ARB_texture_buffer_object.
1209 * From the ARB_texture_buffer_object spec:
1210 * "(7) Do buffer textures support texture parameters (TexParameter) or
1211 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1213 * RESOLVED: No. [...] Note that the spec edits above don't add
1214 * explicit error language for any of these cases. That is because
1215 * each of the functions enumerate the set of valid <target>
1216 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1217 * these cases means that target is not legal, and an INVALID_ENUM
1218 * error should be generated."
1220 * From the OpenGL 3.1 spec:
1221 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1223 return (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31) ||
1224 _mesa_has_OES_texture_buffer(ctx
);
1225 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1226 return _mesa_has_texture_cube_map_array(ctx
);
1229 if (!_mesa_is_desktop_gl(ctx
))
1232 /* Rest of the desktop GL targets. */
1235 case GL_PROXY_TEXTURE_1D
:
1236 case GL_PROXY_TEXTURE_2D
:
1237 case GL_PROXY_TEXTURE_3D
:
1239 case GL_PROXY_TEXTURE_CUBE_MAP
:
1240 return ctx
->Extensions
.ARB_texture_cube_map
;
1241 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1242 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1243 case GL_TEXTURE_RECTANGLE_NV
:
1244 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1245 return ctx
->Extensions
.NV_texture_rectangle
;
1246 case GL_TEXTURE_1D_ARRAY_EXT
:
1247 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1248 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1249 return ctx
->Extensions
.EXT_texture_array
;
1250 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1251 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1252 return ctx
->Extensions
.ARB_texture_multisample
;
1254 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1255 * (30.10.2014) Section 8.11 Texture Queries says:
1256 * "For GetTextureLevelParameter* only, texture may also be a cube
1257 * map texture object. In this case the query is always performed
1258 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1259 * is no way to specify another face."
1261 case GL_TEXTURE_CUBE_MAP
:
1270 get_tex_level_parameter_image(struct gl_context
*ctx
,
1271 const struct gl_texture_object
*texObj
,
1272 GLenum target
, GLint level
,
1273 GLenum pname
, GLint
*params
,
1276 const struct gl_texture_image
*img
= NULL
;
1277 struct gl_texture_image dummy_image
;
1278 mesa_format texFormat
;
1279 const char *suffix
= dsa
? "ture" : "";
1281 img
= _mesa_select_tex_image(texObj
, target
, level
);
1282 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1283 /* In case of undefined texture image return the default values.
1285 * From OpenGL 4.0 spec, page 398:
1286 * "The initial internal format of a texel array is RGBA
1287 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1288 * use TEXTURE_INTERNAL_FORMAT."
1290 memset(&dummy_image
, 0, sizeof(dummy_image
));
1291 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1292 dummy_image
.InternalFormat
= GL_RGBA
;
1293 dummy_image
._BaseFormat
= GL_NONE
;
1294 dummy_image
.FixedSampleLocations
= GL_TRUE
;
1299 texFormat
= img
->TexFormat
;
1302 case GL_TEXTURE_WIDTH
:
1303 *params
= img
->Width
;
1305 case GL_TEXTURE_HEIGHT
:
1306 *params
= img
->Height
;
1308 case GL_TEXTURE_DEPTH
:
1309 *params
= img
->Depth
;
1311 case GL_TEXTURE_INTERNAL_FORMAT
:
1312 if (_mesa_is_format_compressed(texFormat
)) {
1313 /* need to return the actual compressed format */
1314 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1317 /* If the true internal format is not compressed but the user
1318 * requested a generic compressed format, we have to return the
1319 * generic base format that matches.
1321 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1323 * "If no specific compressed format is available,
1324 * internalformat is instead replaced by the corresponding base
1327 * Otherwise just return the user's requested internal format
1330 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1332 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1335 case GL_TEXTURE_BORDER
:
1336 if (ctx
->API
!= API_OPENGL_COMPAT
)
1338 *params
= img
->Border
;
1340 case GL_TEXTURE_RED_SIZE
:
1341 case GL_TEXTURE_GREEN_SIZE
:
1342 case GL_TEXTURE_BLUE_SIZE
:
1343 case GL_TEXTURE_ALPHA_SIZE
:
1344 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1345 *params
= _mesa_get_format_bits(texFormat
, pname
);
1349 case GL_TEXTURE_INTENSITY_SIZE
:
1350 case GL_TEXTURE_LUMINANCE_SIZE
:
1351 if (ctx
->API
!= API_OPENGL_COMPAT
)
1353 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1354 *params
= _mesa_get_format_bits(texFormat
, pname
);
1356 /* intensity or luminance is probably stored as RGB[A] */
1357 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1358 GL_TEXTURE_RED_SIZE
),
1359 _mesa_get_format_bits(texFormat
,
1360 GL_TEXTURE_GREEN_SIZE
));
1367 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1368 if (!ctx
->Extensions
.ARB_depth_texture
)
1370 *params
= _mesa_get_format_bits(texFormat
, pname
);
1372 case GL_TEXTURE_STENCIL_SIZE
:
1373 *params
= _mesa_get_format_bits(texFormat
, pname
);
1375 case GL_TEXTURE_SHARED_SIZE
:
1376 if (ctx
->Version
< 30 &&
1377 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1379 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1382 /* GL_ARB_texture_compression */
1383 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1384 if (_mesa_is_format_compressed(texFormat
) &&
1385 !_mesa_is_proxy_texture(target
)) {
1386 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1387 img
->Height
, img
->Depth
);
1389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1390 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1391 _mesa_enum_to_string(pname
));
1394 case GL_TEXTURE_COMPRESSED
:
1395 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1398 /* GL_ARB_texture_float */
1399 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1400 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1401 if (ctx
->API
!= API_OPENGL_COMPAT
)
1404 case GL_TEXTURE_RED_TYPE_ARB
:
1405 case GL_TEXTURE_GREEN_TYPE_ARB
:
1406 case GL_TEXTURE_BLUE_TYPE_ARB
:
1407 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1408 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1409 if (!ctx
->Extensions
.ARB_texture_float
)
1411 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1412 *params
= _mesa_get_format_datatype(texFormat
);
1417 /* GL_ARB_texture_multisample */
1418 case GL_TEXTURE_SAMPLES
:
1419 if (!ctx
->Extensions
.ARB_texture_multisample
)
1421 *params
= img
->NumSamples
;
1424 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1425 if (!ctx
->Extensions
.ARB_texture_multisample
)
1427 *params
= img
->FixedSampleLocations
;
1430 /* There is never a buffer data store here, but these pnames still have
1434 /* GL_ARB_texture_buffer_object */
1435 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1436 if (!ctx
->Extensions
.ARB_texture_buffer_object
)
1441 /* GL_ARB_texture_buffer_range */
1442 case GL_TEXTURE_BUFFER_OFFSET
:
1443 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1447 case GL_TEXTURE_BUFFER_SIZE
:
1448 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1457 /* no error if we get here */
1461 _mesa_error(ctx
, GL_INVALID_ENUM
,
1462 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1463 _mesa_enum_to_string(pname
));
1468 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1471 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1472 const struct gl_texture_object
*texObj
,
1473 GLenum pname
, GLint
*params
, bool dsa
)
1475 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1476 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1477 int bytes
= MAX2(1, _mesa_get_format_bytes(texFormat
));
1478 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1479 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1480 const char *suffix
= dsa
? "ture" : "";
1482 assert(texObj
->Target
== GL_TEXTURE_BUFFER
);
1485 /* undefined texture buffer object */
1487 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1490 case GL_TEXTURE_INTERNAL_FORMAT
:
1491 *params
= internalFormat
;
1501 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1504 case GL_TEXTURE_WIDTH
:
1505 *params
= ((texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
)
1508 case GL_TEXTURE_HEIGHT
:
1509 case GL_TEXTURE_DEPTH
:
1512 case GL_TEXTURE_BORDER
:
1513 case GL_TEXTURE_SHARED_SIZE
:
1514 case GL_TEXTURE_COMPRESSED
:
1517 case GL_TEXTURE_INTERNAL_FORMAT
:
1518 *params
= internalFormat
;
1520 case GL_TEXTURE_RED_SIZE
:
1521 case GL_TEXTURE_GREEN_SIZE
:
1522 case GL_TEXTURE_BLUE_SIZE
:
1523 case GL_TEXTURE_ALPHA_SIZE
:
1524 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1525 *params
= _mesa_get_format_bits(texFormat
, pname
);
1529 case GL_TEXTURE_INTENSITY_SIZE
:
1530 case GL_TEXTURE_LUMINANCE_SIZE
:
1531 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1532 *params
= _mesa_get_format_bits(texFormat
, pname
);
1534 /* intensity or luminance is probably stored as RGB[A] */
1535 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1536 GL_TEXTURE_RED_SIZE
),
1537 _mesa_get_format_bits(texFormat
,
1538 GL_TEXTURE_GREEN_SIZE
));
1544 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1545 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1546 *params
= _mesa_get_format_bits(texFormat
, pname
);
1549 /* GL_ARB_texture_buffer_range */
1550 case GL_TEXTURE_BUFFER_OFFSET
:
1551 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1553 *params
= texObj
->BufferOffset
;
1555 case GL_TEXTURE_BUFFER_SIZE
:
1556 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1558 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1561 /* GL_ARB_texture_multisample */
1562 case GL_TEXTURE_SAMPLES
:
1563 if (!ctx
->Extensions
.ARB_texture_multisample
)
1568 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1569 if (!ctx
->Extensions
.ARB_texture_multisample
)
1574 /* GL_ARB_texture_compression */
1575 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1576 /* Always illegal for GL_TEXTURE_BUFFER */
1577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1578 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1579 _mesa_enum_to_string(pname
));
1582 /* GL_ARB_texture_float */
1583 case GL_TEXTURE_RED_TYPE_ARB
:
1584 case GL_TEXTURE_GREEN_TYPE_ARB
:
1585 case GL_TEXTURE_BLUE_TYPE_ARB
:
1586 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1587 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1588 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1589 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1590 if (!ctx
->Extensions
.ARB_texture_float
)
1592 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1593 *params
= _mesa_get_format_datatype(texFormat
);
1602 /* no error if we get here */
1606 _mesa_error(ctx
, GL_INVALID_ENUM
,
1607 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix
,
1608 _mesa_enum_to_string(pname
));
1612 valid_tex_level_parameteriv_target(struct gl_context
*ctx
, GLenum target
,
1615 const char *suffix
= dsa
? "ture" : "";
1616 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, dsa
)) {
1617 _mesa_error(ctx
, GL_INVALID_ENUM
,
1618 "glGetTex%sLevelParameter[if]v(target=%s)", suffix
,
1619 _mesa_enum_to_string(target
));
1626 * This isn't exposed to the rest of the driver because it is a part of the
1627 * OpenGL API that is rarely used.
1630 get_tex_level_parameteriv(struct gl_context
*ctx
,
1631 struct gl_texture_object
*texObj
,
1632 GLenum target
, GLint level
,
1633 GLenum pname
, GLint
*params
,
1637 const char *suffix
= dsa
? "ture" : "";
1639 /* Check for errors */
1640 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1641 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1642 "glGetTex%sLevelParameter[if]v("
1643 "current unit >= max combined texture units)", suffix
);
1647 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1648 assert(maxLevels
!= 0);
1650 if (level
< 0 || level
>= maxLevels
) {
1651 _mesa_error(ctx
, GL_INVALID_VALUE
,
1652 "glGetTex%sLevelParameter[if]v(level out of range)", suffix
);
1656 /* Get the level parameter */
1657 if (target
== GL_TEXTURE_BUFFER
) {
1658 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
, dsa
);
1661 get_tex_level_parameter_image(ctx
, texObj
, target
,
1662 level
, pname
, params
, dsa
);
1667 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1668 GLenum pname
, GLfloat
*params
)
1670 struct gl_texture_object
*texObj
;
1672 GET_CURRENT_CONTEXT(ctx
);
1674 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1677 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1681 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1682 pname
, &iparam
, false);
1684 *params
= (GLfloat
) iparam
;
1688 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1689 GLenum pname
, GLint
*params
)
1691 struct gl_texture_object
*texObj
;
1692 GET_CURRENT_CONTEXT(ctx
);
1694 if (!valid_tex_level_parameteriv_target(ctx
, target
, false))
1697 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1701 get_tex_level_parameteriv(ctx
, texObj
, target
, level
,
1702 pname
, params
, false);
1706 _mesa_GetTextureLevelParameterfv(GLuint texture
, GLint level
,
1707 GLenum pname
, GLfloat
*params
)
1709 struct gl_texture_object
*texObj
;
1711 GET_CURRENT_CONTEXT(ctx
);
1713 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1714 "glGetTextureLevelParameterfv");
1718 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1721 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1722 pname
, &iparam
, true);
1724 *params
= (GLfloat
) iparam
;
1728 _mesa_GetTextureLevelParameteriv(GLuint texture
, GLint level
,
1729 GLenum pname
, GLint
*params
)
1731 struct gl_texture_object
*texObj
;
1732 GET_CURRENT_CONTEXT(ctx
);
1734 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
1735 "glGetTextureLevelParameteriv");
1739 if (!valid_tex_level_parameteriv_target(ctx
, texObj
->Target
, true))
1742 get_tex_level_parameteriv(ctx
, texObj
, texObj
->Target
, level
,
1743 pname
, params
, true);
1747 * This isn't exposed to the rest of the driver because it is a part of the
1748 * OpenGL API that is rarely used.
1751 get_tex_parameterfv(struct gl_context
*ctx
,
1752 struct gl_texture_object
*obj
,
1753 GLenum pname
, GLfloat
*params
, bool dsa
)
1755 _mesa_lock_context_textures(ctx
);
1757 case GL_TEXTURE_MAG_FILTER
:
1758 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1760 case GL_TEXTURE_MIN_FILTER
:
1761 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1763 case GL_TEXTURE_WRAP_S
:
1764 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1766 case GL_TEXTURE_WRAP_T
:
1767 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1769 case GL_TEXTURE_WRAP_R
:
1770 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1772 case GL_TEXTURE_BORDER_COLOR
:
1773 if (ctx
->API
== API_OPENGLES
||
1774 !ctx
->Extensions
.ARB_texture_border_clamp
)
1777 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1778 _mesa_update_state_locked(ctx
);
1779 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
1780 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1781 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1782 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1783 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1786 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1787 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1788 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1789 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1792 case GL_TEXTURE_RESIDENT
:
1793 if (ctx
->API
!= API_OPENGL_COMPAT
)
1798 case GL_TEXTURE_PRIORITY
:
1799 if (ctx
->API
!= API_OPENGL_COMPAT
)
1802 *params
= obj
->Priority
;
1804 case GL_TEXTURE_MIN_LOD
:
1805 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1808 *params
= obj
->Sampler
.MinLod
;
1810 case GL_TEXTURE_MAX_LOD
:
1811 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1814 *params
= obj
->Sampler
.MaxLod
;
1816 case GL_TEXTURE_BASE_LEVEL
:
1817 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1820 *params
= (GLfloat
) obj
->BaseLevel
;
1822 case GL_TEXTURE_MAX_LEVEL
:
1823 *params
= (GLfloat
) obj
->MaxLevel
;
1825 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1826 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1828 *params
= obj
->Sampler
.MaxAnisotropy
;
1830 case GL_GENERATE_MIPMAP_SGIS
:
1831 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1834 *params
= (GLfloat
) obj
->GenerateMipmap
;
1836 case GL_TEXTURE_COMPARE_MODE_ARB
:
1837 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1838 && !_mesa_is_gles3(ctx
))
1840 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1842 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1843 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1844 && !_mesa_is_gles3(ctx
))
1846 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1848 case GL_DEPTH_TEXTURE_MODE_ARB
:
1849 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1850 * never existed in OpenGL ES.
1852 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1854 *params
= (GLfloat
) obj
->DepthMode
;
1856 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1857 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
1860 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1862 case GL_TEXTURE_LOD_BIAS
:
1863 if (_mesa_is_gles(ctx
))
1866 *params
= obj
->Sampler
.LodBias
;
1868 case GL_TEXTURE_CROP_RECT_OES
:
1869 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1872 params
[0] = (GLfloat
) obj
->CropRect
[0];
1873 params
[1] = (GLfloat
) obj
->CropRect
[1];
1874 params
[2] = (GLfloat
) obj
->CropRect
[2];
1875 params
[3] = (GLfloat
) obj
->CropRect
[3];
1878 case GL_TEXTURE_SWIZZLE_R_EXT
:
1879 case GL_TEXTURE_SWIZZLE_G_EXT
:
1880 case GL_TEXTURE_SWIZZLE_B_EXT
:
1881 case GL_TEXTURE_SWIZZLE_A_EXT
:
1882 if ((!_mesa_is_desktop_gl(ctx
)
1883 || !ctx
->Extensions
.EXT_texture_swizzle
)
1884 && !_mesa_is_gles3(ctx
))
1886 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1889 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1890 if ((!_mesa_is_desktop_gl(ctx
)
1891 || !ctx
->Extensions
.EXT_texture_swizzle
)
1892 && !_mesa_is_gles3(ctx
)) {
1897 for (comp
= 0; comp
< 4; comp
++) {
1898 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1903 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1904 if (!_mesa_is_desktop_gl(ctx
)
1905 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1907 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1910 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1911 *params
= (GLfloat
) obj
->Immutable
;
1914 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1915 if (_mesa_is_gles3(ctx
) ||
1916 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1917 *params
= (GLfloat
) obj
->ImmutableLevels
;
1922 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1923 if (!ctx
->Extensions
.ARB_texture_view
)
1925 *params
= (GLfloat
) obj
->MinLevel
;
1928 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1929 if (!ctx
->Extensions
.ARB_texture_view
)
1931 *params
= (GLfloat
) obj
->NumLevels
;
1934 case GL_TEXTURE_VIEW_MIN_LAYER
:
1935 if (!ctx
->Extensions
.ARB_texture_view
)
1937 *params
= (GLfloat
) obj
->MinLayer
;
1940 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1941 if (!ctx
->Extensions
.ARB_texture_view
)
1943 *params
= (GLfloat
) obj
->NumLayers
;
1946 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1947 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1949 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1952 case GL_TEXTURE_SRGB_DECODE_EXT
:
1953 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1955 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1958 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1959 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1961 *params
= (GLfloat
) obj
->ImageFormatCompatibilityType
;
1964 case GL_TEXTURE_TARGET
:
1965 if (ctx
->API
!= API_OPENGL_CORE
)
1967 *params
= ENUM_TO_FLOAT(obj
->Target
);
1974 /* no error if we get here */
1975 _mesa_unlock_context_textures(ctx
);
1979 _mesa_unlock_context_textures(ctx
);
1980 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameterfv(pname=0x%x)",
1981 dsa
? "ture" : "", pname
);
1986 get_tex_parameteriv(struct gl_context
*ctx
,
1987 struct gl_texture_object
*obj
,
1988 GLenum pname
, GLint
*params
, bool dsa
)
1990 _mesa_lock_texture(ctx
, obj
);
1992 case GL_TEXTURE_MAG_FILTER
:
1993 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1995 case GL_TEXTURE_MIN_FILTER
:
1996 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1998 case GL_TEXTURE_WRAP_S
:
1999 *params
= (GLint
) obj
->Sampler
.WrapS
;
2001 case GL_TEXTURE_WRAP_T
:
2002 *params
= (GLint
) obj
->Sampler
.WrapT
;
2004 case GL_TEXTURE_WRAP_R
:
2005 *params
= (GLint
) obj
->Sampler
.WrapR
;
2007 case GL_TEXTURE_BORDER_COLOR
:
2008 if (ctx
->API
== API_OPENGLES
||
2009 !ctx
->Extensions
.ARB_texture_border_clamp
)
2014 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
2015 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
2016 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
2017 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
2018 params
[0] = FLOAT_TO_INT(b
[0]);
2019 params
[1] = FLOAT_TO_INT(b
[1]);
2020 params
[2] = FLOAT_TO_INT(b
[2]);
2021 params
[3] = FLOAT_TO_INT(b
[3]);
2024 case GL_TEXTURE_RESIDENT
:
2025 if (ctx
->API
!= API_OPENGL_COMPAT
)
2030 case GL_TEXTURE_PRIORITY
:
2031 if (ctx
->API
!= API_OPENGL_COMPAT
)
2034 *params
= FLOAT_TO_INT(obj
->Priority
);
2036 case GL_TEXTURE_MIN_LOD
:
2037 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2039 /* GL spec 'Data Conversions' section specifies that floating-point
2040 * value in integer Get function is rounded to nearest integer
2042 *params
= IROUND(obj
->Sampler
.MinLod
);
2044 case GL_TEXTURE_MAX_LOD
:
2045 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2047 /* GL spec 'Data Conversions' section specifies that floating-point
2048 * value in integer Get function is rounded to nearest integer
2050 *params
= IROUND(obj
->Sampler
.MaxLod
);
2052 case GL_TEXTURE_BASE_LEVEL
:
2053 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
2056 *params
= obj
->BaseLevel
;
2058 case GL_TEXTURE_MAX_LEVEL
:
2059 *params
= obj
->MaxLevel
;
2061 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2062 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
2064 /* GL spec 'Data Conversions' section specifies that floating-point
2065 * value in integer Get function is rounded to nearest integer
2067 *params
= IROUND(obj
->Sampler
.MaxAnisotropy
);
2069 case GL_GENERATE_MIPMAP_SGIS
:
2070 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
2073 *params
= (GLint
) obj
->GenerateMipmap
;
2075 case GL_TEXTURE_COMPARE_MODE_ARB
:
2076 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2077 && !_mesa_is_gles3(ctx
))
2079 *params
= (GLint
) obj
->Sampler
.CompareMode
;
2081 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2082 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
2083 && !_mesa_is_gles3(ctx
))
2085 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
2087 case GL_DEPTH_TEXTURE_MODE_ARB
:
2088 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
2090 *params
= (GLint
) obj
->DepthMode
;
2092 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
2093 if (!_mesa_has_ARB_stencil_texturing(ctx
) && !_mesa_is_gles31(ctx
))
2096 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
2098 case GL_TEXTURE_LOD_BIAS
:
2099 if (_mesa_is_gles(ctx
))
2102 /* GL spec 'Data Conversions' section specifies that floating-point
2103 * value in integer Get function is rounded to nearest integer
2105 *params
= IROUND(obj
->Sampler
.LodBias
);
2107 case GL_TEXTURE_CROP_RECT_OES
:
2108 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
2111 params
[0] = obj
->CropRect
[0];
2112 params
[1] = obj
->CropRect
[1];
2113 params
[2] = obj
->CropRect
[2];
2114 params
[3] = obj
->CropRect
[3];
2116 case GL_TEXTURE_SWIZZLE_R_EXT
:
2117 case GL_TEXTURE_SWIZZLE_G_EXT
:
2118 case GL_TEXTURE_SWIZZLE_B_EXT
:
2119 case GL_TEXTURE_SWIZZLE_A_EXT
:
2120 if ((!_mesa_is_desktop_gl(ctx
)
2121 || !ctx
->Extensions
.EXT_texture_swizzle
)
2122 && !_mesa_is_gles3(ctx
))
2124 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
2127 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
2128 if ((!_mesa_is_desktop_gl(ctx
)
2129 || !ctx
->Extensions
.EXT_texture_swizzle
)
2130 && !_mesa_is_gles3(ctx
))
2132 COPY_4V(params
, obj
->Swizzle
);
2135 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
2136 if (!_mesa_is_desktop_gl(ctx
)
2137 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
2139 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
2142 case GL_TEXTURE_IMMUTABLE_FORMAT
:
2143 *params
= (GLint
) obj
->Immutable
;
2146 case GL_TEXTURE_IMMUTABLE_LEVELS
:
2147 if (_mesa_is_gles3(ctx
) ||
2148 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
2149 *params
= obj
->ImmutableLevels
;
2154 case GL_TEXTURE_VIEW_MIN_LEVEL
:
2155 if (!ctx
->Extensions
.ARB_texture_view
)
2157 *params
= (GLint
) obj
->MinLevel
;
2160 case GL_TEXTURE_VIEW_NUM_LEVELS
:
2161 if (!ctx
->Extensions
.ARB_texture_view
)
2163 *params
= (GLint
) obj
->NumLevels
;
2166 case GL_TEXTURE_VIEW_MIN_LAYER
:
2167 if (!ctx
->Extensions
.ARB_texture_view
)
2169 *params
= (GLint
) obj
->MinLayer
;
2172 case GL_TEXTURE_VIEW_NUM_LAYERS
:
2173 if (!ctx
->Extensions
.ARB_texture_view
)
2175 *params
= (GLint
) obj
->NumLayers
;
2178 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
2179 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
2181 *params
= obj
->RequiredTextureImageUnits
;
2184 case GL_TEXTURE_SRGB_DECODE_EXT
:
2185 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
2187 *params
= obj
->Sampler
.sRGBDecode
;
2190 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
2191 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2193 *params
= obj
->ImageFormatCompatibilityType
;
2196 case GL_TEXTURE_TARGET
:
2197 if (ctx
->API
!= API_OPENGL_CORE
)
2199 *params
= (GLint
) obj
->Target
;
2206 /* no error if we get here */
2207 _mesa_unlock_texture(ctx
, obj
);
2211 _mesa_unlock_texture(ctx
, obj
);
2212 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTex%sParameteriv(pname=0x%x)",
2213 dsa
? "ture" : "", pname
);
2217 get_tex_parameterIiv(struct gl_context
*ctx
,
2218 struct gl_texture_object
*obj
,
2219 GLenum pname
, GLint
*params
, bool dsa
)
2222 case GL_TEXTURE_BORDER_COLOR
:
2223 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2226 get_tex_parameteriv(ctx
, obj
, pname
, params
, dsa
);
2231 get_tex_parameterIuiv(struct gl_context
*ctx
,
2232 struct gl_texture_object
*obj
,
2233 GLenum pname
, GLuint
*params
, bool dsa
)
2236 case GL_TEXTURE_BORDER_COLOR
:
2237 COPY_4V(params
, obj
->Sampler
.BorderColor
.i
);
2242 get_tex_parameteriv(ctx
, obj
, pname
, ip
, dsa
);
2244 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
2245 pname
== GL_TEXTURE_CROP_RECT_OES
) {
2255 _mesa_GetTexParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
2257 struct gl_texture_object
*obj
;
2258 GET_CURRENT_CONTEXT(ctx
);
2260 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2264 get_tex_parameterfv(ctx
, obj
, pname
, params
, false);
2268 _mesa_GetTexParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2270 struct gl_texture_object
*obj
;
2271 GET_CURRENT_CONTEXT(ctx
);
2273 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2277 get_tex_parameteriv(ctx
, obj
, pname
, params
, false);
2280 /** New in GL 3.0 */
2282 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
2284 struct gl_texture_object
*texObj
;
2285 GET_CURRENT_CONTEXT(ctx
);
2287 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2291 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, false);
2295 /** New in GL 3.0 */
2297 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
2299 struct gl_texture_object
*texObj
;
2300 GET_CURRENT_CONTEXT(ctx
);
2302 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
2306 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, false);
2311 _mesa_GetTextureParameterfv(GLuint texture
, GLenum pname
, GLfloat
*params
)
2313 struct gl_texture_object
*obj
;
2314 GET_CURRENT_CONTEXT(ctx
);
2316 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterfv");
2320 get_tex_parameterfv(ctx
, obj
, pname
, params
, true);
2324 _mesa_GetTextureParameteriv(GLuint texture
, GLenum pname
, GLint
*params
)
2326 struct gl_texture_object
*obj
;
2327 GET_CURRENT_CONTEXT(ctx
);
2329 obj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameteriv");
2333 get_tex_parameteriv(ctx
, obj
, pname
, params
, true);
2337 _mesa_GetTextureParameterIiv(GLuint texture
, GLenum pname
, GLint
*params
)
2339 struct gl_texture_object
*texObj
;
2340 GET_CURRENT_CONTEXT(ctx
);
2342 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIiv");
2346 get_tex_parameterIiv(ctx
, texObj
, pname
, params
, true);
2351 _mesa_GetTextureParameterIuiv(GLuint texture
, GLenum pname
, GLuint
*params
)
2353 struct gl_texture_object
*texObj
;
2354 GET_CURRENT_CONTEXT(ctx
);
2356 texObj
= get_texobj_by_name(ctx
, texture
, "glGetTextureParameterIuiv");
2360 get_tex_parameterIuiv(ctx
, texObj
, pname
, params
, true);