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;
79 _mesa_is_valid_generate_texture_mipmap_internalformat(struct gl_context *ctx,
80 GLenum internalformat)
82 if (_mesa_is_gles3(ctx)) {
83 /* From the ES 3.2 specification's description of GenerateMipmap():
84 * "An INVALID_OPERATION error is generated if the levelbase array was
85 * not specified with an unsized internal format from table 8.3 or a
86 * sized internal format that is both color-renderable and
87 * texture-filterable according to table 8.10."
89 * GL_EXT_texture_format_BGRA8888 adds a GL_BGRA_EXT unsized internal
90 * format, and includes it in a very similar looking table. So we
91 * include it here as well.
93 return internalformat == GL_RGBA || internalformat == GL_RGB ||
94 internalformat == GL_LUMINANCE_ALPHA ||
95 internalformat == GL_LUMINANCE || internalformat == GL_ALPHA ||
96 internalformat == GL_BGRA_EXT ||
97 (_mesa_is_es3_color_renderable(internalformat) &&
98 _mesa_is_es3_texture_filterable(internalformat));
101 return (!_mesa_is_enum_format_integer(internalformat) &&
102 !_mesa_is_depthstencil_format(internalformat) &&
103 !_mesa_is_astc_format(internalformat) &&
104 !_mesa_is_stencil_format(internalformat));
108 * Implements glGenerateMipmap and glGenerateTextureMipmap.
109 * Generates all the mipmap levels below the base level.
112 _mesa_generate_texture_mipmap(struct gl_context *ctx,
113 struct gl_texture_object *texObj, GLenum target,
116 struct gl_texture_image *srcImage;
117 const char *suffix = dsa ? "Texture" : "";
119 FLUSH_VERTICES(ctx, 0);
121 if (texObj->BaseLevel >= texObj->MaxLevel) {
126 if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
127 !_mesa_cube_complete(texObj)) {
128 _mesa_error(ctx, GL_INVALID_OPERATION,
129 "glGenerate%sMipmap(incomplete cube map)", suffix);
133 _mesa_lock_texture(ctx, texObj);
135 srcImage = _mesa_select_tex_image(texObj, target, texObj->BaseLevel);
137 _mesa_unlock_texture(ctx, texObj);
138 _mesa_error(ctx, GL_INVALID_OPERATION,
139 "glGenerate%sMipmap(zero size base image)", suffix);
143 if (!_mesa_is_valid_generate_texture_mipmap_internalformat(ctx,
144 srcImage->InternalFormat)) {
145 _mesa_unlock_texture(ctx, texObj);
146 _mesa_error(ctx, GL_INVALID_OPERATION,
147 "glGenerate%sMipmap(invalid internal format %s)", suffix,
148 _mesa_enum_to_string(srcImage->InternalFormat));
152 if (srcImage->Width == 0 || srcImage->Height == 0) {
153 _mesa_unlock_texture(ctx, texObj);
157 if (target == GL_TEXTURE_CUBE_MAP) {
159 for (face = 0; face < 6; face++) {
160 ctx->Driver.GenerateMipmap(ctx,
161 GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texObj);
165 ctx->Driver.GenerateMipmap(ctx, target, texObj);
167 _mesa_unlock_texture(ctx, texObj);
171 * Generate all the mipmap levels below the base level.
172 * Note: this GL function would be more useful if one could specify a
173 * cube face, a set of array slices, etc.
176 _mesa_GenerateMipmap(GLenum target)
178 struct gl_texture_object *texObj;
179 GET_CURRENT_CONTEXT(ctx);
181 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, target)) {
182 _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmap(target=%s)",
183 _mesa_enum_to_string(target));
187 texObj = _mesa_get_current_tex_object(ctx, target);
191 _mesa_generate_texture_mipmap(ctx, texObj, target, false);
195 * Generate all the mipmap levels below the base level.
198 _mesa_GenerateTextureMipmap(GLuint texture)
200 struct gl_texture_object *texObj;
201 GET_CURRENT_CONTEXT(ctx);
203 texObj = _mesa_lookup_texture_err(ctx, texture, "glGenerateTextureMipmap");
207 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, texObj->Target)) {
208 _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateTextureMipmap(target=%s)",
209 _mesa_enum_to_string(texObj->Target));
213 _mesa_generate_texture_mipmap(ctx, texObj, texObj->Target, true);