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/context.h"
35 #include "main/enums.h"
36 #include "main/colormac.h"
37 #include "main/macros.h"
38 #include "main/texcompress.h"
39 #include "main/texparam.h"
40 #include "main/teximage.h"
41 #include "main/texstate.h"
42 #include "shader/prog_instruction.h"
46 * Check if a coordinate wrap mode is supported for the texture target.
47 * \return GL_TRUE if legal, GL_FALSE otherwise
50 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
52 const struct gl_extensions
* const e
= & ctx
->Extensions
;
54 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
55 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
56 /* any texture target */
59 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
61 (wrap
== GL_MIRRORED_REPEAT
&&
62 e
->ARB_texture_mirrored_repeat
) ||
63 (wrap
== GL_MIRROR_CLAMP_EXT
&&
64 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
65 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
66 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
67 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
68 (e
->EXT_texture_mirror_clamp
)))) {
69 /* non-rectangle texture */
73 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
79 * Get current texture object for given target.
80 * Return NULL if any error.
82 static struct gl_texture_object
*
83 get_texobj(GLcontext
*ctx
, GLenum target
)
85 struct gl_texture_unit
*texUnit
;
87 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
88 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(current unit)");
92 texUnit
= _mesa_get_current_tex_unit(ctx
);
96 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
98 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
100 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
101 case GL_TEXTURE_CUBE_MAP
:
102 if (ctx
->Extensions
.ARB_texture_cube_map
) {
103 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
106 case GL_TEXTURE_RECTANGLE_NV
:
107 if (ctx
->Extensions
.NV_texture_rectangle
) {
108 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
111 case GL_TEXTURE_1D_ARRAY_EXT
:
112 if (ctx
->Extensions
.MESA_texture_array
) {
113 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
116 case GL_TEXTURE_2D_ARRAY_EXT
:
117 if (ctx
->Extensions
.MESA_texture_array
) {
118 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
125 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(target)");
131 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
132 * \return -1 if error.
135 comp_to_swizzle(GLenum comp
)
157 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
160 ASSERT(swz
<= SWIZZLE_NIL
);
162 GLuint mask
= 0x7 << (3 * comp
);
163 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
170 * This is called just prior to changing any texture object state.
171 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
172 * state flag and then mark the texture object as 'incomplete' so that any
173 * per-texture derived state gets recomputed.
176 flush(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
178 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
179 texObj
->_Complete
= GL_FALSE
;
184 * Set an integer-valued texture parameter
185 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
188 set_tex_parameteri(GLcontext
*ctx
,
189 struct gl_texture_object
*texObj
,
190 GLenum pname
, const GLint
*params
)
193 case GL_TEXTURE_MIN_FILTER
:
194 if (texObj
->MinFilter
== params
[0])
200 texObj
->MinFilter
= params
[0];
202 case GL_NEAREST_MIPMAP_NEAREST
:
203 case GL_LINEAR_MIPMAP_NEAREST
:
204 case GL_NEAREST_MIPMAP_LINEAR
:
205 case GL_LINEAR_MIPMAP_LINEAR
:
206 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
208 texObj
->MinFilter
= params
[0];
213 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
218 case GL_TEXTURE_MAG_FILTER
:
219 if (texObj
->MagFilter
== params
[0])
225 texObj
->MagFilter
= params
[0];
228 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
233 case GL_TEXTURE_WRAP_S
:
234 if (texObj
->WrapS
== params
[0])
236 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
238 texObj
->WrapS
= params
[0];
243 case GL_TEXTURE_WRAP_T
:
244 if (texObj
->WrapT
== params
[0])
246 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
248 texObj
->WrapT
= params
[0];
253 case GL_TEXTURE_WRAP_R
:
254 if (texObj
->WrapR
== params
[0])
256 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
258 texObj
->WrapR
= params
[0];
263 case GL_TEXTURE_BASE_LEVEL
:
264 if (texObj
->BaseLevel
== params
[0])
267 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
268 _mesa_error(ctx
, GL_INVALID_VALUE
,
269 "glTexParameter(param=%d)", params
[0]);
273 texObj
->BaseLevel
= params
[0];
276 case GL_TEXTURE_MAX_LEVEL
:
277 if (texObj
->MaxLevel
== params
[0])
279 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
281 "glTexParameter(param=%d)", params
[0]);
285 texObj
->MaxLevel
= params
[0];
288 case GL_GENERATE_MIPMAP_SGIS
:
289 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
290 if (texObj
->GenerateMipmap
!= params
[0]) {
292 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
298 _mesa_error(ctx
, GL_INVALID_ENUM
,
299 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
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 if (texObj
->DepthMode
!= params
[0]) {
359 texObj
->DepthMode
= params
[0];
364 _mesa_error(ctx
, GL_INVALID_ENUM
,
365 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
369 #ifdef FEATURE_OES_draw_texture
370 case GL_TEXTURE_CROP_RECT_OES
:
371 texObj
->CropRect
[0] = params
[0];
372 texObj
->CropRect
[1] = params
[1];
373 texObj
->CropRect
[2] = params
[2];
374 texObj
->CropRect
[3] = params
[3];
378 case GL_TEXTURE_SWIZZLE_R_EXT
:
379 case GL_TEXTURE_SWIZZLE_G_EXT
:
380 case GL_TEXTURE_SWIZZLE_B_EXT
:
381 case GL_TEXTURE_SWIZZLE_A_EXT
:
382 if (ctx
->Extensions
.EXT_texture_swizzle
) {
383 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
384 const GLint swz
= comp_to_swizzle(params
[0]);
386 _mesa_error(ctx
, GL_INVALID_OPERATION
,
387 "glTexParameter(swizzle 0x%x)", params
[0]);
393 texObj
->Swizzle
[comp
] = params
[0];
394 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
398 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
401 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
402 if (ctx
->Extensions
.EXT_texture_swizzle
) {
405 for (comp
= 0; comp
< 4; comp
++) {
406 const GLint swz
= comp_to_swizzle(params
[comp
]);
408 texObj
->Swizzle
[comp
] = params
[comp
];
409 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
413 "glTexParameter(swizzle 0x%x)", params
[comp
]);
419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
423 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
430 * Set a float-valued texture parameter
431 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
434 set_tex_parameterf(GLcontext
*ctx
,
435 struct gl_texture_object
*texObj
,
436 GLenum pname
, const GLfloat
*params
)
439 case GL_TEXTURE_MIN_LOD
:
440 if (texObj
->MinLod
== params
[0])
443 texObj
->MinLod
= params
[0];
446 case GL_TEXTURE_MAX_LOD
:
447 if (texObj
->MaxLod
== params
[0])
450 texObj
->MaxLod
= params
[0];
453 case GL_TEXTURE_PRIORITY
:
455 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
458 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
459 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
460 if (texObj
->MaxAnisotropy
== params
[0])
462 if (params
[0] < 1.0) {
463 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
467 /* clamp to max, that's what NVIDIA does */
468 texObj
->MaxAnisotropy
= MIN2(params
[0],
469 ctx
->Const
.MaxTextureMaxAnisotropy
);
473 static GLuint count
= 0;
475 _mesa_error(ctx
, GL_INVALID_ENUM
,
476 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
480 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
481 if (ctx
->Extensions
.ARB_shadow_ambient
) {
482 if (texObj
->CompareFailValue
!= params
[0]) {
484 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
489 _mesa_error(ctx
, GL_INVALID_ENUM
,
490 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
494 case GL_TEXTURE_LOD_BIAS
:
495 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
496 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
497 if (texObj
->LodBias
!= params
[0]) {
499 texObj
->LodBias
= params
[0];
506 case GL_TEXTURE_BORDER_COLOR
:
508 texObj
->BorderColor
[RCOMP
] = params
[0];
509 texObj
->BorderColor
[GCOMP
] = params
[1];
510 texObj
->BorderColor
[BCOMP
] = params
[2];
511 texObj
->BorderColor
[ACOMP
] = params
[3];
515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
522 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
524 GLboolean need_update
;
525 struct gl_texture_object
*texObj
;
526 GET_CURRENT_CONTEXT(ctx
);
527 ASSERT_OUTSIDE_BEGIN_END(ctx
);
529 texObj
= get_texobj(ctx
, target
);
534 case GL_TEXTURE_MIN_FILTER
:
535 case GL_TEXTURE_MAG_FILTER
:
536 case GL_TEXTURE_WRAP_S
:
537 case GL_TEXTURE_WRAP_T
:
538 case GL_TEXTURE_WRAP_R
:
539 case GL_TEXTURE_BASE_LEVEL
:
540 case GL_TEXTURE_MAX_LEVEL
:
541 case GL_GENERATE_MIPMAP_SGIS
:
542 case GL_TEXTURE_COMPARE_MODE_ARB
:
543 case GL_TEXTURE_COMPARE_FUNC_ARB
:
544 case GL_DEPTH_TEXTURE_MODE_ARB
:
546 /* convert float param to int */
548 p
[0] = (GLint
) param
;
549 p
[1] = p
[2] = p
[3] = 0;
550 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
555 /* this will generate an error if pname is illegal */
558 p
[1] = p
[2] = p
[3] = 0.0F
;
559 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
563 if (ctx
->Driver
.TexParameter
&& need_update
) {
564 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
570 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
572 GLboolean need_update
;
573 struct gl_texture_object
*texObj
;
574 GET_CURRENT_CONTEXT(ctx
);
575 ASSERT_OUTSIDE_BEGIN_END(ctx
);
577 texObj
= get_texobj(ctx
, target
);
582 case GL_TEXTURE_MIN_FILTER
:
583 case GL_TEXTURE_MAG_FILTER
:
584 case GL_TEXTURE_WRAP_S
:
585 case GL_TEXTURE_WRAP_T
:
586 case GL_TEXTURE_WRAP_R
:
587 case GL_TEXTURE_BASE_LEVEL
:
588 case GL_TEXTURE_MAX_LEVEL
:
589 case GL_GENERATE_MIPMAP_SGIS
:
590 case GL_TEXTURE_COMPARE_MODE_ARB
:
591 case GL_TEXTURE_COMPARE_FUNC_ARB
:
592 case GL_DEPTH_TEXTURE_MODE_ARB
:
594 /* convert float param to int */
595 GLint p
= (GLint
) params
[0];
596 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, &p
);
600 #ifdef 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
, target
, 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
);
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
:
645 GLfloat fparam
= (GLfloat
) param
;
646 /* convert int param to float */
647 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
651 /* this will generate an error if pname is illegal */
652 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, ¶m
);
655 if (ctx
->Driver
.TexParameter
&& need_update
) {
656 GLfloat fparam
= (GLfloat
) param
;
657 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
663 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
665 GLboolean need_update
;
666 struct gl_texture_object
*texObj
;
667 GET_CURRENT_CONTEXT(ctx
);
668 ASSERT_OUTSIDE_BEGIN_END(ctx
);
670 texObj
= get_texobj(ctx
, target
);
675 case GL_TEXTURE_BORDER_COLOR
:
677 /* convert int params to float */
679 fparams
[0] = INT_TO_FLOAT(params
[0]);
680 fparams
[1] = INT_TO_FLOAT(params
[1]);
681 fparams
[2] = INT_TO_FLOAT(params
[2]);
682 fparams
[3] = INT_TO_FLOAT(params
[3]);
683 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
686 case GL_TEXTURE_MIN_LOD
:
687 case GL_TEXTURE_MAX_LOD
:
688 case GL_TEXTURE_PRIORITY
:
689 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
690 case GL_TEXTURE_LOD_BIAS
:
691 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
693 /* convert int param to float */
694 GLfloat fparam
= (GLfloat
) params
[0];
695 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, &fparam
);
699 /* this will generate an error if pname is illegal */
700 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
703 if (ctx
->Driver
.TexParameter
&& need_update
) {
705 fparams
[0] = INT_TO_FLOAT(params
[0]);
706 if (pname
== GL_TEXTURE_BORDER_COLOR
||
707 pname
== GL_TEXTURE_CROP_RECT_OES
) {
708 fparams
[1] = INT_TO_FLOAT(params
[1]);
709 fparams
[2] = INT_TO_FLOAT(params
[2]);
710 fparams
[3] = INT_TO_FLOAT(params
[3]);
712 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
718 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
719 GLenum pname
, GLfloat
*params
)
722 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
723 *params
= (GLfloat
) iparam
;
728 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
729 GLenum pname
, GLint
*params
)
731 const struct gl_texture_unit
*texUnit
;
732 struct gl_texture_object
*texObj
;
733 const struct gl_texture_image
*img
= NULL
;
736 GET_CURRENT_CONTEXT(ctx
);
737 ASSERT_OUTSIDE_BEGIN_END(ctx
);
739 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
740 _mesa_error(ctx
, GL_INVALID_OPERATION
,
741 "glGetTexLevelParameteriv(current unit)");
745 texUnit
= _mesa_get_current_tex_unit(ctx
);
747 /* this will catch bad target values */
748 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
749 if (maxLevels
== 0) {
750 _mesa_error(ctx
, GL_INVALID_ENUM
,
751 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
755 if (level
< 0 || level
>= maxLevels
) {
756 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
760 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
761 _mesa_lock_texture(ctx
, texObj
);
763 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
764 if (!img
|| !img
->TexFormat
) {
765 /* undefined texture image */
766 if (pname
== GL_TEXTURE_COMPONENTS
)
773 isProxy
= _mesa_is_proxy_texture(target
);
776 case GL_TEXTURE_WIDTH
:
777 *params
= img
->Width
;
779 case GL_TEXTURE_HEIGHT
:
780 *params
= img
->Height
;
782 case GL_TEXTURE_DEPTH
:
783 *params
= img
->Depth
;
785 case GL_TEXTURE_INTERNAL_FORMAT
:
786 if (img
->IsCompressed
) {
787 /* need to return the actual compressed format */
788 *params
= _mesa_compressed_format_to_glenum(ctx
,
789 img
->TexFormat
->MesaFormat
);
792 /* return the user's requested internal format */
793 *params
= img
->InternalFormat
;
796 case GL_TEXTURE_BORDER
:
797 *params
= img
->Border
;
799 case GL_TEXTURE_RED_SIZE
:
800 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
801 *params
= img
->TexFormat
->RedBits
;
805 case GL_TEXTURE_GREEN_SIZE
:
806 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
807 *params
= img
->TexFormat
->GreenBits
;
811 case GL_TEXTURE_BLUE_SIZE
:
812 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
813 *params
= img
->TexFormat
->BlueBits
;
817 case GL_TEXTURE_ALPHA_SIZE
:
818 if (img
->_BaseFormat
== GL_ALPHA
||
819 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
820 img
->_BaseFormat
== GL_RGBA
)
821 *params
= img
->TexFormat
->AlphaBits
;
825 case GL_TEXTURE_INTENSITY_SIZE
:
826 if (img
->_BaseFormat
!= GL_INTENSITY
)
828 else if (img
->TexFormat
->IntensityBits
> 0)
829 *params
= img
->TexFormat
->IntensityBits
;
830 else /* intensity probably stored as rgb texture */
831 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
833 case GL_TEXTURE_LUMINANCE_SIZE
:
834 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
835 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
837 else if (img
->TexFormat
->LuminanceBits
> 0)
838 *params
= img
->TexFormat
->LuminanceBits
;
839 else /* luminance probably stored as rgb texture */
840 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
842 case GL_TEXTURE_INDEX_SIZE_EXT
:
843 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
844 *params
= img
->TexFormat
->IndexBits
;
848 case GL_TEXTURE_DEPTH_SIZE_ARB
:
849 if (ctx
->Extensions
.ARB_depth_texture
)
850 *params
= img
->TexFormat
->DepthBits
;
852 _mesa_error(ctx
, GL_INVALID_ENUM
,
853 "glGetTexLevelParameter[if]v(pname)");
855 case GL_TEXTURE_STENCIL_SIZE_EXT
:
856 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
857 ctx
->Extensions
.ARB_framebuffer_object
) {
858 *params
= img
->TexFormat
->StencilBits
;
861 _mesa_error(ctx
, GL_INVALID_ENUM
,
862 "glGetTexLevelParameter[if]v(pname)");
866 /* GL_ARB_texture_compression */
867 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
868 if (img
->IsCompressed
&& !isProxy
) {
869 /* Don't use ctx->Driver.CompressedTextureSize() since that
870 * may returned a padded hardware size.
872 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
873 img
->Height
, img
->Depth
,
874 img
->TexFormat
->MesaFormat
);
877 _mesa_error(ctx
, GL_INVALID_OPERATION
,
878 "glGetTexLevelParameter[if]v(pname)");
881 case GL_TEXTURE_COMPRESSED
:
882 *params
= (GLint
) img
->IsCompressed
;
885 /* GL_ARB_texture_float */
886 case GL_TEXTURE_RED_TYPE_ARB
:
887 if (ctx
->Extensions
.ARB_texture_float
) {
888 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
891 _mesa_error(ctx
, GL_INVALID_ENUM
,
892 "glGetTexLevelParameter[if]v(pname)");
895 case GL_TEXTURE_GREEN_TYPE_ARB
:
896 if (ctx
->Extensions
.ARB_texture_float
) {
897 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
900 _mesa_error(ctx
, GL_INVALID_ENUM
,
901 "glGetTexLevelParameter[if]v(pname)");
904 case GL_TEXTURE_BLUE_TYPE_ARB
:
905 if (ctx
->Extensions
.ARB_texture_float
) {
906 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
909 _mesa_error(ctx
, GL_INVALID_ENUM
,
910 "glGetTexLevelParameter[if]v(pname)");
913 case GL_TEXTURE_ALPHA_TYPE_ARB
:
914 if (ctx
->Extensions
.ARB_texture_float
) {
915 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
918 _mesa_error(ctx
, GL_INVALID_ENUM
,
919 "glGetTexLevelParameter[if]v(pname)");
922 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
923 if (ctx
->Extensions
.ARB_texture_float
) {
924 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
927 _mesa_error(ctx
, GL_INVALID_ENUM
,
928 "glGetTexLevelParameter[if]v(pname)");
931 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
932 if (ctx
->Extensions
.ARB_texture_float
) {
933 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
936 _mesa_error(ctx
, GL_INVALID_ENUM
,
937 "glGetTexLevelParameter[if]v(pname)");
940 case GL_TEXTURE_DEPTH_TYPE_ARB
:
941 if (ctx
->Extensions
.ARB_texture_float
) {
942 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
945 _mesa_error(ctx
, GL_INVALID_ENUM
,
946 "glGetTexLevelParameter[if]v(pname)");
951 _mesa_error(ctx
, GL_INVALID_ENUM
,
952 "glGetTexLevelParameter[if]v(pname)");
956 _mesa_unlock_texture(ctx
, texObj
);
962 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
964 struct gl_texture_unit
*texUnit
;
965 struct gl_texture_object
*obj
;
966 GLboolean error
= GL_FALSE
;
967 GET_CURRENT_CONTEXT(ctx
);
968 ASSERT_OUTSIDE_BEGIN_END(ctx
);
970 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
971 _mesa_error(ctx
, GL_INVALID_OPERATION
,
972 "glGetTexParameterfv(current unit)");
976 texUnit
= _mesa_get_current_tex_unit(ctx
);
978 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
980 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
984 _mesa_lock_texture(ctx
, obj
);
986 case GL_TEXTURE_MAG_FILTER
:
987 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
989 case GL_TEXTURE_MIN_FILTER
:
990 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
992 case GL_TEXTURE_WRAP_S
:
993 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
995 case GL_TEXTURE_WRAP_T
:
996 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
998 case GL_TEXTURE_WRAP_R
:
999 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1001 case GL_TEXTURE_BORDER_COLOR
:
1002 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1003 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1004 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1005 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1007 case GL_TEXTURE_RESIDENT
:
1010 if (ctx
->Driver
.IsTextureResident
)
1011 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1014 *params
= ENUM_TO_FLOAT(resident
);
1017 case GL_TEXTURE_PRIORITY
:
1018 *params
= obj
->Priority
;
1020 case GL_TEXTURE_MIN_LOD
:
1021 *params
= obj
->MinLod
;
1023 case GL_TEXTURE_MAX_LOD
:
1024 *params
= obj
->MaxLod
;
1026 case GL_TEXTURE_BASE_LEVEL
:
1027 *params
= (GLfloat
) obj
->BaseLevel
;
1029 case GL_TEXTURE_MAX_LEVEL
:
1030 *params
= (GLfloat
) obj
->MaxLevel
;
1032 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1033 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1034 *params
= obj
->MaxAnisotropy
;
1039 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1040 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1041 *params
= obj
->CompareFailValue
;
1046 case GL_GENERATE_MIPMAP_SGIS
:
1047 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1048 *params
= (GLfloat
) obj
->GenerateMipmap
;
1053 case GL_TEXTURE_COMPARE_MODE_ARB
:
1054 if (ctx
->Extensions
.ARB_shadow
) {
1055 *params
= (GLfloat
) obj
->CompareMode
;
1060 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1061 if (ctx
->Extensions
.ARB_shadow
) {
1062 *params
= (GLfloat
) obj
->CompareFunc
;
1067 case GL_DEPTH_TEXTURE_MODE_ARB
:
1068 if (ctx
->Extensions
.ARB_depth_texture
) {
1069 *params
= (GLfloat
) obj
->DepthMode
;
1074 case GL_TEXTURE_LOD_BIAS
:
1075 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1076 *params
= obj
->LodBias
;
1081 #ifdef FEATURE_OES_draw_texture
1082 case GL_TEXTURE_CROP_RECT_OES
:
1083 params
[0] = obj
->CropRect
[0];
1084 params
[1] = obj
->CropRect
[1];
1085 params
[2] = obj
->CropRect
[2];
1086 params
[3] = obj
->CropRect
[3];
1090 case GL_TEXTURE_SWIZZLE_R_EXT
:
1091 case GL_TEXTURE_SWIZZLE_G_EXT
:
1092 case GL_TEXTURE_SWIZZLE_B_EXT
:
1093 case GL_TEXTURE_SWIZZLE_A_EXT
:
1094 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1095 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1096 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1103 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1104 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1106 for (comp
= 0; comp
< 4; comp
++) {
1107 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1121 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1124 _mesa_unlock_texture(ctx
, obj
);
1129 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1131 struct gl_texture_unit
*texUnit
;
1132 struct gl_texture_object
*obj
;
1133 GLboolean error
= GL_FALSE
;
1134 GET_CURRENT_CONTEXT(ctx
);
1135 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1137 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1138 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1139 "glGetTexParameteriv(current unit)");
1143 texUnit
= _mesa_get_current_tex_unit(ctx
);
1145 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1147 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1152 case GL_TEXTURE_MAG_FILTER
:
1153 *params
= (GLint
) obj
->MagFilter
;
1155 case GL_TEXTURE_MIN_FILTER
:
1156 *params
= (GLint
) obj
->MinFilter
;
1158 case GL_TEXTURE_WRAP_S
:
1159 *params
= (GLint
) obj
->WrapS
;
1161 case GL_TEXTURE_WRAP_T
:
1162 *params
= (GLint
) obj
->WrapT
;
1164 case GL_TEXTURE_WRAP_R
:
1165 *params
= (GLint
) obj
->WrapR
;
1167 case GL_TEXTURE_BORDER_COLOR
:
1170 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1171 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1172 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1173 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1174 params
[0] = FLOAT_TO_INT(b
[0]);
1175 params
[1] = FLOAT_TO_INT(b
[1]);
1176 params
[2] = FLOAT_TO_INT(b
[2]);
1177 params
[3] = FLOAT_TO_INT(b
[3]);
1180 case GL_TEXTURE_RESIDENT
:
1183 if (ctx
->Driver
.IsTextureResident
)
1184 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1187 *params
= (GLint
) resident
;
1190 case GL_TEXTURE_PRIORITY
:
1191 *params
= FLOAT_TO_INT(obj
->Priority
);
1193 case GL_TEXTURE_MIN_LOD
:
1194 *params
= (GLint
) obj
->MinLod
;
1196 case GL_TEXTURE_MAX_LOD
:
1197 *params
= (GLint
) obj
->MaxLod
;
1199 case GL_TEXTURE_BASE_LEVEL
:
1200 *params
= obj
->BaseLevel
;
1202 case GL_TEXTURE_MAX_LEVEL
:
1203 *params
= obj
->MaxLevel
;
1205 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1206 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1207 *params
= (GLint
) obj
->MaxAnisotropy
;
1213 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1214 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1215 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1221 case GL_GENERATE_MIPMAP_SGIS
:
1222 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1223 *params
= (GLint
) obj
->GenerateMipmap
;
1229 case GL_TEXTURE_COMPARE_MODE_ARB
:
1230 if (ctx
->Extensions
.ARB_shadow
) {
1231 *params
= (GLint
) obj
->CompareMode
;
1237 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1238 if (ctx
->Extensions
.ARB_shadow
) {
1239 *params
= (GLint
) obj
->CompareFunc
;
1245 case GL_DEPTH_TEXTURE_MODE_ARB
:
1246 if (ctx
->Extensions
.ARB_depth_texture
) {
1247 *params
= (GLint
) obj
->DepthMode
;
1253 case GL_TEXTURE_LOD_BIAS
:
1254 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1255 *params
= (GLint
) obj
->LodBias
;
1261 #ifdef FEATURE_OES_draw_texture
1262 case GL_TEXTURE_CROP_RECT_OES
:
1263 params
[0] = obj
->CropRect
[0];
1264 params
[1] = obj
->CropRect
[1];
1265 params
[2] = obj
->CropRect
[2];
1266 params
[3] = obj
->CropRect
[3];
1269 case GL_TEXTURE_SWIZZLE_R_EXT
:
1270 case GL_TEXTURE_SWIZZLE_G_EXT
:
1271 case GL_TEXTURE_SWIZZLE_B_EXT
:
1272 case GL_TEXTURE_SWIZZLE_A_EXT
:
1273 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1274 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1275 *params
= obj
->Swizzle
[comp
];
1282 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1283 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1284 COPY_4V(params
, obj
->Swizzle
);
1292 ; /* silence warnings */
1296 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1299 _mesa_unlock_texture(ctx
, obj
);