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 "program/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 (texObj
->GenerateMipmap
!= params
[0]) {
296 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
301 case GL_TEXTURE_COMPARE_MODE_ARB
:
302 if (ctx
->Extensions
.ARB_shadow
&&
303 (params
[0] == GL_NONE
||
304 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
305 if (texObj
->CompareMode
!= params
[0]) {
307 texObj
->CompareMode
= params
[0];
313 _mesa_error(ctx
, GL_INVALID_ENUM
,
314 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
318 case GL_TEXTURE_COMPARE_FUNC_ARB
:
319 if (ctx
->Extensions
.ARB_shadow
) {
320 if (texObj
->CompareFunc
== params
[0])
326 texObj
->CompareFunc
= params
[0];
334 if (ctx
->Extensions
.EXT_shadow_funcs
) {
336 texObj
->CompareFunc
= params
[0];
341 _mesa_error(ctx
, GL_INVALID_ENUM
,
342 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
346 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
350 case GL_DEPTH_TEXTURE_MODE_ARB
:
351 if (ctx
->Extensions
.ARB_depth_texture
&&
352 (params
[0] == GL_LUMINANCE
||
353 params
[0] == GL_INTENSITY
||
354 params
[0] == GL_ALPHA
)) {
355 if (texObj
->DepthMode
!= params
[0]) {
357 texObj
->DepthMode
= params
[0];
362 _mesa_error(ctx
, GL_INVALID_ENUM
,
363 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
367 #if FEATURE_OES_draw_texture
368 case GL_TEXTURE_CROP_RECT_OES
:
369 texObj
->CropRect
[0] = params
[0];
370 texObj
->CropRect
[1] = params
[1];
371 texObj
->CropRect
[2] = params
[2];
372 texObj
->CropRect
[3] = params
[3];
376 case GL_TEXTURE_SWIZZLE_R_EXT
:
377 case GL_TEXTURE_SWIZZLE_G_EXT
:
378 case GL_TEXTURE_SWIZZLE_B_EXT
:
379 case GL_TEXTURE_SWIZZLE_A_EXT
:
380 if (ctx
->Extensions
.EXT_texture_swizzle
) {
381 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
382 const GLint swz
= comp_to_swizzle(params
[0]);
384 _mesa_error(ctx
, GL_INVALID_OPERATION
,
385 "glTexParameter(swizzle 0x%x)", params
[0]);
391 texObj
->Swizzle
[comp
] = params
[0];
392 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
396 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
399 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
400 if (ctx
->Extensions
.EXT_texture_swizzle
) {
403 for (comp
= 0; comp
< 4; comp
++) {
404 const GLint swz
= comp_to_swizzle(params
[comp
]);
406 texObj
->Swizzle
[comp
] = params
[comp
];
407 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
410 _mesa_error(ctx
, GL_INVALID_OPERATION
,
411 "glTexParameter(swizzle 0x%x)", params
[comp
]);
417 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
421 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
428 * Set a float-valued texture parameter
429 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
432 set_tex_parameterf(GLcontext
*ctx
,
433 struct gl_texture_object
*texObj
,
434 GLenum pname
, const GLfloat
*params
)
437 case GL_TEXTURE_MIN_LOD
:
438 if (texObj
->MinLod
== params
[0])
441 texObj
->MinLod
= params
[0];
444 case GL_TEXTURE_MAX_LOD
:
445 if (texObj
->MaxLod
== params
[0])
448 texObj
->MaxLod
= params
[0];
451 case GL_TEXTURE_PRIORITY
:
453 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
456 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
457 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
458 if (texObj
->MaxAnisotropy
== params
[0])
460 if (params
[0] < 1.0) {
461 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
465 /* clamp to max, that's what NVIDIA does */
466 texObj
->MaxAnisotropy
= MIN2(params
[0],
467 ctx
->Const
.MaxTextureMaxAnisotropy
);
471 static GLuint count
= 0;
473 _mesa_error(ctx
, GL_INVALID_ENUM
,
474 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
478 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
479 if (ctx
->Extensions
.ARB_shadow_ambient
) {
480 if (texObj
->CompareFailValue
!= params
[0]) {
482 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
487 _mesa_error(ctx
, GL_INVALID_ENUM
,
488 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
492 case GL_TEXTURE_LOD_BIAS
:
493 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
494 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
495 if (texObj
->LodBias
!= params
[0]) {
497 texObj
->LodBias
= params
[0];
504 case GL_TEXTURE_BORDER_COLOR
:
506 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
507 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
508 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
509 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
520 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
522 GLboolean need_update
;
523 struct gl_texture_object
*texObj
;
524 GET_CURRENT_CONTEXT(ctx
);
525 ASSERT_OUTSIDE_BEGIN_END(ctx
);
527 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
532 case GL_TEXTURE_MIN_FILTER
:
533 case GL_TEXTURE_MAG_FILTER
:
534 case GL_TEXTURE_WRAP_S
:
535 case GL_TEXTURE_WRAP_T
:
536 case GL_TEXTURE_WRAP_R
:
537 case GL_TEXTURE_BASE_LEVEL
:
538 case GL_TEXTURE_MAX_LEVEL
:
539 case GL_GENERATE_MIPMAP_SGIS
:
540 case GL_TEXTURE_COMPARE_MODE_ARB
:
541 case GL_TEXTURE_COMPARE_FUNC_ARB
:
542 case GL_DEPTH_TEXTURE_MODE_ARB
:
544 /* convert float param to int */
546 p
[0] = (GLint
) param
;
547 p
[1] = p
[2] = p
[3] = 0;
548 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
553 /* this will generate an error if pname is illegal */
556 p
[1] = p
[2] = p
[3] = 0.0F
;
557 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
561 if (ctx
->Driver
.TexParameter
&& need_update
) {
562 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
568 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
570 GLboolean need_update
;
571 struct gl_texture_object
*texObj
;
572 GET_CURRENT_CONTEXT(ctx
);
573 ASSERT_OUTSIDE_BEGIN_END(ctx
);
575 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
580 case GL_TEXTURE_MIN_FILTER
:
581 case GL_TEXTURE_MAG_FILTER
:
582 case GL_TEXTURE_WRAP_S
:
583 case GL_TEXTURE_WRAP_T
:
584 case GL_TEXTURE_WRAP_R
:
585 case GL_TEXTURE_BASE_LEVEL
:
586 case GL_TEXTURE_MAX_LEVEL
:
587 case GL_GENERATE_MIPMAP_SGIS
:
588 case GL_TEXTURE_COMPARE_MODE_ARB
:
589 case GL_TEXTURE_COMPARE_FUNC_ARB
:
590 case GL_DEPTH_TEXTURE_MODE_ARB
:
592 /* convert float param to int */
594 p
[0] = (GLint
) params
[0];
595 p
[1] = p
[2] = p
[3] = 0;
596 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
600 #if FEATURE_OES_draw_texture
601 case GL_TEXTURE_CROP_RECT_OES
:
603 /* convert float params to int */
605 iparams
[0] = (GLint
) params
[0];
606 iparams
[1] = (GLint
) params
[1];
607 iparams
[2] = (GLint
) params
[2];
608 iparams
[3] = (GLint
) params
[3];
609 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
615 /* this will generate an error if pname is illegal */
616 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
619 if (ctx
->Driver
.TexParameter
&& need_update
) {
620 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
626 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
628 GLboolean need_update
;
629 struct gl_texture_object
*texObj
;
630 GET_CURRENT_CONTEXT(ctx
);
631 ASSERT_OUTSIDE_BEGIN_END(ctx
);
633 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
638 case GL_TEXTURE_MIN_LOD
:
639 case GL_TEXTURE_MAX_LOD
:
640 case GL_TEXTURE_PRIORITY
:
641 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
642 case GL_TEXTURE_LOD_BIAS
:
643 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
646 fparam
[0] = (GLfloat
) param
;
647 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
648 /* convert int param to float */
649 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
653 /* this will generate an error if pname is illegal */
657 iparam
[1] = iparam
[2] = iparam
[3] = 0;
658 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
662 if (ctx
->Driver
.TexParameter
&& need_update
) {
663 GLfloat fparam
= (GLfloat
) param
;
664 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
670 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
672 GLboolean need_update
;
673 struct gl_texture_object
*texObj
;
674 GET_CURRENT_CONTEXT(ctx
);
675 ASSERT_OUTSIDE_BEGIN_END(ctx
);
677 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
682 case GL_TEXTURE_BORDER_COLOR
:
684 /* convert int params to float */
686 fparams
[0] = INT_TO_FLOAT(params
[0]);
687 fparams
[1] = INT_TO_FLOAT(params
[1]);
688 fparams
[2] = INT_TO_FLOAT(params
[2]);
689 fparams
[3] = INT_TO_FLOAT(params
[3]);
690 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
693 case GL_TEXTURE_MIN_LOD
:
694 case GL_TEXTURE_MAX_LOD
:
695 case GL_TEXTURE_PRIORITY
:
696 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
697 case GL_TEXTURE_LOD_BIAS
:
698 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
700 /* convert int param to float */
702 fparams
[0] = (GLfloat
) params
[0];
703 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
704 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
708 /* this will generate an error if pname is illegal */
709 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
712 if (ctx
->Driver
.TexParameter
&& need_update
) {
714 fparams
[0] = INT_TO_FLOAT(params
[0]);
715 if (pname
== GL_TEXTURE_BORDER_COLOR
||
716 pname
== GL_TEXTURE_CROP_RECT_OES
) {
717 fparams
[1] = INT_TO_FLOAT(params
[1]);
718 fparams
[2] = INT_TO_FLOAT(params
[2]);
719 fparams
[3] = INT_TO_FLOAT(params
[3]);
721 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
727 * Set tex parameter to integer value(s). Primarily intended to set
728 * integer-valued texture border color (for integer-valued textures).
732 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
734 struct gl_texture_object
*texObj
;
735 GET_CURRENT_CONTEXT(ctx
);
736 ASSERT_OUTSIDE_BEGIN_END(ctx
);
738 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
743 case GL_TEXTURE_BORDER_COLOR
:
744 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
745 /* set the integer-valued border color */
746 COPY_4V(texObj
->BorderColor
.i
, params
);
749 _mesa_TexParameteriv(target
, pname
, params
);
752 /* XXX no driver hook for TexParameterIiv() yet */
757 * Set tex parameter to unsigned integer value(s). Primarily intended to set
758 * uint-valued texture border color (for integer-valued textures).
762 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
764 struct gl_texture_object
*texObj
;
765 GET_CURRENT_CONTEXT(ctx
);
766 ASSERT_OUTSIDE_BEGIN_END(ctx
);
768 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
773 case GL_TEXTURE_BORDER_COLOR
:
774 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
775 /* set the unsigned integer-valued border color */
776 COPY_4V(texObj
->BorderColor
.ui
, params
);
779 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
782 /* XXX no driver hook for TexParameterIuiv() yet */
789 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
790 GLenum pname
, GLfloat
*params
)
793 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
794 *params
= (GLfloat
) iparam
;
799 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
800 GLenum pname
, GLint
*params
)
802 const struct gl_texture_unit
*texUnit
;
803 struct gl_texture_object
*texObj
;
804 const struct gl_texture_image
*img
= NULL
;
808 GET_CURRENT_CONTEXT(ctx
);
809 ASSERT_OUTSIDE_BEGIN_END(ctx
);
811 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
812 _mesa_error(ctx
, GL_INVALID_OPERATION
,
813 "glGetTexLevelParameteriv(current unit)");
817 texUnit
= _mesa_get_current_tex_unit(ctx
);
819 /* this will catch bad target values */
820 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
821 if (maxLevels
== 0) {
822 _mesa_error(ctx
, GL_INVALID_ENUM
,
823 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
827 if (level
< 0 || level
>= maxLevels
) {
828 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
832 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
833 _mesa_lock_texture(ctx
, texObj
);
835 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
836 if (!img
|| !img
->TexFormat
) {
837 /* undefined texture image */
838 if (pname
== GL_TEXTURE_COMPONENTS
)
845 texFormat
= img
->TexFormat
;
847 isProxy
= _mesa_is_proxy_texture(target
);
850 case GL_TEXTURE_WIDTH
:
851 *params
= img
->Width
;
853 case GL_TEXTURE_HEIGHT
:
854 *params
= img
->Height
;
856 case GL_TEXTURE_DEPTH
:
857 *params
= img
->Depth
;
859 case GL_TEXTURE_INTERNAL_FORMAT
:
860 if (_mesa_is_format_compressed(img
->TexFormat
)) {
861 /* need to return the actual compressed format */
862 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
865 /* return the user's requested internal format */
866 *params
= img
->InternalFormat
;
869 case GL_TEXTURE_BORDER
:
870 *params
= img
->Border
;
872 case GL_TEXTURE_RED_SIZE
:
873 case GL_TEXTURE_GREEN_SIZE
:
874 case GL_TEXTURE_BLUE_SIZE
:
875 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
876 *params
= _mesa_get_format_bits(texFormat
, pname
);
880 case GL_TEXTURE_ALPHA_SIZE
:
881 if (img
->_BaseFormat
== GL_ALPHA
||
882 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
883 img
->_BaseFormat
== GL_RGBA
)
884 *params
= _mesa_get_format_bits(texFormat
, pname
);
888 case GL_TEXTURE_INTENSITY_SIZE
:
889 if (img
->_BaseFormat
!= GL_INTENSITY
)
892 *params
= _mesa_get_format_bits(texFormat
, pname
);
894 /* intensity probably stored as rgb texture */
895 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
896 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
900 case GL_TEXTURE_LUMINANCE_SIZE
:
901 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
902 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
905 *params
= _mesa_get_format_bits(texFormat
, pname
);
907 /* luminance probably stored as rgb texture */
908 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
909 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
913 case GL_TEXTURE_INDEX_SIZE_EXT
:
914 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
915 *params
= _mesa_get_format_bits(texFormat
, pname
);
919 case GL_TEXTURE_DEPTH_SIZE_ARB
:
920 if (ctx
->Extensions
.ARB_depth_texture
)
921 *params
= _mesa_get_format_bits(texFormat
, pname
);
923 _mesa_error(ctx
, GL_INVALID_ENUM
,
924 "glGetTexLevelParameter[if]v(pname)");
926 case GL_TEXTURE_STENCIL_SIZE_EXT
:
927 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
928 ctx
->Extensions
.ARB_framebuffer_object
) {
929 *params
= _mesa_get_format_bits(texFormat
, pname
);
932 _mesa_error(ctx
, GL_INVALID_ENUM
,
933 "glGetTexLevelParameter[if]v(pname)");
936 case GL_TEXTURE_SHARED_SIZE
:
937 if (ctx
->VersionMajor
>= 3) {
938 /* XXX return number of exponent bits for shared exponent texture
939 * formats, like GL_RGB9_E5.
944 _mesa_error(ctx
, GL_INVALID_ENUM
,
945 "glGetTexLevelParameter[if]v(pname)");
949 /* GL_ARB_texture_compression */
950 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
951 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
952 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
953 img
->Height
, img
->Depth
);
956 _mesa_error(ctx
, GL_INVALID_OPERATION
,
957 "glGetTexLevelParameter[if]v(pname)");
960 case GL_TEXTURE_COMPRESSED
:
961 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
964 /* GL_ARB_texture_float */
965 case GL_TEXTURE_RED_TYPE_ARB
:
966 if (ctx
->Extensions
.ARB_texture_float
) {
967 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
968 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
971 _mesa_error(ctx
, GL_INVALID_ENUM
,
972 "glGetTexLevelParameter[if]v(pname)");
975 case GL_TEXTURE_GREEN_TYPE_ARB
:
976 if (ctx
->Extensions
.ARB_texture_float
) {
977 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
978 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
981 _mesa_error(ctx
, GL_INVALID_ENUM
,
982 "glGetTexLevelParameter[if]v(pname)");
985 case GL_TEXTURE_BLUE_TYPE_ARB
:
986 if (ctx
->Extensions
.ARB_texture_float
) {
987 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
988 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
991 _mesa_error(ctx
, GL_INVALID_ENUM
,
992 "glGetTexLevelParameter[if]v(pname)");
995 case GL_TEXTURE_ALPHA_TYPE_ARB
:
996 if (ctx
->Extensions
.ARB_texture_float
) {
997 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
998 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1001 _mesa_error(ctx
, GL_INVALID_ENUM
,
1002 "glGetTexLevelParameter[if]v(pname)");
1005 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1006 if (ctx
->Extensions
.ARB_texture_float
) {
1007 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1008 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1011 _mesa_error(ctx
, GL_INVALID_ENUM
,
1012 "glGetTexLevelParameter[if]v(pname)");
1015 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1016 if (ctx
->Extensions
.ARB_texture_float
) {
1017 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1018 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1021 _mesa_error(ctx
, GL_INVALID_ENUM
,
1022 "glGetTexLevelParameter[if]v(pname)");
1025 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1026 if (ctx
->Extensions
.ARB_texture_float
) {
1027 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1028 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1031 _mesa_error(ctx
, GL_INVALID_ENUM
,
1032 "glGetTexLevelParameter[if]v(pname)");
1037 _mesa_error(ctx
, GL_INVALID_ENUM
,
1038 "glGetTexLevelParameter[if]v(pname)");
1042 _mesa_unlock_texture(ctx
, texObj
);
1048 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1050 struct gl_texture_object
*obj
;
1051 GLboolean error
= GL_FALSE
;
1052 GET_CURRENT_CONTEXT(ctx
);
1053 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1055 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1059 _mesa_lock_texture(ctx
, obj
);
1061 case GL_TEXTURE_MAG_FILTER
:
1062 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1064 case GL_TEXTURE_MIN_FILTER
:
1065 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1067 case GL_TEXTURE_WRAP_S
:
1068 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1070 case GL_TEXTURE_WRAP_T
:
1071 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1073 case GL_TEXTURE_WRAP_R
:
1074 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1076 case GL_TEXTURE_BORDER_COLOR
:
1077 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1078 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1079 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1080 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1082 case GL_TEXTURE_RESIDENT
:
1085 if (ctx
->Driver
.IsTextureResident
)
1086 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1089 *params
= ENUM_TO_FLOAT(resident
);
1092 case GL_TEXTURE_PRIORITY
:
1093 *params
= obj
->Priority
;
1095 case GL_TEXTURE_MIN_LOD
:
1096 *params
= obj
->MinLod
;
1098 case GL_TEXTURE_MAX_LOD
:
1099 *params
= obj
->MaxLod
;
1101 case GL_TEXTURE_BASE_LEVEL
:
1102 *params
= (GLfloat
) obj
->BaseLevel
;
1104 case GL_TEXTURE_MAX_LEVEL
:
1105 *params
= (GLfloat
) obj
->MaxLevel
;
1107 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1108 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1109 *params
= obj
->MaxAnisotropy
;
1114 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1115 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1116 *params
= obj
->CompareFailValue
;
1121 case GL_GENERATE_MIPMAP_SGIS
:
1122 *params
= (GLfloat
) obj
->GenerateMipmap
;
1124 case GL_TEXTURE_COMPARE_MODE_ARB
:
1125 if (ctx
->Extensions
.ARB_shadow
) {
1126 *params
= (GLfloat
) obj
->CompareMode
;
1131 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1132 if (ctx
->Extensions
.ARB_shadow
) {
1133 *params
= (GLfloat
) obj
->CompareFunc
;
1138 case GL_DEPTH_TEXTURE_MODE_ARB
:
1139 if (ctx
->Extensions
.ARB_depth_texture
) {
1140 *params
= (GLfloat
) obj
->DepthMode
;
1145 case GL_TEXTURE_LOD_BIAS
:
1146 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1147 *params
= obj
->LodBias
;
1152 #if FEATURE_OES_draw_texture
1153 case GL_TEXTURE_CROP_RECT_OES
:
1154 params
[0] = obj
->CropRect
[0];
1155 params
[1] = obj
->CropRect
[1];
1156 params
[2] = obj
->CropRect
[2];
1157 params
[3] = obj
->CropRect
[3];
1161 case GL_TEXTURE_SWIZZLE_R_EXT
:
1162 case GL_TEXTURE_SWIZZLE_G_EXT
:
1163 case GL_TEXTURE_SWIZZLE_B_EXT
:
1164 case GL_TEXTURE_SWIZZLE_A_EXT
:
1165 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1166 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1167 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1174 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1175 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1177 for (comp
= 0; comp
< 4; comp
++) {
1178 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1192 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1195 _mesa_unlock_texture(ctx
, obj
);
1200 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1202 struct gl_texture_object
*obj
;
1203 GLboolean error
= GL_FALSE
;
1204 GET_CURRENT_CONTEXT(ctx
);
1205 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1207 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1211 _mesa_lock_texture(ctx
, obj
);
1213 case GL_TEXTURE_MAG_FILTER
:
1214 *params
= (GLint
) obj
->MagFilter
;
1216 case GL_TEXTURE_MIN_FILTER
:
1217 *params
= (GLint
) obj
->MinFilter
;
1219 case GL_TEXTURE_WRAP_S
:
1220 *params
= (GLint
) obj
->WrapS
;
1222 case GL_TEXTURE_WRAP_T
:
1223 *params
= (GLint
) obj
->WrapT
;
1225 case GL_TEXTURE_WRAP_R
:
1226 *params
= (GLint
) obj
->WrapR
;
1228 case GL_TEXTURE_BORDER_COLOR
:
1231 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1232 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1233 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1234 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1235 params
[0] = FLOAT_TO_INT(b
[0]);
1236 params
[1] = FLOAT_TO_INT(b
[1]);
1237 params
[2] = FLOAT_TO_INT(b
[2]);
1238 params
[3] = FLOAT_TO_INT(b
[3]);
1241 case GL_TEXTURE_RESIDENT
:
1244 if (ctx
->Driver
.IsTextureResident
)
1245 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1248 *params
= (GLint
) resident
;
1251 case GL_TEXTURE_PRIORITY
:
1252 *params
= FLOAT_TO_INT(obj
->Priority
);
1254 case GL_TEXTURE_MIN_LOD
:
1255 *params
= (GLint
) obj
->MinLod
;
1257 case GL_TEXTURE_MAX_LOD
:
1258 *params
= (GLint
) obj
->MaxLod
;
1260 case GL_TEXTURE_BASE_LEVEL
:
1261 *params
= obj
->BaseLevel
;
1263 case GL_TEXTURE_MAX_LEVEL
:
1264 *params
= obj
->MaxLevel
;
1266 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1267 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1268 *params
= (GLint
) obj
->MaxAnisotropy
;
1274 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1275 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1276 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1282 case GL_GENERATE_MIPMAP_SGIS
:
1283 *params
= (GLint
) obj
->GenerateMipmap
;
1285 case GL_TEXTURE_COMPARE_MODE_ARB
:
1286 if (ctx
->Extensions
.ARB_shadow
) {
1287 *params
= (GLint
) obj
->CompareMode
;
1293 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1294 if (ctx
->Extensions
.ARB_shadow
) {
1295 *params
= (GLint
) obj
->CompareFunc
;
1301 case GL_DEPTH_TEXTURE_MODE_ARB
:
1302 if (ctx
->Extensions
.ARB_depth_texture
) {
1303 *params
= (GLint
) obj
->DepthMode
;
1309 case GL_TEXTURE_LOD_BIAS
:
1310 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1311 *params
= (GLint
) obj
->LodBias
;
1317 #if FEATURE_OES_draw_texture
1318 case GL_TEXTURE_CROP_RECT_OES
:
1319 params
[0] = obj
->CropRect
[0];
1320 params
[1] = obj
->CropRect
[1];
1321 params
[2] = obj
->CropRect
[2];
1322 params
[3] = obj
->CropRect
[3];
1325 case GL_TEXTURE_SWIZZLE_R_EXT
:
1326 case GL_TEXTURE_SWIZZLE_G_EXT
:
1327 case GL_TEXTURE_SWIZZLE_B_EXT
:
1328 case GL_TEXTURE_SWIZZLE_A_EXT
:
1329 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1330 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1331 *params
= obj
->Swizzle
[comp
];
1338 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1339 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1340 COPY_4V(params
, obj
->Swizzle
);
1348 ; /* silence warnings */
1352 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1355 _mesa_unlock_texture(ctx
, obj
);
1359 /** New in GL 3.0 */
1361 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1363 struct gl_texture_object
*texObj
;
1364 GET_CURRENT_CONTEXT(ctx
);
1365 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1367 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1370 case GL_TEXTURE_BORDER_COLOR
:
1371 COPY_4V(params
, texObj
->BorderColor
.i
);
1374 _mesa_GetTexParameteriv(target
, pname
, params
);
1379 /** New in GL 3.0 */
1381 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1383 struct gl_texture_object
*texObj
;
1384 GET_CURRENT_CONTEXT(ctx
);
1385 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1387 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1390 case GL_TEXTURE_BORDER_COLOR
:
1391 COPY_4V(params
, texObj
->BorderColor
.i
);
1396 _mesa_GetTexParameteriv(target
, pname
, ip
);
1398 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1399 pname
== GL_TEXTURE_CROP_RECT_OES
) {