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 #if FEATURE_OES_draw_texture
304 case GL_TEXTURE_CROP_RECT_OES
:
305 texObj
->CropRect
[0] = params
[0];
306 texObj
->CropRect
[1] = params
[1];
307 texObj
->CropRect
[2] = params
[2];
308 texObj
->CropRect
[3] = params
[3];
312 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
313 if (ctx
->Extensions
.AMD_seamless_cubemap_per_texture
) {
314 GLenum param
= params
[0];
315 if (param
!= GL_TRUE
&& param
!= GL_FALSE
) {
318 if (param
!= texObj
->Sampler
.CubeMapSeamless
) {
320 texObj
->Sampler
.CubeMapSeamless
= param
;
331 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
332 _mesa_lookup_enum_by_nr(pname
));
336 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
337 _mesa_lookup_enum_by_nr(params
[0]));
343 * Set a float-valued texture parameter
344 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
347 set_tex_parameterf(struct gl_context
*ctx
,
348 struct gl_texture_object
*texObj
,
349 GLenum pname
, const GLfloat
*params
)
352 case GL_TEXTURE_MIN_LOD
:
353 if (texObj
->Sampler
.MinLod
== params
[0])
356 texObj
->Sampler
.MinLod
= params
[0];
359 case GL_TEXTURE_MAX_LOD
:
360 if (texObj
->Sampler
.MaxLod
== params
[0])
363 texObj
->Sampler
.MaxLod
= params
[0];
366 case GL_TEXTURE_PRIORITY
:
368 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
371 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
372 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
373 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
375 if (params
[0] < 1.0) {
376 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
380 /* clamp to max, that's what NVIDIA does */
381 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
382 ctx
->Const
.MaxTextureMaxAnisotropy
);
386 static GLuint count
= 0;
388 _mesa_error(ctx
, GL_INVALID_ENUM
,
389 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
393 case GL_TEXTURE_LOD_BIAS
:
394 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
395 if (texObj
->Sampler
.LodBias
!= params
[0]) {
397 texObj
->Sampler
.LodBias
= params
[0];
402 case GL_TEXTURE_BORDER_COLOR
:
404 /* ARB_texture_float disables clamping */
405 if (ctx
->Extensions
.ARB_texture_float
) {
406 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
407 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
408 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
409 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
411 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
412 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
413 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
414 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
426 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
428 GLboolean need_update
;
429 struct gl_texture_object
*texObj
;
430 GET_CURRENT_CONTEXT(ctx
);
431 ASSERT_OUTSIDE_BEGIN_END(ctx
);
433 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
438 case GL_TEXTURE_MIN_FILTER
:
439 case GL_TEXTURE_MAG_FILTER
:
440 case GL_TEXTURE_WRAP_S
:
441 case GL_TEXTURE_WRAP_T
:
442 case GL_TEXTURE_WRAP_R
:
443 case GL_TEXTURE_BASE_LEVEL
:
444 case GL_TEXTURE_MAX_LEVEL
:
445 case GL_GENERATE_MIPMAP_SGIS
:
446 case GL_TEXTURE_COMPARE_MODE_ARB
:
447 case GL_TEXTURE_COMPARE_FUNC_ARB
:
448 case GL_DEPTH_TEXTURE_MODE_ARB
:
449 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
451 /* convert float param to int */
453 p
[0] = (GLint
) param
;
454 p
[1] = p
[2] = p
[3] = 0;
455 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
458 case GL_TEXTURE_SWIZZLE_R_EXT
:
459 case GL_TEXTURE_SWIZZLE_G_EXT
:
460 case GL_TEXTURE_SWIZZLE_B_EXT
:
461 case GL_TEXTURE_SWIZZLE_A_EXT
:
464 p
[0] = (GLint
) param
;
465 p
[1] = p
[2] = p
[3] = 0;
466 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
471 /* this will generate an error if pname is illegal */
474 p
[1] = p
[2] = p
[3] = 0.0F
;
475 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
479 if (ctx
->Driver
.TexParameter
&& need_update
) {
480 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
486 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
488 GLboolean need_update
;
489 struct gl_texture_object
*texObj
;
490 GET_CURRENT_CONTEXT(ctx
);
491 ASSERT_OUTSIDE_BEGIN_END(ctx
);
493 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
498 case GL_TEXTURE_MIN_FILTER
:
499 case GL_TEXTURE_MAG_FILTER
:
500 case GL_TEXTURE_WRAP_S
:
501 case GL_TEXTURE_WRAP_T
:
502 case GL_TEXTURE_WRAP_R
:
503 case GL_TEXTURE_BASE_LEVEL
:
504 case GL_TEXTURE_MAX_LEVEL
:
505 case GL_GENERATE_MIPMAP_SGIS
:
506 case GL_TEXTURE_COMPARE_MODE_ARB
:
507 case GL_TEXTURE_COMPARE_FUNC_ARB
:
508 case GL_DEPTH_TEXTURE_MODE_ARB
:
509 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
511 /* convert float param to int */
513 p
[0] = (GLint
) params
[0];
514 p
[1] = p
[2] = p
[3] = 0;
515 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
519 #if FEATURE_OES_draw_texture
520 case GL_TEXTURE_CROP_RECT_OES
:
522 /* convert float params to int */
524 iparams
[0] = (GLint
) params
[0];
525 iparams
[1] = (GLint
) params
[1];
526 iparams
[2] = (GLint
) params
[2];
527 iparams
[3] = (GLint
) params
[3];
528 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
533 case GL_TEXTURE_SWIZZLE_R_EXT
:
534 case GL_TEXTURE_SWIZZLE_G_EXT
:
535 case GL_TEXTURE_SWIZZLE_B_EXT
:
536 case GL_TEXTURE_SWIZZLE_A_EXT
:
537 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
539 GLint p
[4] = {0, 0, 0, 0};
540 p
[0] = (GLint
) params
[0];
541 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
542 p
[1] = (GLint
) params
[1];
543 p
[2] = (GLint
) params
[2];
544 p
[3] = (GLint
) params
[3];
546 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
550 /* this will generate an error if pname is illegal */
551 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
554 if (ctx
->Driver
.TexParameter
&& need_update
) {
555 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
561 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
563 GLboolean need_update
;
564 struct gl_texture_object
*texObj
;
565 GET_CURRENT_CONTEXT(ctx
);
566 ASSERT_OUTSIDE_BEGIN_END(ctx
);
568 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
573 case GL_TEXTURE_MIN_LOD
:
574 case GL_TEXTURE_MAX_LOD
:
575 case GL_TEXTURE_PRIORITY
:
576 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
577 case GL_TEXTURE_LOD_BIAS
:
578 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
581 fparam
[0] = (GLfloat
) param
;
582 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
583 /* convert int param to float */
584 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
588 /* this will generate an error if pname is illegal */
592 iparam
[1] = iparam
[2] = iparam
[3] = 0;
593 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
597 if (ctx
->Driver
.TexParameter
&& need_update
) {
598 GLfloat fparam
= (GLfloat
) param
;
599 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
605 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
607 GLboolean need_update
;
608 struct gl_texture_object
*texObj
;
609 GET_CURRENT_CONTEXT(ctx
);
610 ASSERT_OUTSIDE_BEGIN_END(ctx
);
612 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
617 case GL_TEXTURE_BORDER_COLOR
:
619 /* convert int params to float */
621 fparams
[0] = INT_TO_FLOAT(params
[0]);
622 fparams
[1] = INT_TO_FLOAT(params
[1]);
623 fparams
[2] = INT_TO_FLOAT(params
[2]);
624 fparams
[3] = INT_TO_FLOAT(params
[3]);
625 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
628 case GL_TEXTURE_MIN_LOD
:
629 case GL_TEXTURE_MAX_LOD
:
630 case GL_TEXTURE_PRIORITY
:
631 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
632 case GL_TEXTURE_LOD_BIAS
:
633 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
635 /* convert int param to float */
637 fparams
[0] = (GLfloat
) params
[0];
638 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
639 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
643 /* this will generate an error if pname is illegal */
644 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
647 if (ctx
->Driver
.TexParameter
&& need_update
) {
649 fparams
[0] = INT_TO_FLOAT(params
[0]);
650 if (pname
== GL_TEXTURE_BORDER_COLOR
||
651 pname
== GL_TEXTURE_CROP_RECT_OES
) {
652 fparams
[1] = INT_TO_FLOAT(params
[1]);
653 fparams
[2] = INT_TO_FLOAT(params
[2]);
654 fparams
[3] = INT_TO_FLOAT(params
[3]);
656 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
662 * Set tex parameter to integer value(s). Primarily intended to set
663 * integer-valued texture border color (for integer-valued textures).
667 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
669 struct gl_texture_object
*texObj
;
670 GET_CURRENT_CONTEXT(ctx
);
671 ASSERT_OUTSIDE_BEGIN_END(ctx
);
673 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
678 case GL_TEXTURE_BORDER_COLOR
:
679 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
680 /* set the integer-valued border color */
681 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
684 _mesa_TexParameteriv(target
, pname
, params
);
687 /* XXX no driver hook for TexParameterIiv() yet */
692 * Set tex parameter to unsigned integer value(s). Primarily intended to set
693 * uint-valued texture border color (for integer-valued textures).
697 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
699 struct gl_texture_object
*texObj
;
700 GET_CURRENT_CONTEXT(ctx
);
701 ASSERT_OUTSIDE_BEGIN_END(ctx
);
703 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
708 case GL_TEXTURE_BORDER_COLOR
:
709 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
710 /* set the unsigned integer-valued border color */
711 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
714 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
717 /* XXX no driver hook for TexParameterIuiv() yet */
722 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
723 GLenum pname
, GLfloat
*params
)
726 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
727 *params
= (GLfloat
) iparam
;
732 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
733 GLenum pname
, GLint
*params
)
735 const struct gl_texture_unit
*texUnit
;
736 struct gl_texture_object
*texObj
;
737 const struct gl_texture_image
*img
= NULL
;
740 GET_CURRENT_CONTEXT(ctx
);
741 ASSERT_OUTSIDE_BEGIN_END(ctx
);
743 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
744 _mesa_error(ctx
, GL_INVALID_OPERATION
,
745 "glGetTexLevelParameteriv(current unit)");
749 texUnit
= _mesa_get_current_tex_unit(ctx
);
751 /* this will catch bad target values */
752 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
753 if (maxLevels
== 0) {
754 _mesa_error(ctx
, GL_INVALID_ENUM
,
755 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
759 if (level
< 0 || level
>= maxLevels
) {
760 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
764 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
766 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
767 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
768 /* undefined texture image */
769 if (pname
== GL_TEXTURE_COMPONENTS
)
776 texFormat
= img
->TexFormat
;
779 case GL_TEXTURE_WIDTH
:
780 *params
= img
->Width
;
782 case GL_TEXTURE_HEIGHT
:
783 *params
= img
->Height
;
785 case GL_TEXTURE_DEPTH
:
786 *params
= img
->Depth
;
788 case GL_TEXTURE_INTERNAL_FORMAT
:
789 if (_mesa_is_format_compressed(texFormat
)) {
790 /* need to return the actual compressed format */
791 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
794 /* If the true internal format is not compressed but the user
795 * requested a generic compressed format, we have to return the
796 * generic base format that matches.
798 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
800 * "If no specific compressed format is available,
801 * internalformat is instead replaced by the corresponding base
804 * Otherwise just return the user's requested internal format
807 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
809 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
812 case GL_TEXTURE_BORDER
:
813 *params
= img
->Border
;
815 case GL_TEXTURE_RED_SIZE
:
816 case GL_TEXTURE_GREEN_SIZE
:
817 case GL_TEXTURE_BLUE_SIZE
:
818 case GL_TEXTURE_ALPHA_SIZE
:
819 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
820 *params
= _mesa_get_format_bits(texFormat
, pname
);
824 case GL_TEXTURE_INTENSITY_SIZE
:
825 case GL_TEXTURE_LUMINANCE_SIZE
:
826 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
827 *params
= _mesa_get_format_bits(texFormat
, pname
);
829 /* intensity or luminance is probably stored as RGB[A] */
830 *params
= MIN2(_mesa_get_format_bits(texFormat
,
831 GL_TEXTURE_RED_SIZE
),
832 _mesa_get_format_bits(texFormat
,
833 GL_TEXTURE_GREEN_SIZE
));
840 case GL_TEXTURE_STENCIL_SIZE_EXT
:
841 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
842 !ctx
->Extensions
.ARB_framebuffer_object
)
844 *params
= _mesa_get_format_bits(texFormat
, pname
);
847 /* GL_ARB_texture_compression */
848 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
849 if (_mesa_is_format_compressed(texFormat
) &&
850 !_mesa_is_proxy_texture(target
)) {
851 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
852 img
->Height
, img
->Depth
);
855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
856 "glGetTexLevelParameter[if]v(pname)");
859 case GL_TEXTURE_COMPRESSED
:
860 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
863 /* GL_ARB_texture_float */
864 case GL_TEXTURE_RED_TYPE_ARB
:
865 case GL_TEXTURE_GREEN_TYPE_ARB
:
866 case GL_TEXTURE_BLUE_TYPE_ARB
:
867 case GL_TEXTURE_ALPHA_TYPE_ARB
:
868 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
869 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
870 case GL_TEXTURE_DEPTH_TYPE_ARB
:
871 if (!ctx
->Extensions
.ARB_texture_float
)
873 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
874 *params
= _mesa_get_format_datatype(texFormat
);
883 /* no error if we get here */
887 _mesa_error(ctx
, GL_INVALID_ENUM
,
888 "glGetTexLevelParameter[if]v(pname=%s)",
889 _mesa_lookup_enum_by_nr(pname
));
895 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
897 struct gl_texture_object
*obj
;
898 GET_CURRENT_CONTEXT(ctx
);
899 ASSERT_OUTSIDE_BEGIN_END(ctx
);
901 obj
= get_texobj(ctx
, target
, GL_TRUE
);
905 _mesa_lock_texture(ctx
, obj
);
907 case GL_TEXTURE_MAG_FILTER
:
908 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
910 case GL_TEXTURE_MIN_FILTER
:
911 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
913 case GL_TEXTURE_WRAP_S
:
914 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
916 case GL_TEXTURE_WRAP_T
:
917 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
919 case GL_TEXTURE_WRAP_R
:
920 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
922 case GL_TEXTURE_BORDER_COLOR
:
923 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
924 _mesa_update_state_locked(ctx
);
925 if (ctx
->Color
._ClampFragmentColor
) {
926 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
927 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
928 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
929 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
932 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
933 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
934 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
935 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
938 case GL_TEXTURE_RESIDENT
:
941 case GL_TEXTURE_PRIORITY
:
942 *params
= obj
->Priority
;
944 case GL_TEXTURE_MIN_LOD
:
945 *params
= obj
->Sampler
.MinLod
;
947 case GL_TEXTURE_MAX_LOD
:
948 *params
= obj
->Sampler
.MaxLod
;
950 case GL_TEXTURE_BASE_LEVEL
:
951 *params
= (GLfloat
) obj
->BaseLevel
;
953 case GL_TEXTURE_MAX_LEVEL
:
954 *params
= (GLfloat
) obj
->MaxLevel
;
956 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
957 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
959 *params
= obj
->Sampler
.MaxAnisotropy
;
961 case GL_GENERATE_MIPMAP_SGIS
:
962 *params
= (GLfloat
) obj
->GenerateMipmap
;
964 case GL_TEXTURE_LOD_BIAS
:
965 *params
= obj
->Sampler
.LodBias
;
967 #if FEATURE_OES_draw_texture
968 case GL_TEXTURE_CROP_RECT_OES
:
969 params
[0] = obj
->CropRect
[0];
970 params
[1] = obj
->CropRect
[1];
971 params
[2] = obj
->CropRect
[2];
972 params
[3] = obj
->CropRect
[3];
976 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
977 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
979 *params
= (GLfloat
) obj
->Sampler
.CubeMapSeamless
;
982 case GL_TEXTURE_IMMUTABLE_FORMAT
:
983 if (!ctx
->Extensions
.ARB_texture_storage
)
985 *params
= (GLfloat
) obj
->Immutable
;
992 /* no error if we get here */
993 _mesa_unlock_texture(ctx
, obj
);
997 _mesa_unlock_texture(ctx
, obj
);
998 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
1003 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1005 struct gl_texture_object
*obj
;
1006 GET_CURRENT_CONTEXT(ctx
);
1007 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1009 obj
= get_texobj(ctx
, target
, GL_TRUE
);
1013 _mesa_lock_texture(ctx
, obj
);
1015 case GL_TEXTURE_MAG_FILTER
:
1016 *params
= (GLint
) obj
->Sampler
.MagFilter
;
1018 case GL_TEXTURE_MIN_FILTER
:
1019 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1021 case GL_TEXTURE_WRAP_S
:
1022 *params
= (GLint
) obj
->Sampler
.WrapS
;
1024 case GL_TEXTURE_WRAP_T
:
1025 *params
= (GLint
) obj
->Sampler
.WrapT
;
1027 case GL_TEXTURE_WRAP_R
:
1028 *params
= (GLint
) obj
->Sampler
.WrapR
;
1030 case GL_TEXTURE_BORDER_COLOR
:
1033 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1034 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1035 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1036 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1037 params
[0] = FLOAT_TO_INT(b
[0]);
1038 params
[1] = FLOAT_TO_INT(b
[1]);
1039 params
[2] = FLOAT_TO_INT(b
[2]);
1040 params
[3] = FLOAT_TO_INT(b
[3]);
1043 case GL_TEXTURE_RESIDENT
:
1046 case GL_TEXTURE_PRIORITY
:
1047 *params
= FLOAT_TO_INT(obj
->Priority
);
1049 case GL_TEXTURE_MIN_LOD
:
1050 *params
= (GLint
) obj
->Sampler
.MinLod
;
1052 case GL_TEXTURE_MAX_LOD
:
1053 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1055 case GL_TEXTURE_BASE_LEVEL
:
1056 *params
= obj
->BaseLevel
;
1058 case GL_TEXTURE_MAX_LEVEL
:
1059 *params
= obj
->MaxLevel
;
1061 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1062 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1064 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1066 case GL_GENERATE_MIPMAP_SGIS
:
1067 *params
= (GLint
) obj
->GenerateMipmap
;
1069 case GL_TEXTURE_LOD_BIAS
:
1070 *params
= (GLint
) obj
->Sampler
.LodBias
;
1072 #if FEATURE_OES_draw_texture
1073 case GL_TEXTURE_CROP_RECT_OES
:
1074 params
[0] = obj
->CropRect
[0];
1075 params
[1] = obj
->CropRect
[1];
1076 params
[2] = obj
->CropRect
[2];
1077 params
[3] = obj
->CropRect
[3];
1081 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1082 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1084 *params
= (GLint
) obj
->Sampler
.CubeMapSeamless
;
1087 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1088 if (!ctx
->Extensions
.ARB_texture_storage
)
1090 *params
= (GLint
) obj
->Immutable
;
1093 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1094 if (!ctx
->Extensions
.OES_EGL_image_external
)
1096 *params
= obj
->RequiredTextureImageUnits
;
1103 /* no error if we get here */
1104 _mesa_unlock_texture(ctx
, obj
);
1108 _mesa_unlock_texture(ctx
, obj
);
1109 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1113 /** New in GL 3.0 */
1115 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1117 struct gl_texture_object
*texObj
;
1118 GET_CURRENT_CONTEXT(ctx
);
1119 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1121 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1126 case GL_TEXTURE_BORDER_COLOR
:
1127 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1130 _mesa_GetTexParameteriv(target
, pname
, params
);
1135 /** New in GL 3.0 */
1137 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1139 struct gl_texture_object
*texObj
;
1140 GET_CURRENT_CONTEXT(ctx
);
1141 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1143 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1148 case GL_TEXTURE_BORDER_COLOR
:
1149 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1154 _mesa_GetTexParameteriv(target
, pname
, ip
);
1156 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1157 pname
== GL_TEXTURE_CROP_RECT_OES
) {