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/formats.h"
37 #include "main/macros.h"
38 #include "main/mfeatures.h"
39 #include "main/mtypes.h"
40 #include "main/texcompress.h"
41 #include "main/texparam.h"
42 #include "main/teximage.h"
43 #include "main/texstate.h"
44 #include "main/texfetch.h"
45 #include "program/prog_instruction.h"
49 * Check if a coordinate wrap mode is supported for the texture target.
50 * \return GL_TRUE if legal, GL_FALSE otherwise
53 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
55 const struct gl_extensions
* const e
= & ctx
->Extensions
;
57 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
58 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
59 /* any texture target */
62 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
64 (wrap
== GL_MIRRORED_REPEAT
&&
65 e
->ARB_texture_mirrored_repeat
) ||
66 (wrap
== GL_MIRROR_CLAMP_EXT
&&
67 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
68 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
69 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
70 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
71 (e
->EXT_texture_mirror_clamp
)))) {
72 /* non-rectangle texture */
76 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
82 * Get current texture object for given target.
83 * Return NULL if any error (and record the error).
84 * Note that this is different from _mesa_select_tex_object() in that proxy
85 * targets are not accepted.
86 * Only the glGetTexLevelParameter() functions accept proxy targets.
88 static struct gl_texture_object
*
89 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
91 struct gl_texture_unit
*texUnit
;
93 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
94 _mesa_error(ctx
, GL_INVALID_OPERATION
,
95 "gl%sTexParameter(current unit)", get
? "Get" : "");
99 texUnit
= _mesa_get_current_tex_unit(ctx
);
103 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
105 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
107 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
108 case GL_TEXTURE_CUBE_MAP
:
109 if (ctx
->Extensions
.ARB_texture_cube_map
) {
110 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
113 case GL_TEXTURE_RECTANGLE_NV
:
114 if (ctx
->Extensions
.NV_texture_rectangle
) {
115 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
118 case GL_TEXTURE_1D_ARRAY_EXT
:
119 if (ctx
->Extensions
.MESA_texture_array
) {
120 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
123 case GL_TEXTURE_2D_ARRAY_EXT
:
124 if (ctx
->Extensions
.MESA_texture_array
) {
125 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
132 _mesa_error(ctx
, GL_INVALID_ENUM
,
133 "gl%sTexParameter(target)", get
? "Get" : "");
139 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
140 * \return -1 if error.
143 comp_to_swizzle(GLenum comp
)
165 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
168 ASSERT(swz
<= SWIZZLE_NIL
);
170 GLuint mask
= 0x7 << (3 * comp
);
171 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
178 * This is called just prior to changing any texture object state.
179 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
180 * state flag and then mark the texture object as 'incomplete' so that any
181 * per-texture derived state gets recomputed.
184 flush(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
186 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
187 texObj
->_Complete
= GL_FALSE
;
192 * Set an integer-valued texture parameter
193 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
196 set_tex_parameteri(struct gl_context
*ctx
,
197 struct gl_texture_object
*texObj
,
198 GLenum pname
, const GLint
*params
)
201 case GL_TEXTURE_MIN_FILTER
:
202 if (texObj
->MinFilter
== params
[0])
208 texObj
->MinFilter
= params
[0];
210 case GL_NEAREST_MIPMAP_NEAREST
:
211 case GL_LINEAR_MIPMAP_NEAREST
:
212 case GL_NEAREST_MIPMAP_LINEAR
:
213 case GL_LINEAR_MIPMAP_LINEAR
:
214 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
216 texObj
->MinFilter
= params
[0];
221 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
226 case GL_TEXTURE_MAG_FILTER
:
227 if (texObj
->MagFilter
== params
[0])
233 texObj
->MagFilter
= params
[0];
236 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
241 case GL_TEXTURE_WRAP_S
:
242 if (texObj
->WrapS
== params
[0])
244 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
246 texObj
->WrapS
= params
[0];
251 case GL_TEXTURE_WRAP_T
:
252 if (texObj
->WrapT
== params
[0])
254 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
256 texObj
->WrapT
= params
[0];
261 case GL_TEXTURE_WRAP_R
:
262 if (texObj
->WrapR
== params
[0])
264 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
266 texObj
->WrapR
= params
[0];
271 case GL_TEXTURE_BASE_LEVEL
:
272 if (texObj
->BaseLevel
== params
[0])
275 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
276 _mesa_error(ctx
, GL_INVALID_VALUE
,
277 "glTexParameter(param=%d)", params
[0]);
281 texObj
->BaseLevel
= params
[0];
284 case GL_TEXTURE_MAX_LEVEL
:
285 if (texObj
->MaxLevel
== params
[0])
287 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
289 "glTexParameter(param=%d)", params
[0]);
293 texObj
->MaxLevel
= params
[0];
296 case GL_GENERATE_MIPMAP_SGIS
:
297 if (texObj
->GenerateMipmap
!= params
[0]) {
299 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
304 case GL_TEXTURE_COMPARE_MODE_ARB
:
305 if (ctx
->Extensions
.ARB_shadow
&&
306 (params
[0] == GL_NONE
||
307 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
308 if (texObj
->CompareMode
!= params
[0]) {
310 texObj
->CompareMode
= params
[0];
316 _mesa_error(ctx
, GL_INVALID_ENUM
,
317 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
321 case GL_TEXTURE_COMPARE_FUNC_ARB
:
322 if (ctx
->Extensions
.ARB_shadow
) {
323 if (texObj
->CompareFunc
== params
[0])
329 texObj
->CompareFunc
= params
[0];
337 if (ctx
->Extensions
.EXT_shadow_funcs
) {
339 texObj
->CompareFunc
= params
[0];
344 _mesa_error(ctx
, GL_INVALID_ENUM
,
345 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
349 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
353 case GL_DEPTH_TEXTURE_MODE_ARB
:
354 if (ctx
->Extensions
.ARB_depth_texture
&&
355 (params
[0] == GL_LUMINANCE
||
356 params
[0] == GL_INTENSITY
||
357 params
[0] == GL_ALPHA
||
358 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
))) {
359 if (texObj
->DepthMode
!= params
[0]) {
361 texObj
->DepthMode
= params
[0];
366 _mesa_error(ctx
, GL_INVALID_ENUM
,
367 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
371 #if FEATURE_OES_draw_texture
372 case GL_TEXTURE_CROP_RECT_OES
:
373 texObj
->CropRect
[0] = params
[0];
374 texObj
->CropRect
[1] = params
[1];
375 texObj
->CropRect
[2] = params
[2];
376 texObj
->CropRect
[3] = params
[3];
380 case GL_TEXTURE_SWIZZLE_R_EXT
:
381 case GL_TEXTURE_SWIZZLE_G_EXT
:
382 case GL_TEXTURE_SWIZZLE_B_EXT
:
383 case GL_TEXTURE_SWIZZLE_A_EXT
:
384 if (ctx
->Extensions
.EXT_texture_swizzle
) {
385 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
386 const GLint swz
= comp_to_swizzle(params
[0]);
388 _mesa_error(ctx
, GL_INVALID_OPERATION
,
389 "glTexParameter(swizzle 0x%x)", params
[0]);
395 texObj
->Swizzle
[comp
] = params
[0];
396 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
400 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
403 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
404 if (ctx
->Extensions
.EXT_texture_swizzle
) {
407 for (comp
= 0; comp
< 4; comp
++) {
408 const GLint swz
= comp_to_swizzle(params
[comp
]);
410 texObj
->Swizzle
[comp
] = params
[comp
];
411 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
415 "glTexParameter(swizzle 0x%x)", params
[comp
]);
421 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
423 case GL_TEXTURE_SRGB_DECODE_EXT
:
424 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
425 GLenum decode
= params
[0];
426 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
427 if (texObj
->sRGBDecode
!= decode
) {
429 texObj
->sRGBDecode
= decode
;
430 _mesa_update_fetch_functions(texObj
);
435 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
438 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
445 * Set a float-valued texture parameter
446 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
449 set_tex_parameterf(struct gl_context
*ctx
,
450 struct gl_texture_object
*texObj
,
451 GLenum pname
, const GLfloat
*params
)
454 case GL_TEXTURE_MIN_LOD
:
455 if (texObj
->MinLod
== params
[0])
458 texObj
->MinLod
= params
[0];
461 case GL_TEXTURE_MAX_LOD
:
462 if (texObj
->MaxLod
== params
[0])
465 texObj
->MaxLod
= params
[0];
468 case GL_TEXTURE_PRIORITY
:
470 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
473 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
474 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
475 if (texObj
->MaxAnisotropy
== params
[0])
477 if (params
[0] < 1.0) {
478 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
482 /* clamp to max, that's what NVIDIA does */
483 texObj
->MaxAnisotropy
= MIN2(params
[0],
484 ctx
->Const
.MaxTextureMaxAnisotropy
);
488 static GLuint count
= 0;
490 _mesa_error(ctx
, GL_INVALID_ENUM
,
491 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
495 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
496 if (ctx
->Extensions
.ARB_shadow_ambient
) {
497 if (texObj
->CompareFailValue
!= params
[0]) {
499 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
504 _mesa_error(ctx
, GL_INVALID_ENUM
,
505 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
509 case GL_TEXTURE_LOD_BIAS
:
510 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
511 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
512 if (texObj
->LodBias
!= params
[0]) {
514 texObj
->LodBias
= params
[0];
521 case GL_TEXTURE_BORDER_COLOR
:
523 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
524 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
525 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
526 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
530 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
537 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
539 GLboolean need_update
;
540 struct gl_texture_object
*texObj
;
541 GET_CURRENT_CONTEXT(ctx
);
542 ASSERT_OUTSIDE_BEGIN_END(ctx
);
544 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
549 case GL_TEXTURE_MIN_FILTER
:
550 case GL_TEXTURE_MAG_FILTER
:
551 case GL_TEXTURE_WRAP_S
:
552 case GL_TEXTURE_WRAP_T
:
553 case GL_TEXTURE_WRAP_R
:
554 case GL_TEXTURE_BASE_LEVEL
:
555 case GL_TEXTURE_MAX_LEVEL
:
556 case GL_GENERATE_MIPMAP_SGIS
:
557 case GL_TEXTURE_COMPARE_MODE_ARB
:
558 case GL_TEXTURE_COMPARE_FUNC_ARB
:
559 case GL_DEPTH_TEXTURE_MODE_ARB
:
560 case GL_TEXTURE_SRGB_DECODE_EXT
:
562 /* convert float param to int */
564 p
[0] = (GLint
) param
;
565 p
[1] = p
[2] = p
[3] = 0;
566 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
571 /* this will generate an error if pname is illegal */
574 p
[1] = p
[2] = p
[3] = 0.0F
;
575 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
579 if (ctx
->Driver
.TexParameter
&& need_update
) {
580 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
586 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
588 GLboolean need_update
;
589 struct gl_texture_object
*texObj
;
590 GET_CURRENT_CONTEXT(ctx
);
591 ASSERT_OUTSIDE_BEGIN_END(ctx
);
593 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
598 case GL_TEXTURE_MIN_FILTER
:
599 case GL_TEXTURE_MAG_FILTER
:
600 case GL_TEXTURE_WRAP_S
:
601 case GL_TEXTURE_WRAP_T
:
602 case GL_TEXTURE_WRAP_R
:
603 case GL_TEXTURE_BASE_LEVEL
:
604 case GL_TEXTURE_MAX_LEVEL
:
605 case GL_GENERATE_MIPMAP_SGIS
:
606 case GL_TEXTURE_COMPARE_MODE_ARB
:
607 case GL_TEXTURE_COMPARE_FUNC_ARB
:
608 case GL_DEPTH_TEXTURE_MODE_ARB
:
609 case GL_TEXTURE_SRGB_DECODE_EXT
:
611 /* convert float param to int */
613 p
[0] = (GLint
) params
[0];
614 p
[1] = p
[2] = p
[3] = 0;
615 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
619 #if FEATURE_OES_draw_texture
620 case GL_TEXTURE_CROP_RECT_OES
:
622 /* convert float params to int */
624 iparams
[0] = (GLint
) params
[0];
625 iparams
[1] = (GLint
) params
[1];
626 iparams
[2] = (GLint
) params
[2];
627 iparams
[3] = (GLint
) params
[3];
628 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
634 /* this will generate an error if pname is illegal */
635 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
638 if (ctx
->Driver
.TexParameter
&& need_update
) {
639 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
645 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
647 GLboolean need_update
;
648 struct gl_texture_object
*texObj
;
649 GET_CURRENT_CONTEXT(ctx
);
650 ASSERT_OUTSIDE_BEGIN_END(ctx
);
652 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
657 case GL_TEXTURE_MIN_LOD
:
658 case GL_TEXTURE_MAX_LOD
:
659 case GL_TEXTURE_PRIORITY
:
660 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
661 case GL_TEXTURE_LOD_BIAS
:
662 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
665 fparam
[0] = (GLfloat
) param
;
666 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
667 /* convert int param to float */
668 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
672 /* this will generate an error if pname is illegal */
676 iparam
[1] = iparam
[2] = iparam
[3] = 0;
677 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
681 if (ctx
->Driver
.TexParameter
&& need_update
) {
682 GLfloat fparam
= (GLfloat
) param
;
683 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
689 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
691 GLboolean need_update
;
692 struct gl_texture_object
*texObj
;
693 GET_CURRENT_CONTEXT(ctx
);
694 ASSERT_OUTSIDE_BEGIN_END(ctx
);
696 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
701 case GL_TEXTURE_BORDER_COLOR
:
703 /* convert int params to float */
705 fparams
[0] = INT_TO_FLOAT(params
[0]);
706 fparams
[1] = INT_TO_FLOAT(params
[1]);
707 fparams
[2] = INT_TO_FLOAT(params
[2]);
708 fparams
[3] = INT_TO_FLOAT(params
[3]);
709 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
712 case GL_TEXTURE_MIN_LOD
:
713 case GL_TEXTURE_MAX_LOD
:
714 case GL_TEXTURE_PRIORITY
:
715 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
716 case GL_TEXTURE_LOD_BIAS
:
717 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
719 /* convert int param to float */
721 fparams
[0] = (GLfloat
) params
[0];
722 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
723 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
727 /* this will generate an error if pname is illegal */
728 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
731 if (ctx
->Driver
.TexParameter
&& need_update
) {
733 fparams
[0] = INT_TO_FLOAT(params
[0]);
734 if (pname
== GL_TEXTURE_BORDER_COLOR
||
735 pname
== GL_TEXTURE_CROP_RECT_OES
) {
736 fparams
[1] = INT_TO_FLOAT(params
[1]);
737 fparams
[2] = INT_TO_FLOAT(params
[2]);
738 fparams
[3] = INT_TO_FLOAT(params
[3]);
740 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
746 * Set tex parameter to integer value(s). Primarily intended to set
747 * integer-valued texture border color (for integer-valued textures).
751 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
753 struct gl_texture_object
*texObj
;
754 GET_CURRENT_CONTEXT(ctx
);
755 ASSERT_OUTSIDE_BEGIN_END(ctx
);
757 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
762 case GL_TEXTURE_BORDER_COLOR
:
763 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
764 /* set the integer-valued border color */
765 COPY_4V(texObj
->BorderColor
.i
, params
);
768 _mesa_TexParameteriv(target
, pname
, params
);
771 /* XXX no driver hook for TexParameterIiv() yet */
776 * Set tex parameter to unsigned integer value(s). Primarily intended to set
777 * uint-valued texture border color (for integer-valued textures).
781 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
783 struct gl_texture_object
*texObj
;
784 GET_CURRENT_CONTEXT(ctx
);
785 ASSERT_OUTSIDE_BEGIN_END(ctx
);
787 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
792 case GL_TEXTURE_BORDER_COLOR
:
793 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
794 /* set the unsigned integer-valued border color */
795 COPY_4V(texObj
->BorderColor
.ui
, params
);
798 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
801 /* XXX no driver hook for TexParameterIuiv() yet */
808 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
809 GLenum pname
, GLfloat
*params
)
812 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
813 *params
= (GLfloat
) iparam
;
818 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
819 GLenum pname
, GLint
*params
)
821 const struct gl_texture_unit
*texUnit
;
822 struct gl_texture_object
*texObj
;
823 const struct gl_texture_image
*img
= NULL
;
827 GET_CURRENT_CONTEXT(ctx
);
828 ASSERT_OUTSIDE_BEGIN_END(ctx
);
830 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
832 "glGetTexLevelParameteriv(current unit)");
836 texUnit
= _mesa_get_current_tex_unit(ctx
);
838 /* this will catch bad target values */
839 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
840 if (maxLevels
== 0) {
841 _mesa_error(ctx
, GL_INVALID_ENUM
,
842 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
846 if (level
< 0 || level
>= maxLevels
) {
847 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
851 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
852 _mesa_lock_texture(ctx
, texObj
);
854 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
855 if (!img
|| !img
->TexFormat
) {
856 /* undefined texture image */
857 if (pname
== GL_TEXTURE_COMPONENTS
)
864 texFormat
= img
->TexFormat
;
866 isProxy
= _mesa_is_proxy_texture(target
);
869 case GL_TEXTURE_WIDTH
:
870 *params
= img
->Width
;
872 case GL_TEXTURE_HEIGHT
:
873 *params
= img
->Height
;
875 case GL_TEXTURE_DEPTH
:
876 *params
= img
->Depth
;
878 case GL_TEXTURE_INTERNAL_FORMAT
:
879 if (_mesa_is_format_compressed(img
->TexFormat
)) {
880 /* need to return the actual compressed format */
881 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
884 /* return the user's requested internal format */
885 *params
= img
->InternalFormat
;
888 case GL_TEXTURE_BORDER
:
889 *params
= img
->Border
;
891 case GL_TEXTURE_RED_SIZE
:
892 if (img
->_BaseFormat
== GL_RED
) {
893 *params
= _mesa_get_format_bits(texFormat
, pname
);
897 case GL_TEXTURE_GREEN_SIZE
:
898 if (img
->_BaseFormat
== GL_RG
) {
899 *params
= _mesa_get_format_bits(texFormat
, pname
);
903 case GL_TEXTURE_BLUE_SIZE
:
904 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
905 *params
= _mesa_get_format_bits(texFormat
, pname
);
909 case GL_TEXTURE_ALPHA_SIZE
:
910 if (img
->_BaseFormat
== GL_ALPHA
||
911 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
912 img
->_BaseFormat
== GL_RGBA
)
913 *params
= _mesa_get_format_bits(texFormat
, pname
);
917 case GL_TEXTURE_INTENSITY_SIZE
:
918 if (img
->_BaseFormat
!= GL_INTENSITY
)
921 *params
= _mesa_get_format_bits(texFormat
, pname
);
923 /* intensity probably stored as rgb texture */
924 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
925 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
929 case GL_TEXTURE_LUMINANCE_SIZE
:
930 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
931 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
934 *params
= _mesa_get_format_bits(texFormat
, pname
);
936 /* luminance 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_INDEX_SIZE_EXT
:
943 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
944 *params
= _mesa_get_format_bits(texFormat
, pname
);
948 case GL_TEXTURE_DEPTH_SIZE_ARB
:
949 if (ctx
->Extensions
.ARB_depth_texture
)
950 *params
= _mesa_get_format_bits(texFormat
, pname
);
952 _mesa_error(ctx
, GL_INVALID_ENUM
,
953 "glGetTexLevelParameter[if]v(pname)");
955 case GL_TEXTURE_STENCIL_SIZE_EXT
:
956 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
957 ctx
->Extensions
.ARB_framebuffer_object
) {
958 *params
= _mesa_get_format_bits(texFormat
, pname
);
961 _mesa_error(ctx
, GL_INVALID_ENUM
,
962 "glGetTexLevelParameter[if]v(pname)");
965 case GL_TEXTURE_SHARED_SIZE
:
966 if (ctx
->VersionMajor
>= 3) {
967 /* XXX return number of exponent bits for shared exponent texture
968 * formats, like GL_RGB9_E5.
973 _mesa_error(ctx
, GL_INVALID_ENUM
,
974 "glGetTexLevelParameter[if]v(pname)");
978 /* GL_ARB_texture_compression */
979 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
980 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
981 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
982 img
->Height
, img
->Depth
);
985 _mesa_error(ctx
, GL_INVALID_OPERATION
,
986 "glGetTexLevelParameter[if]v(pname)");
989 case GL_TEXTURE_COMPRESSED
:
990 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
993 /* GL_ARB_texture_float */
994 case GL_TEXTURE_RED_TYPE_ARB
:
995 if (ctx
->Extensions
.ARB_texture_float
) {
996 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
997 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1000 _mesa_error(ctx
, GL_INVALID_ENUM
,
1001 "glGetTexLevelParameter[if]v(pname)");
1004 case GL_TEXTURE_GREEN_TYPE_ARB
:
1005 if (ctx
->Extensions
.ARB_texture_float
) {
1006 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1007 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1010 _mesa_error(ctx
, GL_INVALID_ENUM
,
1011 "glGetTexLevelParameter[if]v(pname)");
1014 case GL_TEXTURE_BLUE_TYPE_ARB
:
1015 if (ctx
->Extensions
.ARB_texture_float
) {
1016 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1017 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1020 _mesa_error(ctx
, GL_INVALID_ENUM
,
1021 "glGetTexLevelParameter[if]v(pname)");
1024 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1025 if (ctx
->Extensions
.ARB_texture_float
) {
1026 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1027 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1030 _mesa_error(ctx
, GL_INVALID_ENUM
,
1031 "glGetTexLevelParameter[if]v(pname)");
1034 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1035 if (ctx
->Extensions
.ARB_texture_float
) {
1036 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1037 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1040 _mesa_error(ctx
, GL_INVALID_ENUM
,
1041 "glGetTexLevelParameter[if]v(pname)");
1044 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1045 if (ctx
->Extensions
.ARB_texture_float
) {
1046 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1047 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1050 _mesa_error(ctx
, GL_INVALID_ENUM
,
1051 "glGetTexLevelParameter[if]v(pname)");
1054 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1055 if (ctx
->Extensions
.ARB_texture_float
) {
1056 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1057 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1060 _mesa_error(ctx
, GL_INVALID_ENUM
,
1061 "glGetTexLevelParameter[if]v(pname)");
1066 _mesa_error(ctx
, GL_INVALID_ENUM
,
1067 "glGetTexLevelParameter[if]v(pname)");
1071 _mesa_unlock_texture(ctx
, texObj
);
1077 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1079 struct gl_texture_object
*obj
;
1080 GLboolean error
= GL_FALSE
;
1081 GET_CURRENT_CONTEXT(ctx
);
1082 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1084 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1088 _mesa_lock_texture(ctx
, obj
);
1090 case GL_TEXTURE_MAG_FILTER
:
1091 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1093 case GL_TEXTURE_MIN_FILTER
:
1094 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1096 case GL_TEXTURE_WRAP_S
:
1097 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1099 case GL_TEXTURE_WRAP_T
:
1100 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1102 case GL_TEXTURE_WRAP_R
:
1103 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1105 case GL_TEXTURE_BORDER_COLOR
:
1106 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1107 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1108 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1109 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1111 case GL_TEXTURE_RESIDENT
:
1114 if (ctx
->Driver
.IsTextureResident
)
1115 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1118 *params
= ENUM_TO_FLOAT(resident
);
1121 case GL_TEXTURE_PRIORITY
:
1122 *params
= obj
->Priority
;
1124 case GL_TEXTURE_MIN_LOD
:
1125 *params
= obj
->MinLod
;
1127 case GL_TEXTURE_MAX_LOD
:
1128 *params
= obj
->MaxLod
;
1130 case GL_TEXTURE_BASE_LEVEL
:
1131 *params
= (GLfloat
) obj
->BaseLevel
;
1133 case GL_TEXTURE_MAX_LEVEL
:
1134 *params
= (GLfloat
) obj
->MaxLevel
;
1136 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1137 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1138 *params
= obj
->MaxAnisotropy
;
1143 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1144 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1145 *params
= obj
->CompareFailValue
;
1150 case GL_GENERATE_MIPMAP_SGIS
:
1151 *params
= (GLfloat
) obj
->GenerateMipmap
;
1153 case GL_TEXTURE_COMPARE_MODE_ARB
:
1154 if (ctx
->Extensions
.ARB_shadow
) {
1155 *params
= (GLfloat
) obj
->CompareMode
;
1160 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1161 if (ctx
->Extensions
.ARB_shadow
) {
1162 *params
= (GLfloat
) obj
->CompareFunc
;
1167 case GL_DEPTH_TEXTURE_MODE_ARB
:
1168 if (ctx
->Extensions
.ARB_depth_texture
) {
1169 *params
= (GLfloat
) obj
->DepthMode
;
1174 case GL_TEXTURE_LOD_BIAS
:
1175 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1176 *params
= obj
->LodBias
;
1181 #if FEATURE_OES_draw_texture
1182 case GL_TEXTURE_CROP_RECT_OES
:
1183 params
[0] = obj
->CropRect
[0];
1184 params
[1] = obj
->CropRect
[1];
1185 params
[2] = obj
->CropRect
[2];
1186 params
[3] = obj
->CropRect
[3];
1190 case GL_TEXTURE_SWIZZLE_R_EXT
:
1191 case GL_TEXTURE_SWIZZLE_G_EXT
:
1192 case GL_TEXTURE_SWIZZLE_B_EXT
:
1193 case GL_TEXTURE_SWIZZLE_A_EXT
:
1194 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1195 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1196 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1203 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1204 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1206 for (comp
= 0; comp
< 4; comp
++) {
1207 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1221 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1224 _mesa_unlock_texture(ctx
, obj
);
1229 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1231 struct gl_texture_object
*obj
;
1232 GLboolean error
= GL_FALSE
;
1233 GET_CURRENT_CONTEXT(ctx
);
1234 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1236 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1240 _mesa_lock_texture(ctx
, obj
);
1242 case GL_TEXTURE_MAG_FILTER
:
1243 *params
= (GLint
) obj
->MagFilter
;
1245 case GL_TEXTURE_MIN_FILTER
:
1246 *params
= (GLint
) obj
->MinFilter
;
1248 case GL_TEXTURE_WRAP_S
:
1249 *params
= (GLint
) obj
->WrapS
;
1251 case GL_TEXTURE_WRAP_T
:
1252 *params
= (GLint
) obj
->WrapT
;
1254 case GL_TEXTURE_WRAP_R
:
1255 *params
= (GLint
) obj
->WrapR
;
1257 case GL_TEXTURE_BORDER_COLOR
:
1260 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1261 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1262 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1263 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1264 params
[0] = FLOAT_TO_INT(b
[0]);
1265 params
[1] = FLOAT_TO_INT(b
[1]);
1266 params
[2] = FLOAT_TO_INT(b
[2]);
1267 params
[3] = FLOAT_TO_INT(b
[3]);
1270 case GL_TEXTURE_RESIDENT
:
1273 if (ctx
->Driver
.IsTextureResident
)
1274 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1277 *params
= (GLint
) resident
;
1280 case GL_TEXTURE_PRIORITY
:
1281 *params
= FLOAT_TO_INT(obj
->Priority
);
1283 case GL_TEXTURE_MIN_LOD
:
1284 *params
= (GLint
) obj
->MinLod
;
1286 case GL_TEXTURE_MAX_LOD
:
1287 *params
= (GLint
) obj
->MaxLod
;
1289 case GL_TEXTURE_BASE_LEVEL
:
1290 *params
= obj
->BaseLevel
;
1292 case GL_TEXTURE_MAX_LEVEL
:
1293 *params
= obj
->MaxLevel
;
1295 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1296 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1297 *params
= (GLint
) obj
->MaxAnisotropy
;
1303 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1304 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1305 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1311 case GL_GENERATE_MIPMAP_SGIS
:
1312 *params
= (GLint
) obj
->GenerateMipmap
;
1314 case GL_TEXTURE_COMPARE_MODE_ARB
:
1315 if (ctx
->Extensions
.ARB_shadow
) {
1316 *params
= (GLint
) obj
->CompareMode
;
1322 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1323 if (ctx
->Extensions
.ARB_shadow
) {
1324 *params
= (GLint
) obj
->CompareFunc
;
1330 case GL_DEPTH_TEXTURE_MODE_ARB
:
1331 if (ctx
->Extensions
.ARB_depth_texture
) {
1332 *params
= (GLint
) obj
->DepthMode
;
1338 case GL_TEXTURE_LOD_BIAS
:
1339 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1340 *params
= (GLint
) obj
->LodBias
;
1346 #if FEATURE_OES_draw_texture
1347 case GL_TEXTURE_CROP_RECT_OES
:
1348 params
[0] = obj
->CropRect
[0];
1349 params
[1] = obj
->CropRect
[1];
1350 params
[2] = obj
->CropRect
[2];
1351 params
[3] = obj
->CropRect
[3];
1354 case GL_TEXTURE_SWIZZLE_R_EXT
:
1355 case GL_TEXTURE_SWIZZLE_G_EXT
:
1356 case GL_TEXTURE_SWIZZLE_B_EXT
:
1357 case GL_TEXTURE_SWIZZLE_A_EXT
:
1358 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1359 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1360 *params
= obj
->Swizzle
[comp
];
1367 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1368 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1369 COPY_4V(params
, obj
->Swizzle
);
1377 ; /* silence warnings */
1381 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1384 _mesa_unlock_texture(ctx
, obj
);
1388 /** New in GL 3.0 */
1390 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1392 struct gl_texture_object
*texObj
;
1393 GET_CURRENT_CONTEXT(ctx
);
1394 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1396 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1399 case GL_TEXTURE_BORDER_COLOR
:
1400 COPY_4V(params
, texObj
->BorderColor
.i
);
1403 _mesa_GetTexParameteriv(target
, pname
, params
);
1408 /** New in GL 3.0 */
1410 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1412 struct gl_texture_object
*texObj
;
1413 GET_CURRENT_CONTEXT(ctx
);
1414 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1416 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1419 case GL_TEXTURE_BORDER_COLOR
:
1420 COPY_4V(params
, texObj
->BorderColor
.i
);
1425 _mesa_GetTexParameteriv(target
, pname
, ip
);
1427 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1428 pname
== GL_TEXTURE_CROP_RECT_OES
) {