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 * BRIAN PAUL 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/colormac.h"
35 #include "main/context.h"
36 #include "main/enums.h"
37 #include "main/formats.h"
38 #include "main/glformats.h"
39 #include "main/macros.h"
40 #include "main/mfeatures.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
];
182 _mesa_error(ctx
, GL_INVALID_ENUM
,
183 "gl%sTexParameter(target)", get
? "Get" : "");
189 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
190 * \return -1 if error.
193 comp_to_swizzle(GLenum comp
)
215 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
218 ASSERT(swz
<= SWIZZLE_NIL
);
220 GLuint mask
= 0x7 << (3 * comp
);
221 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
228 * This is called just prior to changing any texture object state which
229 * will not effect texture completeness.
232 flush(struct gl_context
*ctx
)
234 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
239 * This is called just prior to changing any texture object state which
240 * can effect texture completeness (texture base level, max level).
241 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
242 * state flag and then mark the texture object as 'incomplete' so that any
243 * per-texture derived state gets recomputed.
246 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
248 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
249 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
254 * Set an integer-valued texture parameter
255 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
258 set_tex_parameteri(struct gl_context
*ctx
,
259 struct gl_texture_object
*texObj
,
260 GLenum pname
, const GLint
*params
)
263 case GL_TEXTURE_MIN_FILTER
:
264 if (texObj
->Sampler
.MinFilter
== params
[0])
270 texObj
->Sampler
.MinFilter
= params
[0];
272 case GL_NEAREST_MIPMAP_NEAREST
:
273 case GL_LINEAR_MIPMAP_NEAREST
:
274 case GL_NEAREST_MIPMAP_LINEAR
:
275 case GL_LINEAR_MIPMAP_LINEAR
:
276 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
277 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
279 texObj
->Sampler
.MinFilter
= params
[0];
288 case GL_TEXTURE_MAG_FILTER
:
289 if (texObj
->Sampler
.MagFilter
== params
[0])
294 flush(ctx
); /* does not effect completeness */
295 texObj
->Sampler
.MagFilter
= params
[0];
302 case GL_TEXTURE_WRAP_S
:
303 if (texObj
->Sampler
.WrapS
== params
[0])
305 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
307 texObj
->Sampler
.WrapS
= params
[0];
312 case GL_TEXTURE_WRAP_T
:
313 if (texObj
->Sampler
.WrapT
== params
[0])
315 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
317 texObj
->Sampler
.WrapT
= params
[0];
322 case GL_TEXTURE_WRAP_R
:
323 if (texObj
->Sampler
.WrapR
== params
[0])
325 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
327 texObj
->Sampler
.WrapR
= params
[0];
332 case GL_TEXTURE_BASE_LEVEL
:
333 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
336 if (texObj
->BaseLevel
== params
[0])
339 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
340 _mesa_error(ctx
, GL_INVALID_VALUE
,
341 "glTexParameter(param=%d)", params
[0]);
344 incomplete(ctx
, texObj
);
345 texObj
->BaseLevel
= params
[0];
348 case GL_TEXTURE_MAX_LEVEL
:
349 if (texObj
->MaxLevel
== params
[0])
351 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
352 _mesa_error(ctx
, GL_INVALID_VALUE
,
353 "glTexParameter(param=%d)", params
[0]);
356 incomplete(ctx
, texObj
);
357 texObj
->MaxLevel
= params
[0];
360 case GL_GENERATE_MIPMAP_SGIS
:
361 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
364 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
366 if (texObj
->GenerateMipmap
!= params
[0]) {
368 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
373 case GL_TEXTURE_COMPARE_MODE_ARB
:
374 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
375 || _mesa_is_gles3(ctx
)) {
376 if (texObj
->Sampler
.CompareMode
== params
[0])
378 if (params
[0] == GL_NONE
||
379 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
381 texObj
->Sampler
.CompareMode
= params
[0];
388 case GL_TEXTURE_COMPARE_FUNC_ARB
:
389 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
390 || _mesa_is_gles3(ctx
)) {
391 if (texObj
->Sampler
.CompareFunc
== params
[0])
397 texObj
->Sampler
.CompareFunc
= params
[0];
405 if (ctx
->Extensions
.EXT_shadow_funcs
) {
407 texObj
->Sampler
.CompareFunc
= params
[0];
417 case GL_DEPTH_TEXTURE_MODE_ARB
:
418 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
419 * existed in OpenGL ES.
421 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
422 if (texObj
->DepthMode
== params
[0])
424 if (params
[0] == GL_LUMINANCE
||
425 params
[0] == GL_INTENSITY
||
426 params
[0] == GL_ALPHA
||
427 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
429 texObj
->DepthMode
= params
[0];
436 case GL_TEXTURE_CROP_RECT_OES
:
437 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
440 texObj
->CropRect
[0] = params
[0];
441 texObj
->CropRect
[1] = params
[1];
442 texObj
->CropRect
[2] = params
[2];
443 texObj
->CropRect
[3] = params
[3];
446 case GL_TEXTURE_SWIZZLE_R_EXT
:
447 case GL_TEXTURE_SWIZZLE_G_EXT
:
448 case GL_TEXTURE_SWIZZLE_B_EXT
:
449 case GL_TEXTURE_SWIZZLE_A_EXT
:
450 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
451 || _mesa_is_gles3(ctx
)) {
452 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
453 const GLint swz
= comp_to_swizzle(params
[0]);
455 _mesa_error(ctx
, GL_INVALID_OPERATION
,
456 "glTexParameter(swizzle 0x%x)", params
[0]);
462 texObj
->Swizzle
[comp
] = params
[0];
463 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
468 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
469 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
470 || _mesa_is_gles3(ctx
)) {
473 for (comp
= 0; comp
< 4; comp
++) {
474 const GLint swz
= comp_to_swizzle(params
[comp
]);
476 texObj
->Swizzle
[comp
] = params
[comp
];
477 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
480 _mesa_error(ctx
, GL_INVALID_OPERATION
,
481 "glTexParameter(swizzle 0x%x)", params
[comp
]);
489 case GL_TEXTURE_SRGB_DECODE_EXT
:
490 if (_mesa_is_desktop_gl(ctx
)
491 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
492 GLenum decode
= params
[0];
493 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
494 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
496 texObj
->Sampler
.sRGBDecode
= decode
;
503 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
504 if (_mesa_is_desktop_gl(ctx
)
505 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
506 GLenum param
= params
[0];
507 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
510 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
512 texObj
->Sampler
.CubeMapSeamless
= param
;
523 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
524 _mesa_lookup_enum_by_nr(pname
));
528 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
529 _mesa_lookup_enum_by_nr(params
[0]));
535 * Set a float-valued texture parameter
536 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
539 set_tex_parameterf(struct gl_context
*ctx
,
540 struct gl_texture_object
*texObj
,
541 GLenum pname
, const GLfloat
*params
)
544 case GL_TEXTURE_MIN_LOD
:
545 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
548 if (texObj
->Sampler
.MinLod
== params
[0])
551 texObj
->Sampler
.MinLod
= params
[0];
554 case GL_TEXTURE_MAX_LOD
:
555 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
558 if (texObj
->Sampler
.MaxLod
== params
[0])
561 texObj
->Sampler
.MaxLod
= params
[0];
564 case GL_TEXTURE_PRIORITY
:
565 if (ctx
->API
!= API_OPENGL_COMPAT
)
569 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
572 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
573 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
574 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
576 if (params
[0] < 1.0) {
577 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
581 /* clamp to max, that's what NVIDIA does */
582 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
583 ctx
->Const
.MaxTextureMaxAnisotropy
);
587 static GLuint count
= 0;
593 case GL_TEXTURE_LOD_BIAS
:
594 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
595 * It was removed in core-profile, and it has never existed in OpenGL
598 if (ctx
->API
!= API_OPENGL_COMPAT
)
601 if (texObj
->Sampler
.LodBias
!= params
[0]) {
603 texObj
->Sampler
.LodBias
= params
[0];
608 case GL_TEXTURE_BORDER_COLOR
:
609 if (!_mesa_is_desktop_gl(ctx
))
613 /* ARB_texture_float disables clamping */
614 if (ctx
->Extensions
.ARB_texture_float
) {
615 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
616 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
617 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
618 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
620 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
621 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
622 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
623 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
633 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
634 _mesa_lookup_enum_by_nr(pname
));
640 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
642 GLboolean need_update
;
643 struct gl_texture_object
*texObj
;
644 GET_CURRENT_CONTEXT(ctx
);
646 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
651 case GL_TEXTURE_MIN_FILTER
:
652 case GL_TEXTURE_MAG_FILTER
:
653 case GL_TEXTURE_WRAP_S
:
654 case GL_TEXTURE_WRAP_T
:
655 case GL_TEXTURE_WRAP_R
:
656 case GL_TEXTURE_BASE_LEVEL
:
657 case GL_TEXTURE_MAX_LEVEL
:
658 case GL_GENERATE_MIPMAP_SGIS
:
659 case GL_TEXTURE_COMPARE_MODE_ARB
:
660 case GL_TEXTURE_COMPARE_FUNC_ARB
:
661 case GL_DEPTH_TEXTURE_MODE_ARB
:
662 case GL_TEXTURE_SRGB_DECODE_EXT
:
663 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
664 case GL_TEXTURE_SWIZZLE_R_EXT
:
665 case GL_TEXTURE_SWIZZLE_G_EXT
:
666 case GL_TEXTURE_SWIZZLE_B_EXT
:
667 case GL_TEXTURE_SWIZZLE_A_EXT
:
671 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
672 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
674 p
[1] = p
[2] = p
[3] = 0;
675 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
680 /* this will generate an error if pname is illegal */
683 p
[1] = p
[2] = p
[3] = 0.0F
;
684 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
688 if (ctx
->Driver
.TexParameter
&& need_update
) {
689 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
695 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
697 GLboolean need_update
;
698 struct gl_texture_object
*texObj
;
699 GET_CURRENT_CONTEXT(ctx
);
701 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
706 case GL_TEXTURE_MIN_FILTER
:
707 case GL_TEXTURE_MAG_FILTER
:
708 case GL_TEXTURE_WRAP_S
:
709 case GL_TEXTURE_WRAP_T
:
710 case GL_TEXTURE_WRAP_R
:
711 case GL_TEXTURE_BASE_LEVEL
:
712 case GL_TEXTURE_MAX_LEVEL
:
713 case GL_GENERATE_MIPMAP_SGIS
:
714 case GL_TEXTURE_COMPARE_MODE_ARB
:
715 case GL_TEXTURE_COMPARE_FUNC_ARB
:
716 case GL_DEPTH_TEXTURE_MODE_ARB
:
717 case GL_TEXTURE_SRGB_DECODE_EXT
:
718 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
720 /* convert float param to int */
722 p
[0] = (GLint
) params
[0];
723 p
[1] = p
[2] = p
[3] = 0;
724 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
727 case GL_TEXTURE_CROP_RECT_OES
:
729 /* convert float params to int */
731 iparams
[0] = (GLint
) params
[0];
732 iparams
[1] = (GLint
) params
[1];
733 iparams
[2] = (GLint
) params
[2];
734 iparams
[3] = (GLint
) params
[3];
735 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
738 case GL_TEXTURE_SWIZZLE_R_EXT
:
739 case GL_TEXTURE_SWIZZLE_G_EXT
:
740 case GL_TEXTURE_SWIZZLE_B_EXT
:
741 case GL_TEXTURE_SWIZZLE_A_EXT
:
742 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
744 GLint p
[4] = {0, 0, 0, 0};
745 p
[0] = (GLint
) params
[0];
746 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
747 p
[1] = (GLint
) params
[1];
748 p
[2] = (GLint
) params
[2];
749 p
[3] = (GLint
) params
[3];
751 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
755 /* this will generate an error if pname is illegal */
756 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
759 if (ctx
->Driver
.TexParameter
&& need_update
) {
760 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
766 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
768 GLboolean need_update
;
769 struct gl_texture_object
*texObj
;
770 GET_CURRENT_CONTEXT(ctx
);
772 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
777 case GL_TEXTURE_MIN_LOD
:
778 case GL_TEXTURE_MAX_LOD
:
779 case GL_TEXTURE_PRIORITY
:
780 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
781 case GL_TEXTURE_LOD_BIAS
:
782 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
785 fparam
[0] = (GLfloat
) param
;
786 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
787 /* convert int param to float */
788 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
792 /* this will generate an error if pname is illegal */
796 iparam
[1] = iparam
[2] = iparam
[3] = 0;
797 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
801 if (ctx
->Driver
.TexParameter
&& need_update
) {
802 GLfloat fparam
= (GLfloat
) param
;
803 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
809 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
811 GLboolean need_update
;
812 struct gl_texture_object
*texObj
;
813 GET_CURRENT_CONTEXT(ctx
);
815 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
820 case GL_TEXTURE_BORDER_COLOR
:
822 /* convert int params to float */
824 fparams
[0] = INT_TO_FLOAT(params
[0]);
825 fparams
[1] = INT_TO_FLOAT(params
[1]);
826 fparams
[2] = INT_TO_FLOAT(params
[2]);
827 fparams
[3] = INT_TO_FLOAT(params
[3]);
828 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
831 case GL_TEXTURE_MIN_LOD
:
832 case GL_TEXTURE_MAX_LOD
:
833 case GL_TEXTURE_PRIORITY
:
834 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
835 case GL_TEXTURE_LOD_BIAS
:
836 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
838 /* convert int param to float */
840 fparams
[0] = (GLfloat
) params
[0];
841 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
842 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
846 /* this will generate an error if pname is illegal */
847 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
850 if (ctx
->Driver
.TexParameter
&& need_update
) {
852 fparams
[0] = INT_TO_FLOAT(params
[0]);
853 if (pname
== GL_TEXTURE_BORDER_COLOR
||
854 pname
== GL_TEXTURE_CROP_RECT_OES
) {
855 fparams
[1] = INT_TO_FLOAT(params
[1]);
856 fparams
[2] = INT_TO_FLOAT(params
[2]);
857 fparams
[3] = INT_TO_FLOAT(params
[3]);
859 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
865 * Set tex parameter to integer value(s). Primarily intended to set
866 * integer-valued texture border color (for integer-valued textures).
870 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
872 struct gl_texture_object
*texObj
;
873 GET_CURRENT_CONTEXT(ctx
);
875 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
880 case GL_TEXTURE_BORDER_COLOR
:
881 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
882 /* set the integer-valued border color */
883 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
886 _mesa_TexParameteriv(target
, pname
, params
);
889 /* XXX no driver hook for TexParameterIiv() yet */
894 * Set tex parameter to unsigned integer value(s). Primarily intended to set
895 * uint-valued texture border color (for integer-valued textures).
899 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
901 struct gl_texture_object
*texObj
;
902 GET_CURRENT_CONTEXT(ctx
);
904 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
909 case GL_TEXTURE_BORDER_COLOR
:
910 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
911 /* set the unsigned integer-valued border color */
912 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
915 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
918 /* XXX no driver hook for TexParameterIuiv() yet */
923 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
927 case GL_PROXY_TEXTURE_1D
:
929 case GL_PROXY_TEXTURE_2D
:
931 case GL_PROXY_TEXTURE_3D
:
933 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
934 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
935 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
936 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
937 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
938 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
939 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
940 return ctx
->Extensions
.ARB_texture_cube_map
;
941 case GL_TEXTURE_RECTANGLE_NV
:
942 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
943 return ctx
->Extensions
.NV_texture_rectangle
;
944 case GL_TEXTURE_1D_ARRAY_EXT
:
945 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
946 case GL_TEXTURE_2D_ARRAY_EXT
:
947 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
948 return (ctx
->Extensions
.MESA_texture_array
||
949 ctx
->Extensions
.EXT_texture_array
);
950 case GL_TEXTURE_BUFFER
:
951 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
952 * but not in earlier versions that expose ARB_texture_buffer_object.
954 * From the ARB_texture_buffer_object spec:
955 * "(7) Do buffer textures support texture parameters (TexParameter) or
956 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
958 * RESOLVED: No. [...] Note that the spec edits above don't add
959 * explicit error language for any of these cases. That is because
960 * each of the functions enumerate the set of valid <target>
961 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
962 * these cases means that target is not legal, and an INVALID_ENUM
963 * error should be generated."
965 * From the OpenGL 3.1 spec:
966 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
968 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
969 case GL_TEXTURE_2D_MULTISAMPLE
:
970 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
971 return ctx
->Extensions
.ARB_texture_multisample
;
979 get_tex_level_parameter_image(struct gl_context
*ctx
,
980 const struct gl_texture_object
*texObj
,
981 GLenum target
, GLint level
,
982 GLenum pname
, GLint
*params
)
984 const struct gl_texture_image
*img
= NULL
;
987 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
988 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
989 /* undefined texture image */
990 if (pname
== GL_TEXTURE_COMPONENTS
)
997 texFormat
= img
->TexFormat
;
1000 case GL_TEXTURE_WIDTH
:
1001 *params
= img
->Width
;
1003 case GL_TEXTURE_HEIGHT
:
1004 *params
= img
->Height
;
1006 case GL_TEXTURE_DEPTH
:
1007 *params
= img
->Depth
;
1009 case GL_TEXTURE_INTERNAL_FORMAT
:
1010 if (_mesa_is_format_compressed(texFormat
)) {
1011 /* need to return the actual compressed format */
1012 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1015 /* If the true internal format is not compressed but the user
1016 * requested a generic compressed format, we have to return the
1017 * generic base format that matches.
1019 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1021 * "If no specific compressed format is available,
1022 * internalformat is instead replaced by the corresponding base
1025 * Otherwise just return the user's requested internal format
1028 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1030 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1033 case GL_TEXTURE_BORDER
:
1034 *params
= img
->Border
;
1036 case GL_TEXTURE_RED_SIZE
:
1037 case GL_TEXTURE_GREEN_SIZE
:
1038 case GL_TEXTURE_BLUE_SIZE
:
1039 case GL_TEXTURE_ALPHA_SIZE
:
1040 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1041 *params
= _mesa_get_format_bits(texFormat
, pname
);
1045 case GL_TEXTURE_INTENSITY_SIZE
:
1046 case GL_TEXTURE_LUMINANCE_SIZE
:
1047 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1048 *params
= _mesa_get_format_bits(texFormat
, pname
);
1050 /* intensity or luminance is probably stored as RGB[A] */
1051 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1052 GL_TEXTURE_RED_SIZE
),
1053 _mesa_get_format_bits(texFormat
,
1054 GL_TEXTURE_GREEN_SIZE
));
1061 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1062 if (!ctx
->Extensions
.ARB_depth_texture
)
1064 *params
= _mesa_get_format_bits(texFormat
, pname
);
1066 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1067 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1068 !ctx
->Extensions
.ARB_framebuffer_object
)
1070 *params
= _mesa_get_format_bits(texFormat
, pname
);
1072 case GL_TEXTURE_SHARED_SIZE
:
1073 if (ctx
->Version
< 30 &&
1074 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1076 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1079 /* GL_ARB_texture_compression */
1080 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1081 if (_mesa_is_format_compressed(texFormat
) &&
1082 !_mesa_is_proxy_texture(target
)) {
1083 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1084 img
->Height
, img
->Depth
);
1087 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1088 "glGetTexLevelParameter[if]v(pname)");
1091 case GL_TEXTURE_COMPRESSED
:
1092 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1095 /* GL_ARB_texture_float */
1096 case GL_TEXTURE_RED_TYPE_ARB
:
1097 case GL_TEXTURE_GREEN_TYPE_ARB
:
1098 case GL_TEXTURE_BLUE_TYPE_ARB
:
1099 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1100 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1101 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1102 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1103 if (!ctx
->Extensions
.ARB_texture_float
)
1105 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1106 *params
= _mesa_get_format_datatype(texFormat
);
1111 /* GL_ARB_texture_multisample */
1112 case GL_TEXTURE_SAMPLES
:
1113 if (!ctx
->Extensions
.ARB_texture_multisample
)
1115 *params
= img
->NumSamples
;
1118 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1119 if (!ctx
->Extensions
.ARB_texture_multisample
)
1121 *params
= img
->FixedSampleLocations
;
1128 /* no error if we get here */
1132 _mesa_error(ctx
, GL_INVALID_ENUM
,
1133 "glGetTexLevelParameter[if]v(pname=%s)",
1134 _mesa_lookup_enum_by_nr(pname
));
1139 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1140 const struct gl_texture_object
*texObj
,
1141 GLenum pname
, GLint
*params
)
1143 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1144 gl_format texFormat
= texObj
->_BufferObjectFormat
;
1145 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1146 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1149 /* undefined texture buffer object */
1150 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1155 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1158 case GL_TEXTURE_WIDTH
:
1161 case GL_TEXTURE_HEIGHT
:
1162 case GL_TEXTURE_DEPTH
:
1163 case GL_TEXTURE_BORDER
:
1164 case GL_TEXTURE_SHARED_SIZE
:
1165 case GL_TEXTURE_COMPRESSED
:
1168 case GL_TEXTURE_INTERNAL_FORMAT
:
1169 *params
= internalFormat
;
1171 case GL_TEXTURE_RED_SIZE
:
1172 case GL_TEXTURE_GREEN_SIZE
:
1173 case GL_TEXTURE_BLUE_SIZE
:
1174 case GL_TEXTURE_ALPHA_SIZE
:
1175 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1176 *params
= _mesa_get_format_bits(texFormat
, pname
);
1180 case GL_TEXTURE_INTENSITY_SIZE
:
1181 case GL_TEXTURE_LUMINANCE_SIZE
:
1182 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1183 *params
= _mesa_get_format_bits(texFormat
, pname
);
1185 /* intensity or luminance is probably stored as RGB[A] */
1186 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1187 GL_TEXTURE_RED_SIZE
),
1188 _mesa_get_format_bits(texFormat
,
1189 GL_TEXTURE_GREEN_SIZE
));
1195 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1196 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1197 *params
= _mesa_get_format_bits(texFormat
, pname
);
1200 /* GL_ARB_texture_buffer_range */
1201 case GL_TEXTURE_BUFFER_OFFSET
:
1202 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1204 *params
= texObj
->BufferOffset
;
1206 case GL_TEXTURE_BUFFER_SIZE
:
1207 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1209 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1212 /* GL_ARB_texture_compression */
1213 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1214 /* Always illegal for GL_TEXTURE_BUFFER */
1215 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1216 "glGetTexLevelParameter[if]v(pname)");
1219 /* GL_ARB_texture_float */
1220 case GL_TEXTURE_RED_TYPE_ARB
:
1221 case GL_TEXTURE_GREEN_TYPE_ARB
:
1222 case GL_TEXTURE_BLUE_TYPE_ARB
:
1223 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1224 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1225 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1226 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1227 if (!ctx
->Extensions
.ARB_texture_float
)
1229 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1230 *params
= _mesa_get_format_datatype(texFormat
);
1239 /* no error if we get here */
1243 _mesa_error(ctx
, GL_INVALID_ENUM
,
1244 "glGetTexLevelParameter[if]v(pname=%s)",
1245 _mesa_lookup_enum_by_nr(pname
));
1250 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1251 GLenum pname
, GLfloat
*params
)
1254 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1255 *params
= (GLfloat
) iparam
;
1260 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1261 GLenum pname
, GLint
*params
)
1263 const struct gl_texture_unit
*texUnit
;
1264 struct gl_texture_object
*texObj
;
1266 GET_CURRENT_CONTEXT(ctx
);
1268 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1270 "glGetTexLevelParameteriv(current unit)");
1274 texUnit
= _mesa_get_current_tex_unit(ctx
);
1276 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1277 _mesa_error(ctx
, GL_INVALID_ENUM
,
1278 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1282 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1283 assert(maxLevels
!= 0);
1285 if (level
< 0 || level
>= maxLevels
) {
1286 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1290 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1292 if (target
== GL_TEXTURE_BUFFER
)
1293 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1295 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1300 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1302 struct gl_texture_object
*obj
;
1303 GET_CURRENT_CONTEXT(ctx
);
1305 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1309 _mesa_lock_texture(ctx
, obj
);
1311 case GL_TEXTURE_MAG_FILTER
:
1312 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1314 case GL_TEXTURE_MIN_FILTER
:
1315 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1317 case GL_TEXTURE_WRAP_S
:
1318 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1320 case GL_TEXTURE_WRAP_T
:
1321 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1323 case GL_TEXTURE_WRAP_R
:
1324 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1326 case GL_TEXTURE_BORDER_COLOR
:
1327 if (!_mesa_is_desktop_gl(ctx
))
1330 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1331 _mesa_update_state_locked(ctx
);
1332 if (ctx
->Color
._ClampFragmentColor
) {
1333 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1334 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1335 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1336 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1339 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1340 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1341 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1342 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1345 case GL_TEXTURE_RESIDENT
:
1346 if (ctx
->API
!= API_OPENGL_COMPAT
)
1351 case GL_TEXTURE_PRIORITY
:
1352 if (ctx
->API
!= API_OPENGL_COMPAT
)
1355 *params
= obj
->Priority
;
1357 case GL_TEXTURE_MIN_LOD
:
1358 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1361 *params
= obj
->Sampler
.MinLod
;
1363 case GL_TEXTURE_MAX_LOD
:
1364 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1367 *params
= obj
->Sampler
.MaxLod
;
1369 case GL_TEXTURE_BASE_LEVEL
:
1370 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1373 *params
= (GLfloat
) obj
->BaseLevel
;
1375 case GL_TEXTURE_MAX_LEVEL
:
1376 *params
= (GLfloat
) obj
->MaxLevel
;
1378 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1379 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1381 *params
= obj
->Sampler
.MaxAnisotropy
;
1383 case GL_GENERATE_MIPMAP_SGIS
:
1384 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1387 *params
= (GLfloat
) obj
->GenerateMipmap
;
1389 case GL_TEXTURE_COMPARE_MODE_ARB
:
1390 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1391 && !_mesa_is_gles3(ctx
))
1393 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1395 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1396 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1397 && !_mesa_is_gles3(ctx
))
1399 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1401 case GL_DEPTH_TEXTURE_MODE_ARB
:
1402 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1403 * never existed in OpenGL ES.
1405 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1407 *params
= (GLfloat
) obj
->DepthMode
;
1409 case GL_TEXTURE_LOD_BIAS
:
1410 if (ctx
->API
!= API_OPENGL_COMPAT
)
1413 *params
= obj
->Sampler
.LodBias
;
1415 case GL_TEXTURE_CROP_RECT_OES
:
1416 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1419 params
[0] = (GLfloat
) obj
->CropRect
[0];
1420 params
[1] = (GLfloat
) obj
->CropRect
[1];
1421 params
[2] = (GLfloat
) obj
->CropRect
[2];
1422 params
[3] = (GLfloat
) obj
->CropRect
[3];
1425 case GL_TEXTURE_SWIZZLE_R_EXT
:
1426 case GL_TEXTURE_SWIZZLE_G_EXT
:
1427 case GL_TEXTURE_SWIZZLE_B_EXT
:
1428 case GL_TEXTURE_SWIZZLE_A_EXT
:
1429 if ((!_mesa_is_desktop_gl(ctx
)
1430 || !ctx
->Extensions
.EXT_texture_swizzle
)
1431 && !_mesa_is_gles3(ctx
))
1433 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1436 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1437 if ((!_mesa_is_desktop_gl(ctx
)
1438 || !ctx
->Extensions
.EXT_texture_swizzle
)
1439 && !_mesa_is_gles3(ctx
)) {
1444 for (comp
= 0; comp
< 4; comp
++) {
1445 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1450 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1451 if (!_mesa_is_desktop_gl(ctx
)
1452 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1454 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1457 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1458 if (!ctx
->Extensions
.ARB_texture_storage
)
1460 *params
= (GLfloat
) obj
->Immutable
;
1463 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1464 if (!_mesa_is_gles3(ctx
))
1466 *params
= (GLfloat
) obj
->ImmutableLevels
;
1469 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1470 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1472 *params
= obj
->RequiredTextureImageUnits
;
1475 case GL_TEXTURE_SRGB_DECODE_EXT
:
1476 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1478 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1485 /* no error if we get here */
1486 _mesa_unlock_texture(ctx
, obj
);
1490 _mesa_unlock_texture(ctx
, obj
);
1491 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1496 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1498 struct gl_texture_object
*obj
;
1499 GET_CURRENT_CONTEXT(ctx
);
1501 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1505 _mesa_lock_texture(ctx
, obj
);
1507 case GL_TEXTURE_MAG_FILTER
:
1508 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1510 case GL_TEXTURE_MIN_FILTER
:
1511 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1513 case GL_TEXTURE_WRAP_S
:
1514 *params
= (GLint
) obj
->Sampler
.WrapS
;
1516 case GL_TEXTURE_WRAP_T
:
1517 *params
= (GLint
) obj
->Sampler
.WrapT
;
1519 case GL_TEXTURE_WRAP_R
:
1520 *params
= (GLint
) obj
->Sampler
.WrapR
;
1522 case GL_TEXTURE_BORDER_COLOR
:
1523 if (!_mesa_is_desktop_gl(ctx
))
1528 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1529 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1530 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1531 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1532 params
[0] = FLOAT_TO_INT(b
[0]);
1533 params
[1] = FLOAT_TO_INT(b
[1]);
1534 params
[2] = FLOAT_TO_INT(b
[2]);
1535 params
[3] = FLOAT_TO_INT(b
[3]);
1538 case GL_TEXTURE_RESIDENT
:
1539 if (ctx
->API
!= API_OPENGL_COMPAT
)
1544 case GL_TEXTURE_PRIORITY
:
1545 if (ctx
->API
!= API_OPENGL_COMPAT
)
1548 *params
= FLOAT_TO_INT(obj
->Priority
);
1550 case GL_TEXTURE_MIN_LOD
:
1551 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1554 *params
= (GLint
) obj
->Sampler
.MinLod
;
1556 case GL_TEXTURE_MAX_LOD
:
1557 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1560 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1562 case GL_TEXTURE_BASE_LEVEL
:
1563 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1566 *params
= obj
->BaseLevel
;
1568 case GL_TEXTURE_MAX_LEVEL
:
1569 *params
= obj
->MaxLevel
;
1571 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1572 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1574 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1576 case GL_GENERATE_MIPMAP_SGIS
:
1577 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1580 *params
= (GLint
) obj
->GenerateMipmap
;
1582 case GL_TEXTURE_COMPARE_MODE_ARB
:
1583 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1584 && !_mesa_is_gles3(ctx
))
1586 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1588 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1589 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1590 && !_mesa_is_gles3(ctx
))
1592 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1594 case GL_DEPTH_TEXTURE_MODE_ARB
:
1595 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1597 *params
= (GLint
) obj
->DepthMode
;
1599 case GL_TEXTURE_LOD_BIAS
:
1600 if (ctx
->API
!= API_OPENGL_COMPAT
)
1603 *params
= (GLint
) obj
->Sampler
.LodBias
;
1605 case GL_TEXTURE_CROP_RECT_OES
:
1606 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1609 params
[0] = obj
->CropRect
[0];
1610 params
[1] = obj
->CropRect
[1];
1611 params
[2] = obj
->CropRect
[2];
1612 params
[3] = obj
->CropRect
[3];
1614 case GL_TEXTURE_SWIZZLE_R_EXT
:
1615 case GL_TEXTURE_SWIZZLE_G_EXT
:
1616 case GL_TEXTURE_SWIZZLE_B_EXT
:
1617 case GL_TEXTURE_SWIZZLE_A_EXT
:
1618 if ((!_mesa_is_desktop_gl(ctx
)
1619 || !ctx
->Extensions
.EXT_texture_swizzle
)
1620 && !_mesa_is_gles3(ctx
))
1622 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1625 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1626 if ((!_mesa_is_desktop_gl(ctx
)
1627 || !ctx
->Extensions
.EXT_texture_swizzle
)
1628 && !_mesa_is_gles3(ctx
))
1630 COPY_4V(params
, obj
->Swizzle
);
1633 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1634 if (!_mesa_is_desktop_gl(ctx
)
1635 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1637 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1640 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1641 if (!ctx
->Extensions
.ARB_texture_storage
)
1643 *params
= (GLint
) obj
->Immutable
;
1646 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1647 if (!_mesa_is_gles3(ctx
))
1649 *params
= obj
->ImmutableLevels
;
1652 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1653 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1655 *params
= obj
->RequiredTextureImageUnits
;
1658 case GL_TEXTURE_SRGB_DECODE_EXT
:
1659 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1661 *params
= obj
->Sampler
.sRGBDecode
;
1668 /* no error if we get here */
1669 _mesa_unlock_texture(ctx
, obj
);
1673 _mesa_unlock_texture(ctx
, obj
);
1674 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1678 /** New in GL 3.0 */
1680 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1682 struct gl_texture_object
*texObj
;
1683 GET_CURRENT_CONTEXT(ctx
);
1685 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1690 case GL_TEXTURE_BORDER_COLOR
:
1691 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1694 _mesa_GetTexParameteriv(target
, pname
, params
);
1699 /** New in GL 3.0 */
1701 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1703 struct gl_texture_object
*texObj
;
1704 GET_CURRENT_CONTEXT(ctx
);
1706 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1711 case GL_TEXTURE_BORDER_COLOR
:
1712 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1717 _mesa_GetTexParameteriv(target
, pname
, ip
);
1719 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1720 pname
== GL_TEXTURE_CROP_RECT_OES
) {