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 "main/texfetch.h"
47 #include "program/prog_instruction.h"
51 * Check if a coordinate wrap mode is supported for the texture target.
52 * \return GL_TRUE if legal, GL_FALSE otherwise
55 validate_texture_wrap_mode(struct gl_context
* ctx
, GLenum target
, GLenum wrap
)
57 const struct gl_extensions
* const e
= & ctx
->Extensions
;
59 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
60 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
61 /* any texture target */
64 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
66 (wrap
== GL_MIRRORED_REPEAT
&&
67 e
->ARB_texture_mirrored_repeat
) ||
68 (wrap
== GL_MIRROR_CLAMP_EXT
&&
69 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
70 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
71 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
72 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
73 (e
->EXT_texture_mirror_clamp
)))) {
74 /* non-rectangle texture */
78 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
84 * Get current texture object for given target.
85 * Return NULL if any error (and record the error).
86 * Note that this is different from _mesa_select_tex_object() in that proxy
87 * targets are not accepted.
88 * Only the glGetTexLevelParameter() functions accept proxy targets.
90 static struct gl_texture_object
*
91 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
93 struct gl_texture_unit
*texUnit
;
95 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
96 _mesa_error(ctx
, GL_INVALID_OPERATION
,
97 "gl%sTexParameter(current unit)", get
? "Get" : "");
101 texUnit
= _mesa_get_current_tex_unit(ctx
);
105 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
107 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
109 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
110 case GL_TEXTURE_CUBE_MAP
:
111 if (ctx
->Extensions
.ARB_texture_cube_map
) {
112 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
115 case GL_TEXTURE_RECTANGLE_NV
:
116 if (ctx
->Extensions
.NV_texture_rectangle
) {
117 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
120 case GL_TEXTURE_1D_ARRAY_EXT
:
121 if (ctx
->Extensions
.MESA_texture_array
||
122 ctx
->Extensions
.EXT_texture_array
) {
123 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
126 case GL_TEXTURE_2D_ARRAY_EXT
:
127 if (ctx
->Extensions
.MESA_texture_array
||
128 ctx
->Extensions
.EXT_texture_array
) {
129 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
136 _mesa_error(ctx
, GL_INVALID_ENUM
,
137 "gl%sTexParameter(target)", get
? "Get" : "");
143 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
144 * \return -1 if error.
147 comp_to_swizzle(GLenum comp
)
169 set_swizzle_component(GLuint
*swizzle
, GLuint comp
, GLuint swz
)
172 ASSERT(swz
<= SWIZZLE_NIL
);
174 GLuint mask
= 0x7 << (3 * comp
);
175 GLuint s
= (*swizzle
& ~mask
) | (swz
<< (3 * comp
));
182 * This is called just prior to changing any texture object state which
183 * will not effect texture completeness.
186 flush(struct gl_context
*ctx
)
188 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
193 * This is called just prior to changing any texture object state which
194 * can effect texture completeness (texture base level, max level,
195 * minification filter).
196 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
197 * state flag and then mark the texture object as 'incomplete' so that any
198 * per-texture derived state gets recomputed.
201 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
203 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
204 texObj
->_Complete
= GL_FALSE
;
209 * Set an integer-valued texture parameter
210 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
213 set_tex_parameteri(struct gl_context
*ctx
,
214 struct gl_texture_object
*texObj
,
215 GLenum pname
, const GLint
*params
)
218 case GL_TEXTURE_MIN_FILTER
:
219 if (texObj
->Sampler
.MinFilter
== params
[0])
224 incomplete(ctx
, texObj
);
225 texObj
->Sampler
.MinFilter
= params
[0];
227 case GL_NEAREST_MIPMAP_NEAREST
:
228 case GL_LINEAR_MIPMAP_NEAREST
:
229 case GL_NEAREST_MIPMAP_LINEAR
:
230 case GL_LINEAR_MIPMAP_LINEAR
:
231 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
232 incomplete(ctx
, texObj
);
233 texObj
->Sampler
.MinFilter
= params
[0];
242 case GL_TEXTURE_MAG_FILTER
:
243 if (texObj
->Sampler
.MagFilter
== params
[0])
248 flush(ctx
); /* does not effect completeness */
249 texObj
->Sampler
.MagFilter
= params
[0];
256 case GL_TEXTURE_WRAP_S
:
257 if (texObj
->Sampler
.WrapS
== params
[0])
259 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
261 texObj
->Sampler
.WrapS
= params
[0];
266 case GL_TEXTURE_WRAP_T
:
267 if (texObj
->Sampler
.WrapT
== params
[0])
269 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
271 texObj
->Sampler
.WrapT
= params
[0];
276 case GL_TEXTURE_WRAP_R
:
277 if (texObj
->Sampler
.WrapR
== params
[0])
279 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
281 texObj
->Sampler
.WrapR
= params
[0];
286 case GL_TEXTURE_BASE_LEVEL
:
287 if (texObj
->BaseLevel
== params
[0])
290 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
291 _mesa_error(ctx
, GL_INVALID_VALUE
,
292 "glTexParameter(param=%d)", params
[0]);
295 incomplete(ctx
, texObj
);
296 texObj
->BaseLevel
= params
[0];
299 case GL_TEXTURE_MAX_LEVEL
:
300 if (texObj
->MaxLevel
== params
[0])
302 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
303 _mesa_error(ctx
, GL_INVALID_OPERATION
,
304 "glTexParameter(param=%d)", params
[0]);
307 incomplete(ctx
, texObj
);
308 texObj
->MaxLevel
= params
[0];
311 case GL_GENERATE_MIPMAP_SGIS
:
312 if (texObj
->GenerateMipmap
!= params
[0]) {
314 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
319 case GL_TEXTURE_COMPARE_MODE_ARB
:
320 if (ctx
->Extensions
.ARB_shadow
) {
321 if (texObj
->Sampler
.CompareMode
== params
[0])
323 if (params
[0] == GL_NONE
||
324 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
326 texObj
->Sampler
.CompareMode
= params
[0];
333 case GL_TEXTURE_COMPARE_FUNC_ARB
:
334 if (ctx
->Extensions
.ARB_shadow
) {
335 if (texObj
->Sampler
.CompareFunc
== params
[0])
341 texObj
->Sampler
.CompareFunc
= params
[0];
349 if (ctx
->Extensions
.EXT_shadow_funcs
) {
351 texObj
->Sampler
.CompareFunc
= params
[0];
361 case GL_DEPTH_TEXTURE_MODE_ARB
:
362 if (ctx
->Extensions
.ARB_depth_texture
) {
363 if (texObj
->Sampler
.DepthMode
== params
[0])
365 if (params
[0] == GL_LUMINANCE
||
366 params
[0] == GL_INTENSITY
||
367 params
[0] == GL_ALPHA
||
368 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
370 texObj
->Sampler
.DepthMode
= params
[0];
377 #if FEATURE_OES_draw_texture
378 case GL_TEXTURE_CROP_RECT_OES
:
379 texObj
->CropRect
[0] = params
[0];
380 texObj
->CropRect
[1] = params
[1];
381 texObj
->CropRect
[2] = params
[2];
382 texObj
->CropRect
[3] = params
[3];
386 case GL_TEXTURE_SWIZZLE_R_EXT
:
387 case GL_TEXTURE_SWIZZLE_G_EXT
:
388 case GL_TEXTURE_SWIZZLE_B_EXT
:
389 case GL_TEXTURE_SWIZZLE_A_EXT
:
390 if (ctx
->Extensions
.EXT_texture_swizzle
) {
391 const GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
392 const GLint swz
= comp_to_swizzle(params
[0]);
394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
395 "glTexParameter(swizzle 0x%x)", params
[0]);
401 texObj
->Swizzle
[comp
] = params
[0];
402 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
408 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
409 if (ctx
->Extensions
.EXT_texture_swizzle
) {
412 for (comp
= 0; comp
< 4; comp
++) {
413 const GLint swz
= comp_to_swizzle(params
[comp
]);
415 texObj
->Swizzle
[comp
] = params
[comp
];
416 set_swizzle_component(&texObj
->_Swizzle
, comp
, swz
);
419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
420 "glTexParameter(swizzle 0x%x)", params
[comp
]);
428 case GL_TEXTURE_SRGB_DECODE_EXT
:
429 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
430 GLenum decode
= params
[0];
431 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
432 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
434 texObj
->Sampler
.sRGBDecode
= decode
;
435 _mesa_update_fetch_functions(texObj
);
447 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
448 _mesa_lookup_enum_by_nr(pname
));
452 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
453 _mesa_lookup_enum_by_nr(params
[0]));
459 * Set a float-valued texture parameter
460 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
463 set_tex_parameterf(struct gl_context
*ctx
,
464 struct gl_texture_object
*texObj
,
465 GLenum pname
, const GLfloat
*params
)
468 case GL_TEXTURE_MIN_LOD
:
469 if (texObj
->Sampler
.MinLod
== params
[0])
472 texObj
->Sampler
.MinLod
= params
[0];
475 case GL_TEXTURE_MAX_LOD
:
476 if (texObj
->Sampler
.MaxLod
== params
[0])
479 texObj
->Sampler
.MaxLod
= params
[0];
482 case GL_TEXTURE_PRIORITY
:
484 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
487 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
488 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
489 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
491 if (params
[0] < 1.0) {
492 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
496 /* clamp to max, that's what NVIDIA does */
497 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
498 ctx
->Const
.MaxTextureMaxAnisotropy
);
502 static GLuint count
= 0;
504 _mesa_error(ctx
, GL_INVALID_ENUM
,
505 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
509 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
510 if (ctx
->Extensions
.ARB_shadow_ambient
) {
511 if (texObj
->Sampler
.CompareFailValue
!= params
[0]) {
513 texObj
->Sampler
.CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
518 _mesa_error(ctx
, GL_INVALID_ENUM
,
519 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
523 case GL_TEXTURE_LOD_BIAS
:
524 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
525 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
526 if (texObj
->Sampler
.LodBias
!= params
[0]) {
528 texObj
->Sampler
.LodBias
= params
[0];
535 case GL_TEXTURE_BORDER_COLOR
:
537 /* ARB_texture_float disables clamping */
538 if (ctx
->Extensions
.ARB_texture_float
) {
539 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
540 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
541 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
542 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
544 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
545 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
546 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
547 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
552 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
559 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
561 GLboolean need_update
;
562 struct gl_texture_object
*texObj
;
563 GET_CURRENT_CONTEXT(ctx
);
564 ASSERT_OUTSIDE_BEGIN_END(ctx
);
566 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
571 case GL_TEXTURE_MIN_FILTER
:
572 case GL_TEXTURE_MAG_FILTER
:
573 case GL_TEXTURE_WRAP_S
:
574 case GL_TEXTURE_WRAP_T
:
575 case GL_TEXTURE_WRAP_R
:
576 case GL_TEXTURE_BASE_LEVEL
:
577 case GL_TEXTURE_MAX_LEVEL
:
578 case GL_GENERATE_MIPMAP_SGIS
:
579 case GL_TEXTURE_COMPARE_MODE_ARB
:
580 case GL_TEXTURE_COMPARE_FUNC_ARB
:
581 case GL_DEPTH_TEXTURE_MODE_ARB
:
582 case GL_TEXTURE_SRGB_DECODE_EXT
:
584 /* convert float param to int */
586 p
[0] = (GLint
) param
;
587 p
[1] = p
[2] = p
[3] = 0;
588 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
593 /* this will generate an error if pname is illegal */
596 p
[1] = p
[2] = p
[3] = 0.0F
;
597 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
601 if (ctx
->Driver
.TexParameter
&& need_update
) {
602 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
608 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
610 GLboolean need_update
;
611 struct gl_texture_object
*texObj
;
612 GET_CURRENT_CONTEXT(ctx
);
613 ASSERT_OUTSIDE_BEGIN_END(ctx
);
615 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
620 case GL_TEXTURE_MIN_FILTER
:
621 case GL_TEXTURE_MAG_FILTER
:
622 case GL_TEXTURE_WRAP_S
:
623 case GL_TEXTURE_WRAP_T
:
624 case GL_TEXTURE_WRAP_R
:
625 case GL_TEXTURE_BASE_LEVEL
:
626 case GL_TEXTURE_MAX_LEVEL
:
627 case GL_GENERATE_MIPMAP_SGIS
:
628 case GL_TEXTURE_COMPARE_MODE_ARB
:
629 case GL_TEXTURE_COMPARE_FUNC_ARB
:
630 case GL_DEPTH_TEXTURE_MODE_ARB
:
631 case GL_TEXTURE_SRGB_DECODE_EXT
:
633 /* convert float param to int */
635 p
[0] = (GLint
) params
[0];
636 p
[1] = p
[2] = p
[3] = 0;
637 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
641 #if FEATURE_OES_draw_texture
642 case GL_TEXTURE_CROP_RECT_OES
:
644 /* convert float params to int */
646 iparams
[0] = (GLint
) params
[0];
647 iparams
[1] = (GLint
) params
[1];
648 iparams
[2] = (GLint
) params
[2];
649 iparams
[3] = (GLint
) params
[3];
650 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
656 /* this will generate an error if pname is illegal */
657 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
660 if (ctx
->Driver
.TexParameter
&& need_update
) {
661 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
667 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
669 GLboolean need_update
;
670 struct gl_texture_object
*texObj
;
671 GET_CURRENT_CONTEXT(ctx
);
672 ASSERT_OUTSIDE_BEGIN_END(ctx
);
674 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
679 case GL_TEXTURE_MIN_LOD
:
680 case GL_TEXTURE_MAX_LOD
:
681 case GL_TEXTURE_PRIORITY
:
682 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
683 case GL_TEXTURE_LOD_BIAS
:
684 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
687 fparam
[0] = (GLfloat
) param
;
688 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
689 /* convert int param to float */
690 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
694 /* this will generate an error if pname is illegal */
698 iparam
[1] = iparam
[2] = iparam
[3] = 0;
699 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
703 if (ctx
->Driver
.TexParameter
&& need_update
) {
704 GLfloat fparam
= (GLfloat
) param
;
705 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
711 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
713 GLboolean need_update
;
714 struct gl_texture_object
*texObj
;
715 GET_CURRENT_CONTEXT(ctx
);
716 ASSERT_OUTSIDE_BEGIN_END(ctx
);
718 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
723 case GL_TEXTURE_BORDER_COLOR
:
725 /* convert int params to float */
727 fparams
[0] = INT_TO_FLOAT(params
[0]);
728 fparams
[1] = INT_TO_FLOAT(params
[1]);
729 fparams
[2] = INT_TO_FLOAT(params
[2]);
730 fparams
[3] = INT_TO_FLOAT(params
[3]);
731 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
734 case GL_TEXTURE_MIN_LOD
:
735 case GL_TEXTURE_MAX_LOD
:
736 case GL_TEXTURE_PRIORITY
:
737 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
738 case GL_TEXTURE_LOD_BIAS
:
739 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
741 /* convert int param to float */
743 fparams
[0] = (GLfloat
) params
[0];
744 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
745 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
749 /* this will generate an error if pname is illegal */
750 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
753 if (ctx
->Driver
.TexParameter
&& need_update
) {
755 fparams
[0] = INT_TO_FLOAT(params
[0]);
756 if (pname
== GL_TEXTURE_BORDER_COLOR
||
757 pname
== GL_TEXTURE_CROP_RECT_OES
) {
758 fparams
[1] = INT_TO_FLOAT(params
[1]);
759 fparams
[2] = INT_TO_FLOAT(params
[2]);
760 fparams
[3] = INT_TO_FLOAT(params
[3]);
762 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
768 * Set tex parameter to integer value(s). Primarily intended to set
769 * integer-valued texture border color (for integer-valued textures).
773 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
775 struct gl_texture_object
*texObj
;
776 GET_CURRENT_CONTEXT(ctx
);
777 ASSERT_OUTSIDE_BEGIN_END(ctx
);
779 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
784 case GL_TEXTURE_BORDER_COLOR
:
785 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
786 /* set the integer-valued border color */
787 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
790 _mesa_TexParameteriv(target
, pname
, params
);
793 /* XXX no driver hook for TexParameterIiv() yet */
798 * Set tex parameter to unsigned integer value(s). Primarily intended to set
799 * uint-valued texture border color (for integer-valued textures).
803 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
805 struct gl_texture_object
*texObj
;
806 GET_CURRENT_CONTEXT(ctx
);
807 ASSERT_OUTSIDE_BEGIN_END(ctx
);
809 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
814 case GL_TEXTURE_BORDER_COLOR
:
815 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
816 /* set the unsigned integer-valued border color */
817 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
820 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
823 /* XXX no driver hook for TexParameterIuiv() yet */
830 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
831 GLenum pname
, GLfloat
*params
)
834 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
835 *params
= (GLfloat
) iparam
;
840 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
841 GLenum pname
, GLint
*params
)
843 const struct gl_texture_unit
*texUnit
;
844 struct gl_texture_object
*texObj
;
845 const struct gl_texture_image
*img
= NULL
;
848 GET_CURRENT_CONTEXT(ctx
);
849 ASSERT_OUTSIDE_BEGIN_END(ctx
);
851 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
852 _mesa_error(ctx
, GL_INVALID_OPERATION
,
853 "glGetTexLevelParameteriv(current unit)");
857 texUnit
= _mesa_get_current_tex_unit(ctx
);
859 /* this will catch bad target values */
860 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
861 if (maxLevels
== 0) {
862 _mesa_error(ctx
, GL_INVALID_ENUM
,
863 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
867 if (level
< 0 || level
>= maxLevels
) {
868 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
872 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
874 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
875 if (!img
|| !img
->TexFormat
) {
876 /* undefined texture image */
877 if (pname
== GL_TEXTURE_COMPONENTS
)
884 texFormat
= img
->TexFormat
;
887 case GL_TEXTURE_WIDTH
:
888 *params
= img
->Width
;
890 case GL_TEXTURE_HEIGHT
:
891 *params
= img
->Height
;
893 case GL_TEXTURE_DEPTH
:
894 *params
= img
->Depth
;
896 case GL_TEXTURE_INTERNAL_FORMAT
:
897 if (_mesa_is_format_compressed(texFormat
)) {
898 /* need to return the actual compressed format */
899 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
902 /* return the user's requested internal format */
903 *params
= img
->InternalFormat
;
906 case GL_TEXTURE_BORDER
:
907 *params
= img
->Border
;
909 case GL_TEXTURE_RED_SIZE
:
910 if (img
->_BaseFormat
== GL_RED
) {
911 *params
= _mesa_get_format_bits(texFormat
, pname
);
915 case GL_TEXTURE_GREEN_SIZE
:
916 if (img
->_BaseFormat
== GL_RG
) {
917 *params
= _mesa_get_format_bits(texFormat
, pname
);
921 case GL_TEXTURE_BLUE_SIZE
:
922 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
923 *params
= _mesa_get_format_bits(texFormat
, pname
);
927 case GL_TEXTURE_ALPHA_SIZE
:
928 if (img
->_BaseFormat
== GL_ALPHA
||
929 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
930 img
->_BaseFormat
== GL_RGBA
)
931 *params
= _mesa_get_format_bits(texFormat
, pname
);
935 case GL_TEXTURE_INTENSITY_SIZE
:
936 if (img
->_BaseFormat
!= GL_INTENSITY
)
939 *params
= _mesa_get_format_bits(texFormat
, pname
);
941 /* intensity probably stored as rgb texture */
942 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
943 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
947 case GL_TEXTURE_LUMINANCE_SIZE
:
948 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
949 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
952 *params
= _mesa_get_format_bits(texFormat
, pname
);
954 /* luminance probably stored as rgb texture */
955 *params
= MIN2(_mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
),
956 _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
));
960 case GL_TEXTURE_INDEX_SIZE_EXT
:
961 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
962 *params
= _mesa_get_format_bits(texFormat
, pname
);
966 case GL_TEXTURE_DEPTH_SIZE_ARB
:
967 if (ctx
->Extensions
.ARB_depth_texture
)
968 *params
= _mesa_get_format_bits(texFormat
, pname
);
972 case GL_TEXTURE_STENCIL_SIZE_EXT
:
973 if (ctx
->Extensions
.EXT_packed_depth_stencil
||
974 ctx
->Extensions
.ARB_framebuffer_object
) {
975 *params
= _mesa_get_format_bits(texFormat
, pname
);
981 case GL_TEXTURE_SHARED_SIZE
:
982 if (ctx
->VersionMajor
>= 3) {
983 /* XXX return number of exponent bits for shared exponent texture
984 * formats, like GL_RGB9_E5.
993 /* GL_ARB_texture_compression */
994 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
995 if (_mesa_is_format_compressed(texFormat
) &&
996 !_mesa_is_proxy_texture(target
)) {
997 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
998 img
->Height
, img
->Depth
);
1001 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1002 "glGetTexLevelParameter[if]v(pname)");
1005 case GL_TEXTURE_COMPRESSED
:
1006 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
1009 /* GL_ARB_texture_float */
1010 case GL_TEXTURE_RED_TYPE_ARB
:
1011 if (ctx
->Extensions
.ARB_texture_float
) {
1012 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_RED_SIZE
) ?
1013 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1019 case GL_TEXTURE_GREEN_TYPE_ARB
:
1020 if (ctx
->Extensions
.ARB_texture_float
) {
1021 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_GREEN_SIZE
) ?
1022 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1028 case GL_TEXTURE_BLUE_TYPE_ARB
:
1029 if (ctx
->Extensions
.ARB_texture_float
) {
1030 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_BLUE_SIZE
) ?
1031 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
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
;
1046 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1047 if (ctx
->Extensions
.ARB_texture_float
) {
1048 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_LUMINANCE_SIZE
) ?
1049 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1055 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1056 if (ctx
->Extensions
.ARB_texture_float
) {
1057 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_INTENSITY_SIZE
) ?
1058 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1064 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1065 if (ctx
->Extensions
.ARB_texture_float
) {
1066 *params
= _mesa_get_format_bits(texFormat
, GL_TEXTURE_DEPTH_SIZE
) ?
1067 _mesa_get_format_datatype(texFormat
) : GL_NONE
;
1078 /* no error if we get here */
1082 _mesa_error(ctx
, GL_INVALID_ENUM
,
1083 "glGetTexLevelParameter[if]v(pname=%s)",
1084 _mesa_lookup_enum_by_nr(pname
));
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
->Sampler
.MagFilter
);
1106 case GL_TEXTURE_MIN_FILTER
:
1107 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1109 case GL_TEXTURE_WRAP_S
:
1110 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1112 case GL_TEXTURE_WRAP_T
:
1113 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1115 case GL_TEXTURE_WRAP_R
:
1116 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1118 case GL_TEXTURE_BORDER_COLOR
:
1119 if(ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1120 _mesa_update_state_locked(ctx
);
1121 if(ctx
->Color
._ClampFragmentColor
)
1123 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1124 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1125 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1126 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1130 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1131 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1132 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1133 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1136 case GL_TEXTURE_RESIDENT
:
1139 if (ctx
->Driver
.IsTextureResident
)
1140 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1143 *params
= ENUM_TO_FLOAT(resident
);
1146 case GL_TEXTURE_PRIORITY
:
1147 *params
= obj
->Priority
;
1149 case GL_TEXTURE_MIN_LOD
:
1150 *params
= obj
->Sampler
.MinLod
;
1152 case GL_TEXTURE_MAX_LOD
:
1153 *params
= obj
->Sampler
.MaxLod
;
1155 case GL_TEXTURE_BASE_LEVEL
:
1156 *params
= (GLfloat
) obj
->BaseLevel
;
1158 case GL_TEXTURE_MAX_LEVEL
:
1159 *params
= (GLfloat
) obj
->MaxLevel
;
1161 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1162 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1163 *params
= obj
->Sampler
.MaxAnisotropy
;
1168 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1169 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1170 *params
= obj
->Sampler
.CompareFailValue
;
1175 case GL_GENERATE_MIPMAP_SGIS
:
1176 *params
= (GLfloat
) obj
->GenerateMipmap
;
1178 case GL_TEXTURE_COMPARE_MODE_ARB
:
1179 if (ctx
->Extensions
.ARB_shadow
) {
1180 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1185 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1186 if (ctx
->Extensions
.ARB_shadow
) {
1187 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1192 case GL_DEPTH_TEXTURE_MODE_ARB
:
1193 if (ctx
->Extensions
.ARB_depth_texture
) {
1194 *params
= (GLfloat
) obj
->Sampler
.DepthMode
;
1199 case GL_TEXTURE_LOD_BIAS
:
1200 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1201 *params
= obj
->Sampler
.LodBias
;
1206 #if FEATURE_OES_draw_texture
1207 case GL_TEXTURE_CROP_RECT_OES
:
1208 params
[0] = obj
->CropRect
[0];
1209 params
[1] = obj
->CropRect
[1];
1210 params
[2] = obj
->CropRect
[2];
1211 params
[3] = obj
->CropRect
[3];
1215 case GL_TEXTURE_SWIZZLE_R_EXT
:
1216 case GL_TEXTURE_SWIZZLE_G_EXT
:
1217 case GL_TEXTURE_SWIZZLE_B_EXT
:
1218 case GL_TEXTURE_SWIZZLE_A_EXT
:
1219 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1220 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1221 *params
= (GLfloat
) obj
->Swizzle
[comp
];
1228 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1229 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1231 for (comp
= 0; comp
< 4; comp
++) {
1232 params
[comp
] = (GLfloat
) obj
->Swizzle
[comp
];
1246 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1249 _mesa_unlock_texture(ctx
, obj
);
1254 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1256 struct gl_texture_object
*obj
;
1257 GLboolean error
= GL_FALSE
;
1258 GET_CURRENT_CONTEXT(ctx
);
1259 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1261 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1265 _mesa_lock_texture(ctx
, obj
);
1267 case GL_TEXTURE_MAG_FILTER
:
1268 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1270 case GL_TEXTURE_MIN_FILTER
:
1271 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1273 case GL_TEXTURE_WRAP_S
:
1274 *params
= (GLint
) obj
->Sampler
.WrapS
;
1276 case GL_TEXTURE_WRAP_T
:
1277 *params
= (GLint
) obj
->Sampler
.WrapT
;
1279 case GL_TEXTURE_WRAP_R
:
1280 *params
= (GLint
) obj
->Sampler
.WrapR
;
1282 case GL_TEXTURE_BORDER_COLOR
:
1285 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1286 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1287 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1288 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1289 params
[0] = FLOAT_TO_INT(b
[0]);
1290 params
[1] = FLOAT_TO_INT(b
[1]);
1291 params
[2] = FLOAT_TO_INT(b
[2]);
1292 params
[3] = FLOAT_TO_INT(b
[3]);
1295 case GL_TEXTURE_RESIDENT
:
1298 if (ctx
->Driver
.IsTextureResident
)
1299 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1302 *params
= (GLint
) resident
;
1305 case GL_TEXTURE_PRIORITY
:
1306 *params
= FLOAT_TO_INT(obj
->Priority
);
1308 case GL_TEXTURE_MIN_LOD
:
1309 *params
= (GLint
) obj
->Sampler
.MinLod
;
1311 case GL_TEXTURE_MAX_LOD
:
1312 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1314 case GL_TEXTURE_BASE_LEVEL
:
1315 *params
= obj
->BaseLevel
;
1317 case GL_TEXTURE_MAX_LEVEL
:
1318 *params
= obj
->MaxLevel
;
1320 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1321 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1322 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1328 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1329 if (ctx
->Extensions
.ARB_shadow_ambient
) {
1330 *params
= (GLint
) FLOAT_TO_INT(obj
->Sampler
.CompareFailValue
);
1336 case GL_GENERATE_MIPMAP_SGIS
:
1337 *params
= (GLint
) obj
->GenerateMipmap
;
1339 case GL_TEXTURE_COMPARE_MODE_ARB
:
1340 if (ctx
->Extensions
.ARB_shadow
) {
1341 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1347 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1348 if (ctx
->Extensions
.ARB_shadow
) {
1349 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1355 case GL_DEPTH_TEXTURE_MODE_ARB
:
1356 if (ctx
->Extensions
.ARB_depth_texture
) {
1357 *params
= (GLint
) obj
->Sampler
.DepthMode
;
1363 case GL_TEXTURE_LOD_BIAS
:
1364 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1365 *params
= (GLint
) obj
->Sampler
.LodBias
;
1371 #if FEATURE_OES_draw_texture
1372 case GL_TEXTURE_CROP_RECT_OES
:
1373 params
[0] = obj
->CropRect
[0];
1374 params
[1] = obj
->CropRect
[1];
1375 params
[2] = obj
->CropRect
[2];
1376 params
[3] = obj
->CropRect
[3];
1379 case GL_TEXTURE_SWIZZLE_R_EXT
:
1380 case GL_TEXTURE_SWIZZLE_G_EXT
:
1381 case GL_TEXTURE_SWIZZLE_B_EXT
:
1382 case GL_TEXTURE_SWIZZLE_A_EXT
:
1383 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1384 GLuint comp
= pname
- GL_TEXTURE_SWIZZLE_R_EXT
;
1385 *params
= obj
->Swizzle
[comp
];
1392 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
1393 if (ctx
->Extensions
.EXT_texture_swizzle
) {
1394 COPY_4V(params
, obj
->Swizzle
);
1402 ; /* silence warnings */
1406 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)",
1409 _mesa_unlock_texture(ctx
, obj
);
1413 /** New in GL 3.0 */
1415 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1417 struct gl_texture_object
*texObj
;
1418 GET_CURRENT_CONTEXT(ctx
);
1419 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1421 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1424 case GL_TEXTURE_BORDER_COLOR
:
1425 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1428 _mesa_GetTexParameteriv(target
, pname
, params
);
1433 /** New in GL 3.0 */
1435 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1437 struct gl_texture_object
*texObj
;
1438 GET_CURRENT_CONTEXT(ctx
);
1439 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1441 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1444 case GL_TEXTURE_BORDER_COLOR
:
1445 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1450 _mesa_GetTexParameteriv(target
, pname
, ip
);
1452 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1453 pname
== GL_TEXTURE_CROP_RECT_OES
) {