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/enums.h"
37 #include "main/formats.h"
38 #include "main/macros.h"
39 #include "main/texcompress.h"
40 #include "main/texparam.h"
41 #include "main/teximage.h"
42 #include "main/texstate.h"
43 #include "shader/prog_instruction.h"
47 * Check if a coordinate wrap mode is supported for the texture target.
48 * \return GL_TRUE if legal, GL_FALSE otherwise
51 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
53 const struct gl_extensions
* const e
= & ctx
->Extensions
;
55 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
56 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
57 /* any texture target */
60 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
62 (wrap
== GL_MIRRORED_REPEAT
&&
63 e
->ARB_texture_mirrored_repeat
) ||
64 (wrap
== GL_MIRROR_CLAMP_EXT
&&
65 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
66 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
67 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
68 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
69 (e
->EXT_texture_mirror_clamp
)))) {
70 /* non-rectangle texture */
74 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
80 * Get current texture object for given target.
81 * Return NULL if any error.
83 static struct gl_texture_object
*
84 get_texobj(GLcontext
*ctx
, GLenum target
)
86 struct gl_texture_unit
*texUnit
;
88 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
89 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(current unit)");
93 texUnit
= _mesa_get_current_tex_unit(ctx
);
97 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
99 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
101 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
102 case GL_TEXTURE_CUBE_MAP
:
103 if (ctx
->Extensions
.ARB_texture_cube_map
) {
104 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
107 case GL_TEXTURE_RECTANGLE_NV
:
108 if (ctx
->Extensions
.NV_texture_rectangle
) {
109 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
112 case GL_TEXTURE_1D_ARRAY_EXT
:
113 if (ctx
->Extensions
.MESA_texture_array
) {
114 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
117 case GL_TEXTURE_2D_ARRAY_EXT
:
118 if (ctx
->Extensions
.MESA_texture_array
) {
119 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
126 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(target)");
132 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
133 * \return -1 if error.
136 comp_to_swizzle(GLenum comp
)
158 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
161 ASSERT(swz
<= SWIZZLE_NIL
);
163 GLuint mask
= 0x7 << (3 * comp
);
164 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
171 * This is called just prior to changing any texture object state.
172 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
173 * state flag and then mark the texture object as 'incomplete' so that any
174 * per-texture derived state gets recomputed.
177 flush(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
179 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
180 texObj
->_Complete
= GL_FALSE
;
185 * Set an integer-valued texture parameter
186 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
189 set_tex_parameteri(GLcontext
*ctx
,
190 struct gl_texture_object
*texObj
,
191 GLenum pname
, const GLint
*params
)
194 case GL_TEXTURE_MIN_FILTER
:
195 if (texObj
->MinFilter
== params
[0])
201 texObj
->MinFilter
= params
[0];
203 case GL_NEAREST_MIPMAP_NEAREST
:
204 case GL_LINEAR_MIPMAP_NEAREST
:
205 case GL_NEAREST_MIPMAP_LINEAR
:
206 case GL_LINEAR_MIPMAP_LINEAR
:
207 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
209 texObj
->MinFilter
= params
[0];
214 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
219 case GL_TEXTURE_MAG_FILTER
:
220 if (texObj
->MagFilter
== params
[0])
226 texObj
->MagFilter
= params
[0];
229 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
234 case GL_TEXTURE_WRAP_S
:
235 if (texObj
->WrapS
== params
[0])
237 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
239 texObj
->WrapS
= params
[0];
244 case GL_TEXTURE_WRAP_T
:
245 if (texObj
->WrapT
== params
[0])
247 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
249 texObj
->WrapT
= params
[0];
254 case GL_TEXTURE_WRAP_R
:
255 if (texObj
->WrapR
== params
[0])
257 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
259 texObj
->WrapR
= params
[0];
264 case GL_TEXTURE_BASE_LEVEL
:
265 if (texObj
->BaseLevel
== params
[0])
268 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
269 _mesa_error(ctx
, GL_INVALID_VALUE
,
270 "glTexParameter(param=%d)", params
[0]);
274 texObj
->BaseLevel
= params
[0];
277 case GL_TEXTURE_MAX_LEVEL
:
278 if (texObj
->MaxLevel
== params
[0])
280 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
281 _mesa_error(ctx
, GL_INVALID_OPERATION
,
282 "glTexParameter(param=%d)", params
[0]);
286 texObj
->MaxLevel
= params
[0];
289 case GL_GENERATE_MIPMAP_SGIS
:
290 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
291 if (texObj
->GenerateMipmap
!= params
[0]) {
293 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
299 _mesa_error(ctx
, GL_INVALID_ENUM
,
300 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
304 case GL_TEXTURE_COMPARE_MODE_ARB
:
305 if (ctx
->Extensions
.ARB_shadow
&&
306 (params
[0] == GL_NONE
||
307 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
308 if (texObj
->CompareMode
!= params
[0]) {
310 texObj
->CompareMode
= params
[0];
316 _mesa_error(ctx
, GL_INVALID_ENUM
,
317 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
321 case GL_TEXTURE_COMPARE_FUNC_ARB
:
322 if (ctx
->Extensions
.ARB_shadow
) {
323 if (texObj
->CompareFunc
== params
[0])
329 texObj
->CompareFunc
= params
[0];
337 if (ctx
->Extensions
.EXT_shadow_funcs
) {
339 texObj
->CompareFunc
= params
[0];
344 _mesa_error(ctx
, GL_INVALID_ENUM
,
345 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
349 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
353 case GL_DEPTH_TEXTURE_MODE_ARB
:
354 if (ctx
->Extensions
.ARB_depth_texture
&&
355 (params
[0] == GL_LUMINANCE
||
356 params
[0] == GL_INTENSITY
||
357 params
[0] == GL_ALPHA
)) {
358 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 #ifdef 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(GLcontext
*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
[RCOMP
] = params
[0];
510 texObj
->BorderColor
[GCOMP
] = params
[1];
511 texObj
->BorderColor
[BCOMP
] = params
[2];
512 texObj
->BorderColor
[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
);
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 */
548 GLint p
= (GLint
) param
;
549 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
553 /* this will generate an error if pname is illegal */
554 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, ¶m
);
557 if (ctx
->Driver
.TexParameter
&& need_update
) {
558 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
564 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
566 GLboolean need_update
;
567 struct gl_texture_object
*texObj
;
568 GET_CURRENT_CONTEXT(ctx
);
569 ASSERT_OUTSIDE_BEGIN_END(ctx
);
571 texObj
= get_texobj(ctx
, target
);
576 case GL_TEXTURE_MIN_FILTER
:
577 case GL_TEXTURE_MAG_FILTER
:
578 case GL_TEXTURE_WRAP_S
:
579 case GL_TEXTURE_WRAP_T
:
580 case GL_TEXTURE_WRAP_R
:
581 case GL_TEXTURE_BASE_LEVEL
:
582 case GL_TEXTURE_MAX_LEVEL
:
583 case GL_GENERATE_MIPMAP_SGIS
:
584 case GL_TEXTURE_COMPARE_MODE_ARB
:
585 case GL_TEXTURE_COMPARE_FUNC_ARB
:
586 case GL_DEPTH_TEXTURE_MODE_ARB
:
588 /* convert float param to int */
589 GLint p
= (GLint
) params
[0];
590 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
594 #ifdef FEATURE_OES_draw_texture
595 case GL_TEXTURE_CROP_RECT_OES
:
597 /* convert float params to int */
599 iparams
[0] = (GLint
) params
[0];
600 iparams
[1] = (GLint
) params
[1];
601 iparams
[2] = (GLint
) params
[2];
602 iparams
[3] = (GLint
) params
[3];
603 need_update
= set_tex_parameteri(ctx
, target
, iparams
);
609 /* this will generate an error if pname is illegal */
610 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
613 if (ctx
->Driver
.TexParameter
&& need_update
) {
614 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
620 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
622 GLboolean need_update
;
623 struct gl_texture_object
*texObj
;
624 GET_CURRENT_CONTEXT(ctx
);
625 ASSERT_OUTSIDE_BEGIN_END(ctx
);
627 texObj
= get_texobj(ctx
, target
);
632 case GL_TEXTURE_MIN_LOD
:
633 case GL_TEXTURE_MAX_LOD
:
634 case GL_TEXTURE_PRIORITY
:
635 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
636 case GL_TEXTURE_LOD_BIAS
:
637 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
639 GLfloat fparam
= (GLfloat
) param
;
640 /* convert int param to float */
641 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
645 /* this will generate an error if pname is illegal */
646 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, ¶m
);
649 if (ctx
->Driver
.TexParameter
&& need_update
) {
650 GLfloat fparam
= (GLfloat
) param
;
651 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
657 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
659 GLboolean need_update
;
660 struct gl_texture_object
*texObj
;
661 GET_CURRENT_CONTEXT(ctx
);
662 ASSERT_OUTSIDE_BEGIN_END(ctx
);
664 texObj
= get_texobj(ctx
, target
);
669 case GL_TEXTURE_BORDER_COLOR
:
671 /* convert int params to float */
673 fparams
[0] = INT_TO_FLOAT(params
[0]);
674 fparams
[1] = INT_TO_FLOAT(params
[1]);
675 fparams
[2] = INT_TO_FLOAT(params
[2]);
676 fparams
[3] = INT_TO_FLOAT(params
[3]);
677 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
680 case GL_TEXTURE_MIN_LOD
:
681 case GL_TEXTURE_MAX_LOD
:
682 case GL_TEXTURE_PRIORITY
:
683 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
684 case GL_TEXTURE_LOD_BIAS
:
685 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
687 /* convert int param to float */
688 GLfloat fparam
= (GLfloat
) params
[0];
689 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
693 /* this will generate an error if pname is illegal */
694 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
697 if (ctx
->Driver
.TexParameter
&& need_update
) {
699 fparams
[0] = INT_TO_FLOAT(params
[0]);
700 if (pname
== GL_TEXTURE_BORDER_COLOR
||
701 pname
== GL_TEXTURE_CROP_RECT_OES
) {
702 fparams
[1] = INT_TO_FLOAT(params
[1]);
703 fparams
[2] = INT_TO_FLOAT(params
[2]);
704 fparams
[3] = INT_TO_FLOAT(params
[3]);
706 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
712 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
713 GLenum pname
, GLfloat
*params
)
716 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
717 *params
= (GLfloat
) iparam
;
722 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
723 GLenum pname
, GLint
*params
)
725 const struct gl_texture_unit
*texUnit
;
726 struct gl_texture_object
*texObj
;
727 const struct gl_texture_image
*img
= NULL
;
731 GET_CURRENT_CONTEXT(ctx
);
732 ASSERT_OUTSIDE_BEGIN_END(ctx
);
734 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
736 "glGetTexLevelParameteriv(current unit)");
740 texUnit
= _mesa_get_current_tex_unit(ctx
);
742 /* this will catch bad target values */
743 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
744 if (maxLevels
== 0) {
745 _mesa_error(ctx
, GL_INVALID_ENUM
,
746 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
750 if (level
< 0 || level
>= maxLevels
) {
751 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
755 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
756 _mesa_lock_texture(ctx
, texObj
);
758 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
759 if (!img
|| !img
->TexFormat
) {
760 /* undefined texture image */
761 if (pname
== GL_TEXTURE_COMPONENTS
)
768 texFormat
= img
->TexFormat
->MesaFormat
;
770 isProxy
= _mesa_is_proxy_texture(target
);
773 case GL_TEXTURE_WIDTH
:
774 *params
= img
->Width
;
776 case GL_TEXTURE_HEIGHT
:
777 *params
= img
->Height
;
779 case GL_TEXTURE_DEPTH
:
780 *params
= img
->Depth
;
782 case GL_TEXTURE_INTERNAL_FORMAT
:
783 *params
= img
->InternalFormat
;
785 case GL_TEXTURE_BORDER
:
786 *params
= img
->Border
;
788 case GL_TEXTURE_RED_SIZE
:
789 case GL_TEXTURE_GREEN_SIZE
:
790 case GL_TEXTURE_BLUE_SIZE
:
791 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
792 *params
= _mesa_get_format_bits(texFormat
, pname
);
796 case GL_TEXTURE_ALPHA_SIZE
:
797 if (img
->_BaseFormat
== GL_ALPHA
||
798 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
799 img
->_BaseFormat
== GL_RGBA
)
800 *params
= _mesa_get_format_bits(texFormat
, pname
);
804 case GL_TEXTURE_INTENSITY_SIZE
:
805 if (img
->_BaseFormat
!= GL_INTENSITY
)
808 *params
= _mesa_get_format_bits(texFormat
, pname
);
810 /* intensity probably stored as rgb texture */
811 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
812 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
816 case GL_TEXTURE_LUMINANCE_SIZE
:
817 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
818 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
821 *params
= _mesa_get_format_bits(texFormat
, pname
);
822 if (img
->TexFormat
->LuminanceBits
== 0) {
823 /* luminance probably stored as rgb texture */
824 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
825 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
829 case GL_TEXTURE_INDEX_SIZE_EXT
:
830 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
831 *params
= _mesa_get_format_bits(texFormat
, pname
);
835 case GL_TEXTURE_DEPTH_SIZE_ARB
:
836 if (ctx
->Extensions
.ARB_depth_texture
)
837 *params
= _mesa_get_format_bits(texFormat
, pname
);
839 _mesa_error(ctx
, GL_INVALID_ENUM
,
840 "glGetTexLevelParameter[if]v(pname)");
842 case GL_TEXTURE_STENCIL_SIZE_EXT
:
843 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
844 ctx
->Extensions
.ARB_framebuffer_object
) {
845 *params
= _mesa_get_format_bits(texFormat
, pname
);
848 _mesa_error(ctx
, GL_INVALID_ENUM
,
849 "glGetTexLevelParameter[if]v(pname)");
853 /* GL_ARB_texture_compression */
854 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
855 if (img
->IsCompressed
&& !isProxy
) {
856 /* Don't use ctx->Driver.CompressedTextureSize() since that
857 * may returned a padded hardware size.
859 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
860 img
->Height
, img
->Depth
,
864 _mesa_error(ctx
, GL_INVALID_OPERATION
,
865 "glGetTexLevelParameter[if]v(pname)");
868 case GL_TEXTURE_COMPRESSED
:
869 *params
= (GLint
) img
->IsCompressed
;
872 /* GL_ARB_texture_float */
873 case GL_TEXTURE_RED_TYPE_ARB
:
874 if (ctx
->Extensions
.ARB_texture_float
) {
875 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
876 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
879 _mesa_error(ctx
, GL_INVALID_ENUM
,
880 "glGetTexLevelParameter[if]v(pname)");
883 case GL_TEXTURE_GREEN_TYPE_ARB
:
884 if (ctx
->Extensions
.ARB_texture_float
) {
885 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
886 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
889 _mesa_error(ctx
, GL_INVALID_ENUM
,
890 "glGetTexLevelParameter[if]v(pname)");
893 case GL_TEXTURE_BLUE_TYPE_ARB
:
894 if (ctx
->Extensions
.ARB_texture_float
) {
895 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
896 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
899 _mesa_error(ctx
, GL_INVALID_ENUM
,
900 "glGetTexLevelParameter[if]v(pname)");
903 case GL_TEXTURE_ALPHA_TYPE_ARB
:
904 if (ctx
->Extensions
.ARB_texture_float
) {
905 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
906 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
909 _mesa_error(ctx
, GL_INVALID_ENUM
,
910 "glGetTexLevelParameter[if]v(pname)");
913 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
914 if (ctx
->Extensions
.ARB_texture_float
) {
915 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
916 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
919 _mesa_error(ctx
, GL_INVALID_ENUM
,
920 "glGetTexLevelParameter[if]v(pname)");
923 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
924 if (ctx
->Extensions
.ARB_texture_float
) {
925 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
926 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
929 _mesa_error(ctx
, GL_INVALID_ENUM
,
930 "glGetTexLevelParameter[if]v(pname)");
933 case GL_TEXTURE_DEPTH_TYPE_ARB
:
934 if (ctx
->Extensions
.ARB_texture_float
) {
935 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
936 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
939 _mesa_error(ctx
, GL_INVALID_ENUM
,
940 "glGetTexLevelParameter[if]v(pname)");
945 _mesa_error(ctx
, GL_INVALID_ENUM
,
946 "glGetTexLevelParameter[if]v(pname)");
950 _mesa_unlock_texture(ctx
, texObj
);
956 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
958 struct gl_texture_unit
*texUnit
;
959 struct gl_texture_object
*obj
;
960 GLboolean error
= GL_FALSE
;
961 GET_CURRENT_CONTEXT(ctx
);
962 ASSERT_OUTSIDE_BEGIN_END(ctx
);
964 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
965 _mesa_error(ctx
, GL_INVALID_OPERATION
,
966 "glGetTexParameterfv(current unit)");
970 texUnit
= _mesa_get_current_tex_unit(ctx
);
972 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
974 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
978 _mesa_lock_texture(ctx
, obj
);
980 case GL_TEXTURE_MAG_FILTER
:
981 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
983 case GL_TEXTURE_MIN_FILTER
:
984 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
986 case GL_TEXTURE_WRAP_S
:
987 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
989 case GL_TEXTURE_WRAP_T
:
990 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
992 case GL_TEXTURE_WRAP_R
:
993 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
995 case GL_TEXTURE_BORDER_COLOR
:
996 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
997 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
998 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
999 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1001 case GL_TEXTURE_RESIDENT
:
1004 if (ctx
->Driver
.IsTextureResident
)
1005 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1008 *params
= ENUM_TO_FLOAT(resident
);
1011 case GL_TEXTURE_PRIORITY
:
1012 *params
= obj
->Priority
;
1014 case GL_TEXTURE_MIN_LOD
:
1015 *params
= obj
->MinLod
;
1017 case GL_TEXTURE_MAX_LOD
:
1018 *params
= obj
->MaxLod
;
1020 case GL_TEXTURE_BASE_LEVEL
:
1021 *params
= (GLfloat
) obj
->BaseLevel
;
1023 case GL_TEXTURE_MAX_LEVEL
:
1024 *params
= (GLfloat
) obj
->MaxLevel
;
1026 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1027 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1028 *params
= obj
->MaxAnisotropy
;
1033 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1034 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1035 *params
= obj
->CompareFailValue
;
1040 case GL_GENERATE_MIPMAP_SGIS
:
1041 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1042 *params
= (GLfloat
) obj
->GenerateMipmap
;
1047 case GL_TEXTURE_COMPARE_MODE_ARB
:
1048 if (ctx
->Extensions
.ARB_shadow
) {
1049 *params
= (GLfloat
) obj
->CompareMode
;
1054 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1055 if (ctx
->Extensions
.ARB_shadow
) {
1056 *params
= (GLfloat
) obj
->CompareFunc
;
1061 case GL_DEPTH_TEXTURE_MODE_ARB
:
1062 if (ctx
->Extensions
.ARB_depth_texture
) {
1063 *params
= (GLfloat
) obj
->DepthMode
;
1068 case GL_TEXTURE_LOD_BIAS
:
1069 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1070 *params
= obj
->LodBias
;
1075 #ifdef FEATURE_OES_draw_texture
1076 case GL_TEXTURE_CROP_RECT_OES
:
1077 params
[0] = obj
->CropRect
[0];
1078 params
[1] = obj
->CropRect
[1];
1079 params
[2] = obj
->CropRect
[2];
1080 params
[3] = obj
->CropRect
[3];
1084 case GL_TEXTURE_SWIZZLE_R_EXT
:
1085 case GL_TEXTURE_SWIZZLE_G_EXT
:
1086 case GL_TEXTURE_SWIZZLE_B_EXT
:
1087 case GL_TEXTURE_SWIZZLE_A_EXT
:
1088 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1089 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1090 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1097 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1098 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1100 for (comp
= 0; comp
< 4; comp
++) {
1101 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1115 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1118 _mesa_unlock_texture(ctx
, obj
);
1123 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1125 struct gl_texture_unit
*texUnit
;
1126 struct gl_texture_object
*obj
;
1127 GLboolean error
= GL_FALSE
;
1128 GET_CURRENT_CONTEXT(ctx
);
1129 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1131 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1132 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1133 "glGetTexParameteriv(current unit)");
1137 texUnit
= _mesa_get_current_tex_unit(ctx
);
1139 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1141 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1146 case GL_TEXTURE_MAG_FILTER
:
1147 *params
= (GLint
) obj
->MagFilter
;
1149 case GL_TEXTURE_MIN_FILTER
:
1150 *params
= (GLint
) obj
->MinFilter
;
1152 case GL_TEXTURE_WRAP_S
:
1153 *params
= (GLint
) obj
->WrapS
;
1155 case GL_TEXTURE_WRAP_T
:
1156 *params
= (GLint
) obj
->WrapT
;
1158 case GL_TEXTURE_WRAP_R
:
1159 *params
= (GLint
) obj
->WrapR
;
1161 case GL_TEXTURE_BORDER_COLOR
:
1164 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1165 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1166 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1167 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1168 params
[0] = FLOAT_TO_INT(b
[0]);
1169 params
[1] = FLOAT_TO_INT(b
[1]);
1170 params
[2] = FLOAT_TO_INT(b
[2]);
1171 params
[3] = FLOAT_TO_INT(b
[3]);
1174 case GL_TEXTURE_RESIDENT
:
1177 if (ctx
->Driver
.IsTextureResident
)
1178 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1181 *params
= (GLint
) resident
;
1184 case GL_TEXTURE_PRIORITY
:
1185 *params
= FLOAT_TO_INT(obj
->Priority
);
1187 case GL_TEXTURE_MIN_LOD
:
1188 *params
= (GLint
) obj
->MinLod
;
1190 case GL_TEXTURE_MAX_LOD
:
1191 *params
= (GLint
) obj
->MaxLod
;
1193 case GL_TEXTURE_BASE_LEVEL
:
1194 *params
= obj
->BaseLevel
;
1196 case GL_TEXTURE_MAX_LEVEL
:
1197 *params
= obj
->MaxLevel
;
1199 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1200 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1201 *params
= (GLint
) obj
->MaxAnisotropy
;
1207 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1208 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1209 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1215 case GL_GENERATE_MIPMAP_SGIS
:
1216 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1217 *params
= (GLint
) obj
->GenerateMipmap
;
1223 case GL_TEXTURE_COMPARE_MODE_ARB
:
1224 if (ctx
->Extensions
.ARB_shadow
) {
1225 *params
= (GLint
) obj
->CompareMode
;
1231 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1232 if (ctx
->Extensions
.ARB_shadow
) {
1233 *params
= (GLint
) obj
->CompareFunc
;
1239 case GL_DEPTH_TEXTURE_MODE_ARB
:
1240 if (ctx
->Extensions
.ARB_depth_texture
) {
1241 *params
= (GLint
) obj
->DepthMode
;
1247 case GL_TEXTURE_LOD_BIAS
:
1248 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1249 *params
= (GLint
) obj
->LodBias
;
1255 #ifdef FEATURE_OES_draw_texture
1256 case GL_TEXTURE_CROP_RECT_OES
:
1257 params
[0] = obj
->CropRect
[0];
1258 params
[1] = obj
->CropRect
[1];
1259 params
[2] = obj
->CropRect
[2];
1260 params
[3] = obj
->CropRect
[3];
1263 case GL_TEXTURE_SWIZZLE_R_EXT
:
1264 case GL_TEXTURE_SWIZZLE_G_EXT
:
1265 case GL_TEXTURE_SWIZZLE_B_EXT
:
1266 case GL_TEXTURE_SWIZZLE_A_EXT
:
1267 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1268 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1269 *params
= obj
->Swizzle
[comp
];
1276 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1277 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1278 COPY_4V(params
, obj
->Swizzle
);
1286 ; /* silence warnings */
1290 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1293 _mesa_unlock_texture(ctx
, obj
);