summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2011-09-17 11:26:54 -0600
committerBrian Paul <[email protected]>2011-09-20 20:17:42 -0600
commit1e939f53749781312b1b3b729e2d73493ae6b304 (patch)
tree9719833f4da5f66a750bbd7d284877ed74bec8c7 /src
parent4731a598f00c8a229df7b36d9a2a7505b679de1d (diff)
meta: fix broken sRGB mipmap generation
If we're generating a mipmap for an sRGB texture we need to bypass sRGB->linear conversion. Otherwise the destination mipmap level (drawn with a textured quad) will have the wrong colors. If we can't turn of sRGB->linear conversion (GL_EXT_texture_sRGB_decode) we need to use the software fallback for mipmap generation. Note: This is a candidate for the 7.11 branch.
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/common/meta.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 1b71aa19445..82b072eeb8c 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -2452,6 +2452,15 @@ _mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target,
return GL_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.
+ */
+ return GL_TRUE;
+ }
+
/*
* Test that we can actually render in the texture's format.
*/
@@ -2669,6 +2678,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
const GLenum wrapSSave = texObj->Sampler.WrapS;
const GLenum wrapTSave = texObj->Sampler.WrapT;
const GLenum wrapRSave = texObj->Sampler.WrapR;
+ const GLenum srgbDecodeSave = texObj->Sampler.sRGBDecode;
+ const GLenum srgbBufferSave = ctx->Color.sRGBEnabled;
const GLuint fboSave = ctx->DrawBuffer->Name;
const GLuint original_active_unit = ctx->Texture.CurrentUnit;
GLenum faceTarget;
@@ -2731,6 +2742,15 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
_mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
_mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ /* We don't want to encode or decode sRGB values; treat them as linear */
+ if (ctx->Extensions.EXT_texture_sRGB_decode) {
+ _mesa_TexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
+ GL_SKIP_DECODE_EXT);
+ }
+ if (ctx->Extensions.EXT_framebuffer_sRGB) {
+ _mesa_Disable(GL_FRAMEBUFFER_SRGB_EXT);
+ }
+
_mesa_set_enable(ctx, target, GL_TRUE);
/* setup texcoords (XXX what about border?) */
@@ -2875,6 +2895,14 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
_mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
+ if (ctx->Extensions.EXT_texture_sRGB_decode) {
+ _mesa_TexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
+ srgbDecodeSave);
+ }
+ if (ctx->Extensions.EXT_framebuffer_sRGB && srgbBufferSave) {
+ _mesa_Enable(GL_FRAMEBUFFER_SRGB_EXT);
+ }
+
_mesa_lock_texture(ctx, texObj); /* relock */
_mesa_meta_end(ctx);