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 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
88 supported
= is_desktop_gl
89 && (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
90 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
91 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
94 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
95 supported
= is_desktop_gl
&& e
->EXT_texture_mirror_clamp
96 && (target
!= GL_TEXTURE_RECTANGLE_NV
)
97 && (target
!= GL_TEXTURE_EXTERNAL_OES
);
106 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
113 * Get current texture object for given target.
114 * Return NULL if any error (and record the error).
115 * Note that this is different from _mesa_select_tex_object() in that proxy
116 * targets are not accepted.
117 * Only the glGetTexLevelParameter() functions accept proxy targets.
119 static struct gl_texture_object
*
120 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
122 struct gl_texture_unit
*texUnit
;
124 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
125 _mesa_error(ctx
, GL_INVALID_OPERATION
,
126 "gl%sTexParameter(current unit)", get
? "Get" : "");
130 texUnit
= _mesa_get_current_tex_unit(ctx
);
134 if (_mesa_is_desktop_gl(ctx
))
135 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
138 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
140 if (ctx
->API
!= API_OPENGLES
)
141 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
143 case GL_TEXTURE_CUBE_MAP
:
144 if (ctx
->Extensions
.ARB_texture_cube_map
) {
145 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
148 case GL_TEXTURE_RECTANGLE_NV
:
149 if (_mesa_is_desktop_gl(ctx
)
150 && ctx
->Extensions
.NV_texture_rectangle
) {
151 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
154 case GL_TEXTURE_1D_ARRAY_EXT
:
155 if (_mesa_is_desktop_gl(ctx
)
156 && (ctx
->Extensions
.MESA_texture_array
||
157 ctx
->Extensions
.EXT_texture_array
)) {
158 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
161 case GL_TEXTURE_2D_ARRAY_EXT
:
162 if ((_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
163 && (ctx
->Extensions
.MESA_texture_array
||
164 ctx
->Extensions
.EXT_texture_array
)) {
165 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
168 case GL_TEXTURE_EXTERNAL_OES
:
169 if (_mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
) {
170 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
173 case GL_TEXTURE_CUBE_MAP_ARRAY
:
174 if (ctx
->Extensions
.ARB_texture_cube_map_array
) {
175 return texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
];
178 case GL_TEXTURE_2D_MULTISAMPLE
:
179 if (ctx
->Extensions
.ARB_texture_multisample
) {
180 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
];
183 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
184 if (ctx
->Extensions
.ARB_texture_multisample
) {
185 return texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
];
192 _mesa_error(ctx
, GL_INVALID_ENUM
,
193 "gl%sTexParameter(target)", get
? "Get" : "");
199 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
200 * \return -1 if error.
203 comp_to_swizzle(GLenum comp
)
225 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
228 ASSERT(swz
<= SWIZZLE_NIL
);
230 GLuint mask
= 0x7 << (3 * comp
);
231 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
238 * This is called just prior to changing any texture object state which
239 * will not effect texture completeness.
242 flush(struct gl_context
*ctx
)
244 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
249 * This is called just prior to changing any texture object state which
250 * can effect texture completeness (texture base level, max level).
251 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
252 * state flag and then mark the texture object as 'incomplete' so that any
253 * per-texture derived state gets recomputed.
256 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
258 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
259 _mesa_dirty_texobj(ctx
, texObj
);
264 target_allows_setting_sampler_parameters(GLenum target
)
267 case GL_TEXTURE_2D_MULTISAMPLE
:
268 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
278 * Set an integer-valued texture parameter
279 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
282 set_tex_parameteri(struct gl_context
*ctx
,
283 struct gl_texture_object
*texObj
,
284 GLenum pname
, const GLint
*params
)
287 case GL_TEXTURE_MIN_FILTER
:
288 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
289 goto invalid_operation
;
291 if (texObj
->Sampler
.MinFilter
== params
[0])
297 texObj
->Sampler
.MinFilter
= params
[0];
299 case GL_NEAREST_MIPMAP_NEAREST
:
300 case GL_LINEAR_MIPMAP_NEAREST
:
301 case GL_NEAREST_MIPMAP_LINEAR
:
302 case GL_LINEAR_MIPMAP_LINEAR
:
303 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
304 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
306 texObj
->Sampler
.MinFilter
= params
[0];
315 case GL_TEXTURE_MAG_FILTER
:
316 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
317 goto invalid_operation
;
319 if (texObj
->Sampler
.MagFilter
== params
[0])
324 flush(ctx
); /* does not effect completeness */
325 texObj
->Sampler
.MagFilter
= params
[0];
332 case GL_TEXTURE_WRAP_S
:
333 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
334 goto invalid_operation
;
336 if (texObj
->Sampler
.WrapS
== params
[0])
338 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
340 texObj
->Sampler
.WrapS
= params
[0];
345 case GL_TEXTURE_WRAP_T
:
346 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
347 goto invalid_operation
;
349 if (texObj
->Sampler
.WrapT
== params
[0])
351 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
353 texObj
->Sampler
.WrapT
= params
[0];
358 case GL_TEXTURE_WRAP_R
:
359 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
360 goto invalid_operation
;
362 if (texObj
->Sampler
.WrapR
== params
[0])
364 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
366 texObj
->Sampler
.WrapR
= params
[0];
371 case GL_TEXTURE_BASE_LEVEL
:
372 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
375 if (texObj
->BaseLevel
== params
[0])
378 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
379 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
380 goto invalid_operation
;
383 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
384 _mesa_error(ctx
, GL_INVALID_VALUE
,
385 "glTexParameter(param=%d)", params
[0]);
388 incomplete(ctx
, texObj
);
390 /** See note about ARB_texture_storage below */
391 if (texObj
->Immutable
)
392 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
394 texObj
->BaseLevel
= params
[0];
398 case GL_TEXTURE_MAX_LEVEL
:
399 if (texObj
->MaxLevel
== params
[0])
402 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
403 _mesa_error(ctx
, GL_INVALID_VALUE
,
404 "glTexParameter(param=%d)", params
[0]);
407 incomplete(ctx
, texObj
);
409 /** From ARB_texture_storage:
410 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
411 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
412 * the range [level_base, <levels> - 1], where <levels> is the parameter
413 * passed the call to TexStorage* for the texture object.
415 if (texObj
->Immutable
)
416 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
417 texObj
->ImmutableLevels
- 1);
419 texObj
->MaxLevel
= params
[0];
423 case GL_GENERATE_MIPMAP_SGIS
:
424 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
427 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
429 if (texObj
->GenerateMipmap
!= params
[0]) {
431 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
436 case GL_TEXTURE_COMPARE_MODE_ARB
:
437 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
438 || _mesa_is_gles3(ctx
)) {
440 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
441 goto invalid_operation
;
443 if (texObj
->Sampler
.CompareMode
== params
[0])
445 if (params
[0] == GL_NONE
||
446 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
448 texObj
->Sampler
.CompareMode
= params
[0];
455 case GL_TEXTURE_COMPARE_FUNC_ARB
:
456 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
457 || _mesa_is_gles3(ctx
)) {
459 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
460 goto invalid_operation
;
462 if (texObj
->Sampler
.CompareFunc
== params
[0])
474 texObj
->Sampler
.CompareFunc
= params
[0];
482 case GL_DEPTH_TEXTURE_MODE_ARB
:
483 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
484 * existed in OpenGL ES.
486 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
487 if (texObj
->DepthMode
== params
[0])
489 if (params
[0] == GL_LUMINANCE
||
490 params
[0] == GL_INTENSITY
||
491 params
[0] == GL_ALPHA
||
492 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
494 texObj
->DepthMode
= params
[0];
501 case GL_TEXTURE_CROP_RECT_OES
:
502 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
505 texObj
->CropRect
[0] = params
[0];
506 texObj
->CropRect
[1] = params
[1];
507 texObj
->CropRect
[2] = params
[2];
508 texObj
->CropRect
[3] = params
[3];
511 case GL_TEXTURE_SWIZZLE_R_EXT
:
512 case GL_TEXTURE_SWIZZLE_G_EXT
:
513 case GL_TEXTURE_SWIZZLE_B_EXT
:
514 case GL_TEXTURE_SWIZZLE_A_EXT
:
515 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
516 || _mesa_is_gles3(ctx
)) {
517 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
518 const GLint swz
= comp_to_swizzle(params
[0]);
520 _mesa_error(ctx
, GL_INVALID_OPERATION
,
521 "glTexParameter(swizzle 0x%x)", params
[0]);
527 texObj
->Swizzle
[comp
] = params
[0];
528 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
533 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
534 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
535 || _mesa_is_gles3(ctx
)) {
538 for (comp
= 0; comp
< 4; comp
++) {
539 const GLint swz
= comp_to_swizzle(params
[comp
]);
541 texObj
->Swizzle
[comp
] = params
[comp
];
542 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
545 _mesa_error(ctx
, GL_INVALID_OPERATION
,
546 "glTexParameter(swizzle 0x%x)", params
[comp
]);
554 case GL_TEXTURE_SRGB_DECODE_EXT
:
555 if (_mesa_is_desktop_gl(ctx
)
556 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
557 GLenum decode
= params
[0];
559 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
560 goto invalid_operation
;
562 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
563 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
565 texObj
->Sampler
.sRGBDecode
= decode
;
572 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
573 if (_mesa_is_desktop_gl(ctx
)
574 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
575 GLenum param
= params
[0];
577 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
578 goto invalid_operation
;
580 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
583 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
585 texObj
->Sampler
.CubeMapSeamless
= param
;
596 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
597 _mesa_lookup_enum_by_nr(pname
));
601 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
602 _mesa_lookup_enum_by_nr(params
[0]));
606 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
607 _mesa_lookup_enum_by_nr(pname
));
613 * Set a float-valued texture parameter
614 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
617 set_tex_parameterf(struct gl_context
*ctx
,
618 struct gl_texture_object
*texObj
,
619 GLenum pname
, const GLfloat
*params
)
622 case GL_TEXTURE_MIN_LOD
:
623 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
626 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
627 goto invalid_operation
;
629 if (texObj
->Sampler
.MinLod
== params
[0])
632 texObj
->Sampler
.MinLod
= params
[0];
635 case GL_TEXTURE_MAX_LOD
:
636 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
639 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
640 goto invalid_operation
;
642 if (texObj
->Sampler
.MaxLod
== params
[0])
645 texObj
->Sampler
.MaxLod
= params
[0];
648 case GL_TEXTURE_PRIORITY
:
649 if (ctx
->API
!= API_OPENGL_COMPAT
)
653 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
656 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
657 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
658 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
659 goto invalid_operation
;
661 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
663 if (params
[0] < 1.0) {
664 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
668 /* clamp to max, that's what NVIDIA does */
669 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
670 ctx
->Const
.MaxTextureMaxAnisotropy
);
674 static GLuint count
= 0;
680 case GL_TEXTURE_LOD_BIAS
:
681 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
682 * It was removed in core-profile, and it has never existed in OpenGL
685 if (ctx
->API
!= API_OPENGL_COMPAT
)
688 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
689 goto invalid_operation
;
691 if (texObj
->Sampler
.LodBias
!= params
[0]) {
693 texObj
->Sampler
.LodBias
= params
[0];
698 case GL_TEXTURE_BORDER_COLOR
:
699 if (!_mesa_is_desktop_gl(ctx
))
702 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
703 goto invalid_operation
;
706 /* ARB_texture_float disables clamping */
707 if (ctx
->Extensions
.ARB_texture_float
) {
708 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
709 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
710 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
711 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
713 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
714 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
715 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
716 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
726 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
727 _mesa_lookup_enum_by_nr(pname
));
731 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
732 _mesa_lookup_enum_by_nr(pname
));
738 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
740 GLboolean need_update
;
741 struct gl_texture_object
*texObj
;
742 GET_CURRENT_CONTEXT(ctx
);
744 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
749 case GL_TEXTURE_MIN_FILTER
:
750 case GL_TEXTURE_MAG_FILTER
:
751 case GL_TEXTURE_WRAP_S
:
752 case GL_TEXTURE_WRAP_T
:
753 case GL_TEXTURE_WRAP_R
:
754 case GL_TEXTURE_BASE_LEVEL
:
755 case GL_TEXTURE_MAX_LEVEL
:
756 case GL_GENERATE_MIPMAP_SGIS
:
757 case GL_TEXTURE_COMPARE_MODE_ARB
:
758 case GL_TEXTURE_COMPARE_FUNC_ARB
:
759 case GL_DEPTH_TEXTURE_MODE_ARB
:
760 case GL_TEXTURE_SRGB_DECODE_EXT
:
761 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
762 case GL_TEXTURE_SWIZZLE_R_EXT
:
763 case GL_TEXTURE_SWIZZLE_G_EXT
:
764 case GL_TEXTURE_SWIZZLE_B_EXT
:
765 case GL_TEXTURE_SWIZZLE_A_EXT
:
769 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
770 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
772 p
[1] = p
[2] = p
[3] = 0;
773 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
778 /* this will generate an error if pname is illegal */
781 p
[1] = p
[2] = p
[3] = 0.0F
;
782 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
786 if (ctx
->Driver
.TexParameter
&& need_update
) {
787 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
793 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
795 GLboolean need_update
;
796 struct gl_texture_object
*texObj
;
797 GET_CURRENT_CONTEXT(ctx
);
799 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
804 case GL_TEXTURE_MIN_FILTER
:
805 case GL_TEXTURE_MAG_FILTER
:
806 case GL_TEXTURE_WRAP_S
:
807 case GL_TEXTURE_WRAP_T
:
808 case GL_TEXTURE_WRAP_R
:
809 case GL_TEXTURE_BASE_LEVEL
:
810 case GL_TEXTURE_MAX_LEVEL
:
811 case GL_GENERATE_MIPMAP_SGIS
:
812 case GL_TEXTURE_COMPARE_MODE_ARB
:
813 case GL_TEXTURE_COMPARE_FUNC_ARB
:
814 case GL_DEPTH_TEXTURE_MODE_ARB
:
815 case GL_TEXTURE_SRGB_DECODE_EXT
:
816 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
818 /* convert float param to int */
820 p
[0] = (GLint
) params
[0];
821 p
[1] = p
[2] = p
[3] = 0;
822 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
825 case GL_TEXTURE_CROP_RECT_OES
:
827 /* convert float params to int */
829 iparams
[0] = (GLint
) params
[0];
830 iparams
[1] = (GLint
) params
[1];
831 iparams
[2] = (GLint
) params
[2];
832 iparams
[3] = (GLint
) params
[3];
833 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
836 case GL_TEXTURE_SWIZZLE_R_EXT
:
837 case GL_TEXTURE_SWIZZLE_G_EXT
:
838 case GL_TEXTURE_SWIZZLE_B_EXT
:
839 case GL_TEXTURE_SWIZZLE_A_EXT
:
840 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
842 GLint p
[4] = {0, 0, 0, 0};
843 p
[0] = (GLint
) params
[0];
844 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
845 p
[1] = (GLint
) params
[1];
846 p
[2] = (GLint
) params
[2];
847 p
[3] = (GLint
) params
[3];
849 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
853 /* this will generate an error if pname is illegal */
854 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
857 if (ctx
->Driver
.TexParameter
&& need_update
) {
858 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
864 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
866 GLboolean need_update
;
867 struct gl_texture_object
*texObj
;
868 GET_CURRENT_CONTEXT(ctx
);
870 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
875 case GL_TEXTURE_MIN_LOD
:
876 case GL_TEXTURE_MAX_LOD
:
877 case GL_TEXTURE_PRIORITY
:
878 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
879 case GL_TEXTURE_LOD_BIAS
:
880 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
883 fparam
[0] = (GLfloat
) param
;
884 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
885 /* convert int param to float */
886 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
890 /* this will generate an error if pname is illegal */
894 iparam
[1] = iparam
[2] = iparam
[3] = 0;
895 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
899 if (ctx
->Driver
.TexParameter
&& need_update
) {
900 GLfloat fparam
= (GLfloat
) param
;
901 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
907 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
909 GLboolean need_update
;
910 struct gl_texture_object
*texObj
;
911 GET_CURRENT_CONTEXT(ctx
);
913 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
918 case GL_TEXTURE_BORDER_COLOR
:
920 /* convert int params to float */
922 fparams
[0] = INT_TO_FLOAT(params
[0]);
923 fparams
[1] = INT_TO_FLOAT(params
[1]);
924 fparams
[2] = INT_TO_FLOAT(params
[2]);
925 fparams
[3] = INT_TO_FLOAT(params
[3]);
926 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
929 case GL_TEXTURE_MIN_LOD
:
930 case GL_TEXTURE_MAX_LOD
:
931 case GL_TEXTURE_PRIORITY
:
932 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
933 case GL_TEXTURE_LOD_BIAS
:
934 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
936 /* convert int param to float */
938 fparams
[0] = (GLfloat
) params
[0];
939 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
940 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
944 /* this will generate an error if pname is illegal */
945 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
948 if (ctx
->Driver
.TexParameter
&& need_update
) {
950 fparams
[0] = INT_TO_FLOAT(params
[0]);
951 if (pname
== GL_TEXTURE_BORDER_COLOR
||
952 pname
== GL_TEXTURE_CROP_RECT_OES
) {
953 fparams
[1] = INT_TO_FLOAT(params
[1]);
954 fparams
[2] = INT_TO_FLOAT(params
[2]);
955 fparams
[3] = INT_TO_FLOAT(params
[3]);
957 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
963 * Set tex parameter to integer value(s). Primarily intended to set
964 * integer-valued texture border color (for integer-valued textures).
968 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
970 struct gl_texture_object
*texObj
;
971 GET_CURRENT_CONTEXT(ctx
);
973 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
978 case GL_TEXTURE_BORDER_COLOR
:
979 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
980 /* set the integer-valued border color */
981 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
984 _mesa_TexParameteriv(target
, pname
, params
);
987 /* XXX no driver hook for TexParameterIiv() yet */
992 * Set tex parameter to unsigned integer value(s). Primarily intended to set
993 * uint-valued texture border color (for integer-valued textures).
997 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
999 struct gl_texture_object
*texObj
;
1000 GET_CURRENT_CONTEXT(ctx
);
1002 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
1007 case GL_TEXTURE_BORDER_COLOR
:
1008 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1009 /* set the unsigned integer-valued border color */
1010 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
1013 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
1016 /* XXX no driver hook for TexParameterIuiv() yet */
1021 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
1025 case GL_PROXY_TEXTURE_1D
:
1027 case GL_PROXY_TEXTURE_2D
:
1029 case GL_PROXY_TEXTURE_3D
:
1031 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1032 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1033 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1034 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1035 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1036 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1037 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1038 return ctx
->Extensions
.ARB_texture_cube_map
;
1039 case GL_TEXTURE_RECTANGLE_NV
:
1040 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1041 return ctx
->Extensions
.NV_texture_rectangle
;
1042 case GL_TEXTURE_1D_ARRAY_EXT
:
1043 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1044 case GL_TEXTURE_2D_ARRAY_EXT
:
1045 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1046 return (ctx
->Extensions
.MESA_texture_array
||
1047 ctx
->Extensions
.EXT_texture_array
);
1048 case GL_TEXTURE_BUFFER
:
1049 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1050 * but not in earlier versions that expose ARB_texture_buffer_object.
1052 * From the ARB_texture_buffer_object spec:
1053 * "(7) Do buffer textures support texture parameters (TexParameter) or
1054 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1056 * RESOLVED: No. [...] Note that the spec edits above don't add
1057 * explicit error language for any of these cases. That is because
1058 * each of the functions enumerate the set of valid <target>
1059 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1060 * these cases means that target is not legal, and an INVALID_ENUM
1061 * error should be generated."
1063 * From the OpenGL 3.1 spec:
1064 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1066 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1067 case GL_TEXTURE_2D_MULTISAMPLE
:
1068 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1069 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1070 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1071 return ctx
->Extensions
.ARB_texture_multisample
;
1079 get_tex_level_parameter_image(struct gl_context
*ctx
,
1080 const struct gl_texture_object
*texObj
,
1081 GLenum target
, GLint level
,
1082 GLenum pname
, GLint
*params
)
1084 const struct gl_texture_image
*img
= NULL
;
1085 gl_format texFormat
;
1087 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1088 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1089 /* undefined texture image */
1090 if (pname
== GL_TEXTURE_COMPONENTS
)
1097 texFormat
= img
->TexFormat
;
1100 case GL_TEXTURE_WIDTH
:
1101 *params
= img
->Width
;
1103 case GL_TEXTURE_HEIGHT
:
1104 *params
= img
->Height
;
1106 case GL_TEXTURE_DEPTH
:
1107 *params
= img
->Depth
;
1109 case GL_TEXTURE_INTERNAL_FORMAT
:
1110 if (_mesa_is_format_compressed(texFormat
)) {
1111 /* need to return the actual compressed format */
1112 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1115 /* If the true internal format is not compressed but the user
1116 * requested a generic compressed format, we have to return the
1117 * generic base format that matches.
1119 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1121 * "If no specific compressed format is available,
1122 * internalformat is instead replaced by the corresponding base
1125 * Otherwise just return the user's requested internal format
1128 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1130 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1133 case GL_TEXTURE_BORDER
:
1134 *params
= img
->Border
;
1136 case GL_TEXTURE_RED_SIZE
:
1137 case GL_TEXTURE_GREEN_SIZE
:
1138 case GL_TEXTURE_BLUE_SIZE
:
1139 case GL_TEXTURE_ALPHA_SIZE
:
1140 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1141 *params
= _mesa_get_format_bits(texFormat
, pname
);
1145 case GL_TEXTURE_INTENSITY_SIZE
:
1146 case GL_TEXTURE_LUMINANCE_SIZE
:
1147 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1148 *params
= _mesa_get_format_bits(texFormat
, pname
);
1150 /* intensity or luminance is probably stored as RGB[A] */
1151 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1152 GL_TEXTURE_RED_SIZE
),
1153 _mesa_get_format_bits(texFormat
,
1154 GL_TEXTURE_GREEN_SIZE
));
1161 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1162 if (!ctx
->Extensions
.ARB_depth_texture
)
1164 *params
= _mesa_get_format_bits(texFormat
, pname
);
1166 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1167 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1168 !ctx
->Extensions
.ARB_framebuffer_object
)
1170 *params
= _mesa_get_format_bits(texFormat
, pname
);
1172 case GL_TEXTURE_SHARED_SIZE
:
1173 if (ctx
->Version
< 30 &&
1174 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1176 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1179 /* GL_ARB_texture_compression */
1180 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1181 if (_mesa_is_format_compressed(texFormat
) &&
1182 !_mesa_is_proxy_texture(target
)) {
1183 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1184 img
->Height
, img
->Depth
);
1187 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1188 "glGetTexLevelParameter[if]v(pname)");
1191 case GL_TEXTURE_COMPRESSED
:
1192 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1195 /* GL_ARB_texture_float */
1196 case GL_TEXTURE_RED_TYPE_ARB
:
1197 case GL_TEXTURE_GREEN_TYPE_ARB
:
1198 case GL_TEXTURE_BLUE_TYPE_ARB
:
1199 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1200 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1201 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1202 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1203 if (!ctx
->Extensions
.ARB_texture_float
)
1205 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1206 *params
= _mesa_get_format_datatype(texFormat
);
1211 /* GL_ARB_texture_multisample */
1212 case GL_TEXTURE_SAMPLES
:
1213 if (!ctx
->Extensions
.ARB_texture_multisample
)
1215 *params
= img
->NumSamples
;
1218 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1219 if (!ctx
->Extensions
.ARB_texture_multisample
)
1221 *params
= img
->FixedSampleLocations
;
1228 /* no error if we get here */
1232 _mesa_error(ctx
, GL_INVALID_ENUM
,
1233 "glGetTexLevelParameter[if]v(pname=%s)",
1234 _mesa_lookup_enum_by_nr(pname
));
1239 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1240 const struct gl_texture_object
*texObj
,
1241 GLenum pname
, GLint
*params
)
1243 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1244 gl_format texFormat
= texObj
->_BufferObjectFormat
;
1245 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1246 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1249 /* undefined texture buffer object */
1250 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1255 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1258 case GL_TEXTURE_WIDTH
:
1261 case GL_TEXTURE_HEIGHT
:
1262 case GL_TEXTURE_DEPTH
:
1263 case GL_TEXTURE_BORDER
:
1264 case GL_TEXTURE_SHARED_SIZE
:
1265 case GL_TEXTURE_COMPRESSED
:
1268 case GL_TEXTURE_INTERNAL_FORMAT
:
1269 *params
= internalFormat
;
1271 case GL_TEXTURE_RED_SIZE
:
1272 case GL_TEXTURE_GREEN_SIZE
:
1273 case GL_TEXTURE_BLUE_SIZE
:
1274 case GL_TEXTURE_ALPHA_SIZE
:
1275 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1276 *params
= _mesa_get_format_bits(texFormat
, pname
);
1280 case GL_TEXTURE_INTENSITY_SIZE
:
1281 case GL_TEXTURE_LUMINANCE_SIZE
:
1282 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1283 *params
= _mesa_get_format_bits(texFormat
, pname
);
1285 /* intensity or luminance is probably stored as RGB[A] */
1286 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1287 GL_TEXTURE_RED_SIZE
),
1288 _mesa_get_format_bits(texFormat
,
1289 GL_TEXTURE_GREEN_SIZE
));
1295 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1296 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1297 *params
= _mesa_get_format_bits(texFormat
, pname
);
1300 /* GL_ARB_texture_buffer_range */
1301 case GL_TEXTURE_BUFFER_OFFSET
:
1302 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1304 *params
= texObj
->BufferOffset
;
1306 case GL_TEXTURE_BUFFER_SIZE
:
1307 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1309 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1312 /* GL_ARB_texture_compression */
1313 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1314 /* Always illegal for GL_TEXTURE_BUFFER */
1315 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1316 "glGetTexLevelParameter[if]v(pname)");
1319 /* GL_ARB_texture_float */
1320 case GL_TEXTURE_RED_TYPE_ARB
:
1321 case GL_TEXTURE_GREEN_TYPE_ARB
:
1322 case GL_TEXTURE_BLUE_TYPE_ARB
:
1323 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1324 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1325 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1326 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1327 if (!ctx
->Extensions
.ARB_texture_float
)
1329 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1330 *params
= _mesa_get_format_datatype(texFormat
);
1339 /* no error if we get here */
1343 _mesa_error(ctx
, GL_INVALID_ENUM
,
1344 "glGetTexLevelParameter[if]v(pname=%s)",
1345 _mesa_lookup_enum_by_nr(pname
));
1350 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1351 GLenum pname
, GLfloat
*params
)
1354 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1355 *params
= (GLfloat
) iparam
;
1360 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1361 GLenum pname
, GLint
*params
)
1363 const struct gl_texture_unit
*texUnit
;
1364 struct gl_texture_object
*texObj
;
1366 GET_CURRENT_CONTEXT(ctx
);
1368 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1369 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1370 "glGetTexLevelParameteriv(current unit)");
1374 texUnit
= _mesa_get_current_tex_unit(ctx
);
1376 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1377 _mesa_error(ctx
, GL_INVALID_ENUM
,
1378 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1382 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1383 assert(maxLevels
!= 0);
1385 if (level
< 0 || level
>= maxLevels
) {
1386 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1390 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1392 if (target
== GL_TEXTURE_BUFFER
)
1393 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1395 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1400 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1402 struct gl_texture_object
*obj
;
1403 GET_CURRENT_CONTEXT(ctx
);
1405 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1409 _mesa_lock_texture(ctx
, obj
);
1411 case GL_TEXTURE_MAG_FILTER
:
1412 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1414 case GL_TEXTURE_MIN_FILTER
:
1415 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1417 case GL_TEXTURE_WRAP_S
:
1418 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1420 case GL_TEXTURE_WRAP_T
:
1421 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1423 case GL_TEXTURE_WRAP_R
:
1424 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1426 case GL_TEXTURE_BORDER_COLOR
:
1427 if (!_mesa_is_desktop_gl(ctx
))
1430 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1431 _mesa_update_state_locked(ctx
);
1432 if (_mesa_get_clamp_fragment_color(ctx
)) {
1433 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1434 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1435 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1436 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1439 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1440 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1441 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1442 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1445 case GL_TEXTURE_RESIDENT
:
1446 if (ctx
->API
!= API_OPENGL_COMPAT
)
1451 case GL_TEXTURE_PRIORITY
:
1452 if (ctx
->API
!= API_OPENGL_COMPAT
)
1455 *params
= obj
->Priority
;
1457 case GL_TEXTURE_MIN_LOD
:
1458 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1461 *params
= obj
->Sampler
.MinLod
;
1463 case GL_TEXTURE_MAX_LOD
:
1464 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1467 *params
= obj
->Sampler
.MaxLod
;
1469 case GL_TEXTURE_BASE_LEVEL
:
1470 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1473 *params
= (GLfloat
) obj
->BaseLevel
;
1475 case GL_TEXTURE_MAX_LEVEL
:
1476 *params
= (GLfloat
) obj
->MaxLevel
;
1478 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1479 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1481 *params
= obj
->Sampler
.MaxAnisotropy
;
1483 case GL_GENERATE_MIPMAP_SGIS
:
1484 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1487 *params
= (GLfloat
) obj
->GenerateMipmap
;
1489 case GL_TEXTURE_COMPARE_MODE_ARB
:
1490 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1491 && !_mesa_is_gles3(ctx
))
1493 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1495 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1496 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1497 && !_mesa_is_gles3(ctx
))
1499 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1501 case GL_DEPTH_TEXTURE_MODE_ARB
:
1502 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1503 * never existed in OpenGL ES.
1505 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1507 *params
= (GLfloat
) obj
->DepthMode
;
1509 case GL_TEXTURE_LOD_BIAS
:
1510 if (ctx
->API
!= API_OPENGL_COMPAT
)
1513 *params
= obj
->Sampler
.LodBias
;
1515 case GL_TEXTURE_CROP_RECT_OES
:
1516 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1519 params
[0] = (GLfloat
) obj
->CropRect
[0];
1520 params
[1] = (GLfloat
) obj
->CropRect
[1];
1521 params
[2] = (GLfloat
) obj
->CropRect
[2];
1522 params
[3] = (GLfloat
) obj
->CropRect
[3];
1525 case GL_TEXTURE_SWIZZLE_R_EXT
:
1526 case GL_TEXTURE_SWIZZLE_G_EXT
:
1527 case GL_TEXTURE_SWIZZLE_B_EXT
:
1528 case GL_TEXTURE_SWIZZLE_A_EXT
:
1529 if ((!_mesa_is_desktop_gl(ctx
)
1530 || !ctx
->Extensions
.EXT_texture_swizzle
)
1531 && !_mesa_is_gles3(ctx
))
1533 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1536 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1537 if ((!_mesa_is_desktop_gl(ctx
)
1538 || !ctx
->Extensions
.EXT_texture_swizzle
)
1539 && !_mesa_is_gles3(ctx
)) {
1544 for (comp
= 0; comp
< 4; comp
++) {
1545 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1550 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1551 if (!_mesa_is_desktop_gl(ctx
)
1552 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1554 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1557 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1558 *params
= (GLfloat
) obj
->Immutable
;
1561 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1562 if (!_mesa_is_gles3(ctx
))
1564 *params
= (GLfloat
) obj
->ImmutableLevels
;
1567 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1568 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1570 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1573 case GL_TEXTURE_SRGB_DECODE_EXT
:
1574 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1576 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1583 /* no error if we get here */
1584 _mesa_unlock_texture(ctx
, obj
);
1588 _mesa_unlock_texture(ctx
, obj
);
1589 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1594 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1596 struct gl_texture_object
*obj
;
1597 GET_CURRENT_CONTEXT(ctx
);
1599 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1603 _mesa_lock_texture(ctx
, obj
);
1605 case GL_TEXTURE_MAG_FILTER
:
1606 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1608 case GL_TEXTURE_MIN_FILTER
:
1609 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1611 case GL_TEXTURE_WRAP_S
:
1612 *params
= (GLint
) obj
->Sampler
.WrapS
;
1614 case GL_TEXTURE_WRAP_T
:
1615 *params
= (GLint
) obj
->Sampler
.WrapT
;
1617 case GL_TEXTURE_WRAP_R
:
1618 *params
= (GLint
) obj
->Sampler
.WrapR
;
1620 case GL_TEXTURE_BORDER_COLOR
:
1621 if (!_mesa_is_desktop_gl(ctx
))
1626 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1627 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1628 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1629 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1630 params
[0] = FLOAT_TO_INT(b
[0]);
1631 params
[1] = FLOAT_TO_INT(b
[1]);
1632 params
[2] = FLOAT_TO_INT(b
[2]);
1633 params
[3] = FLOAT_TO_INT(b
[3]);
1636 case GL_TEXTURE_RESIDENT
:
1637 if (ctx
->API
!= API_OPENGL_COMPAT
)
1642 case GL_TEXTURE_PRIORITY
:
1643 if (ctx
->API
!= API_OPENGL_COMPAT
)
1646 *params
= FLOAT_TO_INT(obj
->Priority
);
1648 case GL_TEXTURE_MIN_LOD
:
1649 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1652 *params
= (GLint
) obj
->Sampler
.MinLod
;
1654 case GL_TEXTURE_MAX_LOD
:
1655 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1658 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1660 case GL_TEXTURE_BASE_LEVEL
:
1661 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1664 *params
= obj
->BaseLevel
;
1666 case GL_TEXTURE_MAX_LEVEL
:
1667 *params
= obj
->MaxLevel
;
1669 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1670 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1672 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1674 case GL_GENERATE_MIPMAP_SGIS
:
1675 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1678 *params
= (GLint
) obj
->GenerateMipmap
;
1680 case GL_TEXTURE_COMPARE_MODE_ARB
:
1681 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1682 && !_mesa_is_gles3(ctx
))
1684 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1686 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1687 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1688 && !_mesa_is_gles3(ctx
))
1690 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1692 case GL_DEPTH_TEXTURE_MODE_ARB
:
1693 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1695 *params
= (GLint
) obj
->DepthMode
;
1697 case GL_TEXTURE_LOD_BIAS
:
1698 if (ctx
->API
!= API_OPENGL_COMPAT
)
1701 *params
= (GLint
) obj
->Sampler
.LodBias
;
1703 case GL_TEXTURE_CROP_RECT_OES
:
1704 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1707 params
[0] = obj
->CropRect
[0];
1708 params
[1] = obj
->CropRect
[1];
1709 params
[2] = obj
->CropRect
[2];
1710 params
[3] = obj
->CropRect
[3];
1712 case GL_TEXTURE_SWIZZLE_R_EXT
:
1713 case GL_TEXTURE_SWIZZLE_G_EXT
:
1714 case GL_TEXTURE_SWIZZLE_B_EXT
:
1715 case GL_TEXTURE_SWIZZLE_A_EXT
:
1716 if ((!_mesa_is_desktop_gl(ctx
)
1717 || !ctx
->Extensions
.EXT_texture_swizzle
)
1718 && !_mesa_is_gles3(ctx
))
1720 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1723 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1724 if ((!_mesa_is_desktop_gl(ctx
)
1725 || !ctx
->Extensions
.EXT_texture_swizzle
)
1726 && !_mesa_is_gles3(ctx
))
1728 COPY_4V(params
, obj
->Swizzle
);
1731 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1732 if (!_mesa_is_desktop_gl(ctx
)
1733 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1735 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1738 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1739 *params
= (GLint
) obj
->Immutable
;
1742 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1743 if (!_mesa_is_gles3(ctx
))
1745 *params
= obj
->ImmutableLevels
;
1748 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1749 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1751 *params
= obj
->RequiredTextureImageUnits
;
1754 case GL_TEXTURE_SRGB_DECODE_EXT
:
1755 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1757 *params
= obj
->Sampler
.sRGBDecode
;
1764 /* no error if we get here */
1765 _mesa_unlock_texture(ctx
, obj
);
1769 _mesa_unlock_texture(ctx
, obj
);
1770 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1774 /** New in GL 3.0 */
1776 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1778 struct gl_texture_object
*texObj
;
1779 GET_CURRENT_CONTEXT(ctx
);
1781 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1786 case GL_TEXTURE_BORDER_COLOR
:
1787 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1790 _mesa_GetTexParameteriv(target
, pname
, params
);
1795 /** New in GL 3.0 */
1797 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1799 struct gl_texture_object
*texObj
;
1800 GET_CURRENT_CONTEXT(ctx
);
1802 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1807 case GL_TEXTURE_BORDER_COLOR
:
1808 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1813 _mesa_GetTexParameteriv(target
, pname
, ip
);
1815 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1816 pname
== GL_TEXTURE_CROP_RECT_OES
) {