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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
30 * glTexParameter-related functions
34 #include "main/glheader.h"
35 #include "main/blend.h"
36 #include "main/colormac.h"
37 #include "main/context.h"
38 #include "main/enums.h"
39 #include "main/formats.h"
40 #include "main/glformats.h"
41 #include "main/macros.h"
42 #include "main/mtypes.h"
43 #include "main/state.h"
44 #include "main/texcompress.h"
45 #include "main/texobj.h"
46 #include "main/texparam.h"
47 #include "main/teximage.h"
48 #include "main/texstate.h"
49 #include "program/prog_instruction.h"
53 * Check if a coordinate wrap mode is supported for the texture target.
54 * \return GL_TRUE if legal, GL_FALSE otherwise
57 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
59 const struct gl_extensions
* const e
= & ctx
->Extensions
;
60 const bool is_desktop_gl
= _mesa_is_desktop_gl(ctx
);
65 /* GL_CLAMP was removed in the core profile, and it has never existed in
68 supported
= (ctx
->API
== API_OPENGL_COMPAT
)
69 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
72 case GL_CLAMP_TO_EDGE
:
76 case GL_CLAMP_TO_BORDER
:
77 supported
= is_desktop_gl
&& e
->ARB_texture_border_clamp
78 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
82 case GL_MIRRORED_REPEAT
:
83 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
84 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
87 case GL_MIRROR_CLAMP_EXT
:
88 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
89 supported
= is_desktop_gl
90 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
91 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
92 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
95 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
96 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
97 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
98 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
107 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
114 * Get current texture object for given target.
115 * Return NULL if any error (and record the error).
116 * Note that this is different from _mesa_select_tex_object() in that proxy
117 * targets are not accepted.
118 * Only the glGetTexLevelParameter() functions accept proxy targets.
120 static struct gl_texture_object
*
121 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
123 struct gl_texture_unit
*texUnit
;
125 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
126 _mesa_error(ctx
, GL_INVALID_OPERATION
,
127 "gl%sTexParameter(current unit)", get
? "Get" : "");
131 texUnit
= _mesa_get_current_tex_unit(ctx
);
135 if (_mesa_is_desktop_gl(ctx
))
136 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
139 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
141 if (ctx
->API
!= API_OPENGLES
)
142 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
144 case GL_TEXTURE_CUBE_MAP
:
145 if (ctx
->Extensions
.ARB_texture_cube_map
) {
146 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
149 case GL_TEXTURE_RECTANGLE_NV
:
150 if (_mesa_is_desktop_gl(ctx
)
151 && ctx
->Extensions
.NV_texture_rectangle
) {
152 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
155 case GL_TEXTURE_1D_ARRAY_EXT
:
156 if (_mesa_is_desktop_gl(ctx
)
157 && (ctx
->Extensions
.MESA_texture_array
||
158 ctx
->Extensions
.EXT_texture_array
)) {
159 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
162 case GL_TEXTURE_2D_ARRAY_EXT
:
163 if ((_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
164 && (ctx
->Extensions
.MESA_texture_array
||
165 ctx
->Extensions
.EXT_texture_array
)) {
166 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
169 case GL_TEXTURE_EXTERNAL_OES
:
170 if (_mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
) {
171 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
174 case GL_TEXTURE_CUBE_MAP_ARRAY
:
175 if (ctx
->Extensions
.ARB_texture_cube_map_array
) {
176 return texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
];
179 case GL_TEXTURE_2D_MULTISAMPLE
:
180 if (ctx
->Extensions
.ARB_texture_storage_multisample
) {
181 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
];
184 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
185 if (ctx
->Extensions
.ARB_texture_storage_multisample
) {
186 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
];
193 _mesa_error(ctx
, GL_INVALID_ENUM
,
194 "gl%sTexParameter(target)", get
? "Get" : "");
200 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
201 * \return -1 if error.
204 comp_to_swizzle(GLenum comp
)
226 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
229 ASSERT(swz
<= SWIZZLE_NIL
);
231 GLuint mask
= 0x7 << (3 * comp
);
232 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
239 * This is called just prior to changing any texture object state which
240 * will not effect texture completeness.
243 flush(struct gl_context
*ctx
)
245 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
250 * This is called just prior to changing any texture object state which
251 * can effect texture completeness (texture base level, max level).
252 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
253 * state flag and then mark the texture object as 'incomplete' so that any
254 * per-texture derived state gets recomputed.
257 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
259 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
260 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
265 target_allows_setting_sampler_parameters(GLenum target
)
268 case GL_TEXTURE_2D_MULTISAMPLE
:
269 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
279 * Set an integer-valued texture parameter
280 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
283 set_tex_parameteri(struct gl_context
*ctx
,
284 struct gl_texture_object
*texObj
,
285 GLenum pname
, const GLint
*params
)
288 case GL_TEXTURE_MIN_FILTER
:
289 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
290 goto invalid_operation
;
292 if (texObj
->Sampler
.MinFilter
== params
[0])
298 texObj
->Sampler
.MinFilter
= params
[0];
300 case GL_NEAREST_MIPMAP_NEAREST
:
301 case GL_LINEAR_MIPMAP_NEAREST
:
302 case GL_NEAREST_MIPMAP_LINEAR
:
303 case GL_LINEAR_MIPMAP_LINEAR
:
304 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
305 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
307 texObj
->Sampler
.MinFilter
= params
[0];
316 case GL_TEXTURE_MAG_FILTER
:
317 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
318 goto invalid_operation
;
320 if (texObj
->Sampler
.MagFilter
== params
[0])
325 flush(ctx
); /* does not effect completeness */
326 texObj
->Sampler
.MagFilter
= params
[0];
333 case GL_TEXTURE_WRAP_S
:
334 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
335 goto invalid_operation
;
337 if (texObj
->Sampler
.WrapS
== params
[0])
339 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
341 texObj
->Sampler
.WrapS
= params
[0];
346 case GL_TEXTURE_WRAP_T
:
347 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
348 goto invalid_operation
;
350 if (texObj
->Sampler
.WrapT
== params
[0])
352 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
354 texObj
->Sampler
.WrapT
= params
[0];
359 case GL_TEXTURE_WRAP_R
:
360 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
361 goto invalid_operation
;
363 if (texObj
->Sampler
.WrapR
== params
[0])
365 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
367 texObj
->Sampler
.WrapR
= params
[0];
372 case GL_TEXTURE_BASE_LEVEL
:
373 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
376 if (texObj
->BaseLevel
== params
[0])
379 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
380 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
381 goto invalid_operation
;
384 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
385 _mesa_error(ctx
, GL_INVALID_VALUE
,
386 "glTexParameter(param=%d)", params
[0]);
389 incomplete(ctx
, texObj
);
390 texObj
->BaseLevel
= params
[0];
393 case GL_TEXTURE_MAX_LEVEL
:
394 if (texObj
->MaxLevel
== params
[0])
397 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
398 _mesa_error(ctx
, GL_INVALID_VALUE
,
399 "glTexParameter(param=%d)", params
[0]);
402 incomplete(ctx
, texObj
);
403 texObj
->MaxLevel
= params
[0];
406 case GL_GENERATE_MIPMAP_SGIS
:
407 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
410 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
412 if (texObj
->GenerateMipmap
!= params
[0]) {
414 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
419 case GL_TEXTURE_COMPARE_MODE_ARB
:
420 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
421 || _mesa_is_gles3(ctx
)) {
423 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
424 goto invalid_operation
;
426 if (texObj
->Sampler
.CompareMode
== params
[0])
428 if (params
[0] == GL_NONE
||
429 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
431 texObj
->Sampler
.CompareMode
= params
[0];
438 case GL_TEXTURE_COMPARE_FUNC_ARB
:
439 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
440 || _mesa_is_gles3(ctx
)) {
442 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
443 goto invalid_operation
;
445 if (texObj
->Sampler
.CompareFunc
== params
[0])
451 texObj
->Sampler
.CompareFunc
= params
[0];
459 if (ctx
->Extensions
.EXT_shadow_funcs
) {
461 texObj
->Sampler
.CompareFunc
= params
[0];
471 case GL_DEPTH_TEXTURE_MODE_ARB
:
472 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
473 * existed in OpenGL ES.
475 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
476 if (texObj
->DepthMode
== params
[0])
478 if (params
[0] == GL_LUMINANCE
||
479 params
[0] == GL_INTENSITY
||
480 params
[0] == GL_ALPHA
||
481 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
483 texObj
->DepthMode
= params
[0];
490 case GL_TEXTURE_CROP_RECT_OES
:
491 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
494 texObj
->CropRect
[0] = params
[0];
495 texObj
->CropRect
[1] = params
[1];
496 texObj
->CropRect
[2] = params
[2];
497 texObj
->CropRect
[3] = params
[3];
500 case GL_TEXTURE_SWIZZLE_R_EXT
:
501 case GL_TEXTURE_SWIZZLE_G_EXT
:
502 case GL_TEXTURE_SWIZZLE_B_EXT
:
503 case GL_TEXTURE_SWIZZLE_A_EXT
:
504 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
505 || _mesa_is_gles3(ctx
)) {
506 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
507 const GLint swz
= comp_to_swizzle(params
[0]);
509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
510 "glTexParameter(swizzle 0x%x)", params
[0]);
516 texObj
->Swizzle
[comp
] = params
[0];
517 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
522 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
523 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
524 || _mesa_is_gles3(ctx
)) {
527 for (comp
= 0; comp
< 4; comp
++) {
528 const GLint swz
= comp_to_swizzle(params
[comp
]);
530 texObj
->Swizzle
[comp
] = params
[comp
];
531 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
534 _mesa_error(ctx
, GL_INVALID_OPERATION
,
535 "glTexParameter(swizzle 0x%x)", params
[comp
]);
543 case GL_TEXTURE_SRGB_DECODE_EXT
:
544 if (_mesa_is_desktop_gl(ctx
)
545 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
546 GLenum decode
= params
[0];
548 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
549 goto invalid_operation
;
551 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
552 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
554 texObj
->Sampler
.sRGBDecode
= decode
;
561 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
562 if (_mesa_is_desktop_gl(ctx
)
563 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
564 GLenum param
= params
[0];
566 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
567 goto invalid_operation
;
569 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
572 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
574 texObj
->Sampler
.CubeMapSeamless
= param
;
585 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
586 _mesa_lookup_enum_by_nr(pname
));
590 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
591 _mesa_lookup_enum_by_nr(params
[0]));
595 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
596 _mesa_lookup_enum_by_nr(pname
));
602 * Set a float-valued texture parameter
603 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
606 set_tex_parameterf(struct gl_context
*ctx
,
607 struct gl_texture_object
*texObj
,
608 GLenum pname
, const GLfloat
*params
)
611 case GL_TEXTURE_MIN_LOD
:
612 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
615 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
616 goto invalid_operation
;
618 if (texObj
->Sampler
.MinLod
== params
[0])
621 texObj
->Sampler
.MinLod
= params
[0];
624 case GL_TEXTURE_MAX_LOD
:
625 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
628 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
629 goto invalid_operation
;
631 if (texObj
->Sampler
.MaxLod
== params
[0])
634 texObj
->Sampler
.MaxLod
= params
[0];
637 case GL_TEXTURE_PRIORITY
:
638 if (ctx
->API
!= API_OPENGL_COMPAT
)
642 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
645 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
646 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
647 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
648 goto invalid_operation
;
650 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
652 if (params
[0] < 1.0) {
653 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
657 /* clamp to max, that's what NVIDIA does */
658 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
659 ctx
->Const
.MaxTextureMaxAnisotropy
);
663 static GLuint count
= 0;
669 case GL_TEXTURE_LOD_BIAS
:
670 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
671 * It was removed in core-profile, and it has never existed in OpenGL
674 if (ctx
->API
!= API_OPENGL_COMPAT
)
677 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
678 goto invalid_operation
;
680 if (texObj
->Sampler
.LodBias
!= params
[0]) {
682 texObj
->Sampler
.LodBias
= params
[0];
687 case GL_TEXTURE_BORDER_COLOR
:
688 if (!_mesa_is_desktop_gl(ctx
))
691 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
692 goto invalid_operation
;
695 /* ARB_texture_float disables clamping */
696 if (ctx
->Extensions
.ARB_texture_float
) {
697 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
698 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
699 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
700 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
702 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
703 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
704 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
705 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
715 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
716 _mesa_lookup_enum_by_nr(pname
));
720 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
721 _mesa_lookup_enum_by_nr(pname
));
727 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
729 GLboolean need_update
;
730 struct gl_texture_object
*texObj
;
731 GET_CURRENT_CONTEXT(ctx
);
733 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
738 case GL_TEXTURE_MIN_FILTER
:
739 case GL_TEXTURE_MAG_FILTER
:
740 case GL_TEXTURE_WRAP_S
:
741 case GL_TEXTURE_WRAP_T
:
742 case GL_TEXTURE_WRAP_R
:
743 case GL_TEXTURE_BASE_LEVEL
:
744 case GL_TEXTURE_MAX_LEVEL
:
745 case GL_GENERATE_MIPMAP_SGIS
:
746 case GL_TEXTURE_COMPARE_MODE_ARB
:
747 case GL_TEXTURE_COMPARE_FUNC_ARB
:
748 case GL_DEPTH_TEXTURE_MODE_ARB
:
749 case GL_TEXTURE_SRGB_DECODE_EXT
:
750 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
751 case GL_TEXTURE_SWIZZLE_R_EXT
:
752 case GL_TEXTURE_SWIZZLE_G_EXT
:
753 case GL_TEXTURE_SWIZZLE_B_EXT
:
754 case GL_TEXTURE_SWIZZLE_A_EXT
:
758 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
759 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
761 p
[1] = p
[2] = p
[3] = 0;
762 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
767 /* this will generate an error if pname is illegal */
770 p
[1] = p
[2] = p
[3] = 0.0F
;
771 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
775 if (ctx
->Driver
.TexParameter
&& need_update
) {
776 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
782 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
784 GLboolean need_update
;
785 struct gl_texture_object
*texObj
;
786 GET_CURRENT_CONTEXT(ctx
);
788 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
793 case GL_TEXTURE_MIN_FILTER
:
794 case GL_TEXTURE_MAG_FILTER
:
795 case GL_TEXTURE_WRAP_S
:
796 case GL_TEXTURE_WRAP_T
:
797 case GL_TEXTURE_WRAP_R
:
798 case GL_TEXTURE_BASE_LEVEL
:
799 case GL_TEXTURE_MAX_LEVEL
:
800 case GL_GENERATE_MIPMAP_SGIS
:
801 case GL_TEXTURE_COMPARE_MODE_ARB
:
802 case GL_TEXTURE_COMPARE_FUNC_ARB
:
803 case GL_DEPTH_TEXTURE_MODE_ARB
:
804 case GL_TEXTURE_SRGB_DECODE_EXT
:
805 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
807 /* convert float param to int */
809 p
[0] = (GLint
) params
[0];
810 p
[1] = p
[2] = p
[3] = 0;
811 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
814 case GL_TEXTURE_CROP_RECT_OES
:
816 /* convert float params to int */
818 iparams
[0] = (GLint
) params
[0];
819 iparams
[1] = (GLint
) params
[1];
820 iparams
[2] = (GLint
) params
[2];
821 iparams
[3] = (GLint
) params
[3];
822 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
825 case GL_TEXTURE_SWIZZLE_R_EXT
:
826 case GL_TEXTURE_SWIZZLE_G_EXT
:
827 case GL_TEXTURE_SWIZZLE_B_EXT
:
828 case GL_TEXTURE_SWIZZLE_A_EXT
:
829 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
831 GLint p
[4] = {0, 0, 0, 0};
832 p
[0] = (GLint
) params
[0];
833 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
834 p
[1] = (GLint
) params
[1];
835 p
[2] = (GLint
) params
[2];
836 p
[3] = (GLint
) params
[3];
838 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
842 /* this will generate an error if pname is illegal */
843 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
846 if (ctx
->Driver
.TexParameter
&& need_update
) {
847 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
853 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
855 GLboolean need_update
;
856 struct gl_texture_object
*texObj
;
857 GET_CURRENT_CONTEXT(ctx
);
859 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
864 case GL_TEXTURE_MIN_LOD
:
865 case GL_TEXTURE_MAX_LOD
:
866 case GL_TEXTURE_PRIORITY
:
867 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
868 case GL_TEXTURE_LOD_BIAS
:
869 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
872 fparam
[0] = (GLfloat
) param
;
873 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
874 /* convert int param to float */
875 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
879 /* this will generate an error if pname is illegal */
883 iparam
[1] = iparam
[2] = iparam
[3] = 0;
884 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
888 if (ctx
->Driver
.TexParameter
&& need_update
) {
889 GLfloat fparam
= (GLfloat
) param
;
890 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
896 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
898 GLboolean need_update
;
899 struct gl_texture_object
*texObj
;
900 GET_CURRENT_CONTEXT(ctx
);
902 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
907 case GL_TEXTURE_BORDER_COLOR
:
909 /* convert int params to float */
911 fparams
[0] = INT_TO_FLOAT(params
[0]);
912 fparams
[1] = INT_TO_FLOAT(params
[1]);
913 fparams
[2] = INT_TO_FLOAT(params
[2]);
914 fparams
[3] = INT_TO_FLOAT(params
[3]);
915 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
918 case GL_TEXTURE_MIN_LOD
:
919 case GL_TEXTURE_MAX_LOD
:
920 case GL_TEXTURE_PRIORITY
:
921 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
922 case GL_TEXTURE_LOD_BIAS
:
923 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
925 /* convert int param to float */
927 fparams
[0] = (GLfloat
) params
[0];
928 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
929 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
933 /* this will generate an error if pname is illegal */
934 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
937 if (ctx
->Driver
.TexParameter
&& need_update
) {
939 fparams
[0] = INT_TO_FLOAT(params
[0]);
940 if (pname
== GL_TEXTURE_BORDER_COLOR
||
941 pname
== GL_TEXTURE_CROP_RECT_OES
) {
942 fparams
[1] = INT_TO_FLOAT(params
[1]);
943 fparams
[2] = INT_TO_FLOAT(params
[2]);
944 fparams
[3] = INT_TO_FLOAT(params
[3]);
946 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
952 * Set tex parameter to integer value(s). Primarily intended to set
953 * integer-valued texture border color (for integer-valued textures).
957 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
959 struct gl_texture_object
*texObj
;
960 GET_CURRENT_CONTEXT(ctx
);
962 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
967 case GL_TEXTURE_BORDER_COLOR
:
968 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
969 /* set the integer-valued border color */
970 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
973 _mesa_TexParameteriv(target
, pname
, params
);
976 /* XXX no driver hook for TexParameterIiv() yet */
981 * Set tex parameter to unsigned integer value(s). Primarily intended to set
982 * uint-valued texture border color (for integer-valued textures).
986 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
988 struct gl_texture_object
*texObj
;
989 GET_CURRENT_CONTEXT(ctx
);
991 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
996 case GL_TEXTURE_BORDER_COLOR
:
997 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
998 /* set the unsigned integer-valued border color */
999 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1002 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1005 /* XXX no driver hook for TexParameterIuiv() yet */
1010 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1014 case GL_PROXY_TEXTURE_1D
:
1016 case GL_PROXY_TEXTURE_2D
:
1018 case GL_PROXY_TEXTURE_3D
:
1020 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1021 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1022 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1023 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1024 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1025 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1026 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1027 return ctx
->Extensions
.ARB_texture_cube_map
;
1028 case GL_TEXTURE_RECTANGLE_NV
:
1029 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1030 return ctx
->Extensions
.NV_texture_rectangle
;
1031 case GL_TEXTURE_1D_ARRAY_EXT
:
1032 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1033 case GL_TEXTURE_2D_ARRAY_EXT
:
1034 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1035 return (ctx
->Extensions
.MESA_texture_array
||
1036 ctx
->Extensions
.EXT_texture_array
);
1037 case GL_TEXTURE_BUFFER
:
1038 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1039 * but not in earlier versions that expose ARB_texture_buffer_object.
1041 * From the ARB_texture_buffer_object spec:
1042 * "(7) Do buffer textures support texture parameters (TexParameter) or
1043 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1045 * RESOLVED: No. [...] Note that the spec edits above don't add
1046 * explicit error language for any of these cases. That is because
1047 * each of the functions enumerate the set of valid <target>
1048 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1049 * these cases means that target is not legal, and an INVALID_ENUM
1050 * error should be generated."
1052 * From the OpenGL 3.1 spec:
1053 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1055 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1056 case GL_TEXTURE_2D_MULTISAMPLE
:
1057 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1058 return ctx
->Extensions
.ARB_texture_multisample
;
1066 get_tex_level_parameter_image(struct gl_context
*ctx
,
1067 const struct gl_texture_object
*texObj
,
1068 GLenum target
, GLint level
,
1069 GLenum pname
, GLint
*params
)
1071 const struct gl_texture_image
*img
= NULL
;
1072 gl_format texFormat
;
1074 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1075 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1076 /* undefined texture image */
1077 if (pname
== GL_TEXTURE_COMPONENTS
)
1084 texFormat
= img
->TexFormat
;
1087 case GL_TEXTURE_WIDTH
:
1088 *params
= img
->Width
;
1090 case GL_TEXTURE_HEIGHT
:
1091 *params
= img
->Height
;
1093 case GL_TEXTURE_DEPTH
:
1094 *params
= img
->Depth
;
1096 case GL_TEXTURE_INTERNAL_FORMAT
:
1097 if (_mesa_is_format_compressed(texFormat
)) {
1098 /* need to return the actual compressed format */
1099 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1102 /* If the true internal format is not compressed but the user
1103 * requested a generic compressed format, we have to return the
1104 * generic base format that matches.
1106 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1108 * "If no specific compressed format is available,
1109 * internalformat is instead replaced by the corresponding base
1112 * Otherwise just return the user's requested internal format
1115 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1117 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1120 case GL_TEXTURE_BORDER
:
1121 *params
= img
->Border
;
1123 case GL_TEXTURE_RED_SIZE
:
1124 case GL_TEXTURE_GREEN_SIZE
:
1125 case GL_TEXTURE_BLUE_SIZE
:
1126 case GL_TEXTURE_ALPHA_SIZE
:
1127 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1128 *params
= _mesa_get_format_bits(texFormat
, pname
);
1132 case GL_TEXTURE_INTENSITY_SIZE
:
1133 case GL_TEXTURE_LUMINANCE_SIZE
:
1134 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1135 *params
= _mesa_get_format_bits(texFormat
, pname
);
1137 /* intensity or luminance is probably stored as RGB[A] */
1138 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1139 GL_TEXTURE_RED_SIZE
),
1140 _mesa_get_format_bits(texFormat
,
1141 GL_TEXTURE_GREEN_SIZE
));
1148 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1149 if (!ctx
->Extensions
.ARB_depth_texture
)
1151 *params
= _mesa_get_format_bits(texFormat
, pname
);
1153 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1154 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1155 !ctx
->Extensions
.ARB_framebuffer_object
)
1157 *params
= _mesa_get_format_bits(texFormat
, pname
);
1159 case GL_TEXTURE_SHARED_SIZE
:
1160 if (ctx
->Version
< 30 &&
1161 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1163 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1166 /* GL_ARB_texture_compression */
1167 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1168 if (_mesa_is_format_compressed(texFormat
) &&
1169 !_mesa_is_proxy_texture(target
)) {
1170 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1171 img
->Height
, img
->Depth
);
1174 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1175 "glGetTexLevelParameter[if]v(pname)");
1178 case GL_TEXTURE_COMPRESSED
:
1179 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1182 /* GL_ARB_texture_float */
1183 case GL_TEXTURE_RED_TYPE_ARB
:
1184 case GL_TEXTURE_GREEN_TYPE_ARB
:
1185 case GL_TEXTURE_BLUE_TYPE_ARB
:
1186 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1187 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1188 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1189 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1190 if (!ctx
->Extensions
.ARB_texture_float
)
1192 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1193 *params
= _mesa_get_format_datatype(texFormat
);
1198 /* GL_ARB_texture_multisample */
1199 case GL_TEXTURE_SAMPLES
:
1200 if (!ctx
->Extensions
.ARB_texture_multisample
)
1202 *params
= img
->NumSamples
;
1205 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1206 if (!ctx
->Extensions
.ARB_texture_multisample
)
1208 *params
= img
->FixedSampleLocations
;
1215 /* no error if we get here */
1219 _mesa_error(ctx
, GL_INVALID_ENUM
,
1220 "glGetTexLevelParameter[if]v(pname=%s)",
1221 _mesa_lookup_enum_by_nr(pname
));
1226 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1227 const struct gl_texture_object
*texObj
,
1228 GLenum pname
, GLint
*params
)
1230 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1231 gl_format texFormat
= texObj
->_BufferObjectFormat
;
1232 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1233 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1236 /* undefined texture buffer object */
1237 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1242 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1245 case GL_TEXTURE_WIDTH
:
1248 case GL_TEXTURE_HEIGHT
:
1249 case GL_TEXTURE_DEPTH
:
1250 case GL_TEXTURE_BORDER
:
1251 case GL_TEXTURE_SHARED_SIZE
:
1252 case GL_TEXTURE_COMPRESSED
:
1255 case GL_TEXTURE_INTERNAL_FORMAT
:
1256 *params
= internalFormat
;
1258 case GL_TEXTURE_RED_SIZE
:
1259 case GL_TEXTURE_GREEN_SIZE
:
1260 case GL_TEXTURE_BLUE_SIZE
:
1261 case GL_TEXTURE_ALPHA_SIZE
:
1262 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1263 *params
= _mesa_get_format_bits(texFormat
, pname
);
1267 case GL_TEXTURE_INTENSITY_SIZE
:
1268 case GL_TEXTURE_LUMINANCE_SIZE
:
1269 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1270 *params
= _mesa_get_format_bits(texFormat
, pname
);
1272 /* intensity or luminance is probably stored as RGB[A] */
1273 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1274 GL_TEXTURE_RED_SIZE
),
1275 _mesa_get_format_bits(texFormat
,
1276 GL_TEXTURE_GREEN_SIZE
));
1282 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1283 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1284 *params
= _mesa_get_format_bits(texFormat
, pname
);
1287 /* GL_ARB_texture_buffer_range */
1288 case GL_TEXTURE_BUFFER_OFFSET
:
1289 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1291 *params
= texObj
->BufferOffset
;
1293 case GL_TEXTURE_BUFFER_SIZE
:
1294 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1296 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1299 /* GL_ARB_texture_compression */
1300 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1301 /* Always illegal for GL_TEXTURE_BUFFER */
1302 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1303 "glGetTexLevelParameter[if]v(pname)");
1306 /* GL_ARB_texture_float */
1307 case GL_TEXTURE_RED_TYPE_ARB
:
1308 case GL_TEXTURE_GREEN_TYPE_ARB
:
1309 case GL_TEXTURE_BLUE_TYPE_ARB
:
1310 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1311 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1312 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1313 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1314 if (!ctx
->Extensions
.ARB_texture_float
)
1316 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1317 *params
= _mesa_get_format_datatype(texFormat
);
1326 /* no error if we get here */
1330 _mesa_error(ctx
, GL_INVALID_ENUM
,
1331 "glGetTexLevelParameter[if]v(pname=%s)",
1332 _mesa_lookup_enum_by_nr(pname
));
1337 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1338 GLenum pname
, GLfloat
*params
)
1341 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1342 *params
= (GLfloat
) iparam
;
1347 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1348 GLenum pname
, GLint
*params
)
1350 const struct gl_texture_unit
*texUnit
;
1351 struct gl_texture_object
*texObj
;
1353 GET_CURRENT_CONTEXT(ctx
);
1355 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1357 "glGetTexLevelParameteriv(current unit)");
1361 texUnit
= _mesa_get_current_tex_unit(ctx
);
1363 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1364 _mesa_error(ctx
, GL_INVALID_ENUM
,
1365 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1369 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1370 assert(maxLevels
!= 0);
1372 if (level
< 0 || level
>= maxLevels
) {
1373 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1377 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1379 if (target
== GL_TEXTURE_BUFFER
)
1380 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1382 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1387 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1389 struct gl_texture_object
*obj
;
1390 GET_CURRENT_CONTEXT(ctx
);
1392 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1396 _mesa_lock_texture(ctx
, obj
);
1398 case GL_TEXTURE_MAG_FILTER
:
1399 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1401 case GL_TEXTURE_MIN_FILTER
:
1402 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1404 case GL_TEXTURE_WRAP_S
:
1405 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1407 case GL_TEXTURE_WRAP_T
:
1408 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1410 case GL_TEXTURE_WRAP_R
:
1411 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1413 case GL_TEXTURE_BORDER_COLOR
:
1414 if (!_mesa_is_desktop_gl(ctx
))
1417 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1418 _mesa_update_state_locked(ctx
);
1419 if (_mesa_get_clamp_fragment_color(ctx
)) {
1420 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1421 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1422 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1423 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1426 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1427 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1428 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1429 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1432 case GL_TEXTURE_RESIDENT
:
1433 if (ctx
->API
!= API_OPENGL_COMPAT
)
1438 case GL_TEXTURE_PRIORITY
:
1439 if (ctx
->API
!= API_OPENGL_COMPAT
)
1442 *params
= obj
->Priority
;
1444 case GL_TEXTURE_MIN_LOD
:
1445 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1448 *params
= obj
->Sampler
.MinLod
;
1450 case GL_TEXTURE_MAX_LOD
:
1451 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1454 *params
= obj
->Sampler
.MaxLod
;
1456 case GL_TEXTURE_BASE_LEVEL
:
1457 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1460 *params
= (GLfloat
) obj
->BaseLevel
;
1462 case GL_TEXTURE_MAX_LEVEL
:
1463 *params
= (GLfloat
) obj
->MaxLevel
;
1465 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1466 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1468 *params
= obj
->Sampler
.MaxAnisotropy
;
1470 case GL_GENERATE_MIPMAP_SGIS
:
1471 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1474 *params
= (GLfloat
) obj
->GenerateMipmap
;
1476 case GL_TEXTURE_COMPARE_MODE_ARB
:
1477 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1478 && !_mesa_is_gles3(ctx
))
1480 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1482 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1483 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1484 && !_mesa_is_gles3(ctx
))
1486 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1488 case GL_DEPTH_TEXTURE_MODE_ARB
:
1489 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1490 * never existed in OpenGL ES.
1492 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1494 *params
= (GLfloat
) obj
->DepthMode
;
1496 case GL_TEXTURE_LOD_BIAS
:
1497 if (ctx
->API
!= API_OPENGL_COMPAT
)
1500 *params
= obj
->Sampler
.LodBias
;
1502 case GL_TEXTURE_CROP_RECT_OES
:
1503 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1506 params
[0] = (GLfloat
) obj
->CropRect
[0];
1507 params
[1] = (GLfloat
) obj
->CropRect
[1];
1508 params
[2] = (GLfloat
) obj
->CropRect
[2];
1509 params
[3] = (GLfloat
) obj
->CropRect
[3];
1512 case GL_TEXTURE_SWIZZLE_R_EXT
:
1513 case GL_TEXTURE_SWIZZLE_G_EXT
:
1514 case GL_TEXTURE_SWIZZLE_B_EXT
:
1515 case GL_TEXTURE_SWIZZLE_A_EXT
:
1516 if ((!_mesa_is_desktop_gl(ctx
)
1517 || !ctx
->Extensions
.EXT_texture_swizzle
)
1518 && !_mesa_is_gles3(ctx
))
1520 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1523 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1524 if ((!_mesa_is_desktop_gl(ctx
)
1525 || !ctx
->Extensions
.EXT_texture_swizzle
)
1526 && !_mesa_is_gles3(ctx
)) {
1531 for (comp
= 0; comp
< 4; comp
++) {
1532 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1537 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1538 if (!_mesa_is_desktop_gl(ctx
)
1539 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1541 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1544 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1545 if (!ctx
->Extensions
.ARB_texture_storage
)
1547 *params
= (GLfloat
) obj
->Immutable
;
1550 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1551 if (!_mesa_is_gles3(ctx
))
1553 *params
= (GLfloat
) obj
->ImmutableLevels
;
1556 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1557 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1559 *params
= obj
->RequiredTextureImageUnits
;
1562 case GL_TEXTURE_SRGB_DECODE_EXT
:
1563 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1565 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1572 /* no error if we get here */
1573 _mesa_unlock_texture(ctx
, obj
);
1577 _mesa_unlock_texture(ctx
, obj
);
1578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1583 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1585 struct gl_texture_object
*obj
;
1586 GET_CURRENT_CONTEXT(ctx
);
1588 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1592 _mesa_lock_texture(ctx
, obj
);
1594 case GL_TEXTURE_MAG_FILTER
:
1595 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1597 case GL_TEXTURE_MIN_FILTER
:
1598 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1600 case GL_TEXTURE_WRAP_S
:
1601 *params
= (GLint
) obj
->Sampler
.WrapS
;
1603 case GL_TEXTURE_WRAP_T
:
1604 *params
= (GLint
) obj
->Sampler
.WrapT
;
1606 case GL_TEXTURE_WRAP_R
:
1607 *params
= (GLint
) obj
->Sampler
.WrapR
;
1609 case GL_TEXTURE_BORDER_COLOR
:
1610 if (!_mesa_is_desktop_gl(ctx
))
1615 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1616 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1617 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1618 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1619 params
[0] = FLOAT_TO_INT(b
[0]);
1620 params
[1] = FLOAT_TO_INT(b
[1]);
1621 params
[2] = FLOAT_TO_INT(b
[2]);
1622 params
[3] = FLOAT_TO_INT(b
[3]);
1625 case GL_TEXTURE_RESIDENT
:
1626 if (ctx
->API
!= API_OPENGL_COMPAT
)
1631 case GL_TEXTURE_PRIORITY
:
1632 if (ctx
->API
!= API_OPENGL_COMPAT
)
1635 *params
= FLOAT_TO_INT(obj
->Priority
);
1637 case GL_TEXTURE_MIN_LOD
:
1638 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1641 *params
= (GLint
) obj
->Sampler
.MinLod
;
1643 case GL_TEXTURE_MAX_LOD
:
1644 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1647 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1649 case GL_TEXTURE_BASE_LEVEL
:
1650 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1653 *params
= obj
->BaseLevel
;
1655 case GL_TEXTURE_MAX_LEVEL
:
1656 *params
= obj
->MaxLevel
;
1658 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1659 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1661 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1663 case GL_GENERATE_MIPMAP_SGIS
:
1664 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1667 *params
= (GLint
) obj
->GenerateMipmap
;
1669 case GL_TEXTURE_COMPARE_MODE_ARB
:
1670 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1671 && !_mesa_is_gles3(ctx
))
1673 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1675 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1676 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1677 && !_mesa_is_gles3(ctx
))
1679 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1681 case GL_DEPTH_TEXTURE_MODE_ARB
:
1682 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1684 *params
= (GLint
) obj
->DepthMode
;
1686 case GL_TEXTURE_LOD_BIAS
:
1687 if (ctx
->API
!= API_OPENGL_COMPAT
)
1690 *params
= (GLint
) obj
->Sampler
.LodBias
;
1692 case GL_TEXTURE_CROP_RECT_OES
:
1693 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1696 params
[0] = obj
->CropRect
[0];
1697 params
[1] = obj
->CropRect
[1];
1698 params
[2] = obj
->CropRect
[2];
1699 params
[3] = obj
->CropRect
[3];
1701 case GL_TEXTURE_SWIZZLE_R_EXT
:
1702 case GL_TEXTURE_SWIZZLE_G_EXT
:
1703 case GL_TEXTURE_SWIZZLE_B_EXT
:
1704 case GL_TEXTURE_SWIZZLE_A_EXT
:
1705 if ((!_mesa_is_desktop_gl(ctx
)
1706 || !ctx
->Extensions
.EXT_texture_swizzle
)
1707 && !_mesa_is_gles3(ctx
))
1709 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1712 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1713 if ((!_mesa_is_desktop_gl(ctx
)
1714 || !ctx
->Extensions
.EXT_texture_swizzle
)
1715 && !_mesa_is_gles3(ctx
))
1717 COPY_4V(params
, obj
->Swizzle
);
1720 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1721 if (!_mesa_is_desktop_gl(ctx
)
1722 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1724 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1727 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1728 if (!ctx
->Extensions
.ARB_texture_storage
)
1730 *params
= (GLint
) obj
->Immutable
;
1733 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1734 if (!_mesa_is_gles3(ctx
))
1736 *params
= obj
->ImmutableLevels
;
1739 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1740 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1742 *params
= obj
->RequiredTextureImageUnits
;
1745 case GL_TEXTURE_SRGB_DECODE_EXT
:
1746 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1748 *params
= obj
->Sampler
.sRGBDecode
;
1755 /* no error if we get here */
1756 _mesa_unlock_texture(ctx
, obj
);
1760 _mesa_unlock_texture(ctx
, obj
);
1761 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1765 /** New in GL 3.0 */
1767 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1769 struct gl_texture_object
*texObj
;
1770 GET_CURRENT_CONTEXT(ctx
);
1772 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1777 case GL_TEXTURE_BORDER_COLOR
:
1778 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1781 _mesa_GetTexParameteriv(target
, pname
, params
);
1786 /** New in GL 3.0 */
1788 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1790 struct gl_texture_object
*texObj
;
1791 GET_CURRENT_CONTEXT(ctx
);
1793 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1798 case GL_TEXTURE_BORDER_COLOR
:
1799 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1804 _mesa_GetTexParameteriv(target
, pname
, ip
);
1806 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1807 pname
== GL_TEXTURE_CROP_RECT_OES
) {