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/image.h"
39 #include "main/macros.h"
40 #include "main/mfeatures.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texcompress.h"
44 #include "main/texparam.h"
45 #include "main/teximage.h"
46 #include "main/texstate.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 (target
== GL_TEXTURE_RECTANGLE_NV
) {
60 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
61 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
))
64 else if (target
== GL_TEXTURE_EXTERNAL_OES
) {
65 if (wrap
== GL_CLAMP_TO_EDGE
)
72 case GL_CLAMP_TO_EDGE
:
73 case GL_MIRRORED_REPEAT
:
75 case GL_CLAMP_TO_BORDER
:
76 if (e
->ARB_texture_border_clamp
)
79 case GL_MIRROR_CLAMP_EXT
:
80 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
81 if (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)
84 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
85 if (e
->EXT_texture_mirror_clamp
)
93 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(param=0x%x)", wrap
);
99 * Get current texture object for given target.
100 * Return NULL if any error (and record the error).
101 * Note that this is different from _mesa_select_tex_object() in that proxy
102 * targets are not accepted.
103 * Only the glGetTexLevelParameter() functions accept proxy targets.
105 static struct gl_texture_object
*
106 get_texobj(struct gl_context
*ctx
, GLenum target
, GLboolean get
)
108 struct gl_texture_unit
*texUnit
;
110 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
111 _mesa_error(ctx
, GL_INVALID_OPERATION
,
112 "gl%sTexParameter(current unit)", get
? "Get" : "");
116 texUnit
= _mesa_get_current_tex_unit(ctx
);
120 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
122 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
124 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
125 case GL_TEXTURE_CUBE_MAP
:
126 if (ctx
->Extensions
.ARB_texture_cube_map
) {
127 return texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
];
130 case GL_TEXTURE_RECTANGLE_NV
:
131 if (ctx
->Extensions
.NV_texture_rectangle
) {
132 return texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
];
135 case GL_TEXTURE_1D_ARRAY_EXT
:
136 if (ctx
->Extensions
.MESA_texture_array
||
137 ctx
->Extensions
.EXT_texture_array
) {
138 return texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
];
141 case GL_TEXTURE_2D_ARRAY_EXT
:
142 if (ctx
->Extensions
.MESA_texture_array
||
143 ctx
->Extensions
.EXT_texture_array
) {
144 return texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
];
147 case GL_TEXTURE_EXTERNAL_OES
:
148 if (ctx
->Extensions
.OES_EGL_image_external
) {
149 return texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
];
156 _mesa_error(ctx
, GL_INVALID_ENUM
,
157 "gl%sTexParameter(target)", get
? "Get" : "");
163 * This is called just prior to changing any texture object state which
164 * will not effect texture completeness.
167 flush(struct gl_context
*ctx
)
169 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
174 * This is called just prior to changing any texture object state which
175 * can effect texture completeness (texture base level, max level,
176 * minification filter).
177 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
178 * state flag and then mark the texture object as 'incomplete' so that any
179 * per-texture derived state gets recomputed.
182 incomplete(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
184 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
185 texObj
->_Complete
= GL_FALSE
;
190 * Set an integer-valued texture parameter
191 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
194 set_tex_parameteri(struct gl_context
*ctx
,
195 struct gl_texture_object
*texObj
,
196 GLenum pname
, const GLint
*params
)
199 case GL_TEXTURE_MIN_FILTER
:
200 if (texObj
->Sampler
.MinFilter
== params
[0])
205 incomplete(ctx
, texObj
);
206 texObj
->Sampler
.MinFilter
= params
[0];
208 case GL_NEAREST_MIPMAP_NEAREST
:
209 case GL_LINEAR_MIPMAP_NEAREST
:
210 case GL_NEAREST_MIPMAP_LINEAR
:
211 case GL_LINEAR_MIPMAP_LINEAR
:
212 if (texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
&&
213 texObj
->Target
!= GL_TEXTURE_EXTERNAL_OES
) {
214 incomplete(ctx
, texObj
);
215 texObj
->Sampler
.MinFilter
= params
[0];
224 case GL_TEXTURE_MAG_FILTER
:
225 if (texObj
->Sampler
.MagFilter
== params
[0])
230 flush(ctx
); /* does not effect completeness */
231 texObj
->Sampler
.MagFilter
= params
[0];
238 case GL_TEXTURE_WRAP_S
:
239 if (texObj
->Sampler
.WrapS
== params
[0])
241 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
243 texObj
->Sampler
.WrapS
= params
[0];
248 case GL_TEXTURE_WRAP_T
:
249 if (texObj
->Sampler
.WrapT
== params
[0])
251 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
253 texObj
->Sampler
.WrapT
= params
[0];
258 case GL_TEXTURE_WRAP_R
:
259 if (texObj
->Sampler
.WrapR
== params
[0])
261 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, params
[0])) {
263 texObj
->Sampler
.WrapR
= params
[0];
268 case GL_TEXTURE_BASE_LEVEL
:
269 if (texObj
->BaseLevel
== params
[0])
272 (texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0)) {
273 _mesa_error(ctx
, GL_INVALID_VALUE
,
274 "glTexParameter(param=%d)", params
[0]);
277 incomplete(ctx
, texObj
);
278 texObj
->BaseLevel
= params
[0];
281 case GL_TEXTURE_MAX_LEVEL
:
282 if (texObj
->MaxLevel
== params
[0])
284 if (params
[0] < 0 || texObj
->Target
== GL_TEXTURE_RECTANGLE_ARB
) {
285 _mesa_error(ctx
, GL_INVALID_OPERATION
,
286 "glTexParameter(param=%d)", params
[0]);
289 incomplete(ctx
, texObj
);
290 texObj
->MaxLevel
= params
[0];
293 case GL_GENERATE_MIPMAP_SGIS
:
294 if (params
[0] && texObj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
296 if (texObj
->GenerateMipmap
!= params
[0]) {
298 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
303 case GL_TEXTURE_COMPARE_MODE_ARB
:
304 if (ctx
->Extensions
.ARB_shadow
) {
305 if (texObj
->Sampler
.CompareMode
== params
[0])
307 if (params
[0] == GL_NONE
||
308 params
[0] == GL_COMPARE_R_TO_TEXTURE_ARB
) {
310 texObj
->Sampler
.CompareMode
= params
[0];
317 case GL_TEXTURE_COMPARE_FUNC_ARB
:
318 if (ctx
->Extensions
.ARB_shadow
) {
319 if (texObj
->Sampler
.CompareFunc
== params
[0])
325 texObj
->Sampler
.CompareFunc
= params
[0];
333 if (ctx
->Extensions
.EXT_shadow_funcs
) {
335 texObj
->Sampler
.CompareFunc
= params
[0];
345 case GL_DEPTH_TEXTURE_MODE_ARB
:
346 if (ctx
->Extensions
.ARB_depth_texture
) {
347 if (texObj
->Sampler
.DepthMode
== params
[0])
349 if (params
[0] == GL_LUMINANCE
||
350 params
[0] == GL_INTENSITY
||
351 params
[0] == GL_ALPHA
||
352 (ctx
->Extensions
.ARB_texture_rg
&& params
[0] == GL_RED
)) {
354 texObj
->Sampler
.DepthMode
= params
[0];
361 #if FEATURE_OES_draw_texture
362 case GL_TEXTURE_CROP_RECT_OES
:
363 texObj
->CropRect
[0] = params
[0];
364 texObj
->CropRect
[1] = params
[1];
365 texObj
->CropRect
[2] = params
[2];
366 texObj
->CropRect
[3] = params
[3];
370 case GL_TEXTURE_SRGB_DECODE_EXT
:
371 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
372 GLenum decode
= params
[0];
373 if (decode
== GL_DECODE_EXT
|| decode
== GL_SKIP_DECODE_EXT
) {
374 if (texObj
->Sampler
.sRGBDecode
!= decode
) {
376 texObj
->Sampler
.sRGBDecode
= decode
;
383 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
384 if (ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
385 GLenum param
= params
[0];
386 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
389 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
391 texObj
->Sampler
.CubeMapSeamless
= param
;
402 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
403 _mesa_lookup_enum_by_nr(pname
));
407 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
408 _mesa_lookup_enum_by_nr(params
[0]));
414 * Set a float-valued texture parameter
415 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
418 set_tex_parameterf(struct gl_context
*ctx
,
419 struct gl_texture_object
*texObj
,
420 GLenum pname
, const GLfloat
*params
)
423 case GL_TEXTURE_MIN_LOD
:
424 if (texObj
->Sampler
.MinLod
== params
[0])
427 texObj
->Sampler
.MinLod
= params
[0];
430 case GL_TEXTURE_MAX_LOD
:
431 if (texObj
->Sampler
.MaxLod
== params
[0])
434 texObj
->Sampler
.MaxLod
= params
[0];
437 case GL_TEXTURE_PRIORITY
:
439 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
442 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
443 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
444 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
446 if (params
[0] < 1.0) {
447 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
451 /* clamp to max, that's what NVIDIA does */
452 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
453 ctx
->Const
.MaxTextureMaxAnisotropy
);
457 static GLuint count
= 0;
459 _mesa_error(ctx
, GL_INVALID_ENUM
,
460 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
464 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
465 if (ctx
->Extensions
.ARB_shadow_ambient
) {
466 if (texObj
->Sampler
.CompareFailValue
!= params
[0]) {
468 texObj
->Sampler
.CompareFailValue
= CLAMP(params
[0], 0.0F
, 1.0F
);
473 _mesa_error(ctx
, GL_INVALID_ENUM
,
474 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
478 case GL_TEXTURE_LOD_BIAS
:
479 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
480 if (texObj
->Sampler
.LodBias
!= params
[0]) {
482 texObj
->Sampler
.LodBias
= params
[0];
487 case GL_TEXTURE_BORDER_COLOR
:
489 /* ARB_texture_float disables clamping */
490 if (ctx
->Extensions
.ARB_texture_float
) {
491 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
492 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
493 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
494 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
496 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
497 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
498 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
499 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
504 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
511 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
513 GLboolean need_update
;
514 struct gl_texture_object
*texObj
;
515 GET_CURRENT_CONTEXT(ctx
);
516 ASSERT_OUTSIDE_BEGIN_END(ctx
);
518 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
523 case GL_TEXTURE_MIN_FILTER
:
524 case GL_TEXTURE_MAG_FILTER
:
525 case GL_TEXTURE_WRAP_S
:
526 case GL_TEXTURE_WRAP_T
:
527 case GL_TEXTURE_WRAP_R
:
528 case GL_TEXTURE_BASE_LEVEL
:
529 case GL_TEXTURE_MAX_LEVEL
:
530 case GL_GENERATE_MIPMAP_SGIS
:
531 case GL_TEXTURE_COMPARE_MODE_ARB
:
532 case GL_TEXTURE_COMPARE_FUNC_ARB
:
533 case GL_DEPTH_TEXTURE_MODE_ARB
:
534 case GL_TEXTURE_SRGB_DECODE_EXT
:
535 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
537 /* convert float param to int */
539 p
[0] = (GLint
) param
;
540 p
[1] = p
[2] = p
[3] = 0;
541 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
544 case GL_TEXTURE_SWIZZLE_R_EXT
:
545 case GL_TEXTURE_SWIZZLE_G_EXT
:
546 case GL_TEXTURE_SWIZZLE_B_EXT
:
547 case GL_TEXTURE_SWIZZLE_A_EXT
:
550 p
[0] = (GLint
) param
;
551 p
[1] = p
[2] = p
[3] = 0;
552 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
557 /* this will generate an error if pname is illegal */
560 p
[1] = p
[2] = p
[3] = 0.0F
;
561 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
565 if (ctx
->Driver
.TexParameter
&& need_update
) {
566 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
572 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
574 GLboolean need_update
;
575 struct gl_texture_object
*texObj
;
576 GET_CURRENT_CONTEXT(ctx
);
577 ASSERT_OUTSIDE_BEGIN_END(ctx
);
579 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
584 case GL_TEXTURE_MIN_FILTER
:
585 case GL_TEXTURE_MAG_FILTER
:
586 case GL_TEXTURE_WRAP_S
:
587 case GL_TEXTURE_WRAP_T
:
588 case GL_TEXTURE_WRAP_R
:
589 case GL_TEXTURE_BASE_LEVEL
:
590 case GL_TEXTURE_MAX_LEVEL
:
591 case GL_GENERATE_MIPMAP_SGIS
:
592 case GL_TEXTURE_COMPARE_MODE_ARB
:
593 case GL_TEXTURE_COMPARE_FUNC_ARB
:
594 case GL_DEPTH_TEXTURE_MODE_ARB
:
595 case GL_TEXTURE_SRGB_DECODE_EXT
:
596 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
598 /* convert float param to int */
600 p
[0] = (GLint
) params
[0];
601 p
[1] = p
[2] = p
[3] = 0;
602 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
606 #if FEATURE_OES_draw_texture
607 case GL_TEXTURE_CROP_RECT_OES
:
609 /* convert float params to int */
611 iparams
[0] = (GLint
) params
[0];
612 iparams
[1] = (GLint
) params
[1];
613 iparams
[2] = (GLint
) params
[2];
614 iparams
[3] = (GLint
) params
[3];
615 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
620 case GL_TEXTURE_SWIZZLE_R_EXT
:
621 case GL_TEXTURE_SWIZZLE_G_EXT
:
622 case GL_TEXTURE_SWIZZLE_B_EXT
:
623 case GL_TEXTURE_SWIZZLE_A_EXT
:
624 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
626 GLint p
[4] = {0, 0, 0, 0};
627 p
[0] = (GLint
) params
[0];
628 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
629 p
[1] = (GLint
) params
[1];
630 p
[2] = (GLint
) params
[2];
631 p
[3] = (GLint
) params
[3];
633 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
637 /* this will generate an error if pname is illegal */
638 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
641 if (ctx
->Driver
.TexParameter
&& need_update
) {
642 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
648 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
650 GLboolean need_update
;
651 struct gl_texture_object
*texObj
;
652 GET_CURRENT_CONTEXT(ctx
);
653 ASSERT_OUTSIDE_BEGIN_END(ctx
);
655 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
660 case GL_TEXTURE_MIN_LOD
:
661 case GL_TEXTURE_MAX_LOD
:
662 case GL_TEXTURE_PRIORITY
:
663 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
664 case GL_TEXTURE_LOD_BIAS
:
665 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
668 fparam
[0] = (GLfloat
) param
;
669 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
670 /* convert int param to float */
671 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
675 /* this will generate an error if pname is illegal */
679 iparam
[1] = iparam
[2] = iparam
[3] = 0;
680 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
684 if (ctx
->Driver
.TexParameter
&& need_update
) {
685 GLfloat fparam
= (GLfloat
) param
;
686 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
692 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
694 GLboolean need_update
;
695 struct gl_texture_object
*texObj
;
696 GET_CURRENT_CONTEXT(ctx
);
697 ASSERT_OUTSIDE_BEGIN_END(ctx
);
699 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
704 case GL_TEXTURE_BORDER_COLOR
:
706 /* convert int params to float */
708 fparams
[0] = INT_TO_FLOAT(params
[0]);
709 fparams
[1] = INT_TO_FLOAT(params
[1]);
710 fparams
[2] = INT_TO_FLOAT(params
[2]);
711 fparams
[3] = INT_TO_FLOAT(params
[3]);
712 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
715 case GL_TEXTURE_MIN_LOD
:
716 case GL_TEXTURE_MAX_LOD
:
717 case GL_TEXTURE_PRIORITY
:
718 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
719 case GL_TEXTURE_LOD_BIAS
:
720 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
722 /* convert int param to float */
724 fparams
[0] = (GLfloat
) params
[0];
725 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
726 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
730 /* this will generate an error if pname is illegal */
731 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
734 if (ctx
->Driver
.TexParameter
&& need_update
) {
736 fparams
[0] = INT_TO_FLOAT(params
[0]);
737 if (pname
== GL_TEXTURE_BORDER_COLOR
||
738 pname
== GL_TEXTURE_CROP_RECT_OES
) {
739 fparams
[1] = INT_TO_FLOAT(params
[1]);
740 fparams
[2] = INT_TO_FLOAT(params
[2]);
741 fparams
[3] = INT_TO_FLOAT(params
[3]);
743 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
749 * Set tex parameter to integer value(s). Primarily intended to set
750 * integer-valued texture border color (for integer-valued textures).
754 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
756 struct gl_texture_object
*texObj
;
757 GET_CURRENT_CONTEXT(ctx
);
758 ASSERT_OUTSIDE_BEGIN_END(ctx
);
760 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
765 case GL_TEXTURE_BORDER_COLOR
:
766 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
767 /* set the integer-valued border color */
768 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
771 _mesa_TexParameteriv(target
, pname
, params
);
774 /* XXX no driver hook for TexParameterIiv() yet */
779 * Set tex parameter to unsigned integer value(s). Primarily intended to set
780 * uint-valued texture border color (for integer-valued textures).
784 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
786 struct gl_texture_object
*texObj
;
787 GET_CURRENT_CONTEXT(ctx
);
788 ASSERT_OUTSIDE_BEGIN_END(ctx
);
790 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
795 case GL_TEXTURE_BORDER_COLOR
:
796 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
797 /* set the unsigned integer-valued border color */
798 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
801 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
804 /* XXX no driver hook for TexParameterIuiv() yet */
809 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
810 GLenum pname
, GLfloat
*params
)
813 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
814 *params
= (GLfloat
) iparam
;
819 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
820 GLenum pname
, GLint
*params
)
822 const struct gl_texture_unit
*texUnit
;
823 struct gl_texture_object
*texObj
;
824 const struct gl_texture_image
*img
= NULL
;
827 GET_CURRENT_CONTEXT(ctx
);
828 ASSERT_OUTSIDE_BEGIN_END(ctx
);
830 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
832 "glGetTexLevelParameteriv(current unit)");
836 texUnit
= _mesa_get_current_tex_unit(ctx
);
838 /* this will catch bad target values */
839 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
840 if (maxLevels
== 0) {
841 _mesa_error(ctx
, GL_INVALID_ENUM
,
842 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
846 if (level
< 0 || level
>= maxLevels
) {
847 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
851 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
853 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
854 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
855 /* undefined texture image */
856 if (pname
== GL_TEXTURE_COMPONENTS
)
863 texFormat
= img
->TexFormat
;
866 case GL_TEXTURE_WIDTH
:
867 *params
= img
->Width
;
869 case GL_TEXTURE_HEIGHT
:
870 *params
= img
->Height
;
872 case GL_TEXTURE_DEPTH
:
873 *params
= img
->Depth
;
875 case GL_TEXTURE_INTERNAL_FORMAT
:
876 if (_mesa_is_format_compressed(texFormat
)) {
877 /* need to return the actual compressed format */
878 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
881 /* If the true internal format is not compressed but the user
882 * requested a generic compressed format, we have to return the
883 * generic base format that matches.
885 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
887 * "If no specific compressed format is available,
888 * internalformat is instead replaced by the corresponding base
891 * Otherwise just return the user's requested internal format
894 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
896 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
899 case GL_TEXTURE_BORDER
:
900 *params
= img
->Border
;
902 case GL_TEXTURE_RED_SIZE
:
903 case GL_TEXTURE_GREEN_SIZE
:
904 case GL_TEXTURE_BLUE_SIZE
:
905 case GL_TEXTURE_ALPHA_SIZE
:
906 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
907 *params
= _mesa_get_format_bits(texFormat
, pname
);
911 case GL_TEXTURE_INTENSITY_SIZE
:
912 case GL_TEXTURE_LUMINANCE_SIZE
:
913 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
914 *params
= _mesa_get_format_bits(texFormat
, pname
);
916 /* intensity or luminance is probably stored as RGB[A] */
917 *params
= MIN2(_mesa_get_format_bits(texFormat
,
918 GL_TEXTURE_RED_SIZE
),
919 _mesa_get_format_bits(texFormat
,
920 GL_TEXTURE_GREEN_SIZE
));
927 case GL_TEXTURE_DEPTH_SIZE_ARB
:
928 if (!ctx
->Extensions
.ARB_depth_texture
)
930 *params
= _mesa_get_format_bits(texFormat
, pname
);
932 case GL_TEXTURE_STENCIL_SIZE_EXT
:
933 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
934 !ctx
->Extensions
.ARB_framebuffer_object
)
936 *params
= _mesa_get_format_bits(texFormat
, pname
);
939 /* GL_ARB_texture_compression */
940 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
941 if (_mesa_is_format_compressed(texFormat
) &&
942 !_mesa_is_proxy_texture(target
)) {
943 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
944 img
->Height
, img
->Depth
);
947 _mesa_error(ctx
, GL_INVALID_OPERATION
,
948 "glGetTexLevelParameter[if]v(pname)");
951 case GL_TEXTURE_COMPRESSED
:
952 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
955 /* GL_ARB_texture_float */
956 case GL_TEXTURE_RED_TYPE_ARB
:
957 case GL_TEXTURE_GREEN_TYPE_ARB
:
958 case GL_TEXTURE_BLUE_TYPE_ARB
:
959 case GL_TEXTURE_ALPHA_TYPE_ARB
:
960 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
961 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
962 case GL_TEXTURE_DEPTH_TYPE_ARB
:
963 if (!ctx
->Extensions
.ARB_texture_float
)
965 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
966 *params
= _mesa_get_format_datatype(texFormat
);
975 /* no error if we get here */
979 _mesa_error(ctx
, GL_INVALID_ENUM
,
980 "glGetTexLevelParameter[if]v(pname=%s)",
981 _mesa_lookup_enum_by_nr(pname
));
987 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
989 struct gl_texture_object
*obj
;
990 GET_CURRENT_CONTEXT(ctx
);
991 ASSERT_OUTSIDE_BEGIN_END(ctx
);
993 obj
= get_texobj(ctx
, target
, GL_TRUE
);
997 _mesa_lock_texture(ctx
, obj
);
999 case GL_TEXTURE_MAG_FILTER
:
1000 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
1002 case GL_TEXTURE_MIN_FILTER
:
1003 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
1005 case GL_TEXTURE_WRAP_S
:
1006 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
1008 case GL_TEXTURE_WRAP_T
:
1009 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
1011 case GL_TEXTURE_WRAP_R
:
1012 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
1014 case GL_TEXTURE_BORDER_COLOR
:
1015 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1016 _mesa_update_state_locked(ctx
);
1017 if (ctx
->Color
._ClampFragmentColor
) {
1018 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1019 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1020 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1021 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1024 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
1025 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
1026 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
1027 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
1030 case GL_TEXTURE_RESIDENT
:
1033 case GL_TEXTURE_PRIORITY
:
1034 *params
= obj
->Priority
;
1036 case GL_TEXTURE_MIN_LOD
:
1037 *params
= obj
->Sampler
.MinLod
;
1039 case GL_TEXTURE_MAX_LOD
:
1040 *params
= obj
->Sampler
.MaxLod
;
1042 case GL_TEXTURE_BASE_LEVEL
:
1043 *params
= (GLfloat
) obj
->BaseLevel
;
1045 case GL_TEXTURE_MAX_LEVEL
:
1046 *params
= (GLfloat
) obj
->MaxLevel
;
1048 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1049 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1051 *params
= obj
->Sampler
.MaxAnisotropy
;
1053 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1054 if (!ctx
->Extensions
.ARB_shadow_ambient
)
1056 *params
= obj
->Sampler
.CompareFailValue
;
1058 case GL_GENERATE_MIPMAP_SGIS
:
1059 *params
= (GLfloat
) obj
->GenerateMipmap
;
1061 case GL_TEXTURE_COMPARE_MODE_ARB
:
1062 if (!ctx
->Extensions
.ARB_shadow
)
1064 *params
= (GLfloat
) obj
->Sampler
.CompareMode
;
1066 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1067 if (!ctx
->Extensions
.ARB_shadow
)
1069 *params
= (GLfloat
) obj
->Sampler
.CompareFunc
;
1071 case GL_DEPTH_TEXTURE_MODE_ARB
:
1072 if (!ctx
->Extensions
.ARB_depth_texture
)
1074 *params
= (GLfloat
) obj
->Sampler
.DepthMode
;
1076 case GL_TEXTURE_LOD_BIAS
:
1077 *params
= obj
->Sampler
.LodBias
;
1079 #if FEATURE_OES_draw_texture
1080 case GL_TEXTURE_CROP_RECT_OES
:
1081 params
[0] = obj
->CropRect
[0];
1082 params
[1] = obj
->CropRect
[1];
1083 params
[2] = obj
->CropRect
[2];
1084 params
[3] = obj
->CropRect
[3];
1088 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1089 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1091 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
1094 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1095 if (!ctx
->Extensions
.ARB_texture_storage
)
1097 *params
= (GLfloat
) obj
->Immutable
;
1104 /* no error if we get here */
1105 _mesa_unlock_texture(ctx
, obj
);
1109 _mesa_unlock_texture(ctx
, obj
);
1110 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1115 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1117 struct gl_texture_object
*obj
;
1118 GET_CURRENT_CONTEXT(ctx
);
1119 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1121 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1125 _mesa_lock_texture(ctx
, obj
);
1127 case GL_TEXTURE_MAG_FILTER
:
1128 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1130 case GL_TEXTURE_MIN_FILTER
:
1131 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1133 case GL_TEXTURE_WRAP_S
:
1134 *params
= (GLint
) obj
->Sampler
.WrapS
;
1136 case GL_TEXTURE_WRAP_T
:
1137 *params
= (GLint
) obj
->Sampler
.WrapT
;
1139 case GL_TEXTURE_WRAP_R
:
1140 *params
= (GLint
) obj
->Sampler
.WrapR
;
1142 case GL_TEXTURE_BORDER_COLOR
:
1145 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1146 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1147 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1148 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1149 params
[0] = FLOAT_TO_INT(b
[0]);
1150 params
[1] = FLOAT_TO_INT(b
[1]);
1151 params
[2] = FLOAT_TO_INT(b
[2]);
1152 params
[3] = FLOAT_TO_INT(b
[3]);
1155 case GL_TEXTURE_RESIDENT
:
1158 case GL_TEXTURE_PRIORITY
:
1159 *params
= FLOAT_TO_INT(obj
->Priority
);
1161 case GL_TEXTURE_MIN_LOD
:
1162 *params
= (GLint
) obj
->Sampler
.MinLod
;
1164 case GL_TEXTURE_MAX_LOD
:
1165 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1167 case GL_TEXTURE_BASE_LEVEL
:
1168 *params
= obj
->BaseLevel
;
1170 case GL_TEXTURE_MAX_LEVEL
:
1171 *params
= obj
->MaxLevel
;
1173 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1174 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1176 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1178 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
1179 if (!ctx
->Extensions
.ARB_shadow_ambient
)
1181 *params
= (GLint
) FLOAT_TO_INT(obj
->Sampler
.CompareFailValue
);
1183 case GL_GENERATE_MIPMAP_SGIS
:
1184 *params
= (GLint
) obj
->GenerateMipmap
;
1186 case GL_TEXTURE_COMPARE_MODE_ARB
:
1187 if (!ctx
->Extensions
.ARB_shadow
)
1189 *params
= (GLint
) obj
->Sampler
.CompareMode
;
1191 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1192 if (!ctx
->Extensions
.ARB_shadow
)
1194 *params
= (GLint
) obj
->Sampler
.CompareFunc
;
1196 case GL_DEPTH_TEXTURE_MODE_ARB
:
1197 if (!ctx
->Extensions
.ARB_depth_texture
)
1199 *params
= (GLint
) obj
->Sampler
.DepthMode
;
1201 case GL_TEXTURE_LOD_BIAS
:
1202 *params
= (GLint
) obj
->Sampler
.LodBias
;
1204 #if FEATURE_OES_draw_texture
1205 case GL_TEXTURE_CROP_RECT_OES
:
1206 params
[0] = obj
->CropRect
[0];
1207 params
[1] = obj
->CropRect
[1];
1208 params
[2] = obj
->CropRect
[2];
1209 params
[3] = obj
->CropRect
[3];
1213 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1214 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1216 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1219 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1220 if (!ctx
->Extensions
.ARB_texture_storage
)
1222 *params
= (GLint
) obj
->Immutable
;
1225 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1226 if (!ctx
->Extensions
.OES_EGL_image_external
)
1228 *params
= obj
->RequiredTextureImageUnits
;
1235 /* no error if we get here */
1236 _mesa_unlock_texture(ctx
, obj
);
1240 _mesa_unlock_texture(ctx
, obj
);
1241 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1245 /** New in GL 3.0 */
1247 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1249 struct gl_texture_object
*texObj
;
1250 GET_CURRENT_CONTEXT(ctx
);
1251 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1253 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1258 case GL_TEXTURE_BORDER_COLOR
:
1259 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1262 _mesa_GetTexParameteriv(target
, pname
, params
);
1267 /** New in GL 3.0 */
1269 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1271 struct gl_texture_object
*texObj
;
1272 GET_CURRENT_CONTEXT(ctx
);
1273 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1275 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1280 case GL_TEXTURE_BORDER_COLOR
:
1281 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1286 _mesa_GetTexParameteriv(target
, pname
, ip
);
1288 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1289 pname
== GL_TEXTURE_CROP_RECT_OES
) {