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/texcompress.h"
42 #include "main/texparam.h"
43 #include "main/teximage.h"
44 #include "main/texstate.h"
45 #include "main/texfetch.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
->MinFilter
== params
[0])
223 incomplete(ctx
, texObj
);
224 texObj
->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
->MinFilter
= params
[0];
241 case GL_TEXTURE_MAG_FILTER
:
242 if (texObj
->MagFilter
== params
[0])
247 flush(ctx
); /* does not effect completeness */
248 texObj
->MagFilter
= params
[0];
255 case GL_TEXTURE_WRAP_S
:
256 if (texObj
->WrapS
== params
[0])
258 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
260 texObj
->WrapS
= params
[0];
265 case GL_TEXTURE_WRAP_T
:
266 if (texObj
->WrapT
== params
[0])
268 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
270 texObj
->WrapT
= params
[0];
275 case GL_TEXTURE_WRAP_R
:
276 if (texObj
->WrapR
== params
[0])
278 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
280 texObj
->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
->CompareMode
== params
[0])
322 if (params
[0] == GL_NONE
||
323 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
325 texObj
->CompareMode
= params
[0];
332 case GL_TEXTURE_COMPARE_FUNC_ARB
:
333 if (ctx
->Extensions
.ARB_shadow
) {
334 if (texObj
->CompareFunc
== params
[0])
340 texObj
->CompareFunc
= params
[0];
348 if (ctx
->Extensions
.EXT_shadow_funcs
) {
350 texObj
->CompareFunc
= params
[0];
360 case GL_DEPTH_TEXTURE_MODE_ARB
:
361 if (ctx
->Extensions
.ARB_depth_texture
) {
362 if (texObj
->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
->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
->sRGBDecode
!= decode
) {
433 texObj
->sRGBDecode
= decode
;
434 _mesa_update_fetch_functions(texObj
);
446 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
447 _mesa_lookup_enum_by_nr(pname
));
451 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
452 _mesa_lookup_enum_by_nr(params
[0]));
458 * Set a float-valued texture parameter
459 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
462 set_tex_parameterf(struct gl_context
*ctx
,
463 struct gl_texture_object
*texObj
,
464 GLenum pname
, const GLfloat
*params
)
467 case GL_TEXTURE_MIN_LOD
:
468 if (texObj
->MinLod
== params
[0])
471 texObj
->MinLod
= params
[0];
474 case GL_TEXTURE_MAX_LOD
:
475 if (texObj
->MaxLod
== params
[0])
478 texObj
->MaxLod
= params
[0];
481 case GL_TEXTURE_PRIORITY
:
483 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
486 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
487 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
488 if (texObj
->MaxAnisotropy
== params
[0])
490 if (params
[0] < 1.0) {
491 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
495 /* clamp to max, that's what NVIDIA does */
496 texObj
->MaxAnisotropy
= MIN2(params
[0],
497 ctx
->Const
.MaxTextureMaxAnisotropy
);
501 static GLuint count
= 0;
503 _mesa_error(ctx
, GL_INVALID_ENUM
,
504 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
508 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
509 if (ctx
->Extensions
.ARB_shadow_ambient
) {
510 if (texObj
->CompareFailValue
!= params
[0]) {
512 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
517 _mesa_error(ctx
, GL_INVALID_ENUM
,
518 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
522 case GL_TEXTURE_LOD_BIAS
:
523 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
524 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
525 if (texObj
->LodBias
!= params
[0]) {
527 texObj
->LodBias
= params
[0];
534 case GL_TEXTURE_BORDER_COLOR
:
536 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
537 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
538 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
539 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
543 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
550 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
552 GLboolean need_update
;
553 struct gl_texture_object
*texObj
;
554 GET_CURRENT_CONTEXT(ctx
);
555 ASSERT_OUTSIDE_BEGIN_END(ctx
);
557 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
562 case GL_TEXTURE_MIN_FILTER
:
563 case GL_TEXTURE_MAG_FILTER
:
564 case GL_TEXTURE_WRAP_S
:
565 case GL_TEXTURE_WRAP_T
:
566 case GL_TEXTURE_WRAP_R
:
567 case GL_TEXTURE_BASE_LEVEL
:
568 case GL_TEXTURE_MAX_LEVEL
:
569 case GL_GENERATE_MIPMAP_SGIS
:
570 case GL_TEXTURE_COMPARE_MODE_ARB
:
571 case GL_TEXTURE_COMPARE_FUNC_ARB
:
572 case GL_DEPTH_TEXTURE_MODE_ARB
:
573 case GL_TEXTURE_SRGB_DECODE_EXT
:
575 /* convert float param to int */
577 p
[0] = (GLint
) param
;
578 p
[1] = p
[2] = p
[3] = 0;
579 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
584 /* this will generate an error if pname is illegal */
587 p
[1] = p
[2] = p
[3] = 0.0F
;
588 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
592 if (ctx
->Driver
.TexParameter
&& need_update
) {
593 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
599 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
601 GLboolean need_update
;
602 struct gl_texture_object
*texObj
;
603 GET_CURRENT_CONTEXT(ctx
);
604 ASSERT_OUTSIDE_BEGIN_END(ctx
);
606 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
611 case GL_TEXTURE_MIN_FILTER
:
612 case GL_TEXTURE_MAG_FILTER
:
613 case GL_TEXTURE_WRAP_S
:
614 case GL_TEXTURE_WRAP_T
:
615 case GL_TEXTURE_WRAP_R
:
616 case GL_TEXTURE_BASE_LEVEL
:
617 case GL_TEXTURE_MAX_LEVEL
:
618 case GL_GENERATE_MIPMAP_SGIS
:
619 case GL_TEXTURE_COMPARE_MODE_ARB
:
620 case GL_TEXTURE_COMPARE_FUNC_ARB
:
621 case GL_DEPTH_TEXTURE_MODE_ARB
:
622 case GL_TEXTURE_SRGB_DECODE_EXT
:
624 /* convert float param to int */
626 p
[0] = (GLint
) params
[0];
627 p
[1] = p
[2] = p
[3] = 0;
628 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
632 #if FEATURE_OES_draw_texture
633 case GL_TEXTURE_CROP_RECT_OES
:
635 /* convert float params to int */
637 iparams
[0] = (GLint
) params
[0];
638 iparams
[1] = (GLint
) params
[1];
639 iparams
[2] = (GLint
) params
[2];
640 iparams
[3] = (GLint
) params
[3];
641 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
647 /* this will generate an error if pname is illegal */
648 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
651 if (ctx
->Driver
.TexParameter
&& need_update
) {
652 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
658 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
660 GLboolean need_update
;
661 struct gl_texture_object
*texObj
;
662 GET_CURRENT_CONTEXT(ctx
);
663 ASSERT_OUTSIDE_BEGIN_END(ctx
);
665 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
670 case GL_TEXTURE_MIN_LOD
:
671 case GL_TEXTURE_MAX_LOD
:
672 case GL_TEXTURE_PRIORITY
:
673 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
674 case GL_TEXTURE_LOD_BIAS
:
675 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
678 fparam
[0] = (GLfloat
) param
;
679 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
680 /* convert int param to float */
681 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
685 /* this will generate an error if pname is illegal */
689 iparam
[1] = iparam
[2] = iparam
[3] = 0;
690 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
694 if (ctx
->Driver
.TexParameter
&& need_update
) {
695 GLfloat fparam
= (GLfloat
) param
;
696 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
702 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
704 GLboolean need_update
;
705 struct gl_texture_object
*texObj
;
706 GET_CURRENT_CONTEXT(ctx
);
707 ASSERT_OUTSIDE_BEGIN_END(ctx
);
709 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
714 case GL_TEXTURE_BORDER_COLOR
:
716 /* convert int params to float */
718 fparams
[0] = INT_TO_FLOAT(params
[0]);
719 fparams
[1] = INT_TO_FLOAT(params
[1]);
720 fparams
[2] = INT_TO_FLOAT(params
[2]);
721 fparams
[3] = INT_TO_FLOAT(params
[3]);
722 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
725 case GL_TEXTURE_MIN_LOD
:
726 case GL_TEXTURE_MAX_LOD
:
727 case GL_TEXTURE_PRIORITY
:
728 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
729 case GL_TEXTURE_LOD_BIAS
:
730 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
732 /* convert int param to float */
734 fparams
[0] = (GLfloat
) params
[0];
735 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
736 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
740 /* this will generate an error if pname is illegal */
741 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
744 if (ctx
->Driver
.TexParameter
&& need_update
) {
746 fparams
[0] = INT_TO_FLOAT(params
[0]);
747 if (pname
== GL_TEXTURE_BORDER_COLOR
||
748 pname
== GL_TEXTURE_CROP_RECT_OES
) {
749 fparams
[1] = INT_TO_FLOAT(params
[1]);
750 fparams
[2] = INT_TO_FLOAT(params
[2]);
751 fparams
[3] = INT_TO_FLOAT(params
[3]);
753 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
759 * Set tex parameter to integer value(s). Primarily intended to set
760 * integer-valued texture border color (for integer-valued textures).
764 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
766 struct gl_texture_object
*texObj
;
767 GET_CURRENT_CONTEXT(ctx
);
768 ASSERT_OUTSIDE_BEGIN_END(ctx
);
770 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
775 case GL_TEXTURE_BORDER_COLOR
:
776 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
777 /* set the integer-valued border color */
778 COPY_4V(texObj
->BorderColor
.i
, params
);
781 _mesa_TexParameteriv(target
, pname
, params
);
784 /* XXX no driver hook for TexParameterIiv() yet */
789 * Set tex parameter to unsigned integer value(s). Primarily intended to set
790 * uint-valued texture border color (for integer-valued textures).
794 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
796 struct gl_texture_object
*texObj
;
797 GET_CURRENT_CONTEXT(ctx
);
798 ASSERT_OUTSIDE_BEGIN_END(ctx
);
800 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
805 case GL_TEXTURE_BORDER_COLOR
:
806 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
807 /* set the unsigned integer-valued border color */
808 COPY_4V(texObj
->BorderColor
.ui
, params
);
811 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
814 /* XXX no driver hook for TexParameterIuiv() yet */
821 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
822 GLenum pname
, GLfloat
*params
)
825 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
826 *params
= (GLfloat
) iparam
;
831 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
832 GLenum pname
, GLint
*params
)
834 const struct gl_texture_unit
*texUnit
;
835 struct gl_texture_object
*texObj
;
836 const struct gl_texture_image
*img
= NULL
;
840 GET_CURRENT_CONTEXT(ctx
);
841 ASSERT_OUTSIDE_BEGIN_END(ctx
);
843 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
845 "glGetTexLevelParameteriv(current unit)");
849 texUnit
= _mesa_get_current_tex_unit(ctx
);
851 /* this will catch bad target values */
852 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
853 if (maxLevels
== 0) {
854 _mesa_error(ctx
, GL_INVALID_ENUM
,
855 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
859 if (level
< 0 || level
>= maxLevels
) {
860 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
864 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
865 _mesa_lock_texture(ctx
, texObj
);
867 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
868 if (!img
|| !img
->TexFormat
) {
869 /* undefined texture image */
870 if (pname
== GL_TEXTURE_COMPONENTS
)
877 texFormat
= img
->TexFormat
;
879 isProxy
= _mesa_is_proxy_texture(target
);
882 case GL_TEXTURE_WIDTH
:
883 *params
= img
->Width
;
885 case GL_TEXTURE_HEIGHT
:
886 *params
= img
->Height
;
888 case GL_TEXTURE_DEPTH
:
889 *params
= img
->Depth
;
891 case GL_TEXTURE_INTERNAL_FORMAT
:
892 if (_mesa_is_format_compressed(img
->TexFormat
)) {
893 /* need to return the actual compressed format */
894 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
897 /* return the user's requested internal format */
898 *params
= img
->InternalFormat
;
901 case GL_TEXTURE_BORDER
:
902 *params
= img
->Border
;
904 case GL_TEXTURE_RED_SIZE
:
905 if (img
->_BaseFormat
== GL_RED
) {
906 *params
= _mesa_get_format_bits(texFormat
, pname
);
910 case GL_TEXTURE_GREEN_SIZE
:
911 if (img
->_BaseFormat
== GL_RG
) {
912 *params
= _mesa_get_format_bits(texFormat
, pname
);
916 case GL_TEXTURE_BLUE_SIZE
:
917 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
918 *params
= _mesa_get_format_bits(texFormat
, pname
);
922 case GL_TEXTURE_ALPHA_SIZE
:
923 if (img
->_BaseFormat
== GL_ALPHA
||
924 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
925 img
->_BaseFormat
== GL_RGBA
)
926 *params
= _mesa_get_format_bits(texFormat
, pname
);
930 case GL_TEXTURE_INTENSITY_SIZE
:
931 if (img
->_BaseFormat
!= GL_INTENSITY
)
934 *params
= _mesa_get_format_bits(texFormat
, pname
);
936 /* intensity probably stored as rgb texture */
937 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
938 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
942 case GL_TEXTURE_LUMINANCE_SIZE
:
943 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
944 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
947 *params
= _mesa_get_format_bits(texFormat
, pname
);
949 /* luminance probably stored as rgb texture */
950 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
951 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
955 case GL_TEXTURE_INDEX_SIZE_EXT
:
956 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
957 *params
= _mesa_get_format_bits(texFormat
, pname
);
961 case GL_TEXTURE_DEPTH_SIZE_ARB
:
962 if (ctx
->Extensions
.ARB_depth_texture
)
963 *params
= _mesa_get_format_bits(texFormat
, pname
);
965 _mesa_error(ctx
, GL_INVALID_ENUM
,
966 "glGetTexLevelParameter[if]v(pname)");
968 case GL_TEXTURE_STENCIL_SIZE_EXT
:
969 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
970 ctx
->Extensions
.ARB_framebuffer_object
) {
971 *params
= _mesa_get_format_bits(texFormat
, pname
);
974 _mesa_error(ctx
, GL_INVALID_ENUM
,
975 "glGetTexLevelParameter[if]v(pname)");
978 case GL_TEXTURE_SHARED_SIZE
:
979 if (ctx
->VersionMajor
>= 3) {
980 /* XXX return number of exponent bits for shared exponent texture
981 * formats, like GL_RGB9_E5.
986 _mesa_error(ctx
, GL_INVALID_ENUM
,
987 "glGetTexLevelParameter[if]v(pname)");
991 /* GL_ARB_texture_compression */
992 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
993 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
994 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
995 img
->Height
, img
->Depth
);
998 _mesa_error(ctx
, GL_INVALID_OPERATION
,
999 "glGetTexLevelParameter[if]v(pname)");
1002 case GL_TEXTURE_COMPRESSED
:
1003 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
1006 /* GL_ARB_texture_float */
1007 case GL_TEXTURE_RED_TYPE_ARB
:
1008 if (ctx
->Extensions
.ARB_texture_float
) {
1009 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
1010 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1013 _mesa_error(ctx
, GL_INVALID_ENUM
,
1014 "glGetTexLevelParameter[if]v(pname)");
1017 case GL_TEXTURE_GREEN_TYPE_ARB
:
1018 if (ctx
->Extensions
.ARB_texture_float
) {
1019 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1020 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1023 _mesa_error(ctx
, GL_INVALID_ENUM
,
1024 "glGetTexLevelParameter[if]v(pname)");
1027 case GL_TEXTURE_BLUE_TYPE_ARB
:
1028 if (ctx
->Extensions
.ARB_texture_float
) {
1029 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1030 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1033 _mesa_error(ctx
, GL_INVALID_ENUM
,
1034 "glGetTexLevelParameter[if]v(pname)");
1037 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1038 if (ctx
->Extensions
.ARB_texture_float
) {
1039 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1040 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1043 _mesa_error(ctx
, GL_INVALID_ENUM
,
1044 "glGetTexLevelParameter[if]v(pname)");
1047 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1048 if (ctx
->Extensions
.ARB_texture_float
) {
1049 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1050 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1053 _mesa_error(ctx
, GL_INVALID_ENUM
,
1054 "glGetTexLevelParameter[if]v(pname)");
1057 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1058 if (ctx
->Extensions
.ARB_texture_float
) {
1059 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1060 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1063 _mesa_error(ctx
, GL_INVALID_ENUM
,
1064 "glGetTexLevelParameter[if]v(pname)");
1067 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1068 if (ctx
->Extensions
.ARB_texture_float
) {
1069 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1070 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1073 _mesa_error(ctx
, GL_INVALID_ENUM
,
1074 "glGetTexLevelParameter[if]v(pname)");
1079 _mesa_error(ctx
, GL_INVALID_ENUM
,
1080 "glGetTexLevelParameter[if]v(pname)");
1084 _mesa_unlock_texture(ctx
, texObj
);
1090 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1092 struct gl_texture_object
*obj
;
1093 GLboolean error
= GL_FALSE
;
1094 GET_CURRENT_CONTEXT(ctx
);
1095 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1097 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1101 _mesa_lock_texture(ctx
, obj
);
1103 case GL_TEXTURE_MAG_FILTER
:
1104 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1106 case GL_TEXTURE_MIN_FILTER
:
1107 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1109 case GL_TEXTURE_WRAP_S
:
1110 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1112 case GL_TEXTURE_WRAP_T
:
1113 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1115 case GL_TEXTURE_WRAP_R
:
1116 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1118 case GL_TEXTURE_BORDER_COLOR
:
1119 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1120 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1121 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1122 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1124 case GL_TEXTURE_RESIDENT
:
1127 if (ctx
->Driver
.IsTextureResident
)
1128 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1131 *params
= ENUM_TO_FLOAT(resident
);
1134 case GL_TEXTURE_PRIORITY
:
1135 *params
= obj
->Priority
;
1137 case GL_TEXTURE_MIN_LOD
:
1138 *params
= obj
->MinLod
;
1140 case GL_TEXTURE_MAX_LOD
:
1141 *params
= obj
->MaxLod
;
1143 case GL_TEXTURE_BASE_LEVEL
:
1144 *params
= (GLfloat
) obj
->BaseLevel
;
1146 case GL_TEXTURE_MAX_LEVEL
:
1147 *params
= (GLfloat
) obj
->MaxLevel
;
1149 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1150 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1151 *params
= obj
->MaxAnisotropy
;
1156 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1157 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1158 *params
= obj
->CompareFailValue
;
1163 case GL_GENERATE_MIPMAP_SGIS
:
1164 *params
= (GLfloat
) obj
->GenerateMipmap
;
1166 case GL_TEXTURE_COMPARE_MODE_ARB
:
1167 if (ctx
->Extensions
.ARB_shadow
) {
1168 *params
= (GLfloat
) obj
->CompareMode
;
1173 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1174 if (ctx
->Extensions
.ARB_shadow
) {
1175 *params
= (GLfloat
) obj
->CompareFunc
;
1180 case GL_DEPTH_TEXTURE_MODE_ARB
:
1181 if (ctx
->Extensions
.ARB_depth_texture
) {
1182 *params
= (GLfloat
) obj
->DepthMode
;
1187 case GL_TEXTURE_LOD_BIAS
:
1188 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1189 *params
= obj
->LodBias
;
1194 #if FEATURE_OES_draw_texture
1195 case GL_TEXTURE_CROP_RECT_OES
:
1196 params
[0] = obj
->CropRect
[0];
1197 params
[1] = obj
->CropRect
[1];
1198 params
[2] = obj
->CropRect
[2];
1199 params
[3] = obj
->CropRect
[3];
1203 case GL_TEXTURE_SWIZZLE_R_EXT
:
1204 case GL_TEXTURE_SWIZZLE_G_EXT
:
1205 case GL_TEXTURE_SWIZZLE_B_EXT
:
1206 case GL_TEXTURE_SWIZZLE_A_EXT
:
1207 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1208 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1209 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1216 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1217 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1219 for (comp
= 0; comp
< 4; comp
++) {
1220 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1234 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1237 _mesa_unlock_texture(ctx
, obj
);
1242 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1244 struct gl_texture_object
*obj
;
1245 GLboolean error
= GL_FALSE
;
1246 GET_CURRENT_CONTEXT(ctx
);
1247 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1249 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1253 _mesa_lock_texture(ctx
, obj
);
1255 case GL_TEXTURE_MAG_FILTER
:
1256 *params
= (GLint
) obj
->MagFilter
;
1258 case GL_TEXTURE_MIN_FILTER
:
1259 *params
= (GLint
) obj
->MinFilter
;
1261 case GL_TEXTURE_WRAP_S
:
1262 *params
= (GLint
) obj
->WrapS
;
1264 case GL_TEXTURE_WRAP_T
:
1265 *params
= (GLint
) obj
->WrapT
;
1267 case GL_TEXTURE_WRAP_R
:
1268 *params
= (GLint
) obj
->WrapR
;
1270 case GL_TEXTURE_BORDER_COLOR
:
1273 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1274 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1275 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1276 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1277 params
[0] = FLOAT_TO_INT(b
[0]);
1278 params
[1] = FLOAT_TO_INT(b
[1]);
1279 params
[2] = FLOAT_TO_INT(b
[2]);
1280 params
[3] = FLOAT_TO_INT(b
[3]);
1283 case GL_TEXTURE_RESIDENT
:
1286 if (ctx
->Driver
.IsTextureResident
)
1287 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1290 *params
= (GLint
) resident
;
1293 case GL_TEXTURE_PRIORITY
:
1294 *params
= FLOAT_TO_INT(obj
->Priority
);
1296 case GL_TEXTURE_MIN_LOD
:
1297 *params
= (GLint
) obj
->MinLod
;
1299 case GL_TEXTURE_MAX_LOD
:
1300 *params
= (GLint
) obj
->MaxLod
;
1302 case GL_TEXTURE_BASE_LEVEL
:
1303 *params
= obj
->BaseLevel
;
1305 case GL_TEXTURE_MAX_LEVEL
:
1306 *params
= obj
->MaxLevel
;
1308 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1309 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1310 *params
= (GLint
) obj
->MaxAnisotropy
;
1316 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1317 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1318 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1324 case GL_GENERATE_MIPMAP_SGIS
:
1325 *params
= (GLint
) obj
->GenerateMipmap
;
1327 case GL_TEXTURE_COMPARE_MODE_ARB
:
1328 if (ctx
->Extensions
.ARB_shadow
) {
1329 *params
= (GLint
) obj
->CompareMode
;
1335 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1336 if (ctx
->Extensions
.ARB_shadow
) {
1337 *params
= (GLint
) obj
->CompareFunc
;
1343 case GL_DEPTH_TEXTURE_MODE_ARB
:
1344 if (ctx
->Extensions
.ARB_depth_texture
) {
1345 *params
= (GLint
) obj
->DepthMode
;
1351 case GL_TEXTURE_LOD_BIAS
:
1352 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1353 *params
= (GLint
) obj
->LodBias
;
1359 #if FEATURE_OES_draw_texture
1360 case GL_TEXTURE_CROP_RECT_OES
:
1361 params
[0] = obj
->CropRect
[0];
1362 params
[1] = obj
->CropRect
[1];
1363 params
[2] = obj
->CropRect
[2];
1364 params
[3] = obj
->CropRect
[3];
1367 case GL_TEXTURE_SWIZZLE_R_EXT
:
1368 case GL_TEXTURE_SWIZZLE_G_EXT
:
1369 case GL_TEXTURE_SWIZZLE_B_EXT
:
1370 case GL_TEXTURE_SWIZZLE_A_EXT
:
1371 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1372 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1373 *params
= obj
->Swizzle
[comp
];
1380 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1381 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1382 COPY_4V(params
, obj
->Swizzle
);
1390 ; /* silence warnings */
1394 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1397 _mesa_unlock_texture(ctx
, obj
);
1401 /** New in GL 3.0 */
1403 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1405 struct gl_texture_object
*texObj
;
1406 GET_CURRENT_CONTEXT(ctx
);
1407 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1409 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1412 case GL_TEXTURE_BORDER_COLOR
:
1413 COPY_4V(params
, texObj
->BorderColor
.i
);
1416 _mesa_GetTexParameteriv(target
, pname
, params
);
1421 /** New in GL 3.0 */
1423 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1425 struct gl_texture_object
*texObj
;
1426 GET_CURRENT_CONTEXT(ctx
);
1427 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1429 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1432 case GL_TEXTURE_BORDER_COLOR
:
1433 COPY_4V(params
, texObj
->BorderColor
.i
);
1438 _mesa_GetTexParameteriv(target
, pname
, ip
);
1440 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1441 pname
== GL_TEXTURE_CROP_RECT_OES
) {