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 "main/texfetch.h"
45 #include "program/prog_instruction.h"
49 * Check if a coordinate wrap mode is supported for the texture target.
50 * \return GL_TRUE if legal, GL_FALSE otherwise
53 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
55 const struct gl_extensions
* const e
= & ctx
->Extensions
;
57 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
58 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
59 /* any texture target */
62 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
64 (wrap
== GL_MIRRORED_REPEAT
&&
65 e
->ARB_texture_mirrored_repeat
) ||
66 (wrap
== GL_MIRROR_CLAMP_EXT
&&
67 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
68 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
69 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
70 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
71 (e
->EXT_texture_mirror_clamp
)))) {
72 /* non-rectangle texture */
76 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
82 * Get current texture object for given target.
83 * Return NULL if any error (and record the error).
84 * Note that this is different from _mesa_select_tex_object() in that proxy
85 * targets are not accepted.
86 * Only the glGetTexLevelParameter() functions accept proxy targets.
88 static struct gl_texture_object
*
89 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
91 struct gl_texture_unit
*texUnit
;
93 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
94 _mesa_error(ctx
, GL_INVALID_OPERATION
,
95 "gl%sTexParameter(current unit)", get
? "Get" : "");
99 texUnit
= _mesa_get_current_tex_unit(ctx
);
103 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
105 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
107 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
108 case GL_TEXTURE_CUBE_MAP
:
109 if (ctx
->Extensions
.ARB_texture_cube_map
) {
110 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
113 case GL_TEXTURE_RECTANGLE_NV
:
114 if (ctx
->Extensions
.NV_texture_rectangle
) {
115 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
118 case GL_TEXTURE_1D_ARRAY_EXT
:
119 if (ctx
->Extensions
.MESA_texture_array
) {
120 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
123 case GL_TEXTURE_2D_ARRAY_EXT
:
124 if (ctx
->Extensions
.MESA_texture_array
) {
125 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
132 _mesa_error(ctx
, GL_INVALID_ENUM
,
133 "gl%sTexParameter(target)", get
? "Get" : "");
139 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
140 * \return -1 if error.
143 comp_to_swizzle(GLenum comp
)
165 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
168 ASSERT(swz
<= SWIZZLE_NIL
);
170 GLuint mask
= 0x7 << (3 * comp
);
171 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
178 * This is called just prior to changing any texture object state which
179 * will not effect texture completeness.
182 flush(struct gl_context
*ctx
)
184 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
189 * This is called just prior to changing any texture object state which
190 * can effect texture completeness (texture base level, max level,
191 * minification filter).
192 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
193 * state flag and then mark the texture object as 'incomplete' so that any
194 * per-texture derived state gets recomputed.
197 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
199 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
200 texObj
->_Complete
= GL_FALSE
;
205 * Set an integer-valued texture parameter
206 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
209 set_tex_parameteri(struct gl_context
*ctx
,
210 struct gl_texture_object
*texObj
,
211 GLenum pname
, const GLint
*params
)
214 case GL_TEXTURE_MIN_FILTER
:
215 if (texObj
->MinFilter
== params
[0])
220 incomplete(ctx
, texObj
);
221 texObj
->MinFilter
= params
[0];
223 case GL_NEAREST_MIPMAP_NEAREST
:
224 case GL_LINEAR_MIPMAP_NEAREST
:
225 case GL_NEAREST_MIPMAP_LINEAR
:
226 case GL_LINEAR_MIPMAP_LINEAR
:
227 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
228 incomplete(ctx
, texObj
);
229 texObj
->MinFilter
= params
[0];
234 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
239 case GL_TEXTURE_MAG_FILTER
:
240 if (texObj
->MagFilter
== params
[0])
245 flush(ctx
); /* does not effect completeness */
246 texObj
->MagFilter
= params
[0];
249 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)",
254 case GL_TEXTURE_WRAP_S
:
255 if (texObj
->WrapS
== params
[0])
257 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
259 texObj
->WrapS
= params
[0];
264 case GL_TEXTURE_WRAP_T
:
265 if (texObj
->WrapT
== params
[0])
267 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
269 texObj
->WrapT
= params
[0];
274 case GL_TEXTURE_WRAP_R
:
275 if (texObj
->WrapR
== params
[0])
277 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
279 texObj
->WrapR
= params
[0];
284 case GL_TEXTURE_BASE_LEVEL
:
285 if (texObj
->BaseLevel
== params
[0])
288 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
289 _mesa_error(ctx
, GL_INVALID_VALUE
,
290 "glTexParameter(param=%d)", params
[0]);
293 incomplete(ctx
, texObj
);
294 texObj
->BaseLevel
= params
[0];
297 case GL_TEXTURE_MAX_LEVEL
:
298 if (texObj
->MaxLevel
== params
[0])
300 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
301 _mesa_error(ctx
, GL_INVALID_OPERATION
,
302 "glTexParameter(param=%d)", params
[0]);
305 incomplete(ctx
, texObj
);
306 texObj
->MaxLevel
= params
[0];
309 case GL_GENERATE_MIPMAP_SGIS
:
310 if (texObj
->GenerateMipmap
!= params
[0]) {
312 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
317 case GL_TEXTURE_COMPARE_MODE_ARB
:
318 if (ctx
->Extensions
.ARB_shadow
&&
319 (params
[0] == GL_NONE
||
320 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
)) {
321 if (texObj
->CompareMode
!= params
[0]) {
323 texObj
->CompareMode
= params
[0];
329 _mesa_error(ctx
, GL_INVALID_ENUM
,
330 "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
334 case GL_TEXTURE_COMPARE_FUNC_ARB
:
335 if (ctx
->Extensions
.ARB_shadow
) {
336 if (texObj
->CompareFunc
== params
[0])
342 texObj
->CompareFunc
= params
[0];
350 if (ctx
->Extensions
.EXT_shadow_funcs
) {
352 texObj
->CompareFunc
= params
[0];
357 _mesa_error(ctx
, GL_INVALID_ENUM
,
358 "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
362 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
366 case GL_DEPTH_TEXTURE_MODE_ARB
:
367 if (ctx
->Extensions
.ARB_depth_texture
&&
368 (params
[0] == GL_LUMINANCE
||
369 params
[0] == GL_INTENSITY
||
370 params
[0] == GL_ALPHA
||
371 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
))) {
372 if (texObj
->DepthMode
!= params
[0]) {
374 texObj
->DepthMode
= params
[0];
379 _mesa_error(ctx
, GL_INVALID_ENUM
,
380 "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
384 #if FEATURE_OES_draw_texture
385 case GL_TEXTURE_CROP_RECT_OES
:
386 texObj
->CropRect
[0] = params
[0];
387 texObj
->CropRect
[1] = params
[1];
388 texObj
->CropRect
[2] = params
[2];
389 texObj
->CropRect
[3] = params
[3];
393 case GL_TEXTURE_SWIZZLE_R_EXT
:
394 case GL_TEXTURE_SWIZZLE_G_EXT
:
395 case GL_TEXTURE_SWIZZLE_B_EXT
:
396 case GL_TEXTURE_SWIZZLE_A_EXT
:
397 if (ctx
->Extensions
.EXT_texture_swizzle
) {
398 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
399 const GLint swz
= comp_to_swizzle(params
[0]);
401 _mesa_error(ctx
, GL_INVALID_OPERATION
,
402 "glTexParameter(swizzle 0x%x)", params
[0]);
408 texObj
->Swizzle
[comp
] = params
[0];
409 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
413 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
416 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
417 if (ctx
->Extensions
.EXT_texture_swizzle
) {
420 for (comp
= 0; comp
< 4; comp
++) {
421 const GLint swz
= comp_to_swizzle(params
[comp
]);
423 texObj
->Swizzle
[comp
] = params
[comp
];
424 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
428 "glTexParameter(swizzle 0x%x)", params
[comp
]);
434 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
436 case GL_TEXTURE_SRGB_DECODE_EXT
:
437 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
438 GLenum decode
= params
[0];
439 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
440 if (texObj
->sRGBDecode
!= decode
) {
442 texObj
->sRGBDecode
= decode
;
443 _mesa_update_fetch_functions(texObj
);
448 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
451 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
458 * Set a float-valued texture parameter
459 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
462 set_tex_parameterf(struct gl_context
*ctx
,
463 struct gl_texture_object
*texObj
,
464 GLenum pname
, const GLfloat
*params
)
467 case GL_TEXTURE_MIN_LOD
:
468 if (texObj
->MinLod
== params
[0])
471 texObj
->MinLod
= params
[0];
474 case GL_TEXTURE_MAX_LOD
:
475 if (texObj
->MaxLod
== params
[0])
478 texObj
->MaxLod
= params
[0];
481 case GL_TEXTURE_PRIORITY
:
483 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
486 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
487 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
488 if (texObj
->MaxAnisotropy
== params
[0])
490 if (params
[0] < 1.0) {
491 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
495 /* clamp to max, that's what NVIDIA does */
496 texObj
->MaxAnisotropy
= MIN2(params
[0],
497 ctx
->Const
.MaxTextureMaxAnisotropy
);
501 static GLuint count
= 0;
503 _mesa_error(ctx
, GL_INVALID_ENUM
,
504 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
508 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
509 if (ctx
->Extensions
.ARB_shadow_ambient
) {
510 if (texObj
->CompareFailValue
!= params
[0]) {
512 texObj
->CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
517 _mesa_error(ctx
, GL_INVALID_ENUM
,
518 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
522 case GL_TEXTURE_LOD_BIAS
:
523 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
524 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
525 if (texObj
->LodBias
!= params
[0]) {
527 texObj
->LodBias
= params
[0];
534 case GL_TEXTURE_BORDER_COLOR
:
536 texObj
->BorderColor
.f
[RCOMP
] = params
[0];
537 texObj
->BorderColor
.f
[GCOMP
] = params
[1];
538 texObj
->BorderColor
.f
[BCOMP
] = params
[2];
539 texObj
->BorderColor
.f
[ACOMP
] = params
[3];
543 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
550 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
552 GLboolean need_update
;
553 struct gl_texture_object
*texObj
;
554 GET_CURRENT_CONTEXT(ctx
);
555 ASSERT_OUTSIDE_BEGIN_END(ctx
);
557 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
562 case GL_TEXTURE_MIN_FILTER
:
563 case GL_TEXTURE_MAG_FILTER
:
564 case GL_TEXTURE_WRAP_S
:
565 case GL_TEXTURE_WRAP_T
:
566 case GL_TEXTURE_WRAP_R
:
567 case GL_TEXTURE_BASE_LEVEL
:
568 case GL_TEXTURE_MAX_LEVEL
:
569 case GL_GENERATE_MIPMAP_SGIS
:
570 case GL_TEXTURE_COMPARE_MODE_ARB
:
571 case GL_TEXTURE_COMPARE_FUNC_ARB
:
572 case GL_DEPTH_TEXTURE_MODE_ARB
:
573 case GL_TEXTURE_SRGB_DECODE_EXT
:
575 /* convert float param to int */
577 p
[0] = (GLint
) param
;
578 p
[1] = p
[2] = p
[3] = 0;
579 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
584 /* this will generate an error if pname is illegal */
587 p
[1] = p
[2] = p
[3] = 0.0F
;
588 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
592 if (ctx
->Driver
.TexParameter
&& need_update
) {
593 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
599 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
601 GLboolean need_update
;
602 struct gl_texture_object
*texObj
;
603 GET_CURRENT_CONTEXT(ctx
);
604 ASSERT_OUTSIDE_BEGIN_END(ctx
);
606 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
611 case GL_TEXTURE_MIN_FILTER
:
612 case GL_TEXTURE_MAG_FILTER
:
613 case GL_TEXTURE_WRAP_S
:
614 case GL_TEXTURE_WRAP_T
:
615 case GL_TEXTURE_WRAP_R
:
616 case GL_TEXTURE_BASE_LEVEL
:
617 case GL_TEXTURE_MAX_LEVEL
:
618 case GL_GENERATE_MIPMAP_SGIS
:
619 case GL_TEXTURE_COMPARE_MODE_ARB
:
620 case GL_TEXTURE_COMPARE_FUNC_ARB
:
621 case GL_DEPTH_TEXTURE_MODE_ARB
:
622 case GL_TEXTURE_SRGB_DECODE_EXT
:
624 /* convert float param to int */
626 p
[0] = (GLint
) params
[0];
627 p
[1] = p
[2] = p
[3] = 0;
628 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
632 #if FEATURE_OES_draw_texture
633 case GL_TEXTURE_CROP_RECT_OES
:
635 /* convert float params to int */
637 iparams
[0] = (GLint
) params
[0];
638 iparams
[1] = (GLint
) params
[1];
639 iparams
[2] = (GLint
) params
[2];
640 iparams
[3] = (GLint
) params
[3];
641 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
647 /* this will generate an error if pname is illegal */
648 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
651 if (ctx
->Driver
.TexParameter
&& need_update
) {
652 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
658 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
660 GLboolean need_update
;
661 struct gl_texture_object
*texObj
;
662 GET_CURRENT_CONTEXT(ctx
);
663 ASSERT_OUTSIDE_BEGIN_END(ctx
);
665 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
670 case GL_TEXTURE_MIN_LOD
:
671 case GL_TEXTURE_MAX_LOD
:
672 case GL_TEXTURE_PRIORITY
:
673 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
674 case GL_TEXTURE_LOD_BIAS
:
675 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
678 fparam
[0] = (GLfloat
) param
;
679 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
680 /* convert int param to float */
681 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
685 /* this will generate an error if pname is illegal */
689 iparam
[1] = iparam
[2] = iparam
[3] = 0;
690 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
694 if (ctx
->Driver
.TexParameter
&& need_update
) {
695 GLfloat fparam
= (GLfloat
) param
;
696 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
702 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
704 GLboolean need_update
;
705 struct gl_texture_object
*texObj
;
706 GET_CURRENT_CONTEXT(ctx
);
707 ASSERT_OUTSIDE_BEGIN_END(ctx
);
709 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
714 case GL_TEXTURE_BORDER_COLOR
:
716 /* convert int params to float */
718 fparams
[0] = INT_TO_FLOAT(params
[0]);
719 fparams
[1] = INT_TO_FLOAT(params
[1]);
720 fparams
[2] = INT_TO_FLOAT(params
[2]);
721 fparams
[3] = INT_TO_FLOAT(params
[3]);
722 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
725 case GL_TEXTURE_MIN_LOD
:
726 case GL_TEXTURE_MAX_LOD
:
727 case GL_TEXTURE_PRIORITY
:
728 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
729 case GL_TEXTURE_LOD_BIAS
:
730 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
732 /* convert int param to float */
734 fparams
[0] = (GLfloat
) params
[0];
735 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
736 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
740 /* this will generate an error if pname is illegal */
741 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
744 if (ctx
->Driver
.TexParameter
&& need_update
) {
746 fparams
[0] = INT_TO_FLOAT(params
[0]);
747 if (pname
== GL_TEXTURE_BORDER_COLOR
||
748 pname
== GL_TEXTURE_CROP_RECT_OES
) {
749 fparams
[1] = INT_TO_FLOAT(params
[1]);
750 fparams
[2] = INT_TO_FLOAT(params
[2]);
751 fparams
[3] = INT_TO_FLOAT(params
[3]);
753 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
759 * Set tex parameter to integer value(s). Primarily intended to set
760 * integer-valued texture border color (for integer-valued textures).
764 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
766 struct gl_texture_object
*texObj
;
767 GET_CURRENT_CONTEXT(ctx
);
768 ASSERT_OUTSIDE_BEGIN_END(ctx
);
770 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
775 case GL_TEXTURE_BORDER_COLOR
:
776 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
777 /* set the integer-valued border color */
778 COPY_4V(texObj
->BorderColor
.i
, params
);
781 _mesa_TexParameteriv(target
, pname
, params
);
784 /* XXX no driver hook for TexParameterIiv() yet */
789 * Set tex parameter to unsigned integer value(s). Primarily intended to set
790 * uint-valued texture border color (for integer-valued textures).
794 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
796 struct gl_texture_object
*texObj
;
797 GET_CURRENT_CONTEXT(ctx
);
798 ASSERT_OUTSIDE_BEGIN_END(ctx
);
800 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
805 case GL_TEXTURE_BORDER_COLOR
:
806 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
807 /* set the unsigned integer-valued border color */
808 COPY_4V(texObj
->BorderColor
.ui
, params
);
811 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
814 /* XXX no driver hook for TexParameterIuiv() yet */
821 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
822 GLenum pname
, GLfloat
*params
)
825 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
826 *params
= (GLfloat
) iparam
;
831 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
832 GLenum pname
, GLint
*params
)
834 const struct gl_texture_unit
*texUnit
;
835 struct gl_texture_object
*texObj
;
836 const struct gl_texture_image
*img
= NULL
;
840 GET_CURRENT_CONTEXT(ctx
);
841 ASSERT_OUTSIDE_BEGIN_END(ctx
);
843 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
845 "glGetTexLevelParameteriv(current unit)");
849 texUnit
= _mesa_get_current_tex_unit(ctx
);
851 /* this will catch bad target values */
852 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
853 if (maxLevels
== 0) {
854 _mesa_error(ctx
, GL_INVALID_ENUM
,
855 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
859 if (level
< 0 || level
>= maxLevels
) {
860 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
864 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
865 _mesa_lock_texture(ctx
, texObj
);
867 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
868 if (!img
|| !img
->TexFormat
) {
869 /* undefined texture image */
870 if (pname
== GL_TEXTURE_COMPONENTS
)
877 texFormat
= img
->TexFormat
;
879 isProxy
= _mesa_is_proxy_texture(target
);
882 case GL_TEXTURE_WIDTH
:
883 *params
= img
->Width
;
885 case GL_TEXTURE_HEIGHT
:
886 *params
= img
->Height
;
888 case GL_TEXTURE_DEPTH
:
889 *params
= img
->Depth
;
891 case GL_TEXTURE_INTERNAL_FORMAT
:
892 if (_mesa_is_format_compressed(img
->TexFormat
)) {
893 /* need to return the actual compressed format */
894 *params
= _mesa_compressed_format_to_glenum(ctx
, img
->TexFormat
);
897 /* return the user's requested internal format */
898 *params
= img
->InternalFormat
;
901 case GL_TEXTURE_BORDER
:
902 *params
= img
->Border
;
904 case GL_TEXTURE_RED_SIZE
:
905 if (img
->_BaseFormat
== GL_RED
) {
906 *params
= _mesa_get_format_bits(texFormat
, pname
);
910 case GL_TEXTURE_GREEN_SIZE
:
911 if (img
->_BaseFormat
== GL_RG
) {
912 *params
= _mesa_get_format_bits(texFormat
, pname
);
916 case GL_TEXTURE_BLUE_SIZE
:
917 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
918 *params
= _mesa_get_format_bits(texFormat
, pname
);
922 case GL_TEXTURE_ALPHA_SIZE
:
923 if (img
->_BaseFormat
== GL_ALPHA
||
924 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
925 img
->_BaseFormat
== GL_RGBA
)
926 *params
= _mesa_get_format_bits(texFormat
, pname
);
930 case GL_TEXTURE_INTENSITY_SIZE
:
931 if (img
->_BaseFormat
!= GL_INTENSITY
)
934 *params
= _mesa_get_format_bits(texFormat
, pname
);
936 /* intensity probably stored as rgb texture */
937 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
938 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
942 case GL_TEXTURE_LUMINANCE_SIZE
:
943 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
944 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
947 *params
= _mesa_get_format_bits(texFormat
, pname
);
949 /* luminance probably stored as rgb texture */
950 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
951 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
955 case GL_TEXTURE_INDEX_SIZE_EXT
:
956 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
957 *params
= _mesa_get_format_bits(texFormat
, pname
);
961 case GL_TEXTURE_DEPTH_SIZE_ARB
:
962 if (ctx
->Extensions
.ARB_depth_texture
)
963 *params
= _mesa_get_format_bits(texFormat
, pname
);
965 _mesa_error(ctx
, GL_INVALID_ENUM
,
966 "glGetTexLevelParameter[if]v(pname)");
968 case GL_TEXTURE_STENCIL_SIZE_EXT
:
969 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
970 ctx
->Extensions
.ARB_framebuffer_object
) {
971 *params
= _mesa_get_format_bits(texFormat
, pname
);
974 _mesa_error(ctx
, GL_INVALID_ENUM
,
975 "glGetTexLevelParameter[if]v(pname)");
978 case GL_TEXTURE_SHARED_SIZE
:
979 if (ctx
->VersionMajor
>= 3) {
980 /* XXX return number of exponent bits for shared exponent texture
981 * formats, like GL_RGB9_E5.
986 _mesa_error(ctx
, GL_INVALID_ENUM
,
987 "glGetTexLevelParameter[if]v(pname)");
991 /* GL_ARB_texture_compression */
992 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
993 if (_mesa_is_format_compressed(img
->TexFormat
) && !isProxy
) {
994 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
995 img
->Height
, img
->Depth
);
998 _mesa_error(ctx
, GL_INVALID_OPERATION
,
999 "glGetTexLevelParameter[if]v(pname)");
1002 case GL_TEXTURE_COMPRESSED
:
1003 *params
= (GLint
) _mesa_is_format_compressed(img
->TexFormat
);
1006 /* GL_ARB_texture_float */
1007 case GL_TEXTURE_RED_TYPE_ARB
:
1008 if (ctx
->Extensions
.ARB_texture_float
) {
1009 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
1010 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1013 _mesa_error(ctx
, GL_INVALID_ENUM
,
1014 "glGetTexLevelParameter[if]v(pname)");
1017 case GL_TEXTURE_GREEN_TYPE_ARB
:
1018 if (ctx
->Extensions
.ARB_texture_float
) {
1019 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1020 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1023 _mesa_error(ctx
, GL_INVALID_ENUM
,
1024 "glGetTexLevelParameter[if]v(pname)");
1027 case GL_TEXTURE_BLUE_TYPE_ARB
:
1028 if (ctx
->Extensions
.ARB_texture_float
) {
1029 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1030 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1033 _mesa_error(ctx
, GL_INVALID_ENUM
,
1034 "glGetTexLevelParameter[if]v(pname)");
1037 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1038 if (ctx
->Extensions
.ARB_texture_float
) {
1039 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1040 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1043 _mesa_error(ctx
, GL_INVALID_ENUM
,
1044 "glGetTexLevelParameter[if]v(pname)");
1047 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1048 if (ctx
->Extensions
.ARB_texture_float
) {
1049 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1050 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1053 _mesa_error(ctx
, GL_INVALID_ENUM
,
1054 "glGetTexLevelParameter[if]v(pname)");
1057 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1058 if (ctx
->Extensions
.ARB_texture_float
) {
1059 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1060 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1063 _mesa_error(ctx
, GL_INVALID_ENUM
,
1064 "glGetTexLevelParameter[if]v(pname)");
1067 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1068 if (ctx
->Extensions
.ARB_texture_float
) {
1069 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1070 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1073 _mesa_error(ctx
, GL_INVALID_ENUM
,
1074 "glGetTexLevelParameter[if]v(pname)");
1079 _mesa_error(ctx
, GL_INVALID_ENUM
,
1080 "glGetTexLevelParameter[if]v(pname)");
1084 _mesa_unlock_texture(ctx
, texObj
);
1090 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1092 struct gl_texture_object
*obj
;
1093 GLboolean error
= GL_FALSE
;
1094 GET_CURRENT_CONTEXT(ctx
);
1095 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1097 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1101 _mesa_lock_texture(ctx
, obj
);
1103 case GL_TEXTURE_MAG_FILTER
:
1104 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1106 case GL_TEXTURE_MIN_FILTER
:
1107 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1109 case GL_TEXTURE_WRAP_S
:
1110 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1112 case GL_TEXTURE_WRAP_T
:
1113 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1115 case GL_TEXTURE_WRAP_R
:
1116 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1118 case GL_TEXTURE_BORDER_COLOR
:
1119 params
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1120 params
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1121 params
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1122 params
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1124 case GL_TEXTURE_RESIDENT
:
1127 if (ctx
->Driver
.IsTextureResident
)
1128 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1131 *params
= ENUM_TO_FLOAT(resident
);
1134 case GL_TEXTURE_PRIORITY
:
1135 *params
= obj
->Priority
;
1137 case GL_TEXTURE_MIN_LOD
:
1138 *params
= obj
->MinLod
;
1140 case GL_TEXTURE_MAX_LOD
:
1141 *params
= obj
->MaxLod
;
1143 case GL_TEXTURE_BASE_LEVEL
:
1144 *params
= (GLfloat
) obj
->BaseLevel
;
1146 case GL_TEXTURE_MAX_LEVEL
:
1147 *params
= (GLfloat
) obj
->MaxLevel
;
1149 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1150 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1151 *params
= obj
->MaxAnisotropy
;
1156 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1157 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1158 *params
= obj
->CompareFailValue
;
1163 case GL_GENERATE_MIPMAP_SGIS
:
1164 *params
= (GLfloat
) obj
->GenerateMipmap
;
1166 case GL_TEXTURE_COMPARE_MODE_ARB
:
1167 if (ctx
->Extensions
.ARB_shadow
) {
1168 *params
= (GLfloat
) obj
->CompareMode
;
1173 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1174 if (ctx
->Extensions
.ARB_shadow
) {
1175 *params
= (GLfloat
) obj
->CompareFunc
;
1180 case GL_DEPTH_TEXTURE_MODE_ARB
:
1181 if (ctx
->Extensions
.ARB_depth_texture
) {
1182 *params
= (GLfloat
) obj
->DepthMode
;
1187 case GL_TEXTURE_LOD_BIAS
:
1188 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1189 *params
= obj
->LodBias
;
1194 #if FEATURE_OES_draw_texture
1195 case GL_TEXTURE_CROP_RECT_OES
:
1196 params
[0] = obj
->CropRect
[0];
1197 params
[1] = obj
->CropRect
[1];
1198 params
[2] = obj
->CropRect
[2];
1199 params
[3] = obj
->CropRect
[3];
1203 case GL_TEXTURE_SWIZZLE_R_EXT
:
1204 case GL_TEXTURE_SWIZZLE_G_EXT
:
1205 case GL_TEXTURE_SWIZZLE_B_EXT
:
1206 case GL_TEXTURE_SWIZZLE_A_EXT
:
1207 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1208 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1209 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1216 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1217 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1219 for (comp
= 0; comp
< 4; comp
++) {
1220 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1234 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1237 _mesa_unlock_texture(ctx
, obj
);
1242 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1244 struct gl_texture_object
*obj
;
1245 GLboolean error
= GL_FALSE
;
1246 GET_CURRENT_CONTEXT(ctx
);
1247 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1249 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1253 _mesa_lock_texture(ctx
, obj
);
1255 case GL_TEXTURE_MAG_FILTER
:
1256 *params
= (GLint
) obj
->MagFilter
;
1258 case GL_TEXTURE_MIN_FILTER
:
1259 *params
= (GLint
) obj
->MinFilter
;
1261 case GL_TEXTURE_WRAP_S
:
1262 *params
= (GLint
) obj
->WrapS
;
1264 case GL_TEXTURE_WRAP_T
:
1265 *params
= (GLint
) obj
->WrapT
;
1267 case GL_TEXTURE_WRAP_R
:
1268 *params
= (GLint
) obj
->WrapR
;
1270 case GL_TEXTURE_BORDER_COLOR
:
1273 b
[0] = CLAMP(obj
->BorderColor
.f
[0], 0.0F
, 1.0F
);
1274 b
[1] = CLAMP(obj
->BorderColor
.f
[1], 0.0F
, 1.0F
);
1275 b
[2] = CLAMP(obj
->BorderColor
.f
[2], 0.0F
, 1.0F
);
1276 b
[3] = CLAMP(obj
->BorderColor
.f
[3], 0.0F
, 1.0F
);
1277 params
[0] = FLOAT_TO_INT(b
[0]);
1278 params
[1] = FLOAT_TO_INT(b
[1]);
1279 params
[2] = FLOAT_TO_INT(b
[2]);
1280 params
[3] = FLOAT_TO_INT(b
[3]);
1283 case GL_TEXTURE_RESIDENT
:
1286 if (ctx
->Driver
.IsTextureResident
)
1287 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1290 *params
= (GLint
) resident
;
1293 case GL_TEXTURE_PRIORITY
:
1294 *params
= FLOAT_TO_INT(obj
->Priority
);
1296 case GL_TEXTURE_MIN_LOD
:
1297 *params
= (GLint
) obj
->MinLod
;
1299 case GL_TEXTURE_MAX_LOD
:
1300 *params
= (GLint
) obj
->MaxLod
;
1302 case GL_TEXTURE_BASE_LEVEL
:
1303 *params
= obj
->BaseLevel
;
1305 case GL_TEXTURE_MAX_LEVEL
:
1306 *params
= obj
->MaxLevel
;
1308 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1309 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1310 *params
= (GLint
) obj
->MaxAnisotropy
;
1316 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1317 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1318 *params
= (GLint
) FLOAT_TO_INT(obj
->CompareFailValue
);
1324 case GL_GENERATE_MIPMAP_SGIS
:
1325 *params
= (GLint
) obj
->GenerateMipmap
;
1327 case GL_TEXTURE_COMPARE_MODE_ARB
:
1328 if (ctx
->Extensions
.ARB_shadow
) {
1329 *params
= (GLint
) obj
->CompareMode
;
1335 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1336 if (ctx
->Extensions
.ARB_shadow
) {
1337 *params
= (GLint
) obj
->CompareFunc
;
1343 case GL_DEPTH_TEXTURE_MODE_ARB
:
1344 if (ctx
->Extensions
.ARB_depth_texture
) {
1345 *params
= (GLint
) obj
->DepthMode
;
1351 case GL_TEXTURE_LOD_BIAS
:
1352 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1353 *params
= (GLint
) obj
->LodBias
;
1359 #if FEATURE_OES_draw_texture
1360 case GL_TEXTURE_CROP_RECT_OES
:
1361 params
[0] = obj
->CropRect
[0];
1362 params
[1] = obj
->CropRect
[1];
1363 params
[2] = obj
->CropRect
[2];
1364 params
[3] = obj
->CropRect
[3];
1367 case GL_TEXTURE_SWIZZLE_R_EXT
:
1368 case GL_TEXTURE_SWIZZLE_G_EXT
:
1369 case GL_TEXTURE_SWIZZLE_B_EXT
:
1370 case GL_TEXTURE_SWIZZLE_A_EXT
:
1371 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1372 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1373 *params
= obj
->Swizzle
[comp
];
1380 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1381 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1382 COPY_4V(params
, obj
->Swizzle
);
1390 ; /* silence warnings */
1394 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1397 _mesa_unlock_texture(ctx
, obj
);
1401 /** New in GL 3.0 */
1403 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1405 struct gl_texture_object
*texObj
;
1406 GET_CURRENT_CONTEXT(ctx
);
1407 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1409 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1412 case GL_TEXTURE_BORDER_COLOR
:
1413 COPY_4V(params
, texObj
->BorderColor
.i
);
1416 _mesa_GetTexParameteriv(target
, pname
, params
);
1421 /** New in GL 3.0 */
1423 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1425 struct gl_texture_object
*texObj
;
1426 GET_CURRENT_CONTEXT(ctx
);
1427 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1429 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1432 case GL_TEXTURE_BORDER_COLOR
:
1433 COPY_4V(params
, texObj
->BorderColor
.i
);
1438 _mesa_GetTexParameteriv(target
, pname
, ip
);
1440 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1441 pname
== GL_TEXTURE_CROP_RECT_OES
) {