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/colormac.h"
36 #include "main/context.h"
37 #include "main/enums.h"
38 #include "main/formats.h"
39 #include "main/glformats.h"
40 #include "main/macros.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texcompress.h"
44 #include "main/texobj.h"
45 #include "main/texparam.h"
46 #include "main/teximage.h"
47 #include "main/texstate.h"
48 #include "program/prog_instruction.h"
52 * Check if a coordinate wrap mode is supported for the texture target.
53 * \return GL_TRUE if legal, GL_FALSE otherwise
56 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
58 const struct gl_extensions
* const e
= & ctx
->Extensions
;
59 const bool is_desktop_gl
= _mesa_is_desktop_gl(ctx
);
64 /* GL_CLAMP was removed in the core profile, and it has never existed in
67 supported
= (ctx
->API
== API_OPENGL_COMPAT
)
68 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
71 case GL_CLAMP_TO_EDGE
:
75 case GL_CLAMP_TO_BORDER
:
76 supported
= is_desktop_gl
&& e
->ARB_texture_border_clamp
77 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
81 case GL_MIRRORED_REPEAT
:
82 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
83 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
86 case GL_MIRROR_CLAMP_EXT
:
87 supported
= is_desktop_gl
88 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
89 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
90 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
93 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
94 supported
= is_desktop_gl
95 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
)
96 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
97 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
100 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
101 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
102 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
103 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
112 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
119 * Get current texture object for given target.
120 * Return NULL if any error (and record the error).
121 * Note that this is different from _mesa_get_current_tex_object() in that
122 * proxy targets are not accepted.
123 * Only the glGetTexLevelParameter() functions accept proxy targets.
125 static struct gl_texture_object
*
126 get_texobj_by_target(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
128 struct gl_texture_unit
*texUnit
;
131 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
132 _mesa_error(ctx
, GL_INVALID_OPERATION
,
133 "gl%sTexParameter(current unit)", get
? "Get" : "");
137 texUnit
= _mesa_get_current_tex_unit(ctx
);
139 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
140 if (targetIndex
< 0 || targetIndex
== TEXTURE_BUFFER_INDEX
) {
141 _mesa_error(ctx
, GL_INVALID_ENUM
,
142 "gl%sTexParameter(target)", get
? "Get" : "");
145 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
147 return texUnit
->CurrentTex
[targetIndex
];
151 * Get current texture object for given name.
152 * Return NULL if any error (and record the error).
153 * Note that proxy targets are not accepted.
154 * Only the glGetTexLevelParameter() functions accept proxy targets.
156 static struct gl_texture_object
*
157 get_texobj_by_name(struct gl_context
*ctx
, GLuint texture
, GLboolean get
)
159 struct gl_texture_object
*texObj
;
161 texObj
= _mesa_lookup_texture(ctx
, texture
);
164 * User passed a non-generated name.
165 * Throw the error in the caller.
170 switch (texObj
->Target
) {
172 case GL_TEXTURE_1D_ARRAY
:
174 case GL_TEXTURE_2D_ARRAY
:
175 case GL_TEXTURE_2D_MULTISAMPLE
:
176 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
178 case GL_TEXTURE_CUBE_MAP
:
179 case GL_TEXTURE_CUBE_MAP_ARRAY
:
180 case GL_TEXTURE_RECTANGLE
:
183 _mesa_error(ctx
, GL_INVALID_ENUM
,
184 "gl%sTextureParameter(target)", get
? "Get" : "");
192 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
193 * \return -1 if error.
196 comp_to_swizzle(GLenum comp
)
218 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
221 ASSERT(swz
<= SWIZZLE_NIL
);
223 GLuint mask
= 0x7 << (3 * comp
);
224 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
231 * This is called just prior to changing any texture object state which
232 * will not effect texture completeness.
235 flush(struct gl_context
*ctx
)
237 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
242 * This is called just prior to changing any texture object state which
243 * can effect texture completeness (texture base level, max level).
244 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
245 * state flag and then mark the texture object as 'incomplete' so that any
246 * per-texture derived state gets recomputed.
249 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
251 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
252 _mesa_dirty_texobj(ctx
, texObj
);
257 target_allows_setting_sampler_parameters(GLenum target
)
260 case GL_TEXTURE_2D_MULTISAMPLE
:
261 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
271 * Set an integer-valued texture parameter
272 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
275 set_tex_parameteri(struct gl_context
*ctx
,
276 struct gl_texture_object
*texObj
,
277 GLenum pname
, const GLint
*params
, bool dsa
)
279 const char *suffix
= dsa
? "ture" : "";
282 case GL_TEXTURE_MIN_FILTER
:
283 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
286 if (texObj
->Sampler
.MinFilter
== params
[0])
292 texObj
->Sampler
.MinFilter
= params
[0];
294 case GL_NEAREST_MIPMAP_NEAREST
:
295 case GL_LINEAR_MIPMAP_NEAREST
:
296 case GL_NEAREST_MIPMAP_LINEAR
:
297 case GL_LINEAR_MIPMAP_LINEAR
:
298 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
299 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
301 texObj
->Sampler
.MinFilter
= params
[0];
310 case GL_TEXTURE_MAG_FILTER
:
311 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
314 if (texObj
->Sampler
.MagFilter
== params
[0])
319 flush(ctx
); /* does not effect completeness */
320 texObj
->Sampler
.MagFilter
= params
[0];
327 case GL_TEXTURE_WRAP_S
:
328 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
331 if (texObj
->Sampler
.WrapS
== params
[0])
333 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
335 texObj
->Sampler
.WrapS
= params
[0];
340 case GL_TEXTURE_WRAP_T
:
341 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
344 if (texObj
->Sampler
.WrapT
== params
[0])
346 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
348 texObj
->Sampler
.WrapT
= params
[0];
353 case GL_TEXTURE_WRAP_R
:
354 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
357 if (texObj
->Sampler
.WrapR
== params
[0])
359 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
361 texObj
->Sampler
.WrapR
= params
[0];
366 case GL_TEXTURE_BASE_LEVEL
:
367 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
370 if (texObj
->BaseLevel
== params
[0])
373 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
374 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
375 goto invalid_operation
;
378 _mesa_error(ctx
, GL_INVALID_VALUE
,
379 "glTex%sParameter(param=%d)", suffix
, params
[0]);
382 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0) {
383 _mesa_error(ctx
, GL_INVALID_OPERATION
,
384 "glTex%sParameter(target=%s, param=%d)", suffix
,
385 _mesa_lookup_enum_by_nr(texObj
->Target
), params
[0]);
388 incomplete(ctx
, texObj
);
390 /** See note about ARB_texture_storage below */
391 if (texObj
->Immutable
)
392 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
394 texObj
->BaseLevel
= params
[0];
398 case GL_TEXTURE_MAX_LEVEL
:
399 if (texObj
->MaxLevel
== params
[0])
403 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
404 _mesa_error(ctx
, GL_INVALID_VALUE
,
405 "glTex%sParameter(param=%d)", suffix
,
409 incomplete(ctx
, texObj
);
411 /** From ARB_texture_storage:
412 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
413 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
414 * the range [level_base, <levels> - 1], where <levels> is the parameter
415 * passed the call to TexStorage* for the texture object.
417 if (texObj
->Immutable
)
418 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
419 texObj
->ImmutableLevels
- 1);
421 texObj
->MaxLevel
= params
[0];
425 case GL_GENERATE_MIPMAP_SGIS
:
426 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
429 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
431 if (texObj
->GenerateMipmap
!= params
[0]) {
433 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
438 case GL_TEXTURE_COMPARE_MODE_ARB
:
439 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
440 || _mesa_is_gles3(ctx
)) {
442 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
445 if (texObj
->Sampler
.CompareMode
== params
[0])
447 if (params
[0] == GL_NONE
||
448 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
450 texObj
->Sampler
.CompareMode
= params
[0];
457 case GL_TEXTURE_COMPARE_FUNC_ARB
:
458 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
459 || _mesa_is_gles3(ctx
)) {
461 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
464 if (texObj
->Sampler
.CompareFunc
== params
[0])
476 texObj
->Sampler
.CompareFunc
= params
[0];
484 case GL_DEPTH_TEXTURE_MODE_ARB
:
485 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
486 * existed in OpenGL ES.
488 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
489 if (texObj
->DepthMode
== params
[0])
491 if (params
[0] == GL_LUMINANCE
||
492 params
[0] == GL_INTENSITY
||
493 params
[0] == GL_ALPHA
||
494 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
496 texObj
->DepthMode
= params
[0];
503 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
504 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_stencil_texturing
) {
505 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
506 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
509 if (texObj
->StencilSampling
== stencil
)
512 texObj
->StencilSampling
= stencil
;
517 case GL_TEXTURE_CROP_RECT_OES
:
518 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
521 texObj
->CropRect
[0] = params
[0];
522 texObj
->CropRect
[1] = params
[1];
523 texObj
->CropRect
[2] = params
[2];
524 texObj
->CropRect
[3] = params
[3];
527 case GL_TEXTURE_SWIZZLE_R_EXT
:
528 case GL_TEXTURE_SWIZZLE_G_EXT
:
529 case GL_TEXTURE_SWIZZLE_B_EXT
:
530 case GL_TEXTURE_SWIZZLE_A_EXT
:
531 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
532 || _mesa_is_gles3(ctx
)) {
533 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
534 const GLint swz
= comp_to_swizzle(params
[0]);
536 _mesa_error(ctx
, GL_INVALID_ENUM
,
537 "glTex%sParameter(swizzle 0x%x)", suffix
, params
[0]);
543 texObj
->Swizzle
[comp
] = params
[0];
544 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
549 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
550 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
551 || _mesa_is_gles3(ctx
)) {
554 for (comp
= 0; comp
< 4; comp
++) {
555 const GLint swz
= comp_to_swizzle(params
[comp
]);
557 texObj
->Swizzle
[comp
] = params
[comp
];
558 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
561 _mesa_error(ctx
, GL_INVALID_ENUM
,
562 "glTex%sParameter(swizzle 0x%x)",
563 suffix
, params
[comp
]);
571 case GL_TEXTURE_SRGB_DECODE_EXT
:
572 if (_mesa_is_desktop_gl(ctx
)
573 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
574 GLenum decode
= params
[0];
576 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
579 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
580 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
582 texObj
->Sampler
.sRGBDecode
= decode
;
589 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
590 if (_mesa_is_desktop_gl(ctx
)
591 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
592 GLenum param
= params
[0];
594 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
597 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
600 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
602 texObj
->Sampler
.CubeMapSeamless
= param
;
613 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
614 suffix
, _mesa_lookup_enum_by_nr(pname
));
618 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(param=%s)",
619 suffix
, _mesa_lookup_enum_by_nr(params
[0]));
623 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTex%sParameter(pname=%s)",
624 suffix
, _mesa_lookup_enum_by_nr(pname
));
628 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
629 suffix
, _mesa_lookup_enum_by_nr(pname
));
635 * Set a float-valued texture parameter
636 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
639 set_tex_parameterf(struct gl_context
*ctx
,
640 struct gl_texture_object
*texObj
,
641 GLenum pname
, const GLfloat
*params
, bool dsa
)
643 const char *suffix
= dsa
? "ture" : "";
646 case GL_TEXTURE_MIN_LOD
:
647 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
650 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
653 if (texObj
->Sampler
.MinLod
== params
[0])
656 texObj
->Sampler
.MinLod
= params
[0];
659 case GL_TEXTURE_MAX_LOD
:
660 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
663 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
666 if (texObj
->Sampler
.MaxLod
== params
[0])
669 texObj
->Sampler
.MaxLod
= params
[0];
672 case GL_TEXTURE_PRIORITY
:
673 if (ctx
->API
!= API_OPENGL_COMPAT
)
677 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
680 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
681 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
682 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
685 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
687 if (params
[0] < 1.0) {
688 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sParameter(param)",
693 /* clamp to max, that's what NVIDIA does */
694 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
695 ctx
->Const
.MaxTextureMaxAnisotropy
);
699 static GLuint count
= 0;
705 case GL_TEXTURE_LOD_BIAS
:
706 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
707 if (_mesa_is_gles(ctx
))
710 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
713 if (texObj
->Sampler
.LodBias
!= params
[0]) {
715 texObj
->Sampler
.LodBias
= params
[0];
720 case GL_TEXTURE_BORDER_COLOR
:
721 if (!_mesa_is_desktop_gl(ctx
))
724 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
728 /* ARB_texture_float disables clamping */
729 if (ctx
->Extensions
.ARB_texture_float
) {
730 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
731 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
732 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
733 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
735 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
736 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
737 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
738 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
748 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
749 suffix
, _mesa_lookup_enum_by_nr(pname
));
753 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sParameter(pname=%s)",
754 suffix
, _mesa_lookup_enum_by_nr(pname
));
760 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
762 GLboolean need_update
;
763 struct gl_texture_object
*texObj
;
764 GET_CURRENT_CONTEXT(ctx
);
766 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
771 case GL_TEXTURE_MIN_FILTER
:
772 case GL_TEXTURE_MAG_FILTER
:
773 case GL_TEXTURE_WRAP_S
:
774 case GL_TEXTURE_WRAP_T
:
775 case GL_TEXTURE_WRAP_R
:
776 case GL_TEXTURE_BASE_LEVEL
:
777 case GL_TEXTURE_MAX_LEVEL
:
778 case GL_GENERATE_MIPMAP_SGIS
:
779 case GL_TEXTURE_COMPARE_MODE_ARB
:
780 case GL_TEXTURE_COMPARE_FUNC_ARB
:
781 case GL_DEPTH_TEXTURE_MODE_ARB
:
782 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
783 case GL_TEXTURE_SRGB_DECODE_EXT
:
784 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
785 case GL_TEXTURE_SWIZZLE_R_EXT
:
786 case GL_TEXTURE_SWIZZLE_G_EXT
:
787 case GL_TEXTURE_SWIZZLE_B_EXT
:
788 case GL_TEXTURE_SWIZZLE_A_EXT
:
792 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
793 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
795 p
[1] = p
[2] = p
[3] = 0;
796 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, false);
801 /* this will generate an error if pname is illegal */
804 p
[1] = p
[2] = p
[3] = 0.0F
;
805 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
, false);
809 if (ctx
->Driver
.TexParameter
&& need_update
) {
810 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, ¶m
);
816 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
818 GLboolean need_update
;
819 struct gl_texture_object
*texObj
;
820 GET_CURRENT_CONTEXT(ctx
);
822 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
827 case GL_TEXTURE_MIN_FILTER
:
828 case GL_TEXTURE_MAG_FILTER
:
829 case GL_TEXTURE_WRAP_S
:
830 case GL_TEXTURE_WRAP_T
:
831 case GL_TEXTURE_WRAP_R
:
832 case GL_TEXTURE_BASE_LEVEL
:
833 case GL_TEXTURE_MAX_LEVEL
:
834 case GL_GENERATE_MIPMAP_SGIS
:
835 case GL_TEXTURE_COMPARE_MODE_ARB
:
836 case GL_TEXTURE_COMPARE_FUNC_ARB
:
837 case GL_DEPTH_TEXTURE_MODE_ARB
:
838 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
839 case GL_TEXTURE_SRGB_DECODE_EXT
:
840 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
842 /* convert float param to int */
844 p
[0] = (GLint
) params
[0];
845 p
[1] = p
[2] = p
[3] = 0;
846 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, false);
849 case GL_TEXTURE_CROP_RECT_OES
:
851 /* convert float params to int */
853 iparams
[0] = (GLint
) params
[0];
854 iparams
[1] = (GLint
) params
[1];
855 iparams
[2] = (GLint
) params
[2];
856 iparams
[3] = (GLint
) params
[3];
857 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
, false);
860 case GL_TEXTURE_SWIZZLE_R_EXT
:
861 case GL_TEXTURE_SWIZZLE_G_EXT
:
862 case GL_TEXTURE_SWIZZLE_B_EXT
:
863 case GL_TEXTURE_SWIZZLE_A_EXT
:
864 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
866 GLint p
[4] = {0, 0, 0, 0};
867 p
[0] = (GLint
) params
[0];
868 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
869 p
[1] = (GLint
) params
[1];
870 p
[2] = (GLint
) params
[2];
871 p
[3] = (GLint
) params
[3];
873 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
, false);
877 /* this will generate an error if pname is illegal */
878 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
, false);
881 if (ctx
->Driver
.TexParameter
&& need_update
) {
882 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, params
);
888 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
890 GLboolean need_update
;
891 struct gl_texture_object
*texObj
;
892 GET_CURRENT_CONTEXT(ctx
);
894 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
899 case GL_TEXTURE_MIN_LOD
:
900 case GL_TEXTURE_MAX_LOD
:
901 case GL_TEXTURE_PRIORITY
:
902 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
903 case GL_TEXTURE_LOD_BIAS
:
904 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
907 fparam
[0] = (GLfloat
) param
;
908 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
909 /* convert int param to float */
910 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
, false);
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
, false);
923 if (ctx
->Driver
.TexParameter
&& need_update
) {
924 GLfloat fparam
= (GLfloat
) param
;
925 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, &fparam
);
931 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
933 GLboolean need_update
;
934 struct gl_texture_object
*texObj
;
935 GET_CURRENT_CONTEXT(ctx
);
937 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
942 case GL_TEXTURE_BORDER_COLOR
:
944 /* convert int params to float */
946 fparams
[0] = INT_TO_FLOAT(params
[0]);
947 fparams
[1] = INT_TO_FLOAT(params
[1]);
948 fparams
[2] = INT_TO_FLOAT(params
[2]);
949 fparams
[3] = INT_TO_FLOAT(params
[3]);
950 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, false);
953 case GL_TEXTURE_MIN_LOD
:
954 case GL_TEXTURE_MAX_LOD
:
955 case GL_TEXTURE_PRIORITY
:
956 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
957 case GL_TEXTURE_LOD_BIAS
:
958 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
960 /* convert int param to float */
962 fparams
[0] = (GLfloat
) params
[0];
963 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
964 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
, false);
968 /* this will generate an error if pname is illegal */
969 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
, false);
972 if (ctx
->Driver
.TexParameter
&& need_update
) {
974 fparams
[0] = INT_TO_FLOAT(params
[0]);
975 if (pname
== GL_TEXTURE_BORDER_COLOR
||
976 pname
== GL_TEXTURE_CROP_RECT_OES
) {
977 fparams
[1] = INT_TO_FLOAT(params
[1]);
978 fparams
[2] = INT_TO_FLOAT(params
[2]);
979 fparams
[3] = INT_TO_FLOAT(params
[3]);
981 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, fparams
);
986 * Set tex parameter to integer value(s). Primarily intended to set
987 * integer-valued texture border color (for integer-valued textures).
991 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
993 struct gl_texture_object
*texObj
;
994 GET_CURRENT_CONTEXT(ctx
);
996 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1001 case GL_TEXTURE_BORDER_COLOR
:
1002 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1003 /* set the integer-valued border color */
1004 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
1007 _mesa_TexParameteriv(target
, pname
, params
);
1010 /* XXX no driver hook for TexParameterIiv() yet */
1015 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1016 * uint-valued texture border color (for integer-valued textures).
1020 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1022 struct gl_texture_object
*texObj
;
1023 GET_CURRENT_CONTEXT(ctx
);
1025 texObj
= get_texobj_by_target(ctx
, target
, GL_FALSE
);
1030 case GL_TEXTURE_BORDER_COLOR
:
1031 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1032 /* set the unsigned integer-valued border color */
1033 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1036 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1039 /* XXX no driver hook for TexParameterIuiv() yet */
1044 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1048 case GL_PROXY_TEXTURE_1D
:
1050 case GL_PROXY_TEXTURE_2D
:
1052 case GL_PROXY_TEXTURE_3D
:
1054 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1055 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1056 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1057 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1058 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1059 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1060 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1061 return ctx
->Extensions
.ARB_texture_cube_map
;
1062 case GL_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1063 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1064 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1065 case GL_TEXTURE_RECTANGLE_NV
:
1066 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1067 return ctx
->Extensions
.NV_texture_rectangle
;
1068 case GL_TEXTURE_1D_ARRAY_EXT
:
1069 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1070 case GL_TEXTURE_2D_ARRAY_EXT
:
1071 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1072 return ctx
->Extensions
.EXT_texture_array
;
1073 case GL_TEXTURE_BUFFER
:
1074 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1075 * but not in earlier versions that expose ARB_texture_buffer_object.
1077 * From the ARB_texture_buffer_object spec:
1078 * "(7) Do buffer textures support texture parameters (TexParameter) or
1079 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1081 * RESOLVED: No. [...] Note that the spec edits above don't add
1082 * explicit error language for any of these cases. That is because
1083 * each of the functions enumerate the set of valid <target>
1084 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1085 * these cases means that target is not legal, and an INVALID_ENUM
1086 * error should be generated."
1088 * From the OpenGL 3.1 spec:
1089 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1091 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1092 case GL_TEXTURE_2D_MULTISAMPLE
:
1093 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1094 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1095 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1096 return ctx
->Extensions
.ARB_texture_multisample
;
1104 get_tex_level_parameter_image(struct gl_context
*ctx
,
1105 const struct gl_texture_object
*texObj
,
1106 GLenum target
, GLint level
,
1107 GLenum pname
, GLint
*params
)
1109 const struct gl_texture_image
*img
= NULL
;
1110 struct gl_texture_image dummy_image
;
1111 mesa_format texFormat
;
1113 img
= _mesa_select_tex_image(texObj
, target
, level
);
1114 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1115 /* In case of undefined texture image return the default values.
1117 * From OpenGL 4.0 spec, page 398:
1118 * "The initial internal format of a texel array is RGBA
1119 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1120 * use TEXTURE_INTERNAL_FORMAT."
1122 memset(&dummy_image
, 0, sizeof(dummy_image
));
1123 dummy_image
.TexFormat
= MESA_FORMAT_NONE
;
1124 dummy_image
.InternalFormat
= GL_RGBA
;
1125 dummy_image
._BaseFormat
= GL_NONE
;
1130 texFormat
= img
->TexFormat
;
1133 case GL_TEXTURE_WIDTH
:
1134 *params
= img
->Width
;
1136 case GL_TEXTURE_HEIGHT
:
1137 *params
= img
->Height
;
1139 case GL_TEXTURE_DEPTH
:
1140 *params
= img
->Depth
;
1142 case GL_TEXTURE_INTERNAL_FORMAT
:
1143 if (_mesa_is_format_compressed(texFormat
)) {
1144 /* need to return the actual compressed format */
1145 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1148 /* If the true internal format is not compressed but the user
1149 * requested a generic compressed format, we have to return the
1150 * generic base format that matches.
1152 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1154 * "If no specific compressed format is available,
1155 * internalformat is instead replaced by the corresponding base
1158 * Otherwise just return the user's requested internal format
1161 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1163 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1166 case GL_TEXTURE_BORDER
:
1167 if (ctx
->API
!= API_OPENGL_COMPAT
)
1169 *params
= img
->Border
;
1171 case GL_TEXTURE_RED_SIZE
:
1172 case GL_TEXTURE_GREEN_SIZE
:
1173 case GL_TEXTURE_BLUE_SIZE
:
1174 case GL_TEXTURE_ALPHA_SIZE
:
1175 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1176 *params
= _mesa_get_format_bits(texFormat
, pname
);
1180 case GL_TEXTURE_INTENSITY_SIZE
:
1181 case GL_TEXTURE_LUMINANCE_SIZE
:
1182 if (ctx
->API
!= API_OPENGL_COMPAT
)
1184 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1185 *params
= _mesa_get_format_bits(texFormat
, pname
);
1187 /* intensity or luminance is probably stored as RGB[A] */
1188 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1189 GL_TEXTURE_RED_SIZE
),
1190 _mesa_get_format_bits(texFormat
,
1191 GL_TEXTURE_GREEN_SIZE
));
1198 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1199 if (!ctx
->Extensions
.ARB_depth_texture
)
1201 *params
= _mesa_get_format_bits(texFormat
, pname
);
1203 case GL_TEXTURE_STENCIL_SIZE
:
1204 *params
= _mesa_get_format_bits(texFormat
, pname
);
1206 case GL_TEXTURE_SHARED_SIZE
:
1207 if (ctx
->Version
< 30 &&
1208 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1210 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1213 /* GL_ARB_texture_compression */
1214 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1215 if (_mesa_is_format_compressed(texFormat
) &&
1216 !_mesa_is_proxy_texture(target
)) {
1217 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1218 img
->Height
, img
->Depth
);
1221 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1222 "glGetTexLevelParameter[if]v(pname)");
1225 case GL_TEXTURE_COMPRESSED
:
1226 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1229 /* GL_ARB_texture_float */
1230 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1231 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1232 if (ctx
->API
!= API_OPENGL_COMPAT
)
1235 case GL_TEXTURE_RED_TYPE_ARB
:
1236 case GL_TEXTURE_GREEN_TYPE_ARB
:
1237 case GL_TEXTURE_BLUE_TYPE_ARB
:
1238 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1239 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1240 if (!ctx
->Extensions
.ARB_texture_float
)
1242 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1243 *params
= _mesa_get_format_datatype(texFormat
);
1248 /* GL_ARB_texture_multisample */
1249 case GL_TEXTURE_SAMPLES
:
1250 if (!ctx
->Extensions
.ARB_texture_multisample
)
1252 *params
= img
->NumSamples
;
1255 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1256 if (!ctx
->Extensions
.ARB_texture_multisample
)
1258 *params
= img
->FixedSampleLocations
;
1265 /* no error if we get here */
1269 _mesa_error(ctx
, GL_INVALID_ENUM
,
1270 "glGetTexLevelParameter[if]v(pname=%s)",
1271 _mesa_lookup_enum_by_nr(pname
));
1276 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1277 const struct gl_texture_object
*texObj
,
1278 GLenum pname
, GLint
*params
)
1280 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1281 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1282 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1283 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1286 /* undefined texture buffer object */
1287 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1292 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1295 case GL_TEXTURE_WIDTH
:
1298 case GL_TEXTURE_HEIGHT
:
1299 case GL_TEXTURE_DEPTH
:
1300 case GL_TEXTURE_BORDER
:
1301 case GL_TEXTURE_SHARED_SIZE
:
1302 case GL_TEXTURE_COMPRESSED
:
1305 case GL_TEXTURE_INTERNAL_FORMAT
:
1306 *params
= internalFormat
;
1308 case GL_TEXTURE_RED_SIZE
:
1309 case GL_TEXTURE_GREEN_SIZE
:
1310 case GL_TEXTURE_BLUE_SIZE
:
1311 case GL_TEXTURE_ALPHA_SIZE
:
1312 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1313 *params
= _mesa_get_format_bits(texFormat
, pname
);
1317 case GL_TEXTURE_INTENSITY_SIZE
:
1318 case GL_TEXTURE_LUMINANCE_SIZE
:
1319 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1320 *params
= _mesa_get_format_bits(texFormat
, pname
);
1322 /* intensity or luminance is probably stored as RGB[A] */
1323 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1324 GL_TEXTURE_RED_SIZE
),
1325 _mesa_get_format_bits(texFormat
,
1326 GL_TEXTURE_GREEN_SIZE
));
1332 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1333 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1334 *params
= _mesa_get_format_bits(texFormat
, pname
);
1337 /* GL_ARB_texture_buffer_range */
1338 case GL_TEXTURE_BUFFER_OFFSET
:
1339 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1341 *params
= texObj
->BufferOffset
;
1343 case GL_TEXTURE_BUFFER_SIZE
:
1344 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1346 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1349 /* GL_ARB_texture_compression */
1350 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1351 /* Always illegal for GL_TEXTURE_BUFFER */
1352 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1353 "glGetTexLevelParameter[if]v(pname)");
1356 /* GL_ARB_texture_float */
1357 case GL_TEXTURE_RED_TYPE_ARB
:
1358 case GL_TEXTURE_GREEN_TYPE_ARB
:
1359 case GL_TEXTURE_BLUE_TYPE_ARB
:
1360 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1361 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1362 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1363 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1364 if (!ctx
->Extensions
.ARB_texture_float
)
1366 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1367 *params
= _mesa_get_format_datatype(texFormat
);
1376 /* no error if we get here */
1380 _mesa_error(ctx
, GL_INVALID_ENUM
,
1381 "glGetTexLevelParameter[if]v(pname=%s)",
1382 _mesa_lookup_enum_by_nr(pname
));
1387 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1388 GLenum pname
, GLfloat
*params
)
1391 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1392 *params
= (GLfloat
) iparam
;
1397 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1398 GLenum pname
, GLint
*params
)
1400 struct gl_texture_object
*texObj
;
1402 GET_CURRENT_CONTEXT(ctx
);
1404 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1406 "glGetTexLevelParameteriv(current unit)");
1410 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1411 _mesa_error(ctx
, GL_INVALID_ENUM
,
1412 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1416 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1417 assert(maxLevels
!= 0);
1419 if (level
< 0 || level
>= maxLevels
) {
1420 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1424 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1426 if (target
== GL_TEXTURE_BUFFER
)
1427 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1429 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1434 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1436 struct gl_texture_object
*obj
;
1437 GET_CURRENT_CONTEXT(ctx
);
1439 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
1443 _mesa_lock_context_textures(ctx
);
1445 case GL_TEXTURE_MAG_FILTER
:
1446 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1448 case GL_TEXTURE_MIN_FILTER
:
1449 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1451 case GL_TEXTURE_WRAP_S
:
1452 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1454 case GL_TEXTURE_WRAP_T
:
1455 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1457 case GL_TEXTURE_WRAP_R
:
1458 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1460 case GL_TEXTURE_BORDER_COLOR
:
1461 if (!_mesa_is_desktop_gl(ctx
))
1464 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1465 _mesa_update_state_locked(ctx
);
1466 if (_mesa_get_clamp_fragment_color(ctx
)) {
1467 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1468 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1469 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1470 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1473 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1474 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1475 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1476 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1479 case GL_TEXTURE_RESIDENT
:
1480 if (ctx
->API
!= API_OPENGL_COMPAT
)
1485 case GL_TEXTURE_PRIORITY
:
1486 if (ctx
->API
!= API_OPENGL_COMPAT
)
1489 *params
= obj
->Priority
;
1491 case GL_TEXTURE_MIN_LOD
:
1492 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1495 *params
= obj
->Sampler
.MinLod
;
1497 case GL_TEXTURE_MAX_LOD
:
1498 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1501 *params
= obj
->Sampler
.MaxLod
;
1503 case GL_TEXTURE_BASE_LEVEL
:
1504 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1507 *params
= (GLfloat
) obj
->BaseLevel
;
1509 case GL_TEXTURE_MAX_LEVEL
:
1510 *params
= (GLfloat
) obj
->MaxLevel
;
1512 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1513 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1515 *params
= obj
->Sampler
.MaxAnisotropy
;
1517 case GL_GENERATE_MIPMAP_SGIS
:
1518 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1521 *params
= (GLfloat
) obj
->GenerateMipmap
;
1523 case GL_TEXTURE_COMPARE_MODE_ARB
:
1524 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1525 && !_mesa_is_gles3(ctx
))
1527 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1529 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1530 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1531 && !_mesa_is_gles3(ctx
))
1533 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1535 case GL_DEPTH_TEXTURE_MODE_ARB
:
1536 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1537 * never existed in OpenGL ES.
1539 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1541 *params
= (GLfloat
) obj
->DepthMode
;
1543 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1544 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
1547 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1549 case GL_TEXTURE_LOD_BIAS
:
1550 if (_mesa_is_gles(ctx
))
1553 *params
= obj
->Sampler
.LodBias
;
1555 case GL_TEXTURE_CROP_RECT_OES
:
1556 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1559 params
[0] = (GLfloat
) obj
->CropRect
[0];
1560 params
[1] = (GLfloat
) obj
->CropRect
[1];
1561 params
[2] = (GLfloat
) obj
->CropRect
[2];
1562 params
[3] = (GLfloat
) obj
->CropRect
[3];
1565 case GL_TEXTURE_SWIZZLE_R_EXT
:
1566 case GL_TEXTURE_SWIZZLE_G_EXT
:
1567 case GL_TEXTURE_SWIZZLE_B_EXT
:
1568 case GL_TEXTURE_SWIZZLE_A_EXT
:
1569 if ((!_mesa_is_desktop_gl(ctx
)
1570 || !ctx
->Extensions
.EXT_texture_swizzle
)
1571 && !_mesa_is_gles3(ctx
))
1573 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1576 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1577 if ((!_mesa_is_desktop_gl(ctx
)
1578 || !ctx
->Extensions
.EXT_texture_swizzle
)
1579 && !_mesa_is_gles3(ctx
)) {
1584 for (comp
= 0; comp
< 4; comp
++) {
1585 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1590 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1591 if (!_mesa_is_desktop_gl(ctx
)
1592 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1594 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1597 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1598 *params
= (GLfloat
) obj
->Immutable
;
1601 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1602 if (_mesa_is_gles3(ctx
) ||
1603 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1604 *params
= (GLfloat
) obj
->ImmutableLevels
;
1609 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1610 if (!ctx
->Extensions
.ARB_texture_view
)
1612 *params
= (GLfloat
) obj
->MinLevel
;
1615 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1616 if (!ctx
->Extensions
.ARB_texture_view
)
1618 *params
= (GLfloat
) obj
->NumLevels
;
1621 case GL_TEXTURE_VIEW_MIN_LAYER
:
1622 if (!ctx
->Extensions
.ARB_texture_view
)
1624 *params
= (GLfloat
) obj
->MinLayer
;
1627 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1628 if (!ctx
->Extensions
.ARB_texture_view
)
1630 *params
= (GLfloat
) obj
->NumLayers
;
1633 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1634 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1636 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1639 case GL_TEXTURE_SRGB_DECODE_EXT
:
1640 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1642 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1649 /* no error if we get here */
1650 _mesa_unlock_context_textures(ctx
);
1654 _mesa_unlock_context_textures(ctx
);
1655 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1660 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1662 struct gl_texture_object
*obj
;
1663 GET_CURRENT_CONTEXT(ctx
);
1665 obj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
1669 _mesa_lock_texture(ctx
, obj
);
1671 case GL_TEXTURE_MAG_FILTER
:
1672 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1674 case GL_TEXTURE_MIN_FILTER
:
1675 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1677 case GL_TEXTURE_WRAP_S
:
1678 *params
= (GLint
) obj
->Sampler
.WrapS
;
1680 case GL_TEXTURE_WRAP_T
:
1681 *params
= (GLint
) obj
->Sampler
.WrapT
;
1683 case GL_TEXTURE_WRAP_R
:
1684 *params
= (GLint
) obj
->Sampler
.WrapR
;
1686 case GL_TEXTURE_BORDER_COLOR
:
1687 if (!_mesa_is_desktop_gl(ctx
))
1692 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1693 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1694 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1695 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1696 params
[0] = FLOAT_TO_INT(b
[0]);
1697 params
[1] = FLOAT_TO_INT(b
[1]);
1698 params
[2] = FLOAT_TO_INT(b
[2]);
1699 params
[3] = FLOAT_TO_INT(b
[3]);
1702 case GL_TEXTURE_RESIDENT
:
1703 if (ctx
->API
!= API_OPENGL_COMPAT
)
1708 case GL_TEXTURE_PRIORITY
:
1709 if (ctx
->API
!= API_OPENGL_COMPAT
)
1712 *params
= FLOAT_TO_INT(obj
->Priority
);
1714 case GL_TEXTURE_MIN_LOD
:
1715 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1718 *params
= (GLint
) obj
->Sampler
.MinLod
;
1720 case GL_TEXTURE_MAX_LOD
:
1721 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1724 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1726 case GL_TEXTURE_BASE_LEVEL
:
1727 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1730 *params
= obj
->BaseLevel
;
1732 case GL_TEXTURE_MAX_LEVEL
:
1733 *params
= obj
->MaxLevel
;
1735 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1736 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1738 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1740 case GL_GENERATE_MIPMAP_SGIS
:
1741 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1744 *params
= (GLint
) obj
->GenerateMipmap
;
1746 case GL_TEXTURE_COMPARE_MODE_ARB
:
1747 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1748 && !_mesa_is_gles3(ctx
))
1750 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1752 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1753 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1754 && !_mesa_is_gles3(ctx
))
1756 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1758 case GL_DEPTH_TEXTURE_MODE_ARB
:
1759 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1761 *params
= (GLint
) obj
->DepthMode
;
1763 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1764 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
1767 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1769 case GL_TEXTURE_LOD_BIAS
:
1770 if (_mesa_is_gles(ctx
))
1773 /* GL spec 'Data Conversions' section specifies that floating-point
1774 * value in integer Get function is rounded to nearest integer
1776 *params
= IROUND(obj
->Sampler
.LodBias
);
1778 case GL_TEXTURE_CROP_RECT_OES
:
1779 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1782 params
[0] = obj
->CropRect
[0];
1783 params
[1] = obj
->CropRect
[1];
1784 params
[2] = obj
->CropRect
[2];
1785 params
[3] = obj
->CropRect
[3];
1787 case GL_TEXTURE_SWIZZLE_R_EXT
:
1788 case GL_TEXTURE_SWIZZLE_G_EXT
:
1789 case GL_TEXTURE_SWIZZLE_B_EXT
:
1790 case GL_TEXTURE_SWIZZLE_A_EXT
:
1791 if ((!_mesa_is_desktop_gl(ctx
)
1792 || !ctx
->Extensions
.EXT_texture_swizzle
)
1793 && !_mesa_is_gles3(ctx
))
1795 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1798 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1799 if ((!_mesa_is_desktop_gl(ctx
)
1800 || !ctx
->Extensions
.EXT_texture_swizzle
)
1801 && !_mesa_is_gles3(ctx
))
1803 COPY_4V(params
, obj
->Swizzle
);
1806 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1807 if (!_mesa_is_desktop_gl(ctx
)
1808 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1810 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1813 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1814 *params
= (GLint
) obj
->Immutable
;
1817 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1818 if (_mesa_is_gles3(ctx
) ||
1819 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1820 *params
= obj
->ImmutableLevels
;
1825 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1826 if (!ctx
->Extensions
.ARB_texture_view
)
1828 *params
= (GLint
) obj
->MinLevel
;
1831 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1832 if (!ctx
->Extensions
.ARB_texture_view
)
1834 *params
= (GLint
) obj
->NumLevels
;
1837 case GL_TEXTURE_VIEW_MIN_LAYER
:
1838 if (!ctx
->Extensions
.ARB_texture_view
)
1840 *params
= (GLint
) obj
->MinLayer
;
1843 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1844 if (!ctx
->Extensions
.ARB_texture_view
)
1846 *params
= (GLint
) obj
->NumLayers
;
1849 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1850 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1852 *params
= obj
->RequiredTextureImageUnits
;
1855 case GL_TEXTURE_SRGB_DECODE_EXT
:
1856 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1858 *params
= obj
->Sampler
.sRGBDecode
;
1861 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1862 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1864 *params
= obj
->ImageFormatCompatibilityType
;
1871 /* no error if we get here */
1872 _mesa_unlock_texture(ctx
, obj
);
1876 _mesa_unlock_texture(ctx
, obj
);
1877 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1880 /** New in GL 3.0 */
1882 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1884 struct gl_texture_object
*texObj
;
1885 GET_CURRENT_CONTEXT(ctx
);
1887 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
1892 case GL_TEXTURE_BORDER_COLOR
:
1893 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1896 _mesa_GetTexParameteriv(target
, pname
, params
);
1901 /** New in GL 3.0 */
1903 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1905 struct gl_texture_object
*texObj
;
1906 GET_CURRENT_CONTEXT(ctx
);
1908 texObj
= get_texobj_by_target(ctx
, target
, GL_TRUE
);
1913 case GL_TEXTURE_BORDER_COLOR
:
1914 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1919 _mesa_GetTexParameteriv(target
, pname
, ip
);
1921 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1922 pname
== GL_TEXTURE_CROP_RECT_OES
) {