summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2011-01-13 12:12:21 +1000
committerDave Airlie <[email protected]>2011-01-16 12:54:06 +1000
commitedc2dd8e4788e556d445c9f59974ed95b33c2bbc (patch)
tree414f98866a8197661563ec673806ead56de3afc7 /src/mesa/main
parentac6334145ec8eef42505cdd727aed7fae0831e12 (diff)
mesa/swrast: implement EXT_texture_sRGB_decode
This implements the extension by choosing a different set of texture fetch functions when the texture parameter changes. Signed-off-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/extensions.c2
-rw-r--r--src/mesa/main/formats.c37
-rw-r--r--src/mesa/main/formats.h3
-rw-r--r--src/mesa/main/mtypes.h2
-rw-r--r--src/mesa/main/texfetch.c25
-rw-r--r--src/mesa/main/texfetch.h2
-rw-r--r--src/mesa/main/texobj.c1
-rw-r--r--src/mesa/main/texparam.c18
8 files changed, 88 insertions, 2 deletions
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 8ca1339c66a..113ac405073 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -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
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 1bc72726e13..3ccc40b9a79 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -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
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index b8e76664f85..d4dc5eac03e 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -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 */
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 55c5fd2b849..a6445b18368 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -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;
diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c
index 113512090b2..bbb0f8e8d27 100644
--- a/src/mesa/main/texfetch.c
+++ b/src/mesa/main/texfetch.c
@@ -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);
+ }
+ }
+ }
+}
diff --git a/src/mesa/main/texfetch.h b/src/mesa/main/texfetch.h
index e78079ae5ab..002ff0c768c 100644
--- a/src/mesa/main/texfetch.h
+++ b/src/mesa/main/texfetch.h
@@ -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
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index f61e0237add..5be881ec45e 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -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;
}
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index d2b8b5ca4ad..29e409d0b8c 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -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];