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(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
) && ctx
->Extensions
.EXT_texture_array
) {
162 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
165 case GL_TEXTURE_2D_ARRAY_EXT
:
166 if ((_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
167 && ctx
->Extensions
.EXT_texture_array
) {
168 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
171 case GL_TEXTURE_EXTERNAL_OES
:
172 if (_mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
) {
173 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
176 case GL_TEXTURE_CUBE_MAP_ARRAY
:
177 if (ctx
->Extensions
.ARB_texture_cube_map_array
) {
178 return texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
];
181 case GL_TEXTURE_2D_MULTISAMPLE
:
182 if (ctx
->Extensions
.ARB_texture_multisample
) {
183 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
];
186 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
187 if (ctx
->Extensions
.ARB_texture_multisample
) {
188 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
];
195 _mesa_error(ctx
, GL_INVALID_ENUM
,
196 "gl%sTexParameter(target)", get
? "Get" : "");
202 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
203 * \return -1 if error.
206 comp_to_swizzle(GLenum comp
)
228 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
231 ASSERT(swz
<= SWIZZLE_NIL
);
233 GLuint mask
= 0x7 << (3 * comp
);
234 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
241 * This is called just prior to changing any texture object state which
242 * will not effect texture completeness.
245 flush(struct gl_context
*ctx
)
247 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
252 * This is called just prior to changing any texture object state which
253 * can effect texture completeness (texture base level, max level).
254 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
255 * state flag and then mark the texture object as 'incomplete' so that any
256 * per-texture derived state gets recomputed.
259 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
261 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
262 _mesa_dirty_texobj(ctx
, texObj
);
267 target_allows_setting_sampler_parameters(GLenum target
)
270 case GL_TEXTURE_2D_MULTISAMPLE
:
271 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
281 * Set an integer-valued texture parameter
282 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
285 set_tex_parameteri(struct gl_context
*ctx
,
286 struct gl_texture_object
*texObj
,
287 GLenum pname
, const GLint
*params
)
290 case GL_TEXTURE_MIN_FILTER
:
291 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
292 goto invalid_operation
;
294 if (texObj
->Sampler
.MinFilter
== params
[0])
300 texObj
->Sampler
.MinFilter
= params
[0];
302 case GL_NEAREST_MIPMAP_NEAREST
:
303 case GL_LINEAR_MIPMAP_NEAREST
:
304 case GL_NEAREST_MIPMAP_LINEAR
:
305 case GL_LINEAR_MIPMAP_LINEAR
:
306 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
307 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
309 texObj
->Sampler
.MinFilter
= params
[0];
318 case GL_TEXTURE_MAG_FILTER
:
319 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
320 goto invalid_operation
;
322 if (texObj
->Sampler
.MagFilter
== params
[0])
327 flush(ctx
); /* does not effect completeness */
328 texObj
->Sampler
.MagFilter
= params
[0];
335 case GL_TEXTURE_WRAP_S
:
336 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
337 goto invalid_operation
;
339 if (texObj
->Sampler
.WrapS
== params
[0])
341 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
343 texObj
->Sampler
.WrapS
= params
[0];
348 case GL_TEXTURE_WRAP_T
:
349 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
350 goto invalid_operation
;
352 if (texObj
->Sampler
.WrapT
== params
[0])
354 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
356 texObj
->Sampler
.WrapT
= params
[0];
361 case GL_TEXTURE_WRAP_R
:
362 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
363 goto invalid_operation
;
365 if (texObj
->Sampler
.WrapR
== params
[0])
367 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
369 texObj
->Sampler
.WrapR
= params
[0];
374 case GL_TEXTURE_BASE_LEVEL
:
375 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
378 if (texObj
->BaseLevel
== params
[0])
381 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
382 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
383 goto invalid_operation
;
386 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
387 _mesa_error(ctx
, GL_INVALID_VALUE
,
388 "glTexParameter(param=%d)", params
[0]);
391 incomplete(ctx
, texObj
);
393 /** See note about ARB_texture_storage below */
394 if (texObj
->Immutable
)
395 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
397 texObj
->BaseLevel
= params
[0];
401 case GL_TEXTURE_MAX_LEVEL
:
402 if (texObj
->MaxLevel
== params
[0])
405 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
406 _mesa_error(ctx
, GL_INVALID_VALUE
,
407 "glTexParameter(param=%d)", params
[0]);
410 incomplete(ctx
, texObj
);
412 /** From ARB_texture_storage:
413 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
414 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
415 * the range [level_base, <levels> - 1], where <levels> is the parameter
416 * passed the call to TexStorage* for the texture object.
418 if (texObj
->Immutable
)
419 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
420 texObj
->ImmutableLevels
- 1);
422 texObj
->MaxLevel
= params
[0];
426 case GL_GENERATE_MIPMAP_SGIS
:
427 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
430 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
432 if (texObj
->GenerateMipmap
!= params
[0]) {
434 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
439 case GL_TEXTURE_COMPARE_MODE_ARB
:
440 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
441 || _mesa_is_gles3(ctx
)) {
443 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
444 goto invalid_operation
;
446 if (texObj
->Sampler
.CompareMode
== params
[0])
448 if (params
[0] == GL_NONE
||
449 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
451 texObj
->Sampler
.CompareMode
= params
[0];
458 case GL_TEXTURE_COMPARE_FUNC_ARB
:
459 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
460 || _mesa_is_gles3(ctx
)) {
462 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
463 goto invalid_operation
;
465 if (texObj
->Sampler
.CompareFunc
== params
[0])
477 texObj
->Sampler
.CompareFunc
= params
[0];
485 case GL_DEPTH_TEXTURE_MODE_ARB
:
486 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
487 * existed in OpenGL ES.
489 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
490 if (texObj
->DepthMode
== params
[0])
492 if (params
[0] == GL_LUMINANCE
||
493 params
[0] == GL_INTENSITY
||
494 params
[0] == GL_ALPHA
||
495 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
497 texObj
->DepthMode
= params
[0];
504 case GL_TEXTURE_CROP_RECT_OES
:
505 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
508 texObj
->CropRect
[0] = params
[0];
509 texObj
->CropRect
[1] = params
[1];
510 texObj
->CropRect
[2] = params
[2];
511 texObj
->CropRect
[3] = params
[3];
514 case GL_TEXTURE_SWIZZLE_R_EXT
:
515 case GL_TEXTURE_SWIZZLE_G_EXT
:
516 case GL_TEXTURE_SWIZZLE_B_EXT
:
517 case GL_TEXTURE_SWIZZLE_A_EXT
:
518 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
519 || _mesa_is_gles3(ctx
)) {
520 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
521 const GLint swz
= comp_to_swizzle(params
[0]);
523 _mesa_error(ctx
, GL_INVALID_OPERATION
,
524 "glTexParameter(swizzle 0x%x)", params
[0]);
530 texObj
->Swizzle
[comp
] = params
[0];
531 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
536 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
537 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
538 || _mesa_is_gles3(ctx
)) {
541 for (comp
= 0; comp
< 4; comp
++) {
542 const GLint swz
= comp_to_swizzle(params
[comp
]);
544 texObj
->Swizzle
[comp
] = params
[comp
];
545 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
549 "glTexParameter(swizzle 0x%x)", params
[comp
]);
557 case GL_TEXTURE_SRGB_DECODE_EXT
:
558 if (_mesa_is_desktop_gl(ctx
)
559 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
560 GLenum decode
= params
[0];
562 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
563 goto invalid_operation
;
565 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
566 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
568 texObj
->Sampler
.sRGBDecode
= decode
;
575 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
576 if (_mesa_is_desktop_gl(ctx
)
577 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
578 GLenum param
= params
[0];
580 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
581 goto invalid_operation
;
583 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
586 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
588 texObj
->Sampler
.CubeMapSeamless
= param
;
599 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
600 _mesa_lookup_enum_by_nr(pname
));
604 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
605 _mesa_lookup_enum_by_nr(params
[0]));
609 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
610 _mesa_lookup_enum_by_nr(pname
));
616 * Set a float-valued texture parameter
617 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
620 set_tex_parameterf(struct gl_context
*ctx
,
621 struct gl_texture_object
*texObj
,
622 GLenum pname
, const GLfloat
*params
)
625 case GL_TEXTURE_MIN_LOD
:
626 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
629 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
630 goto invalid_operation
;
632 if (texObj
->Sampler
.MinLod
== params
[0])
635 texObj
->Sampler
.MinLod
= params
[0];
638 case GL_TEXTURE_MAX_LOD
:
639 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
642 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
643 goto invalid_operation
;
645 if (texObj
->Sampler
.MaxLod
== params
[0])
648 texObj
->Sampler
.MaxLod
= params
[0];
651 case GL_TEXTURE_PRIORITY
:
652 if (ctx
->API
!= API_OPENGL_COMPAT
)
656 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
659 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
660 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
661 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
662 goto invalid_operation
;
664 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
666 if (params
[0] < 1.0) {
667 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
671 /* clamp to max, that's what NVIDIA does */
672 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
673 ctx
->Const
.MaxTextureMaxAnisotropy
);
677 static GLuint count
= 0;
683 case GL_TEXTURE_LOD_BIAS
:
684 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
685 if (_mesa_is_gles(ctx
))
688 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
689 goto invalid_operation
;
691 if (texObj
->Sampler
.LodBias
!= params
[0]) {
693 texObj
->Sampler
.LodBias
= params
[0];
698 case GL_TEXTURE_BORDER_COLOR
:
699 if (!_mesa_is_desktop_gl(ctx
))
702 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
703 goto invalid_operation
;
706 /* ARB_texture_float disables clamping */
707 if (ctx
->Extensions
.ARB_texture_float
) {
708 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
709 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
710 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
711 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
713 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
714 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
715 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
716 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
726 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
727 _mesa_lookup_enum_by_nr(pname
));
731 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
732 _mesa_lookup_enum_by_nr(pname
));
738 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
740 GLboolean need_update
;
741 struct gl_texture_object
*texObj
;
742 GET_CURRENT_CONTEXT(ctx
);
744 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
749 case GL_TEXTURE_MIN_FILTER
:
750 case GL_TEXTURE_MAG_FILTER
:
751 case GL_TEXTURE_WRAP_S
:
752 case GL_TEXTURE_WRAP_T
:
753 case GL_TEXTURE_WRAP_R
:
754 case GL_TEXTURE_BASE_LEVEL
:
755 case GL_TEXTURE_MAX_LEVEL
:
756 case GL_GENERATE_MIPMAP_SGIS
:
757 case GL_TEXTURE_COMPARE_MODE_ARB
:
758 case GL_TEXTURE_COMPARE_FUNC_ARB
:
759 case GL_DEPTH_TEXTURE_MODE_ARB
:
760 case GL_TEXTURE_SRGB_DECODE_EXT
:
761 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
762 case GL_TEXTURE_SWIZZLE_R_EXT
:
763 case GL_TEXTURE_SWIZZLE_G_EXT
:
764 case GL_TEXTURE_SWIZZLE_B_EXT
:
765 case GL_TEXTURE_SWIZZLE_A_EXT
:
769 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
770 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
772 p
[1] = p
[2] = p
[3] = 0;
773 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
778 /* this will generate an error if pname is illegal */
781 p
[1] = p
[2] = p
[3] = 0.0F
;
782 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
786 if (ctx
->Driver
.TexParameter
&& need_update
) {
787 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, ¶m
);
793 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
795 GLboolean need_update
;
796 struct gl_texture_object
*texObj
;
797 GET_CURRENT_CONTEXT(ctx
);
799 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
804 case GL_TEXTURE_MIN_FILTER
:
805 case GL_TEXTURE_MAG_FILTER
:
806 case GL_TEXTURE_WRAP_S
:
807 case GL_TEXTURE_WRAP_T
:
808 case GL_TEXTURE_WRAP_R
:
809 case GL_TEXTURE_BASE_LEVEL
:
810 case GL_TEXTURE_MAX_LEVEL
:
811 case GL_GENERATE_MIPMAP_SGIS
:
812 case GL_TEXTURE_COMPARE_MODE_ARB
:
813 case GL_TEXTURE_COMPARE_FUNC_ARB
:
814 case GL_DEPTH_TEXTURE_MODE_ARB
:
815 case GL_TEXTURE_SRGB_DECODE_EXT
:
816 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
818 /* convert float param to int */
820 p
[0] = (GLint
) params
[0];
821 p
[1] = p
[2] = p
[3] = 0;
822 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
825 case GL_TEXTURE_CROP_RECT_OES
:
827 /* convert float params to int */
829 iparams
[0] = (GLint
) params
[0];
830 iparams
[1] = (GLint
) params
[1];
831 iparams
[2] = (GLint
) params
[2];
832 iparams
[3] = (GLint
) params
[3];
833 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
836 case GL_TEXTURE_SWIZZLE_R_EXT
:
837 case GL_TEXTURE_SWIZZLE_G_EXT
:
838 case GL_TEXTURE_SWIZZLE_B_EXT
:
839 case GL_TEXTURE_SWIZZLE_A_EXT
:
840 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
842 GLint p
[4] = {0, 0, 0, 0};
843 p
[0] = (GLint
) params
[0];
844 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
845 p
[1] = (GLint
) params
[1];
846 p
[2] = (GLint
) params
[2];
847 p
[3] = (GLint
) params
[3];
849 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
853 /* this will generate an error if pname is illegal */
854 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
857 if (ctx
->Driver
.TexParameter
&& need_update
) {
858 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, params
);
864 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
866 GLboolean need_update
;
867 struct gl_texture_object
*texObj
;
868 GET_CURRENT_CONTEXT(ctx
);
870 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
875 case GL_TEXTURE_MIN_LOD
:
876 case GL_TEXTURE_MAX_LOD
:
877 case GL_TEXTURE_PRIORITY
:
878 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
879 case GL_TEXTURE_LOD_BIAS
:
880 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
883 fparam
[0] = (GLfloat
) param
;
884 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
885 /* convert int param to float */
886 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
890 /* this will generate an error if pname is illegal */
894 iparam
[1] = iparam
[2] = iparam
[3] = 0;
895 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
899 if (ctx
->Driver
.TexParameter
&& need_update
) {
900 GLfloat fparam
= (GLfloat
) param
;
901 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, &fparam
);
907 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
909 GLboolean need_update
;
910 struct gl_texture_object
*texObj
;
911 GET_CURRENT_CONTEXT(ctx
);
913 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
918 case GL_TEXTURE_BORDER_COLOR
:
920 /* convert int params to float */
922 fparams
[0] = INT_TO_FLOAT(params
[0]);
923 fparams
[1] = INT_TO_FLOAT(params
[1]);
924 fparams
[2] = INT_TO_FLOAT(params
[2]);
925 fparams
[3] = INT_TO_FLOAT(params
[3]);
926 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
929 case GL_TEXTURE_MIN_LOD
:
930 case GL_TEXTURE_MAX_LOD
:
931 case GL_TEXTURE_PRIORITY
:
932 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
933 case GL_TEXTURE_LOD_BIAS
:
934 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
936 /* convert int param to float */
938 fparams
[0] = (GLfloat
) params
[0];
939 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
940 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
944 /* this will generate an error if pname is illegal */
945 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
948 if (ctx
->Driver
.TexParameter
&& need_update
) {
950 fparams
[0] = INT_TO_FLOAT(params
[0]);
951 if (pname
== GL_TEXTURE_BORDER_COLOR
||
952 pname
== GL_TEXTURE_CROP_RECT_OES
) {
953 fparams
[1] = INT_TO_FLOAT(params
[1]);
954 fparams
[2] = INT_TO_FLOAT(params
[2]);
955 fparams
[3] = INT_TO_FLOAT(params
[3]);
957 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, fparams
);
963 * Set tex parameter to integer value(s). Primarily intended to set
964 * integer-valued texture border color (for integer-valued textures).
968 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
970 struct gl_texture_object
*texObj
;
971 GET_CURRENT_CONTEXT(ctx
);
973 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
978 case GL_TEXTURE_BORDER_COLOR
:
979 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
980 /* set the integer-valued border color */
981 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
984 _mesa_TexParameteriv(target
, pname
, params
);
987 /* XXX no driver hook for TexParameterIiv() yet */
992 * Set tex parameter to unsigned integer value(s). Primarily intended to set
993 * uint-valued texture border color (for integer-valued textures).
997 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
999 struct gl_texture_object
*texObj
;
1000 GET_CURRENT_CONTEXT(ctx
);
1002 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
1007 case GL_TEXTURE_BORDER_COLOR
:
1008 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1009 /* set the unsigned integer-valued border color */
1010 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1013 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1016 /* XXX no driver hook for TexParameterIuiv() yet */
1021 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1025 case GL_PROXY_TEXTURE_1D
:
1027 case GL_PROXY_TEXTURE_2D
:
1029 case GL_PROXY_TEXTURE_3D
:
1031 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1032 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1033 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1034 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1035 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1036 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1037 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1038 return ctx
->Extensions
.ARB_texture_cube_map
;
1039 case GL_TEXTURE_RECTANGLE_NV
:
1040 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1041 return ctx
->Extensions
.NV_texture_rectangle
;
1042 case GL_TEXTURE_1D_ARRAY_EXT
:
1043 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1044 case GL_TEXTURE_2D_ARRAY_EXT
:
1045 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1046 return ctx
->Extensions
.EXT_texture_array
;
1047 case GL_TEXTURE_BUFFER
:
1048 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1049 * but not in earlier versions that expose ARB_texture_buffer_object.
1051 * From the ARB_texture_buffer_object spec:
1052 * "(7) Do buffer textures support texture parameters (TexParameter) or
1053 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1055 * RESOLVED: No. [...] Note that the spec edits above don't add
1056 * explicit error language for any of these cases. That is because
1057 * each of the functions enumerate the set of valid <target>
1058 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1059 * these cases means that target is not legal, and an INVALID_ENUM
1060 * error should be generated."
1062 * From the OpenGL 3.1 spec:
1063 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1065 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1066 case GL_TEXTURE_2D_MULTISAMPLE
:
1067 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1068 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1069 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1070 return ctx
->Extensions
.ARB_texture_multisample
;
1078 get_tex_level_parameter_image(struct gl_context
*ctx
,
1079 const struct gl_texture_object
*texObj
,
1080 GLenum target
, GLint level
,
1081 GLenum pname
, GLint
*params
)
1083 const struct gl_texture_image
*img
= NULL
;
1084 mesa_format texFormat
;
1086 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1087 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1088 /* undefined texture image */
1089 if (pname
== GL_TEXTURE_COMPONENTS
)
1096 texFormat
= img
->TexFormat
;
1099 case GL_TEXTURE_WIDTH
:
1100 *params
= img
->Width
;
1102 case GL_TEXTURE_HEIGHT
:
1103 *params
= img
->Height
;
1105 case GL_TEXTURE_DEPTH
:
1106 *params
= img
->Depth
;
1108 case GL_TEXTURE_INTERNAL_FORMAT
:
1109 if (_mesa_is_format_compressed(texFormat
)) {
1110 /* need to return the actual compressed format */
1111 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1114 /* If the true internal format is not compressed but the user
1115 * requested a generic compressed format, we have to return the
1116 * generic base format that matches.
1118 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1120 * "If no specific compressed format is available,
1121 * internalformat is instead replaced by the corresponding base
1124 * Otherwise just return the user's requested internal format
1127 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1129 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1132 case GL_TEXTURE_BORDER
:
1133 *params
= img
->Border
;
1135 case GL_TEXTURE_RED_SIZE
:
1136 case GL_TEXTURE_GREEN_SIZE
:
1137 case GL_TEXTURE_BLUE_SIZE
:
1138 case GL_TEXTURE_ALPHA_SIZE
:
1139 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1140 *params
= _mesa_get_format_bits(texFormat
, pname
);
1144 case GL_TEXTURE_INTENSITY_SIZE
:
1145 case GL_TEXTURE_LUMINANCE_SIZE
:
1146 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1147 *params
= _mesa_get_format_bits(texFormat
, pname
);
1149 /* intensity or luminance is probably stored as RGB[A] */
1150 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1151 GL_TEXTURE_RED_SIZE
),
1152 _mesa_get_format_bits(texFormat
,
1153 GL_TEXTURE_GREEN_SIZE
));
1160 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1161 if (!ctx
->Extensions
.ARB_depth_texture
)
1163 *params
= _mesa_get_format_bits(texFormat
, pname
);
1165 case GL_TEXTURE_STENCIL_SIZE
:
1166 *params
= _mesa_get_format_bits(texFormat
, pname
);
1168 case GL_TEXTURE_SHARED_SIZE
:
1169 if (ctx
->Version
< 30 &&
1170 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1172 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1175 /* GL_ARB_texture_compression */
1176 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1177 if (_mesa_is_format_compressed(texFormat
) &&
1178 !_mesa_is_proxy_texture(target
)) {
1179 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1180 img
->Height
, img
->Depth
);
1183 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1184 "glGetTexLevelParameter[if]v(pname)");
1187 case GL_TEXTURE_COMPRESSED
:
1188 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1191 /* GL_ARB_texture_float */
1192 case GL_TEXTURE_RED_TYPE_ARB
:
1193 case GL_TEXTURE_GREEN_TYPE_ARB
:
1194 case GL_TEXTURE_BLUE_TYPE_ARB
:
1195 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1196 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1197 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1198 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1199 if (!ctx
->Extensions
.ARB_texture_float
)
1201 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1202 *params
= _mesa_get_format_datatype(texFormat
);
1207 /* GL_ARB_texture_multisample */
1208 case GL_TEXTURE_SAMPLES
:
1209 if (!ctx
->Extensions
.ARB_texture_multisample
)
1211 *params
= img
->NumSamples
;
1214 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1215 if (!ctx
->Extensions
.ARB_texture_multisample
)
1217 *params
= img
->FixedSampleLocations
;
1224 /* no error if we get here */
1228 _mesa_error(ctx
, GL_INVALID_ENUM
,
1229 "glGetTexLevelParameter[if]v(pname=%s)",
1230 _mesa_lookup_enum_by_nr(pname
));
1235 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1236 const struct gl_texture_object
*texObj
,
1237 GLenum pname
, GLint
*params
)
1239 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1240 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1241 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1242 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1245 /* undefined texture buffer object */
1246 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1251 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1254 case GL_TEXTURE_WIDTH
:
1257 case GL_TEXTURE_HEIGHT
:
1258 case GL_TEXTURE_DEPTH
:
1259 case GL_TEXTURE_BORDER
:
1260 case GL_TEXTURE_SHARED_SIZE
:
1261 case GL_TEXTURE_COMPRESSED
:
1264 case GL_TEXTURE_INTERNAL_FORMAT
:
1265 *params
= internalFormat
;
1267 case GL_TEXTURE_RED_SIZE
:
1268 case GL_TEXTURE_GREEN_SIZE
:
1269 case GL_TEXTURE_BLUE_SIZE
:
1270 case GL_TEXTURE_ALPHA_SIZE
:
1271 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1272 *params
= _mesa_get_format_bits(texFormat
, pname
);
1276 case GL_TEXTURE_INTENSITY_SIZE
:
1277 case GL_TEXTURE_LUMINANCE_SIZE
:
1278 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1279 *params
= _mesa_get_format_bits(texFormat
, pname
);
1281 /* intensity or luminance is probably stored as RGB[A] */
1282 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1283 GL_TEXTURE_RED_SIZE
),
1284 _mesa_get_format_bits(texFormat
,
1285 GL_TEXTURE_GREEN_SIZE
));
1291 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1292 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1293 *params
= _mesa_get_format_bits(texFormat
, pname
);
1296 /* GL_ARB_texture_buffer_range */
1297 case GL_TEXTURE_BUFFER_OFFSET
:
1298 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1300 *params
= texObj
->BufferOffset
;
1302 case GL_TEXTURE_BUFFER_SIZE
:
1303 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1305 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1308 /* GL_ARB_texture_compression */
1309 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1310 /* Always illegal for GL_TEXTURE_BUFFER */
1311 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1312 "glGetTexLevelParameter[if]v(pname)");
1315 /* GL_ARB_texture_float */
1316 case GL_TEXTURE_RED_TYPE_ARB
:
1317 case GL_TEXTURE_GREEN_TYPE_ARB
:
1318 case GL_TEXTURE_BLUE_TYPE_ARB
:
1319 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1320 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1321 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1322 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1323 if (!ctx
->Extensions
.ARB_texture_float
)
1325 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1326 *params
= _mesa_get_format_datatype(texFormat
);
1335 /* no error if we get here */
1339 _mesa_error(ctx
, GL_INVALID_ENUM
,
1340 "glGetTexLevelParameter[if]v(pname=%s)",
1341 _mesa_lookup_enum_by_nr(pname
));
1346 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1347 GLenum pname
, GLfloat
*params
)
1350 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1351 *params
= (GLfloat
) iparam
;
1356 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1357 GLenum pname
, GLint
*params
)
1359 struct gl_texture_object
*texObj
;
1361 GET_CURRENT_CONTEXT(ctx
);
1363 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1364 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1365 "glGetTexLevelParameteriv(current unit)");
1369 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1370 _mesa_error(ctx
, GL_INVALID_ENUM
,
1371 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1375 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1376 assert(maxLevels
!= 0);
1378 if (level
< 0 || level
>= maxLevels
) {
1379 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1383 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1385 if (target
== GL_TEXTURE_BUFFER
)
1386 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1388 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1393 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1395 struct gl_texture_object
*obj
;
1396 GET_CURRENT_CONTEXT(ctx
);
1398 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1402 _mesa_lock_texture(ctx
, obj
);
1404 case GL_TEXTURE_MAG_FILTER
:
1405 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1407 case GL_TEXTURE_MIN_FILTER
:
1408 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1410 case GL_TEXTURE_WRAP_S
:
1411 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1413 case GL_TEXTURE_WRAP_T
:
1414 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1416 case GL_TEXTURE_WRAP_R
:
1417 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1419 case GL_TEXTURE_BORDER_COLOR
:
1420 if (!_mesa_is_desktop_gl(ctx
))
1423 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1424 _mesa_update_state_locked(ctx
);
1425 if (_mesa_get_clamp_fragment_color(ctx
)) {
1426 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1427 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1428 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1429 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1432 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1433 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1434 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1435 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1438 case GL_TEXTURE_RESIDENT
:
1439 if (ctx
->API
!= API_OPENGL_COMPAT
)
1444 case GL_TEXTURE_PRIORITY
:
1445 if (ctx
->API
!= API_OPENGL_COMPAT
)
1448 *params
= obj
->Priority
;
1450 case GL_TEXTURE_MIN_LOD
:
1451 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1454 *params
= obj
->Sampler
.MinLod
;
1456 case GL_TEXTURE_MAX_LOD
:
1457 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1460 *params
= obj
->Sampler
.MaxLod
;
1462 case GL_TEXTURE_BASE_LEVEL
:
1463 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1466 *params
= (GLfloat
) obj
->BaseLevel
;
1468 case GL_TEXTURE_MAX_LEVEL
:
1469 *params
= (GLfloat
) obj
->MaxLevel
;
1471 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1472 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1474 *params
= obj
->Sampler
.MaxAnisotropy
;
1476 case GL_GENERATE_MIPMAP_SGIS
:
1477 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1480 *params
= (GLfloat
) obj
->GenerateMipmap
;
1482 case GL_TEXTURE_COMPARE_MODE_ARB
:
1483 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1484 && !_mesa_is_gles3(ctx
))
1486 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1488 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1489 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1490 && !_mesa_is_gles3(ctx
))
1492 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1494 case GL_DEPTH_TEXTURE_MODE_ARB
:
1495 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1496 * never existed in OpenGL ES.
1498 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1500 *params
= (GLfloat
) obj
->DepthMode
;
1502 case GL_TEXTURE_LOD_BIAS
:
1503 if (_mesa_is_gles(ctx
))
1506 *params
= obj
->Sampler
.LodBias
;
1508 case GL_TEXTURE_CROP_RECT_OES
:
1509 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1512 params
[0] = (GLfloat
) obj
->CropRect
[0];
1513 params
[1] = (GLfloat
) obj
->CropRect
[1];
1514 params
[2] = (GLfloat
) obj
->CropRect
[2];
1515 params
[3] = (GLfloat
) obj
->CropRect
[3];
1518 case GL_TEXTURE_SWIZZLE_R_EXT
:
1519 case GL_TEXTURE_SWIZZLE_G_EXT
:
1520 case GL_TEXTURE_SWIZZLE_B_EXT
:
1521 case GL_TEXTURE_SWIZZLE_A_EXT
:
1522 if ((!_mesa_is_desktop_gl(ctx
)
1523 || !ctx
->Extensions
.EXT_texture_swizzle
)
1524 && !_mesa_is_gles3(ctx
))
1526 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1529 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1530 if ((!_mesa_is_desktop_gl(ctx
)
1531 || !ctx
->Extensions
.EXT_texture_swizzle
)
1532 && !_mesa_is_gles3(ctx
)) {
1537 for (comp
= 0; comp
< 4; comp
++) {
1538 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1543 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1544 if (!_mesa_is_desktop_gl(ctx
)
1545 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1547 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1550 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1551 *params
= (GLfloat
) obj
->Immutable
;
1554 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1555 if (_mesa_is_gles3(ctx
) ||
1556 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1557 *params
= (GLfloat
) obj
->ImmutableLevels
;
1562 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1563 if (!ctx
->Extensions
.ARB_texture_view
)
1565 *params
= (GLfloat
) obj
->MinLevel
;
1568 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1569 if (!ctx
->Extensions
.ARB_texture_view
)
1571 *params
= (GLfloat
) obj
->NumLevels
;
1574 case GL_TEXTURE_VIEW_MIN_LAYER
:
1575 if (!ctx
->Extensions
.ARB_texture_view
)
1577 *params
= (GLfloat
) obj
->MinLayer
;
1580 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1581 if (!ctx
->Extensions
.ARB_texture_view
)
1583 *params
= (GLfloat
) obj
->NumLayers
;
1586 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1587 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1589 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1592 case GL_TEXTURE_SRGB_DECODE_EXT
:
1593 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1595 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1602 /* no error if we get here */
1603 _mesa_unlock_texture(ctx
, obj
);
1607 _mesa_unlock_texture(ctx
, obj
);
1608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1613 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1615 struct gl_texture_object
*obj
;
1616 GET_CURRENT_CONTEXT(ctx
);
1618 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1622 _mesa_lock_texture(ctx
, obj
);
1624 case GL_TEXTURE_MAG_FILTER
:
1625 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1627 case GL_TEXTURE_MIN_FILTER
:
1628 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1630 case GL_TEXTURE_WRAP_S
:
1631 *params
= (GLint
) obj
->Sampler
.WrapS
;
1633 case GL_TEXTURE_WRAP_T
:
1634 *params
= (GLint
) obj
->Sampler
.WrapT
;
1636 case GL_TEXTURE_WRAP_R
:
1637 *params
= (GLint
) obj
->Sampler
.WrapR
;
1639 case GL_TEXTURE_BORDER_COLOR
:
1640 if (!_mesa_is_desktop_gl(ctx
))
1645 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1646 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1647 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1648 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1649 params
[0] = FLOAT_TO_INT(b
[0]);
1650 params
[1] = FLOAT_TO_INT(b
[1]);
1651 params
[2] = FLOAT_TO_INT(b
[2]);
1652 params
[3] = FLOAT_TO_INT(b
[3]);
1655 case GL_TEXTURE_RESIDENT
:
1656 if (ctx
->API
!= API_OPENGL_COMPAT
)
1661 case GL_TEXTURE_PRIORITY
:
1662 if (ctx
->API
!= API_OPENGL_COMPAT
)
1665 *params
= FLOAT_TO_INT(obj
->Priority
);
1667 case GL_TEXTURE_MIN_LOD
:
1668 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1671 *params
= (GLint
) obj
->Sampler
.MinLod
;
1673 case GL_TEXTURE_MAX_LOD
:
1674 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1677 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1679 case GL_TEXTURE_BASE_LEVEL
:
1680 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1683 *params
= obj
->BaseLevel
;
1685 case GL_TEXTURE_MAX_LEVEL
:
1686 *params
= obj
->MaxLevel
;
1688 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1689 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1691 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1693 case GL_GENERATE_MIPMAP_SGIS
:
1694 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1697 *params
= (GLint
) obj
->GenerateMipmap
;
1699 case GL_TEXTURE_COMPARE_MODE_ARB
:
1700 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1701 && !_mesa_is_gles3(ctx
))
1703 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1705 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1706 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1707 && !_mesa_is_gles3(ctx
))
1709 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1711 case GL_DEPTH_TEXTURE_MODE_ARB
:
1712 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1714 *params
= (GLint
) obj
->DepthMode
;
1716 case GL_TEXTURE_LOD_BIAS
:
1717 if (_mesa_is_gles(ctx
))
1720 /* GL spec 'Data Conversions' section specifies that floating-point
1721 * value in integer Get function is rounded to nearest integer
1723 *params
= IROUND(obj
->Sampler
.LodBias
);
1725 case GL_TEXTURE_CROP_RECT_OES
:
1726 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1729 params
[0] = obj
->CropRect
[0];
1730 params
[1] = obj
->CropRect
[1];
1731 params
[2] = obj
->CropRect
[2];
1732 params
[3] = obj
->CropRect
[3];
1734 case GL_TEXTURE_SWIZZLE_R_EXT
:
1735 case GL_TEXTURE_SWIZZLE_G_EXT
:
1736 case GL_TEXTURE_SWIZZLE_B_EXT
:
1737 case GL_TEXTURE_SWIZZLE_A_EXT
:
1738 if ((!_mesa_is_desktop_gl(ctx
)
1739 || !ctx
->Extensions
.EXT_texture_swizzle
)
1740 && !_mesa_is_gles3(ctx
))
1742 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1745 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1746 if ((!_mesa_is_desktop_gl(ctx
)
1747 || !ctx
->Extensions
.EXT_texture_swizzle
)
1748 && !_mesa_is_gles3(ctx
))
1750 COPY_4V(params
, obj
->Swizzle
);
1753 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1754 if (!_mesa_is_desktop_gl(ctx
)
1755 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1757 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1760 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1761 *params
= (GLint
) obj
->Immutable
;
1764 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1765 if (_mesa_is_gles3(ctx
) ||
1766 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1767 *params
= obj
->ImmutableLevels
;
1772 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1773 if (!ctx
->Extensions
.ARB_texture_view
)
1775 *params
= (GLint
) obj
->MinLevel
;
1778 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1779 if (!ctx
->Extensions
.ARB_texture_view
)
1781 *params
= (GLint
) obj
->NumLevels
;
1784 case GL_TEXTURE_VIEW_MIN_LAYER
:
1785 if (!ctx
->Extensions
.ARB_texture_view
)
1787 *params
= (GLint
) obj
->MinLayer
;
1790 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1791 if (!ctx
->Extensions
.ARB_texture_view
)
1793 *params
= (GLint
) obj
->NumLayers
;
1796 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1797 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1799 *params
= obj
->RequiredTextureImageUnits
;
1802 case GL_TEXTURE_SRGB_DECODE_EXT
:
1803 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1805 *params
= obj
->Sampler
.sRGBDecode
;
1808 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1809 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1811 *params
= obj
->ImageFormatCompatibilityType
;
1818 /* no error if we get here */
1819 _mesa_unlock_texture(ctx
, obj
);
1823 _mesa_unlock_texture(ctx
, obj
);
1824 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1828 /** New in GL 3.0 */
1830 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1832 struct gl_texture_object
*texObj
;
1833 GET_CURRENT_CONTEXT(ctx
);
1835 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1840 case GL_TEXTURE_BORDER_COLOR
:
1841 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1844 _mesa_GetTexParameteriv(target
, pname
, params
);
1849 /** New in GL 3.0 */
1851 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1853 struct gl_texture_object
*texObj
;
1854 GET_CURRENT_CONTEXT(ctx
);
1856 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1861 case GL_TEXTURE_BORDER_COLOR
:
1862 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1867 _mesa_GetTexParameteriv(target
, pname
, ip
);
1869 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1870 pname
== GL_TEXTURE_CROP_RECT_OES
) {