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
);
866 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
867 if (!img
|| !img
->TexFormat
) {
868 /* undefined texture image */
869 if (pname
== GL_TEXTURE_COMPONENTS
)
876 texFormat
= img
->TexFormat
;
878 isProxy
= _mesa_is_proxy_texture(target
);
881 case GL_TEXTURE_WIDTH
:
882 *params
= img
->Width
;
884 case GL_TEXTURE_HEIGHT
:
885 *params
= img
->Height
;
887 case GL_TEXTURE_DEPTH
:
888 *params
= img
->Depth
;
890 case GL_TEXTURE_INTERNAL_FORMAT
:
891 if (_mesa_is_format_compressed(texFormat
)) {
892 /* need to return the actual compressed format */
893 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
896 /* return the user's requested internal format */
897 *params
= img
->InternalFormat
;
900 case GL_TEXTURE_BORDER
:
901 *params
= img
->Border
;
903 case GL_TEXTURE_RED_SIZE
:
904 if (img
->_BaseFormat
== GL_RED
) {
905 *params
= _mesa_get_format_bits(texFormat
, pname
);
909 case GL_TEXTURE_GREEN_SIZE
:
910 if (img
->_BaseFormat
== GL_RG
) {
911 *params
= _mesa_get_format_bits(texFormat
, pname
);
915 case GL_TEXTURE_BLUE_SIZE
:
916 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
917 *params
= _mesa_get_format_bits(texFormat
, pname
);
921 case GL_TEXTURE_ALPHA_SIZE
:
922 if (img
->_BaseFormat
== GL_ALPHA
||
923 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
924 img
->_BaseFormat
== GL_RGBA
)
925 *params
= _mesa_get_format_bits(texFormat
, pname
);
929 case GL_TEXTURE_INTENSITY_SIZE
:
930 if (img
->_BaseFormat
!= GL_INTENSITY
)
933 *params
= _mesa_get_format_bits(texFormat
, pname
);
935 /* intensity probably stored as rgb texture */
936 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
937 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
941 case GL_TEXTURE_LUMINANCE_SIZE
:
942 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
943 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
946 *params
= _mesa_get_format_bits(texFormat
, pname
);
948 /* luminance probably stored as rgb texture */
949 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
950 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
954 case GL_TEXTURE_INDEX_SIZE_EXT
:
955 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
956 *params
= _mesa_get_format_bits(texFormat
, pname
);
960 case GL_TEXTURE_DEPTH_SIZE_ARB
:
961 if (ctx
->Extensions
.ARB_depth_texture
)
962 *params
= _mesa_get_format_bits(texFormat
, pname
);
966 case GL_TEXTURE_STENCIL_SIZE_EXT
:
967 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
968 ctx
->Extensions
.ARB_framebuffer_object
) {
969 *params
= _mesa_get_format_bits(texFormat
, pname
);
975 case GL_TEXTURE_SHARED_SIZE
:
976 if (ctx
->VersionMajor
>= 3) {
977 /* XXX return number of exponent bits for shared exponent texture
978 * formats, like GL_RGB9_E5.
987 /* GL_ARB_texture_compression */
988 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
989 if (_mesa_is_format_compressed(texFormat
) && !isProxy
) {
990 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
991 img
->Height
, img
->Depth
);
994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
995 "glGetTexLevelParameter[if]v(pname)");
998 case GL_TEXTURE_COMPRESSED
:
999 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1002 /* GL_ARB_texture_float */
1003 case GL_TEXTURE_RED_TYPE_ARB
:
1004 if (ctx
->Extensions
.ARB_texture_float
) {
1005 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
1006 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1012 case GL_TEXTURE_GREEN_TYPE_ARB
:
1013 if (ctx
->Extensions
.ARB_texture_float
) {
1014 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1015 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1021 case GL_TEXTURE_BLUE_TYPE_ARB
:
1022 if (ctx
->Extensions
.ARB_texture_float
) {
1023 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1024 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1030 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1031 if (ctx
->Extensions
.ARB_texture_float
) {
1032 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1033 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1039 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1040 if (ctx
->Extensions
.ARB_texture_float
) {
1041 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1042 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1048 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1049 if (ctx
->Extensions
.ARB_texture_float
) {
1050 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1051 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1057 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1058 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
;
1071 /* no error if we get here */
1075 _mesa_error(ctx
, GL_INVALID_ENUM
,
1076 "glGetTexLevelParameter[if]v(pname=%s)",
1077 _mesa_lookup_enum_by_nr(pname
));
1083 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1085 struct gl_texture_object
*obj
;
1086 GLboolean error
= GL_FALSE
;
1087 GET_CURRENT_CONTEXT(ctx
);
1088 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1090 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1094 _mesa_lock_texture(ctx
, obj
);
1096 case GL_TEXTURE_MAG_FILTER
:
1097 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1099 case GL_TEXTURE_MIN_FILTER
:
1100 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1102 case GL_TEXTURE_WRAP_S
:
1103 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1105 case GL_TEXTURE_WRAP_T
:
1106 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1108 case GL_TEXTURE_WRAP_R
:
1109 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1111 case GL_TEXTURE_BORDER_COLOR
:
1112 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1113 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1114 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1115 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1117 case GL_TEXTURE_RESIDENT
:
1120 if (ctx
->Driver
.IsTextureResident
)
1121 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1124 *params
= ENUM_TO_FLOAT(resident
);
1127 case GL_TEXTURE_PRIORITY
:
1128 *params
= obj
->Priority
;
1130 case GL_TEXTURE_MIN_LOD
:
1131 *params
= obj
->MinLod
;
1133 case GL_TEXTURE_MAX_LOD
:
1134 *params
= obj
->MaxLod
;
1136 case GL_TEXTURE_BASE_LEVEL
:
1137 *params
= (GLfloat
) obj
->BaseLevel
;
1139 case GL_TEXTURE_MAX_LEVEL
:
1140 *params
= (GLfloat
) obj
->MaxLevel
;
1142 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1143 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1144 *params
= obj
->MaxAnisotropy
;
1149 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1150 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1151 *params
= obj
->CompareFailValue
;
1156 case GL_GENERATE_MIPMAP_SGIS
:
1157 *params
= (GLfloat
) obj
->GenerateMipmap
;
1159 case GL_TEXTURE_COMPARE_MODE_ARB
:
1160 if (ctx
->Extensions
.ARB_shadow
) {
1161 *params
= (GLfloat
) obj
->CompareMode
;
1166 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1167 if (ctx
->Extensions
.ARB_shadow
) {
1168 *params
= (GLfloat
) obj
->CompareFunc
;
1173 case GL_DEPTH_TEXTURE_MODE_ARB
:
1174 if (ctx
->Extensions
.ARB_depth_texture
) {
1175 *params
= (GLfloat
) obj
->DepthMode
;
1180 case GL_TEXTURE_LOD_BIAS
:
1181 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1182 *params
= obj
->LodBias
;
1187 #if FEATURE_OES_draw_texture
1188 case GL_TEXTURE_CROP_RECT_OES
:
1189 params
[0] = obj
->CropRect
[0];
1190 params
[1] = obj
->CropRect
[1];
1191 params
[2] = obj
->CropRect
[2];
1192 params
[3] = obj
->CropRect
[3];
1196 case GL_TEXTURE_SWIZZLE_R_EXT
:
1197 case GL_TEXTURE_SWIZZLE_G_EXT
:
1198 case GL_TEXTURE_SWIZZLE_B_EXT
:
1199 case GL_TEXTURE_SWIZZLE_A_EXT
:
1200 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1201 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1202 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1209 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1210 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1212 for (comp
= 0; comp
< 4; comp
++) {
1213 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1227 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1230 _mesa_unlock_texture(ctx
, obj
);
1235 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1237 struct gl_texture_object
*obj
;
1238 GLboolean error
= GL_FALSE
;
1239 GET_CURRENT_CONTEXT(ctx
);
1240 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1242 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1246 _mesa_lock_texture(ctx
, obj
);
1248 case GL_TEXTURE_MAG_FILTER
:
1249 *params
= (GLint
) obj
->MagFilter
;
1251 case GL_TEXTURE_MIN_FILTER
:
1252 *params
= (GLint
) obj
->MinFilter
;
1254 case GL_TEXTURE_WRAP_S
:
1255 *params
= (GLint
) obj
->WrapS
;
1257 case GL_TEXTURE_WRAP_T
:
1258 *params
= (GLint
) obj
->WrapT
;
1260 case GL_TEXTURE_WRAP_R
:
1261 *params
= (GLint
) obj
->WrapR
;
1263 case GL_TEXTURE_BORDER_COLOR
:
1266 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1267 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1268 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1269 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1270 params
[0] = FLOAT_TO_INT(b
[0]);
1271 params
[1] = FLOAT_TO_INT(b
[1]);
1272 params
[2] = FLOAT_TO_INT(b
[2]);
1273 params
[3] = FLOAT_TO_INT(b
[3]);
1276 case GL_TEXTURE_RESIDENT
:
1279 if (ctx
->Driver
.IsTextureResident
)
1280 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1283 *params
= (GLint
) resident
;
1286 case GL_TEXTURE_PRIORITY
:
1287 *params
= FLOAT_TO_INT(obj
->Priority
);
1289 case GL_TEXTURE_MIN_LOD
:
1290 *params
= (GLint
) obj
->MinLod
;
1292 case GL_TEXTURE_MAX_LOD
:
1293 *params
= (GLint
) obj
->MaxLod
;
1295 case GL_TEXTURE_BASE_LEVEL
:
1296 *params
= obj
->BaseLevel
;
1298 case GL_TEXTURE_MAX_LEVEL
:
1299 *params
= obj
->MaxLevel
;
1301 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1302 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1303 *params
= (GLint
) obj
->MaxAnisotropy
;
1309 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1310 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1311 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1317 case GL_GENERATE_MIPMAP_SGIS
:
1318 *params
= (GLint
) obj
->GenerateMipmap
;
1320 case GL_TEXTURE_COMPARE_MODE_ARB
:
1321 if (ctx
->Extensions
.ARB_shadow
) {
1322 *params
= (GLint
) obj
->CompareMode
;
1328 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1329 if (ctx
->Extensions
.ARB_shadow
) {
1330 *params
= (GLint
) obj
->CompareFunc
;
1336 case GL_DEPTH_TEXTURE_MODE_ARB
:
1337 if (ctx
->Extensions
.ARB_depth_texture
) {
1338 *params
= (GLint
) obj
->DepthMode
;
1344 case GL_TEXTURE_LOD_BIAS
:
1345 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1346 *params
= (GLint
) obj
->LodBias
;
1352 #if FEATURE_OES_draw_texture
1353 case GL_TEXTURE_CROP_RECT_OES
:
1354 params
[0] = obj
->CropRect
[0];
1355 params
[1] = obj
->CropRect
[1];
1356 params
[2] = obj
->CropRect
[2];
1357 params
[3] = obj
->CropRect
[3];
1360 case GL_TEXTURE_SWIZZLE_R_EXT
:
1361 case GL_TEXTURE_SWIZZLE_G_EXT
:
1362 case GL_TEXTURE_SWIZZLE_B_EXT
:
1363 case GL_TEXTURE_SWIZZLE_A_EXT
:
1364 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1365 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1366 *params
= obj
->Swizzle
[comp
];
1373 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1374 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1375 COPY_4V(params
, obj
->Swizzle
);
1383 ; /* silence warnings */
1387 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1390 _mesa_unlock_texture(ctx
, obj
);
1394 /** New in GL 3.0 */
1396 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1398 struct gl_texture_object
*texObj
;
1399 GET_CURRENT_CONTEXT(ctx
);
1400 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1402 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1405 case GL_TEXTURE_BORDER_COLOR
:
1406 COPY_4V(params
, texObj
->BorderColor
.i
);
1409 _mesa_GetTexParameteriv(target
, pname
, params
);
1414 /** New in GL 3.0 */
1416 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1418 struct gl_texture_object
*texObj
;
1419 GET_CURRENT_CONTEXT(ctx
);
1420 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1422 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1425 case GL_TEXTURE_BORDER_COLOR
:
1426 COPY_4V(params
, texObj
->BorderColor
.i
);
1431 _mesa_GetTexParameteriv(target
, pname
, ip
);
1433 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1434 pname
== GL_TEXTURE_CROP_RECT_OES
) {