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 <airlied@redhat.com>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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 */
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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];
|
||||
|
Reference in New Issue
Block a user