/** * Check if the call to _mesa_meta_GenerateMipmap() will require a * software fallback. The fallback path will require that the texture * images are mapped. * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise */ static bool fallback_required(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj) { struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap; struct gl_texture_image *baseImage; GLuint srcLevel; GLenum status; /* check for fallbacks */ if (target == GL_TEXTURE_3D) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() to %s target\n", _mesa_enum_to_string(target)); return true; } srcLevel = texObj->BaseLevel; baseImage = _mesa_select_tex_image(texObj, target, srcLevel); if (!baseImage) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() couldn't find base teximage\n"); return true; } if (_mesa_is_format_compressed(baseImage->TexFormat)) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() with %s format\n", _mesa_get_format_name(baseImage->TexFormat)); return true; } if (_mesa_get_format_color_encoding(baseImage->TexFormat) == GL_SRGB && !ctx->Extensions.EXT_texture_sRGB_decode) { /* The texture format is sRGB but we can't turn off sRGB->linear * texture sample conversion. So we won't be able to generate the * right colors when rendering. Need to use a fallback. */ _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() of sRGB texture without " "sRGB decode\n"); return true; } /* * Test that we can actually render in the texture's format. */ if (mipmap->fb == NULL) { mipmap->fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF); if (mipmap->fb == NULL) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() ran out of memory\n"); return true; } } _mesa_meta_framebuffer_texture_image(ctx, mipmap->fb, GL_COLOR_ATTACHMENT0, baseImage, 0); status = _mesa_check_framebuffer_status(ctx, mipmap->fb); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() got incomplete FBO\n"); return true; } return false; }
/** * Check if the call to _mesa_meta_GenerateMipmap() will require a * software fallback. The fallback path will require that the texture * images are mapped. * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise */ static bool fallback_required(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj) { const GLuint fboSave = ctx->DrawBuffer->Name; struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap; struct gl_texture_image *baseImage; GLuint srcLevel; GLenum status; /* check for fallbacks */ // if (target == GL_TEXTURE_3D) { // _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, // "glGenerateMipmap() to %s target\n", // _mesa_lookup_enum_by_nr(target)); // return true; // } srcLevel = texObj->BaseLevel; baseImage = _mesa_select_tex_image(texObj, target, srcLevel); if (!baseImage) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() couldn't find base teximage\n"); return true; } if (_mesa_is_format_compressed(baseImage->TexFormat)) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() with %s format\n", _mesa_get_format_name(baseImage->TexFormat)); return true; } if (_mesa_get_format_color_encoding(baseImage->TexFormat) == GL_SRGB && !ctx->Extensions.EXT_texture_sRGB_decode) { /* The texture format is sRGB but we can't turn off sRGB->linear * texture sample conversion. So we won't be able to generate the * right colors when rendering. Need to use a fallback. */ _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() of sRGB texture without " "sRGB decode\n"); return true; } /* * Test that we can actually render in the texture's format. */ if (!mipmap->FBO) glGenFramebuffers(1, &mipmap->FBO); glBindFramebuffer(GL_FRAMEBUFFER, mipmap->FBO); _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, baseImage, 0); status = glCheckFramebufferStatus(GL_FRAMEBUFFER); glBindFramebuffer(GL_FRAMEBUFFER, fboSave); if (status != GL_FRAMEBUFFER_COMPLETE) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() got incomplete FBO\n"); return true; } return false; }
/** * Check if the call to _mesa_meta_GenerateMipmap() will require a * software fallback. The fallback path will require that the texture * images are mapped. * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise */ static bool fallback_required(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj) { const GLuint fboSave = ctx->DrawBuffer->Name; struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap; struct gl_texture_image *baseImage; GLuint srcLevel; GLenum status; /* GL_DRAW_FRAMEBUFFER does not exist in OpenGL ES 1.x, and since * _mesa_meta_begin hasn't been called yet, we have to work-around API * difficulties. The whole reason that GL_DRAW_FRAMEBUFFER is used instead * of GL_FRAMEBUFFER is that the read framebuffer may be different. This * is moot in OpenGL ES 1.x. */ const GLenum fbo_target = ctx->API == API_OPENGLES ? GL_FRAMEBUFFER : GL_DRAW_FRAMEBUFFER; /* check for fallbacks */ if (target == GL_TEXTURE_3D) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() to %s target\n", _mesa_enum_to_string(target)); return true; } srcLevel = texObj->BaseLevel; baseImage = _mesa_select_tex_image(texObj, target, srcLevel); if (!baseImage) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() couldn't find base teximage\n"); return true; } if (_mesa_is_format_compressed(baseImage->TexFormat)) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() with %s format\n", _mesa_get_format_name(baseImage->TexFormat)); return true; } if (_mesa_get_format_color_encoding(baseImage->TexFormat) == GL_SRGB && !ctx->Extensions.EXT_texture_sRGB_decode) { /* The texture format is sRGB but we can't turn off sRGB->linear * texture sample conversion. So we won't be able to generate the * right colors when rendering. Need to use a fallback. */ _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() of sRGB texture without " "sRGB decode\n"); return true; } /* * Test that we can actually render in the texture's format. */ if (!mipmap->FBO) _mesa_GenFramebuffers(1, &mipmap->FBO); _mesa_BindFramebuffer(fbo_target, mipmap->FBO); _mesa_meta_bind_fbo_image(fbo_target, GL_COLOR_ATTACHMENT0, baseImage, 0); status = _mesa_CheckFramebufferStatus(fbo_target); _mesa_BindFramebuffer(fbo_target, fboSave); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() got incomplete FBO\n"); return true; } return false; }