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_get_current_tex_object() in that
122 * proxy 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
;
131 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
132 _mesa_error(ctx
, GL_INVALID_OPERATION
,
133 "gl%sTexParameter(current unit)", get
? "Get" : "");
137 texUnit
= _mesa_get_current_tex_unit(ctx
);
139 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
140 if (targetIndex
< 0 || targetIndex
== TEXTURE_BUFFER_INDEX
) {
141 _mesa_error(ctx
, GL_INVALID_ENUM
,
142 "gl%sTexParameter(target)", get
? "Get" : "");
145 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
147 return texUnit
->CurrentTex
[targetIndex
];
152 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
153 * \return -1 if error.
156 comp_to_swizzle(GLenum comp
)
178 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
181 ASSERT(swz
<= SWIZZLE_NIL
);
183 GLuint mask
= 0x7 << (3 * comp
);
184 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
191 * This is called just prior to changing any texture object state which
192 * will not effect texture completeness.
195 flush(struct gl_context
*ctx
)
197 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
202 * This is called just prior to changing any texture object state which
203 * can effect texture completeness (texture base level, max level).
204 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
205 * state flag and then mark the texture object as 'incomplete' so that any
206 * per-texture derived state gets recomputed.
209 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
211 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
212 _mesa_dirty_texobj(ctx
, texObj
);
217 target_allows_setting_sampler_parameters(GLenum target
)
220 case GL_TEXTURE_2D_MULTISAMPLE
:
221 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
231 * Set an integer-valued texture parameter
232 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
235 set_tex_parameteri(struct gl_context
*ctx
,
236 struct gl_texture_object
*texObj
,
237 GLenum pname
, const GLint
*params
)
240 case GL_TEXTURE_MIN_FILTER
:
241 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
242 goto invalid_operation
;
244 if (texObj
->Sampler
.MinFilter
== params
[0])
250 texObj
->Sampler
.MinFilter
= params
[0];
252 case GL_NEAREST_MIPMAP_NEAREST
:
253 case GL_LINEAR_MIPMAP_NEAREST
:
254 case GL_NEAREST_MIPMAP_LINEAR
:
255 case GL_LINEAR_MIPMAP_LINEAR
:
256 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
257 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
259 texObj
->Sampler
.MinFilter
= params
[0];
268 case GL_TEXTURE_MAG_FILTER
:
269 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
270 goto invalid_operation
;
272 if (texObj
->Sampler
.MagFilter
== params
[0])
277 flush(ctx
); /* does not effect completeness */
278 texObj
->Sampler
.MagFilter
= params
[0];
285 case GL_TEXTURE_WRAP_S
:
286 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
287 goto invalid_operation
;
289 if (texObj
->Sampler
.WrapS
== params
[0])
291 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
293 texObj
->Sampler
.WrapS
= params
[0];
298 case GL_TEXTURE_WRAP_T
:
299 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
300 goto invalid_operation
;
302 if (texObj
->Sampler
.WrapT
== params
[0])
304 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
306 texObj
->Sampler
.WrapT
= params
[0];
311 case GL_TEXTURE_WRAP_R
:
312 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
313 goto invalid_operation
;
315 if (texObj
->Sampler
.WrapR
== params
[0])
317 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
319 texObj
->Sampler
.WrapR
= params
[0];
324 case GL_TEXTURE_BASE_LEVEL
:
325 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
328 if (texObj
->BaseLevel
== params
[0])
331 if ((texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
332 texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) && params
[0] != 0)
333 goto invalid_operation
;
336 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
337 _mesa_error(ctx
, GL_INVALID_VALUE
,
338 "glTexParameter(param=%d)", params
[0]);
341 incomplete(ctx
, texObj
);
343 /** See note about ARB_texture_storage below */
344 if (texObj
->Immutable
)
345 texObj
->BaseLevel
= MIN2(texObj
->ImmutableLevels
- 1, params
[0]);
347 texObj
->BaseLevel
= params
[0];
351 case GL_TEXTURE_MAX_LEVEL
:
352 if (texObj
->MaxLevel
== params
[0])
356 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] > 0)) {
357 _mesa_error(ctx
, GL_INVALID_VALUE
,
358 "glTexParameter(param=%d)", params
[0]);
361 incomplete(ctx
, texObj
);
363 /** From ARB_texture_storage:
364 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
365 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
366 * the range [level_base, <levels> - 1], where <levels> is the parameter
367 * passed the call to TexStorage* for the texture object.
369 if (texObj
->Immutable
)
370 texObj
->MaxLevel
= CLAMP(params
[0], texObj
->BaseLevel
,
371 texObj
->ImmutableLevels
- 1);
373 texObj
->MaxLevel
= params
[0];
377 case GL_GENERATE_MIPMAP_SGIS
:
378 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
381 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
383 if (texObj
->GenerateMipmap
!= params
[0]) {
385 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
390 case GL_TEXTURE_COMPARE_MODE_ARB
:
391 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
392 || _mesa_is_gles3(ctx
)) {
394 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
395 goto invalid_operation
;
397 if (texObj
->Sampler
.CompareMode
== params
[0])
399 if (params
[0] == GL_NONE
||
400 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
402 texObj
->Sampler
.CompareMode
= params
[0];
409 case GL_TEXTURE_COMPARE_FUNC_ARB
:
410 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_shadow
)
411 || _mesa_is_gles3(ctx
)) {
413 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
414 goto invalid_operation
;
416 if (texObj
->Sampler
.CompareFunc
== params
[0])
428 texObj
->Sampler
.CompareFunc
= params
[0];
436 case GL_DEPTH_TEXTURE_MODE_ARB
:
437 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
438 * existed in OpenGL ES.
440 if (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_texture
) {
441 if (texObj
->DepthMode
== params
[0])
443 if (params
[0] == GL_LUMINANCE
||
444 params
[0] == GL_INTENSITY
||
445 params
[0] == GL_ALPHA
||
446 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
448 texObj
->DepthMode
= params
[0];
455 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
456 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_stencil_texturing
) {
457 bool stencil
= params
[0] == GL_STENCIL_INDEX
;
458 if (!stencil
&& params
[0] != GL_DEPTH_COMPONENT
)
461 if (texObj
->StencilSampling
== stencil
)
464 texObj
->StencilSampling
= stencil
;
469 case GL_TEXTURE_CROP_RECT_OES
:
470 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
473 texObj
->CropRect
[0] = params
[0];
474 texObj
->CropRect
[1] = params
[1];
475 texObj
->CropRect
[2] = params
[2];
476 texObj
->CropRect
[3] = params
[3];
479 case GL_TEXTURE_SWIZZLE_R_EXT
:
480 case GL_TEXTURE_SWIZZLE_G_EXT
:
481 case GL_TEXTURE_SWIZZLE_B_EXT
:
482 case GL_TEXTURE_SWIZZLE_A_EXT
:
483 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
484 || _mesa_is_gles3(ctx
)) {
485 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
486 const GLint swz
= comp_to_swizzle(params
[0]);
488 _mesa_error(ctx
, GL_INVALID_OPERATION
,
489 "glTexParameter(swizzle 0x%x)", params
[0]);
495 texObj
->Swizzle
[comp
] = params
[0];
496 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
501 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
502 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_swizzle
)
503 || _mesa_is_gles3(ctx
)) {
506 for (comp
= 0; comp
< 4; comp
++) {
507 const GLint swz
= comp_to_swizzle(params
[comp
]);
509 texObj
->Swizzle
[comp
] = params
[comp
];
510 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
513 _mesa_error(ctx
, GL_INVALID_OPERATION
,
514 "glTexParameter(swizzle 0x%x)", params
[comp
]);
522 case GL_TEXTURE_SRGB_DECODE_EXT
:
523 if (_mesa_is_desktop_gl(ctx
)
524 && ctx
->Extensions
.EXT_texture_sRGB_decode
) {
525 GLenum decode
= params
[0];
527 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
528 goto invalid_operation
;
530 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
531 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
533 texObj
->Sampler
.sRGBDecode
= decode
;
540 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
541 if (_mesa_is_desktop_gl(ctx
)
542 && ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
543 GLenum param
= params
[0];
545 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
546 goto invalid_operation
;
548 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
551 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
553 texObj
->Sampler
.CubeMapSeamless
= param
;
564 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
565 _mesa_lookup_enum_by_nr(pname
));
569 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
570 _mesa_lookup_enum_by_nr(params
[0]));
574 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
575 _mesa_lookup_enum_by_nr(pname
));
581 * Set a float-valued texture parameter
582 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
585 set_tex_parameterf(struct gl_context
*ctx
,
586 struct gl_texture_object
*texObj
,
587 GLenum pname
, const GLfloat
*params
)
590 case GL_TEXTURE_MIN_LOD
:
591 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
594 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
595 goto invalid_operation
;
597 if (texObj
->Sampler
.MinLod
== params
[0])
600 texObj
->Sampler
.MinLod
= params
[0];
603 case GL_TEXTURE_MAX_LOD
:
604 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
607 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
608 goto invalid_operation
;
610 if (texObj
->Sampler
.MaxLod
== params
[0])
613 texObj
->Sampler
.MaxLod
= params
[0];
616 case GL_TEXTURE_PRIORITY
:
617 if (ctx
->API
!= API_OPENGL_COMPAT
)
621 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
624 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
625 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
626 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
627 goto invalid_operation
;
629 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
631 if (params
[0] < 1.0) {
632 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
636 /* clamp to max, that's what NVIDIA does */
637 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
638 ctx
->Const
.MaxTextureMaxAnisotropy
);
642 static GLuint count
= 0;
648 case GL_TEXTURE_LOD_BIAS
:
649 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
650 if (_mesa_is_gles(ctx
))
653 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
654 goto invalid_operation
;
656 if (texObj
->Sampler
.LodBias
!= params
[0]) {
658 texObj
->Sampler
.LodBias
= params
[0];
663 case GL_TEXTURE_BORDER_COLOR
:
664 if (!_mesa_is_desktop_gl(ctx
))
667 if (!target_allows_setting_sampler_parameters(texObj
->Target
))
668 goto invalid_operation
;
671 /* ARB_texture_float disables clamping */
672 if (ctx
->Extensions
.ARB_texture_float
) {
673 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
674 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
675 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
676 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
678 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
679 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
680 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
681 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
691 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
692 _mesa_lookup_enum_by_nr(pname
));
696 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(pname=%s)",
697 _mesa_lookup_enum_by_nr(pname
));
703 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
705 GLboolean need_update
;
706 struct gl_texture_object
*texObj
;
707 GET_CURRENT_CONTEXT(ctx
);
709 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
714 case GL_TEXTURE_MIN_FILTER
:
715 case GL_TEXTURE_MAG_FILTER
:
716 case GL_TEXTURE_WRAP_S
:
717 case GL_TEXTURE_WRAP_T
:
718 case GL_TEXTURE_WRAP_R
:
719 case GL_TEXTURE_BASE_LEVEL
:
720 case GL_TEXTURE_MAX_LEVEL
:
721 case GL_GENERATE_MIPMAP_SGIS
:
722 case GL_TEXTURE_COMPARE_MODE_ARB
:
723 case GL_TEXTURE_COMPARE_FUNC_ARB
:
724 case GL_DEPTH_TEXTURE_MODE_ARB
:
725 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
726 case GL_TEXTURE_SRGB_DECODE_EXT
:
727 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
728 case GL_TEXTURE_SWIZZLE_R_EXT
:
729 case GL_TEXTURE_SWIZZLE_G_EXT
:
730 case GL_TEXTURE_SWIZZLE_B_EXT
:
731 case GL_TEXTURE_SWIZZLE_A_EXT
:
735 ((param
> INT_MAX
) ? INT_MAX
: (GLint
) (param
+ 0.5)) :
736 ((param
< INT_MIN
) ? INT_MIN
: (GLint
) (param
- 0.5));
738 p
[1] = p
[2] = p
[3] = 0;
739 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
744 /* this will generate an error if pname is illegal */
747 p
[1] = p
[2] = p
[3] = 0.0F
;
748 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
752 if (ctx
->Driver
.TexParameter
&& need_update
) {
753 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, ¶m
);
759 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
761 GLboolean need_update
;
762 struct gl_texture_object
*texObj
;
763 GET_CURRENT_CONTEXT(ctx
);
765 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
770 case GL_TEXTURE_MIN_FILTER
:
771 case GL_TEXTURE_MAG_FILTER
:
772 case GL_TEXTURE_WRAP_S
:
773 case GL_TEXTURE_WRAP_T
:
774 case GL_TEXTURE_WRAP_R
:
775 case GL_TEXTURE_BASE_LEVEL
:
776 case GL_TEXTURE_MAX_LEVEL
:
777 case GL_GENERATE_MIPMAP_SGIS
:
778 case GL_TEXTURE_COMPARE_MODE_ARB
:
779 case GL_TEXTURE_COMPARE_FUNC_ARB
:
780 case GL_DEPTH_TEXTURE_MODE_ARB
:
781 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
782 case GL_TEXTURE_SRGB_DECODE_EXT
:
783 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
785 /* convert float param to int */
787 p
[0] = (GLint
) params
[0];
788 p
[1] = p
[2] = p
[3] = 0;
789 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
792 case GL_TEXTURE_CROP_RECT_OES
:
794 /* convert float params to int */
796 iparams
[0] = (GLint
) params
[0];
797 iparams
[1] = (GLint
) params
[1];
798 iparams
[2] = (GLint
) params
[2];
799 iparams
[3] = (GLint
) params
[3];
800 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
803 case GL_TEXTURE_SWIZZLE_R_EXT
:
804 case GL_TEXTURE_SWIZZLE_G_EXT
:
805 case GL_TEXTURE_SWIZZLE_B_EXT
:
806 case GL_TEXTURE_SWIZZLE_A_EXT
:
807 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
809 GLint p
[4] = {0, 0, 0, 0};
810 p
[0] = (GLint
) params
[0];
811 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
812 p
[1] = (GLint
) params
[1];
813 p
[2] = (GLint
) params
[2];
814 p
[3] = (GLint
) params
[3];
816 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
820 /* this will generate an error if pname is illegal */
821 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
824 if (ctx
->Driver
.TexParameter
&& need_update
) {
825 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, params
);
831 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
833 GLboolean need_update
;
834 struct gl_texture_object
*texObj
;
835 GET_CURRENT_CONTEXT(ctx
);
837 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
842 case GL_TEXTURE_MIN_LOD
:
843 case GL_TEXTURE_MAX_LOD
:
844 case GL_TEXTURE_PRIORITY
:
845 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
846 case GL_TEXTURE_LOD_BIAS
:
847 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
850 fparam
[0] = (GLfloat
) param
;
851 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
852 /* convert int param to float */
853 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
857 /* this will generate an error if pname is illegal */
861 iparam
[1] = iparam
[2] = iparam
[3] = 0;
862 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
866 if (ctx
->Driver
.TexParameter
&& need_update
) {
867 GLfloat fparam
= (GLfloat
) param
;
868 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, &fparam
);
874 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
876 GLboolean need_update
;
877 struct gl_texture_object
*texObj
;
878 GET_CURRENT_CONTEXT(ctx
);
880 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
885 case GL_TEXTURE_BORDER_COLOR
:
887 /* convert int params to float */
889 fparams
[0] = INT_TO_FLOAT(params
[0]);
890 fparams
[1] = INT_TO_FLOAT(params
[1]);
891 fparams
[2] = INT_TO_FLOAT(params
[2]);
892 fparams
[3] = INT_TO_FLOAT(params
[3]);
893 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
896 case GL_TEXTURE_MIN_LOD
:
897 case GL_TEXTURE_MAX_LOD
:
898 case GL_TEXTURE_PRIORITY
:
899 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
900 case GL_TEXTURE_LOD_BIAS
:
901 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
903 /* convert int param to float */
905 fparams
[0] = (GLfloat
) params
[0];
906 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
907 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
911 /* this will generate an error if pname is illegal */
912 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
915 if (ctx
->Driver
.TexParameter
&& need_update
) {
917 fparams
[0] = INT_TO_FLOAT(params
[0]);
918 if (pname
== GL_TEXTURE_BORDER_COLOR
||
919 pname
== GL_TEXTURE_CROP_RECT_OES
) {
920 fparams
[1] = INT_TO_FLOAT(params
[1]);
921 fparams
[2] = INT_TO_FLOAT(params
[2]);
922 fparams
[3] = INT_TO_FLOAT(params
[3]);
924 ctx
->Driver
.TexParameter(ctx
, texObj
, pname
, fparams
);
930 * Set tex parameter to integer value(s). Primarily intended to set
931 * integer-valued texture border color (for integer-valued textures).
935 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
937 struct gl_texture_object
*texObj
;
938 GET_CURRENT_CONTEXT(ctx
);
940 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
945 case GL_TEXTURE_BORDER_COLOR
:
946 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
947 /* set the integer-valued border color */
948 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
951 _mesa_TexParameteriv(target
, pname
, params
);
954 /* XXX no driver hook for TexParameterIiv() yet */
959 * Set tex parameter to unsigned integer value(s). Primarily intended to set
960 * uint-valued texture border color (for integer-valued textures).
964 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
966 struct gl_texture_object
*texObj
;
967 GET_CURRENT_CONTEXT(ctx
);
969 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
974 case GL_TEXTURE_BORDER_COLOR
:
975 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
976 /* set the unsigned integer-valued border color */
977 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
980 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
983 /* XXX no driver hook for TexParameterIuiv() yet */
988 legal_get_tex_level_parameter_target(struct gl_context
*ctx
, GLenum target
)
992 case GL_PROXY_TEXTURE_1D
:
994 case GL_PROXY_TEXTURE_2D
:
996 case GL_PROXY_TEXTURE_3D
:
998 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1000 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1001 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1002 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1003 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1004 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1005 return ctx
->Extensions
.ARB_texture_cube_map
;
1006 case GL_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1007 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB
:
1008 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1009 case GL_TEXTURE_RECTANGLE_NV
:
1010 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1011 return ctx
->Extensions
.NV_texture_rectangle
;
1012 case GL_TEXTURE_1D_ARRAY_EXT
:
1013 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1014 case GL_TEXTURE_2D_ARRAY_EXT
:
1015 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1016 return ctx
->Extensions
.EXT_texture_array
;
1017 case GL_TEXTURE_BUFFER
:
1018 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1019 * but not in earlier versions that expose ARB_texture_buffer_object.
1021 * From the ARB_texture_buffer_object spec:
1022 * "(7) Do buffer textures support texture parameters (TexParameter) or
1023 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1025 * RESOLVED: No. [...] Note that the spec edits above don't add
1026 * explicit error language for any of these cases. That is because
1027 * each of the functions enumerate the set of valid <target>
1028 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1029 * these cases means that target is not legal, and an INVALID_ENUM
1030 * error should be generated."
1032 * From the OpenGL 3.1 spec:
1033 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1035 return ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 31;
1036 case GL_TEXTURE_2D_MULTISAMPLE
:
1037 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1038 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1039 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1040 return ctx
->Extensions
.ARB_texture_multisample
;
1048 get_tex_level_parameter_image(struct gl_context
*ctx
,
1049 const struct gl_texture_object
*texObj
,
1050 GLenum target
, GLint level
,
1051 GLenum pname
, GLint
*params
)
1053 const struct gl_texture_image
*img
= NULL
;
1054 mesa_format texFormat
;
1056 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1057 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
1058 /* In case of undefined texture image return the default values.
1060 * From OpenGL 4.0 spec, page 398:
1061 * "The initial internal format of a texel array is RGBA
1062 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1063 * use TEXTURE_INTERNAL_FORMAT."
1066 if (pname
== GL_TEXTURE_INTERNAL_FORMAT
)
1073 texFormat
= img
->TexFormat
;
1076 case GL_TEXTURE_WIDTH
:
1077 *params
= img
->Width
;
1079 case GL_TEXTURE_HEIGHT
:
1080 *params
= img
->Height
;
1082 case GL_TEXTURE_DEPTH
:
1083 *params
= img
->Depth
;
1085 case GL_TEXTURE_INTERNAL_FORMAT
:
1086 if (_mesa_is_format_compressed(texFormat
)) {
1087 /* need to return the actual compressed format */
1088 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
1091 /* If the true internal format is not compressed but the user
1092 * requested a generic compressed format, we have to return the
1093 * generic base format that matches.
1095 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1097 * "If no specific compressed format is available,
1098 * internalformat is instead replaced by the corresponding base
1101 * Otherwise just return the user's requested internal format
1104 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
1106 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
1109 case GL_TEXTURE_BORDER
:
1110 *params
= img
->Border
;
1112 case GL_TEXTURE_RED_SIZE
:
1113 case GL_TEXTURE_GREEN_SIZE
:
1114 case GL_TEXTURE_BLUE_SIZE
:
1115 case GL_TEXTURE_ALPHA_SIZE
:
1116 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1117 *params
= _mesa_get_format_bits(texFormat
, pname
);
1121 case GL_TEXTURE_INTENSITY_SIZE
:
1122 case GL_TEXTURE_LUMINANCE_SIZE
:
1123 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
1124 *params
= _mesa_get_format_bits(texFormat
, pname
);
1126 /* intensity or luminance is probably stored as RGB[A] */
1127 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1128 GL_TEXTURE_RED_SIZE
),
1129 _mesa_get_format_bits(texFormat
,
1130 GL_TEXTURE_GREEN_SIZE
));
1137 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1138 if (!ctx
->Extensions
.ARB_depth_texture
)
1140 *params
= _mesa_get_format_bits(texFormat
, pname
);
1142 case GL_TEXTURE_STENCIL_SIZE
:
1143 *params
= _mesa_get_format_bits(texFormat
, pname
);
1145 case GL_TEXTURE_SHARED_SIZE
:
1146 if (ctx
->Version
< 30 &&
1147 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1149 *params
= texFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
? 5 : 0;
1152 /* GL_ARB_texture_compression */
1153 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1154 if (_mesa_is_format_compressed(texFormat
) &&
1155 !_mesa_is_proxy_texture(target
)) {
1156 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1157 img
->Height
, img
->Depth
);
1160 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1161 "glGetTexLevelParameter[if]v(pname)");
1164 case GL_TEXTURE_COMPRESSED
:
1165 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1168 /* GL_ARB_texture_float */
1169 case GL_TEXTURE_RED_TYPE_ARB
:
1170 case GL_TEXTURE_GREEN_TYPE_ARB
:
1171 case GL_TEXTURE_BLUE_TYPE_ARB
:
1172 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1173 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1174 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1175 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1176 if (!ctx
->Extensions
.ARB_texture_float
)
1178 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1179 *params
= _mesa_get_format_datatype(texFormat
);
1184 /* GL_ARB_texture_multisample */
1185 case GL_TEXTURE_SAMPLES
:
1186 if (!ctx
->Extensions
.ARB_texture_multisample
)
1188 *params
= img
->NumSamples
;
1191 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS
:
1192 if (!ctx
->Extensions
.ARB_texture_multisample
)
1194 *params
= img
->FixedSampleLocations
;
1201 /* no error if we get here */
1205 _mesa_error(ctx
, GL_INVALID_ENUM
,
1206 "glGetTexLevelParameter[if]v(pname=%s)",
1207 _mesa_lookup_enum_by_nr(pname
));
1212 get_tex_level_parameter_buffer(struct gl_context
*ctx
,
1213 const struct gl_texture_object
*texObj
,
1214 GLenum pname
, GLint
*params
)
1216 const struct gl_buffer_object
*bo
= texObj
->BufferObject
;
1217 mesa_format texFormat
= texObj
->_BufferObjectFormat
;
1218 GLenum internalFormat
= texObj
->BufferObjectFormat
;
1219 GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
1222 /* undefined texture buffer object */
1223 *params
= pname
== GL_TEXTURE_COMPONENTS
? 1 : 0;
1228 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING
:
1231 case GL_TEXTURE_WIDTH
:
1234 case GL_TEXTURE_HEIGHT
:
1235 case GL_TEXTURE_DEPTH
:
1236 case GL_TEXTURE_BORDER
:
1237 case GL_TEXTURE_SHARED_SIZE
:
1238 case GL_TEXTURE_COMPRESSED
:
1241 case GL_TEXTURE_INTERNAL_FORMAT
:
1242 *params
= internalFormat
;
1244 case GL_TEXTURE_RED_SIZE
:
1245 case GL_TEXTURE_GREEN_SIZE
:
1246 case GL_TEXTURE_BLUE_SIZE
:
1247 case GL_TEXTURE_ALPHA_SIZE
:
1248 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1249 *params
= _mesa_get_format_bits(texFormat
, pname
);
1253 case GL_TEXTURE_INTENSITY_SIZE
:
1254 case GL_TEXTURE_LUMINANCE_SIZE
:
1255 if (_mesa_base_format_has_channel(baseFormat
, pname
)) {
1256 *params
= _mesa_get_format_bits(texFormat
, pname
);
1258 /* intensity or luminance is probably stored as RGB[A] */
1259 *params
= MIN2(_mesa_get_format_bits(texFormat
,
1260 GL_TEXTURE_RED_SIZE
),
1261 _mesa_get_format_bits(texFormat
,
1262 GL_TEXTURE_GREEN_SIZE
));
1268 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1269 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1270 *params
= _mesa_get_format_bits(texFormat
, pname
);
1273 /* GL_ARB_texture_buffer_range */
1274 case GL_TEXTURE_BUFFER_OFFSET
:
1275 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1277 *params
= texObj
->BufferOffset
;
1279 case GL_TEXTURE_BUFFER_SIZE
:
1280 if (!ctx
->Extensions
.ARB_texture_buffer_range
)
1282 *params
= (texObj
->BufferSize
== -1) ? bo
->Size
: texObj
->BufferSize
;
1285 /* GL_ARB_texture_compression */
1286 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1287 /* Always illegal for GL_TEXTURE_BUFFER */
1288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1289 "glGetTexLevelParameter[if]v(pname)");
1292 /* GL_ARB_texture_float */
1293 case GL_TEXTURE_RED_TYPE_ARB
:
1294 case GL_TEXTURE_GREEN_TYPE_ARB
:
1295 case GL_TEXTURE_BLUE_TYPE_ARB
:
1296 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1297 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1298 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1299 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1300 if (!ctx
->Extensions
.ARB_texture_float
)
1302 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1303 *params
= _mesa_get_format_datatype(texFormat
);
1312 /* no error if we get here */
1316 _mesa_error(ctx
, GL_INVALID_ENUM
,
1317 "glGetTexLevelParameter[if]v(pname=%s)",
1318 _mesa_lookup_enum_by_nr(pname
));
1323 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1324 GLenum pname
, GLfloat
*params
)
1327 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1328 *params
= (GLfloat
) iparam
;
1333 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1334 GLenum pname
, GLint
*params
)
1336 struct gl_texture_object
*texObj
;
1338 GET_CURRENT_CONTEXT(ctx
);
1340 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1342 "glGetTexLevelParameteriv(current unit)");
1346 if (!legal_get_tex_level_parameter_target(ctx
, target
)) {
1347 _mesa_error(ctx
, GL_INVALID_ENUM
,
1348 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
1352 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1353 assert(maxLevels
!= 0);
1355 if (level
< 0 || level
>= maxLevels
) {
1356 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1360 texObj
= _mesa_get_current_tex_object(ctx
, target
);
1362 if (target
== GL_TEXTURE_BUFFER
)
1363 get_tex_level_parameter_buffer(ctx
, texObj
, pname
, params
);
1365 get_tex_level_parameter_image(ctx
, texObj
, target
, level
, pname
, params
);
1370 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1372 struct gl_texture_object
*obj
;
1373 GET_CURRENT_CONTEXT(ctx
);
1375 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1379 _mesa_lock_texture(ctx
, obj
);
1381 case GL_TEXTURE_MAG_FILTER
:
1382 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1384 case GL_TEXTURE_MIN_FILTER
:
1385 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1387 case GL_TEXTURE_WRAP_S
:
1388 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1390 case GL_TEXTURE_WRAP_T
:
1391 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1393 case GL_TEXTURE_WRAP_R
:
1394 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1396 case GL_TEXTURE_BORDER_COLOR
:
1397 if (!_mesa_is_desktop_gl(ctx
))
1400 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1401 _mesa_update_state_locked(ctx
);
1402 if (_mesa_get_clamp_fragment_color(ctx
)) {
1403 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1404 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1405 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1406 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1409 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1410 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1411 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1412 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1415 case GL_TEXTURE_RESIDENT
:
1416 if (ctx
->API
!= API_OPENGL_COMPAT
)
1421 case GL_TEXTURE_PRIORITY
:
1422 if (ctx
->API
!= API_OPENGL_COMPAT
)
1425 *params
= obj
->Priority
;
1427 case GL_TEXTURE_MIN_LOD
:
1428 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1431 *params
= obj
->Sampler
.MinLod
;
1433 case GL_TEXTURE_MAX_LOD
:
1434 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1437 *params
= obj
->Sampler
.MaxLod
;
1439 case GL_TEXTURE_BASE_LEVEL
:
1440 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1443 *params
= (GLfloat
) obj
->BaseLevel
;
1445 case GL_TEXTURE_MAX_LEVEL
:
1446 *params
= (GLfloat
) obj
->MaxLevel
;
1448 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1449 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1451 *params
= obj
->Sampler
.MaxAnisotropy
;
1453 case GL_GENERATE_MIPMAP_SGIS
:
1454 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1457 *params
= (GLfloat
) obj
->GenerateMipmap
;
1459 case GL_TEXTURE_COMPARE_MODE_ARB
:
1460 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1461 && !_mesa_is_gles3(ctx
))
1463 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1465 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1466 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1467 && !_mesa_is_gles3(ctx
))
1469 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1471 case GL_DEPTH_TEXTURE_MODE_ARB
:
1472 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1473 * never existed in OpenGL ES.
1475 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1477 *params
= (GLfloat
) obj
->DepthMode
;
1479 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1480 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
1483 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1485 case GL_TEXTURE_LOD_BIAS
:
1486 if (_mesa_is_gles(ctx
))
1489 *params
= obj
->Sampler
.LodBias
;
1491 case GL_TEXTURE_CROP_RECT_OES
:
1492 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1495 params
[0] = (GLfloat
) obj
->CropRect
[0];
1496 params
[1] = (GLfloat
) obj
->CropRect
[1];
1497 params
[2] = (GLfloat
) obj
->CropRect
[2];
1498 params
[3] = (GLfloat
) obj
->CropRect
[3];
1501 case GL_TEXTURE_SWIZZLE_R_EXT
:
1502 case GL_TEXTURE_SWIZZLE_G_EXT
:
1503 case GL_TEXTURE_SWIZZLE_B_EXT
:
1504 case GL_TEXTURE_SWIZZLE_A_EXT
:
1505 if ((!_mesa_is_desktop_gl(ctx
)
1506 || !ctx
->Extensions
.EXT_texture_swizzle
)
1507 && !_mesa_is_gles3(ctx
))
1509 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1512 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1513 if ((!_mesa_is_desktop_gl(ctx
)
1514 || !ctx
->Extensions
.EXT_texture_swizzle
)
1515 && !_mesa_is_gles3(ctx
)) {
1520 for (comp
= 0; comp
< 4; comp
++) {
1521 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1526 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1527 if (!_mesa_is_desktop_gl(ctx
)
1528 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1530 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1533 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1534 *params
= (GLfloat
) obj
->Immutable
;
1537 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1538 if (_mesa_is_gles3(ctx
) ||
1539 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1540 *params
= (GLfloat
) obj
->ImmutableLevels
;
1545 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1546 if (!ctx
->Extensions
.ARB_texture_view
)
1548 *params
= (GLfloat
) obj
->MinLevel
;
1551 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1552 if (!ctx
->Extensions
.ARB_texture_view
)
1554 *params
= (GLfloat
) obj
->NumLevels
;
1557 case GL_TEXTURE_VIEW_MIN_LAYER
:
1558 if (!ctx
->Extensions
.ARB_texture_view
)
1560 *params
= (GLfloat
) obj
->MinLayer
;
1563 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1564 if (!ctx
->Extensions
.ARB_texture_view
)
1566 *params
= (GLfloat
) obj
->NumLayers
;
1569 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1570 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1572 *params
= (GLfloat
) obj
->RequiredTextureImageUnits
;
1575 case GL_TEXTURE_SRGB_DECODE_EXT
:
1576 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1578 *params
= (GLfloat
) obj
->Sampler
.sRGBDecode
;
1585 /* no error if we get here */
1586 _mesa_unlock_texture(ctx
, obj
);
1590 _mesa_unlock_texture(ctx
, obj
);
1591 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1596 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1598 struct gl_texture_object
*obj
;
1599 GET_CURRENT_CONTEXT(ctx
);
1601 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1605 _mesa_lock_texture(ctx
, obj
);
1607 case GL_TEXTURE_MAG_FILTER
:
1608 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1610 case GL_TEXTURE_MIN_FILTER
:
1611 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1613 case GL_TEXTURE_WRAP_S
:
1614 *params
= (GLint
) obj
->Sampler
.WrapS
;
1616 case GL_TEXTURE_WRAP_T
:
1617 *params
= (GLint
) obj
->Sampler
.WrapT
;
1619 case GL_TEXTURE_WRAP_R
:
1620 *params
= (GLint
) obj
->Sampler
.WrapR
;
1622 case GL_TEXTURE_BORDER_COLOR
:
1623 if (!_mesa_is_desktop_gl(ctx
))
1628 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1629 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1630 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1631 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1632 params
[0] = FLOAT_TO_INT(b
[0]);
1633 params
[1] = FLOAT_TO_INT(b
[1]);
1634 params
[2] = FLOAT_TO_INT(b
[2]);
1635 params
[3] = FLOAT_TO_INT(b
[3]);
1638 case GL_TEXTURE_RESIDENT
:
1639 if (ctx
->API
!= API_OPENGL_COMPAT
)
1644 case GL_TEXTURE_PRIORITY
:
1645 if (ctx
->API
!= API_OPENGL_COMPAT
)
1648 *params
= FLOAT_TO_INT(obj
->Priority
);
1650 case GL_TEXTURE_MIN_LOD
:
1651 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1654 *params
= (GLint
) obj
->Sampler
.MinLod
;
1656 case GL_TEXTURE_MAX_LOD
:
1657 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1660 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1662 case GL_TEXTURE_BASE_LEVEL
:
1663 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1666 *params
= obj
->BaseLevel
;
1668 case GL_TEXTURE_MAX_LEVEL
:
1669 *params
= obj
->MaxLevel
;
1671 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1672 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1674 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1676 case GL_GENERATE_MIPMAP_SGIS
:
1677 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1680 *params
= (GLint
) obj
->GenerateMipmap
;
1682 case GL_TEXTURE_COMPARE_MODE_ARB
:
1683 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1684 && !_mesa_is_gles3(ctx
))
1686 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1688 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1689 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_shadow
)
1690 && !_mesa_is_gles3(ctx
))
1692 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1694 case GL_DEPTH_TEXTURE_MODE_ARB
:
1695 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_depth_texture
)
1697 *params
= (GLint
) obj
->DepthMode
;
1699 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
1700 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_stencil_texturing
)
1703 (obj
->StencilSampling
? GL_STENCIL_INDEX
: GL_DEPTH_COMPONENT
);
1705 case GL_TEXTURE_LOD_BIAS
:
1706 if (_mesa_is_gles(ctx
))
1709 /* GL spec 'Data Conversions' section specifies that floating-point
1710 * value in integer Get function is rounded to nearest integer
1712 *params
= IROUND(obj
->Sampler
.LodBias
);
1714 case GL_TEXTURE_CROP_RECT_OES
:
1715 if (ctx
->API
!= API_OPENGLES
|| !ctx
->Extensions
.OES_draw_texture
)
1718 params
[0] = obj
->CropRect
[0];
1719 params
[1] = obj
->CropRect
[1];
1720 params
[2] = obj
->CropRect
[2];
1721 params
[3] = obj
->CropRect
[3];
1723 case GL_TEXTURE_SWIZZLE_R_EXT
:
1724 case GL_TEXTURE_SWIZZLE_G_EXT
:
1725 case GL_TEXTURE_SWIZZLE_B_EXT
:
1726 case GL_TEXTURE_SWIZZLE_A_EXT
:
1727 if ((!_mesa_is_desktop_gl(ctx
)
1728 || !ctx
->Extensions
.EXT_texture_swizzle
)
1729 && !_mesa_is_gles3(ctx
))
1731 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1734 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1735 if ((!_mesa_is_desktop_gl(ctx
)
1736 || !ctx
->Extensions
.EXT_texture_swizzle
)
1737 && !_mesa_is_gles3(ctx
))
1739 COPY_4V(params
, obj
->Swizzle
);
1742 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1743 if (!_mesa_is_desktop_gl(ctx
)
1744 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1746 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1749 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1750 *params
= (GLint
) obj
->Immutable
;
1753 case GL_TEXTURE_IMMUTABLE_LEVELS
:
1754 if (_mesa_is_gles3(ctx
) ||
1755 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_view
))
1756 *params
= obj
->ImmutableLevels
;
1761 case GL_TEXTURE_VIEW_MIN_LEVEL
:
1762 if (!ctx
->Extensions
.ARB_texture_view
)
1764 *params
= (GLint
) obj
->MinLevel
;
1767 case GL_TEXTURE_VIEW_NUM_LEVELS
:
1768 if (!ctx
->Extensions
.ARB_texture_view
)
1770 *params
= (GLint
) obj
->NumLevels
;
1773 case GL_TEXTURE_VIEW_MIN_LAYER
:
1774 if (!ctx
->Extensions
.ARB_texture_view
)
1776 *params
= (GLint
) obj
->MinLayer
;
1779 case GL_TEXTURE_VIEW_NUM_LAYERS
:
1780 if (!ctx
->Extensions
.ARB_texture_view
)
1782 *params
= (GLint
) obj
->NumLayers
;
1785 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1786 if (!_mesa_is_gles(ctx
) || !ctx
->Extensions
.OES_EGL_image_external
)
1788 *params
= obj
->RequiredTextureImageUnits
;
1791 case GL_TEXTURE_SRGB_DECODE_EXT
:
1792 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1794 *params
= obj
->Sampler
.sRGBDecode
;
1797 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
1798 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
1800 *params
= obj
->ImageFormatCompatibilityType
;
1807 /* no error if we get here */
1808 _mesa_unlock_texture(ctx
, obj
);
1812 _mesa_unlock_texture(ctx
, obj
);
1813 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1817 /** New in GL 3.0 */
1819 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1821 struct gl_texture_object
*texObj
;
1822 GET_CURRENT_CONTEXT(ctx
);
1824 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1829 case GL_TEXTURE_BORDER_COLOR
:
1830 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1833 _mesa_GetTexParameteriv(target
, pname
, params
);
1838 /** New in GL 3.0 */
1840 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1842 struct gl_texture_object
*texObj
;
1843 GET_CURRENT_CONTEXT(ctx
);
1845 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1850 case GL_TEXTURE_BORDER_COLOR
:
1851 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1856 _mesa_GetTexParameteriv(target
, pname
, ip
);
1858 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1859 pname
== GL_TEXTURE_CROP_RECT_OES
) {