mesa/swrast: implement EXT_texture_sRGB_decode
authorDave Airlie <airlied@gmail.com>
Thu, 13 Jan 2011 02:12:21 +0000 (12:12 +1000)
committerDave Airlie <airlied@redhat.com>
Sun, 16 Jan 2011 02:54:06 +0000 (12:54 +1000)
This implements the extension by choosing a different set of texture
fetch functions when the texture parameter changes.

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/mesa/main/extensions.c
src/mesa/main/formats.c
src/mesa/main/formats.h
src/mesa/main/mtypes.h
src/mesa/main/texfetch.c
src/mesa/main/texfetch.h
src/mesa/main/texobj.c
src/mesa/main/texparam.c

index 8ca1339c66a6c437dcbfe724f0f9b57c7f263cd6..113ac4050735dee90198cbd6712b4088fde9059b 100644 (file)
@@ -197,6 +197,7 @@ static const struct extension extension_table[] = {
    { "GL_EXT_texture_rectangle",                   o(NV_texture_rectangle),                    GL             },
    { "GL_EXT_texture_shared_exponent",             o(EXT_texture_shared_exponent),             GL             },
    { "GL_EXT_texture_sRGB",                        o(EXT_texture_sRGB),                        GL             },
+   { "GL_EXT_texture_sRGB_decode",                 o(EXT_texture_sRGB_decode),                        GL             },
    { "GL_EXT_texture_swizzle",                     o(EXT_texture_swizzle),                     GL             },
    { "GL_EXT_texture_type_2_10_10_10_REV",         o(dummy_true),                                         ES2 },
    { "GL_EXT_timer_query",                         o(EXT_timer_query),                         GL             },
@@ -488,6 +489,7 @@ _mesa_enable_sw_extensions(struct gl_context *ctx)
    ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
 #if FEATURE_EXT_texture_sRGB
    ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+   ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
 #endif
    ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
 #if FEATURE_EXT_transform_feedback
index 1bc72726e132955fd4b02db18c437e17e4f8e7f6..3ccc40b9a7957650050b8362cb474c7f5b14e392 100644 (file)
@@ -1090,6 +1090,43 @@ _mesa_get_format_color_encoding(gl_format format)
    }
 }
 
+gl_format
+_mesa_get_srgb_format_linear(gl_format format)
+{
+   switch (format) {
+   case MESA_FORMAT_SRGB8:
+      format = MESA_FORMAT_RGB888;
+      break;
+   case MESA_FORMAT_SRGBA8:
+      format = MESA_FORMAT_RGBA8888;
+      break;
+   case MESA_FORMAT_SARGB8:
+      format = MESA_FORMAT_ARGB8888;
+      break;
+   case MESA_FORMAT_SL8:
+      format = MESA_FORMAT_L8;
+      break;
+   case MESA_FORMAT_SLA8:
+      format = MESA_FORMAT_AL88;
+      break;
+   case MESA_FORMAT_SRGB_DXT1:
+      format = MESA_FORMAT_RGB_DXT1;
+      break;
+   case MESA_FORMAT_SRGBA_DXT1:
+      format = MESA_FORMAT_RGBA_DXT1;
+      break;
+   case MESA_FORMAT_SRGBA_DXT3:
+      format = MESA_FORMAT_RGBA_DXT3;
+      break;
+   case MESA_FORMAT_SRGBA_DXT5:
+      format = MESA_FORMAT_RGBA_DXT5;
+      break;
+   default:
+      break;
+   }
+   return format;
+}
+
 
 /**
  * Return number of bytes needed to store an image of the given size
index b8e76664f85f9db90001cf00f65027dc8c76efb1..d4dc5eac03e44d0349f3dba4412b5f18b9db7cbd 100644 (file)
@@ -228,4 +228,7 @@ _mesa_format_to_type_and_comps(gl_format format,
 extern void
 _mesa_test_formats(void);
 
+extern gl_format
+_mesa_get_srgb_format_linear(gl_format format);
+
 #endif /* FORMATS_H */
index 55c5fd2b84908c4ed27dd4bc5c75dcfd5ddda777..a6445b18368b241a9dd646f25f0ac0554600a655 100644 (file)
@@ -1322,6 +1322,7 @@ struct gl_texture_object
    GLboolean _Complete;                /**< Is texture object complete? */
    GLboolean _RenderToTexture;  /**< Any rendering to this texture? */
    GLboolean Purgeable;         /**< Is the buffer purgeable under memory pressure? */
+   GLenum sRGBDecode;
 
    /** Actual texture images, indexed by [cube face] and [mipmap level] */
    struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
@@ -2790,6 +2791,7 @@ struct gl_extensions
    GLboolean EXT_texture_mirror_clamp;
    GLboolean EXT_texture_shared_exponent;
    GLboolean EXT_texture_sRGB;
+   GLboolean EXT_texture_sRGB_decode;
    GLboolean EXT_texture_swizzle;
    GLboolean EXT_transform_feedback;
    GLboolean EXT_timer_query;
index 113512090b269b9523e674f0c6a923399dd80e3f..bbb0f8e8d270164ba19bc552a43b43f8de5673e2 100644 (file)
@@ -39,6 +39,7 @@
 #include "texcompress_fxt1.h"
 #include "texcompress_s3tc.h"
 #include "texfetch.h"
+#include "teximage.h"
 
 
 /**
@@ -858,12 +859,34 @@ void
 _mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
 {
    ASSERT(dims == 1 || dims == 2 || dims == 3);
+   GLuint format = texImage->TexFormat;
 
+   if (texImage->TexObject->sRGBDecode == GL_SKIP_DECODE_EXT &&
+       _mesa_get_format_color_encoding(format) == GL_SRGB) {
+      format = _mesa_get_srgb_format_linear(format);
+   }
    texImage->FetchTexelf =
-      _mesa_get_texel_fetch_func(texImage->TexFormat, dims);
+      _mesa_get_texel_fetch_func(format, dims);
 
    texImage->FetchTexelc = fetch_texel_float_to_chan;
 
    ASSERT(texImage->FetchTexelc);
    ASSERT(texImage->FetchTexelf);
 }
+
+void
+_mesa_update_fetch_functions(struct gl_texture_object *texObj)
+{
+   GLuint face, i;
+   GLuint dims;
+
+   dims = _mesa_get_texture_dimensions(texObj->Target);
+
+   for (face = 0; face < 6; face++) {
+      for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
+         if (texObj->Image[face][i]) {
+           _mesa_set_fetch_functions(texObj->Image[face][i], dims);
+         }
+      }
+   }
+}
index e78079ae5ab3e88d144a35f000f69feaaa34e379..002ff0c768c8748b3f1e337bce392d95fc20aaa5 100644 (file)
@@ -40,4 +40,6 @@ _mesa_get_texel_fetch_func(gl_format format, GLuint dims);
 extern void
 _mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims);
 
+void
+_mesa_update_fetch_functions(struct gl_texture_object *texObj);
 #endif
index f61e0237add44fd21542a8082a7d29a19cc8f8eb..5be881ec45e55c3db7407006932768526dd38536 100644 (file)
@@ -141,6 +141,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
    obj->Swizzle[2] = GL_BLUE;
    obj->Swizzle[3] = GL_ALPHA;
    obj->_Swizzle = SWIZZLE_NOOP;
+   obj->sRGBDecode = GL_DECODE_EXT;
 }
 
 
index d2b8b5ca4ad828b3bada55af65a870003d9a1819..29e409d0b8c5a0f2fef051e1522aad3f88dc7620 100644 (file)
@@ -41,6 +41,7 @@
 #include "main/texparam.h"
 #include "main/teximage.h"
 #include "main/texstate.h"
+#include "main/texfetch.h"
 #include "program/prog_instruction.h"
 
 
@@ -419,7 +420,20 @@ set_tex_parameteri(struct gl_context *ctx,
       }
       _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
       return GL_FALSE;
-
+   case GL_TEXTURE_SRGB_DECODE_EXT:
+      if (ctx->Extensions.EXT_texture_sRGB_decode) {
+        GLenum decode = params[0];
+        if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
+           if (texObj->sRGBDecode != decode) {
+              flush(ctx, texObj);
+              texObj->sRGBDecode = decode;
+              _mesa_update_fetch_functions(texObj);
+           }
+           return GL_TRUE;
+        }
+      }
+      _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
+      return GL_FALSE;
    default:
       _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
    }
@@ -543,6 +557,7 @@ _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
    case GL_TEXTURE_COMPARE_MODE_ARB:
    case GL_TEXTURE_COMPARE_FUNC_ARB:
    case GL_DEPTH_TEXTURE_MODE_ARB:
+   case GL_TEXTURE_SRGB_DECODE_EXT:
       {
          /* convert float param to int */
          GLint p[4];
@@ -591,6 +606,7 @@ _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
    case GL_TEXTURE_COMPARE_MODE_ARB:
    case GL_TEXTURE_COMPARE_FUNC_ARB:
    case GL_DEPTH_TEXTURE_MODE_ARB:
+   case GL_TEXTURE_SRGB_DECODE_EXT:
       {
          /* convert float param to int */
          GLint p[4];