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/mtypes.h"
39 #include "main/texcompress.h"
40 #include "main/texparam.h"
41 #include "main/teximage.h"
42 #include "main/texstate.h"
43 #include "program/prog_instruction.h"
47 * Check if a coordinate wrap mode is supported for the texture target.
48 * \return GL_TRUE if legal, GL_FALSE otherwise
51 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
53 const struct gl_extensions
* const e
= & ctx
->Extensions
;
55 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
56 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
57 /* any texture target */
60 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
62 (wrap
== GL_MIRRORED_REPEAT
&&
63 e
->ARB_texture_mirrored_repeat
) ||
64 (wrap
== GL_MIRROR_CLAMP_EXT
&&
65 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
66 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
67 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
68 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
69 (e
->EXT_texture_mirror_clamp
)))) {
70 /* non-rectangle texture */
74 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
80 * Get current texture object for given target.
81 * Return NULL if any error (and record the error).
82 * Note that this is different from _mesa_select_tex_object() in that proxy
83 * targets are not accepted.
84 * Only the glGetTexLevelParameter() functions accept proxy targets.
86 static struct gl_texture_object
*
87 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
89 struct gl_texture_unit
*texUnit
;
91 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
92 _mesa_error(ctx
, GL_INVALID_OPERATION
,
93 "gl%sTexParameter(current unit)", get
? "Get" : "");
97 texUnit
= _mesa_get_current_tex_unit(ctx
);
101 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
103 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
105 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
106 case GL_TEXTURE_CUBE_MAP
:
107 if (ctx
->Extensions
.ARB_texture_cube_map
) {
108 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
111 case GL_TEXTURE_RECTANGLE_NV
:
112 if (ctx
->Extensions
.NV_texture_rectangle
) {
113 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
116 case GL_TEXTURE_1D_ARRAY_EXT
:
117 if (ctx
->Extensions
.MESA_texture_array
) {
118 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
121 case GL_TEXTURE_2D_ARRAY_EXT
:
122 if (ctx
->Extensions
.MESA_texture_array
) {
123 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
130 _mesa_error(ctx
, GL_INVALID_ENUM
,
131 "gl%sTexParameter(target)", get
? "Get" : "");
137 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
138 * \return -1 if error.
141 comp_to_swizzle(GLenum comp
)
163 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
166 ASSERT(swz
<= SWIZZLE_NIL
);
168 GLuint mask
= 0x7 << (3 * comp
);
169 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
176 * This is called just prior to changing any texture object state.
177 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
178 * state flag and then mark the texture object as 'incomplete' so that any
179 * per-texture derived state gets recomputed.
182 flush(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
184 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
185 texObj
->_Complete
= GL_FALSE
;
190 * Set an integer-valued texture parameter
191 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
194 set_tex_parameteri(struct gl_context
*ctx
,
195 struct gl_texture_object
*texObj
,
196 GLenum pname
, const GLint
*params
)
199 case GL_TEXTURE_MIN_FILTER
:
200 if (texObj
->MinFilter
== params
[0])
206 texObj
->MinFilter
= params
[0];
208 case GL_NEAREST_MIPMAP_NEAREST
:
209 case GL_LINEAR_MIPMAP_NEAREST
:
210 case GL_NEAREST_MIPMAP_LINEAR
:
211 case GL_LINEAR_MIPMAP_LINEAR
:
212 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
214 texObj
->MinFilter
= params
[0];
219 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
224 case GL_TEXTURE_MAG_FILTER
:
225 if (texObj
->MagFilter
== params
[0])
231 texObj
->MagFilter
= params
[0];
234 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
239 case GL_TEXTURE_WRAP_S
:
240 if (texObj
->WrapS
== params
[0])
242 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
244 texObj
->WrapS
= params
[0];
249 case GL_TEXTURE_WRAP_T
:
250 if (texObj
->WrapT
== params
[0])
252 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
254 texObj
->WrapT
= params
[0];
259 case GL_TEXTURE_WRAP_R
:
260 if (texObj
->WrapR
== params
[0])
262 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
264 texObj
->WrapR
= params
[0];
269 case GL_TEXTURE_BASE_LEVEL
:
270 if (texObj
->BaseLevel
== params
[0])
273 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
274 _mesa_error(ctx
, GL_INVALID_VALUE
,
275 "glTexParameter(param=%d)", params
[0]);
279 texObj
->BaseLevel
= params
[0];
282 case GL_TEXTURE_MAX_LEVEL
:
283 if (texObj
->MaxLevel
== params
[0])
285 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
286 _mesa_error(ctx
, GL_INVALID_OPERATION
,
287 "glTexParameter(param=%d)", params
[0]);
291 texObj
->MaxLevel
= params
[0];
294 case GL_GENERATE_MIPMAP_SGIS
:
295 if (texObj
->GenerateMipmap
!= params
[0]) {
297 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
302 case GL_TEXTURE_COMPARE_MODE_ARB
:
303 if (ctx
->Extensions
.ARB_shadow
&&
304 (params
[0] == GL_NONE
||
305 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
306 if (texObj
->CompareMode
!= params
[0]) {
308 texObj
->CompareMode
= params
[0];
314 _mesa_error(ctx
, GL_INVALID_ENUM
,
315 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
319 case GL_TEXTURE_COMPARE_FUNC_ARB
:
320 if (ctx
->Extensions
.ARB_shadow
) {
321 if (texObj
->CompareFunc
== params
[0])
327 texObj
->CompareFunc
= params
[0];
335 if (ctx
->Extensions
.EXT_shadow_funcs
) {
337 texObj
->CompareFunc
= params
[0];
342 _mesa_error(ctx
, GL_INVALID_ENUM
,
343 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
347 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
351 case GL_DEPTH_TEXTURE_MODE_ARB
:
352 if (ctx
->Extensions
.ARB_depth_texture
&&
353 (params
[0] == GL_LUMINANCE
||
354 params
[0] == GL_INTENSITY
||
355 params
[0] == GL_ALPHA
||
356 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
))) {
357 if (texObj
->DepthMode
!= params
[0]) {
359 texObj
->DepthMode
= params
[0];
364 _mesa_error(ctx
, GL_INVALID_ENUM
,
365 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
369 #if FEATURE_OES_draw_texture
370 case GL_TEXTURE_CROP_RECT_OES
:
371 texObj
->CropRect
[0] = params
[0];
372 texObj
->CropRect
[1] = params
[1];
373 texObj
->CropRect
[2] = params
[2];
374 texObj
->CropRect
[3] = params
[3];
378 case GL_TEXTURE_SWIZZLE_R_EXT
:
379 case GL_TEXTURE_SWIZZLE_G_EXT
:
380 case GL_TEXTURE_SWIZZLE_B_EXT
:
381 case GL_TEXTURE_SWIZZLE_A_EXT
:
382 if (ctx
->Extensions
.EXT_texture_swizzle
) {
383 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
384 const GLint swz
= comp_to_swizzle(params
[0]);
386 _mesa_error(ctx
, GL_INVALID_OPERATION
,
387 "glTexParameter(swizzle 0x%x)", params
[0]);
393 texObj
->Swizzle
[comp
] = params
[0];
394 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
398 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
401 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
402 if (ctx
->Extensions
.EXT_texture_swizzle
) {
405 for (comp
= 0; comp
< 4; comp
++) {
406 const GLint swz
= comp_to_swizzle(params
[comp
]);
408 texObj
->Swizzle
[comp
] = params
[comp
];
409 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
413 "glTexParameter(swizzle 0x%x)", params
[comp
]);
419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
423 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
430 * Set a float-valued texture parameter
431 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
434 set_tex_parameterf(struct gl_context
*ctx
,
435 struct gl_texture_object
*texObj
,
436 GLenum pname
, const GLfloat
*params
)
439 case GL_TEXTURE_MIN_LOD
:
440 if (texObj
->MinLod
== params
[0])
443 texObj
->MinLod
= params
[0];
446 case GL_TEXTURE_MAX_LOD
:
447 if (texObj
->MaxLod
== params
[0])
450 texObj
->MaxLod
= params
[0];
453 case GL_TEXTURE_PRIORITY
:
455 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
458 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
459 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
460 if (texObj
->MaxAnisotropy
== params
[0])
462 if (params
[0] < 1.0) {
463 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
467 /* clamp to max, that's what NVIDIA does */
468 texObj
->MaxAnisotropy
= MIN2(params
[0],
469 ctx
->Const
.MaxTextureMaxAnisotropy
);
473 static GLuint count
= 0;
475 _mesa_error(ctx
, GL_INVALID_ENUM
,
476 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
480 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
481 if (ctx
->Extensions
.ARB_shadow_ambient
) {
482 if (texObj
->CompareFailValue
!= params
[0]) {
484 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
489 _mesa_error(ctx
, GL_INVALID_ENUM
,
490 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
494 case GL_TEXTURE_LOD_BIAS
:
495 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
496 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
497 if (texObj
->LodBias
!= params
[0]) {
499 texObj
->LodBias
= params
[0];
506 case GL_TEXTURE_BORDER_COLOR
:
508 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
509 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
510 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
511 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
522 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
524 GLboolean need_update
;
525 struct gl_texture_object
*texObj
;
526 GET_CURRENT_CONTEXT(ctx
);
527 ASSERT_OUTSIDE_BEGIN_END(ctx
);
529 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
534 case GL_TEXTURE_MIN_FILTER
:
535 case GL_TEXTURE_MAG_FILTER
:
536 case GL_TEXTURE_WRAP_S
:
537 case GL_TEXTURE_WRAP_T
:
538 case GL_TEXTURE_WRAP_R
:
539 case GL_TEXTURE_BASE_LEVEL
:
540 case GL_TEXTURE_MAX_LEVEL
:
541 case GL_GENERATE_MIPMAP_SGIS
:
542 case GL_TEXTURE_COMPARE_MODE_ARB
:
543 case GL_TEXTURE_COMPARE_FUNC_ARB
:
544 case GL_DEPTH_TEXTURE_MODE_ARB
:
546 /* convert float param to int */
548 p
[0] = (GLint
) param
;
549 p
[1] = p
[2] = p
[3] = 0;
550 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
555 /* this will generate an error if pname is illegal */
558 p
[1] = p
[2] = p
[3] = 0.0F
;
559 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
563 if (ctx
->Driver
.TexParameter
&& need_update
) {
564 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
570 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
572 GLboolean need_update
;
573 struct gl_texture_object
*texObj
;
574 GET_CURRENT_CONTEXT(ctx
);
575 ASSERT_OUTSIDE_BEGIN_END(ctx
);
577 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
582 case GL_TEXTURE_MIN_FILTER
:
583 case GL_TEXTURE_MAG_FILTER
:
584 case GL_TEXTURE_WRAP_S
:
585 case GL_TEXTURE_WRAP_T
:
586 case GL_TEXTURE_WRAP_R
:
587 case GL_TEXTURE_BASE_LEVEL
:
588 case GL_TEXTURE_MAX_LEVEL
:
589 case GL_GENERATE_MIPMAP_SGIS
:
590 case GL_TEXTURE_COMPARE_MODE_ARB
:
591 case GL_TEXTURE_COMPARE_FUNC_ARB
:
592 case GL_DEPTH_TEXTURE_MODE_ARB
:
594 /* convert float param to int */
596 p
[0] = (GLint
) params
[0];
597 p
[1] = p
[2] = p
[3] = 0;
598 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
602 #if FEATURE_OES_draw_texture
603 case GL_TEXTURE_CROP_RECT_OES
:
605 /* convert float params to int */
607 iparams
[0] = (GLint
) params
[0];
608 iparams
[1] = (GLint
) params
[1];
609 iparams
[2] = (GLint
) params
[2];
610 iparams
[3] = (GLint
) params
[3];
611 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
617 /* this will generate an error if pname is illegal */
618 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
621 if (ctx
->Driver
.TexParameter
&& need_update
) {
622 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
628 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
630 GLboolean need_update
;
631 struct gl_texture_object
*texObj
;
632 GET_CURRENT_CONTEXT(ctx
);
633 ASSERT_OUTSIDE_BEGIN_END(ctx
);
635 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
640 case GL_TEXTURE_MIN_LOD
:
641 case GL_TEXTURE_MAX_LOD
:
642 case GL_TEXTURE_PRIORITY
:
643 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
644 case GL_TEXTURE_LOD_BIAS
:
645 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
648 fparam
[0] = (GLfloat
) param
;
649 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
650 /* convert int param to float */
651 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
655 /* this will generate an error if pname is illegal */
659 iparam
[1] = iparam
[2] = iparam
[3] = 0;
660 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
664 if (ctx
->Driver
.TexParameter
&& need_update
) {
665 GLfloat fparam
= (GLfloat
) param
;
666 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
672 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
674 GLboolean need_update
;
675 struct gl_texture_object
*texObj
;
676 GET_CURRENT_CONTEXT(ctx
);
677 ASSERT_OUTSIDE_BEGIN_END(ctx
);
679 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
684 case GL_TEXTURE_BORDER_COLOR
:
686 /* convert int params to float */
688 fparams
[0] = INT_TO_FLOAT(params
[0]);
689 fparams
[1] = INT_TO_FLOAT(params
[1]);
690 fparams
[2] = INT_TO_FLOAT(params
[2]);
691 fparams
[3] = INT_TO_FLOAT(params
[3]);
692 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
695 case GL_TEXTURE_MIN_LOD
:
696 case GL_TEXTURE_MAX_LOD
:
697 case GL_TEXTURE_PRIORITY
:
698 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
699 case GL_TEXTURE_LOD_BIAS
:
700 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
702 /* convert int param to float */
704 fparams
[0] = (GLfloat
) params
[0];
705 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
706 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
710 /* this will generate an error if pname is illegal */
711 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
714 if (ctx
->Driver
.TexParameter
&& need_update
) {
716 fparams
[0] = INT_TO_FLOAT(params
[0]);
717 if (pname
== GL_TEXTURE_BORDER_COLOR
||
718 pname
== GL_TEXTURE_CROP_RECT_OES
) {
719 fparams
[1] = INT_TO_FLOAT(params
[1]);
720 fparams
[2] = INT_TO_FLOAT(params
[2]);
721 fparams
[3] = INT_TO_FLOAT(params
[3]);
723 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
729 * Set tex parameter to integer value(s). Primarily intended to set
730 * integer-valued texture border color (for integer-valued textures).
734 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
736 struct gl_texture_object
*texObj
;
737 GET_CURRENT_CONTEXT(ctx
);
738 ASSERT_OUTSIDE_BEGIN_END(ctx
);
740 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
745 case GL_TEXTURE_BORDER_COLOR
:
746 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
747 /* set the integer-valued border color */
748 COPY_4V(texObj
->BorderColor
.i
, params
);
751 _mesa_TexParameteriv(target
, pname
, params
);
754 /* XXX no driver hook for TexParameterIiv() yet */
759 * Set tex parameter to unsigned integer value(s). Primarily intended to set
760 * uint-valued texture border color (for integer-valued textures).
764 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*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 unsigned integer-valued border color */
778 COPY_4V(texObj
->BorderColor
.ui
, params
);
781 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
784 /* XXX no driver hook for TexParameterIuiv() yet */
791 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
792 GLenum pname
, GLfloat
*params
)
795 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
796 *params
= (GLfloat
) iparam
;
801 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
802 GLenum pname
, GLint
*params
)
804 const struct gl_texture_unit
*texUnit
;
805 struct gl_texture_object
*texObj
;
806 const struct gl_texture_image
*img
= NULL
;
810 GET_CURRENT_CONTEXT(ctx
);
811 ASSERT_OUTSIDE_BEGIN_END(ctx
);
813 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
814 _mesa_error(ctx
, GL_INVALID_OPERATION
,
815 "glGetTexLevelParameteriv(current unit)");
819 texUnit
= _mesa_get_current_tex_unit(ctx
);
821 /* this will catch bad target values */
822 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
823 if (maxLevels
== 0) {
824 _mesa_error(ctx
, GL_INVALID_ENUM
,
825 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
829 if (level
< 0 || level
>= maxLevels
) {
830 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
834 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
835 _mesa_lock_texture(ctx
, texObj
);
837 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
838 if (!img
|| !img
->TexFormat
) {
839 /* undefined texture image */
840 if (pname
== GL_TEXTURE_COMPONENTS
)
847 texFormat
= img
->TexFormat
;
849 isProxy
= _mesa_is_proxy_texture(target
);
852 case GL_TEXTURE_WIDTH
:
853 *params
= img
->Width
;
855 case GL_TEXTURE_HEIGHT
:
856 *params
= img
->Height
;
858 case GL_TEXTURE_DEPTH
:
859 *params
= img
->Depth
;
861 case GL_TEXTURE_INTERNAL_FORMAT
:
862 if (_mesa_is_format_compressed(img
->TexFormat
)) {
863 /* need to return the actual compressed format */
864 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
867 /* return the user's requested internal format */
868 *params
= img
->InternalFormat
;
871 case GL_TEXTURE_BORDER
:
872 *params
= img
->Border
;
874 case GL_TEXTURE_RED_SIZE
:
875 if (img
->_BaseFormat
== GL_RED
) {
876 *params
= _mesa_get_format_bits(texFormat
, pname
);
880 case GL_TEXTURE_GREEN_SIZE
:
881 if (img
->_BaseFormat
== GL_RG
) {
882 *params
= _mesa_get_format_bits(texFormat
, pname
);
886 case GL_TEXTURE_BLUE_SIZE
:
887 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
888 *params
= _mesa_get_format_bits(texFormat
, pname
);
892 case GL_TEXTURE_ALPHA_SIZE
:
893 if (img
->_BaseFormat
== GL_ALPHA
||
894 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
895 img
->_BaseFormat
== GL_RGBA
)
896 *params
= _mesa_get_format_bits(texFormat
, pname
);
900 case GL_TEXTURE_INTENSITY_SIZE
:
901 if (img
->_BaseFormat
!= GL_INTENSITY
)
904 *params
= _mesa_get_format_bits(texFormat
, pname
);
906 /* intensity probably stored as rgb texture */
907 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
908 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
912 case GL_TEXTURE_LUMINANCE_SIZE
:
913 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
914 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
917 *params
= _mesa_get_format_bits(texFormat
, pname
);
919 /* luminance probably stored as rgb texture */
920 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
921 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
925 case GL_TEXTURE_INDEX_SIZE_EXT
:
926 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
927 *params
= _mesa_get_format_bits(texFormat
, pname
);
931 case GL_TEXTURE_DEPTH_SIZE_ARB
:
932 if (ctx
->Extensions
.ARB_depth_texture
)
933 *params
= _mesa_get_format_bits(texFormat
, pname
);
935 _mesa_error(ctx
, GL_INVALID_ENUM
,
936 "glGetTexLevelParameter[if]v(pname)");
938 case GL_TEXTURE_STENCIL_SIZE_EXT
:
939 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
940 ctx
->Extensions
.ARB_framebuffer_object
) {
941 *params
= _mesa_get_format_bits(texFormat
, pname
);
944 _mesa_error(ctx
, GL_INVALID_ENUM
,
945 "glGetTexLevelParameter[if]v(pname)");
948 case GL_TEXTURE_SHARED_SIZE
:
949 if (ctx
->VersionMajor
>= 3) {
950 /* XXX return number of exponent bits for shared exponent texture
951 * formats, like GL_RGB9_E5.
956 _mesa_error(ctx
, GL_INVALID_ENUM
,
957 "glGetTexLevelParameter[if]v(pname)");
961 /* GL_ARB_texture_compression */
962 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
963 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
964 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
965 img
->Height
, img
->Depth
);
968 _mesa_error(ctx
, GL_INVALID_OPERATION
,
969 "glGetTexLevelParameter[if]v(pname)");
972 case GL_TEXTURE_COMPRESSED
:
973 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
976 /* GL_ARB_texture_float */
977 case GL_TEXTURE_RED_TYPE_ARB
:
978 if (ctx
->Extensions
.ARB_texture_float
) {
979 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
980 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
983 _mesa_error(ctx
, GL_INVALID_ENUM
,
984 "glGetTexLevelParameter[if]v(pname)");
987 case GL_TEXTURE_GREEN_TYPE_ARB
:
988 if (ctx
->Extensions
.ARB_texture_float
) {
989 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
990 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
993 _mesa_error(ctx
, GL_INVALID_ENUM
,
994 "glGetTexLevelParameter[if]v(pname)");
997 case GL_TEXTURE_BLUE_TYPE_ARB
:
998 if (ctx
->Extensions
.ARB_texture_float
) {
999 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1000 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1003 _mesa_error(ctx
, GL_INVALID_ENUM
,
1004 "glGetTexLevelParameter[if]v(pname)");
1007 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1008 if (ctx
->Extensions
.ARB_texture_float
) {
1009 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_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_LUMINANCE_TYPE_ARB
:
1018 if (ctx
->Extensions
.ARB_texture_float
) {
1019 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_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_INTENSITY_TYPE_ARB
:
1028 if (ctx
->Extensions
.ARB_texture_float
) {
1029 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_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_DEPTH_TYPE_ARB
:
1038 if (ctx
->Extensions
.ARB_texture_float
) {
1039 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1040 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1043 _mesa_error(ctx
, GL_INVALID_ENUM
,
1044 "glGetTexLevelParameter[if]v(pname)");
1049 _mesa_error(ctx
, GL_INVALID_ENUM
,
1050 "glGetTexLevelParameter[if]v(pname)");
1054 _mesa_unlock_texture(ctx
, texObj
);
1060 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1062 struct gl_texture_object
*obj
;
1063 GLboolean error
= GL_FALSE
;
1064 GET_CURRENT_CONTEXT(ctx
);
1065 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1067 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1071 _mesa_lock_texture(ctx
, obj
);
1073 case GL_TEXTURE_MAG_FILTER
:
1074 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1076 case GL_TEXTURE_MIN_FILTER
:
1077 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1079 case GL_TEXTURE_WRAP_S
:
1080 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1082 case GL_TEXTURE_WRAP_T
:
1083 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1085 case GL_TEXTURE_WRAP_R
:
1086 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1088 case GL_TEXTURE_BORDER_COLOR
:
1089 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1090 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1091 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1092 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1094 case GL_TEXTURE_RESIDENT
:
1097 if (ctx
->Driver
.IsTextureResident
)
1098 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1101 *params
= ENUM_TO_FLOAT(resident
);
1104 case GL_TEXTURE_PRIORITY
:
1105 *params
= obj
->Priority
;
1107 case GL_TEXTURE_MIN_LOD
:
1108 *params
= obj
->MinLod
;
1110 case GL_TEXTURE_MAX_LOD
:
1111 *params
= obj
->MaxLod
;
1113 case GL_TEXTURE_BASE_LEVEL
:
1114 *params
= (GLfloat
) obj
->BaseLevel
;
1116 case GL_TEXTURE_MAX_LEVEL
:
1117 *params
= (GLfloat
) obj
->MaxLevel
;
1119 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1120 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1121 *params
= obj
->MaxAnisotropy
;
1126 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1127 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1128 *params
= obj
->CompareFailValue
;
1133 case GL_GENERATE_MIPMAP_SGIS
:
1134 *params
= (GLfloat
) obj
->GenerateMipmap
;
1136 case GL_TEXTURE_COMPARE_MODE_ARB
:
1137 if (ctx
->Extensions
.ARB_shadow
) {
1138 *params
= (GLfloat
) obj
->CompareMode
;
1143 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1144 if (ctx
->Extensions
.ARB_shadow
) {
1145 *params
= (GLfloat
) obj
->CompareFunc
;
1150 case GL_DEPTH_TEXTURE_MODE_ARB
:
1151 if (ctx
->Extensions
.ARB_depth_texture
) {
1152 *params
= (GLfloat
) obj
->DepthMode
;
1157 case GL_TEXTURE_LOD_BIAS
:
1158 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1159 *params
= obj
->LodBias
;
1164 #if FEATURE_OES_draw_texture
1165 case GL_TEXTURE_CROP_RECT_OES
:
1166 params
[0] = obj
->CropRect
[0];
1167 params
[1] = obj
->CropRect
[1];
1168 params
[2] = obj
->CropRect
[2];
1169 params
[3] = obj
->CropRect
[3];
1173 case GL_TEXTURE_SWIZZLE_R_EXT
:
1174 case GL_TEXTURE_SWIZZLE_G_EXT
:
1175 case GL_TEXTURE_SWIZZLE_B_EXT
:
1176 case GL_TEXTURE_SWIZZLE_A_EXT
:
1177 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1178 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1179 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1186 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1187 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1189 for (comp
= 0; comp
< 4; comp
++) {
1190 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1204 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1207 _mesa_unlock_texture(ctx
, obj
);
1212 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1214 struct gl_texture_object
*obj
;
1215 GLboolean error
= GL_FALSE
;
1216 GET_CURRENT_CONTEXT(ctx
);
1217 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1219 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1223 _mesa_lock_texture(ctx
, obj
);
1225 case GL_TEXTURE_MAG_FILTER
:
1226 *params
= (GLint
) obj
->MagFilter
;
1228 case GL_TEXTURE_MIN_FILTER
:
1229 *params
= (GLint
) obj
->MinFilter
;
1231 case GL_TEXTURE_WRAP_S
:
1232 *params
= (GLint
) obj
->WrapS
;
1234 case GL_TEXTURE_WRAP_T
:
1235 *params
= (GLint
) obj
->WrapT
;
1237 case GL_TEXTURE_WRAP_R
:
1238 *params
= (GLint
) obj
->WrapR
;
1240 case GL_TEXTURE_BORDER_COLOR
:
1243 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1244 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1245 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1246 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1247 params
[0] = FLOAT_TO_INT(b
[0]);
1248 params
[1] = FLOAT_TO_INT(b
[1]);
1249 params
[2] = FLOAT_TO_INT(b
[2]);
1250 params
[3] = FLOAT_TO_INT(b
[3]);
1253 case GL_TEXTURE_RESIDENT
:
1256 if (ctx
->Driver
.IsTextureResident
)
1257 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1260 *params
= (GLint
) resident
;
1263 case GL_TEXTURE_PRIORITY
:
1264 *params
= FLOAT_TO_INT(obj
->Priority
);
1266 case GL_TEXTURE_MIN_LOD
:
1267 *params
= (GLint
) obj
->MinLod
;
1269 case GL_TEXTURE_MAX_LOD
:
1270 *params
= (GLint
) obj
->MaxLod
;
1272 case GL_TEXTURE_BASE_LEVEL
:
1273 *params
= obj
->BaseLevel
;
1275 case GL_TEXTURE_MAX_LEVEL
:
1276 *params
= obj
->MaxLevel
;
1278 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1279 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1280 *params
= (GLint
) obj
->MaxAnisotropy
;
1286 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1287 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1288 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1294 case GL_GENERATE_MIPMAP_SGIS
:
1295 *params
= (GLint
) obj
->GenerateMipmap
;
1297 case GL_TEXTURE_COMPARE_MODE_ARB
:
1298 if (ctx
->Extensions
.ARB_shadow
) {
1299 *params
= (GLint
) obj
->CompareMode
;
1305 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1306 if (ctx
->Extensions
.ARB_shadow
) {
1307 *params
= (GLint
) obj
->CompareFunc
;
1313 case GL_DEPTH_TEXTURE_MODE_ARB
:
1314 if (ctx
->Extensions
.ARB_depth_texture
) {
1315 *params
= (GLint
) obj
->DepthMode
;
1321 case GL_TEXTURE_LOD_BIAS
:
1322 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1323 *params
= (GLint
) obj
->LodBias
;
1329 #if FEATURE_OES_draw_texture
1330 case GL_TEXTURE_CROP_RECT_OES
:
1331 params
[0] = obj
->CropRect
[0];
1332 params
[1] = obj
->CropRect
[1];
1333 params
[2] = obj
->CropRect
[2];
1334 params
[3] = obj
->CropRect
[3];
1337 case GL_TEXTURE_SWIZZLE_R_EXT
:
1338 case GL_TEXTURE_SWIZZLE_G_EXT
:
1339 case GL_TEXTURE_SWIZZLE_B_EXT
:
1340 case GL_TEXTURE_SWIZZLE_A_EXT
:
1341 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1342 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1343 *params
= obj
->Swizzle
[comp
];
1350 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1351 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1352 COPY_4V(params
, obj
->Swizzle
);
1360 ; /* silence warnings */
1364 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1367 _mesa_unlock_texture(ctx
, obj
);
1371 /** New in GL 3.0 */
1373 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1375 struct gl_texture_object
*texObj
;
1376 GET_CURRENT_CONTEXT(ctx
);
1377 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1379 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1382 case GL_TEXTURE_BORDER_COLOR
:
1383 COPY_4V(params
, texObj
->BorderColor
.i
);
1386 _mesa_GetTexParameteriv(target
, pname
, params
);
1391 /** New in GL 3.0 */
1393 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1395 struct gl_texture_object
*texObj
;
1396 GET_CURRENT_CONTEXT(ctx
);
1397 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1399 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1402 case GL_TEXTURE_BORDER_COLOR
:
1403 COPY_4V(params
, texObj
->BorderColor
.i
);
1408 _mesa_GetTexParameteriv(target
, pname
, ip
);
1410 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1411 pname
== GL_TEXTURE_CROP_RECT_OES
) {