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/texcompress.h"
39 #include "main/texparam.h"
40 #include "main/teximage.h"
41 #include "main/texstate.h"
42 #include "shader/prog_instruction.h"
46 * Check if a coordinate wrap mode is supported for the texture target.
47 * \return GL_TRUE if legal, GL_FALSE otherwise
50 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
52 const struct gl_extensions
* const e
= & ctx
->Extensions
;
54 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
55 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
56 /* any texture target */
59 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
61 (wrap
== GL_MIRRORED_REPEAT
&&
62 e
->ARB_texture_mirrored_repeat
) ||
63 (wrap
== GL_MIRROR_CLAMP_EXT
&&
64 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
65 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
66 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
67 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
68 (e
->EXT_texture_mirror_clamp
)))) {
69 /* non-rectangle texture */
73 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
79 * Get current texture object for given target.
80 * Return NULL if any error (and record the error).
81 * Note that this is different from _mesa_select_tex_object() in that proxy
82 * targets are not accepted.
83 * Only the glGetTexLevelParameter() functions accept proxy targets.
85 static struct gl_texture_object
*
86 get_texobj(GLcontext
*ctx
, GLenum target
, GLboolean get
)
88 struct gl_texture_unit
*texUnit
;
90 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
91 _mesa_error(ctx
, GL_INVALID_OPERATION
,
92 "gl%sTexParameter(current unit)", get
? "Get" : "");
96 texUnit
= _mesa_get_current_tex_unit(ctx
);
100 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
102 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
104 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
105 case GL_TEXTURE_CUBE_MAP
:
106 if (ctx
->Extensions
.ARB_texture_cube_map
) {
107 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
110 case GL_TEXTURE_RECTANGLE_NV
:
111 if (ctx
->Extensions
.NV_texture_rectangle
) {
112 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
115 case GL_TEXTURE_1D_ARRAY_EXT
:
116 if (ctx
->Extensions
.MESA_texture_array
) {
117 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
120 case GL_TEXTURE_2D_ARRAY_EXT
:
121 if (ctx
->Extensions
.MESA_texture_array
) {
122 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
129 _mesa_error(ctx
, GL_INVALID_ENUM
,
130 "gl%sTexParameter(target)", get
? "Get" : "");
136 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
137 * \return -1 if error.
140 comp_to_swizzle(GLenum comp
)
162 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
165 ASSERT(swz
<= SWIZZLE_NIL
);
167 GLuint mask
= 0x7 << (3 * comp
);
168 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
175 * This is called just prior to changing any texture object state.
176 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
177 * state flag and then mark the texture object as 'incomplete' so that any
178 * per-texture derived state gets recomputed.
181 flush(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
183 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
184 texObj
->_Complete
= GL_FALSE
;
189 * Set an integer-valued texture parameter
190 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
193 set_tex_parameteri(GLcontext
*ctx
,
194 struct gl_texture_object
*texObj
,
195 GLenum pname
, const GLint
*params
)
198 case GL_TEXTURE_MIN_FILTER
:
199 if (texObj
->MinFilter
== params
[0])
205 texObj
->MinFilter
= params
[0];
207 case GL_NEAREST_MIPMAP_NEAREST
:
208 case GL_LINEAR_MIPMAP_NEAREST
:
209 case GL_NEAREST_MIPMAP_LINEAR
:
210 case GL_LINEAR_MIPMAP_LINEAR
:
211 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
213 texObj
->MinFilter
= params
[0];
218 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
223 case GL_TEXTURE_MAG_FILTER
:
224 if (texObj
->MagFilter
== params
[0])
230 texObj
->MagFilter
= params
[0];
233 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
238 case GL_TEXTURE_WRAP_S
:
239 if (texObj
->WrapS
== params
[0])
241 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
243 texObj
->WrapS
= params
[0];
248 case GL_TEXTURE_WRAP_T
:
249 if (texObj
->WrapT
== params
[0])
251 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
253 texObj
->WrapT
= params
[0];
258 case GL_TEXTURE_WRAP_R
:
259 if (texObj
->WrapR
== params
[0])
261 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
263 texObj
->WrapR
= params
[0];
268 case GL_TEXTURE_BASE_LEVEL
:
269 if (texObj
->BaseLevel
== params
[0])
272 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
273 _mesa_error(ctx
, GL_INVALID_VALUE
,
274 "glTexParameter(param=%d)", params
[0]);
278 texObj
->BaseLevel
= params
[0];
281 case GL_TEXTURE_MAX_LEVEL
:
282 if (texObj
->MaxLevel
== params
[0])
284 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
285 _mesa_error(ctx
, GL_INVALID_OPERATION
,
286 "glTexParameter(param=%d)", params
[0]);
290 texObj
->MaxLevel
= params
[0];
293 case GL_GENERATE_MIPMAP_SGIS
:
294 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
295 if (texObj
->GenerateMipmap
!= params
[0]) {
297 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
303 _mesa_error(ctx
, GL_INVALID_ENUM
,
304 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
308 case GL_TEXTURE_COMPARE_MODE_ARB
:
309 if (ctx
->Extensions
.ARB_shadow
&&
310 (params
[0] == GL_NONE
||
311 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
312 if (texObj
->CompareMode
!= params
[0]) {
314 texObj
->CompareMode
= params
[0];
320 _mesa_error(ctx
, GL_INVALID_ENUM
,
321 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
325 case GL_TEXTURE_COMPARE_FUNC_ARB
:
326 if (ctx
->Extensions
.ARB_shadow
) {
327 if (texObj
->CompareFunc
== params
[0])
333 texObj
->CompareFunc
= params
[0];
341 if (ctx
->Extensions
.EXT_shadow_funcs
) {
343 texObj
->CompareFunc
= params
[0];
348 _mesa_error(ctx
, GL_INVALID_ENUM
,
349 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
353 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
357 case GL_DEPTH_TEXTURE_MODE_ARB
:
358 if (ctx
->Extensions
.ARB_depth_texture
&&
359 (params
[0] == GL_LUMINANCE
||
360 params
[0] == GL_INTENSITY
||
361 params
[0] == GL_ALPHA
)) {
362 if (texObj
->DepthMode
!= params
[0]) {
364 texObj
->DepthMode
= params
[0];
369 _mesa_error(ctx
, GL_INVALID_ENUM
,
370 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
374 #ifdef FEATURE_OES_draw_texture
375 case GL_TEXTURE_CROP_RECT_OES
:
376 texObj
->CropRect
[0] = params
[0];
377 texObj
->CropRect
[1] = params
[1];
378 texObj
->CropRect
[2] = params
[2];
379 texObj
->CropRect
[3] = params
[3];
383 case GL_TEXTURE_SWIZZLE_R_EXT
:
384 case GL_TEXTURE_SWIZZLE_G_EXT
:
385 case GL_TEXTURE_SWIZZLE_B_EXT
:
386 case GL_TEXTURE_SWIZZLE_A_EXT
:
387 if (ctx
->Extensions
.EXT_texture_swizzle
) {
388 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
389 const GLint swz
= comp_to_swizzle(params
[0]);
391 _mesa_error(ctx
, GL_INVALID_OPERATION
,
392 "glTexParameter(swizzle 0x%x)", params
[0]);
398 texObj
->Swizzle
[comp
] = params
[0];
399 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
403 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
406 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
407 if (ctx
->Extensions
.EXT_texture_swizzle
) {
410 for (comp
= 0; comp
< 4; comp
++) {
411 const GLint swz
= comp_to_swizzle(params
[comp
]);
413 texObj
->Swizzle
[comp
] = params
[comp
];
414 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
417 _mesa_error(ctx
, GL_INVALID_OPERATION
,
418 "glTexParameter(swizzle 0x%x)", params
[comp
]);
424 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
428 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
435 * Set a float-valued texture parameter
436 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
439 set_tex_parameterf(GLcontext
*ctx
,
440 struct gl_texture_object
*texObj
,
441 GLenum pname
, const GLfloat
*params
)
444 case GL_TEXTURE_MIN_LOD
:
445 if (texObj
->MinLod
== params
[0])
448 texObj
->MinLod
= params
[0];
451 case GL_TEXTURE_MAX_LOD
:
452 if (texObj
->MaxLod
== params
[0])
455 texObj
->MaxLod
= params
[0];
458 case GL_TEXTURE_PRIORITY
:
460 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
463 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
464 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
465 if (texObj
->MaxAnisotropy
== params
[0])
467 if (params
[0] < 1.0) {
468 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
472 /* clamp to max, that's what NVIDIA does */
473 texObj
->MaxAnisotropy
= MIN2(params
[0],
474 ctx
->Const
.MaxTextureMaxAnisotropy
);
478 static GLuint count
= 0;
480 _mesa_error(ctx
, GL_INVALID_ENUM
,
481 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
485 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
486 if (ctx
->Extensions
.ARB_shadow_ambient
) {
487 if (texObj
->CompareFailValue
!= params
[0]) {
489 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
494 _mesa_error(ctx
, GL_INVALID_ENUM
,
495 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
499 case GL_TEXTURE_LOD_BIAS
:
500 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
501 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
502 if (texObj
->LodBias
!= params
[0]) {
504 texObj
->LodBias
= params
[0];
511 case GL_TEXTURE_BORDER_COLOR
:
513 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
514 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
515 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
516 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
520 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
527 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
529 GLboolean need_update
;
530 struct gl_texture_object
*texObj
;
531 GET_CURRENT_CONTEXT(ctx
);
532 ASSERT_OUTSIDE_BEGIN_END(ctx
);
534 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
539 case GL_TEXTURE_MIN_FILTER
:
540 case GL_TEXTURE_MAG_FILTER
:
541 case GL_TEXTURE_WRAP_S
:
542 case GL_TEXTURE_WRAP_T
:
543 case GL_TEXTURE_WRAP_R
:
544 case GL_TEXTURE_BASE_LEVEL
:
545 case GL_TEXTURE_MAX_LEVEL
:
546 case GL_GENERATE_MIPMAP_SGIS
:
547 case GL_TEXTURE_COMPARE_MODE_ARB
:
548 case GL_TEXTURE_COMPARE_FUNC_ARB
:
549 case GL_DEPTH_TEXTURE_MODE_ARB
:
551 /* convert float param to int */
553 p
[0] = (GLint
) param
;
554 p
[1] = p
[2] = p
[3] = 0;
555 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
560 /* this will generate an error if pname is illegal */
563 p
[1] = p
[2] = p
[3] = 0.0F
;
564 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
568 if (ctx
->Driver
.TexParameter
&& need_update
) {
569 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
575 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
577 GLboolean need_update
;
578 struct gl_texture_object
*texObj
;
579 GET_CURRENT_CONTEXT(ctx
);
580 ASSERT_OUTSIDE_BEGIN_END(ctx
);
582 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
587 case GL_TEXTURE_MIN_FILTER
:
588 case GL_TEXTURE_MAG_FILTER
:
589 case GL_TEXTURE_WRAP_S
:
590 case GL_TEXTURE_WRAP_T
:
591 case GL_TEXTURE_WRAP_R
:
592 case GL_TEXTURE_BASE_LEVEL
:
593 case GL_TEXTURE_MAX_LEVEL
:
594 case GL_GENERATE_MIPMAP_SGIS
:
595 case GL_TEXTURE_COMPARE_MODE_ARB
:
596 case GL_TEXTURE_COMPARE_FUNC_ARB
:
597 case GL_DEPTH_TEXTURE_MODE_ARB
:
599 /* convert float param to int */
601 p
[0] = (GLint
) params
[0];
602 p
[1] = p
[2] = p
[3] = 0;
603 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
607 #ifdef FEATURE_OES_draw_texture
608 case GL_TEXTURE_CROP_RECT_OES
:
610 /* convert float params to int */
612 iparams
[0] = (GLint
) params
[0];
613 iparams
[1] = (GLint
) params
[1];
614 iparams
[2] = (GLint
) params
[2];
615 iparams
[3] = (GLint
) params
[3];
616 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
622 /* this will generate an error if pname is illegal */
623 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
626 if (ctx
->Driver
.TexParameter
&& need_update
) {
627 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
633 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
635 GLboolean need_update
;
636 struct gl_texture_object
*texObj
;
637 GET_CURRENT_CONTEXT(ctx
);
638 ASSERT_OUTSIDE_BEGIN_END(ctx
);
640 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
645 case GL_TEXTURE_MIN_LOD
:
646 case GL_TEXTURE_MAX_LOD
:
647 case GL_TEXTURE_PRIORITY
:
648 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
649 case GL_TEXTURE_LOD_BIAS
:
650 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
653 fparam
[0] = (GLfloat
) param
;
654 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
655 /* convert int param to float */
656 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
660 /* this will generate an error if pname is illegal */
664 iparam
[1] = iparam
[2] = iparam
[3] = 0;
665 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
669 if (ctx
->Driver
.TexParameter
&& need_update
) {
670 GLfloat fparam
= (GLfloat
) param
;
671 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
677 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
679 GLboolean need_update
;
680 struct gl_texture_object
*texObj
;
681 GET_CURRENT_CONTEXT(ctx
);
682 ASSERT_OUTSIDE_BEGIN_END(ctx
);
684 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
689 case GL_TEXTURE_BORDER_COLOR
:
691 /* convert int params to float */
693 fparams
[0] = INT_TO_FLOAT(params
[0]);
694 fparams
[1] = INT_TO_FLOAT(params
[1]);
695 fparams
[2] = INT_TO_FLOAT(params
[2]);
696 fparams
[3] = INT_TO_FLOAT(params
[3]);
697 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
700 case GL_TEXTURE_MIN_LOD
:
701 case GL_TEXTURE_MAX_LOD
:
702 case GL_TEXTURE_PRIORITY
:
703 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
704 case GL_TEXTURE_LOD_BIAS
:
705 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
707 /* convert int param to float */
709 fparams
[0] = (GLfloat
) params
[0];
710 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
711 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
715 /* this will generate an error if pname is illegal */
716 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
719 if (ctx
->Driver
.TexParameter
&& need_update
) {
721 fparams
[0] = INT_TO_FLOAT(params
[0]);
722 if (pname
== GL_TEXTURE_BORDER_COLOR
||
723 pname
== GL_TEXTURE_CROP_RECT_OES
) {
724 fparams
[1] = INT_TO_FLOAT(params
[1]);
725 fparams
[2] = INT_TO_FLOAT(params
[2]);
726 fparams
[3] = INT_TO_FLOAT(params
[3]);
728 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
734 * Set tex parameter to integer value(s). Primarily intended to set
735 * integer-valued texture border color (for integer-valued textures).
739 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
741 struct gl_texture_object
*texObj
;
742 GET_CURRENT_CONTEXT(ctx
);
743 ASSERT_OUTSIDE_BEGIN_END(ctx
);
745 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
750 case GL_TEXTURE_BORDER_COLOR
:
751 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
752 /* set the integer-valued border color */
753 COPY_4V(texObj
->BorderColor
.i
, params
);
756 _mesa_TexParameteriv(target
, pname
, params
);
759 /* XXX no driver hook for TexParameterIiv() yet */
764 * Set tex parameter to unsigned integer value(s). Primarily intended to set
765 * uint-valued texture border color (for integer-valued textures).
769 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
771 struct gl_texture_object
*texObj
;
772 GET_CURRENT_CONTEXT(ctx
);
773 ASSERT_OUTSIDE_BEGIN_END(ctx
);
775 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
780 case GL_TEXTURE_BORDER_COLOR
:
781 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
782 /* set the unsigned integer-valued border color */
783 COPY_4V(texObj
->BorderColor
.ui
, params
);
786 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
789 /* XXX no driver hook for TexParameterIuiv() yet */
796 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
797 GLenum pname
, GLfloat
*params
)
800 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
801 *params
= (GLfloat
) iparam
;
806 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
807 GLenum pname
, GLint
*params
)
809 const struct gl_texture_unit
*texUnit
;
810 struct gl_texture_object
*texObj
;
811 const struct gl_texture_image
*img
= NULL
;
815 GET_CURRENT_CONTEXT(ctx
);
816 ASSERT_OUTSIDE_BEGIN_END(ctx
);
818 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
819 _mesa_error(ctx
, GL_INVALID_OPERATION
,
820 "glGetTexLevelParameteriv(current unit)");
824 texUnit
= _mesa_get_current_tex_unit(ctx
);
826 /* this will catch bad target values */
827 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
828 if (maxLevels
== 0) {
829 _mesa_error(ctx
, GL_INVALID_ENUM
,
830 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
834 if (level
< 0 || level
>= maxLevels
) {
835 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
839 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
840 _mesa_lock_texture(ctx
, texObj
);
842 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
843 if (!img
|| !img
->TexFormat
) {
844 /* undefined texture image */
845 if (pname
== GL_TEXTURE_COMPONENTS
)
852 texFormat
= img
->TexFormat
;
854 isProxy
= _mesa_is_proxy_texture(target
);
857 case GL_TEXTURE_WIDTH
:
858 *params
= img
->Width
;
860 case GL_TEXTURE_HEIGHT
:
861 *params
= img
->Height
;
863 case GL_TEXTURE_DEPTH
:
864 *params
= img
->Depth
;
866 case GL_TEXTURE_INTERNAL_FORMAT
:
867 if (_mesa_is_format_compressed(img
->TexFormat
)) {
868 /* need to return the actual compressed format */
869 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
872 /* return the user's requested internal format */
873 *params
= img
->InternalFormat
;
876 case GL_TEXTURE_BORDER
:
877 *params
= img
->Border
;
879 case GL_TEXTURE_RED_SIZE
:
880 case GL_TEXTURE_GREEN_SIZE
:
881 case GL_TEXTURE_BLUE_SIZE
:
882 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
883 *params
= _mesa_get_format_bits(texFormat
, pname
);
887 case GL_TEXTURE_ALPHA_SIZE
:
888 if (img
->_BaseFormat
== GL_ALPHA
||
889 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
890 img
->_BaseFormat
== GL_RGBA
)
891 *params
= _mesa_get_format_bits(texFormat
, pname
);
895 case GL_TEXTURE_INTENSITY_SIZE
:
896 if (img
->_BaseFormat
!= GL_INTENSITY
)
899 *params
= _mesa_get_format_bits(texFormat
, pname
);
901 /* intensity probably stored as rgb texture */
902 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
903 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
907 case GL_TEXTURE_LUMINANCE_SIZE
:
908 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
909 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
912 *params
= _mesa_get_format_bits(texFormat
, pname
);
914 /* luminance probably stored as rgb texture */
915 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
916 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
920 case GL_TEXTURE_INDEX_SIZE_EXT
:
921 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
922 *params
= _mesa_get_format_bits(texFormat
, pname
);
926 case GL_TEXTURE_DEPTH_SIZE_ARB
:
927 if (ctx
->Extensions
.ARB_depth_texture
)
928 *params
= _mesa_get_format_bits(texFormat
, pname
);
930 _mesa_error(ctx
, GL_INVALID_ENUM
,
931 "glGetTexLevelParameter[if]v(pname)");
933 case GL_TEXTURE_STENCIL_SIZE_EXT
:
934 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
935 ctx
->Extensions
.ARB_framebuffer_object
) {
936 *params
= _mesa_get_format_bits(texFormat
, pname
);
939 _mesa_error(ctx
, GL_INVALID_ENUM
,
940 "glGetTexLevelParameter[if]v(pname)");
944 /* GL_ARB_texture_compression */
945 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
946 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
947 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
948 img
->Height
, img
->Depth
);
951 _mesa_error(ctx
, GL_INVALID_OPERATION
,
952 "glGetTexLevelParameter[if]v(pname)");
955 case GL_TEXTURE_COMPRESSED
:
956 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
959 /* GL_ARB_texture_float */
960 case GL_TEXTURE_RED_TYPE_ARB
:
961 if (ctx
->Extensions
.ARB_texture_float
) {
962 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
963 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
966 _mesa_error(ctx
, GL_INVALID_ENUM
,
967 "glGetTexLevelParameter[if]v(pname)");
970 case GL_TEXTURE_GREEN_TYPE_ARB
:
971 if (ctx
->Extensions
.ARB_texture_float
) {
972 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
973 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
976 _mesa_error(ctx
, GL_INVALID_ENUM
,
977 "glGetTexLevelParameter[if]v(pname)");
980 case GL_TEXTURE_BLUE_TYPE_ARB
:
981 if (ctx
->Extensions
.ARB_texture_float
) {
982 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
983 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
986 _mesa_error(ctx
, GL_INVALID_ENUM
,
987 "glGetTexLevelParameter[if]v(pname)");
990 case GL_TEXTURE_ALPHA_TYPE_ARB
:
991 if (ctx
->Extensions
.ARB_texture_float
) {
992 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
993 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
996 _mesa_error(ctx
, GL_INVALID_ENUM
,
997 "glGetTexLevelParameter[if]v(pname)");
1000 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1001 if (ctx
->Extensions
.ARB_texture_float
) {
1002 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1003 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1006 _mesa_error(ctx
, GL_INVALID_ENUM
,
1007 "glGetTexLevelParameter[if]v(pname)");
1010 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1011 if (ctx
->Extensions
.ARB_texture_float
) {
1012 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1013 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1016 _mesa_error(ctx
, GL_INVALID_ENUM
,
1017 "glGetTexLevelParameter[if]v(pname)");
1020 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1021 if (ctx
->Extensions
.ARB_texture_float
) {
1022 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1023 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1026 _mesa_error(ctx
, GL_INVALID_ENUM
,
1027 "glGetTexLevelParameter[if]v(pname)");
1032 _mesa_error(ctx
, GL_INVALID_ENUM
,
1033 "glGetTexLevelParameter[if]v(pname)");
1037 _mesa_unlock_texture(ctx
, texObj
);
1043 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1045 struct gl_texture_object
*obj
;
1046 GLboolean error
= GL_FALSE
;
1047 GET_CURRENT_CONTEXT(ctx
);
1048 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1050 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1054 _mesa_lock_texture(ctx
, obj
);
1056 case GL_TEXTURE_MAG_FILTER
:
1057 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1059 case GL_TEXTURE_MIN_FILTER
:
1060 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1062 case GL_TEXTURE_WRAP_S
:
1063 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1065 case GL_TEXTURE_WRAP_T
:
1066 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1068 case GL_TEXTURE_WRAP_R
:
1069 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1071 case GL_TEXTURE_BORDER_COLOR
:
1072 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1073 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1074 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1075 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1077 case GL_TEXTURE_RESIDENT
:
1080 if (ctx
->Driver
.IsTextureResident
)
1081 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1084 *params
= ENUM_TO_FLOAT(resident
);
1087 case GL_TEXTURE_PRIORITY
:
1088 *params
= obj
->Priority
;
1090 case GL_TEXTURE_MIN_LOD
:
1091 *params
= obj
->MinLod
;
1093 case GL_TEXTURE_MAX_LOD
:
1094 *params
= obj
->MaxLod
;
1096 case GL_TEXTURE_BASE_LEVEL
:
1097 *params
= (GLfloat
) obj
->BaseLevel
;
1099 case GL_TEXTURE_MAX_LEVEL
:
1100 *params
= (GLfloat
) obj
->MaxLevel
;
1102 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1103 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1104 *params
= obj
->MaxAnisotropy
;
1109 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1110 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1111 *params
= obj
->CompareFailValue
;
1116 case GL_GENERATE_MIPMAP_SGIS
:
1117 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1118 *params
= (GLfloat
) obj
->GenerateMipmap
;
1123 case GL_TEXTURE_COMPARE_MODE_ARB
:
1124 if (ctx
->Extensions
.ARB_shadow
) {
1125 *params
= (GLfloat
) obj
->CompareMode
;
1130 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1131 if (ctx
->Extensions
.ARB_shadow
) {
1132 *params
= (GLfloat
) obj
->CompareFunc
;
1137 case GL_DEPTH_TEXTURE_MODE_ARB
:
1138 if (ctx
->Extensions
.ARB_depth_texture
) {
1139 *params
= (GLfloat
) obj
->DepthMode
;
1144 case GL_TEXTURE_LOD_BIAS
:
1145 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1146 *params
= obj
->LodBias
;
1151 #ifdef FEATURE_OES_draw_texture
1152 case GL_TEXTURE_CROP_RECT_OES
:
1153 params
[0] = obj
->CropRect
[0];
1154 params
[1] = obj
->CropRect
[1];
1155 params
[2] = obj
->CropRect
[2];
1156 params
[3] = obj
->CropRect
[3];
1160 case GL_TEXTURE_SWIZZLE_R_EXT
:
1161 case GL_TEXTURE_SWIZZLE_G_EXT
:
1162 case GL_TEXTURE_SWIZZLE_B_EXT
:
1163 case GL_TEXTURE_SWIZZLE_A_EXT
:
1164 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1165 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1166 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1173 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1174 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1176 for (comp
= 0; comp
< 4; comp
++) {
1177 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1191 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1194 _mesa_unlock_texture(ctx
, obj
);
1199 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1201 struct gl_texture_object
*obj
;
1202 GLboolean error
= GL_FALSE
;
1203 GET_CURRENT_CONTEXT(ctx
);
1204 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1206 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1210 _mesa_lock_texture(ctx
, obj
);
1212 case GL_TEXTURE_MAG_FILTER
:
1213 *params
= (GLint
) obj
->MagFilter
;
1215 case GL_TEXTURE_MIN_FILTER
:
1216 *params
= (GLint
) obj
->MinFilter
;
1218 case GL_TEXTURE_WRAP_S
:
1219 *params
= (GLint
) obj
->WrapS
;
1221 case GL_TEXTURE_WRAP_T
:
1222 *params
= (GLint
) obj
->WrapT
;
1224 case GL_TEXTURE_WRAP_R
:
1225 *params
= (GLint
) obj
->WrapR
;
1227 case GL_TEXTURE_BORDER_COLOR
:
1230 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1231 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1232 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1233 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1234 params
[0] = FLOAT_TO_INT(b
[0]);
1235 params
[1] = FLOAT_TO_INT(b
[1]);
1236 params
[2] = FLOAT_TO_INT(b
[2]);
1237 params
[3] = FLOAT_TO_INT(b
[3]);
1240 case GL_TEXTURE_RESIDENT
:
1243 if (ctx
->Driver
.IsTextureResident
)
1244 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1247 *params
= (GLint
) resident
;
1250 case GL_TEXTURE_PRIORITY
:
1251 *params
= FLOAT_TO_INT(obj
->Priority
);
1253 case GL_TEXTURE_MIN_LOD
:
1254 *params
= (GLint
) obj
->MinLod
;
1256 case GL_TEXTURE_MAX_LOD
:
1257 *params
= (GLint
) obj
->MaxLod
;
1259 case GL_TEXTURE_BASE_LEVEL
:
1260 *params
= obj
->BaseLevel
;
1262 case GL_TEXTURE_MAX_LEVEL
:
1263 *params
= obj
->MaxLevel
;
1265 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1266 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1267 *params
= (GLint
) obj
->MaxAnisotropy
;
1273 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1274 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1275 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1281 case GL_GENERATE_MIPMAP_SGIS
:
1282 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1283 *params
= (GLint
) obj
->GenerateMipmap
;
1289 case GL_TEXTURE_COMPARE_MODE_ARB
:
1290 if (ctx
->Extensions
.ARB_shadow
) {
1291 *params
= (GLint
) obj
->CompareMode
;
1297 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1298 if (ctx
->Extensions
.ARB_shadow
) {
1299 *params
= (GLint
) obj
->CompareFunc
;
1305 case GL_DEPTH_TEXTURE_MODE_ARB
:
1306 if (ctx
->Extensions
.ARB_depth_texture
) {
1307 *params
= (GLint
) obj
->DepthMode
;
1313 case GL_TEXTURE_LOD_BIAS
:
1314 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1315 *params
= (GLint
) obj
->LodBias
;
1321 #ifdef FEATURE_OES_draw_texture
1322 case GL_TEXTURE_CROP_RECT_OES
:
1323 params
[0] = obj
->CropRect
[0];
1324 params
[1] = obj
->CropRect
[1];
1325 params
[2] = obj
->CropRect
[2];
1326 params
[3] = obj
->CropRect
[3];
1329 case GL_TEXTURE_SWIZZLE_R_EXT
:
1330 case GL_TEXTURE_SWIZZLE_G_EXT
:
1331 case GL_TEXTURE_SWIZZLE_B_EXT
:
1332 case GL_TEXTURE_SWIZZLE_A_EXT
:
1333 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1334 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1335 *params
= obj
->Swizzle
[comp
];
1342 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1343 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1344 COPY_4V(params
, obj
->Swizzle
);
1352 ; /* silence warnings */
1356 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1359 _mesa_unlock_texture(ctx
, obj
);
1363 /** New in GL 3.0 */
1365 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1367 struct gl_texture_object
*texObj
;
1368 GET_CURRENT_CONTEXT(ctx
);
1369 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1371 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1374 case GL_TEXTURE_BORDER_COLOR
:
1375 COPY_4V(params
, texObj
->BorderColor
.i
);
1378 _mesa_GetTexParameteriv(target
, pname
, params
);
1383 /** New in GL 3.0 */
1385 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1387 struct gl_texture_object
*texObj
;
1388 GET_CURRENT_CONTEXT(ctx
);
1389 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1391 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1394 case GL_TEXTURE_BORDER_COLOR
:
1395 COPY_4V(params
, texObj
->BorderColor
.i
);
1400 _mesa_GetTexParameteriv(target
, pname
, ip
);
1402 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1403 pname
== GL_TEXTURE_CROP_RECT_OES
) {