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/mfeatures.h"
40 #include "main/mtypes.h"
41 #include "main/state.h"
42 #include "main/texcompress.h"
43 #include "main/texparam.h"
44 #include "main/teximage.h"
45 #include "main/texstate.h"
46 #include "program/prog_instruction.h"
50 * Check if a coordinate wrap mode is supported for the texture target.
51 * \return GL_TRUE if legal, GL_FALSE otherwise
54 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
56 const struct gl_extensions
* const e
= & ctx
->Extensions
;
58 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
59 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
60 /* any texture target */
63 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
65 wrap
== GL_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 ctx
->Extensions
.EXT_texture_array
) {
121 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
124 case GL_TEXTURE_2D_ARRAY_EXT
:
125 if (ctx
->Extensions
.MESA_texture_array
||
126 ctx
->Extensions
.EXT_texture_array
) {
127 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
134 _mesa_error(ctx
, GL_INVALID_ENUM
,
135 "gl%sTexParameter(target)", get
? "Get" : "");
141 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
142 * \return -1 if error.
145 comp_to_swizzle(GLenum comp
)
167 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
170 ASSERT(swz
<= SWIZZLE_NIL
);
172 GLuint mask
= 0x7 << (3 * comp
);
173 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
180 * This is called just prior to changing any texture object state which
181 * will not effect texture completeness.
184 flush(struct gl_context
*ctx
)
186 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
191 * This is called just prior to changing any texture object state which
192 * can effect texture completeness (texture base level, max level,
193 * minification filter).
194 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
195 * state flag and then mark the texture object as 'incomplete' so that any
196 * per-texture derived state gets recomputed.
199 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
201 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
202 texObj
->_Complete
= GL_FALSE
;
207 * Set an integer-valued texture parameter
208 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
211 set_tex_parameteri(struct gl_context
*ctx
,
212 struct gl_texture_object
*texObj
,
213 GLenum pname
, const GLint
*params
)
216 case GL_TEXTURE_MIN_FILTER
:
217 if (texObj
->Sampler
.MinFilter
== params
[0])
222 incomplete(ctx
, texObj
);
223 texObj
->Sampler
.MinFilter
= params
[0];
225 case GL_NEAREST_MIPMAP_NEAREST
:
226 case GL_LINEAR_MIPMAP_NEAREST
:
227 case GL_NEAREST_MIPMAP_LINEAR
:
228 case GL_LINEAR_MIPMAP_LINEAR
:
229 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
230 incomplete(ctx
, texObj
);
231 texObj
->Sampler
.MinFilter
= params
[0];
240 case GL_TEXTURE_MAG_FILTER
:
241 if (texObj
->Sampler
.MagFilter
== params
[0])
246 flush(ctx
); /* does not effect completeness */
247 texObj
->Sampler
.MagFilter
= params
[0];
254 case GL_TEXTURE_WRAP_S
:
255 if (texObj
->Sampler
.WrapS
== params
[0])
257 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
259 texObj
->Sampler
.WrapS
= params
[0];
264 case GL_TEXTURE_WRAP_T
:
265 if (texObj
->Sampler
.WrapT
== params
[0])
267 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
269 texObj
->Sampler
.WrapT
= params
[0];
274 case GL_TEXTURE_WRAP_R
:
275 if (texObj
->Sampler
.WrapR
== params
[0])
277 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
279 texObj
->Sampler
.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 if (texObj
->Sampler
.CompareMode
== params
[0])
321 if (params
[0] == GL_NONE
||
322 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
324 texObj
->Sampler
.CompareMode
= params
[0];
331 case GL_TEXTURE_COMPARE_FUNC_ARB
:
332 if (ctx
->Extensions
.ARB_shadow
) {
333 if (texObj
->Sampler
.CompareFunc
== params
[0])
339 texObj
->Sampler
.CompareFunc
= params
[0];
347 if (ctx
->Extensions
.EXT_shadow_funcs
) {
349 texObj
->Sampler
.CompareFunc
= params
[0];
359 case GL_DEPTH_TEXTURE_MODE_ARB
:
360 if (ctx
->Extensions
.ARB_depth_texture
) {
361 if (texObj
->Sampler
.DepthMode
== params
[0])
363 if (params
[0] == GL_LUMINANCE
||
364 params
[0] == GL_INTENSITY
||
365 params
[0] == GL_ALPHA
||
366 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
368 texObj
->Sampler
.DepthMode
= params
[0];
375 #if FEATURE_OES_draw_texture
376 case GL_TEXTURE_CROP_RECT_OES
:
377 texObj
->CropRect
[0] = params
[0];
378 texObj
->CropRect
[1] = params
[1];
379 texObj
->CropRect
[2] = params
[2];
380 texObj
->CropRect
[3] = params
[3];
384 case GL_TEXTURE_SWIZZLE_R_EXT
:
385 case GL_TEXTURE_SWIZZLE_G_EXT
:
386 case GL_TEXTURE_SWIZZLE_B_EXT
:
387 case GL_TEXTURE_SWIZZLE_A_EXT
:
388 if (ctx
->Extensions
.EXT_texture_swizzle
) {
389 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
390 const GLint swz
= comp_to_swizzle(params
[0]);
392 _mesa_error(ctx
, GL_INVALID_OPERATION
,
393 "glTexParameter(swizzle 0x%x)", params
[0]);
399 texObj
->Swizzle
[comp
] = params
[0];
400 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
406 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
407 if (ctx
->Extensions
.EXT_texture_swizzle
) {
410 for (comp
= 0; comp
< 4; comp
++) {
411 const GLint swz
= comp_to_swizzle(params
[comp
]);
413 texObj
->Swizzle
[comp
] = params
[comp
];
414 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
417 _mesa_error(ctx
, GL_INVALID_OPERATION
,
418 "glTexParameter(swizzle 0x%x)", params
[comp
]);
426 case GL_TEXTURE_SRGB_DECODE_EXT
:
427 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
428 GLenum decode
= params
[0];
429 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
430 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
432 texObj
->Sampler
.sRGBDecode
= decode
;
439 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
440 if (ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
441 GLenum param
= params
[0];
442 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
445 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
447 texObj
->Sampler
.CubeMapSeamless
= param
;
458 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
459 _mesa_lookup_enum_by_nr(pname
));
463 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
464 _mesa_lookup_enum_by_nr(params
[0]));
470 * Set a float-valued texture parameter
471 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
474 set_tex_parameterf(struct gl_context
*ctx
,
475 struct gl_texture_object
*texObj
,
476 GLenum pname
, const GLfloat
*params
)
479 case GL_TEXTURE_MIN_LOD
:
480 if (texObj
->Sampler
.MinLod
== params
[0])
483 texObj
->Sampler
.MinLod
= params
[0];
486 case GL_TEXTURE_MAX_LOD
:
487 if (texObj
->Sampler
.MaxLod
== params
[0])
490 texObj
->Sampler
.MaxLod
= params
[0];
493 case GL_TEXTURE_PRIORITY
:
495 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
498 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
499 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
500 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
502 if (params
[0] < 1.0) {
503 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
507 /* clamp to max, that's what NVIDIA does */
508 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
509 ctx
->Const
.MaxTextureMaxAnisotropy
);
513 static GLuint count
= 0;
515 _mesa_error(ctx
, GL_INVALID_ENUM
,
516 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
520 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
521 if (ctx
->Extensions
.ARB_shadow_ambient
) {
522 if (texObj
->Sampler
.CompareFailValue
!= params
[0]) {
524 texObj
->Sampler
.CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
529 _mesa_error(ctx
, GL_INVALID_ENUM
,
530 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
534 case GL_TEXTURE_LOD_BIAS
:
535 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
536 if (texObj
->Sampler
.LodBias
!= params
[0]) {
538 texObj
->Sampler
.LodBias
= params
[0];
543 case GL_TEXTURE_BORDER_COLOR
:
545 /* ARB_texture_float disables clamping */
546 if (ctx
->Extensions
.ARB_texture_float
) {
547 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
548 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
549 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
550 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
552 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
553 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
554 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
555 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
560 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
567 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
569 GLboolean need_update
;
570 struct gl_texture_object
*texObj
;
571 GET_CURRENT_CONTEXT(ctx
);
572 ASSERT_OUTSIDE_BEGIN_END(ctx
);
574 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
579 case GL_TEXTURE_MIN_FILTER
:
580 case GL_TEXTURE_MAG_FILTER
:
581 case GL_TEXTURE_WRAP_S
:
582 case GL_TEXTURE_WRAP_T
:
583 case GL_TEXTURE_WRAP_R
:
584 case GL_TEXTURE_BASE_LEVEL
:
585 case GL_TEXTURE_MAX_LEVEL
:
586 case GL_GENERATE_MIPMAP_SGIS
:
587 case GL_TEXTURE_COMPARE_MODE_ARB
:
588 case GL_TEXTURE_COMPARE_FUNC_ARB
:
589 case GL_DEPTH_TEXTURE_MODE_ARB
:
590 case GL_TEXTURE_SRGB_DECODE_EXT
:
591 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
593 /* convert float param to int */
595 p
[0] = (GLint
) param
;
596 p
[1] = p
[2] = p
[3] = 0;
597 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
602 /* this will generate an error if pname is illegal */
605 p
[1] = p
[2] = p
[3] = 0.0F
;
606 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
610 if (ctx
->Driver
.TexParameter
&& need_update
) {
611 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
617 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
619 GLboolean need_update
;
620 struct gl_texture_object
*texObj
;
621 GET_CURRENT_CONTEXT(ctx
);
622 ASSERT_OUTSIDE_BEGIN_END(ctx
);
624 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
629 case GL_TEXTURE_MIN_FILTER
:
630 case GL_TEXTURE_MAG_FILTER
:
631 case GL_TEXTURE_WRAP_S
:
632 case GL_TEXTURE_WRAP_T
:
633 case GL_TEXTURE_WRAP_R
:
634 case GL_TEXTURE_BASE_LEVEL
:
635 case GL_TEXTURE_MAX_LEVEL
:
636 case GL_GENERATE_MIPMAP_SGIS
:
637 case GL_TEXTURE_COMPARE_MODE_ARB
:
638 case GL_TEXTURE_COMPARE_FUNC_ARB
:
639 case GL_DEPTH_TEXTURE_MODE_ARB
:
640 case GL_TEXTURE_SRGB_DECODE_EXT
:
641 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
643 /* convert float param to int */
645 p
[0] = (GLint
) params
[0];
646 p
[1] = p
[2] = p
[3] = 0;
647 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
651 #if FEATURE_OES_draw_texture
652 case GL_TEXTURE_CROP_RECT_OES
:
654 /* convert float params to int */
656 iparams
[0] = (GLint
) params
[0];
657 iparams
[1] = (GLint
) params
[1];
658 iparams
[2] = (GLint
) params
[2];
659 iparams
[3] = (GLint
) params
[3];
660 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
666 /* this will generate an error if pname is illegal */
667 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
670 if (ctx
->Driver
.TexParameter
&& need_update
) {
671 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
677 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
679 GLboolean need_update
;
680 struct gl_texture_object
*texObj
;
681 GET_CURRENT_CONTEXT(ctx
);
682 ASSERT_OUTSIDE_BEGIN_END(ctx
);
684 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
689 case GL_TEXTURE_MIN_LOD
:
690 case GL_TEXTURE_MAX_LOD
:
691 case GL_TEXTURE_PRIORITY
:
692 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
693 case GL_TEXTURE_LOD_BIAS
:
694 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
697 fparam
[0] = (GLfloat
) param
;
698 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
699 /* convert int param to float */
700 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
704 /* this will generate an error if pname is illegal */
708 iparam
[1] = iparam
[2] = iparam
[3] = 0;
709 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
713 if (ctx
->Driver
.TexParameter
&& need_update
) {
714 GLfloat fparam
= (GLfloat
) param
;
715 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
721 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
723 GLboolean need_update
;
724 struct gl_texture_object
*texObj
;
725 GET_CURRENT_CONTEXT(ctx
);
726 ASSERT_OUTSIDE_BEGIN_END(ctx
);
728 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
733 case GL_TEXTURE_BORDER_COLOR
:
735 /* convert int params to float */
737 fparams
[0] = INT_TO_FLOAT(params
[0]);
738 fparams
[1] = INT_TO_FLOAT(params
[1]);
739 fparams
[2] = INT_TO_FLOAT(params
[2]);
740 fparams
[3] = INT_TO_FLOAT(params
[3]);
741 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
744 case GL_TEXTURE_MIN_LOD
:
745 case GL_TEXTURE_MAX_LOD
:
746 case GL_TEXTURE_PRIORITY
:
747 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
748 case GL_TEXTURE_LOD_BIAS
:
749 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
751 /* convert int param to float */
753 fparams
[0] = (GLfloat
) params
[0];
754 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
755 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
759 /* this will generate an error if pname is illegal */
760 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
763 if (ctx
->Driver
.TexParameter
&& need_update
) {
765 fparams
[0] = INT_TO_FLOAT(params
[0]);
766 if (pname
== GL_TEXTURE_BORDER_COLOR
||
767 pname
== GL_TEXTURE_CROP_RECT_OES
) {
768 fparams
[1] = INT_TO_FLOAT(params
[1]);
769 fparams
[2] = INT_TO_FLOAT(params
[2]);
770 fparams
[3] = INT_TO_FLOAT(params
[3]);
772 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
778 * Set tex parameter to integer value(s). Primarily intended to set
779 * integer-valued texture border color (for integer-valued textures).
783 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
785 struct gl_texture_object
*texObj
;
786 GET_CURRENT_CONTEXT(ctx
);
787 ASSERT_OUTSIDE_BEGIN_END(ctx
);
789 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
794 case GL_TEXTURE_BORDER_COLOR
:
795 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
796 /* set the integer-valued border color */
797 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
800 _mesa_TexParameteriv(target
, pname
, params
);
803 /* XXX no driver hook for TexParameterIiv() yet */
808 * Set tex parameter to unsigned integer value(s). Primarily intended to set
809 * uint-valued texture border color (for integer-valued textures).
813 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
815 struct gl_texture_object
*texObj
;
816 GET_CURRENT_CONTEXT(ctx
);
817 ASSERT_OUTSIDE_BEGIN_END(ctx
);
819 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
824 case GL_TEXTURE_BORDER_COLOR
:
825 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
826 /* set the unsigned integer-valued border color */
827 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
830 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
833 /* XXX no driver hook for TexParameterIuiv() yet */
840 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
841 GLenum pname
, GLfloat
*params
)
844 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
845 *params
= (GLfloat
) iparam
;
850 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
851 GLenum pname
, GLint
*params
)
853 const struct gl_texture_unit
*texUnit
;
854 struct gl_texture_object
*texObj
;
855 const struct gl_texture_image
*img
= NULL
;
858 GET_CURRENT_CONTEXT(ctx
);
859 ASSERT_OUTSIDE_BEGIN_END(ctx
);
861 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
862 _mesa_error(ctx
, GL_INVALID_OPERATION
,
863 "glGetTexLevelParameteriv(current unit)");
867 texUnit
= _mesa_get_current_tex_unit(ctx
);
869 /* this will catch bad target values */
870 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
871 if (maxLevels
== 0) {
872 _mesa_error(ctx
, GL_INVALID_ENUM
,
873 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
877 if (level
< 0 || level
>= maxLevels
) {
878 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
882 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
884 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
885 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
886 /* undefined texture image */
887 if (pname
== GL_TEXTURE_COMPONENTS
)
894 texFormat
= img
->TexFormat
;
897 case GL_TEXTURE_WIDTH
:
898 *params
= img
->Width
;
900 case GL_TEXTURE_HEIGHT
:
901 *params
= img
->Height
;
903 case GL_TEXTURE_DEPTH
:
904 *params
= img
->Depth
;
906 case GL_TEXTURE_INTERNAL_FORMAT
:
907 if (_mesa_is_format_compressed(texFormat
)) {
908 /* need to return the actual compressed format */
909 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
912 /* If the true internal format is not compressed but the user
913 * requested a generic compressed format, we have to return the
914 * generic base format that matches.
916 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
918 * "If no specific compressed format is available,
919 * internalformat is instead replaced by the corresponding base
922 * Otherwise just return the user's requested internal format
925 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
927 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
930 case GL_TEXTURE_BORDER
:
931 *params
= img
->Border
;
933 case GL_TEXTURE_RED_SIZE
:
934 if (img
->_BaseFormat
== GL_RED
) {
935 *params
= _mesa_get_format_bits(texFormat
, pname
);
939 case GL_TEXTURE_GREEN_SIZE
:
940 if (img
->_BaseFormat
== GL_RG
) {
941 *params
= _mesa_get_format_bits(texFormat
, pname
);
945 case GL_TEXTURE_BLUE_SIZE
:
946 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
947 *params
= _mesa_get_format_bits(texFormat
, pname
);
951 case GL_TEXTURE_ALPHA_SIZE
:
952 if (img
->_BaseFormat
== GL_ALPHA
||
953 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
954 img
->_BaseFormat
== GL_RGBA
)
955 *params
= _mesa_get_format_bits(texFormat
, pname
);
959 case GL_TEXTURE_INTENSITY_SIZE
:
960 if (img
->_BaseFormat
!= GL_INTENSITY
)
963 *params
= _mesa_get_format_bits(texFormat
, pname
);
965 /* intensity probably stored as rgb texture */
966 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
967 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
971 case GL_TEXTURE_LUMINANCE_SIZE
:
972 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
973 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
976 *params
= _mesa_get_format_bits(texFormat
, pname
);
978 /* luminance probably stored as rgb texture */
979 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
980 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
984 case GL_TEXTURE_DEPTH_SIZE_ARB
:
985 if (!ctx
->Extensions
.ARB_depth_texture
)
987 *params
= _mesa_get_format_bits(texFormat
, pname
);
989 case GL_TEXTURE_STENCIL_SIZE_EXT
:
990 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
991 !ctx
->Extensions
.ARB_framebuffer_object
)
993 *params
= _mesa_get_format_bits(texFormat
, pname
);
995 case GL_TEXTURE_SHARED_SIZE
:
996 if (ctx
->VersionMajor
< 3 &&
997 !ctx
->Extensions
.EXT_texture_shared_exponent
)
999 *params
= texFormat
== MESA_FORMAT_RGB9_E5_FLOAT
? 5 : 0;
1002 /* GL_ARB_texture_compression */
1003 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1004 if (_mesa_is_format_compressed(texFormat
) &&
1005 !_mesa_is_proxy_texture(target
)) {
1006 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
1007 img
->Height
, img
->Depth
);
1010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1011 "glGetTexLevelParameter[if]v(pname)");
1014 case GL_TEXTURE_COMPRESSED
:
1015 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1018 /* GL_ARB_texture_float */
1019 case GL_TEXTURE_RED_TYPE_ARB
:
1020 if (!ctx
->Extensions
.ARB_texture_float
)
1022 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
1023 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1025 case GL_TEXTURE_GREEN_TYPE_ARB
:
1026 if (!ctx
->Extensions
.ARB_texture_float
)
1028 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1029 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1031 case GL_TEXTURE_BLUE_TYPE_ARB
:
1032 if (!ctx
->Extensions
.ARB_texture_float
)
1034 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1035 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1037 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1038 if (!ctx
->Extensions
.ARB_texture_float
)
1040 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_ALPHA_SIZE
) ?
1041 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1043 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1044 if (!ctx
->Extensions
.ARB_texture_float
)
1046 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1047 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1049 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1050 if (!ctx
->Extensions
.ARB_texture_float
)
1052 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1053 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1055 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1056 if (!ctx
->Extensions
.ARB_texture_float
)
1058 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1059 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1066 /* no error if we get here */
1070 _mesa_error(ctx
, GL_INVALID_ENUM
,
1071 "glGetTexLevelParameter[if]v(pname=%s)",
1072 _mesa_lookup_enum_by_nr(pname
));
1078 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1080 struct gl_texture_object
*obj
;
1081 GET_CURRENT_CONTEXT(ctx
);
1082 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1084 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1088 _mesa_lock_texture(ctx
, obj
);
1090 case GL_TEXTURE_MAG_FILTER
:
1091 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1093 case GL_TEXTURE_MIN_FILTER
:
1094 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1096 case GL_TEXTURE_WRAP_S
:
1097 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1099 case GL_TEXTURE_WRAP_T
:
1100 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1102 case GL_TEXTURE_WRAP_R
:
1103 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1105 case GL_TEXTURE_BORDER_COLOR
:
1106 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1107 _mesa_update_state_locked(ctx
);
1108 if (ctx
->Color
._ClampFragmentColor
) {
1109 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1110 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1111 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1112 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1115 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1116 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1117 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1118 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1121 case GL_TEXTURE_RESIDENT
:
1122 *params
= ctx
->Driver
.IsTextureResident
?
1123 ctx
->Driver
.IsTextureResident(ctx
, obj
) : 1.0F
;
1125 case GL_TEXTURE_PRIORITY
:
1126 *params
= obj
->Priority
;
1128 case GL_TEXTURE_MIN_LOD
:
1129 *params
= obj
->Sampler
.MinLod
;
1131 case GL_TEXTURE_MAX_LOD
:
1132 *params
= obj
->Sampler
.MaxLod
;
1134 case GL_TEXTURE_BASE_LEVEL
:
1135 *params
= (GLfloat
) obj
->BaseLevel
;
1137 case GL_TEXTURE_MAX_LEVEL
:
1138 *params
= (GLfloat
) obj
->MaxLevel
;
1140 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1141 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1143 *params
= obj
->Sampler
.MaxAnisotropy
;
1145 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1146 if (!ctx
->Extensions
.ARB_shadow_ambient
)
1148 *params
= obj
->Sampler
.CompareFailValue
;
1150 case GL_GENERATE_MIPMAP_SGIS
:
1151 *params
= (GLfloat
) obj
->GenerateMipmap
;
1153 case GL_TEXTURE_COMPARE_MODE_ARB
:
1154 if (!ctx
->Extensions
.ARB_shadow
)
1156 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1158 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1159 if (!ctx
->Extensions
.ARB_shadow
)
1161 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1163 case GL_DEPTH_TEXTURE_MODE_ARB
:
1164 if (!ctx
->Extensions
.ARB_depth_texture
)
1166 *params
= (GLfloat
) obj
->Sampler
.DepthMode
;
1168 case GL_TEXTURE_LOD_BIAS
:
1169 *params
= obj
->Sampler
.LodBias
;
1171 #if FEATURE_OES_draw_texture
1172 case GL_TEXTURE_CROP_RECT_OES
:
1173 params
[0] = obj
->CropRect
[0];
1174 params
[1] = obj
->CropRect
[1];
1175 params
[2] = obj
->CropRect
[2];
1176 params
[3] = obj
->CropRect
[3];
1180 case GL_TEXTURE_SWIZZLE_R_EXT
:
1181 case GL_TEXTURE_SWIZZLE_G_EXT
:
1182 case GL_TEXTURE_SWIZZLE_B_EXT
:
1183 case GL_TEXTURE_SWIZZLE_A_EXT
:
1184 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1186 *params
= (GLfloat
) obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1189 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1190 if (!ctx
->Extensions
.EXT_texture_swizzle
) {
1195 for (comp
= 0; comp
< 4; comp
++) {
1196 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1201 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1202 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1204 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1211 /* no error if we get here */
1212 _mesa_unlock_texture(ctx
, obj
);
1216 _mesa_unlock_texture(ctx
, obj
);
1217 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1222 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1224 struct gl_texture_object
*obj
;
1225 GET_CURRENT_CONTEXT(ctx
);
1226 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1228 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1232 _mesa_lock_texture(ctx
, obj
);
1234 case GL_TEXTURE_MAG_FILTER
:
1235 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1237 case GL_TEXTURE_MIN_FILTER
:
1238 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1240 case GL_TEXTURE_WRAP_S
:
1241 *params
= (GLint
) obj
->Sampler
.WrapS
;
1243 case GL_TEXTURE_WRAP_T
:
1244 *params
= (GLint
) obj
->Sampler
.WrapT
;
1246 case GL_TEXTURE_WRAP_R
:
1247 *params
= (GLint
) obj
->Sampler
.WrapR
;
1249 case GL_TEXTURE_BORDER_COLOR
:
1252 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1253 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1254 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1255 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1256 params
[0] = FLOAT_TO_INT(b
[0]);
1257 params
[1] = FLOAT_TO_INT(b
[1]);
1258 params
[2] = FLOAT_TO_INT(b
[2]);
1259 params
[3] = FLOAT_TO_INT(b
[3]);
1262 case GL_TEXTURE_RESIDENT
:
1263 *params
= ctx
->Driver
.IsTextureResident
?
1264 ctx
->Driver
.IsTextureResident(ctx
, obj
) : 1;
1266 case GL_TEXTURE_PRIORITY
:
1267 *params
= FLOAT_TO_INT(obj
->Priority
);
1269 case GL_TEXTURE_MIN_LOD
:
1270 *params
= (GLint
) obj
->Sampler
.MinLod
;
1272 case GL_TEXTURE_MAX_LOD
:
1273 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1275 case GL_TEXTURE_BASE_LEVEL
:
1276 *params
= obj
->BaseLevel
;
1278 case GL_TEXTURE_MAX_LEVEL
:
1279 *params
= obj
->MaxLevel
;
1281 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1282 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1284 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1286 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1287 if (!ctx
->Extensions
.ARB_shadow_ambient
)
1289 *params
= (GLint
) FLOAT_TO_INT(obj
->Sampler
.CompareFailValue
);
1291 case GL_GENERATE_MIPMAP_SGIS
:
1292 *params
= (GLint
) obj
->GenerateMipmap
;
1294 case GL_TEXTURE_COMPARE_MODE_ARB
:
1295 if (!ctx
->Extensions
.ARB_shadow
)
1297 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1299 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1300 if (!ctx
->Extensions
.ARB_shadow
)
1302 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1304 case GL_DEPTH_TEXTURE_MODE_ARB
:
1305 if (!ctx
->Extensions
.ARB_depth_texture
)
1307 *params
= (GLint
) obj
->Sampler
.DepthMode
;
1309 case GL_TEXTURE_LOD_BIAS
:
1310 *params
= (GLint
) obj
->Sampler
.LodBias
;
1312 #if FEATURE_OES_draw_texture
1313 case GL_TEXTURE_CROP_RECT_OES
:
1314 params
[0] = obj
->CropRect
[0];
1315 params
[1] = obj
->CropRect
[1];
1316 params
[2] = obj
->CropRect
[2];
1317 params
[3] = obj
->CropRect
[3];
1320 case GL_TEXTURE_SWIZZLE_R_EXT
:
1321 case GL_TEXTURE_SWIZZLE_G_EXT
:
1322 case GL_TEXTURE_SWIZZLE_B_EXT
:
1323 case GL_TEXTURE_SWIZZLE_A_EXT
:
1324 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1326 *params
= obj
->Swizzle
[pname
- GL_TEXTURE_SWIZZLE_R_EXT
];
1329 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1330 if (!ctx
->Extensions
.EXT_texture_swizzle
)
1332 COPY_4V(params
, obj
->Swizzle
);
1335 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1336 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1338 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1345 /* no error if we get here */
1346 _mesa_unlock_texture(ctx
, obj
);
1350 _mesa_unlock_texture(ctx
, obj
);
1351 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1355 /** New in GL 3.0 */
1357 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1359 struct gl_texture_object
*texObj
;
1360 GET_CURRENT_CONTEXT(ctx
);
1361 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1363 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1368 case GL_TEXTURE_BORDER_COLOR
:
1369 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1372 _mesa_GetTexParameteriv(target
, pname
, params
);
1377 /** New in GL 3.0 */
1379 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1381 struct gl_texture_object
*texObj
;
1382 GET_CURRENT_CONTEXT(ctx
);
1383 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1385 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1390 case GL_TEXTURE_BORDER_COLOR
:
1391 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1396 _mesa_GetTexParameteriv(target
, pname
, ip
);
1398 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1399 pname
== GL_TEXTURE_CROP_RECT_OES
) {