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_select_tex_object() in that proxy
122 * targets are not accepted.
123 * Only the glGetTexLevelParameter() functions accept proxy targets.
125 static struct gl_texture_object
*
126 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
128 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
);
140 if (_mesa_is_desktop_gl(ctx
))
141 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
144 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
146 if (ctx
->API
!= API_OPENGLES
)
147 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
149 case GL_TEXTURE_CUBE_MAP
:
150 if (ctx
->Extensions
.ARB_texture_cube_map
) {
151 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
154 case GL_TEXTURE_RECTANGLE_NV
:
155 if (_mesa_is_desktop_gl(ctx
)
156 && ctx
->Extensions
.NV_texture_rectangle
) {
157 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
160 case GL_TEXTURE_1D_ARRAY_EXT
:
161 if (_mesa_is_desktop_gl(ctx
)
162 && (ctx
->Extensions
.MESA_texture_array
||
163 ctx
->Extensions
.EXT_texture_array
)) {
164 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
167 case GL_TEXTURE_2D_ARRAY_EXT
:
168 if ((_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
169 && (ctx
->Extensions
.MESA_texture_array
||
170 ctx
->Extensions
.EXT_texture_array
)) {
171 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
174 case GL_TEXTURE_EXTERNAL_OES
:
175 if (_mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
) {
176 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
179 case GL_TEXTURE_CUBE_MAP_ARRAY
:
180 if (ctx
->Extensions
.ARB_texture_cube_map_array
) {
181 return texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
];
184 case GL_TEXTURE_2D_MULTISAMPLE
:
185 if (ctx
->Extensions
.ARB_texture_multisample
) {
186 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
];
189 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
190 if (ctx
->Extensions
.ARB_texture_multisample
) {
191 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
];
198 _mesa_error(ctx
, GL_INVALID_ENUM
,
199 "gl%sTexParameter(target)", get
? "Get" : "");
205 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
206 * \return -1 if error.
209 comp_to_swizzle(GLenum comp
)
231 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
234 ASSERT(swz
<= SWIZZLE_NIL
);
236 GLuint mask
= 0x7 << (3 * comp
);
237 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
244 * This is called just prior to changing any texture object state which
245 * will not effect texture completeness.
248 flush(struct gl_context
*ctx
)
250 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
255 * This is called just prior to changing any texture object state which
256 * can effect texture completeness (texture base level, max level).
257 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
258 * state flag and then mark the texture object as 'incomplete' so that any
259 * per-texture derived state gets recomputed.
262 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
264 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
265 _mesa_dirty_texobj(ctx
, texObj
);
270 target_allows_setting_sampler_parameters(GLenum target
)
273 case GL_TEXTURE_2D_MULTISAMPLE
:
274 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
284 * Set an integer-valued texture parameter
285 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
288 set_tex_parameteri(struct gl_context
*ctx
,
289 struct gl_texture_object
*texObj
,
290 GLenum pname
, const GLint
*params
)
293 case GL_TEXTURE_MIN_FILTER
:
294 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
295 goto invalid_operation
;
297 if (texObj
->Sampler
.MinFilter
== params
[0])
303 texObj
->Sampler
.MinFilter
= params
[0];
305 case GL_NEAREST_MIPMAP_NEAREST
:
306 case GL_LINEAR_MIPMAP_NEAREST
:
307 case GL_NEAREST_MIPMAP_LINEAR
:
308 case GL_LINEAR_MIPMAP_LINEAR
:
309 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
310 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
312 texObj
->Sampler
.MinFilter
= params
[0];
321 case GL_TEXTURE_MAG_FILTER
:
322 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
323 goto invalid_operation
;
325 if (texObj
->Sampler
.MagFilter
== params
[0])
330 flush(ctx
); /* does not effect completeness */
331 texObj
->Sampler
.MagFilter
= params
[0];
338 case GL_TEXTURE_WRAP_S
:
339 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
340 goto invalid_operation
;
342 if (texObj
->Sampler
.WrapS
== params
[0])
344 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
346 texObj
->Sampler
.WrapS
= params
[0];
351 case GL_TEXTURE_WRAP_T
:
352 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
353 goto invalid_operation
;
355 if (texObj
->Sampler
.WrapT
== params
[0])
357 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
359 texObj
->Sampler
.WrapT
= params
[0];
364 case GL_TEXTURE_WRAP_R
:
365 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
366 goto invalid_operation
;
368 if (texObj
->Sampler
.WrapR
== params
[0])
370 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
372 texObj
->Sampler
.WrapR
= params
[0];
377 case GL_TEXTURE_BASE_LEVEL
:
378 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
381 if (texObj
->BaseLevel
== params
[0])
384 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
385 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
386 goto invalid_operation
;
389 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
390 _mesa_error(ctx
, GL_INVALID_VALUE
,
391 "glTexParameter(param=%d)", params
[0]);
394 incomplete(ctx
, texObj
);
396 /** See note about ARB_texture_storage below */
397 if (texObj
->Immutable
)
398 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
400 texObj
->BaseLevel
= params
[0];
404 case GL_TEXTURE_MAX_LEVEL
:
405 if (texObj
->MaxLevel
== params
[0])
408 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
409 _mesa_error(ctx
, GL_INVALID_VALUE
,
410 "glTexParameter(param=%d)", params
[0]);
413 incomplete(ctx
, texObj
);
415 /** From ARB_texture_storage:
416 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
417 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
418 * the range [level_base, <levels> - 1], where <levels> is the parameter
419 * passed the call to TexStorage* for the texture object.
421 if (texObj
->Immutable
)
422 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
423 texObj
->ImmutableLevels
- 1);
425 texObj
->MaxLevel
= params
[0];
429 case GL_GENERATE_MIPMAP_SGIS
:
430 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
433 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
435 if (texObj
->GenerateMipmap
!= params
[0]) {
437 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
442 case GL_TEXTURE_COMPARE_MODE_ARB
:
443 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
444 || _mesa_is_gles3(ctx
)) {
446 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
447 goto invalid_operation
;
449 if (texObj
->Sampler
.CompareMode
== params
[0])
451 if (params
[0] == GL_NONE
||
452 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
454 texObj
->Sampler
.CompareMode
= params
[0];
461 case GL_TEXTURE_COMPARE_FUNC_ARB
:
462 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
463 || _mesa_is_gles3(ctx
)) {
465 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
466 goto invalid_operation
;
468 if (texObj
->Sampler
.CompareFunc
== params
[0])
480 texObj
->Sampler
.CompareFunc
= params
[0];
488 case GL_DEPTH_TEXTURE_MODE_ARB
:
489 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
490 * existed in OpenGL ES.
492 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
493 if (texObj
->DepthMode
== params
[0])
495 if (params
[0] == GL_LUMINANCE
||
496 params
[0] == GL_INTENSITY
||
497 params
[0] == GL_ALPHA
||
498 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
500 texObj
->DepthMode
= params
[0];
507 case GL_TEXTURE_CROP_RECT_OES
:
508 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
511 texObj
->CropRect
[0] = params
[0];
512 texObj
->CropRect
[1] = params
[1];
513 texObj
->CropRect
[2] = params
[2];
514 texObj
->CropRect
[3] = params
[3];
517 case GL_TEXTURE_SWIZZLE_R_EXT
:
518 case GL_TEXTURE_SWIZZLE_G_EXT
:
519 case GL_TEXTURE_SWIZZLE_B_EXT
:
520 case GL_TEXTURE_SWIZZLE_A_EXT
:
521 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
522 || _mesa_is_gles3(ctx
)) {
523 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
524 const GLint swz
= comp_to_swizzle(params
[0]);
526 _mesa_error(ctx
, GL_INVALID_OPERATION
,
527 "glTexParameter(swizzle 0x%x)", params
[0]);
533 texObj
->Swizzle
[comp
] = params
[0];
534 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
539 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
540 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
541 || _mesa_is_gles3(ctx
)) {
544 for (comp
= 0; comp
< 4; comp
++) {
545 const GLint swz
= comp_to_swizzle(params
[comp
]);
547 texObj
->Swizzle
[comp
] = params
[comp
];
548 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
551 _mesa_error(ctx
, GL_INVALID_OPERATION
,
552 "glTexParameter(swizzle 0x%x)", params
[comp
]);
560 case GL_TEXTURE_SRGB_DECODE_EXT
:
561 if (_mesa_is_desktop_gl(ctx
)
562 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
563 GLenum decode
= params
[0];
565 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
566 goto invalid_operation
;
568 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
569 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
571 texObj
->Sampler
.sRGBDecode
= decode
;
578 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
579 if (_mesa_is_desktop_gl(ctx
)
580 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
581 GLenum param
= params
[0];
583 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
584 goto invalid_operation
;
586 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
589 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
591 texObj
->Sampler
.CubeMapSeamless
= param
;
602 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
603 _mesa_lookup_enum_by_nr(pname
));
607 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
608 _mesa_lookup_enum_by_nr(params
[0]));
612 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
613 _mesa_lookup_enum_by_nr(pname
));
619 * Set a float-valued texture parameter
620 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
623 set_tex_parameterf(struct gl_context
*ctx
,
624 struct gl_texture_object
*texObj
,
625 GLenum pname
, const GLfloat
*params
)
628 case GL_TEXTURE_MIN_LOD
:
629 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
632 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
633 goto invalid_operation
;
635 if (texObj
->Sampler
.MinLod
== params
[0])
638 texObj
->Sampler
.MinLod
= params
[0];
641 case GL_TEXTURE_MAX_LOD
:
642 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
645 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
646 goto invalid_operation
;
648 if (texObj
->Sampler
.MaxLod
== params
[0])
651 texObj
->Sampler
.MaxLod
= params
[0];
654 case GL_TEXTURE_PRIORITY
:
655 if (ctx
->API
!= API_OPENGL_COMPAT
)
659 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
662 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
663 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
664 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
665 goto invalid_operation
;
667 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
669 if (params
[0] < 1.0) {
670 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
674 /* clamp to max, that's what NVIDIA does */
675 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
676 ctx
->Const
.MaxTextureMaxAnisotropy
);
680 static GLuint count
= 0;
686 case GL_TEXTURE_LOD_BIAS
:
687 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
688 if (_mesa_is_gles(ctx
))
691 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
692 goto invalid_operation
;
694 if (texObj
->Sampler
.LodBias
!= params
[0]) {
696 texObj
->Sampler
.LodBias
= params
[0];
701 case GL_TEXTURE_BORDER_COLOR
:
702 if (!_mesa_is_desktop_gl(ctx
))
705 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
706 goto invalid_operation
;
709 /* ARB_texture_float disables clamping */
710 if (ctx
->Extensions
.ARB_texture_float
) {
711 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
712 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
713 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
714 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
716 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
717 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
718 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
719 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
729 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
730 _mesa_lookup_enum_by_nr(pname
));
734 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
735 _mesa_lookup_enum_by_nr(pname
));
741 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
743 GLboolean need_update
;
744 struct gl_texture_object
*texObj
;
745 GET_CURRENT_CONTEXT(ctx
);
747 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
752 case GL_TEXTURE_MIN_FILTER
:
753 case GL_TEXTURE_MAG_FILTER
:
754 case GL_TEXTURE_WRAP_S
:
755 case GL_TEXTURE_WRAP_T
:
756 case GL_TEXTURE_WRAP_R
:
757 case GL_TEXTURE_BASE_LEVEL
:
758 case GL_TEXTURE_MAX_LEVEL
:
759 case GL_GENERATE_MIPMAP_SGIS
:
760 case GL_TEXTURE_COMPARE_MODE_ARB
:
761 case GL_TEXTURE_COMPARE_FUNC_ARB
:
762 case GL_DEPTH_TEXTURE_MODE_ARB
:
763 case GL_TEXTURE_SRGB_DECODE_EXT
:
764 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
765 case GL_TEXTURE_SWIZZLE_R_EXT
:
766 case GL_TEXTURE_SWIZZLE_G_EXT
:
767 case GL_TEXTURE_SWIZZLE_B_EXT
:
768 case GL_TEXTURE_SWIZZLE_A_EXT
:
772 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
773 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
775 p
[1] = p
[2] = p
[3] = 0;
776 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
781 /* this will generate an error if pname is illegal */
784 p
[1] = p
[2] = p
[3] = 0.0F
;
785 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
789 if (ctx
->Driver
.TexParameter
&& need_update
) {
790 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
796 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
798 GLboolean need_update
;
799 struct gl_texture_object
*texObj
;
800 GET_CURRENT_CONTEXT(ctx
);
802 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
807 case GL_TEXTURE_MIN_FILTER
:
808 case GL_TEXTURE_MAG_FILTER
:
809 case GL_TEXTURE_WRAP_S
:
810 case GL_TEXTURE_WRAP_T
:
811 case GL_TEXTURE_WRAP_R
:
812 case GL_TEXTURE_BASE_LEVEL
:
813 case GL_TEXTURE_MAX_LEVEL
:
814 case GL_GENERATE_MIPMAP_SGIS
:
815 case GL_TEXTURE_COMPARE_MODE_ARB
:
816 case GL_TEXTURE_COMPARE_FUNC_ARB
:
817 case GL_DEPTH_TEXTURE_MODE_ARB
:
818 case GL_TEXTURE_SRGB_DECODE_EXT
:
819 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
821 /* convert float param to int */
823 p
[0] = (GLint
) params
[0];
824 p
[1] = p
[2] = p
[3] = 0;
825 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
828 case GL_TEXTURE_CROP_RECT_OES
:
830 /* convert float params to int */
832 iparams
[0] = (GLint
) params
[0];
833 iparams
[1] = (GLint
) params
[1];
834 iparams
[2] = (GLint
) params
[2];
835 iparams
[3] = (GLint
) params
[3];
836 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
839 case GL_TEXTURE_SWIZZLE_R_EXT
:
840 case GL_TEXTURE_SWIZZLE_G_EXT
:
841 case GL_TEXTURE_SWIZZLE_B_EXT
:
842 case GL_TEXTURE_SWIZZLE_A_EXT
:
843 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
845 GLint p
[4] = {0, 0, 0, 0};
846 p
[0] = (GLint
) params
[0];
847 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
848 p
[1] = (GLint
) params
[1];
849 p
[2] = (GLint
) params
[2];
850 p
[3] = (GLint
) params
[3];
852 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
856 /* this will generate an error if pname is illegal */
857 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
860 if (ctx
->Driver
.TexParameter
&& need_update
) {
861 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
867 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
869 GLboolean need_update
;
870 struct gl_texture_object
*texObj
;
871 GET_CURRENT_CONTEXT(ctx
);
873 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
878 case GL_TEXTURE_MIN_LOD
:
879 case GL_TEXTURE_MAX_LOD
:
880 case GL_TEXTURE_PRIORITY
:
881 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
882 case GL_TEXTURE_LOD_BIAS
:
883 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
886 fparam
[0] = (GLfloat
) param
;
887 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
888 /* convert int param to float */
889 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
893 /* this will generate an error if pname is illegal */
897 iparam
[1] = iparam
[2] = iparam
[3] = 0;
898 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
902 if (ctx
->Driver
.TexParameter
&& need_update
) {
903 GLfloat fparam
= (GLfloat
) param
;
904 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
910 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
912 GLboolean need_update
;
913 struct gl_texture_object
*texObj
;
914 GET_CURRENT_CONTEXT(ctx
);
916 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
921 case GL_TEXTURE_BORDER_COLOR
:
923 /* convert int params to float */
925 fparams
[0] = INT_TO_FLOAT(params
[0]);
926 fparams
[1] = INT_TO_FLOAT(params
[1]);
927 fparams
[2] = INT_TO_FLOAT(params
[2]);
928 fparams
[3] = INT_TO_FLOAT(params
[3]);
929 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
932 case GL_TEXTURE_MIN_LOD
:
933 case GL_TEXTURE_MAX_LOD
:
934 case GL_TEXTURE_PRIORITY
:
935 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
936 case GL_TEXTURE_LOD_BIAS
:
937 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
939 /* convert int param to float */
941 fparams
[0] = (GLfloat
) params
[0];
942 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
943 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
947 /* this will generate an error if pname is illegal */
948 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
951 if (ctx
->Driver
.TexParameter
&& need_update
) {
953 fparams
[0] = INT_TO_FLOAT(params
[0]);
954 if (pname
== GL_TEXTURE_BORDER_COLOR
||
955 pname
== GL_TEXTURE_CROP_RECT_OES
) {
956 fparams
[1] = INT_TO_FLOAT(params
[1]);
957 fparams
[2] = INT_TO_FLOAT(params
[2]);
958 fparams
[3] = INT_TO_FLOAT(params
[3]);
960 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
966 * Set tex parameter to integer value(s). Primarily intended to set
967 * integer-valued texture border color (for integer-valued textures).
971 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
973 struct gl_texture_object
*texObj
;
974 GET_CURRENT_CONTEXT(ctx
);
976 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
981 case GL_TEXTURE_BORDER_COLOR
:
982 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
983 /* set the integer-valued border color */
984 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
987 _mesa_TexParameteriv(target
, pname
, params
);
990 /* XXX no driver hook for TexParameterIiv() yet */
995 * Set tex parameter to unsigned integer value(s). Primarily intended to set
996 * uint-valued texture border color (for integer-valued textures).
1000 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1002 struct gl_texture_object
*texObj
;
1003 GET_CURRENT_CONTEXT(ctx
);
1005 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
1010 case GL_TEXTURE_BORDER_COLOR
:
1011 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1012 /* set the unsigned integer-valued border color */
1013 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1016 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1019 /* XXX no driver hook for TexParameterIuiv() yet */
1024 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1028 case GL_PROXY_TEXTURE_1D
:
1030 case GL_PROXY_TEXTURE_2D
:
1032 case GL_PROXY_TEXTURE_3D
:
1034 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1035 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1036 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1037 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1038 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1039 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1040 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1041 return ctx
->Extensions
.ARB_texture_cube_map
;
1042 case GL_TEXTURE_RECTANGLE_NV
:
1043 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1044 return ctx
->Extensions
.NV_texture_rectangle
;
1045 case GL_TEXTURE_1D_ARRAY_EXT
:
1046 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1047 case GL_TEXTURE_2D_ARRAY_EXT
:
1048 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1049 return (ctx
->Extensions
.MESA_texture_array
||
1050 ctx
->Extensions
.EXT_texture_array
);
1051 case GL_TEXTURE_BUFFER
:
1052 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1053 * but not in earlier versions that expose ARB_texture_buffer_object.
1055 * From the ARB_texture_buffer_object spec:
1056 * "(7) Do buffer textures support texture parameters (TexParameter) or
1057 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1059 * RESOLVED: No. [...] Note that the spec edits above don't add
1060 * explicit error language for any of these cases. That is because
1061 * each of the functions enumerate the set of valid <target>
1062 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1063 * these cases means that target is not legal, and an INVALID_ENUM
1064 * error should be generated."
1066 * From the OpenGL 3.1 spec:
1067 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1069 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1070 case GL_TEXTURE_2D_MULTISAMPLE
:
1071 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1072 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1073 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1074 return ctx
->Extensions
.ARB_texture_multisample
;
1082 get_tex_level_parameter_image(struct gl_context
*ctx
,
1083 const struct gl_texture_object
*texObj
,
1084 GLenum target
, GLint level
,
1085 GLenum pname
, GLint
*params
)
1087 const struct gl_texture_image
*img
= NULL
;
1088 gl_format texFormat
;
1090 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1091 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1092 /* undefined texture image */
1093 if (pname
== GL_TEXTURE_COMPONENTS
)
1100 texFormat
= img
->TexFormat
;
1103 case GL_TEXTURE_WIDTH
:
1104 *params
= img
->Width
;
1106 case GL_TEXTURE_HEIGHT
:
1107 *params
= img
->Height
;
1109 case GL_TEXTURE_DEPTH
:
1110 *params
= img
->Depth
;
1112 case GL_TEXTURE_INTERNAL_FORMAT
:
1113 if (_mesa_is_format_compressed(texFormat
)) {
1114 /* need to return the actual compressed format */
1115 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1118 /* If the true internal format is not compressed but the user
1119 * requested a generic compressed format, we have to return the
1120 * generic base format that matches.
1122 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1124 * "If no specific compressed format is available,
1125 * internalformat is instead replaced by the corresponding base
1128 * Otherwise just return the user's requested internal format
1131 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1133 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1136 case GL_TEXTURE_BORDER
:
1137 *params
= img
->Border
;
1139 case GL_TEXTURE_RED_SIZE
:
1140 case GL_TEXTURE_GREEN_SIZE
:
1141 case GL_TEXTURE_BLUE_SIZE
:
1142 case GL_TEXTURE_ALPHA_SIZE
:
1143 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1144 *params
= _mesa_get_format_bits(texFormat
, pname
);
1148 case GL_TEXTURE_INTENSITY_SIZE
:
1149 case GL_TEXTURE_LUMINANCE_SIZE
:
1150 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1151 *params
= _mesa_get_format_bits(texFormat
, pname
);
1153 /* intensity or luminance is probably stored as RGB[A] */
1154 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1155 GL_TEXTURE_RED_SIZE
),
1156 _mesa_get_format_bits(texFormat
,
1157 GL_TEXTURE_GREEN_SIZE
));
1164 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1165 if (!ctx
->Extensions
.ARB_depth_texture
)
1167 *params
= _mesa_get_format_bits(texFormat
, pname
);
1169 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1170 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1171 !ctx
->Extensions
.ARB_framebuffer_object
)
1173 *params
= _mesa_get_format_bits(texFormat
, pname
);
1175 case GL_TEXTURE_SHARED_SIZE
:
1176 if (ctx
->Version
< 30 &&
1177 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1179 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1182 /* GL_ARB_texture_compression */
1183 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1184 if (_mesa_is_format_compressed(texFormat
) &&
1185 !_mesa_is_proxy_texture(target
)) {
1186 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1187 img
->Height
, img
->Depth
);
1190 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1191 "glGetTexLevelParameter[if]v(pname)");
1194 case GL_TEXTURE_COMPRESSED
:
1195 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1198 /* GL_ARB_texture_float */
1199 case GL_TEXTURE_RED_TYPE_ARB
:
1200 case GL_TEXTURE_GREEN_TYPE_ARB
:
1201 case GL_TEXTURE_BLUE_TYPE_ARB
:
1202 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1203 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1204 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1205 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1206 if (!ctx
->Extensions
.ARB_texture_float
)
1208 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1209 *params
= _mesa_get_format_datatype(texFormat
);
1214 /* GL_ARB_texture_multisample */
1215 case GL_TEXTURE_SAMPLES
:
1216 if (!ctx
->Extensions
.ARB_texture_multisample
)
1218 *params
= img
->NumSamples
;
1221 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1222 if (!ctx
->Extensions
.ARB_texture_multisample
)
1224 *params
= img
->FixedSampleLocations
;
1231 /* no error if we get here */
1235 _mesa_error(ctx
, GL_INVALID_ENUM
,
1236 "glGetTexLevelParameter[if]v(pname=%s)",
1237 _mesa_lookup_enum_by_nr(pname
));
1242 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1243 const struct gl_texture_object
*texObj
,
1244 GLenum pname
, GLint
*params
)
1246 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1247 gl_format texFormat
= texObj
->_BufferObjectFormat
;
1248 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1249 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1252 /* undefined texture buffer object */
1253 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1258 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1261 case GL_TEXTURE_WIDTH
:
1264 case GL_TEXTURE_HEIGHT
:
1265 case GL_TEXTURE_DEPTH
:
1266 case GL_TEXTURE_BORDER
:
1267 case GL_TEXTURE_SHARED_SIZE
:
1268 case GL_TEXTURE_COMPRESSED
:
1271 case GL_TEXTURE_INTERNAL_FORMAT
:
1272 *params
= internalFormat
;
1274 case GL_TEXTURE_RED_SIZE
:
1275 case GL_TEXTURE_GREEN_SIZE
:
1276 case GL_TEXTURE_BLUE_SIZE
:
1277 case GL_TEXTURE_ALPHA_SIZE
:
1278 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1279 *params
= _mesa_get_format_bits(texFormat
, pname
);
1283 case GL_TEXTURE_INTENSITY_SIZE
:
1284 case GL_TEXTURE_LUMINANCE_SIZE
:
1285 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1286 *params
= _mesa_get_format_bits(texFormat
, pname
);
1288 /* intensity or luminance is probably stored as RGB[A] */
1289 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1290 GL_TEXTURE_RED_SIZE
),
1291 _mesa_get_format_bits(texFormat
,
1292 GL_TEXTURE_GREEN_SIZE
));
1298 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1299 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1300 *params
= _mesa_get_format_bits(texFormat
, pname
);
1303 /* GL_ARB_texture_buffer_range */
1304 case GL_TEXTURE_BUFFER_OFFSET
:
1305 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1307 *params
= texObj
->BufferOffset
;
1309 case GL_TEXTURE_BUFFER_SIZE
:
1310 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1312 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1315 /* GL_ARB_texture_compression */
1316 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1317 /* Always illegal for GL_TEXTURE_BUFFER */
1318 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1319 "glGetTexLevelParameter[if]v(pname)");
1322 /* GL_ARB_texture_float */
1323 case GL_TEXTURE_RED_TYPE_ARB
:
1324 case GL_TEXTURE_GREEN_TYPE_ARB
:
1325 case GL_TEXTURE_BLUE_TYPE_ARB
:
1326 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1327 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1328 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1329 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1330 if (!ctx
->Extensions
.ARB_texture_float
)
1332 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1333 *params
= _mesa_get_format_datatype(texFormat
);
1342 /* no error if we get here */
1346 _mesa_error(ctx
, GL_INVALID_ENUM
,
1347 "glGetTexLevelParameter[if]v(pname=%s)",
1348 _mesa_lookup_enum_by_nr(pname
));
1353 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1354 GLenum pname
, GLfloat
*params
)
1357 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1358 *params
= (GLfloat
) iparam
;
1363 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1364 GLenum pname
, GLint
*params
)
1366 const struct gl_texture_unit
*texUnit
;
1367 struct gl_texture_object
*texObj
;
1369 GET_CURRENT_CONTEXT(ctx
);
1371 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1372 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1373 "glGetTexLevelParameteriv(current unit)");
1377 texUnit
= _mesa_get_current_tex_unit(ctx
);
1379 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1380 _mesa_error(ctx
, GL_INVALID_ENUM
,
1381 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1385 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1386 assert(maxLevels
!= 0);
1388 if (level
< 0 || level
>= maxLevels
) {
1389 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1393 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1395 if (target
== GL_TEXTURE_BUFFER
)
1396 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1398 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1403 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1405 struct gl_texture_object
*obj
;
1406 GET_CURRENT_CONTEXT(ctx
);
1408 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1412 _mesa_lock_texture(ctx
, obj
);
1414 case GL_TEXTURE_MAG_FILTER
:
1415 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1417 case GL_TEXTURE_MIN_FILTER
:
1418 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1420 case GL_TEXTURE_WRAP_S
:
1421 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1423 case GL_TEXTURE_WRAP_T
:
1424 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1426 case GL_TEXTURE_WRAP_R
:
1427 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1429 case GL_TEXTURE_BORDER_COLOR
:
1430 if (!_mesa_is_desktop_gl(ctx
))
1433 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1434 _mesa_update_state_locked(ctx
);
1435 if (_mesa_get_clamp_fragment_color(ctx
)) {
1436 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1437 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1438 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1439 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1442 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1443 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1444 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1445 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1448 case GL_TEXTURE_RESIDENT
:
1449 if (ctx
->API
!= API_OPENGL_COMPAT
)
1454 case GL_TEXTURE_PRIORITY
:
1455 if (ctx
->API
!= API_OPENGL_COMPAT
)
1458 *params
= obj
->Priority
;
1460 case GL_TEXTURE_MIN_LOD
:
1461 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1464 *params
= obj
->Sampler
.MinLod
;
1466 case GL_TEXTURE_MAX_LOD
:
1467 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1470 *params
= obj
->Sampler
.MaxLod
;
1472 case GL_TEXTURE_BASE_LEVEL
:
1473 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1476 *params
= (GLfloat
) obj
->BaseLevel
;
1478 case GL_TEXTURE_MAX_LEVEL
:
1479 *params
= (GLfloat
) obj
->MaxLevel
;
1481 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1482 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1484 *params
= obj
->Sampler
.MaxAnisotropy
;
1486 case GL_GENERATE_MIPMAP_SGIS
:
1487 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1490 *params
= (GLfloat
) obj
->GenerateMipmap
;
1492 case GL_TEXTURE_COMPARE_MODE_ARB
:
1493 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1494 && !_mesa_is_gles3(ctx
))
1496 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1498 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1499 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1500 && !_mesa_is_gles3(ctx
))
1502 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1504 case GL_DEPTH_TEXTURE_MODE_ARB
:
1505 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1506 * never existed in OpenGL ES.
1508 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1510 *params
= (GLfloat
) obj
->DepthMode
;
1512 case GL_TEXTURE_LOD_BIAS
:
1513 if (_mesa_is_gles(ctx
))
1516 *params
= obj
->Sampler
.LodBias
;
1518 case GL_TEXTURE_CROP_RECT_OES
:
1519 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1522 params
[0] = (GLfloat
) obj
->CropRect
[0];
1523 params
[1] = (GLfloat
) obj
->CropRect
[1];
1524 params
[2] = (GLfloat
) obj
->CropRect
[2];
1525 params
[3] = (GLfloat
) obj
->CropRect
[3];
1528 case GL_TEXTURE_SWIZZLE_R_EXT
:
1529 case GL_TEXTURE_SWIZZLE_G_EXT
:
1530 case GL_TEXTURE_SWIZZLE_B_EXT
:
1531 case GL_TEXTURE_SWIZZLE_A_EXT
:
1532 if ((!_mesa_is_desktop_gl(ctx
)
1533 || !ctx
->Extensions
.EXT_texture_swizzle
)
1534 && !_mesa_is_gles3(ctx
))
1536 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1539 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1540 if ((!_mesa_is_desktop_gl(ctx
)
1541 || !ctx
->Extensions
.EXT_texture_swizzle
)
1542 && !_mesa_is_gles3(ctx
)) {
1547 for (comp
= 0; comp
< 4; comp
++) {
1548 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1553 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1554 if (!_mesa_is_desktop_gl(ctx
)
1555 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1557 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1560 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1561 *params
= (GLfloat
) obj
->Immutable
;
1564 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1565 if (!_mesa_is_gles3(ctx
))
1567 *params
= (GLfloat
) obj
->ImmutableLevels
;
1570 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1571 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1573 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1576 case GL_TEXTURE_SRGB_DECODE_EXT
:
1577 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1579 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1586 /* no error if we get here */
1587 _mesa_unlock_texture(ctx
, obj
);
1591 _mesa_unlock_texture(ctx
, obj
);
1592 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1597 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1599 struct gl_texture_object
*obj
;
1600 GET_CURRENT_CONTEXT(ctx
);
1602 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1606 _mesa_lock_texture(ctx
, obj
);
1608 case GL_TEXTURE_MAG_FILTER
:
1609 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1611 case GL_TEXTURE_MIN_FILTER
:
1612 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1614 case GL_TEXTURE_WRAP_S
:
1615 *params
= (GLint
) obj
->Sampler
.WrapS
;
1617 case GL_TEXTURE_WRAP_T
:
1618 *params
= (GLint
) obj
->Sampler
.WrapT
;
1620 case GL_TEXTURE_WRAP_R
:
1621 *params
= (GLint
) obj
->Sampler
.WrapR
;
1623 case GL_TEXTURE_BORDER_COLOR
:
1624 if (!_mesa_is_desktop_gl(ctx
))
1629 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1630 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1631 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1632 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1633 params
[0] = FLOAT_TO_INT(b
[0]);
1634 params
[1] = FLOAT_TO_INT(b
[1]);
1635 params
[2] = FLOAT_TO_INT(b
[2]);
1636 params
[3] = FLOAT_TO_INT(b
[3]);
1639 case GL_TEXTURE_RESIDENT
:
1640 if (ctx
->API
!= API_OPENGL_COMPAT
)
1645 case GL_TEXTURE_PRIORITY
:
1646 if (ctx
->API
!= API_OPENGL_COMPAT
)
1649 *params
= FLOAT_TO_INT(obj
->Priority
);
1651 case GL_TEXTURE_MIN_LOD
:
1652 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1655 *params
= (GLint
) obj
->Sampler
.MinLod
;
1657 case GL_TEXTURE_MAX_LOD
:
1658 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1661 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1663 case GL_TEXTURE_BASE_LEVEL
:
1664 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1667 *params
= obj
->BaseLevel
;
1669 case GL_TEXTURE_MAX_LEVEL
:
1670 *params
= obj
->MaxLevel
;
1672 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1673 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1675 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1677 case GL_GENERATE_MIPMAP_SGIS
:
1678 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1681 *params
= (GLint
) obj
->GenerateMipmap
;
1683 case GL_TEXTURE_COMPARE_MODE_ARB
:
1684 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1685 && !_mesa_is_gles3(ctx
))
1687 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1689 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1690 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1691 && !_mesa_is_gles3(ctx
))
1693 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1695 case GL_DEPTH_TEXTURE_MODE_ARB
:
1696 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1698 *params
= (GLint
) obj
->DepthMode
;
1700 case GL_TEXTURE_LOD_BIAS
:
1701 if (_mesa_is_gles(ctx
))
1704 /* GL spec 'Data Conversions' section specifies that floating-point
1705 * value in integer Get function is rounded to nearest integer
1707 *params
= (GLint
) roundf(obj
->Sampler
.LodBias
);
1709 case GL_TEXTURE_CROP_RECT_OES
:
1710 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1713 params
[0] = obj
->CropRect
[0];
1714 params
[1] = obj
->CropRect
[1];
1715 params
[2] = obj
->CropRect
[2];
1716 params
[3] = obj
->CropRect
[3];
1718 case GL_TEXTURE_SWIZZLE_R_EXT
:
1719 case GL_TEXTURE_SWIZZLE_G_EXT
:
1720 case GL_TEXTURE_SWIZZLE_B_EXT
:
1721 case GL_TEXTURE_SWIZZLE_A_EXT
:
1722 if ((!_mesa_is_desktop_gl(ctx
)
1723 || !ctx
->Extensions
.EXT_texture_swizzle
)
1724 && !_mesa_is_gles3(ctx
))
1726 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1729 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1730 if ((!_mesa_is_desktop_gl(ctx
)
1731 || !ctx
->Extensions
.EXT_texture_swizzle
)
1732 && !_mesa_is_gles3(ctx
))
1734 COPY_4V(params
, obj
->Swizzle
);
1737 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1738 if (!_mesa_is_desktop_gl(ctx
)
1739 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1741 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1744 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1745 *params
= (GLint
) obj
->Immutable
;
1748 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1749 if (!_mesa_is_gles3(ctx
))
1751 *params
= obj
->ImmutableLevels
;
1754 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1755 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1757 *params
= obj
->RequiredTextureImageUnits
;
1760 case GL_TEXTURE_SRGB_DECODE_EXT
:
1761 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1763 *params
= obj
->Sampler
.sRGBDecode
;
1770 /* no error if we get here */
1771 _mesa_unlock_texture(ctx
, obj
);
1775 _mesa_unlock_texture(ctx
, obj
);
1776 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1780 /** New in GL 3.0 */
1782 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1784 struct gl_texture_object
*texObj
;
1785 GET_CURRENT_CONTEXT(ctx
);
1787 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1792 case GL_TEXTURE_BORDER_COLOR
:
1793 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1796 _mesa_GetTexParameteriv(target
, pname
, params
);
1801 /** New in GL 3.0 */
1803 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1805 struct gl_texture_object
*texObj
;
1806 GET_CURRENT_CONTEXT(ctx
);
1808 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1813 case GL_TEXTURE_BORDER_COLOR
:
1814 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1819 _mesa_GetTexParameteriv(target
, pname
, ip
);
1821 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1822 pname
== GL_TEXTURE_CROP_RECT_OES
) {