2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2013 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * glGenerateMipmap function
33 #include "genmipmap.h"
34 #include "glformats.h"
42 _mesa_is_valid_generate_texture_mipmap_target(struct gl_context
*ctx
,
49 error
= _mesa_is_gles(ctx
);
55 error
= ctx
->API
== API_OPENGLES
;
57 case GL_TEXTURE_CUBE_MAP
:
58 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
60 case GL_TEXTURE_1D_ARRAY
:
61 error
= _mesa_is_gles(ctx
) || !ctx
->Extensions
.EXT_texture_array
;
63 case GL_TEXTURE_2D_ARRAY
:
64 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
65 || !ctx
->Extensions
.EXT_texture_array
;
67 case GL_TEXTURE_CUBE_MAP_ARRAY
:
68 error
= _mesa_is_gles(ctx
) ||
69 !ctx
->Extensions
.ARB_texture_cube_map_array
;
75 return (error
!= GL_TRUE
);
79 _mesa_is_valid_generate_texture_mipmap_internalformat(struct gl_context
*ctx
,
80 GLenum internalformat
)
82 return (!_mesa_is_enum_format_integer(internalformat
) &&
83 !_mesa_is_depthstencil_format(internalformat
) &&
84 !_mesa_is_astc_format(internalformat
) &&
85 !_mesa_is_stencil_format(internalformat
));
89 * Implements glGenerateMipmap and glGenerateTextureMipmap.
90 * Generates all the mipmap levels below the base level.
93 _mesa_generate_texture_mipmap(struct gl_context
*ctx
,
94 struct gl_texture_object
*texObj
, GLenum target
,
97 struct gl_texture_image
*srcImage
;
98 const char *suffix
= dsa
? "Texture" : "";
100 FLUSH_VERTICES(ctx
, 0);
102 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
107 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
108 !_mesa_cube_complete(texObj
)) {
109 _mesa_error(ctx
, GL_INVALID_OPERATION
,
110 "glGenerate%sMipmap(incomplete cube map)", suffix
);
114 _mesa_lock_texture(ctx
, texObj
);
116 srcImage
= _mesa_select_tex_image(texObj
, target
, texObj
->BaseLevel
);
118 _mesa_unlock_texture(ctx
, texObj
);
119 _mesa_error(ctx
, GL_INVALID_OPERATION
,
120 "glGenerate%sMipmap(zero size base image)", suffix
);
124 if (!_mesa_is_valid_generate_texture_mipmap_internalformat(ctx
,
125 srcImage
->InternalFormat
)) {
126 _mesa_unlock_texture(ctx
, texObj
);
127 _mesa_error(ctx
, GL_INVALID_OPERATION
,
128 "glGenerate%sMipmap(invalid internal format)", suffix
);
132 if (target
== GL_TEXTURE_CUBE_MAP
) {
134 for (face
= 0; face
< 6; face
++) {
135 ctx
->Driver
.GenerateMipmap(ctx
,
136 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
, texObj
);
140 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
142 _mesa_unlock_texture(ctx
, texObj
);
146 * Generate all the mipmap levels below the base level.
147 * Note: this GL function would be more useful if one could specify a
148 * cube face, a set of array slices, etc.
151 _mesa_GenerateMipmap(GLenum target
)
153 struct gl_texture_object
*texObj
;
154 GET_CURRENT_CONTEXT(ctx
);
156 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx
, target
)) {
157 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmap(target=%s)",
158 _mesa_enum_to_string(target
));
162 texObj
= _mesa_get_current_tex_object(ctx
, target
);
166 _mesa_generate_texture_mipmap(ctx
, texObj
, target
, false);
170 * Generate all the mipmap levels below the base level.
173 _mesa_GenerateTextureMipmap(GLuint texture
)
175 struct gl_texture_object
*texObj
;
176 GET_CURRENT_CONTEXT(ctx
);
178 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glGenerateTextureMipmap");
182 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx
, texObj
->Target
)) {
183 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateTextureMipmap(target=%s)",
184 _mesa_enum_to_string(texObj
->Target
));
188 _mesa_generate_texture_mipmap(ctx
, texObj
, texObj
->Target
, true);