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];
317 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=%s)",
318 _mesa_lookup_enum_by_nr(pname
));
322 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param=%s)",
323 _mesa_lookup_enum_by_nr(params
[0]));
329 * Set a float-valued texture parameter
330 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
333 set_tex_parameterf(struct gl_context
*ctx
,
334 struct gl_texture_object
*texObj
,
335 GLenum pname
, const GLfloat
*params
)
338 case GL_TEXTURE_MIN_LOD
:
339 if (texObj
->Sampler
.MinLod
== params
[0])
342 texObj
->Sampler
.MinLod
= params
[0];
345 case GL_TEXTURE_MAX_LOD
:
346 if (texObj
->Sampler
.MaxLod
== params
[0])
349 texObj
->Sampler
.MaxLod
= params
[0];
352 case GL_TEXTURE_PRIORITY
:
354 texObj
->Priority
= CLAMP(params
[0], 0.0F
, 1.0F
);
357 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
358 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
359 if (texObj
->Sampler
.MaxAnisotropy
== params
[0])
361 if (params
[0] < 1.0) {
362 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
366 /* clamp to max, that's what NVIDIA does */
367 texObj
->Sampler
.MaxAnisotropy
= MIN2(params
[0],
368 ctx
->Const
.MaxTextureMaxAnisotropy
);
372 static GLuint count
= 0;
374 _mesa_error(ctx
, GL_INVALID_ENUM
,
375 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
379 case GL_TEXTURE_LOD_BIAS
:
380 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
381 if (texObj
->Sampler
.LodBias
!= params
[0]) {
383 texObj
->Sampler
.LodBias
= params
[0];
388 case GL_TEXTURE_BORDER_COLOR
:
390 /* ARB_texture_float disables clamping */
391 if (ctx
->Extensions
.ARB_texture_float
) {
392 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = params
[0];
393 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = params
[1];
394 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = params
[2];
395 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = params
[3];
397 texObj
->Sampler
.BorderColor
.f
[RCOMP
] = CLAMP(params
[0], 0.0F
, 1.0F
);
398 texObj
->Sampler
.BorderColor
.f
[GCOMP
] = CLAMP(params
[1], 0.0F
, 1.0F
);
399 texObj
->Sampler
.BorderColor
.f
[BCOMP
] = CLAMP(params
[2], 0.0F
, 1.0F
);
400 texObj
->Sampler
.BorderColor
.f
[ACOMP
] = CLAMP(params
[3], 0.0F
, 1.0F
);
405 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(pname=0x%x)", pname
);
412 _mesa_TexParameterf(GLenum target
, GLenum pname
, GLfloat param
)
414 GLboolean need_update
;
415 struct gl_texture_object
*texObj
;
416 GET_CURRENT_CONTEXT(ctx
);
417 ASSERT_OUTSIDE_BEGIN_END(ctx
);
419 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
424 case GL_TEXTURE_MIN_FILTER
:
425 case GL_TEXTURE_MAG_FILTER
:
426 case GL_TEXTURE_WRAP_S
:
427 case GL_TEXTURE_WRAP_T
:
428 case GL_TEXTURE_WRAP_R
:
429 case GL_TEXTURE_BASE_LEVEL
:
430 case GL_TEXTURE_MAX_LEVEL
:
431 case GL_GENERATE_MIPMAP_SGIS
:
432 case GL_TEXTURE_COMPARE_MODE_ARB
:
433 case GL_TEXTURE_COMPARE_FUNC_ARB
:
434 case GL_DEPTH_TEXTURE_MODE_ARB
:
435 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
437 /* convert float param to int */
439 p
[0] = (GLint
) param
;
440 p
[1] = p
[2] = p
[3] = 0;
441 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
444 case GL_TEXTURE_SWIZZLE_R_EXT
:
445 case GL_TEXTURE_SWIZZLE_G_EXT
:
446 case GL_TEXTURE_SWIZZLE_B_EXT
:
447 case GL_TEXTURE_SWIZZLE_A_EXT
:
450 p
[0] = (GLint
) param
;
451 p
[1] = p
[2] = p
[3] = 0;
452 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
457 /* this will generate an error if pname is illegal */
460 p
[1] = p
[2] = p
[3] = 0.0F
;
461 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, p
);
465 if (ctx
->Driver
.TexParameter
&& need_update
) {
466 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, ¶m
);
472 _mesa_TexParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
474 GLboolean need_update
;
475 struct gl_texture_object
*texObj
;
476 GET_CURRENT_CONTEXT(ctx
);
477 ASSERT_OUTSIDE_BEGIN_END(ctx
);
479 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
484 case GL_TEXTURE_MIN_FILTER
:
485 case GL_TEXTURE_MAG_FILTER
:
486 case GL_TEXTURE_WRAP_S
:
487 case GL_TEXTURE_WRAP_T
:
488 case GL_TEXTURE_WRAP_R
:
489 case GL_TEXTURE_BASE_LEVEL
:
490 case GL_TEXTURE_MAX_LEVEL
:
491 case GL_GENERATE_MIPMAP_SGIS
:
492 case GL_TEXTURE_COMPARE_MODE_ARB
:
493 case GL_TEXTURE_COMPARE_FUNC_ARB
:
494 case GL_DEPTH_TEXTURE_MODE_ARB
:
495 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
497 /* convert float param to int */
499 p
[0] = (GLint
) params
[0];
500 p
[1] = p
[2] = p
[3] = 0;
501 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
505 #if FEATURE_OES_draw_texture
506 case GL_TEXTURE_CROP_RECT_OES
:
508 /* convert float params to int */
510 iparams
[0] = (GLint
) params
[0];
511 iparams
[1] = (GLint
) params
[1];
512 iparams
[2] = (GLint
) params
[2];
513 iparams
[3] = (GLint
) params
[3];
514 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparams
);
519 case GL_TEXTURE_SWIZZLE_R_EXT
:
520 case GL_TEXTURE_SWIZZLE_G_EXT
:
521 case GL_TEXTURE_SWIZZLE_B_EXT
:
522 case GL_TEXTURE_SWIZZLE_A_EXT
:
523 case GL_TEXTURE_SWIZZLE_RGBA_EXT
:
525 GLint p
[4] = {0, 0, 0, 0};
526 p
[0] = (GLint
) params
[0];
527 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
) {
528 p
[1] = (GLint
) params
[1];
529 p
[2] = (GLint
) params
[2];
530 p
[3] = (GLint
) params
[3];
532 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, p
);
536 /* this will generate an error if pname is illegal */
537 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, params
);
540 if (ctx
->Driver
.TexParameter
&& need_update
) {
541 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, params
);
547 _mesa_TexParameteri(GLenum target
, GLenum pname
, GLint param
)
549 GLboolean need_update
;
550 struct gl_texture_object
*texObj
;
551 GET_CURRENT_CONTEXT(ctx
);
552 ASSERT_OUTSIDE_BEGIN_END(ctx
);
554 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
559 case GL_TEXTURE_MIN_LOD
:
560 case GL_TEXTURE_MAX_LOD
:
561 case GL_TEXTURE_PRIORITY
:
562 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
563 case GL_TEXTURE_LOD_BIAS
:
564 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
567 fparam
[0] = (GLfloat
) param
;
568 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
569 /* convert int param to float */
570 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparam
);
574 /* this will generate an error if pname is illegal */
578 iparam
[1] = iparam
[2] = iparam
[3] = 0;
579 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, iparam
);
583 if (ctx
->Driver
.TexParameter
&& need_update
) {
584 GLfloat fparam
= (GLfloat
) param
;
585 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, &fparam
);
591 _mesa_TexParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
593 GLboolean need_update
;
594 struct gl_texture_object
*texObj
;
595 GET_CURRENT_CONTEXT(ctx
);
596 ASSERT_OUTSIDE_BEGIN_END(ctx
);
598 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
603 case GL_TEXTURE_BORDER_COLOR
:
605 /* convert int params to float */
607 fparams
[0] = INT_TO_FLOAT(params
[0]);
608 fparams
[1] = INT_TO_FLOAT(params
[1]);
609 fparams
[2] = INT_TO_FLOAT(params
[2]);
610 fparams
[3] = INT_TO_FLOAT(params
[3]);
611 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
614 case GL_TEXTURE_MIN_LOD
:
615 case GL_TEXTURE_MAX_LOD
:
616 case GL_TEXTURE_PRIORITY
:
617 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
618 case GL_TEXTURE_LOD_BIAS
:
619 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
:
621 /* convert int param to float */
623 fparams
[0] = (GLfloat
) params
[0];
624 fparams
[1] = fparams
[2] = fparams
[3] = 0.0F
;
625 need_update
= set_tex_parameterf(ctx
, texObj
, pname
, fparams
);
629 /* this will generate an error if pname is illegal */
630 need_update
= set_tex_parameteri(ctx
, texObj
, pname
, params
);
633 if (ctx
->Driver
.TexParameter
&& need_update
) {
635 fparams
[0] = INT_TO_FLOAT(params
[0]);
636 if (pname
== GL_TEXTURE_BORDER_COLOR
||
637 pname
== GL_TEXTURE_CROP_RECT_OES
) {
638 fparams
[1] = INT_TO_FLOAT(params
[1]);
639 fparams
[2] = INT_TO_FLOAT(params
[2]);
640 fparams
[3] = INT_TO_FLOAT(params
[3]);
642 ctx
->Driver
.TexParameter(ctx
, target
, texObj
, pname
, fparams
);
648 * Set tex parameter to integer value(s). Primarily intended to set
649 * integer-valued texture border color (for integer-valued textures).
653 _mesa_TexParameterIiv(GLenum target
, GLenum pname
, const GLint
*params
)
655 struct gl_texture_object
*texObj
;
656 GET_CURRENT_CONTEXT(ctx
);
657 ASSERT_OUTSIDE_BEGIN_END(ctx
);
659 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
664 case GL_TEXTURE_BORDER_COLOR
:
665 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
666 /* set the integer-valued border color */
667 COPY_4V(texObj
->Sampler
.BorderColor
.i
, params
);
670 _mesa_TexParameteriv(target
, pname
, params
);
673 /* XXX no driver hook for TexParameterIiv() yet */
678 * Set tex parameter to unsigned integer value(s). Primarily intended to set
679 * uint-valued texture border color (for integer-valued textures).
683 _mesa_TexParameterIuiv(GLenum target
, GLenum pname
, const GLuint
*params
)
685 struct gl_texture_object
*texObj
;
686 GET_CURRENT_CONTEXT(ctx
);
687 ASSERT_OUTSIDE_BEGIN_END(ctx
);
689 texObj
= get_texobj(ctx
, target
, GL_FALSE
);
694 case GL_TEXTURE_BORDER_COLOR
:
695 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
696 /* set the unsigned integer-valued border color */
697 COPY_4V(texObj
->Sampler
.BorderColor
.ui
, params
);
700 _mesa_TexParameteriv(target
, pname
, (const GLint
*) params
);
703 /* XXX no driver hook for TexParameterIuiv() yet */
708 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
709 GLenum pname
, GLfloat
*params
)
712 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
713 *params
= (GLfloat
) iparam
;
718 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
719 GLenum pname
, GLint
*params
)
721 const struct gl_texture_unit
*texUnit
;
722 struct gl_texture_object
*texObj
;
723 const struct gl_texture_image
*img
= NULL
;
726 GET_CURRENT_CONTEXT(ctx
);
727 ASSERT_OUTSIDE_BEGIN_END(ctx
);
729 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
730 _mesa_error(ctx
, GL_INVALID_OPERATION
,
731 "glGetTexLevelParameteriv(current unit)");
735 texUnit
= _mesa_get_current_tex_unit(ctx
);
737 /* this will catch bad target values */
738 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
739 if (maxLevels
== 0) {
740 _mesa_error(ctx
, GL_INVALID_ENUM
,
741 "glGetTexLevelParameter[if]v(target=0x%x)", target
);
745 if (level
< 0 || level
>= maxLevels
) {
746 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
750 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
752 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
753 if (!img
|| img
->TexFormat
== MESA_FORMAT_NONE
) {
754 /* undefined texture image */
755 if (pname
== GL_TEXTURE_COMPONENTS
)
762 texFormat
= img
->TexFormat
;
765 case GL_TEXTURE_WIDTH
:
766 *params
= img
->Width
;
768 case GL_TEXTURE_HEIGHT
:
769 *params
= img
->Height
;
771 case GL_TEXTURE_DEPTH
:
772 *params
= img
->Depth
;
774 case GL_TEXTURE_INTERNAL_FORMAT
:
775 if (_mesa_is_format_compressed(texFormat
)) {
776 /* need to return the actual compressed format */
777 *params
= _mesa_compressed_format_to_glenum(ctx
, texFormat
);
780 /* If the true internal format is not compressed but the user
781 * requested a generic compressed format, we have to return the
782 * generic base format that matches.
784 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
786 * "If no specific compressed format is available,
787 * internalformat is instead replaced by the corresponding base
790 * Otherwise just return the user's requested internal format
793 _mesa_gl_compressed_format_base_format(img
->InternalFormat
);
795 *params
= (f
!= 0) ? f
: img
->InternalFormat
;
798 case GL_TEXTURE_BORDER
:
799 *params
= img
->Border
;
801 case GL_TEXTURE_RED_SIZE
:
802 case GL_TEXTURE_GREEN_SIZE
:
803 case GL_TEXTURE_BLUE_SIZE
:
804 case GL_TEXTURE_ALPHA_SIZE
:
805 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
806 *params
= _mesa_get_format_bits(texFormat
, pname
);
810 case GL_TEXTURE_INTENSITY_SIZE
:
811 case GL_TEXTURE_LUMINANCE_SIZE
:
812 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
)) {
813 *params
= _mesa_get_format_bits(texFormat
, pname
);
815 /* intensity or luminance is probably stored as RGB[A] */
816 *params
= MIN2(_mesa_get_format_bits(texFormat
,
817 GL_TEXTURE_RED_SIZE
),
818 _mesa_get_format_bits(texFormat
,
819 GL_TEXTURE_GREEN_SIZE
));
826 case GL_TEXTURE_STENCIL_SIZE_EXT
:
827 if (!ctx
->Extensions
.EXT_packed_depth_stencil
&&
828 !ctx
->Extensions
.ARB_framebuffer_object
)
830 *params
= _mesa_get_format_bits(texFormat
, pname
);
833 /* GL_ARB_texture_compression */
834 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
835 if (_mesa_is_format_compressed(texFormat
) &&
836 !_mesa_is_proxy_texture(target
)) {
837 *params
= _mesa_format_image_size(texFormat
, img
->Width
,
838 img
->Height
, img
->Depth
);
841 _mesa_error(ctx
, GL_INVALID_OPERATION
,
842 "glGetTexLevelParameter[if]v(pname)");
845 case GL_TEXTURE_COMPRESSED
:
846 *params
= (GLint
) _mesa_is_format_compressed(texFormat
);
849 /* GL_ARB_texture_float */
850 case GL_TEXTURE_RED_TYPE_ARB
:
851 case GL_TEXTURE_GREEN_TYPE_ARB
:
852 case GL_TEXTURE_BLUE_TYPE_ARB
:
853 case GL_TEXTURE_ALPHA_TYPE_ARB
:
854 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
855 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
856 case GL_TEXTURE_DEPTH_TYPE_ARB
:
857 if (!ctx
->Extensions
.ARB_texture_float
)
859 if (_mesa_base_format_has_channel(img
->_BaseFormat
, pname
))
860 *params
= _mesa_get_format_datatype(texFormat
);
869 /* no error if we get here */
873 _mesa_error(ctx
, GL_INVALID_ENUM
,
874 "glGetTexLevelParameter[if]v(pname=%s)",
875 _mesa_lookup_enum_by_nr(pname
));
881 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
883 struct gl_texture_object
*obj
;
884 GET_CURRENT_CONTEXT(ctx
);
885 ASSERT_OUTSIDE_BEGIN_END(ctx
);
887 obj
= get_texobj(ctx
, target
, GL_TRUE
);
891 _mesa_lock_texture(ctx
, obj
);
893 case GL_TEXTURE_MAG_FILTER
:
894 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MagFilter
);
896 case GL_TEXTURE_MIN_FILTER
:
897 *params
= ENUM_TO_FLOAT(obj
->Sampler
.MinFilter
);
899 case GL_TEXTURE_WRAP_S
:
900 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapS
);
902 case GL_TEXTURE_WRAP_T
:
903 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapT
);
905 case GL_TEXTURE_WRAP_R
:
906 *params
= ENUM_TO_FLOAT(obj
->Sampler
.WrapR
);
908 case GL_TEXTURE_BORDER_COLOR
:
909 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
910 _mesa_update_state_locked(ctx
);
911 if (ctx
->Color
._ClampFragmentColor
) {
912 params
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
913 params
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
914 params
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
915 params
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
918 params
[0] = obj
->Sampler
.BorderColor
.f
[0];
919 params
[1] = obj
->Sampler
.BorderColor
.f
[1];
920 params
[2] = obj
->Sampler
.BorderColor
.f
[2];
921 params
[3] = obj
->Sampler
.BorderColor
.f
[3];
924 case GL_TEXTURE_RESIDENT
:
927 case GL_TEXTURE_PRIORITY
:
928 *params
= obj
->Priority
;
930 case GL_TEXTURE_MIN_LOD
:
931 *params
= obj
->Sampler
.MinLod
;
933 case GL_TEXTURE_MAX_LOD
:
934 *params
= obj
->Sampler
.MaxLod
;
936 case GL_TEXTURE_BASE_LEVEL
:
937 *params
= (GLfloat
) obj
->BaseLevel
;
939 case GL_TEXTURE_MAX_LEVEL
:
940 *params
= (GLfloat
) obj
->MaxLevel
;
942 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
943 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
945 *params
= obj
->Sampler
.MaxAnisotropy
;
947 case GL_GENERATE_MIPMAP_SGIS
:
948 *params
= (GLfloat
) obj
->GenerateMipmap
;
950 case GL_TEXTURE_LOD_BIAS
:
951 *params
= obj
->Sampler
.LodBias
;
953 #if FEATURE_OES_draw_texture
954 case GL_TEXTURE_CROP_RECT_OES
:
955 params
[0] = obj
->CropRect
[0];
956 params
[1] = obj
->CropRect
[1];
957 params
[2] = obj
->CropRect
[2];
958 params
[3] = obj
->CropRect
[3];
962 case GL_TEXTURE_IMMUTABLE_FORMAT
:
963 if (!ctx
->Extensions
.ARB_texture_storage
)
965 *params
= (GLfloat
) obj
->Immutable
;
972 /* no error if we get here */
973 _mesa_unlock_texture(ctx
, obj
);
977 _mesa_unlock_texture(ctx
, obj
);
978 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)", pname
);
983 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
985 struct gl_texture_object
*obj
;
986 GET_CURRENT_CONTEXT(ctx
);
987 ASSERT_OUTSIDE_BEGIN_END(ctx
);
989 obj
= get_texobj(ctx
, target
, GL_TRUE
);
993 _mesa_lock_texture(ctx
, obj
);
995 case GL_TEXTURE_MAG_FILTER
:
996 *params
= (GLint
) obj
->Sampler
.MagFilter
;
998 case GL_TEXTURE_MIN_FILTER
:
999 *params
= (GLint
) obj
->Sampler
.MinFilter
;
1001 case GL_TEXTURE_WRAP_S
:
1002 *params
= (GLint
) obj
->Sampler
.WrapS
;
1004 case GL_TEXTURE_WRAP_T
:
1005 *params
= (GLint
) obj
->Sampler
.WrapT
;
1007 case GL_TEXTURE_WRAP_R
:
1008 *params
= (GLint
) obj
->Sampler
.WrapR
;
1010 case GL_TEXTURE_BORDER_COLOR
:
1013 b
[0] = CLAMP(obj
->Sampler
.BorderColor
.f
[0], 0.0F
, 1.0F
);
1014 b
[1] = CLAMP(obj
->Sampler
.BorderColor
.f
[1], 0.0F
, 1.0F
);
1015 b
[2] = CLAMP(obj
->Sampler
.BorderColor
.f
[2], 0.0F
, 1.0F
);
1016 b
[3] = CLAMP(obj
->Sampler
.BorderColor
.f
[3], 0.0F
, 1.0F
);
1017 params
[0] = FLOAT_TO_INT(b
[0]);
1018 params
[1] = FLOAT_TO_INT(b
[1]);
1019 params
[2] = FLOAT_TO_INT(b
[2]);
1020 params
[3] = FLOAT_TO_INT(b
[3]);
1023 case GL_TEXTURE_RESIDENT
:
1026 case GL_TEXTURE_PRIORITY
:
1027 *params
= FLOAT_TO_INT(obj
->Priority
);
1029 case GL_TEXTURE_MIN_LOD
:
1030 *params
= (GLint
) obj
->Sampler
.MinLod
;
1032 case GL_TEXTURE_MAX_LOD
:
1033 *params
= (GLint
) obj
->Sampler
.MaxLod
;
1035 case GL_TEXTURE_BASE_LEVEL
:
1036 *params
= obj
->BaseLevel
;
1038 case GL_TEXTURE_MAX_LEVEL
:
1039 *params
= obj
->MaxLevel
;
1041 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1042 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
1044 *params
= (GLint
) obj
->Sampler
.MaxAnisotropy
;
1046 case GL_GENERATE_MIPMAP_SGIS
:
1047 *params
= (GLint
) obj
->GenerateMipmap
;
1049 case GL_TEXTURE_LOD_BIAS
:
1050 *params
= (GLint
) obj
->Sampler
.LodBias
;
1052 #if FEATURE_OES_draw_texture
1053 case GL_TEXTURE_CROP_RECT_OES
:
1054 params
[0] = obj
->CropRect
[0];
1055 params
[1] = obj
->CropRect
[1];
1056 params
[2] = obj
->CropRect
[2];
1057 params
[3] = obj
->CropRect
[3];
1061 case GL_TEXTURE_IMMUTABLE_FORMAT
:
1062 if (!ctx
->Extensions
.ARB_texture_storage
)
1064 *params
= (GLint
) obj
->Immutable
;
1067 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
:
1068 if (!ctx
->Extensions
.OES_EGL_image_external
)
1070 *params
= obj
->RequiredTextureImageUnits
;
1077 /* no error if we get here */
1078 _mesa_unlock_texture(ctx
, obj
);
1082 _mesa_unlock_texture(ctx
, obj
);
1083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
1087 /** New in GL 3.0 */
1089 _mesa_GetTexParameterIiv(GLenum target
, GLenum pname
, GLint
*params
)
1091 struct gl_texture_object
*texObj
;
1092 GET_CURRENT_CONTEXT(ctx
);
1093 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1095 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1100 case GL_TEXTURE_BORDER_COLOR
:
1101 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1104 _mesa_GetTexParameteriv(target
, pname
, params
);
1109 /** New in GL 3.0 */
1111 _mesa_GetTexParameterIuiv(GLenum target
, GLenum pname
, GLuint
*params
)
1113 struct gl_texture_object
*texObj
;
1114 GET_CURRENT_CONTEXT(ctx
);
1115 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1117 texObj
= get_texobj(ctx
, target
, GL_TRUE
);
1122 case GL_TEXTURE_BORDER_COLOR
:
1123 COPY_4V(params
, texObj
->Sampler
.BorderColor
.i
);
1128 _mesa_GetTexParameteriv(target
, pname
, ip
);
1130 if (pname
== GL_TEXTURE_SWIZZLE_RGBA_EXT
||
1131 pname
== GL_TEXTURE_CROP_RECT_OES
) {