2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * glTexParameter-related functions
33 #include "main/glheader.h"
34 #include "main/blend.h"
35 #include "main/colormac.h"
36 #include "main/context.h"
37 #include "main/enums.h"
38 #include "main/formats.h"
39 #include "main/glformats.h"
40 #include "main/macros.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texcompress.h"
44 #include "main/texobj.h"
45 #include "main/texparam.h"
46 #include "main/teximage.h"
47 #include "main/texstate.h"
48 #include "program/prog_instruction.h"
52 * Check if a coordinate wrap mode is supported for the texture target.
53 * \return GL_TRUE if legal, GL_FALSE otherwise
56 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
58 const struct gl_extensions
* const e
= & ctx
->Extensions
;
59 const bool is_desktop_gl
= _mesa_is_desktop_gl(ctx
);
64 /* GL_CLAMP was removed in the core profile, and it has never existed in
67 supported
= (ctx
->API
== API_OPENGL_COMPAT
)
68 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
71 case GL_CLAMP_TO_EDGE
:
75 case GL_CLAMP_TO_BORDER
:
76 supported
= is_desktop_gl
&& e
->ARB_texture_border_clamp
77 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
81 case GL_MIRRORED_REPEAT
:
82 supported
= (target
!= GL_TEXTURE_RECTANGLE_NV
)
83 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
86 case GL_MIRROR_CLAMP_EXT
:
87 supported
= is_desktop_gl
88 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
89 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
90 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
93 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
94 supported
= is_desktop_gl
95 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
)
96 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
97 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
100 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
101 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
102 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
103 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
112 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
119 * Get current texture object for given target.
120 * Return NULL if any error (and record the error).
121 * Note that this is different from _mesa_select_tex_object() in that proxy
122 * targets are not accepted.
123 * Only the glGetTexLevelParameter() functions accept proxy targets.
125 static struct gl_texture_object
*
126 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
128 struct gl_texture_unit
*texUnit
;
130 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
131 _mesa_error(ctx
, GL_INVALID_OPERATION
,
132 "gl%sTexParameter(current unit)", get
? "Get" : "");
136 texUnit
= _mesa_get_current_tex_unit(ctx
);
140 if (_mesa_is_desktop_gl(ctx
))
141 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
144 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
146 if (ctx
->API
!= API_OPENGLES
)
147 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
149 case GL_TEXTURE_CUBE_MAP
:
150 if (ctx
->Extensions
.ARB_texture_cube_map
) {
151 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
154 case GL_TEXTURE_RECTANGLE_NV
:
155 if (_mesa_is_desktop_gl(ctx
)
156 && ctx
->Extensions
.NV_texture_rectangle
) {
157 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
160 case GL_TEXTURE_1D_ARRAY_EXT
:
161 if (_mesa_is_desktop_gl(ctx
)
162 && (ctx
->Extensions
.MESA_texture_array
||
163 ctx
->Extensions
.EXT_texture_array
)) {
164 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
167 case GL_TEXTURE_2D_ARRAY_EXT
:
168 if ((_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
169 && (ctx
->Extensions
.MESA_texture_array
||
170 ctx
->Extensions
.EXT_texture_array
)) {
171 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
174 case GL_TEXTURE_EXTERNAL_OES
:
175 if (_mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
) {
176 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
179 case GL_TEXTURE_CUBE_MAP_ARRAY
:
180 if (ctx
->Extensions
.ARB_texture_cube_map_array
) {
181 return texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
];
184 case GL_TEXTURE_2D_MULTISAMPLE
:
185 if (ctx
->Extensions
.ARB_texture_multisample
) {
186 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
];
189 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
190 if (ctx
->Extensions
.ARB_texture_multisample
) {
191 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
];
198 _mesa_error(ctx
, GL_INVALID_ENUM
,
199 "gl%sTexParameter(target)", get
? "Get" : "");
205 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
206 * \return -1 if error.
209 comp_to_swizzle(GLenum comp
)
231 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
234 ASSERT(swz
<= SWIZZLE_NIL
);
236 GLuint mask
= 0x7 << (3 * comp
);
237 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
244 * This is called just prior to changing any texture object state which
245 * will not effect texture completeness.
248 flush(struct gl_context
*ctx
)
250 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
255 * This is called just prior to changing any texture object state which
256 * can effect texture completeness (texture base level, max level).
257 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
258 * state flag and then mark the texture object as 'incomplete' so that any
259 * per-texture derived state gets recomputed.
262 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
264 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
265 _mesa_dirty_texobj(ctx
, texObj
);
270 target_allows_setting_sampler_parameters(GLenum target
)
273 case GL_TEXTURE_2D_MULTISAMPLE
:
274 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
284 * Set an integer-valued texture parameter
285 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
288 set_tex_parameteri(struct gl_context
*ctx
,
289 struct gl_texture_object
*texObj
,
290 GLenum pname
, const GLint
*params
)
293 case GL_TEXTURE_MIN_FILTER
:
294 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
295 goto invalid_operation
;
297 if (texObj
->Sampler
.MinFilter
== params
[0])
303 texObj
->Sampler
.MinFilter
= params
[0];
305 case GL_NEAREST_MIPMAP_NEAREST
:
306 case GL_LINEAR_MIPMAP_NEAREST
:
307 case GL_NEAREST_MIPMAP_LINEAR
:
308 case GL_LINEAR_MIPMAP_LINEAR
:
309 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
310 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
312 texObj
->Sampler
.MinFilter
= params
[0];
321 case GL_TEXTURE_MAG_FILTER
:
322 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
323 goto invalid_operation
;
325 if (texObj
->Sampler
.MagFilter
== params
[0])
330 flush(ctx
); /* does not effect completeness */
331 texObj
->Sampler
.MagFilter
= params
[0];
338 case GL_TEXTURE_WRAP_S
:
339 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
340 goto invalid_operation
;
342 if (texObj
->Sampler
.WrapS
== params
[0])
344 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
346 texObj
->Sampler
.WrapS
= params
[0];
351 case GL_TEXTURE_WRAP_T
:
352 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
353 goto invalid_operation
;
355 if (texObj
->Sampler
.WrapT
== params
[0])
357 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
359 texObj
->Sampler
.WrapT
= params
[0];
364 case GL_TEXTURE_WRAP_R
:
365 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
366 goto invalid_operation
;
368 if (texObj
->Sampler
.WrapR
== params
[0])
370 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
372 texObj
->Sampler
.WrapR
= params
[0];
377 case GL_TEXTURE_BASE_LEVEL
:
378 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
381 if (texObj
->BaseLevel
== params
[0])
384 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
385 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
386 goto invalid_operation
;
389 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
390 _mesa_error(ctx
, GL_INVALID_VALUE
,
391 "glTexParameter(param=%d)", params
[0]);
394 incomplete(ctx
, texObj
);
396 /** See note about ARB_texture_storage below */
397 if (texObj
->Immutable
)
398 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
400 texObj
->BaseLevel
= params
[0];
404 case GL_TEXTURE_MAX_LEVEL
:
405 if (texObj
->MaxLevel
== params
[0])
408 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
409 _mesa_error(ctx
, GL_INVALID_VALUE
,
410 "glTexParameter(param=%d)", params
[0]);
413 incomplete(ctx
, texObj
);
415 /** From ARB_texture_storage:
416 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
417 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
418 * the range [level_base, <levels> - 1], where <levels> is the parameter
419 * passed the call to TexStorage* for the texture object.
421 if (texObj
->Immutable
)
422 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
423 texObj
->ImmutableLevels
- 1);
425 texObj
->MaxLevel
= params
[0];
429 case GL_GENERATE_MIPMAP_SGIS
:
430 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
433 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
435 if (texObj
->GenerateMipmap
!= params
[0]) {
437 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
442 case GL_TEXTURE_COMPARE_MODE_ARB
:
443 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
444 || _mesa_is_gles3(ctx
)) {
446 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
447 goto invalid_operation
;
449 if (texObj
->Sampler
.CompareMode
== params
[0])
451 if (params
[0] == GL_NONE
||
452 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
454 texObj
->Sampler
.CompareMode
= params
[0];
461 case GL_TEXTURE_COMPARE_FUNC_ARB
:
462 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
463 || _mesa_is_gles3(ctx
)) {
465 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
466 goto invalid_operation
;
468 if (texObj
->Sampler
.CompareFunc
== params
[0])
480 texObj
->Sampler
.CompareFunc
= params
[0];
488 case GL_DEPTH_TEXTURE_MODE_ARB
:
489 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
490 * existed in OpenGL ES.
492 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
493 if (texObj
->DepthMode
== params
[0])
495 if (params
[0] == GL_LUMINANCE
||
496 params
[0] == GL_INTENSITY
||
497 params
[0] == GL_ALPHA
||
498 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
500 texObj
->DepthMode
= params
[0];
507 case GL_TEXTURE_CROP_RECT_OES
:
508 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
511 texObj
->CropRect
[0] = params
[0];
512 texObj
->CropRect
[1] = params
[1];
513 texObj
->CropRect
[2] = params
[2];
514 texObj
->CropRect
[3] = params
[3];
517 case GL_TEXTURE_SWIZZLE_R_EXT
:
518 case GL_TEXTURE_SWIZZLE_G_EXT
:
519 case GL_TEXTURE_SWIZZLE_B_EXT
:
520 case GL_TEXTURE_SWIZZLE_A_EXT
:
521 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
522 || _mesa_is_gles3(ctx
)) {
523 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
524 const GLint swz
= comp_to_swizzle(params
[0]);
526 _mesa_error(ctx
, GL_INVALID_OPERATION
,
527 "glTexParameter(swizzle 0x%x)", params
[0]);
533 texObj
->Swizzle
[comp
] = params
[0];
534 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
539 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
540 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
541 || _mesa_is_gles3(ctx
)) {
544 for (comp
= 0; comp
< 4; comp
++) {
545 const GLint swz
= comp_to_swizzle(params
[comp
]);
547 texObj
->Swizzle
[comp
] = params
[comp
];
548 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
551 _mesa_error(ctx
, GL_INVALID_OPERATION
,
552 "glTexParameter(swizzle 0x%x)", params
[comp
]);
560 case GL_TEXTURE_SRGB_DECODE_EXT
:
561 if (_mesa_is_desktop_gl(ctx
)
562 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
563 GLenum decode
= params
[0];
565 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
566 goto invalid_operation
;
568 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
569 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
571 texObj
->Sampler
.sRGBDecode
= decode
;
578 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
579 if (_mesa_is_desktop_gl(ctx
)
580 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
581 GLenum param
= params
[0];
583 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
584 goto invalid_operation
;
586 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
589 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
591 texObj
->Sampler
.CubeMapSeamless
= param
;
602 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
603 _mesa_lookup_enum_by_nr(pname
));
607 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
608 _mesa_lookup_enum_by_nr(params
[0]));
612 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
613 _mesa_lookup_enum_by_nr(pname
));
619 * Set a float-valued texture parameter
620 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
623 set_tex_parameterf(struct gl_context
*ctx
,
624 struct gl_texture_object
*texObj
,
625 GLenum pname
, const GLfloat
*params
)
628 case GL_TEXTURE_MIN_LOD
:
629 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
632 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
633 goto invalid_operation
;
635 if (texObj
->Sampler
.MinLod
== params
[0])
638 texObj
->Sampler
.MinLod
= params
[0];
641 case GL_TEXTURE_MAX_LOD
:
642 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
645 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
646 goto invalid_operation
;
648 if (texObj
->Sampler
.MaxLod
== params
[0])
651 texObj
->Sampler
.MaxLod
= params
[0];
654 case GL_TEXTURE_PRIORITY
:
655 if (ctx
->API
!= API_OPENGL_COMPAT
)
659 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
662 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
663 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
664 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
665 goto invalid_operation
;
667 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
669 if (params
[0] < 1.0) {
670 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
674 /* clamp to max, that's what NVIDIA does */
675 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
676 ctx
->Const
.MaxTextureMaxAnisotropy
);
680 static GLuint count
= 0;
686 case GL_TEXTURE_LOD_BIAS
:
687 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
688 * It was removed in core-profile, and it has never existed in OpenGL
691 if (ctx
->API
!= API_OPENGL_COMPAT
)
694 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
695 goto invalid_operation
;
697 if (texObj
->Sampler
.LodBias
!= params
[0]) {
699 texObj
->Sampler
.LodBias
= params
[0];
704 case GL_TEXTURE_BORDER_COLOR
:
705 if (!_mesa_is_desktop_gl(ctx
))
708 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
709 goto invalid_operation
;
712 /* ARB_texture_float disables clamping */
713 if (ctx
->Extensions
.ARB_texture_float
) {
714 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
715 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
716 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
717 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
719 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
720 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
721 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
722 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
732 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
733 _mesa_lookup_enum_by_nr(pname
));
737 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
738 _mesa_lookup_enum_by_nr(pname
));
744 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
746 GLboolean need_update
;
747 struct gl_texture_object
*texObj
;
748 GET_CURRENT_CONTEXT(ctx
);
750 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
755 case GL_TEXTURE_MIN_FILTER
:
756 case GL_TEXTURE_MAG_FILTER
:
757 case GL_TEXTURE_WRAP_S
:
758 case GL_TEXTURE_WRAP_T
:
759 case GL_TEXTURE_WRAP_R
:
760 case GL_TEXTURE_BASE_LEVEL
:
761 case GL_TEXTURE_MAX_LEVEL
:
762 case GL_GENERATE_MIPMAP_SGIS
:
763 case GL_TEXTURE_COMPARE_MODE_ARB
:
764 case GL_TEXTURE_COMPARE_FUNC_ARB
:
765 case GL_DEPTH_TEXTURE_MODE_ARB
:
766 case GL_TEXTURE_SRGB_DECODE_EXT
:
767 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
768 case GL_TEXTURE_SWIZZLE_R_EXT
:
769 case GL_TEXTURE_SWIZZLE_G_EXT
:
770 case GL_TEXTURE_SWIZZLE_B_EXT
:
771 case GL_TEXTURE_SWIZZLE_A_EXT
:
775 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
776 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
778 p
[1] = p
[2] = p
[3] = 0;
779 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
784 /* this will generate an error if pname is illegal */
787 p
[1] = p
[2] = p
[3] = 0.0F
;
788 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
792 if (ctx
->Driver
.TexParameter
&& need_update
) {
793 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
799 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
801 GLboolean need_update
;
802 struct gl_texture_object
*texObj
;
803 GET_CURRENT_CONTEXT(ctx
);
805 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
810 case GL_TEXTURE_MIN_FILTER
:
811 case GL_TEXTURE_MAG_FILTER
:
812 case GL_TEXTURE_WRAP_S
:
813 case GL_TEXTURE_WRAP_T
:
814 case GL_TEXTURE_WRAP_R
:
815 case GL_TEXTURE_BASE_LEVEL
:
816 case GL_TEXTURE_MAX_LEVEL
:
817 case GL_GENERATE_MIPMAP_SGIS
:
818 case GL_TEXTURE_COMPARE_MODE_ARB
:
819 case GL_TEXTURE_COMPARE_FUNC_ARB
:
820 case GL_DEPTH_TEXTURE_MODE_ARB
:
821 case GL_TEXTURE_SRGB_DECODE_EXT
:
822 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
824 /* convert float param to int */
826 p
[0] = (GLint
) params
[0];
827 p
[1] = p
[2] = p
[3] = 0;
828 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
831 case GL_TEXTURE_CROP_RECT_OES
:
833 /* convert float params to int */
835 iparams
[0] = (GLint
) params
[0];
836 iparams
[1] = (GLint
) params
[1];
837 iparams
[2] = (GLint
) params
[2];
838 iparams
[3] = (GLint
) params
[3];
839 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
842 case GL_TEXTURE_SWIZZLE_R_EXT
:
843 case GL_TEXTURE_SWIZZLE_G_EXT
:
844 case GL_TEXTURE_SWIZZLE_B_EXT
:
845 case GL_TEXTURE_SWIZZLE_A_EXT
:
846 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
848 GLint p
[4] = {0, 0, 0, 0};
849 p
[0] = (GLint
) params
[0];
850 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
851 p
[1] = (GLint
) params
[1];
852 p
[2] = (GLint
) params
[2];
853 p
[3] = (GLint
) params
[3];
855 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
859 /* this will generate an error if pname is illegal */
860 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
863 if (ctx
->Driver
.TexParameter
&& need_update
) {
864 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
870 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
872 GLboolean need_update
;
873 struct gl_texture_object
*texObj
;
874 GET_CURRENT_CONTEXT(ctx
);
876 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
881 case GL_TEXTURE_MIN_LOD
:
882 case GL_TEXTURE_MAX_LOD
:
883 case GL_TEXTURE_PRIORITY
:
884 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
885 case GL_TEXTURE_LOD_BIAS
:
886 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
889 fparam
[0] = (GLfloat
) param
;
890 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
891 /* convert int param to float */
892 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
896 /* this will generate an error if pname is illegal */
900 iparam
[1] = iparam
[2] = iparam
[3] = 0;
901 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
905 if (ctx
->Driver
.TexParameter
&& need_update
) {
906 GLfloat fparam
= (GLfloat
) param
;
907 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
913 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
915 GLboolean need_update
;
916 struct gl_texture_object
*texObj
;
917 GET_CURRENT_CONTEXT(ctx
);
919 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
924 case GL_TEXTURE_BORDER_COLOR
:
926 /* convert int params to float */
928 fparams
[0] = INT_TO_FLOAT(params
[0]);
929 fparams
[1] = INT_TO_FLOAT(params
[1]);
930 fparams
[2] = INT_TO_FLOAT(params
[2]);
931 fparams
[3] = INT_TO_FLOAT(params
[3]);
932 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
935 case GL_TEXTURE_MIN_LOD
:
936 case GL_TEXTURE_MAX_LOD
:
937 case GL_TEXTURE_PRIORITY
:
938 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
939 case GL_TEXTURE_LOD_BIAS
:
940 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
942 /* convert int param to float */
944 fparams
[0] = (GLfloat
) params
[0];
945 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
946 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
950 /* this will generate an error if pname is illegal */
951 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
954 if (ctx
->Driver
.TexParameter
&& need_update
) {
956 fparams
[0] = INT_TO_FLOAT(params
[0]);
957 if (pname
== GL_TEXTURE_BORDER_COLOR
||
958 pname
== GL_TEXTURE_CROP_RECT_OES
) {
959 fparams
[1] = INT_TO_FLOAT(params
[1]);
960 fparams
[2] = INT_TO_FLOAT(params
[2]);
961 fparams
[3] = INT_TO_FLOAT(params
[3]);
963 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
969 * Set tex parameter to integer value(s). Primarily intended to set
970 * integer-valued texture border color (for integer-valued textures).
974 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
976 struct gl_texture_object
*texObj
;
977 GET_CURRENT_CONTEXT(ctx
);
979 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
984 case GL_TEXTURE_BORDER_COLOR
:
985 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
986 /* set the integer-valued border color */
987 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
990 _mesa_TexParameteriv(target
, pname
, params
);
993 /* XXX no driver hook for TexParameterIiv() yet */
998 * Set tex parameter to unsigned integer value(s). Primarily intended to set
999 * uint-valued texture border color (for integer-valued textures).
1003 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
1005 struct gl_texture_object
*texObj
;
1006 GET_CURRENT_CONTEXT(ctx
);
1008 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
1013 case GL_TEXTURE_BORDER_COLOR
:
1014 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1015 /* set the unsigned integer-valued border color */
1016 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1019 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1022 /* XXX no driver hook for TexParameterIuiv() yet */
1027 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1031 case GL_PROXY_TEXTURE_1D
:
1033 case GL_PROXY_TEXTURE_2D
:
1035 case GL_PROXY_TEXTURE_3D
:
1037 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1038 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1039 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1040 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1041 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1042 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1043 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1044 return ctx
->Extensions
.ARB_texture_cube_map
;
1045 case GL_TEXTURE_RECTANGLE_NV
:
1046 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1047 return ctx
->Extensions
.NV_texture_rectangle
;
1048 case GL_TEXTURE_1D_ARRAY_EXT
:
1049 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1050 case GL_TEXTURE_2D_ARRAY_EXT
:
1051 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1052 return (ctx
->Extensions
.MESA_texture_array
||
1053 ctx
->Extensions
.EXT_texture_array
);
1054 case GL_TEXTURE_BUFFER
:
1055 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1056 * but not in earlier versions that expose ARB_texture_buffer_object.
1058 * From the ARB_texture_buffer_object spec:
1059 * "(7) Do buffer textures support texture parameters (TexParameter) or
1060 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1062 * RESOLVED: No. [...] Note that the spec edits above don't add
1063 * explicit error language for any of these cases. That is because
1064 * each of the functions enumerate the set of valid <target>
1065 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1066 * these cases means that target is not legal, and an INVALID_ENUM
1067 * error should be generated."
1069 * From the OpenGL 3.1 spec:
1070 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1072 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1073 case GL_TEXTURE_2D_MULTISAMPLE
:
1074 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1075 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1076 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1077 return ctx
->Extensions
.ARB_texture_multisample
;
1085 get_tex_level_parameter_image(struct gl_context
*ctx
,
1086 const struct gl_texture_object
*texObj
,
1087 GLenum target
, GLint level
,
1088 GLenum pname
, GLint
*params
)
1090 const struct gl_texture_image
*img
= NULL
;
1091 gl_format texFormat
;
1093 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1094 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1095 /* undefined texture image */
1096 if (pname
== GL_TEXTURE_COMPONENTS
)
1103 texFormat
= img
->TexFormat
;
1106 case GL_TEXTURE_WIDTH
:
1107 *params
= img
->Width
;
1109 case GL_TEXTURE_HEIGHT
:
1110 *params
= img
->Height
;
1112 case GL_TEXTURE_DEPTH
:
1113 *params
= img
->Depth
;
1115 case GL_TEXTURE_INTERNAL_FORMAT
:
1116 if (_mesa_is_format_compressed(texFormat
)) {
1117 /* need to return the actual compressed format */
1118 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1121 /* If the true internal format is not compressed but the user
1122 * requested a generic compressed format, we have to return the
1123 * generic base format that matches.
1125 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1127 * "If no specific compressed format is available,
1128 * internalformat is instead replaced by the corresponding base
1131 * Otherwise just return the user's requested internal format
1134 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1136 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1139 case GL_TEXTURE_BORDER
:
1140 *params
= img
->Border
;
1142 case GL_TEXTURE_RED_SIZE
:
1143 case GL_TEXTURE_GREEN_SIZE
:
1144 case GL_TEXTURE_BLUE_SIZE
:
1145 case GL_TEXTURE_ALPHA_SIZE
:
1146 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1147 *params
= _mesa_get_format_bits(texFormat
, pname
);
1151 case GL_TEXTURE_INTENSITY_SIZE
:
1152 case GL_TEXTURE_LUMINANCE_SIZE
:
1153 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1154 *params
= _mesa_get_format_bits(texFormat
, pname
);
1156 /* intensity or luminance is probably stored as RGB[A] */
1157 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1158 GL_TEXTURE_RED_SIZE
),
1159 _mesa_get_format_bits(texFormat
,
1160 GL_TEXTURE_GREEN_SIZE
));
1167 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1168 if (!ctx
->Extensions
.ARB_depth_texture
)
1170 *params
= _mesa_get_format_bits(texFormat
, pname
);
1172 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1173 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1174 !ctx
->Extensions
.ARB_framebuffer_object
)
1176 *params
= _mesa_get_format_bits(texFormat
, pname
);
1178 case GL_TEXTURE_SHARED_SIZE
:
1179 if (ctx
->Version
< 30 &&
1180 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1182 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1185 /* GL_ARB_texture_compression */
1186 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1187 if (_mesa_is_format_compressed(texFormat
) &&
1188 !_mesa_is_proxy_texture(target
)) {
1189 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1190 img
->Height
, img
->Depth
);
1193 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1194 "glGetTexLevelParameter[if]v(pname)");
1197 case GL_TEXTURE_COMPRESSED
:
1198 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1201 /* GL_ARB_texture_float */
1202 case GL_TEXTURE_RED_TYPE_ARB
:
1203 case GL_TEXTURE_GREEN_TYPE_ARB
:
1204 case GL_TEXTURE_BLUE_TYPE_ARB
:
1205 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1206 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1207 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1208 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1209 if (!ctx
->Extensions
.ARB_texture_float
)
1211 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1212 *params
= _mesa_get_format_datatype(texFormat
);
1217 /* GL_ARB_texture_multisample */
1218 case GL_TEXTURE_SAMPLES
:
1219 if (!ctx
->Extensions
.ARB_texture_multisample
)
1221 *params
= img
->NumSamples
;
1224 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1225 if (!ctx
->Extensions
.ARB_texture_multisample
)
1227 *params
= img
->FixedSampleLocations
;
1234 /* no error if we get here */
1238 _mesa_error(ctx
, GL_INVALID_ENUM
,
1239 "glGetTexLevelParameter[if]v(pname=%s)",
1240 _mesa_lookup_enum_by_nr(pname
));
1245 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1246 const struct gl_texture_object
*texObj
,
1247 GLenum pname
, GLint
*params
)
1249 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1250 gl_format texFormat
= texObj
->_BufferObjectFormat
;
1251 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1252 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1255 /* undefined texture buffer object */
1256 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1261 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1264 case GL_TEXTURE_WIDTH
:
1267 case GL_TEXTURE_HEIGHT
:
1268 case GL_TEXTURE_DEPTH
:
1269 case GL_TEXTURE_BORDER
:
1270 case GL_TEXTURE_SHARED_SIZE
:
1271 case GL_TEXTURE_COMPRESSED
:
1274 case GL_TEXTURE_INTERNAL_FORMAT
:
1275 *params
= internalFormat
;
1277 case GL_TEXTURE_RED_SIZE
:
1278 case GL_TEXTURE_GREEN_SIZE
:
1279 case GL_TEXTURE_BLUE_SIZE
:
1280 case GL_TEXTURE_ALPHA_SIZE
:
1281 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1282 *params
= _mesa_get_format_bits(texFormat
, pname
);
1286 case GL_TEXTURE_INTENSITY_SIZE
:
1287 case GL_TEXTURE_LUMINANCE_SIZE
:
1288 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1289 *params
= _mesa_get_format_bits(texFormat
, pname
);
1291 /* intensity or luminance is probably stored as RGB[A] */
1292 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1293 GL_TEXTURE_RED_SIZE
),
1294 _mesa_get_format_bits(texFormat
,
1295 GL_TEXTURE_GREEN_SIZE
));
1301 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1302 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1303 *params
= _mesa_get_format_bits(texFormat
, pname
);
1306 /* GL_ARB_texture_buffer_range */
1307 case GL_TEXTURE_BUFFER_OFFSET
:
1308 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1310 *params
= texObj
->BufferOffset
;
1312 case GL_TEXTURE_BUFFER_SIZE
:
1313 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1315 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1318 /* GL_ARB_texture_compression */
1319 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1320 /* Always illegal for GL_TEXTURE_BUFFER */
1321 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1322 "glGetTexLevelParameter[if]v(pname)");
1325 /* GL_ARB_texture_float */
1326 case GL_TEXTURE_RED_TYPE_ARB
:
1327 case GL_TEXTURE_GREEN_TYPE_ARB
:
1328 case GL_TEXTURE_BLUE_TYPE_ARB
:
1329 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1330 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1331 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1332 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1333 if (!ctx
->Extensions
.ARB_texture_float
)
1335 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1336 *params
= _mesa_get_format_datatype(texFormat
);
1345 /* no error if we get here */
1349 _mesa_error(ctx
, GL_INVALID_ENUM
,
1350 "glGetTexLevelParameter[if]v(pname=%s)",
1351 _mesa_lookup_enum_by_nr(pname
));
1356 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1357 GLenum pname
, GLfloat
*params
)
1360 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1361 *params
= (GLfloat
) iparam
;
1366 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1367 GLenum pname
, GLint
*params
)
1369 const struct gl_texture_unit
*texUnit
;
1370 struct gl_texture_object
*texObj
;
1372 GET_CURRENT_CONTEXT(ctx
);
1374 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1375 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1376 "glGetTexLevelParameteriv(current unit)");
1380 texUnit
= _mesa_get_current_tex_unit(ctx
);
1382 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1383 _mesa_error(ctx
, GL_INVALID_ENUM
,
1384 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1388 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1389 assert(maxLevels
!= 0);
1391 if (level
< 0 || level
>= maxLevels
) {
1392 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1396 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1398 if (target
== GL_TEXTURE_BUFFER
)
1399 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1401 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1406 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1408 struct gl_texture_object
*obj
;
1409 GET_CURRENT_CONTEXT(ctx
);
1411 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1415 _mesa_lock_texture(ctx
, obj
);
1417 case GL_TEXTURE_MAG_FILTER
:
1418 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1420 case GL_TEXTURE_MIN_FILTER
:
1421 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1423 case GL_TEXTURE_WRAP_S
:
1424 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1426 case GL_TEXTURE_WRAP_T
:
1427 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1429 case GL_TEXTURE_WRAP_R
:
1430 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1432 case GL_TEXTURE_BORDER_COLOR
:
1433 if (!_mesa_is_desktop_gl(ctx
))
1436 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1437 _mesa_update_state_locked(ctx
);
1438 if (_mesa_get_clamp_fragment_color(ctx
)) {
1439 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1440 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1441 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1442 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1445 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1446 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1447 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1448 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1451 case GL_TEXTURE_RESIDENT
:
1452 if (ctx
->API
!= API_OPENGL_COMPAT
)
1457 case GL_TEXTURE_PRIORITY
:
1458 if (ctx
->API
!= API_OPENGL_COMPAT
)
1461 *params
= obj
->Priority
;
1463 case GL_TEXTURE_MIN_LOD
:
1464 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1467 *params
= obj
->Sampler
.MinLod
;
1469 case GL_TEXTURE_MAX_LOD
:
1470 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1473 *params
= obj
->Sampler
.MaxLod
;
1475 case GL_TEXTURE_BASE_LEVEL
:
1476 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1479 *params
= (GLfloat
) obj
->BaseLevel
;
1481 case GL_TEXTURE_MAX_LEVEL
:
1482 *params
= (GLfloat
) obj
->MaxLevel
;
1484 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1485 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1487 *params
= obj
->Sampler
.MaxAnisotropy
;
1489 case GL_GENERATE_MIPMAP_SGIS
:
1490 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1493 *params
= (GLfloat
) obj
->GenerateMipmap
;
1495 case GL_TEXTURE_COMPARE_MODE_ARB
:
1496 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1497 && !_mesa_is_gles3(ctx
))
1499 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1501 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1502 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1503 && !_mesa_is_gles3(ctx
))
1505 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1507 case GL_DEPTH_TEXTURE_MODE_ARB
:
1508 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1509 * never existed in OpenGL ES.
1511 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1513 *params
= (GLfloat
) obj
->DepthMode
;
1515 case GL_TEXTURE_LOD_BIAS
:
1516 if (ctx
->API
!= API_OPENGL_COMPAT
)
1519 *params
= obj
->Sampler
.LodBias
;
1521 case GL_TEXTURE_CROP_RECT_OES
:
1522 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1525 params
[0] = (GLfloat
) obj
->CropRect
[0];
1526 params
[1] = (GLfloat
) obj
->CropRect
[1];
1527 params
[2] = (GLfloat
) obj
->CropRect
[2];
1528 params
[3] = (GLfloat
) obj
->CropRect
[3];
1531 case GL_TEXTURE_SWIZZLE_R_EXT
:
1532 case GL_TEXTURE_SWIZZLE_G_EXT
:
1533 case GL_TEXTURE_SWIZZLE_B_EXT
:
1534 case GL_TEXTURE_SWIZZLE_A_EXT
:
1535 if ((!_mesa_is_desktop_gl(ctx
)
1536 || !ctx
->Extensions
.EXT_texture_swizzle
)
1537 && !_mesa_is_gles3(ctx
))
1539 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1542 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1543 if ((!_mesa_is_desktop_gl(ctx
)
1544 || !ctx
->Extensions
.EXT_texture_swizzle
)
1545 && !_mesa_is_gles3(ctx
)) {
1550 for (comp
= 0; comp
< 4; comp
++) {
1551 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1556 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1557 if (!_mesa_is_desktop_gl(ctx
)
1558 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1560 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1563 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1564 *params
= (GLfloat
) obj
->Immutable
;
1567 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1568 if (!_mesa_is_gles3(ctx
))
1570 *params
= (GLfloat
) obj
->ImmutableLevels
;
1573 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1574 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1576 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1579 case GL_TEXTURE_SRGB_DECODE_EXT
:
1580 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1582 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1589 /* no error if we get here */
1590 _mesa_unlock_texture(ctx
, obj
);
1594 _mesa_unlock_texture(ctx
, obj
);
1595 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1600 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1602 struct gl_texture_object
*obj
;
1603 GET_CURRENT_CONTEXT(ctx
);
1605 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1609 _mesa_lock_texture(ctx
, obj
);
1611 case GL_TEXTURE_MAG_FILTER
:
1612 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1614 case GL_TEXTURE_MIN_FILTER
:
1615 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1617 case GL_TEXTURE_WRAP_S
:
1618 *params
= (GLint
) obj
->Sampler
.WrapS
;
1620 case GL_TEXTURE_WRAP_T
:
1621 *params
= (GLint
) obj
->Sampler
.WrapT
;
1623 case GL_TEXTURE_WRAP_R
:
1624 *params
= (GLint
) obj
->Sampler
.WrapR
;
1626 case GL_TEXTURE_BORDER_COLOR
:
1627 if (!_mesa_is_desktop_gl(ctx
))
1632 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1633 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1634 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1635 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1636 params
[0] = FLOAT_TO_INT(b
[0]);
1637 params
[1] = FLOAT_TO_INT(b
[1]);
1638 params
[2] = FLOAT_TO_INT(b
[2]);
1639 params
[3] = FLOAT_TO_INT(b
[3]);
1642 case GL_TEXTURE_RESIDENT
:
1643 if (ctx
->API
!= API_OPENGL_COMPAT
)
1648 case GL_TEXTURE_PRIORITY
:
1649 if (ctx
->API
!= API_OPENGL_COMPAT
)
1652 *params
= FLOAT_TO_INT(obj
->Priority
);
1654 case GL_TEXTURE_MIN_LOD
:
1655 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1658 *params
= (GLint
) obj
->Sampler
.MinLod
;
1660 case GL_TEXTURE_MAX_LOD
:
1661 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1664 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1666 case GL_TEXTURE_BASE_LEVEL
:
1667 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1670 *params
= obj
->BaseLevel
;
1672 case GL_TEXTURE_MAX_LEVEL
:
1673 *params
= obj
->MaxLevel
;
1675 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1676 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1678 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1680 case GL_GENERATE_MIPMAP_SGIS
:
1681 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1684 *params
= (GLint
) obj
->GenerateMipmap
;
1686 case GL_TEXTURE_COMPARE_MODE_ARB
:
1687 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1688 && !_mesa_is_gles3(ctx
))
1690 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1692 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1693 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1694 && !_mesa_is_gles3(ctx
))
1696 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1698 case GL_DEPTH_TEXTURE_MODE_ARB
:
1699 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1701 *params
= (GLint
) obj
->DepthMode
;
1703 case GL_TEXTURE_LOD_BIAS
:
1704 if (ctx
->API
!= API_OPENGL_COMPAT
)
1707 *params
= (GLint
) obj
->Sampler
.LodBias
;
1709 case GL_TEXTURE_CROP_RECT_OES
:
1710 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1713 params
[0] = obj
->CropRect
[0];
1714 params
[1] = obj
->CropRect
[1];
1715 params
[2] = obj
->CropRect
[2];
1716 params
[3] = obj
->CropRect
[3];
1718 case GL_TEXTURE_SWIZZLE_R_EXT
:
1719 case GL_TEXTURE_SWIZZLE_G_EXT
:
1720 case GL_TEXTURE_SWIZZLE_B_EXT
:
1721 case GL_TEXTURE_SWIZZLE_A_EXT
:
1722 if ((!_mesa_is_desktop_gl(ctx
)
1723 || !ctx
->Extensions
.EXT_texture_swizzle
)
1724 && !_mesa_is_gles3(ctx
))
1726 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1729 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1730 if ((!_mesa_is_desktop_gl(ctx
)
1731 || !ctx
->Extensions
.EXT_texture_swizzle
)
1732 && !_mesa_is_gles3(ctx
))
1734 COPY_4V(params
, obj
->Swizzle
);
1737 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1738 if (!_mesa_is_desktop_gl(ctx
)
1739 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1741 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1744 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1745 *params
= (GLint
) obj
->Immutable
;
1748 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1749 if (!_mesa_is_gles3(ctx
))
1751 *params
= obj
->ImmutableLevels
;
1754 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1755 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1757 *params
= obj
->RequiredTextureImageUnits
;
1760 case GL_TEXTURE_SRGB_DECODE_EXT
:
1761 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1763 *params
= obj
->Sampler
.sRGBDecode
;
1770 /* no error if we get here */
1771 _mesa_unlock_texture(ctx
, obj
);
1775 _mesa_unlock_texture(ctx
, obj
);
1776 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1780 /** New in GL 3.0 */
1782 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1784 struct gl_texture_object
*texObj
;
1785 GET_CURRENT_CONTEXT(ctx
);
1787 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1792 case GL_TEXTURE_BORDER_COLOR
:
1793 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1796 _mesa_GetTexParameteriv(target
, pname
, params
);
1801 /** New in GL 3.0 */
1803 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1805 struct gl_texture_object
*texObj
;
1806 GET_CURRENT_CONTEXT(ctx
);
1808 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1813 case GL_TEXTURE_BORDER_COLOR
:
1814 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1819 _mesa_GetTexParameteriv(target
, pname
, ip
);
1821 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1822 pname
== GL_TEXTURE_CROP_RECT_OES
) {