2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
88 supported
= is_desktop_gl
89 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
90 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
91 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
94 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
95 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
96 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
97 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
106 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
113 * Get current texture object for given target.
114 * Return NULL if any error (and record the error).
115 * Note that this is different from _mesa_select_tex_object() in that proxy
116 * targets are not accepted.
117 * Only the glGetTexLevelParameter() functions accept proxy targets.
119 static struct gl_texture_object
*
120 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
122 struct gl_texture_unit
*texUnit
;
124 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
125 _mesa_error(ctx
, GL_INVALID_OPERATION
,
126 "gl%sTexParameter(current unit)", get
? "Get" : "");
130 texUnit
= _mesa_get_current_tex_unit(ctx
);
134 if (_mesa_is_desktop_gl(ctx
))
135 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
138 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
140 if (ctx
->API
!= API_OPENGLES
)
141 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
143 case GL_TEXTURE_CUBE_MAP
:
144 if (ctx
->Extensions
.ARB_texture_cube_map
) {
145 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
148 case GL_TEXTURE_RECTANGLE_NV
:
149 if (_mesa_is_desktop_gl(ctx
)
150 && ctx
->Extensions
.NV_texture_rectangle
) {
151 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
154 case GL_TEXTURE_1D_ARRAY_EXT
:
155 if (_mesa_is_desktop_gl(ctx
)
156 && (ctx
->Extensions
.MESA_texture_array
||
157 ctx
->Extensions
.EXT_texture_array
)) {
158 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
161 case GL_TEXTURE_2D_ARRAY_EXT
:
162 if ((_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
163 && (ctx
->Extensions
.MESA_texture_array
||
164 ctx
->Extensions
.EXT_texture_array
)) {
165 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
168 case GL_TEXTURE_EXTERNAL_OES
:
169 if (_mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
) {
170 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
173 case GL_TEXTURE_CUBE_MAP_ARRAY
:
174 if (ctx
->Extensions
.ARB_texture_cube_map_array
) {
175 return texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
];
178 case GL_TEXTURE_2D_MULTISAMPLE
:
179 if (ctx
->Extensions
.ARB_texture_storage_multisample
) {
180 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
];
183 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
184 if (ctx
->Extensions
.ARB_texture_storage_multisample
) {
185 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
];
192 _mesa_error(ctx
, GL_INVALID_ENUM
,
193 "gl%sTexParameter(target)", get
? "Get" : "");
199 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
200 * \return -1 if error.
203 comp_to_swizzle(GLenum comp
)
225 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
228 ASSERT(swz
<= SWIZZLE_NIL
);
230 GLuint mask
= 0x7 << (3 * comp
);
231 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
238 * This is called just prior to changing any texture object state which
239 * will not effect texture completeness.
242 flush(struct gl_context
*ctx
)
244 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
249 * This is called just prior to changing any texture object state which
250 * can effect texture completeness (texture base level, max level).
251 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
252 * state flag and then mark the texture object as 'incomplete' so that any
253 * per-texture derived state gets recomputed.
256 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
258 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
259 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
264 target_allows_setting_sampler_parameters(GLenum target
)
267 case GL_TEXTURE_2D_MULTISAMPLE
:
268 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
278 * Set an integer-valued texture parameter
279 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
282 set_tex_parameteri(struct gl_context
*ctx
,
283 struct gl_texture_object
*texObj
,
284 GLenum pname
, const GLint
*params
)
287 case GL_TEXTURE_MIN_FILTER
:
288 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
289 goto invalid_operation
;
291 if (texObj
->Sampler
.MinFilter
== params
[0])
297 texObj
->Sampler
.MinFilter
= params
[0];
299 case GL_NEAREST_MIPMAP_NEAREST
:
300 case GL_LINEAR_MIPMAP_NEAREST
:
301 case GL_NEAREST_MIPMAP_LINEAR
:
302 case GL_LINEAR_MIPMAP_LINEAR
:
303 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
304 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
306 texObj
->Sampler
.MinFilter
= params
[0];
315 case GL_TEXTURE_MAG_FILTER
:
316 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
317 goto invalid_operation
;
319 if (texObj
->Sampler
.MagFilter
== params
[0])
324 flush(ctx
); /* does not effect completeness */
325 texObj
->Sampler
.MagFilter
= params
[0];
332 case GL_TEXTURE_WRAP_S
:
333 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
334 goto invalid_operation
;
336 if (texObj
->Sampler
.WrapS
== params
[0])
338 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
340 texObj
->Sampler
.WrapS
= params
[0];
345 case GL_TEXTURE_WRAP_T
:
346 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
347 goto invalid_operation
;
349 if (texObj
->Sampler
.WrapT
== params
[0])
351 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
353 texObj
->Sampler
.WrapT
= params
[0];
358 case GL_TEXTURE_WRAP_R
:
359 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
360 goto invalid_operation
;
362 if (texObj
->Sampler
.WrapR
== params
[0])
364 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
366 texObj
->Sampler
.WrapR
= params
[0];
371 case GL_TEXTURE_BASE_LEVEL
:
372 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
375 if (texObj
->BaseLevel
== params
[0])
378 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
379 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
380 goto invalid_operation
;
383 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
384 _mesa_error(ctx
, GL_INVALID_VALUE
,
385 "glTexParameter(param=%d)", params
[0]);
388 incomplete(ctx
, texObj
);
389 texObj
->BaseLevel
= params
[0];
392 case GL_TEXTURE_MAX_LEVEL
:
393 if (texObj
->MaxLevel
== params
[0])
396 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
397 _mesa_error(ctx
, GL_INVALID_VALUE
,
398 "glTexParameter(param=%d)", params
[0]);
401 incomplete(ctx
, texObj
);
402 texObj
->MaxLevel
= params
[0];
405 case GL_GENERATE_MIPMAP_SGIS
:
406 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
409 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
411 if (texObj
->GenerateMipmap
!= params
[0]) {
413 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
418 case GL_TEXTURE_COMPARE_MODE_ARB
:
419 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
420 || _mesa_is_gles3(ctx
)) {
422 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
423 goto invalid_operation
;
425 if (texObj
->Sampler
.CompareMode
== params
[0])
427 if (params
[0] == GL_NONE
||
428 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
430 texObj
->Sampler
.CompareMode
= params
[0];
437 case GL_TEXTURE_COMPARE_FUNC_ARB
:
438 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
439 || _mesa_is_gles3(ctx
)) {
441 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
442 goto invalid_operation
;
444 if (texObj
->Sampler
.CompareFunc
== params
[0])
450 texObj
->Sampler
.CompareFunc
= params
[0];
458 if (ctx
->Extensions
.EXT_shadow_funcs
) {
460 texObj
->Sampler
.CompareFunc
= params
[0];
470 case GL_DEPTH_TEXTURE_MODE_ARB
:
471 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
472 * existed in OpenGL ES.
474 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
475 if (texObj
->DepthMode
== params
[0])
477 if (params
[0] == GL_LUMINANCE
||
478 params
[0] == GL_INTENSITY
||
479 params
[0] == GL_ALPHA
||
480 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
482 texObj
->DepthMode
= params
[0];
489 case GL_TEXTURE_CROP_RECT_OES
:
490 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
493 texObj
->CropRect
[0] = params
[0];
494 texObj
->CropRect
[1] = params
[1];
495 texObj
->CropRect
[2] = params
[2];
496 texObj
->CropRect
[3] = params
[3];
499 case GL_TEXTURE_SWIZZLE_R_EXT
:
500 case GL_TEXTURE_SWIZZLE_G_EXT
:
501 case GL_TEXTURE_SWIZZLE_B_EXT
:
502 case GL_TEXTURE_SWIZZLE_A_EXT
:
503 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
504 || _mesa_is_gles3(ctx
)) {
505 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
506 const GLint swz
= comp_to_swizzle(params
[0]);
508 _mesa_error(ctx
, GL_INVALID_OPERATION
,
509 "glTexParameter(swizzle 0x%x)", params
[0]);
515 texObj
->Swizzle
[comp
] = params
[0];
516 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
521 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
522 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
523 || _mesa_is_gles3(ctx
)) {
526 for (comp
= 0; comp
< 4; comp
++) {
527 const GLint swz
= comp_to_swizzle(params
[comp
]);
529 texObj
->Swizzle
[comp
] = params
[comp
];
530 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
533 _mesa_error(ctx
, GL_INVALID_OPERATION
,
534 "glTexParameter(swizzle 0x%x)", params
[comp
]);
542 case GL_TEXTURE_SRGB_DECODE_EXT
:
543 if (_mesa_is_desktop_gl(ctx
)
544 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
545 GLenum decode
= params
[0];
547 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
548 goto invalid_operation
;
550 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
551 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
553 texObj
->Sampler
.sRGBDecode
= decode
;
560 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
561 if (_mesa_is_desktop_gl(ctx
)
562 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
563 GLenum param
= params
[0];
565 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
566 goto invalid_operation
;
568 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
571 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
573 texObj
->Sampler
.CubeMapSeamless
= param
;
584 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
585 _mesa_lookup_enum_by_nr(pname
));
589 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
590 _mesa_lookup_enum_by_nr(params
[0]));
594 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
595 _mesa_lookup_enum_by_nr(pname
));
601 * Set a float-valued texture parameter
602 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
605 set_tex_parameterf(struct gl_context
*ctx
,
606 struct gl_texture_object
*texObj
,
607 GLenum pname
, const GLfloat
*params
)
610 case GL_TEXTURE_MIN_LOD
:
611 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
614 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
615 goto invalid_operation
;
617 if (texObj
->Sampler
.MinLod
== params
[0])
620 texObj
->Sampler
.MinLod
= params
[0];
623 case GL_TEXTURE_MAX_LOD
:
624 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
627 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
628 goto invalid_operation
;
630 if (texObj
->Sampler
.MaxLod
== params
[0])
633 texObj
->Sampler
.MaxLod
= params
[0];
636 case GL_TEXTURE_PRIORITY
:
637 if (ctx
->API
!= API_OPENGL_COMPAT
)
641 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
644 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
645 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
646 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
647 goto invalid_operation
;
649 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
651 if (params
[0] < 1.0) {
652 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
656 /* clamp to max, that's what NVIDIA does */
657 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
658 ctx
->Const
.MaxTextureMaxAnisotropy
);
662 static GLuint count
= 0;
668 case GL_TEXTURE_LOD_BIAS
:
669 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
670 * It was removed in core-profile, and it has never existed in OpenGL
673 if (ctx
->API
!= API_OPENGL_COMPAT
)
676 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
677 goto invalid_operation
;
679 if (texObj
->Sampler
.LodBias
!= params
[0]) {
681 texObj
->Sampler
.LodBias
= params
[0];
686 case GL_TEXTURE_BORDER_COLOR
:
687 if (!_mesa_is_desktop_gl(ctx
))
690 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
691 goto invalid_operation
;
694 /* ARB_texture_float disables clamping */
695 if (ctx
->Extensions
.ARB_texture_float
) {
696 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
697 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
698 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
699 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
701 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
702 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
703 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
704 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
715 _mesa_lookup_enum_by_nr(pname
));
719 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
720 _mesa_lookup_enum_by_nr(pname
));
726 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
728 GLboolean need_update
;
729 struct gl_texture_object
*texObj
;
730 GET_CURRENT_CONTEXT(ctx
);
732 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
737 case GL_TEXTURE_MIN_FILTER
:
738 case GL_TEXTURE_MAG_FILTER
:
739 case GL_TEXTURE_WRAP_S
:
740 case GL_TEXTURE_WRAP_T
:
741 case GL_TEXTURE_WRAP_R
:
742 case GL_TEXTURE_BASE_LEVEL
:
743 case GL_TEXTURE_MAX_LEVEL
:
744 case GL_GENERATE_MIPMAP_SGIS
:
745 case GL_TEXTURE_COMPARE_MODE_ARB
:
746 case GL_TEXTURE_COMPARE_FUNC_ARB
:
747 case GL_DEPTH_TEXTURE_MODE_ARB
:
748 case GL_TEXTURE_SRGB_DECODE_EXT
:
749 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
750 case GL_TEXTURE_SWIZZLE_R_EXT
:
751 case GL_TEXTURE_SWIZZLE_G_EXT
:
752 case GL_TEXTURE_SWIZZLE_B_EXT
:
753 case GL_TEXTURE_SWIZZLE_A_EXT
:
757 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
758 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
760 p
[1] = p
[2] = p
[3] = 0;
761 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
766 /* this will generate an error if pname is illegal */
769 p
[1] = p
[2] = p
[3] = 0.0F
;
770 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
774 if (ctx
->Driver
.TexParameter
&& need_update
) {
775 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
781 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
783 GLboolean need_update
;
784 struct gl_texture_object
*texObj
;
785 GET_CURRENT_CONTEXT(ctx
);
787 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
792 case GL_TEXTURE_MIN_FILTER
:
793 case GL_TEXTURE_MAG_FILTER
:
794 case GL_TEXTURE_WRAP_S
:
795 case GL_TEXTURE_WRAP_T
:
796 case GL_TEXTURE_WRAP_R
:
797 case GL_TEXTURE_BASE_LEVEL
:
798 case GL_TEXTURE_MAX_LEVEL
:
799 case GL_GENERATE_MIPMAP_SGIS
:
800 case GL_TEXTURE_COMPARE_MODE_ARB
:
801 case GL_TEXTURE_COMPARE_FUNC_ARB
:
802 case GL_DEPTH_TEXTURE_MODE_ARB
:
803 case GL_TEXTURE_SRGB_DECODE_EXT
:
804 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
806 /* convert float param to int */
808 p
[0] = (GLint
) params
[0];
809 p
[1] = p
[2] = p
[3] = 0;
810 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
813 case GL_TEXTURE_CROP_RECT_OES
:
815 /* convert float params to int */
817 iparams
[0] = (GLint
) params
[0];
818 iparams
[1] = (GLint
) params
[1];
819 iparams
[2] = (GLint
) params
[2];
820 iparams
[3] = (GLint
) params
[3];
821 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
824 case GL_TEXTURE_SWIZZLE_R_EXT
:
825 case GL_TEXTURE_SWIZZLE_G_EXT
:
826 case GL_TEXTURE_SWIZZLE_B_EXT
:
827 case GL_TEXTURE_SWIZZLE_A_EXT
:
828 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
830 GLint p
[4] = {0, 0, 0, 0};
831 p
[0] = (GLint
) params
[0];
832 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
833 p
[1] = (GLint
) params
[1];
834 p
[2] = (GLint
) params
[2];
835 p
[3] = (GLint
) params
[3];
837 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
841 /* this will generate an error if pname is illegal */
842 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
845 if (ctx
->Driver
.TexParameter
&& need_update
) {
846 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
852 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
854 GLboolean need_update
;
855 struct gl_texture_object
*texObj
;
856 GET_CURRENT_CONTEXT(ctx
);
858 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
863 case GL_TEXTURE_MIN_LOD
:
864 case GL_TEXTURE_MAX_LOD
:
865 case GL_TEXTURE_PRIORITY
:
866 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
867 case GL_TEXTURE_LOD_BIAS
:
868 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
871 fparam
[0] = (GLfloat
) param
;
872 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
873 /* convert int param to float */
874 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
878 /* this will generate an error if pname is illegal */
882 iparam
[1] = iparam
[2] = iparam
[3] = 0;
883 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
887 if (ctx
->Driver
.TexParameter
&& need_update
) {
888 GLfloat fparam
= (GLfloat
) param
;
889 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
895 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
897 GLboolean need_update
;
898 struct gl_texture_object
*texObj
;
899 GET_CURRENT_CONTEXT(ctx
);
901 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
906 case GL_TEXTURE_BORDER_COLOR
:
908 /* convert int params to float */
910 fparams
[0] = INT_TO_FLOAT(params
[0]);
911 fparams
[1] = INT_TO_FLOAT(params
[1]);
912 fparams
[2] = INT_TO_FLOAT(params
[2]);
913 fparams
[3] = INT_TO_FLOAT(params
[3]);
914 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
917 case GL_TEXTURE_MIN_LOD
:
918 case GL_TEXTURE_MAX_LOD
:
919 case GL_TEXTURE_PRIORITY
:
920 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
921 case GL_TEXTURE_LOD_BIAS
:
922 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
924 /* convert int param to float */
926 fparams
[0] = (GLfloat
) params
[0];
927 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
928 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
932 /* this will generate an error if pname is illegal */
933 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
936 if (ctx
->Driver
.TexParameter
&& need_update
) {
938 fparams
[0] = INT_TO_FLOAT(params
[0]);
939 if (pname
== GL_TEXTURE_BORDER_COLOR
||
940 pname
== GL_TEXTURE_CROP_RECT_OES
) {
941 fparams
[1] = INT_TO_FLOAT(params
[1]);
942 fparams
[2] = INT_TO_FLOAT(params
[2]);
943 fparams
[3] = INT_TO_FLOAT(params
[3]);
945 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
951 * Set tex parameter to integer value(s). Primarily intended to set
952 * integer-valued texture border color (for integer-valued textures).
956 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
958 struct gl_texture_object
*texObj
;
959 GET_CURRENT_CONTEXT(ctx
);
961 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
966 case GL_TEXTURE_BORDER_COLOR
:
967 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
968 /* set the integer-valued border color */
969 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
972 _mesa_TexParameteriv(target
, pname
, params
);
975 /* XXX no driver hook for TexParameterIiv() yet */
980 * Set tex parameter to unsigned integer value(s). Primarily intended to set
981 * uint-valued texture border color (for integer-valued textures).
985 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
987 struct gl_texture_object
*texObj
;
988 GET_CURRENT_CONTEXT(ctx
);
990 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
995 case GL_TEXTURE_BORDER_COLOR
:
996 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
997 /* set the unsigned integer-valued border color */
998 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1001 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1004 /* XXX no driver hook for TexParameterIuiv() yet */
1009 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1013 case GL_PROXY_TEXTURE_1D
:
1015 case GL_PROXY_TEXTURE_2D
:
1017 case GL_PROXY_TEXTURE_3D
:
1019 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1021 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1022 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1023 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1024 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1025 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1026 return ctx
->Extensions
.ARB_texture_cube_map
;
1027 case GL_TEXTURE_RECTANGLE_NV
:
1028 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1029 return ctx
->Extensions
.NV_texture_rectangle
;
1030 case GL_TEXTURE_1D_ARRAY_EXT
:
1031 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1032 case GL_TEXTURE_2D_ARRAY_EXT
:
1033 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1034 return (ctx
->Extensions
.MESA_texture_array
||
1035 ctx
->Extensions
.EXT_texture_array
);
1036 case GL_TEXTURE_BUFFER
:
1037 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1038 * but not in earlier versions that expose ARB_texture_buffer_object.
1040 * From the ARB_texture_buffer_object spec:
1041 * "(7) Do buffer textures support texture parameters (TexParameter) or
1042 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1044 * RESOLVED: No. [...] Note that the spec edits above don't add
1045 * explicit error language for any of these cases. That is because
1046 * each of the functions enumerate the set of valid <target>
1047 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1048 * these cases means that target is not legal, and an INVALID_ENUM
1049 * error should be generated."
1051 * From the OpenGL 3.1 spec:
1052 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1054 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1055 case GL_TEXTURE_2D_MULTISAMPLE
:
1056 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1057 return ctx
->Extensions
.ARB_texture_multisample
;
1065 get_tex_level_parameter_image(struct gl_context
*ctx
,
1066 const struct gl_texture_object
*texObj
,
1067 GLenum target
, GLint level
,
1068 GLenum pname
, GLint
*params
)
1070 const struct gl_texture_image
*img
= NULL
;
1071 gl_format texFormat
;
1073 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1074 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1075 /* undefined texture image */
1076 if (pname
== GL_TEXTURE_COMPONENTS
)
1083 texFormat
= img
->TexFormat
;
1086 case GL_TEXTURE_WIDTH
:
1087 *params
= img
->Width
;
1089 case GL_TEXTURE_HEIGHT
:
1090 *params
= img
->Height
;
1092 case GL_TEXTURE_DEPTH
:
1093 *params
= img
->Depth
;
1095 case GL_TEXTURE_INTERNAL_FORMAT
:
1096 if (_mesa_is_format_compressed(texFormat
)) {
1097 /* need to return the actual compressed format */
1098 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1101 /* If the true internal format is not compressed but the user
1102 * requested a generic compressed format, we have to return the
1103 * generic base format that matches.
1105 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1107 * "If no specific compressed format is available,
1108 * internalformat is instead replaced by the corresponding base
1111 * Otherwise just return the user's requested internal format
1114 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1116 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1119 case GL_TEXTURE_BORDER
:
1120 *params
= img
->Border
;
1122 case GL_TEXTURE_RED_SIZE
:
1123 case GL_TEXTURE_GREEN_SIZE
:
1124 case GL_TEXTURE_BLUE_SIZE
:
1125 case GL_TEXTURE_ALPHA_SIZE
:
1126 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1127 *params
= _mesa_get_format_bits(texFormat
, pname
);
1131 case GL_TEXTURE_INTENSITY_SIZE
:
1132 case GL_TEXTURE_LUMINANCE_SIZE
:
1133 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1134 *params
= _mesa_get_format_bits(texFormat
, pname
);
1136 /* intensity or luminance is probably stored as RGB[A] */
1137 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1138 GL_TEXTURE_RED_SIZE
),
1139 _mesa_get_format_bits(texFormat
,
1140 GL_TEXTURE_GREEN_SIZE
));
1147 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1148 if (!ctx
->Extensions
.ARB_depth_texture
)
1150 *params
= _mesa_get_format_bits(texFormat
, pname
);
1152 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1153 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1154 !ctx
->Extensions
.ARB_framebuffer_object
)
1156 *params
= _mesa_get_format_bits(texFormat
, pname
);
1158 case GL_TEXTURE_SHARED_SIZE
:
1159 if (ctx
->Version
< 30 &&
1160 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1162 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1165 /* GL_ARB_texture_compression */
1166 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1167 if (_mesa_is_format_compressed(texFormat
) &&
1168 !_mesa_is_proxy_texture(target
)) {
1169 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1170 img
->Height
, img
->Depth
);
1173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1174 "glGetTexLevelParameter[if]v(pname)");
1177 case GL_TEXTURE_COMPRESSED
:
1178 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1181 /* GL_ARB_texture_float */
1182 case GL_TEXTURE_RED_TYPE_ARB
:
1183 case GL_TEXTURE_GREEN_TYPE_ARB
:
1184 case GL_TEXTURE_BLUE_TYPE_ARB
:
1185 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1186 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1187 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1188 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1189 if (!ctx
->Extensions
.ARB_texture_float
)
1191 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1192 *params
= _mesa_get_format_datatype(texFormat
);
1197 /* GL_ARB_texture_multisample */
1198 case GL_TEXTURE_SAMPLES
:
1199 if (!ctx
->Extensions
.ARB_texture_multisample
)
1201 *params
= img
->NumSamples
;
1204 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1205 if (!ctx
->Extensions
.ARB_texture_multisample
)
1207 *params
= img
->FixedSampleLocations
;
1214 /* no error if we get here */
1218 _mesa_error(ctx
, GL_INVALID_ENUM
,
1219 "glGetTexLevelParameter[if]v(pname=%s)",
1220 _mesa_lookup_enum_by_nr(pname
));
1225 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1226 const struct gl_texture_object
*texObj
,
1227 GLenum pname
, GLint
*params
)
1229 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1230 gl_format texFormat
= texObj
->_BufferObjectFormat
;
1231 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1232 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1235 /* undefined texture buffer object */
1236 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1241 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1244 case GL_TEXTURE_WIDTH
:
1247 case GL_TEXTURE_HEIGHT
:
1248 case GL_TEXTURE_DEPTH
:
1249 case GL_TEXTURE_BORDER
:
1250 case GL_TEXTURE_SHARED_SIZE
:
1251 case GL_TEXTURE_COMPRESSED
:
1254 case GL_TEXTURE_INTERNAL_FORMAT
:
1255 *params
= internalFormat
;
1257 case GL_TEXTURE_RED_SIZE
:
1258 case GL_TEXTURE_GREEN_SIZE
:
1259 case GL_TEXTURE_BLUE_SIZE
:
1260 case GL_TEXTURE_ALPHA_SIZE
:
1261 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1262 *params
= _mesa_get_format_bits(texFormat
, pname
);
1266 case GL_TEXTURE_INTENSITY_SIZE
:
1267 case GL_TEXTURE_LUMINANCE_SIZE
:
1268 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1269 *params
= _mesa_get_format_bits(texFormat
, pname
);
1271 /* intensity or luminance is probably stored as RGB[A] */
1272 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1273 GL_TEXTURE_RED_SIZE
),
1274 _mesa_get_format_bits(texFormat
,
1275 GL_TEXTURE_GREEN_SIZE
));
1281 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1282 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1283 *params
= _mesa_get_format_bits(texFormat
, pname
);
1286 /* GL_ARB_texture_buffer_range */
1287 case GL_TEXTURE_BUFFER_OFFSET
:
1288 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1290 *params
= texObj
->BufferOffset
;
1292 case GL_TEXTURE_BUFFER_SIZE
:
1293 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1295 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1298 /* GL_ARB_texture_compression */
1299 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1300 /* Always illegal for GL_TEXTURE_BUFFER */
1301 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1302 "glGetTexLevelParameter[if]v(pname)");
1305 /* GL_ARB_texture_float */
1306 case GL_TEXTURE_RED_TYPE_ARB
:
1307 case GL_TEXTURE_GREEN_TYPE_ARB
:
1308 case GL_TEXTURE_BLUE_TYPE_ARB
:
1309 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1310 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1311 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1312 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1313 if (!ctx
->Extensions
.ARB_texture_float
)
1315 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1316 *params
= _mesa_get_format_datatype(texFormat
);
1325 /* no error if we get here */
1329 _mesa_error(ctx
, GL_INVALID_ENUM
,
1330 "glGetTexLevelParameter[if]v(pname=%s)",
1331 _mesa_lookup_enum_by_nr(pname
));
1336 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1337 GLenum pname
, GLfloat
*params
)
1340 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1341 *params
= (GLfloat
) iparam
;
1346 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1347 GLenum pname
, GLint
*params
)
1349 const struct gl_texture_unit
*texUnit
;
1350 struct gl_texture_object
*texObj
;
1352 GET_CURRENT_CONTEXT(ctx
);
1354 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1355 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1356 "glGetTexLevelParameteriv(current unit)");
1360 texUnit
= _mesa_get_current_tex_unit(ctx
);
1362 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1363 _mesa_error(ctx
, GL_INVALID_ENUM
,
1364 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1368 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1369 assert(maxLevels
!= 0);
1371 if (level
< 0 || level
>= maxLevels
) {
1372 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1376 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1378 if (target
== GL_TEXTURE_BUFFER
)
1379 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1381 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1386 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1388 struct gl_texture_object
*obj
;
1389 GET_CURRENT_CONTEXT(ctx
);
1391 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1395 _mesa_lock_texture(ctx
, obj
);
1397 case GL_TEXTURE_MAG_FILTER
:
1398 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1400 case GL_TEXTURE_MIN_FILTER
:
1401 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1403 case GL_TEXTURE_WRAP_S
:
1404 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1406 case GL_TEXTURE_WRAP_T
:
1407 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1409 case GL_TEXTURE_WRAP_R
:
1410 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1412 case GL_TEXTURE_BORDER_COLOR
:
1413 if (!_mesa_is_desktop_gl(ctx
))
1416 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1417 _mesa_update_state_locked(ctx
);
1418 if (_mesa_get_clamp_fragment_color(ctx
)) {
1419 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1420 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1421 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1422 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1425 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1426 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1427 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1428 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1431 case GL_TEXTURE_RESIDENT
:
1432 if (ctx
->API
!= API_OPENGL_COMPAT
)
1437 case GL_TEXTURE_PRIORITY
:
1438 if (ctx
->API
!= API_OPENGL_COMPAT
)
1441 *params
= obj
->Priority
;
1443 case GL_TEXTURE_MIN_LOD
:
1444 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1447 *params
= obj
->Sampler
.MinLod
;
1449 case GL_TEXTURE_MAX_LOD
:
1450 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1453 *params
= obj
->Sampler
.MaxLod
;
1455 case GL_TEXTURE_BASE_LEVEL
:
1456 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1459 *params
= (GLfloat
) obj
->BaseLevel
;
1461 case GL_TEXTURE_MAX_LEVEL
:
1462 *params
= (GLfloat
) obj
->MaxLevel
;
1464 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1465 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1467 *params
= obj
->Sampler
.MaxAnisotropy
;
1469 case GL_GENERATE_MIPMAP_SGIS
:
1470 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1473 *params
= (GLfloat
) obj
->GenerateMipmap
;
1475 case GL_TEXTURE_COMPARE_MODE_ARB
:
1476 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1477 && !_mesa_is_gles3(ctx
))
1479 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1481 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1482 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1483 && !_mesa_is_gles3(ctx
))
1485 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1487 case GL_DEPTH_TEXTURE_MODE_ARB
:
1488 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1489 * never existed in OpenGL ES.
1491 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1493 *params
= (GLfloat
) obj
->DepthMode
;
1495 case GL_TEXTURE_LOD_BIAS
:
1496 if (ctx
->API
!= API_OPENGL_COMPAT
)
1499 *params
= obj
->Sampler
.LodBias
;
1501 case GL_TEXTURE_CROP_RECT_OES
:
1502 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1505 params
[0] = (GLfloat
) obj
->CropRect
[0];
1506 params
[1] = (GLfloat
) obj
->CropRect
[1];
1507 params
[2] = (GLfloat
) obj
->CropRect
[2];
1508 params
[3] = (GLfloat
) obj
->CropRect
[3];
1511 case GL_TEXTURE_SWIZZLE_R_EXT
:
1512 case GL_TEXTURE_SWIZZLE_G_EXT
:
1513 case GL_TEXTURE_SWIZZLE_B_EXT
:
1514 case GL_TEXTURE_SWIZZLE_A_EXT
:
1515 if ((!_mesa_is_desktop_gl(ctx
)
1516 || !ctx
->Extensions
.EXT_texture_swizzle
)
1517 && !_mesa_is_gles3(ctx
))
1519 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1522 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1523 if ((!_mesa_is_desktop_gl(ctx
)
1524 || !ctx
->Extensions
.EXT_texture_swizzle
)
1525 && !_mesa_is_gles3(ctx
)) {
1530 for (comp
= 0; comp
< 4; comp
++) {
1531 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1536 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1537 if (!_mesa_is_desktop_gl(ctx
)
1538 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1540 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1543 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1544 if (!ctx
->Extensions
.ARB_texture_storage
)
1546 *params
= (GLfloat
) obj
->Immutable
;
1549 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1550 if (!_mesa_is_gles3(ctx
))
1552 *params
= (GLfloat
) obj
->ImmutableLevels
;
1555 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1556 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1558 *params
= obj
->RequiredTextureImageUnits
;
1561 case GL_TEXTURE_SRGB_DECODE_EXT
:
1562 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1564 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1571 /* no error if we get here */
1572 _mesa_unlock_texture(ctx
, obj
);
1576 _mesa_unlock_texture(ctx
, obj
);
1577 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1582 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1584 struct gl_texture_object
*obj
;
1585 GET_CURRENT_CONTEXT(ctx
);
1587 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1591 _mesa_lock_texture(ctx
, obj
);
1593 case GL_TEXTURE_MAG_FILTER
:
1594 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1596 case GL_TEXTURE_MIN_FILTER
:
1597 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1599 case GL_TEXTURE_WRAP_S
:
1600 *params
= (GLint
) obj
->Sampler
.WrapS
;
1602 case GL_TEXTURE_WRAP_T
:
1603 *params
= (GLint
) obj
->Sampler
.WrapT
;
1605 case GL_TEXTURE_WRAP_R
:
1606 *params
= (GLint
) obj
->Sampler
.WrapR
;
1608 case GL_TEXTURE_BORDER_COLOR
:
1609 if (!_mesa_is_desktop_gl(ctx
))
1614 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1615 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1616 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1617 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1618 params
[0] = FLOAT_TO_INT(b
[0]);
1619 params
[1] = FLOAT_TO_INT(b
[1]);
1620 params
[2] = FLOAT_TO_INT(b
[2]);
1621 params
[3] = FLOAT_TO_INT(b
[3]);
1624 case GL_TEXTURE_RESIDENT
:
1625 if (ctx
->API
!= API_OPENGL_COMPAT
)
1630 case GL_TEXTURE_PRIORITY
:
1631 if (ctx
->API
!= API_OPENGL_COMPAT
)
1634 *params
= FLOAT_TO_INT(obj
->Priority
);
1636 case GL_TEXTURE_MIN_LOD
:
1637 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1640 *params
= (GLint
) obj
->Sampler
.MinLod
;
1642 case GL_TEXTURE_MAX_LOD
:
1643 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1646 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1648 case GL_TEXTURE_BASE_LEVEL
:
1649 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1652 *params
= obj
->BaseLevel
;
1654 case GL_TEXTURE_MAX_LEVEL
:
1655 *params
= obj
->MaxLevel
;
1657 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1658 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1660 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1662 case GL_GENERATE_MIPMAP_SGIS
:
1663 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1666 *params
= (GLint
) obj
->GenerateMipmap
;
1668 case GL_TEXTURE_COMPARE_MODE_ARB
:
1669 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1670 && !_mesa_is_gles3(ctx
))
1672 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1674 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1675 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1676 && !_mesa_is_gles3(ctx
))
1678 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1680 case GL_DEPTH_TEXTURE_MODE_ARB
:
1681 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1683 *params
= (GLint
) obj
->DepthMode
;
1685 case GL_TEXTURE_LOD_BIAS
:
1686 if (ctx
->API
!= API_OPENGL_COMPAT
)
1689 *params
= (GLint
) obj
->Sampler
.LodBias
;
1691 case GL_TEXTURE_CROP_RECT_OES
:
1692 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1695 params
[0] = obj
->CropRect
[0];
1696 params
[1] = obj
->CropRect
[1];
1697 params
[2] = obj
->CropRect
[2];
1698 params
[3] = obj
->CropRect
[3];
1700 case GL_TEXTURE_SWIZZLE_R_EXT
:
1701 case GL_TEXTURE_SWIZZLE_G_EXT
:
1702 case GL_TEXTURE_SWIZZLE_B_EXT
:
1703 case GL_TEXTURE_SWIZZLE_A_EXT
:
1704 if ((!_mesa_is_desktop_gl(ctx
)
1705 || !ctx
->Extensions
.EXT_texture_swizzle
)
1706 && !_mesa_is_gles3(ctx
))
1708 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1711 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1712 if ((!_mesa_is_desktop_gl(ctx
)
1713 || !ctx
->Extensions
.EXT_texture_swizzle
)
1714 && !_mesa_is_gles3(ctx
))
1716 COPY_4V(params
, obj
->Swizzle
);
1719 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1720 if (!_mesa_is_desktop_gl(ctx
)
1721 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1723 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1726 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1727 if (!ctx
->Extensions
.ARB_texture_storage
)
1729 *params
= (GLint
) obj
->Immutable
;
1732 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1733 if (!_mesa_is_gles3(ctx
))
1735 *params
= obj
->ImmutableLevels
;
1738 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1739 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1741 *params
= obj
->RequiredTextureImageUnits
;
1744 case GL_TEXTURE_SRGB_DECODE_EXT
:
1745 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1747 *params
= obj
->Sampler
.sRGBDecode
;
1754 /* no error if we get here */
1755 _mesa_unlock_texture(ctx
, obj
);
1759 _mesa_unlock_texture(ctx
, obj
);
1760 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1764 /** New in GL 3.0 */
1766 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1768 struct gl_texture_object
*texObj
;
1769 GET_CURRENT_CONTEXT(ctx
);
1771 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1776 case GL_TEXTURE_BORDER_COLOR
:
1777 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1780 _mesa_GetTexParameteriv(target
, pname
, params
);
1785 /** New in GL 3.0 */
1787 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1789 struct gl_texture_object
*texObj
;
1790 GET_CURRENT_CONTEXT(ctx
);
1792 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1797 case GL_TEXTURE_BORDER_COLOR
:
1798 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1803 _mesa_GetTexParameteriv(target
, pname
, ip
);
1805 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1806 pname
== GL_TEXTURE_CROP_RECT_OES
) {