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
;
60 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
61 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
62 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
))
65 else if (target
== GL_TEXTURE_EXTERNAL_OES
) {
66 if (wrap
== GL_CLAMP_TO_EDGE
)
73 case GL_CLAMP_TO_EDGE
:
74 case GL_MIRRORED_REPEAT
:
76 case GL_CLAMP_TO_BORDER
:
77 if (e
->ARB_texture_border_clamp
)
80 case GL_MIRROR_CLAMP_EXT
:
81 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
82 if (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
85 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
86 if (e
->EXT_texture_mirror_clamp
)
94 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
100 * Get current texture object for given target.
101 * Return NULL if any error (and record the error).
102 * Note that this is different from _mesa_select_tex_object() in that proxy
103 * targets are not accepted.
104 * Only the glGetTexLevelParameter() functions accept proxy targets.
106 static struct gl_texture_object
*
107 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
109 struct gl_texture_unit
*texUnit
;
111 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
112 _mesa_error(ctx
, GL_INVALID_OPERATION
,
113 "gl%sTexParameter(current unit)", get
? "Get" : "");
117 texUnit
= _mesa_get_current_tex_unit(ctx
);
121 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
123 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
125 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
126 case GL_TEXTURE_CUBE_MAP
:
127 if (ctx
->Extensions
.ARB_texture_cube_map
) {
128 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
131 case GL_TEXTURE_RECTANGLE_NV
:
132 if (ctx
->Extensions
.NV_texture_rectangle
) {
133 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
136 case GL_TEXTURE_1D_ARRAY_EXT
:
137 if (ctx
->Extensions
.MESA_texture_array
||
138 ctx
->Extensions
.EXT_texture_array
) {
139 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
142 case GL_TEXTURE_2D_ARRAY_EXT
:
143 if (ctx
->Extensions
.MESA_texture_array
||
144 ctx
->Extensions
.EXT_texture_array
) {
145 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
148 case GL_TEXTURE_EXTERNAL_OES
:
149 if (ctx
->Extensions
.OES_EGL_image_external
) {
150 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
157 _mesa_error(ctx
, GL_INVALID_ENUM
,
158 "gl%sTexParameter(target)", get
? "Get" : "");
164 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
165 * \return -1 if error.
168 comp_to_swizzle(GLenum comp
)
190 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
193 ASSERT(swz
<= SWIZZLE_NIL
);
195 GLuint mask
= 0x7 << (3 * comp
);
196 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
203 * This is called just prior to changing any texture object state which
204 * will not effect texture completeness.
207 flush(struct gl_context
*ctx
)
209 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
214 * This is called just prior to changing any texture object state which
215 * can effect texture completeness (texture base level, max level).
216 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
217 * state flag and then mark the texture object as 'incomplete' so that any
218 * per-texture derived state gets recomputed.
221 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
223 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
224 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
229 * Set an integer-valued texture parameter
230 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
233 set_tex_parameteri(struct gl_context
*ctx
,
234 struct gl_texture_object
*texObj
,
235 GLenum pname
, const GLint
*params
)
238 case GL_TEXTURE_MIN_FILTER
:
239 if (texObj
->Sampler
.MinFilter
== params
[0])
245 texObj
->Sampler
.MinFilter
= params
[0];
247 case GL_NEAREST_MIPMAP_NEAREST
:
248 case GL_LINEAR_MIPMAP_NEAREST
:
249 case GL_NEAREST_MIPMAP_LINEAR
:
250 case GL_LINEAR_MIPMAP_LINEAR
:
251 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
252 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
254 texObj
->Sampler
.MinFilter
= params
[0];
263 case GL_TEXTURE_MAG_FILTER
:
264 if (texObj
->Sampler
.MagFilter
== params
[0])
269 flush(ctx
); /* does not effect completeness */
270 texObj
->Sampler
.MagFilter
= params
[0];
277 case GL_TEXTURE_WRAP_S
:
278 if (texObj
->Sampler
.WrapS
== params
[0])
280 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
282 texObj
->Sampler
.WrapS
= params
[0];
287 case GL_TEXTURE_WRAP_T
:
288 if (texObj
->Sampler
.WrapT
== params
[0])
290 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
292 texObj
->Sampler
.WrapT
= params
[0];
297 case GL_TEXTURE_WRAP_R
:
298 if (texObj
->Sampler
.WrapR
== params
[0])
300 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
302 texObj
->Sampler
.WrapR
= params
[0];
307 case GL_TEXTURE_BASE_LEVEL
:
308 if (texObj
->BaseLevel
== params
[0])
311 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
312 _mesa_error(ctx
, GL_INVALID_VALUE
,
313 "glTexParameter(param=%d)", params
[0]);
316 incomplete(ctx
, texObj
);
317 texObj
->BaseLevel
= params
[0];
320 case GL_TEXTURE_MAX_LEVEL
:
321 if (texObj
->MaxLevel
== params
[0])
323 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
324 _mesa_error(ctx
, GL_INVALID_OPERATION
,
325 "glTexParameter(param=%d)", params
[0]);
328 incomplete(ctx
, texObj
);
329 texObj
->MaxLevel
= params
[0];
332 case GL_GENERATE_MIPMAP_SGIS
:
333 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
335 if (texObj
->GenerateMipmap
!= params
[0]) {
337 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
342 case GL_TEXTURE_COMPARE_MODE_ARB
:
343 if (ctx
->Extensions
.ARB_shadow
) {
344 if (texObj
->Sampler
.CompareMode
== params
[0])
346 if (params
[0] == GL_NONE
||
347 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
349 texObj
->Sampler
.CompareMode
= params
[0];
356 case GL_TEXTURE_COMPARE_FUNC_ARB
:
357 if (ctx
->Extensions
.ARB_shadow
) {
358 if (texObj
->Sampler
.CompareFunc
== params
[0])
364 texObj
->Sampler
.CompareFunc
= params
[0];
372 if (ctx
->Extensions
.EXT_shadow_funcs
) {
374 texObj
->Sampler
.CompareFunc
= params
[0];
384 case GL_DEPTH_TEXTURE_MODE_ARB
:
385 if (ctx
->Extensions
.ARB_depth_texture
) {
386 if (texObj
->DepthMode
== params
[0])
388 if (params
[0] == GL_LUMINANCE
||
389 params
[0] == GL_INTENSITY
||
390 params
[0] == GL_ALPHA
||
391 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
393 texObj
->DepthMode
= params
[0];
400 #if FEATURE_OES_draw_texture
401 case GL_TEXTURE_CROP_RECT_OES
:
402 texObj
->CropRect
[0] = params
[0];
403 texObj
->CropRect
[1] = params
[1];
404 texObj
->CropRect
[2] = params
[2];
405 texObj
->CropRect
[3] = params
[3];
409 case GL_TEXTURE_SWIZZLE_R_EXT
:
410 case GL_TEXTURE_SWIZZLE_G_EXT
:
411 case GL_TEXTURE_SWIZZLE_B_EXT
:
412 case GL_TEXTURE_SWIZZLE_A_EXT
:
413 if (ctx
->Extensions
.EXT_texture_swizzle
) {
414 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
415 const GLint swz
= comp_to_swizzle(params
[0]);
417 _mesa_error(ctx
, GL_INVALID_OPERATION
,
418 "glTexParameter(swizzle 0x%x)", params
[0]);
424 texObj
->Swizzle
[comp
] = params
[0];
425 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
430 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
431 if (ctx
->Extensions
.EXT_texture_swizzle
) {
434 for (comp
= 0; comp
< 4; comp
++) {
435 const GLint swz
= comp_to_swizzle(params
[comp
]);
437 texObj
->Swizzle
[comp
] = params
[comp
];
438 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
442 "glTexParameter(swizzle 0x%x)", params
[comp
]);
450 case GL_TEXTURE_SRGB_DECODE_EXT
:
451 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
452 GLenum decode
= params
[0];
453 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
454 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
456 texObj
->Sampler
.sRGBDecode
= decode
;
463 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
464 if (ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
465 GLenum param
= params
[0];
466 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
469 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
471 texObj
->Sampler
.CubeMapSeamless
= param
;
482 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
483 _mesa_lookup_enum_by_nr(pname
));
487 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
488 _mesa_lookup_enum_by_nr(params
[0]));
494 * Set a float-valued texture parameter
495 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
498 set_tex_parameterf(struct gl_context
*ctx
,
499 struct gl_texture_object
*texObj
,
500 GLenum pname
, const GLfloat
*params
)
503 case GL_TEXTURE_MIN_LOD
:
504 if (texObj
->Sampler
.MinLod
== params
[0])
507 texObj
->Sampler
.MinLod
= params
[0];
510 case GL_TEXTURE_MAX_LOD
:
511 if (texObj
->Sampler
.MaxLod
== params
[0])
514 texObj
->Sampler
.MaxLod
= params
[0];
517 case GL_TEXTURE_PRIORITY
:
519 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
522 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
523 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
524 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
526 if (params
[0] < 1.0) {
527 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
531 /* clamp to max, that's what NVIDIA does */
532 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
533 ctx
->Const
.MaxTextureMaxAnisotropy
);
537 static GLuint count
= 0;
539 _mesa_error(ctx
, GL_INVALID_ENUM
,
540 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
544 case GL_TEXTURE_LOD_BIAS
:
545 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
546 if (texObj
->Sampler
.LodBias
!= params
[0]) {
548 texObj
->Sampler
.LodBias
= params
[0];
553 case GL_TEXTURE_BORDER_COLOR
:
555 /* ARB_texture_float disables clamping */
556 if (ctx
->Extensions
.ARB_texture_float
) {
557 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
558 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
559 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
560 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
562 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
563 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
564 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
565 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
570 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
577 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
579 GLboolean need_update
;
580 struct gl_texture_object
*texObj
;
581 GET_CURRENT_CONTEXT(ctx
);
582 ASSERT_OUTSIDE_BEGIN_END(ctx
);
584 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
589 case GL_TEXTURE_MIN_FILTER
:
590 case GL_TEXTURE_MAG_FILTER
:
591 case GL_TEXTURE_WRAP_S
:
592 case GL_TEXTURE_WRAP_T
:
593 case GL_TEXTURE_WRAP_R
:
594 case GL_TEXTURE_BASE_LEVEL
:
595 case GL_TEXTURE_MAX_LEVEL
:
596 case GL_GENERATE_MIPMAP_SGIS
:
597 case GL_TEXTURE_COMPARE_MODE_ARB
:
598 case GL_TEXTURE_COMPARE_FUNC_ARB
:
599 case GL_DEPTH_TEXTURE_MODE_ARB
:
600 case GL_TEXTURE_SRGB_DECODE_EXT
:
601 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
603 /* convert float param to int */
605 p
[0] = (GLint
) param
;
606 p
[1] = p
[2] = p
[3] = 0;
607 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
610 case GL_TEXTURE_SWIZZLE_R_EXT
:
611 case GL_TEXTURE_SWIZZLE_G_EXT
:
612 case GL_TEXTURE_SWIZZLE_B_EXT
:
613 case GL_TEXTURE_SWIZZLE_A_EXT
:
616 p
[0] = (GLint
) param
;
617 p
[1] = p
[2] = p
[3] = 0;
618 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
623 /* this will generate an error if pname is illegal */
626 p
[1] = p
[2] = p
[3] = 0.0F
;
627 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
631 if (ctx
->Driver
.TexParameter
&& need_update
) {
632 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
638 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
640 GLboolean need_update
;
641 struct gl_texture_object
*texObj
;
642 GET_CURRENT_CONTEXT(ctx
);
643 ASSERT_OUTSIDE_BEGIN_END(ctx
);
645 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
650 case GL_TEXTURE_MIN_FILTER
:
651 case GL_TEXTURE_MAG_FILTER
:
652 case GL_TEXTURE_WRAP_S
:
653 case GL_TEXTURE_WRAP_T
:
654 case GL_TEXTURE_WRAP_R
:
655 case GL_TEXTURE_BASE_LEVEL
:
656 case GL_TEXTURE_MAX_LEVEL
:
657 case GL_GENERATE_MIPMAP_SGIS
:
658 case GL_TEXTURE_COMPARE_MODE_ARB
:
659 case GL_TEXTURE_COMPARE_FUNC_ARB
:
660 case GL_DEPTH_TEXTURE_MODE_ARB
:
661 case GL_TEXTURE_SRGB_DECODE_EXT
:
662 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
664 /* convert float param to int */
666 p
[0] = (GLint
) params
[0];
667 p
[1] = p
[2] = p
[3] = 0;
668 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
672 #if FEATURE_OES_draw_texture
673 case GL_TEXTURE_CROP_RECT_OES
:
675 /* convert float params to int */
677 iparams
[0] = (GLint
) params
[0];
678 iparams
[1] = (GLint
) params
[1];
679 iparams
[2] = (GLint
) params
[2];
680 iparams
[3] = (GLint
) params
[3];
681 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
686 case GL_TEXTURE_SWIZZLE_R_EXT
:
687 case GL_TEXTURE_SWIZZLE_G_EXT
:
688 case GL_TEXTURE_SWIZZLE_B_EXT
:
689 case GL_TEXTURE_SWIZZLE_A_EXT
:
690 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
692 GLint p
[4] = {0, 0, 0, 0};
693 p
[0] = (GLint
) params
[0];
694 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
695 p
[1] = (GLint
) params
[1];
696 p
[2] = (GLint
) params
[2];
697 p
[3] = (GLint
) params
[3];
699 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
703 /* this will generate an error if pname is illegal */
704 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
707 if (ctx
->Driver
.TexParameter
&& need_update
) {
708 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
714 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
716 GLboolean need_update
;
717 struct gl_texture_object
*texObj
;
718 GET_CURRENT_CONTEXT(ctx
);
719 ASSERT_OUTSIDE_BEGIN_END(ctx
);
721 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
726 case GL_TEXTURE_MIN_LOD
:
727 case GL_TEXTURE_MAX_LOD
:
728 case GL_TEXTURE_PRIORITY
:
729 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
730 case GL_TEXTURE_LOD_BIAS
:
731 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
734 fparam
[0] = (GLfloat
) param
;
735 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
736 /* convert int param to float */
737 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
741 /* this will generate an error if pname is illegal */
745 iparam
[1] = iparam
[2] = iparam
[3] = 0;
746 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
750 if (ctx
->Driver
.TexParameter
&& need_update
) {
751 GLfloat fparam
= (GLfloat
) param
;
752 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
758 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
760 GLboolean need_update
;
761 struct gl_texture_object
*texObj
;
762 GET_CURRENT_CONTEXT(ctx
);
763 ASSERT_OUTSIDE_BEGIN_END(ctx
);
765 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
770 case GL_TEXTURE_BORDER_COLOR
:
772 /* convert int params to float */
774 fparams
[0] = INT_TO_FLOAT(params
[0]);
775 fparams
[1] = INT_TO_FLOAT(params
[1]);
776 fparams
[2] = INT_TO_FLOAT(params
[2]);
777 fparams
[3] = INT_TO_FLOAT(params
[3]);
778 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
781 case GL_TEXTURE_MIN_LOD
:
782 case GL_TEXTURE_MAX_LOD
:
783 case GL_TEXTURE_PRIORITY
:
784 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
785 case GL_TEXTURE_LOD_BIAS
:
786 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
788 /* convert int param to float */
790 fparams
[0] = (GLfloat
) params
[0];
791 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
792 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
796 /* this will generate an error if pname is illegal */
797 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
800 if (ctx
->Driver
.TexParameter
&& need_update
) {
802 fparams
[0] = INT_TO_FLOAT(params
[0]);
803 if (pname
== GL_TEXTURE_BORDER_COLOR
||
804 pname
== GL_TEXTURE_CROP_RECT_OES
) {
805 fparams
[1] = INT_TO_FLOAT(params
[1]);
806 fparams
[2] = INT_TO_FLOAT(params
[2]);
807 fparams
[3] = INT_TO_FLOAT(params
[3]);
809 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
815 * Set tex parameter to integer value(s). Primarily intended to set
816 * integer-valued texture border color (for integer-valued textures).
820 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
822 struct gl_texture_object
*texObj
;
823 GET_CURRENT_CONTEXT(ctx
);
824 ASSERT_OUTSIDE_BEGIN_END(ctx
);
826 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
831 case GL_TEXTURE_BORDER_COLOR
:
832 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
833 /* set the integer-valued border color */
834 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
837 _mesa_TexParameteriv(target
, pname
, params
);
840 /* XXX no driver hook for TexParameterIiv() yet */
845 * Set tex parameter to unsigned integer value(s). Primarily intended to set
846 * uint-valued texture border color (for integer-valued textures).
850 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
852 struct gl_texture_object
*texObj
;
853 GET_CURRENT_CONTEXT(ctx
);
854 ASSERT_OUTSIDE_BEGIN_END(ctx
);
856 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
861 case GL_TEXTURE_BORDER_COLOR
:
862 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
863 /* set the unsigned integer-valued border color */
864 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
867 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
870 /* XXX no driver hook for TexParameterIuiv() yet */
875 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
876 GLenum pname
, GLfloat
*params
)
879 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
880 *params
= (GLfloat
) iparam
;
885 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
886 GLenum pname
, GLint
*params
)
888 const struct gl_texture_unit
*texUnit
;
889 struct gl_texture_object
*texObj
;
890 const struct gl_texture_image
*img
= NULL
;
893 GET_CURRENT_CONTEXT(ctx
);
894 ASSERT_OUTSIDE_BEGIN_END(ctx
);
896 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
897 _mesa_error(ctx
, GL_INVALID_OPERATION
,
898 "glGetTexLevelParameteriv(current unit)");
902 texUnit
= _mesa_get_current_tex_unit(ctx
);
904 /* this will catch bad target values */
905 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
906 if (maxLevels
== 0) {
907 _mesa_error(ctx
, GL_INVALID_ENUM
,
908 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
912 if (level
< 0 || level
>= maxLevels
) {
913 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
917 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
919 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
920 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
921 /* undefined texture image */
922 if (pname
== GL_TEXTURE_COMPONENTS
)
929 texFormat
= img
->TexFormat
;
932 case GL_TEXTURE_WIDTH
:
933 *params
= img
->Width
;
935 case GL_TEXTURE_HEIGHT
:
936 *params
= img
->Height
;
938 case GL_TEXTURE_DEPTH
:
939 *params
= img
->Depth
;
941 case GL_TEXTURE_INTERNAL_FORMAT
:
942 if (_mesa_is_format_compressed(texFormat
)) {
943 /* need to return the actual compressed format */
944 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
947 /* If the true internal format is not compressed but the user
948 * requested a generic compressed format, we have to return the
949 * generic base format that matches.
951 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
953 * "If no specific compressed format is available,
954 * internalformat is instead replaced by the corresponding base
957 * Otherwise just return the user's requested internal format
960 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
962 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
965 case GL_TEXTURE_BORDER
:
966 *params
= img
->Border
;
968 case GL_TEXTURE_RED_SIZE
:
969 case GL_TEXTURE_GREEN_SIZE
:
970 case GL_TEXTURE_BLUE_SIZE
:
971 case GL_TEXTURE_ALPHA_SIZE
:
972 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
973 *params
= _mesa_get_format_bits(texFormat
, pname
);
977 case GL_TEXTURE_INTENSITY_SIZE
:
978 case GL_TEXTURE_LUMINANCE_SIZE
:
979 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
980 *params
= _mesa_get_format_bits(texFormat
, pname
);
982 /* intensity or luminance is probably stored as RGB[A] */
983 *params
= MIN2(_mesa_get_format_bits(texFormat
,
984 GL_TEXTURE_RED_SIZE
),
985 _mesa_get_format_bits(texFormat
,
986 GL_TEXTURE_GREEN_SIZE
));
993 case GL_TEXTURE_DEPTH_SIZE_ARB
:
994 if (!ctx
->Extensions
.ARB_depth_texture
)
996 *params
= _mesa_get_format_bits(texFormat
, pname
);
998 case GL_TEXTURE_STENCIL_SIZE_EXT
:
999 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
1000 !ctx
->Extensions
.ARB_framebuffer_object
)
1002 *params
= _mesa_get_format_bits(texFormat
, pname
);
1004 case GL_TEXTURE_SHARED_SIZE
:
1005 if (ctx
->Version
< 30 &&
1006 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1008 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1011 /* GL_ARB_texture_compression */
1012 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1013 if (_mesa_is_format_compressed(texFormat
) &&
1014 !_mesa_is_proxy_texture(target
)) {
1015 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1016 img
->Height
, img
->Depth
);
1019 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1020 "glGetTexLevelParameter[if]v(pname)");
1023 case GL_TEXTURE_COMPRESSED
:
1024 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1027 /* GL_ARB_texture_float */
1028 case GL_TEXTURE_RED_TYPE_ARB
:
1029 case GL_TEXTURE_GREEN_TYPE_ARB
:
1030 case GL_TEXTURE_BLUE_TYPE_ARB
:
1031 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1032 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1033 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1034 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1035 if (!ctx
->Extensions
.ARB_texture_float
)
1037 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
1038 *params
= _mesa_get_format_datatype(texFormat
);
1047 /* no error if we get here */
1051 _mesa_error(ctx
, GL_INVALID_ENUM
,
1052 "glGetTexLevelParameter[if]v(pname=%s)",
1053 _mesa_lookup_enum_by_nr(pname
));
1059 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1061 struct gl_texture_object
*obj
;
1062 GET_CURRENT_CONTEXT(ctx
);
1063 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1065 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1069 _mesa_lock_texture(ctx
, obj
);
1071 case GL_TEXTURE_MAG_FILTER
:
1072 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1074 case GL_TEXTURE_MIN_FILTER
:
1075 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1077 case GL_TEXTURE_WRAP_S
:
1078 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1080 case GL_TEXTURE_WRAP_T
:
1081 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1083 case GL_TEXTURE_WRAP_R
:
1084 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1086 case GL_TEXTURE_BORDER_COLOR
:
1087 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1088 _mesa_update_state_locked(ctx
);
1089 if (ctx
->Color
._ClampFragmentColor
) {
1090 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1091 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1092 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1093 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1096 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1097 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1098 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1099 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1102 case GL_TEXTURE_RESIDENT
:
1105 case GL_TEXTURE_PRIORITY
:
1106 *params
= obj
->Priority
;
1108 case GL_TEXTURE_MIN_LOD
:
1109 *params
= obj
->Sampler
.MinLod
;
1111 case GL_TEXTURE_MAX_LOD
:
1112 *params
= obj
->Sampler
.MaxLod
;
1114 case GL_TEXTURE_BASE_LEVEL
:
1115 *params
= (GLfloat
) obj
->BaseLevel
;
1117 case GL_TEXTURE_MAX_LEVEL
:
1118 *params
= (GLfloat
) obj
->MaxLevel
;
1120 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1121 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1123 *params
= obj
->Sampler
.MaxAnisotropy
;
1125 case GL_GENERATE_MIPMAP_SGIS
:
1126 *params
= (GLfloat
) obj
->GenerateMipmap
;
1128 case GL_TEXTURE_COMPARE_MODE_ARB
:
1129 if (!ctx
->Extensions
.ARB_shadow
)
1131 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1133 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1134 if (!ctx
->Extensions
.ARB_shadow
)
1136 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1138 case GL_DEPTH_TEXTURE_MODE_ARB
:
1139 if (!ctx
->Extensions
.ARB_depth_texture
)
1141 *params
= (GLfloat
) obj
->DepthMode
;
1143 case GL_TEXTURE_LOD_BIAS
:
1144 *params
= obj
->Sampler
.LodBias
;
1146 #if FEATURE_OES_draw_texture
1147 case GL_TEXTURE_CROP_RECT_OES
:
1148 params
[0] = obj
->CropRect
[0];
1149 params
[1] = obj
->CropRect
[1];
1150 params
[2] = obj
->CropRect
[2];
1151 params
[3] = obj
->CropRect
[3];
1155 case GL_TEXTURE_SWIZZLE_R_EXT
:
1156 case GL_TEXTURE_SWIZZLE_G_EXT
:
1157 case GL_TEXTURE_SWIZZLE_B_EXT
:
1158 case GL_TEXTURE_SWIZZLE_A_EXT
:
1159 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1161 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1164 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1165 if (!ctx
->Extensions
.EXT_texture_swizzle
) {
1170 for (comp
= 0; comp
< 4; comp
++) {
1171 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1176 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1177 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1179 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1182 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1183 if (!ctx
->Extensions
.ARB_texture_storage
)
1185 *params
= (GLfloat
) obj
->Immutable
;
1192 /* no error if we get here */
1193 _mesa_unlock_texture(ctx
, obj
);
1197 _mesa_unlock_texture(ctx
, obj
);
1198 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1203 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1205 struct gl_texture_object
*obj
;
1206 GET_CURRENT_CONTEXT(ctx
);
1207 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1209 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1213 _mesa_lock_texture(ctx
, obj
);
1215 case GL_TEXTURE_MAG_FILTER
:
1216 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1218 case GL_TEXTURE_MIN_FILTER
:
1219 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1221 case GL_TEXTURE_WRAP_S
:
1222 *params
= (GLint
) obj
->Sampler
.WrapS
;
1224 case GL_TEXTURE_WRAP_T
:
1225 *params
= (GLint
) obj
->Sampler
.WrapT
;
1227 case GL_TEXTURE_WRAP_R
:
1228 *params
= (GLint
) obj
->Sampler
.WrapR
;
1230 case GL_TEXTURE_BORDER_COLOR
:
1233 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1234 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1235 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1236 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1237 params
[0] = FLOAT_TO_INT(b
[0]);
1238 params
[1] = FLOAT_TO_INT(b
[1]);
1239 params
[2] = FLOAT_TO_INT(b
[2]);
1240 params
[3] = FLOAT_TO_INT(b
[3]);
1243 case GL_TEXTURE_RESIDENT
:
1246 case GL_TEXTURE_PRIORITY
:
1247 *params
= FLOAT_TO_INT(obj
->Priority
);
1249 case GL_TEXTURE_MIN_LOD
:
1250 *params
= (GLint
) obj
->Sampler
.MinLod
;
1252 case GL_TEXTURE_MAX_LOD
:
1253 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1255 case GL_TEXTURE_BASE_LEVEL
:
1256 *params
= obj
->BaseLevel
;
1258 case GL_TEXTURE_MAX_LEVEL
:
1259 *params
= obj
->MaxLevel
;
1261 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1262 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1264 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1266 case GL_GENERATE_MIPMAP_SGIS
:
1267 *params
= (GLint
) obj
->GenerateMipmap
;
1269 case GL_TEXTURE_COMPARE_MODE_ARB
:
1270 if (!ctx
->Extensions
.ARB_shadow
)
1272 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1274 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1275 if (!ctx
->Extensions
.ARB_shadow
)
1277 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1279 case GL_DEPTH_TEXTURE_MODE_ARB
:
1280 if (!ctx
->Extensions
.ARB_depth_texture
)
1282 *params
= (GLint
) obj
->DepthMode
;
1284 case GL_TEXTURE_LOD_BIAS
:
1285 *params
= (GLint
) obj
->Sampler
.LodBias
;
1287 #if FEATURE_OES_draw_texture
1288 case GL_TEXTURE_CROP_RECT_OES
:
1289 params
[0] = obj
->CropRect
[0];
1290 params
[1] = obj
->CropRect
[1];
1291 params
[2] = obj
->CropRect
[2];
1292 params
[3] = obj
->CropRect
[3];
1295 case GL_TEXTURE_SWIZZLE_R_EXT
:
1296 case GL_TEXTURE_SWIZZLE_G_EXT
:
1297 case GL_TEXTURE_SWIZZLE_B_EXT
:
1298 case GL_TEXTURE_SWIZZLE_A_EXT
:
1299 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1301 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1304 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1305 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1307 COPY_4V(params
, obj
->Swizzle
);
1310 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1311 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1313 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1316 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1317 if (!ctx
->Extensions
.ARB_texture_storage
)
1319 *params
= (GLint
) obj
->Immutable
;
1322 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1323 if (!ctx
->Extensions
.OES_EGL_image_external
)
1325 *params
= obj
->RequiredTextureImageUnits
;
1332 /* no error if we get here */
1333 _mesa_unlock_texture(ctx
, obj
);
1337 _mesa_unlock_texture(ctx
, obj
);
1338 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1342 /** New in GL 3.0 */
1344 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1346 struct gl_texture_object
*texObj
;
1347 GET_CURRENT_CONTEXT(ctx
);
1348 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1350 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1355 case GL_TEXTURE_BORDER_COLOR
:
1356 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1359 _mesa_GetTexParameteriv(target
, pname
, params
);
1364 /** New in GL 3.0 */
1366 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1368 struct gl_texture_object
*texObj
;
1369 GET_CURRENT_CONTEXT(ctx
);
1370 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1372 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1377 case GL_TEXTURE_BORDER_COLOR
:
1378 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1383 _mesa_GetTexParameteriv(target
, pname
, ip
);
1385 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1386 pname
== GL_TEXTURE_CROP_RECT_OES
) {