2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * glTexParameter-related functions
33 #include "main/glheader.h"
34 #include "main/colormac.h"
35 #include "main/context.h"
36 #include "main/formats.h"
37 #include "main/macros.h"
38 #include "main/mfeatures.h"
39 #include "main/mtypes.h"
40 #include "main/texcompress.h"
41 #include "main/texparam.h"
42 #include "main/teximage.h"
43 #include "main/texstate.h"
44 #include "program/prog_instruction.h"
48 * Check if a coordinate wrap mode is supported for the texture target.
49 * \return GL_TRUE if legal, GL_FALSE otherwise
52 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
54 const struct gl_extensions
* const e
= & ctx
->Extensions
;
56 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
57 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
58 /* any texture target */
61 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
63 (wrap
== GL_MIRRORED_REPEAT
&&
64 e
->ARB_texture_mirrored_repeat
) ||
65 (wrap
== GL_MIRROR_CLAMP_EXT
&&
66 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
67 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
68 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
69 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
70 (e
->EXT_texture_mirror_clamp
)))) {
71 /* non-rectangle texture */
75 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
81 * Get current texture object for given target.
82 * Return NULL if any error (and record the error).
83 * Note that this is different from _mesa_select_tex_object() in that proxy
84 * targets are not accepted.
85 * Only the glGetTexLevelParameter() functions accept proxy targets.
87 static struct gl_texture_object
*
88 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
90 struct gl_texture_unit
*texUnit
;
92 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
93 _mesa_error(ctx
, GL_INVALID_OPERATION
,
94 "gl%sTexParameter(current unit)", get
? "Get" : "");
98 texUnit
= _mesa_get_current_tex_unit(ctx
);
102 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
104 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
106 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
107 case GL_TEXTURE_CUBE_MAP
:
108 if (ctx
->Extensions
.ARB_texture_cube_map
) {
109 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
112 case GL_TEXTURE_RECTANGLE_NV
:
113 if (ctx
->Extensions
.NV_texture_rectangle
) {
114 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
117 case GL_TEXTURE_1D_ARRAY_EXT
:
118 if (ctx
->Extensions
.MESA_texture_array
) {
119 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
122 case GL_TEXTURE_2D_ARRAY_EXT
:
123 if (ctx
->Extensions
.MESA_texture_array
) {
124 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
131 _mesa_error(ctx
, GL_INVALID_ENUM
,
132 "gl%sTexParameter(target)", get
? "Get" : "");
138 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
139 * \return -1 if error.
142 comp_to_swizzle(GLenum comp
)
164 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
167 ASSERT(swz
<= SWIZZLE_NIL
);
169 GLuint mask
= 0x7 << (3 * comp
);
170 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
177 * This is called just prior to changing any texture object state.
178 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
179 * state flag and then mark the texture object as 'incomplete' so that any
180 * per-texture derived state gets recomputed.
183 flush(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
185 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
186 texObj
->_Complete
= GL_FALSE
;
191 * Set an integer-valued texture parameter
192 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
195 set_tex_parameteri(struct gl_context
*ctx
,
196 struct gl_texture_object
*texObj
,
197 GLenum pname
, const GLint
*params
)
200 case GL_TEXTURE_MIN_FILTER
:
201 if (texObj
->MinFilter
== params
[0])
207 texObj
->MinFilter
= params
[0];
209 case GL_NEAREST_MIPMAP_NEAREST
:
210 case GL_LINEAR_MIPMAP_NEAREST
:
211 case GL_NEAREST_MIPMAP_LINEAR
:
212 case GL_LINEAR_MIPMAP_LINEAR
:
213 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
215 texObj
->MinFilter
= params
[0];
220 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
225 case GL_TEXTURE_MAG_FILTER
:
226 if (texObj
->MagFilter
== params
[0])
232 texObj
->MagFilter
= params
[0];
235 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
240 case GL_TEXTURE_WRAP_S
:
241 if (texObj
->WrapS
== params
[0])
243 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
245 texObj
->WrapS
= params
[0];
250 case GL_TEXTURE_WRAP_T
:
251 if (texObj
->WrapT
== params
[0])
253 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
255 texObj
->WrapT
= params
[0];
260 case GL_TEXTURE_WRAP_R
:
261 if (texObj
->WrapR
== params
[0])
263 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
265 texObj
->WrapR
= params
[0];
270 case GL_TEXTURE_BASE_LEVEL
:
271 if (texObj
->BaseLevel
== params
[0])
274 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
275 _mesa_error(ctx
, GL_INVALID_VALUE
,
276 "glTexParameter(param=%d)", params
[0]);
280 texObj
->BaseLevel
= params
[0];
283 case GL_TEXTURE_MAX_LEVEL
:
284 if (texObj
->MaxLevel
== params
[0])
286 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
287 _mesa_error(ctx
, GL_INVALID_OPERATION
,
288 "glTexParameter(param=%d)", params
[0]);
292 texObj
->MaxLevel
= params
[0];
295 case GL_GENERATE_MIPMAP_SGIS
:
296 if (texObj
->GenerateMipmap
!= params
[0]) {
298 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
303 case GL_TEXTURE_COMPARE_MODE_ARB
:
304 if (ctx
->Extensions
.ARB_shadow
&&
305 (params
[0] == GL_NONE
||
306 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
307 if (texObj
->CompareMode
!= params
[0]) {
309 texObj
->CompareMode
= params
[0];
315 _mesa_error(ctx
, GL_INVALID_ENUM
,
316 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
320 case GL_TEXTURE_COMPARE_FUNC_ARB
:
321 if (ctx
->Extensions
.ARB_shadow
) {
322 if (texObj
->CompareFunc
== params
[0])
328 texObj
->CompareFunc
= params
[0];
336 if (ctx
->Extensions
.EXT_shadow_funcs
) {
338 texObj
->CompareFunc
= params
[0];
343 _mesa_error(ctx
, GL_INVALID_ENUM
,
344 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
348 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
352 case GL_DEPTH_TEXTURE_MODE_ARB
:
353 if (ctx
->Extensions
.ARB_depth_texture
&&
354 (params
[0] == GL_LUMINANCE
||
355 params
[0] == GL_INTENSITY
||
356 params
[0] == GL_ALPHA
||
357 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
))) {
358 if (texObj
->DepthMode
!= params
[0]) {
360 texObj
->DepthMode
= params
[0];
365 _mesa_error(ctx
, GL_INVALID_ENUM
,
366 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
370 #if FEATURE_OES_draw_texture
371 case GL_TEXTURE_CROP_RECT_OES
:
372 texObj
->CropRect
[0] = params
[0];
373 texObj
->CropRect
[1] = params
[1];
374 texObj
->CropRect
[2] = params
[2];
375 texObj
->CropRect
[3] = params
[3];
379 case GL_TEXTURE_SWIZZLE_R_EXT
:
380 case GL_TEXTURE_SWIZZLE_G_EXT
:
381 case GL_TEXTURE_SWIZZLE_B_EXT
:
382 case GL_TEXTURE_SWIZZLE_A_EXT
:
383 if (ctx
->Extensions
.EXT_texture_swizzle
) {
384 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
385 const GLint swz
= comp_to_swizzle(params
[0]);
387 _mesa_error(ctx
, GL_INVALID_OPERATION
,
388 "glTexParameter(swizzle 0x%x)", params
[0]);
394 texObj
->Swizzle
[comp
] = params
[0];
395 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
399 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
402 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
403 if (ctx
->Extensions
.EXT_texture_swizzle
) {
406 for (comp
= 0; comp
< 4; comp
++) {
407 const GLint swz
= comp_to_swizzle(params
[comp
]);
409 texObj
->Swizzle
[comp
] = params
[comp
];
410 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
413 _mesa_error(ctx
, GL_INVALID_OPERATION
,
414 "glTexParameter(swizzle 0x%x)", params
[comp
]);
420 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
424 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
431 * Set a float-valued texture parameter
432 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
435 set_tex_parameterf(struct gl_context
*ctx
,
436 struct gl_texture_object
*texObj
,
437 GLenum pname
, const GLfloat
*params
)
440 case GL_TEXTURE_MIN_LOD
:
441 if (texObj
->MinLod
== params
[0])
444 texObj
->MinLod
= params
[0];
447 case GL_TEXTURE_MAX_LOD
:
448 if (texObj
->MaxLod
== params
[0])
451 texObj
->MaxLod
= params
[0];
454 case GL_TEXTURE_PRIORITY
:
456 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
459 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
460 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
461 if (texObj
->MaxAnisotropy
== params
[0])
463 if (params
[0] < 1.0) {
464 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
468 /* clamp to max, that's what NVIDIA does */
469 texObj
->MaxAnisotropy
= MIN2(params
[0],
470 ctx
->Const
.MaxTextureMaxAnisotropy
);
474 static GLuint count
= 0;
476 _mesa_error(ctx
, GL_INVALID_ENUM
,
477 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
481 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
482 if (ctx
->Extensions
.ARB_shadow_ambient
) {
483 if (texObj
->CompareFailValue
!= params
[0]) {
485 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
490 _mesa_error(ctx
, GL_INVALID_ENUM
,
491 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
495 case GL_TEXTURE_LOD_BIAS
:
496 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
497 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
498 if (texObj
->LodBias
!= params
[0]) {
500 texObj
->LodBias
= params
[0];
507 case GL_TEXTURE_BORDER_COLOR
:
509 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
510 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
511 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
512 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
523 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
525 GLboolean need_update
;
526 struct gl_texture_object
*texObj
;
527 GET_CURRENT_CONTEXT(ctx
);
528 ASSERT_OUTSIDE_BEGIN_END(ctx
);
530 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
535 case GL_TEXTURE_MIN_FILTER
:
536 case GL_TEXTURE_MAG_FILTER
:
537 case GL_TEXTURE_WRAP_S
:
538 case GL_TEXTURE_WRAP_T
:
539 case GL_TEXTURE_WRAP_R
:
540 case GL_TEXTURE_BASE_LEVEL
:
541 case GL_TEXTURE_MAX_LEVEL
:
542 case GL_GENERATE_MIPMAP_SGIS
:
543 case GL_TEXTURE_COMPARE_MODE_ARB
:
544 case GL_TEXTURE_COMPARE_FUNC_ARB
:
545 case GL_DEPTH_TEXTURE_MODE_ARB
:
547 /* convert float param to int */
549 p
[0] = (GLint
) param
;
550 p
[1] = p
[2] = p
[3] = 0;
551 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
556 /* this will generate an error if pname is illegal */
559 p
[1] = p
[2] = p
[3] = 0.0F
;
560 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
564 if (ctx
->Driver
.TexParameter
&& need_update
) {
565 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
571 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
573 GLboolean need_update
;
574 struct gl_texture_object
*texObj
;
575 GET_CURRENT_CONTEXT(ctx
);
576 ASSERT_OUTSIDE_BEGIN_END(ctx
);
578 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
583 case GL_TEXTURE_MIN_FILTER
:
584 case GL_TEXTURE_MAG_FILTER
:
585 case GL_TEXTURE_WRAP_S
:
586 case GL_TEXTURE_WRAP_T
:
587 case GL_TEXTURE_WRAP_R
:
588 case GL_TEXTURE_BASE_LEVEL
:
589 case GL_TEXTURE_MAX_LEVEL
:
590 case GL_GENERATE_MIPMAP_SGIS
:
591 case GL_TEXTURE_COMPARE_MODE_ARB
:
592 case GL_TEXTURE_COMPARE_FUNC_ARB
:
593 case GL_DEPTH_TEXTURE_MODE_ARB
:
595 /* convert float param to int */
597 p
[0] = (GLint
) params
[0];
598 p
[1] = p
[2] = p
[3] = 0;
599 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
603 #if FEATURE_OES_draw_texture
604 case GL_TEXTURE_CROP_RECT_OES
:
606 /* convert float params to int */
608 iparams
[0] = (GLint
) params
[0];
609 iparams
[1] = (GLint
) params
[1];
610 iparams
[2] = (GLint
) params
[2];
611 iparams
[3] = (GLint
) params
[3];
612 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
618 /* this will generate an error if pname is illegal */
619 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
622 if (ctx
->Driver
.TexParameter
&& need_update
) {
623 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
629 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
631 GLboolean need_update
;
632 struct gl_texture_object
*texObj
;
633 GET_CURRENT_CONTEXT(ctx
);
634 ASSERT_OUTSIDE_BEGIN_END(ctx
);
636 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
641 case GL_TEXTURE_MIN_LOD
:
642 case GL_TEXTURE_MAX_LOD
:
643 case GL_TEXTURE_PRIORITY
:
644 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
645 case GL_TEXTURE_LOD_BIAS
:
646 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
649 fparam
[0] = (GLfloat
) param
;
650 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
651 /* convert int param to float */
652 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
656 /* this will generate an error if pname is illegal */
660 iparam
[1] = iparam
[2] = iparam
[3] = 0;
661 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
665 if (ctx
->Driver
.TexParameter
&& need_update
) {
666 GLfloat fparam
= (GLfloat
) param
;
667 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
673 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
675 GLboolean need_update
;
676 struct gl_texture_object
*texObj
;
677 GET_CURRENT_CONTEXT(ctx
);
678 ASSERT_OUTSIDE_BEGIN_END(ctx
);
680 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
685 case GL_TEXTURE_BORDER_COLOR
:
687 /* convert int params to float */
689 fparams
[0] = INT_TO_FLOAT(params
[0]);
690 fparams
[1] = INT_TO_FLOAT(params
[1]);
691 fparams
[2] = INT_TO_FLOAT(params
[2]);
692 fparams
[3] = INT_TO_FLOAT(params
[3]);
693 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
696 case GL_TEXTURE_MIN_LOD
:
697 case GL_TEXTURE_MAX_LOD
:
698 case GL_TEXTURE_PRIORITY
:
699 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
700 case GL_TEXTURE_LOD_BIAS
:
701 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
703 /* convert int param to float */
705 fparams
[0] = (GLfloat
) params
[0];
706 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
707 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
711 /* this will generate an error if pname is illegal */
712 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
715 if (ctx
->Driver
.TexParameter
&& need_update
) {
717 fparams
[0] = INT_TO_FLOAT(params
[0]);
718 if (pname
== GL_TEXTURE_BORDER_COLOR
||
719 pname
== GL_TEXTURE_CROP_RECT_OES
) {
720 fparams
[1] = INT_TO_FLOAT(params
[1]);
721 fparams
[2] = INT_TO_FLOAT(params
[2]);
722 fparams
[3] = INT_TO_FLOAT(params
[3]);
724 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
730 * Set tex parameter to integer value(s). Primarily intended to set
731 * integer-valued texture border color (for integer-valued textures).
735 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
737 struct gl_texture_object
*texObj
;
738 GET_CURRENT_CONTEXT(ctx
);
739 ASSERT_OUTSIDE_BEGIN_END(ctx
);
741 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
746 case GL_TEXTURE_BORDER_COLOR
:
747 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
748 /* set the integer-valued border color */
749 COPY_4V(texObj
->BorderColor
.i
, params
);
752 _mesa_TexParameteriv(target
, pname
, params
);
755 /* XXX no driver hook for TexParameterIiv() yet */
760 * Set tex parameter to unsigned integer value(s). Primarily intended to set
761 * uint-valued texture border color (for integer-valued textures).
765 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
767 struct gl_texture_object
*texObj
;
768 GET_CURRENT_CONTEXT(ctx
);
769 ASSERT_OUTSIDE_BEGIN_END(ctx
);
771 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
776 case GL_TEXTURE_BORDER_COLOR
:
777 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
778 /* set the unsigned integer-valued border color */
779 COPY_4V(texObj
->BorderColor
.ui
, params
);
782 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
785 /* XXX no driver hook for TexParameterIuiv() yet */
792 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
793 GLenum pname
, GLfloat
*params
)
796 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
797 *params
= (GLfloat
) iparam
;
802 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
803 GLenum pname
, GLint
*params
)
805 const struct gl_texture_unit
*texUnit
;
806 struct gl_texture_object
*texObj
;
807 const struct gl_texture_image
*img
= NULL
;
811 GET_CURRENT_CONTEXT(ctx
);
812 ASSERT_OUTSIDE_BEGIN_END(ctx
);
814 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
815 _mesa_error(ctx
, GL_INVALID_OPERATION
,
816 "glGetTexLevelParameteriv(current unit)");
820 texUnit
= _mesa_get_current_tex_unit(ctx
);
822 /* this will catch bad target values */
823 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
824 if (maxLevels
== 0) {
825 _mesa_error(ctx
, GL_INVALID_ENUM
,
826 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
830 if (level
< 0 || level
>= maxLevels
) {
831 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
835 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
836 _mesa_lock_texture(ctx
, texObj
);
838 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
839 if (!img
|| !img
->TexFormat
) {
840 /* undefined texture image */
841 if (pname
== GL_TEXTURE_COMPONENTS
)
848 texFormat
= img
->TexFormat
;
850 isProxy
= _mesa_is_proxy_texture(target
);
853 case GL_TEXTURE_WIDTH
:
854 *params
= img
->Width
;
856 case GL_TEXTURE_HEIGHT
:
857 *params
= img
->Height
;
859 case GL_TEXTURE_DEPTH
:
860 *params
= img
->Depth
;
862 case GL_TEXTURE_INTERNAL_FORMAT
:
863 if (_mesa_is_format_compressed(img
->TexFormat
)) {
864 /* need to return the actual compressed format */
865 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
868 /* return the user's requested internal format */
869 *params
= img
->InternalFormat
;
872 case GL_TEXTURE_BORDER
:
873 *params
= img
->Border
;
875 case GL_TEXTURE_RED_SIZE
:
876 if (img
->_BaseFormat
== GL_RED
) {
877 *params
= _mesa_get_format_bits(texFormat
, pname
);
881 case GL_TEXTURE_GREEN_SIZE
:
882 if (img
->_BaseFormat
== GL_RG
) {
883 *params
= _mesa_get_format_bits(texFormat
, pname
);
887 case GL_TEXTURE_BLUE_SIZE
:
888 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
889 *params
= _mesa_get_format_bits(texFormat
, pname
);
893 case GL_TEXTURE_ALPHA_SIZE
:
894 if (img
->_BaseFormat
== GL_ALPHA
||
895 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
896 img
->_BaseFormat
== GL_RGBA
)
897 *params
= _mesa_get_format_bits(texFormat
, pname
);
901 case GL_TEXTURE_INTENSITY_SIZE
:
902 if (img
->_BaseFormat
!= GL_INTENSITY
)
905 *params
= _mesa_get_format_bits(texFormat
, pname
);
907 /* intensity 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_LUMINANCE_SIZE
:
914 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
915 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
918 *params
= _mesa_get_format_bits(texFormat
, pname
);
920 /* luminance probably stored as rgb texture */
921 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
922 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
926 case GL_TEXTURE_INDEX_SIZE_EXT
:
927 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
928 *params
= _mesa_get_format_bits(texFormat
, pname
);
932 case GL_TEXTURE_DEPTH_SIZE_ARB
:
933 if (ctx
->Extensions
.ARB_depth_texture
)
934 *params
= _mesa_get_format_bits(texFormat
, pname
);
936 _mesa_error(ctx
, GL_INVALID_ENUM
,
937 "glGetTexLevelParameter[if]v(pname)");
939 case GL_TEXTURE_STENCIL_SIZE_EXT
:
940 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
941 ctx
->Extensions
.ARB_framebuffer_object
) {
942 *params
= _mesa_get_format_bits(texFormat
, pname
);
945 _mesa_error(ctx
, GL_INVALID_ENUM
,
946 "glGetTexLevelParameter[if]v(pname)");
949 case GL_TEXTURE_SHARED_SIZE
:
950 if (ctx
->VersionMajor
>= 3) {
951 /* XXX return number of exponent bits for shared exponent texture
952 * formats, like GL_RGB9_E5.
957 _mesa_error(ctx
, GL_INVALID_ENUM
,
958 "glGetTexLevelParameter[if]v(pname)");
962 /* GL_ARB_texture_compression */
963 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
964 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
965 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
966 img
->Height
, img
->Depth
);
969 _mesa_error(ctx
, GL_INVALID_OPERATION
,
970 "glGetTexLevelParameter[if]v(pname)");
973 case GL_TEXTURE_COMPRESSED
:
974 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
977 /* GL_ARB_texture_float */
978 case GL_TEXTURE_RED_TYPE_ARB
:
979 if (ctx
->Extensions
.ARB_texture_float
) {
980 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
981 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
984 _mesa_error(ctx
, GL_INVALID_ENUM
,
985 "glGetTexLevelParameter[if]v(pname)");
988 case GL_TEXTURE_GREEN_TYPE_ARB
:
989 if (ctx
->Extensions
.ARB_texture_float
) {
990 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
991 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
994 _mesa_error(ctx
, GL_INVALID_ENUM
,
995 "glGetTexLevelParameter[if]v(pname)");
998 case GL_TEXTURE_BLUE_TYPE_ARB
:
999 if (ctx
->Extensions
.ARB_texture_float
) {
1000 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1001 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1004 _mesa_error(ctx
, GL_INVALID_ENUM
,
1005 "glGetTexLevelParameter[if]v(pname)");
1008 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1009 if (ctx
->Extensions
.ARB_texture_float
) {
1010 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1011 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1014 _mesa_error(ctx
, GL_INVALID_ENUM
,
1015 "glGetTexLevelParameter[if]v(pname)");
1018 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1019 if (ctx
->Extensions
.ARB_texture_float
) {
1020 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1021 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1024 _mesa_error(ctx
, GL_INVALID_ENUM
,
1025 "glGetTexLevelParameter[if]v(pname)");
1028 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1029 if (ctx
->Extensions
.ARB_texture_float
) {
1030 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1031 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1034 _mesa_error(ctx
, GL_INVALID_ENUM
,
1035 "glGetTexLevelParameter[if]v(pname)");
1038 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1039 if (ctx
->Extensions
.ARB_texture_float
) {
1040 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1041 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1044 _mesa_error(ctx
, GL_INVALID_ENUM
,
1045 "glGetTexLevelParameter[if]v(pname)");
1050 _mesa_error(ctx
, GL_INVALID_ENUM
,
1051 "glGetTexLevelParameter[if]v(pname)");
1055 _mesa_unlock_texture(ctx
, texObj
);
1061 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1063 struct gl_texture_object
*obj
;
1064 GLboolean error
= GL_FALSE
;
1065 GET_CURRENT_CONTEXT(ctx
);
1066 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1068 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1072 _mesa_lock_texture(ctx
, obj
);
1074 case GL_TEXTURE_MAG_FILTER
:
1075 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1077 case GL_TEXTURE_MIN_FILTER
:
1078 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1080 case GL_TEXTURE_WRAP_S
:
1081 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1083 case GL_TEXTURE_WRAP_T
:
1084 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1086 case GL_TEXTURE_WRAP_R
:
1087 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1089 case GL_TEXTURE_BORDER_COLOR
:
1090 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1091 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1092 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1093 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1095 case GL_TEXTURE_RESIDENT
:
1098 if (ctx
->Driver
.IsTextureResident
)
1099 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1102 *params
= ENUM_TO_FLOAT(resident
);
1105 case GL_TEXTURE_PRIORITY
:
1106 *params
= obj
->Priority
;
1108 case GL_TEXTURE_MIN_LOD
:
1109 *params
= obj
->MinLod
;
1111 case GL_TEXTURE_MAX_LOD
:
1112 *params
= obj
->MaxLod
;
1114 case GL_TEXTURE_BASE_LEVEL
:
1115 *params
= (GLfloat
) obj
->BaseLevel
;
1117 case GL_TEXTURE_MAX_LEVEL
:
1118 *params
= (GLfloat
) obj
->MaxLevel
;
1120 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1121 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1122 *params
= obj
->MaxAnisotropy
;
1127 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1128 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1129 *params
= obj
->CompareFailValue
;
1134 case GL_GENERATE_MIPMAP_SGIS
:
1135 *params
= (GLfloat
) obj
->GenerateMipmap
;
1137 case GL_TEXTURE_COMPARE_MODE_ARB
:
1138 if (ctx
->Extensions
.ARB_shadow
) {
1139 *params
= (GLfloat
) obj
->CompareMode
;
1144 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1145 if (ctx
->Extensions
.ARB_shadow
) {
1146 *params
= (GLfloat
) obj
->CompareFunc
;
1151 case GL_DEPTH_TEXTURE_MODE_ARB
:
1152 if (ctx
->Extensions
.ARB_depth_texture
) {
1153 *params
= (GLfloat
) obj
->DepthMode
;
1158 case GL_TEXTURE_LOD_BIAS
:
1159 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1160 *params
= obj
->LodBias
;
1165 #if FEATURE_OES_draw_texture
1166 case GL_TEXTURE_CROP_RECT_OES
:
1167 params
[0] = obj
->CropRect
[0];
1168 params
[1] = obj
->CropRect
[1];
1169 params
[2] = obj
->CropRect
[2];
1170 params
[3] = obj
->CropRect
[3];
1174 case GL_TEXTURE_SWIZZLE_R_EXT
:
1175 case GL_TEXTURE_SWIZZLE_G_EXT
:
1176 case GL_TEXTURE_SWIZZLE_B_EXT
:
1177 case GL_TEXTURE_SWIZZLE_A_EXT
:
1178 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1179 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1180 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1187 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1188 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1190 for (comp
= 0; comp
< 4; comp
++) {
1191 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1205 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1208 _mesa_unlock_texture(ctx
, obj
);
1213 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1215 struct gl_texture_object
*obj
;
1216 GLboolean error
= GL_FALSE
;
1217 GET_CURRENT_CONTEXT(ctx
);
1218 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1220 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1224 _mesa_lock_texture(ctx
, obj
);
1226 case GL_TEXTURE_MAG_FILTER
:
1227 *params
= (GLint
) obj
->MagFilter
;
1229 case GL_TEXTURE_MIN_FILTER
:
1230 *params
= (GLint
) obj
->MinFilter
;
1232 case GL_TEXTURE_WRAP_S
:
1233 *params
= (GLint
) obj
->WrapS
;
1235 case GL_TEXTURE_WRAP_T
:
1236 *params
= (GLint
) obj
->WrapT
;
1238 case GL_TEXTURE_WRAP_R
:
1239 *params
= (GLint
) obj
->WrapR
;
1241 case GL_TEXTURE_BORDER_COLOR
:
1244 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1245 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1246 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1247 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1248 params
[0] = FLOAT_TO_INT(b
[0]);
1249 params
[1] = FLOAT_TO_INT(b
[1]);
1250 params
[2] = FLOAT_TO_INT(b
[2]);
1251 params
[3] = FLOAT_TO_INT(b
[3]);
1254 case GL_TEXTURE_RESIDENT
:
1257 if (ctx
->Driver
.IsTextureResident
)
1258 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1261 *params
= (GLint
) resident
;
1264 case GL_TEXTURE_PRIORITY
:
1265 *params
= FLOAT_TO_INT(obj
->Priority
);
1267 case GL_TEXTURE_MIN_LOD
:
1268 *params
= (GLint
) obj
->MinLod
;
1270 case GL_TEXTURE_MAX_LOD
:
1271 *params
= (GLint
) obj
->MaxLod
;
1273 case GL_TEXTURE_BASE_LEVEL
:
1274 *params
= obj
->BaseLevel
;
1276 case GL_TEXTURE_MAX_LEVEL
:
1277 *params
= obj
->MaxLevel
;
1279 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1280 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1281 *params
= (GLint
) obj
->MaxAnisotropy
;
1287 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1288 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1289 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1295 case GL_GENERATE_MIPMAP_SGIS
:
1296 *params
= (GLint
) obj
->GenerateMipmap
;
1298 case GL_TEXTURE_COMPARE_MODE_ARB
:
1299 if (ctx
->Extensions
.ARB_shadow
) {
1300 *params
= (GLint
) obj
->CompareMode
;
1306 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1307 if (ctx
->Extensions
.ARB_shadow
) {
1308 *params
= (GLint
) obj
->CompareFunc
;
1314 case GL_DEPTH_TEXTURE_MODE_ARB
:
1315 if (ctx
->Extensions
.ARB_depth_texture
) {
1316 *params
= (GLint
) obj
->DepthMode
;
1322 case GL_TEXTURE_LOD_BIAS
:
1323 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1324 *params
= (GLint
) obj
->LodBias
;
1330 #if FEATURE_OES_draw_texture
1331 case GL_TEXTURE_CROP_RECT_OES
:
1332 params
[0] = obj
->CropRect
[0];
1333 params
[1] = obj
->CropRect
[1];
1334 params
[2] = obj
->CropRect
[2];
1335 params
[3] = obj
->CropRect
[3];
1338 case GL_TEXTURE_SWIZZLE_R_EXT
:
1339 case GL_TEXTURE_SWIZZLE_G_EXT
:
1340 case GL_TEXTURE_SWIZZLE_B_EXT
:
1341 case GL_TEXTURE_SWIZZLE_A_EXT
:
1342 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1343 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1344 *params
= obj
->Swizzle
[comp
];
1351 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1352 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1353 COPY_4V(params
, obj
->Swizzle
);
1361 ; /* silence warnings */
1365 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1368 _mesa_unlock_texture(ctx
, obj
);
1372 /** New in GL 3.0 */
1374 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1376 struct gl_texture_object
*texObj
;
1377 GET_CURRENT_CONTEXT(ctx
);
1378 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1380 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1383 case GL_TEXTURE_BORDER_COLOR
:
1384 COPY_4V(params
, texObj
->BorderColor
.i
);
1387 _mesa_GetTexParameteriv(target
, pname
, params
);
1392 /** New in GL 3.0 */
1394 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1396 struct gl_texture_object
*texObj
;
1397 GET_CURRENT_CONTEXT(ctx
);
1398 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1400 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1403 case GL_TEXTURE_BORDER_COLOR
:
1404 COPY_4V(params
, texObj
->BorderColor
.i
);
1409 _mesa_GetTexParameteriv(target
, pname
, ip
);
1411 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1412 pname
== GL_TEXTURE_CROP_RECT_OES
) {