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/macros.h"
39 #include "main/mfeatures.h"
40 #include "main/mtypes.h"
41 #include "main/state.h"
42 #include "main/texcompress.h"
43 #include "main/texparam.h"
44 #include "main/teximage.h"
45 #include "main/texstate.h"
46 #include "program/prog_instruction.h"
50 * Check if a coordinate wrap mode is supported for the texture target.
51 * \return GL_TRUE if legal, GL_FALSE otherwise
54 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
56 const struct gl_extensions
* const e
= & ctx
->Extensions
;
58 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
59 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
60 /* any texture target */
63 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
65 (wrap
== GL_MIRRORED_REPEAT
&&
66 e
->ARB_texture_mirrored_repeat
) ||
67 (wrap
== GL_MIRROR_CLAMP_EXT
&&
68 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
69 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
70 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
71 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
72 (e
->EXT_texture_mirror_clamp
)))) {
73 /* non-rectangle texture */
77 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
83 * Get current texture object for given target.
84 * Return NULL if any error (and record the error).
85 * Note that this is different from _mesa_select_tex_object() in that proxy
86 * targets are not accepted.
87 * Only the glGetTexLevelParameter() functions accept proxy targets.
89 static struct gl_texture_object
*
90 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
92 struct gl_texture_unit
*texUnit
;
94 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
95 _mesa_error(ctx
, GL_INVALID_OPERATION
,
96 "gl%sTexParameter(current unit)", get
? "Get" : "");
100 texUnit
= _mesa_get_current_tex_unit(ctx
);
104 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
106 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
108 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
109 case GL_TEXTURE_CUBE_MAP
:
110 if (ctx
->Extensions
.ARB_texture_cube_map
) {
111 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
114 case GL_TEXTURE_RECTANGLE_NV
:
115 if (ctx
->Extensions
.NV_texture_rectangle
) {
116 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
119 case GL_TEXTURE_1D_ARRAY_EXT
:
120 if (ctx
->Extensions
.MESA_texture_array
||
121 ctx
->Extensions
.EXT_texture_array
) {
122 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
125 case GL_TEXTURE_2D_ARRAY_EXT
:
126 if (ctx
->Extensions
.MESA_texture_array
||
127 ctx
->Extensions
.EXT_texture_array
) {
128 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
135 _mesa_error(ctx
, GL_INVALID_ENUM
,
136 "gl%sTexParameter(target)", get
? "Get" : "");
142 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
143 * \return -1 if error.
146 comp_to_swizzle(GLenum comp
)
168 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
171 ASSERT(swz
<= SWIZZLE_NIL
);
173 GLuint mask
= 0x7 << (3 * comp
);
174 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
181 * This is called just prior to changing any texture object state which
182 * will not effect texture completeness.
185 flush(struct gl_context
*ctx
)
187 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
192 * This is called just prior to changing any texture object state which
193 * can effect texture completeness (texture base level, max level,
194 * minification filter).
195 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
196 * state flag and then mark the texture object as 'incomplete' so that any
197 * per-texture derived state gets recomputed.
200 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
202 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
203 texObj
->_Complete
= GL_FALSE
;
208 * Set an integer-valued texture parameter
209 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
212 set_tex_parameteri(struct gl_context
*ctx
,
213 struct gl_texture_object
*texObj
,
214 GLenum pname
, const GLint
*params
)
217 case GL_TEXTURE_MIN_FILTER
:
218 if (texObj
->Sampler
.MinFilter
== params
[0])
223 incomplete(ctx
, texObj
);
224 texObj
->Sampler
.MinFilter
= params
[0];
226 case GL_NEAREST_MIPMAP_NEAREST
:
227 case GL_LINEAR_MIPMAP_NEAREST
:
228 case GL_NEAREST_MIPMAP_LINEAR
:
229 case GL_LINEAR_MIPMAP_LINEAR
:
230 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
231 incomplete(ctx
, texObj
);
232 texObj
->Sampler
.MinFilter
= params
[0];
241 case GL_TEXTURE_MAG_FILTER
:
242 if (texObj
->Sampler
.MagFilter
== params
[0])
247 flush(ctx
); /* does not effect completeness */
248 texObj
->Sampler
.MagFilter
= params
[0];
255 case GL_TEXTURE_WRAP_S
:
256 if (texObj
->Sampler
.WrapS
== params
[0])
258 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
260 texObj
->Sampler
.WrapS
= params
[0];
265 case GL_TEXTURE_WRAP_T
:
266 if (texObj
->Sampler
.WrapT
== params
[0])
268 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
270 texObj
->Sampler
.WrapT
= params
[0];
275 case GL_TEXTURE_WRAP_R
:
276 if (texObj
->Sampler
.WrapR
== params
[0])
278 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
280 texObj
->Sampler
.WrapR
= params
[0];
285 case GL_TEXTURE_BASE_LEVEL
:
286 if (texObj
->BaseLevel
== params
[0])
289 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
290 _mesa_error(ctx
, GL_INVALID_VALUE
,
291 "glTexParameter(param=%d)", params
[0]);
294 incomplete(ctx
, texObj
);
295 texObj
->BaseLevel
= params
[0];
298 case GL_TEXTURE_MAX_LEVEL
:
299 if (texObj
->MaxLevel
== params
[0])
301 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
302 _mesa_error(ctx
, GL_INVALID_OPERATION
,
303 "glTexParameter(param=%d)", params
[0]);
306 incomplete(ctx
, texObj
);
307 texObj
->MaxLevel
= params
[0];
310 case GL_GENERATE_MIPMAP_SGIS
:
311 if (texObj
->GenerateMipmap
!= params
[0]) {
313 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
318 case GL_TEXTURE_COMPARE_MODE_ARB
:
319 if (ctx
->Extensions
.ARB_shadow
) {
320 if (texObj
->Sampler
.CompareMode
== params
[0])
322 if (params
[0] == GL_NONE
||
323 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
325 texObj
->Sampler
.CompareMode
= params
[0];
332 case GL_TEXTURE_COMPARE_FUNC_ARB
:
333 if (ctx
->Extensions
.ARB_shadow
) {
334 if (texObj
->Sampler
.CompareFunc
== params
[0])
340 texObj
->Sampler
.CompareFunc
= params
[0];
348 if (ctx
->Extensions
.EXT_shadow_funcs
) {
350 texObj
->Sampler
.CompareFunc
= params
[0];
360 case GL_DEPTH_TEXTURE_MODE_ARB
:
361 if (ctx
->Extensions
.ARB_depth_texture
) {
362 if (texObj
->Sampler
.DepthMode
== params
[0])
364 if (params
[0] == GL_LUMINANCE
||
365 params
[0] == GL_INTENSITY
||
366 params
[0] == GL_ALPHA
||
367 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
369 texObj
->Sampler
.DepthMode
= params
[0];
376 #if FEATURE_OES_draw_texture
377 case GL_TEXTURE_CROP_RECT_OES
:
378 texObj
->CropRect
[0] = params
[0];
379 texObj
->CropRect
[1] = params
[1];
380 texObj
->CropRect
[2] = params
[2];
381 texObj
->CropRect
[3] = params
[3];
385 case GL_TEXTURE_SWIZZLE_R_EXT
:
386 case GL_TEXTURE_SWIZZLE_G_EXT
:
387 case GL_TEXTURE_SWIZZLE_B_EXT
:
388 case GL_TEXTURE_SWIZZLE_A_EXT
:
389 if (ctx
->Extensions
.EXT_texture_swizzle
) {
390 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
391 const GLint swz
= comp_to_swizzle(params
[0]);
393 _mesa_error(ctx
, GL_INVALID_OPERATION
,
394 "glTexParameter(swizzle 0x%x)", params
[0]);
400 texObj
->Swizzle
[comp
] = params
[0];
401 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
407 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
408 if (ctx
->Extensions
.EXT_texture_swizzle
) {
411 for (comp
= 0; comp
< 4; comp
++) {
412 const GLint swz
= comp_to_swizzle(params
[comp
]);
414 texObj
->Swizzle
[comp
] = params
[comp
];
415 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
418 _mesa_error(ctx
, GL_INVALID_OPERATION
,
419 "glTexParameter(swizzle 0x%x)", params
[comp
]);
427 case GL_TEXTURE_SRGB_DECODE_EXT
:
428 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
429 GLenum decode
= params
[0];
430 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
431 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
433 texObj
->Sampler
.sRGBDecode
= decode
;
440 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
441 if (ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
442 GLenum param
= params
[0];
443 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
446 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
448 texObj
->Sampler
.CubeMapSeamless
= param
;
459 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
460 _mesa_lookup_enum_by_nr(pname
));
464 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
465 _mesa_lookup_enum_by_nr(params
[0]));
471 * Set a float-valued texture parameter
472 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
475 set_tex_parameterf(struct gl_context
*ctx
,
476 struct gl_texture_object
*texObj
,
477 GLenum pname
, const GLfloat
*params
)
480 case GL_TEXTURE_MIN_LOD
:
481 if (texObj
->Sampler
.MinLod
== params
[0])
484 texObj
->Sampler
.MinLod
= params
[0];
487 case GL_TEXTURE_MAX_LOD
:
488 if (texObj
->Sampler
.MaxLod
== params
[0])
491 texObj
->Sampler
.MaxLod
= params
[0];
494 case GL_TEXTURE_PRIORITY
:
496 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
499 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
500 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
501 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
503 if (params
[0] < 1.0) {
504 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
508 /* clamp to max, that's what NVIDIA does */
509 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
510 ctx
->Const
.MaxTextureMaxAnisotropy
);
514 static GLuint count
= 0;
516 _mesa_error(ctx
, GL_INVALID_ENUM
,
517 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
521 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
522 if (ctx
->Extensions
.ARB_shadow_ambient
) {
523 if (texObj
->Sampler
.CompareFailValue
!= params
[0]) {
525 texObj
->Sampler
.CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
530 _mesa_error(ctx
, GL_INVALID_ENUM
,
531 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
535 case GL_TEXTURE_LOD_BIAS
:
536 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
537 if (texObj
->Sampler
.LodBias
!= params
[0]) {
539 texObj
->Sampler
.LodBias
= params
[0];
544 case GL_TEXTURE_BORDER_COLOR
:
546 /* ARB_texture_float disables clamping */
547 if (ctx
->Extensions
.ARB_texture_float
) {
548 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
549 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
550 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
551 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
553 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
554 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
555 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
556 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
561 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
568 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
570 GLboolean need_update
;
571 struct gl_texture_object
*texObj
;
572 GET_CURRENT_CONTEXT(ctx
);
573 ASSERT_OUTSIDE_BEGIN_END(ctx
);
575 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
580 case GL_TEXTURE_MIN_FILTER
:
581 case GL_TEXTURE_MAG_FILTER
:
582 case GL_TEXTURE_WRAP_S
:
583 case GL_TEXTURE_WRAP_T
:
584 case GL_TEXTURE_WRAP_R
:
585 case GL_TEXTURE_BASE_LEVEL
:
586 case GL_TEXTURE_MAX_LEVEL
:
587 case GL_GENERATE_MIPMAP_SGIS
:
588 case GL_TEXTURE_COMPARE_MODE_ARB
:
589 case GL_TEXTURE_COMPARE_FUNC_ARB
:
590 case GL_DEPTH_TEXTURE_MODE_ARB
:
591 case GL_TEXTURE_SRGB_DECODE_EXT
:
592 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
594 /* convert float param to int */
596 p
[0] = (GLint
) param
;
597 p
[1] = p
[2] = p
[3] = 0;
598 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
603 /* this will generate an error if pname is illegal */
606 p
[1] = p
[2] = p
[3] = 0.0F
;
607 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
611 if (ctx
->Driver
.TexParameter
&& need_update
) {
612 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
618 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
620 GLboolean need_update
;
621 struct gl_texture_object
*texObj
;
622 GET_CURRENT_CONTEXT(ctx
);
623 ASSERT_OUTSIDE_BEGIN_END(ctx
);
625 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
630 case GL_TEXTURE_MIN_FILTER
:
631 case GL_TEXTURE_MAG_FILTER
:
632 case GL_TEXTURE_WRAP_S
:
633 case GL_TEXTURE_WRAP_T
:
634 case GL_TEXTURE_WRAP_R
:
635 case GL_TEXTURE_BASE_LEVEL
:
636 case GL_TEXTURE_MAX_LEVEL
:
637 case GL_GENERATE_MIPMAP_SGIS
:
638 case GL_TEXTURE_COMPARE_MODE_ARB
:
639 case GL_TEXTURE_COMPARE_FUNC_ARB
:
640 case GL_DEPTH_TEXTURE_MODE_ARB
:
641 case GL_TEXTURE_SRGB_DECODE_EXT
:
642 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
644 /* convert float param to int */
646 p
[0] = (GLint
) params
[0];
647 p
[1] = p
[2] = p
[3] = 0;
648 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
652 #if FEATURE_OES_draw_texture
653 case GL_TEXTURE_CROP_RECT_OES
:
655 /* convert float params to int */
657 iparams
[0] = (GLint
) params
[0];
658 iparams
[1] = (GLint
) params
[1];
659 iparams
[2] = (GLint
) params
[2];
660 iparams
[3] = (GLint
) params
[3];
661 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
667 /* this will generate an error if pname is illegal */
668 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
671 if (ctx
->Driver
.TexParameter
&& need_update
) {
672 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
678 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
680 GLboolean need_update
;
681 struct gl_texture_object
*texObj
;
682 GET_CURRENT_CONTEXT(ctx
);
683 ASSERT_OUTSIDE_BEGIN_END(ctx
);
685 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
690 case GL_TEXTURE_MIN_LOD
:
691 case GL_TEXTURE_MAX_LOD
:
692 case GL_TEXTURE_PRIORITY
:
693 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
694 case GL_TEXTURE_LOD_BIAS
:
695 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
698 fparam
[0] = (GLfloat
) param
;
699 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
700 /* convert int param to float */
701 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
705 /* this will generate an error if pname is illegal */
709 iparam
[1] = iparam
[2] = iparam
[3] = 0;
710 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
714 if (ctx
->Driver
.TexParameter
&& need_update
) {
715 GLfloat fparam
= (GLfloat
) param
;
716 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
722 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
724 GLboolean need_update
;
725 struct gl_texture_object
*texObj
;
726 GET_CURRENT_CONTEXT(ctx
);
727 ASSERT_OUTSIDE_BEGIN_END(ctx
);
729 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
734 case GL_TEXTURE_BORDER_COLOR
:
736 /* convert int params to float */
738 fparams
[0] = INT_TO_FLOAT(params
[0]);
739 fparams
[1] = INT_TO_FLOAT(params
[1]);
740 fparams
[2] = INT_TO_FLOAT(params
[2]);
741 fparams
[3] = INT_TO_FLOAT(params
[3]);
742 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
745 case GL_TEXTURE_MIN_LOD
:
746 case GL_TEXTURE_MAX_LOD
:
747 case GL_TEXTURE_PRIORITY
:
748 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
749 case GL_TEXTURE_LOD_BIAS
:
750 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
752 /* convert int param to float */
754 fparams
[0] = (GLfloat
) params
[0];
755 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
756 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
760 /* this will generate an error if pname is illegal */
761 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
764 if (ctx
->Driver
.TexParameter
&& need_update
) {
766 fparams
[0] = INT_TO_FLOAT(params
[0]);
767 if (pname
== GL_TEXTURE_BORDER_COLOR
||
768 pname
== GL_TEXTURE_CROP_RECT_OES
) {
769 fparams
[1] = INT_TO_FLOAT(params
[1]);
770 fparams
[2] = INT_TO_FLOAT(params
[2]);
771 fparams
[3] = INT_TO_FLOAT(params
[3]);
773 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
779 * Set tex parameter to integer value(s). Primarily intended to set
780 * integer-valued texture border color (for integer-valued textures).
784 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
786 struct gl_texture_object
*texObj
;
787 GET_CURRENT_CONTEXT(ctx
);
788 ASSERT_OUTSIDE_BEGIN_END(ctx
);
790 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
795 case GL_TEXTURE_BORDER_COLOR
:
796 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
797 /* set the integer-valued border color */
798 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
801 _mesa_TexParameteriv(target
, pname
, params
);
804 /* XXX no driver hook for TexParameterIiv() yet */
809 * Set tex parameter to unsigned integer value(s). Primarily intended to set
810 * uint-valued texture border color (for integer-valued textures).
814 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
816 struct gl_texture_object
*texObj
;
817 GET_CURRENT_CONTEXT(ctx
);
818 ASSERT_OUTSIDE_BEGIN_END(ctx
);
820 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
825 case GL_TEXTURE_BORDER_COLOR
:
826 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
827 /* set the unsigned integer-valued border color */
828 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
831 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
834 /* XXX no driver hook for TexParameterIuiv() yet */
841 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
842 GLenum pname
, GLfloat
*params
)
845 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
846 *params
= (GLfloat
) iparam
;
851 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
852 GLenum pname
, GLint
*params
)
854 const struct gl_texture_unit
*texUnit
;
855 struct gl_texture_object
*texObj
;
856 const struct gl_texture_image
*img
= NULL
;
859 GET_CURRENT_CONTEXT(ctx
);
860 ASSERT_OUTSIDE_BEGIN_END(ctx
);
862 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
863 _mesa_error(ctx
, GL_INVALID_OPERATION
,
864 "glGetTexLevelParameteriv(current unit)");
868 texUnit
= _mesa_get_current_tex_unit(ctx
);
870 /* this will catch bad target values */
871 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
872 if (maxLevels
== 0) {
873 _mesa_error(ctx
, GL_INVALID_ENUM
,
874 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
878 if (level
< 0 || level
>= maxLevels
) {
879 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
883 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
885 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
886 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
887 /* undefined texture image */
888 if (pname
== GL_TEXTURE_COMPONENTS
)
895 texFormat
= img
->TexFormat
;
898 case GL_TEXTURE_WIDTH
:
899 *params
= img
->Width
;
901 case GL_TEXTURE_HEIGHT
:
902 *params
= img
->Height
;
904 case GL_TEXTURE_DEPTH
:
905 *params
= img
->Depth
;
907 case GL_TEXTURE_INTERNAL_FORMAT
:
908 if (_mesa_is_format_compressed(texFormat
)) {
909 /* need to return the actual compressed format */
910 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
913 /* If the true internal format is not compressed but the user
914 * requested a generic compressed format, we have to return the
915 * generic base format that matches.
917 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
919 * "If no specific compressed format is available,
920 * internalformat is instead replaced by the corresponding base
923 * Otherwise just return the user's requested internal format
926 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
928 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
931 case GL_TEXTURE_BORDER
:
932 *params
= img
->Border
;
934 case GL_TEXTURE_RED_SIZE
:
935 if (img
->_BaseFormat
== GL_RED
) {
936 *params
= _mesa_get_format_bits(texFormat
, pname
);
940 case GL_TEXTURE_GREEN_SIZE
:
941 if (img
->_BaseFormat
== GL_RG
) {
942 *params
= _mesa_get_format_bits(texFormat
, pname
);
946 case GL_TEXTURE_BLUE_SIZE
:
947 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
948 *params
= _mesa_get_format_bits(texFormat
, pname
);
952 case GL_TEXTURE_ALPHA_SIZE
:
953 if (img
->_BaseFormat
== GL_ALPHA
||
954 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
955 img
->_BaseFormat
== GL_RGBA
)
956 *params
= _mesa_get_format_bits(texFormat
, pname
);
960 case GL_TEXTURE_INTENSITY_SIZE
:
961 if (img
->_BaseFormat
!= GL_INTENSITY
)
964 *params
= _mesa_get_format_bits(texFormat
, pname
);
966 /* intensity probably stored as rgb texture */
967 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
968 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
972 case GL_TEXTURE_LUMINANCE_SIZE
:
973 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
974 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
977 *params
= _mesa_get_format_bits(texFormat
, pname
);
979 /* luminance probably stored as rgb texture */
980 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
981 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
985 case GL_TEXTURE_DEPTH_SIZE_ARB
:
986 if (!ctx
->Extensions
.ARB_depth_texture
)
988 *params
= _mesa_get_format_bits(texFormat
, pname
);
990 case GL_TEXTURE_STENCIL_SIZE_EXT
:
991 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
992 !ctx
->Extensions
.ARB_framebuffer_object
)
994 *params
= _mesa_get_format_bits(texFormat
, pname
);
996 case GL_TEXTURE_SHARED_SIZE
:
997 if (ctx
->VersionMajor
< 3 &&
998 !ctx
->Extensions
.EXT_texture_shared_exponent
)
1000 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1003 /* GL_ARB_texture_compression */
1004 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1005 if (_mesa_is_format_compressed(texFormat
) &&
1006 !_mesa_is_proxy_texture(target
)) {
1007 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1008 img
->Height
, img
->Depth
);
1011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1012 "glGetTexLevelParameter[if]v(pname)");
1015 case GL_TEXTURE_COMPRESSED
:
1016 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1019 /* GL_ARB_texture_float */
1020 case GL_TEXTURE_RED_TYPE_ARB
:
1021 if (!ctx
->Extensions
.ARB_texture_float
)
1023 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
1024 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1026 case GL_TEXTURE_GREEN_TYPE_ARB
:
1027 if (!ctx
->Extensions
.ARB_texture_float
)
1029 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1030 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1032 case GL_TEXTURE_BLUE_TYPE_ARB
:
1033 if (!ctx
->Extensions
.ARB_texture_float
)
1035 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1036 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1038 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1039 if (!ctx
->Extensions
.ARB_texture_float
)
1041 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1042 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1044 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1045 if (!ctx
->Extensions
.ARB_texture_float
)
1047 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1048 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1050 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1051 if (!ctx
->Extensions
.ARB_texture_float
)
1053 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1054 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1056 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1057 if (!ctx
->Extensions
.ARB_texture_float
)
1059 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1060 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1067 /* no error if we get here */
1071 _mesa_error(ctx
, GL_INVALID_ENUM
,
1072 "glGetTexLevelParameter[if]v(pname=%s)",
1073 _mesa_lookup_enum_by_nr(pname
));
1079 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1081 struct gl_texture_object
*obj
;
1082 GET_CURRENT_CONTEXT(ctx
);
1083 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1085 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1089 _mesa_lock_texture(ctx
, obj
);
1091 case GL_TEXTURE_MAG_FILTER
:
1092 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1094 case GL_TEXTURE_MIN_FILTER
:
1095 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1097 case GL_TEXTURE_WRAP_S
:
1098 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1100 case GL_TEXTURE_WRAP_T
:
1101 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1103 case GL_TEXTURE_WRAP_R
:
1104 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1106 case GL_TEXTURE_BORDER_COLOR
:
1107 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1108 _mesa_update_state_locked(ctx
);
1109 if (ctx
->Color
._ClampFragmentColor
) {
1110 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1111 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1112 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1113 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1116 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1117 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1118 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1119 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1122 case GL_TEXTURE_RESIDENT
:
1123 *params
= ctx
->Driver
.IsTextureResident
?
1124 ctx
->Driver
.IsTextureResident(ctx
, obj
) : 1.0F
;
1126 case GL_TEXTURE_PRIORITY
:
1127 *params
= obj
->Priority
;
1129 case GL_TEXTURE_MIN_LOD
:
1130 *params
= obj
->Sampler
.MinLod
;
1132 case GL_TEXTURE_MAX_LOD
:
1133 *params
= obj
->Sampler
.MaxLod
;
1135 case GL_TEXTURE_BASE_LEVEL
:
1136 *params
= (GLfloat
) obj
->BaseLevel
;
1138 case GL_TEXTURE_MAX_LEVEL
:
1139 *params
= (GLfloat
) obj
->MaxLevel
;
1141 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1142 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1144 *params
= obj
->Sampler
.MaxAnisotropy
;
1146 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1147 if (!ctx
->Extensions
.ARB_shadow_ambient
)
1149 *params
= obj
->Sampler
.CompareFailValue
;
1151 case GL_GENERATE_MIPMAP_SGIS
:
1152 *params
= (GLfloat
) obj
->GenerateMipmap
;
1154 case GL_TEXTURE_COMPARE_MODE_ARB
:
1155 if (!ctx
->Extensions
.ARB_shadow
)
1157 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1159 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1160 if (!ctx
->Extensions
.ARB_shadow
)
1162 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1164 case GL_DEPTH_TEXTURE_MODE_ARB
:
1165 if (!ctx
->Extensions
.ARB_depth_texture
)
1167 *params
= (GLfloat
) obj
->Sampler
.DepthMode
;
1169 case GL_TEXTURE_LOD_BIAS
:
1170 *params
= obj
->Sampler
.LodBias
;
1172 #if FEATURE_OES_draw_texture
1173 case GL_TEXTURE_CROP_RECT_OES
:
1174 params
[0] = obj
->CropRect
[0];
1175 params
[1] = obj
->CropRect
[1];
1176 params
[2] = obj
->CropRect
[2];
1177 params
[3] = obj
->CropRect
[3];
1181 case GL_TEXTURE_SWIZZLE_R_EXT
:
1182 case GL_TEXTURE_SWIZZLE_G_EXT
:
1183 case GL_TEXTURE_SWIZZLE_B_EXT
:
1184 case GL_TEXTURE_SWIZZLE_A_EXT
:
1185 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1187 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1190 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1191 if (!ctx
->Extensions
.EXT_texture_swizzle
) {
1196 for (comp
= 0; comp
< 4; comp
++) {
1197 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1202 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1203 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1205 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1212 /* no error if we get here */
1213 _mesa_unlock_texture(ctx
, obj
);
1217 _mesa_unlock_texture(ctx
, obj
);
1218 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1223 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1225 struct gl_texture_object
*obj
;
1226 GET_CURRENT_CONTEXT(ctx
);
1227 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1229 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1233 _mesa_lock_texture(ctx
, obj
);
1235 case GL_TEXTURE_MAG_FILTER
:
1236 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1238 case GL_TEXTURE_MIN_FILTER
:
1239 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1241 case GL_TEXTURE_WRAP_S
:
1242 *params
= (GLint
) obj
->Sampler
.WrapS
;
1244 case GL_TEXTURE_WRAP_T
:
1245 *params
= (GLint
) obj
->Sampler
.WrapT
;
1247 case GL_TEXTURE_WRAP_R
:
1248 *params
= (GLint
) obj
->Sampler
.WrapR
;
1250 case GL_TEXTURE_BORDER_COLOR
:
1253 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1254 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1255 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1256 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1257 params
[0] = FLOAT_TO_INT(b
[0]);
1258 params
[1] = FLOAT_TO_INT(b
[1]);
1259 params
[2] = FLOAT_TO_INT(b
[2]);
1260 params
[3] = FLOAT_TO_INT(b
[3]);
1263 case GL_TEXTURE_RESIDENT
:
1264 *params
= ctx
->Driver
.IsTextureResident
?
1265 ctx
->Driver
.IsTextureResident(ctx
, obj
) : 1;
1267 case GL_TEXTURE_PRIORITY
:
1268 *params
= FLOAT_TO_INT(obj
->Priority
);
1270 case GL_TEXTURE_MIN_LOD
:
1271 *params
= (GLint
) obj
->Sampler
.MinLod
;
1273 case GL_TEXTURE_MAX_LOD
:
1274 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1276 case GL_TEXTURE_BASE_LEVEL
:
1277 *params
= obj
->BaseLevel
;
1279 case GL_TEXTURE_MAX_LEVEL
:
1280 *params
= obj
->MaxLevel
;
1282 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1283 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1285 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1287 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1288 if (!ctx
->Extensions
.ARB_shadow_ambient
)
1290 *params
= (GLint
) FLOAT_TO_INT(obj
->Sampler
.CompareFailValue
);
1292 case GL_GENERATE_MIPMAP_SGIS
:
1293 *params
= (GLint
) obj
->GenerateMipmap
;
1295 case GL_TEXTURE_COMPARE_MODE_ARB
:
1296 if (!ctx
->Extensions
.ARB_shadow
)
1298 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1300 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1301 if (!ctx
->Extensions
.ARB_shadow
)
1303 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1305 case GL_DEPTH_TEXTURE_MODE_ARB
:
1306 if (!ctx
->Extensions
.ARB_depth_texture
)
1308 *params
= (GLint
) obj
->Sampler
.DepthMode
;
1310 case GL_TEXTURE_LOD_BIAS
:
1311 *params
= (GLint
) obj
->Sampler
.LodBias
;
1313 #if FEATURE_OES_draw_texture
1314 case GL_TEXTURE_CROP_RECT_OES
:
1315 params
[0] = obj
->CropRect
[0];
1316 params
[1] = obj
->CropRect
[1];
1317 params
[2] = obj
->CropRect
[2];
1318 params
[3] = obj
->CropRect
[3];
1321 case GL_TEXTURE_SWIZZLE_R_EXT
:
1322 case GL_TEXTURE_SWIZZLE_G_EXT
:
1323 case GL_TEXTURE_SWIZZLE_B_EXT
:
1324 case GL_TEXTURE_SWIZZLE_A_EXT
:
1325 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1327 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1330 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1331 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1333 COPY_4V(params
, obj
->Swizzle
);
1336 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1337 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1339 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1346 /* no error if we get here */
1347 _mesa_unlock_texture(ctx
, obj
);
1351 _mesa_unlock_texture(ctx
, obj
);
1352 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1356 /** New in GL 3.0 */
1358 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1360 struct gl_texture_object
*texObj
;
1361 GET_CURRENT_CONTEXT(ctx
);
1362 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1364 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1369 case GL_TEXTURE_BORDER_COLOR
:
1370 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1373 _mesa_GetTexParameteriv(target
, pname
, params
);
1378 /** New in GL 3.0 */
1380 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1382 struct gl_texture_object
*texObj
;
1383 GET_CURRENT_CONTEXT(ctx
);
1384 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1386 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1391 case GL_TEXTURE_BORDER_COLOR
:
1392 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1397 _mesa_GetTexParameteriv(target
, pname
, ip
);
1399 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1400 pname
== GL_TEXTURE_CROP_RECT_OES
) {