From e961a5da77cbcdb0e32400ec707c16fcfe9d7083 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 12 Jun 2008 16:55:28 -0600 Subject: mesa: add some #if FEATURE_x tests --- src/mesa/main/texcompress.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/mesa/main/texcompress.c') diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index c44d594d68..5ad936419b 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -137,8 +137,10 @@ _mesa_compressed_texture_size( GLcontext *ctx, ASSERT(depth == 1); (void) depth; + (void) size; switch (mesaFormat) { +#if FEATURE_texture_fxt1 case MESA_FORMAT_RGB_FXT1: case MESA_FORMAT_RGBA_FXT1: /* round up width to next multiple of 8, height to next multiple of 4 */ @@ -152,6 +154,8 @@ _mesa_compressed_texture_size( GLcontext *ctx, if (size < 16) size = 16; return size; +#endif +#if FEATURE_texture_s3tc case MESA_FORMAT_RGB_DXT1: case MESA_FORMAT_RGBA_DXT1: /* round up width, height to next multiple of 4 */ @@ -178,6 +182,7 @@ _mesa_compressed_texture_size( GLcontext *ctx, if (size < 16) size = 16; return size; +#endif default: _mesa_problem(ctx, "bad mesaFormat in _mesa_compressed_texture_size"); return 0; @@ -202,12 +207,15 @@ _mesa_compressed_texture_size_glenum(GLcontext *ctx, GLuint mesaFormat; switch (glformat) { +#if FEATURE_texture_fxt1 case GL_COMPRESSED_RGB_FXT1_3DFX: mesaFormat = MESA_FORMAT_RGB_FXT1; break; case GL_COMPRESSED_RGBA_FXT1_3DFX: mesaFormat = MESA_FORMAT_RGBA_FXT1; break; +#endif +#if FEATURE_texture_s3tc case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_RGB_S3TC: mesaFormat = MESA_FORMAT_RGB_DXT1; @@ -224,6 +232,7 @@ _mesa_compressed_texture_size_glenum(GLcontext *ctx, case GL_RGBA4_S3TC: mesaFormat = MESA_FORMAT_RGBA_DXT5; break; +#endif default: return 0; } @@ -245,10 +254,13 @@ _mesa_compressed_row_stride(GLuint mesaFormat, GLsizei width) GLint stride; switch (mesaFormat) { +#if FEATURE_texture_fxt1 case MESA_FORMAT_RGB_FXT1: case MESA_FORMAT_RGBA_FXT1: stride = ((width + 7) / 8) * 16; /* 16 bytes per 8x4 tile */ break; +#endif +#if FEATURE_texture_s3tc case MESA_FORMAT_RGB_DXT1: case MESA_FORMAT_RGBA_DXT1: stride = ((width + 3) / 4) * 8; /* 8 bytes per 4x4 tile */ @@ -257,6 +269,7 @@ _mesa_compressed_row_stride(GLuint mesaFormat, GLsizei width) case MESA_FORMAT_RGBA_DXT5: stride = ((width + 3) / 4) * 16; /* 16 bytes per 4x4 tile */ break; +#endif default: _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_row_stride"); return 0; @@ -293,10 +306,13 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, */ switch (mesaFormat) { +#if FEATURE_texture_fxt1 case MESA_FORMAT_RGB_FXT1: case MESA_FORMAT_RGBA_FXT1: addr = (GLubyte *) image + 16 * (((width + 7) / 8) * (row / 4) + col / 8); break; +#endif +#if FEATURE_texture_s3tc case MESA_FORMAT_RGB_DXT1: case MESA_FORMAT_RGBA_DXT1: addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4); @@ -305,6 +321,7 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, case MESA_FORMAT_RGBA_DXT5: addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4); break; +#endif default: _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_image_address"); addr = NULL; -- cgit v1.2.3 From 5bd093bd7b3711f88e1fd0fc9cdb37a18d7d24b9 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 12 Dec 2008 05:06:48 +0100 Subject: mesa: fixes for srgb, new srgb formats add some more srgb texture formats, including compressed ones various fixes relating to srgb formats issues: _mesa_get_teximage is completely broken for srgb textures, both for non-compressed ones (swizzling) and compressed ones (shouldn't do standard-to-linear conversion) texelFetch function may be broken for little or big endian (or both...) --- src/mesa/main/texcompress.c | 71 ++++++++++++--- src/mesa/main/texcompress_s3tc.c | 184 +++++++++++++++++++++++++++++++++++---- src/mesa/main/texformat.c | 65 ++++++++++++-- src/mesa/main/texformat.h | 13 +++ src/mesa/main/texformat_tmp.h | 26 ++++++ src/mesa/main/texstore.c | 51 +++++++---- src/mesa/main/texstore.h | 2 + 7 files changed, 358 insertions(+), 54 deletions(-) (limited to 'src/mesa/main/texcompress.c') diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index 0653407048..04f0f3ab13 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -3,6 +3,7 @@ * Version: 6.5.1 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -84,6 +85,25 @@ _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all) if (all) n += 1; } +#if FEATURE_EXT_texture_sRGB + if (ctx->Extensions.EXT_texture_sRGB) { + if (formats) { + if (all) { + /* according to sRGB spec, these should not be returned + via the GL_COMPRESSED_TEXTURE_FORMATS query as they + aren't really general purpose */ + formats[n++] = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT; + formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; + formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; + formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; + } + } + else { + if (all) + n += 4; + } + } +#endif /* FEATURE_EXT_texture_sRGB */ } if (ctx->Extensions.S3_s3tc) { if (formats) { @@ -96,19 +116,6 @@ _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all) n += 4; } } -#if FEATURE_EXT_texture_sRGB - if (ctx->Extensions.EXT_texture_sRGB) { - if (formats) { - formats[n++] = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT; - formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; - formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; - formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; - } - else { - n += 4; - } - } -#endif /* FEATURE_EXT_texture_sRGB */ } return n; } @@ -156,6 +163,10 @@ _mesa_compressed_texture_size( GLcontext *ctx, #if FEATURE_texture_s3tc case MESA_FORMAT_RGB_DXT1: case MESA_FORMAT_RGBA_DXT1: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGB_DXT1: + case MESA_FORMAT_SRGBA_DXT1: +#endif /* round up width, height to next multiple of 4 */ width = (width + 3) & ~3; height = (height + 3) & ~3; @@ -167,6 +178,10 @@ _mesa_compressed_texture_size( GLcontext *ctx, return size; case MESA_FORMAT_RGBA_DXT3: case MESA_FORMAT_RGBA_DXT5: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGBA_DXT3: + case MESA_FORMAT_SRGBA_DXT5: +#endif /* round up width, height to next multiple of 4 */ width = (width + 3) & ~3; height = (height + 3) & ~3; @@ -226,6 +241,20 @@ _mesa_compressed_texture_size_glenum(GLcontext *ctx, case GL_RGBA4_S3TC: mesaFormat = MESA_FORMAT_RGBA_DXT5; break; +#if FEATURE_EXT_texture_sRGB + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + mesaFormat = MESA_FORMAT_SRGB_DXT1; + break; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + mesaFormat = MESA_FORMAT_SRGBA_DXT1; + break; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + mesaFormat = MESA_FORMAT_SRGBA_DXT3; + break; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + mesaFormat = MESA_FORMAT_SRGBA_DXT5; + break; +#endif #endif default: return 0; @@ -257,10 +286,18 @@ _mesa_compressed_row_stride(GLuint mesaFormat, GLsizei width) #if FEATURE_texture_s3tc case MESA_FORMAT_RGB_DXT1: case MESA_FORMAT_RGBA_DXT1: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGB_DXT1: + case MESA_FORMAT_SRGBA_DXT1: +#endif stride = ((width + 3) / 4) * 8; /* 8 bytes per 4x4 tile */ break; case MESA_FORMAT_RGBA_DXT3: case MESA_FORMAT_RGBA_DXT5: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGBA_DXT3: + case MESA_FORMAT_SRGBA_DXT5: +#endif stride = ((width + 3) / 4) * 16; /* 16 bytes per 4x4 tile */ break; #endif @@ -309,10 +346,18 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, #if FEATURE_texture_s3tc case MESA_FORMAT_RGB_DXT1: case MESA_FORMAT_RGBA_DXT1: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGB_DXT1: + case MESA_FORMAT_SRGBA_DXT1: +#endif addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4); break; case MESA_FORMAT_RGBA_DXT3: case MESA_FORMAT_RGBA_DXT5: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGBA_DXT3: + case MESA_FORMAT_SRGBA_DXT5: +#endif addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4); break; #endif diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c index 4f329cdf59..ccc007c24d 100644 --- a/src/mesa/main/texcompress_s3tc.c +++ b/src/mesa/main/texcompress_s3tc.c @@ -3,6 +3,7 @@ * Version: 6.5.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -56,6 +57,34 @@ #define DXTN_LIBNAME "libtxc_dxtn.so" #endif +#if FEATURE_EXT_texture_sRGB +/** + * Convert an 8-bit sRGB value from non-linear space to a + * linear RGB value in [0, 1]. + * Implemented with a 256-entry lookup table. + */ +static INLINE GLfloat +nonlinear_to_linear(GLubyte cs8) +{ + static GLfloat table[256]; + static GLboolean tableReady = GL_FALSE; + if (!tableReady) { + /* compute lookup table now */ + GLuint i; + for (i = 0; i < 256; i++) { + const GLfloat cs = UBYTE_TO_FLOAT(i); + if (cs <= 0.04045) { + table[i] = cs / 12.92f; + } + else { + table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4); + } + } + tableReady = GL_TRUE; + } + return table[cs8]; +} +#endif /* FEATURE_EXT_texture_sRGB */ typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut ); @@ -552,6 +581,59 @@ fetch_texel_2d_f_rgba_dxt5( const struct gl_texture_image *texImage, texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]); } +#if FEATURE_EXT_texture_sRGB +static void +fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + /* just sample as GLchan and convert to float here */ + GLchan rgba[4]; + fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba); + texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]); +} + +static void +fetch_texel_2d_f_srgba_dxt1( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + /* just sample as GLchan and convert to float here */ + GLchan rgba[4]; + fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba); + texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]); +} + +static void +fetch_texel_2d_f_srgba_dxt3( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + /* just sample as GLchan and convert to float here */ + GLchan rgba[4]; + fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba); + texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]); +} + +static void +fetch_texel_2d_f_srgba_dxt5( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + /* just sample as GLchan and convert to float here */ + GLchan rgba[4]; + fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba); + texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]); +} +#endif const struct gl_texture_format _mesa_texformat_rgb_dxt1 = { MESA_FORMAT_RGB_DXT1, /* MesaFormat */ @@ -577,6 +659,78 @@ const struct gl_texture_format _mesa_texformat_rgb_dxt1 = { NULL /* StoreTexel */ }; +const struct gl_texture_format _mesa_texformat_rgba_dxt1 = { + MESA_FORMAT_RGBA_DXT1, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4, /*approx*/ /* RedBits */ + 4, /*approx*/ /* GreenBits */ + 4, /*approx*/ /* BlueBits */ + 1, /*approx*/ /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 0, /* StencilBits */ + 0, /* TexelBytes */ + texstore_rgba_dxt1, /* StoreTexImageFunc */ + NULL, /*impossible*/ /* FetchTexel1D */ + fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */ + NULL, /*impossible*/ /* FetchTexel3D */ + NULL, /*impossible*/ /* FetchTexel1Df */ + fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */ + NULL, /*impossible*/ /* FetchTexel3Df */ + NULL /* StoreTexel */ +}; + +const struct gl_texture_format _mesa_texformat_rgba_dxt3 = { + MESA_FORMAT_RGBA_DXT3, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4, /*approx*/ /* RedBits */ + 4, /*approx*/ /* GreenBits */ + 4, /*approx*/ /* BlueBits */ + 4, /*approx*/ /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 0, /* StencilBits */ + 0, /* TexelBytes */ + texstore_rgba_dxt3, /* StoreTexImageFunc */ + NULL, /*impossible*/ /* FetchTexel1D */ + fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */ + NULL, /*impossible*/ /* FetchTexel3D */ + NULL, /*impossible*/ /* FetchTexel1Df */ + fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */ + NULL, /*impossible*/ /* FetchTexel3Df */ + NULL /* StoreTexel */ +}; + +const struct gl_texture_format _mesa_texformat_rgba_dxt5 = { + MESA_FORMAT_RGBA_DXT5, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4,/*approx*/ /* RedBits */ + 4,/*approx*/ /* GreenBits */ + 4,/*approx*/ /* BlueBits */ + 4,/*approx*/ /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 0, /* StencilBits */ + 0, /* TexelBytes */ + texstore_rgba_dxt5, /* StoreTexImageFunc */ + NULL, /*impossible*/ /* FetchTexel1D */ + fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */ + NULL, /*impossible*/ /* FetchTexel3D */ + NULL, /*impossible*/ /* FetchTexel1Df */ + fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */ + NULL, /*impossible*/ /* FetchTexel3Df */ + NULL /* StoreTexel */ +}; + #if FEATURE_EXT_texture_sRGB const struct gl_texture_format _mesa_texformat_srgb_dxt1 = { MESA_FORMAT_SRGB_DXT1, /* MesaFormat */ @@ -594,17 +748,16 @@ const struct gl_texture_format _mesa_texformat_srgb_dxt1 = { 0, /* TexelBytes */ texstore_rgb_dxt1, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ - fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */ + NULL, /* FetchTexel2D */ NULL, /*impossible*/ /* FetchTexel3D */ NULL, /*impossible*/ /* FetchTexel1Df */ - fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */ + fetch_texel_2d_f_srgb_dxt1, /* FetchTexel2Df */ NULL, /*impossible*/ /* FetchTexel3Df */ NULL /* StoreTexel */ }; -#endif -const struct gl_texture_format _mesa_texformat_rgba_dxt1 = { - MESA_FORMAT_RGBA_DXT1, /* MesaFormat */ +const struct gl_texture_format _mesa_texformat_srgba_dxt1 = { + MESA_FORMAT_SRGBA_DXT1, /* MesaFormat */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 4, /*approx*/ /* RedBits */ @@ -619,16 +772,16 @@ const struct gl_texture_format _mesa_texformat_rgba_dxt1 = { 0, /* TexelBytes */ texstore_rgba_dxt1, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ - fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */ + NULL, /* FetchTexel2D */ NULL, /*impossible*/ /* FetchTexel3D */ NULL, /*impossible*/ /* FetchTexel1Df */ - fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */ + fetch_texel_2d_f_srgba_dxt1, /* FetchTexel2Df */ NULL, /*impossible*/ /* FetchTexel3Df */ NULL /* StoreTexel */ }; -const struct gl_texture_format _mesa_texformat_rgba_dxt3 = { - MESA_FORMAT_RGBA_DXT3, /* MesaFormat */ +const struct gl_texture_format _mesa_texformat_srgba_dxt3 = { + MESA_FORMAT_SRGBA_DXT3, /* MesaFormat */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 4, /*approx*/ /* RedBits */ @@ -643,16 +796,16 @@ const struct gl_texture_format _mesa_texformat_rgba_dxt3 = { 0, /* TexelBytes */ texstore_rgba_dxt3, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ - fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */ + NULL, /* FetchTexel2D */ NULL, /*impossible*/ /* FetchTexel3D */ NULL, /*impossible*/ /* FetchTexel1Df */ - fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */ + fetch_texel_2d_f_srgba_dxt3, /* FetchTexel2Df */ NULL, /*impossible*/ /* FetchTexel3Df */ NULL /* StoreTexel */ }; -const struct gl_texture_format _mesa_texformat_rgba_dxt5 = { - MESA_FORMAT_RGBA_DXT5, /* MesaFormat */ +const struct gl_texture_format _mesa_texformat_srgba_dxt5 = { + MESA_FORMAT_SRGBA_DXT5, /* MesaFormat */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 4,/*approx*/ /* RedBits */ @@ -667,10 +820,11 @@ const struct gl_texture_format _mesa_texformat_rgba_dxt5 = { 0, /* TexelBytes */ texstore_rgba_dxt5, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ - fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */ + NULL, /* FetchTexel2D */ NULL, /*impossible*/ /* FetchTexel3D */ NULL, /*impossible*/ /* FetchTexel1Df */ - fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */ + fetch_texel_2d_f_srgba_dxt5, /* FetchTexel2Df */ NULL, /*impossible*/ /* FetchTexel3Df */ NULL /* StoreTexel */ }; +#endif diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c index ce2772c299..db3525666a 100644 --- a/src/mesa/main/texformat.c +++ b/src/mesa/main/texformat.c @@ -3,6 +3,7 @@ * Version: 6.5.1 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -333,6 +334,30 @@ const struct gl_texture_format _mesa_texformat_srgba8 = { store_texel_srgba8 /* StoreTexel */ }; +const struct gl_texture_format _mesa_texformat_sargb8 = { + MESA_FORMAT_SARGB8, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 8, /* RedBits */ + 8, /* GreenBits */ + 8, /* BlueBits */ + 8, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 0, /* StencilBits */ + 4, /* TexelBytes */ + _mesa_texstore_sargb8, /* StoreTexImageFunc */ + NULL, /* FetchTexel1D */ + NULL, /* FetchTexel2D */ + NULL, /* FetchTexel3D */ + fetch_texel_1d_sargb8, /* FetchTexel1Df */ + fetch_texel_2d_sargb8, /* FetchTexel2Df */ + fetch_texel_3d_sargb8, /* FetchTexel3Df */ + store_texel_sargb8 /* StoreTexel */ +}; + const struct gl_texture_format _mesa_texformat_sl8 = { MESA_FORMAT_SL8, /* MesaFormat */ GL_LUMINANCE, /* BaseFormat */ @@ -1578,21 +1603,40 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, case GL_SLUMINANCE_ALPHA_EXT: case GL_SLUMINANCE8_ALPHA8_EXT: return &_mesa_texformat_sla8; - /* NOTE: not supporting any compression of sRGB at this time */ - case GL_COMPRESSED_SRGB_EXT: - return &_mesa_texformat_srgb8; - case GL_COMPRESSED_SRGB_ALPHA_EXT: - return &_mesa_texformat_srgba8; case GL_COMPRESSED_SLUMINANCE_EXT: return &_mesa_texformat_sl8; case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: return &_mesa_texformat_sla8; - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_EXT: +#if FEATURE_texture_s3tc + if (ctx->Extensions.EXT_texture_compression_s3tc) + return &_mesa_texformat_srgb_dxt1; +#endif return &_mesa_texformat_srgb8; + case GL_COMPRESSED_SRGB_ALPHA_EXT: +#if FEATURE_texture_s3tc + if (ctx->Extensions.EXT_texture_compression_s3tc) + return &_mesa_texformat_srgba_dxt3; /* Not srgba_dxt1, see spec */ +#endif + return &_mesa_texformat_srgba8; +#if FEATURE_texture_s3tc + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + if (ctx->Extensions.EXT_texture_compression_s3tc) + return &_mesa_texformat_srgb_dxt1; + break; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + if (ctx->Extensions.EXT_texture_compression_s3tc) + return &_mesa_texformat_srgba_dxt1; + break; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + if (ctx->Extensions.EXT_texture_compression_s3tc) + return &_mesa_texformat_srgba_dxt3; + break; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - return &_mesa_texformat_srgba8; + if (ctx->Extensions.EXT_texture_compression_s3tc) + return &_mesa_texformat_srgba_dxt5; + break; +#endif default: ; /* fallthrough */ } @@ -1694,6 +1738,7 @@ _mesa_format_to_type_and_comps(const struct gl_texture_format *format, *comps = 3; return; case MESA_FORMAT_SRGBA8: + case MESA_FORMAT_SARGB8: *datatype = GL_UNSIGNED_BYTE; *comps = 4; return; @@ -1716,6 +1761,12 @@ _mesa_format_to_type_and_comps(const struct gl_texture_format *format, case MESA_FORMAT_RGBA_DXT1: case MESA_FORMAT_RGBA_DXT3: case MESA_FORMAT_RGBA_DXT5: +#if FEATURE_EXT_texture_sRGB + case MESA_FORMAT_SRGB_DXT1: + case MESA_FORMAT_SRGBA_DXT1: + case MESA_FORMAT_SRGBA_DXT3: + case MESA_FORMAT_SRGBA_DXT5: +#endif /* XXX generate error instead? */ *datatype = GL_UNSIGNED_BYTE; *comps = 0; diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h index f34b3b8223..c7a754b0b7 100644 --- a/src/mesa/main/texformat.h +++ b/src/mesa/main/texformat.h @@ -3,6 +3,7 @@ * Version: 6.5.1 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -96,9 +97,15 @@ enum _format { /*@{*/ MESA_FORMAT_SRGB8, MESA_FORMAT_SRGBA8, + MESA_FORMAT_SARGB8, MESA_FORMAT_SL8, MESA_FORMAT_SLA8, +#if FEATURE_texture_s3tc MESA_FORMAT_SRGB_DXT1, + MESA_FORMAT_SRGBA_DXT1, + MESA_FORMAT_SRGBA_DXT3, + MESA_FORMAT_SRGBA_DXT5, +#endif /*@}*/ #endif @@ -172,9 +179,15 @@ extern const struct gl_texture_format _mesa_texformat_intensity; /*@{*/ extern const struct gl_texture_format _mesa_texformat_srgb8; extern const struct gl_texture_format _mesa_texformat_srgba8; +extern const struct gl_texture_format _mesa_texformat_sargb8; extern const struct gl_texture_format _mesa_texformat_sl8; extern const struct gl_texture_format _mesa_texformat_sla8; +#if FEATURE_texture_s3tc extern const struct gl_texture_format _mesa_texformat_srgb_dxt1; +extern const struct gl_texture_format _mesa_texformat_srgba_dxt1; +extern const struct gl_texture_format _mesa_texformat_srgba_dxt3; +extern const struct gl_texture_format _mesa_texformat_srgba_dxt5; +#endif /*@}*/ #endif diff --git a/src/mesa/main/texformat_tmp.h b/src/mesa/main/texformat_tmp.h index 7499ba7b36..b1031b0cfe 100644 --- a/src/mesa/main/texformat_tmp.h +++ b/src/mesa/main/texformat_tmp.h @@ -3,6 +3,7 @@ * Version: 6.5.1 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -1191,6 +1192,31 @@ static void store_texel_srgba8(struct gl_texture_image *texImage, dst[0] = rgba[RCOMP]; dst[1] = rgba[GCOMP]; dst[2] = rgba[BCOMP]; + dst[3] = rgba[ACOMP]; +} +#endif + +/* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */ +static void FETCH(sargb8)(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4); + texel[RCOMP] = nonlinear_to_linear(src[1]); + texel[GCOMP] = nonlinear_to_linear(src[2]); + texel[BCOMP] = nonlinear_to_linear(src[3]); + texel[ACOMP] = UBYTE_TO_FLOAT(src[0]); /* linear! */ +} + +#if DIM == 3 +static void store_texel_sargb8(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLubyte *rgba = (const GLubyte *) texel; + GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4); + dst[0] = rgba[ACOMP]; + dst[1] = rgba[RCOMP]; + dst[2] = rgba[GCOMP]; + dst[3] = rgba[BCOMP]; } #endif diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 7278180a5c..8afb947fa1 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -3,6 +3,7 @@ * Version: 7.3 * * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -2662,7 +2663,6 @@ _mesa_texstore_rgba_float16(TEXSTORE_PARAMS) GLboolean _mesa_texstore_srgb8(TEXSTORE_PARAMS) { - const GLboolean littleEndian = _mesa_little_endian(); const struct gl_texture_format *newDstFormat; StoreTexImageFunc store; GLboolean k; @@ -2670,14 +2670,8 @@ _mesa_texstore_srgb8(TEXSTORE_PARAMS) ASSERT(dstFormat == &_mesa_texformat_srgb8); /* reuse normal rgb texstore code */ - if (littleEndian) { - newDstFormat = &_mesa_texformat_bgr888; - store = _mesa_texstore_bgr888; - } - else { - newDstFormat = &_mesa_texformat_rgb888; - store = _mesa_texstore_rgb888; - } + newDstFormat = &_mesa_texformat_rgb888; + store = _mesa_texstore_rgb888; k = store(ctx, dims, baseInternalFormat, newDstFormat, dstAddr, @@ -2693,17 +2687,13 @@ _mesa_texstore_srgb8(TEXSTORE_PARAMS) GLboolean _mesa_texstore_srgba8(TEXSTORE_PARAMS) { - const GLboolean littleEndian = _mesa_little_endian(); const struct gl_texture_format *newDstFormat; GLboolean k; ASSERT(dstFormat == &_mesa_texformat_srgba8); /* reuse normal rgba texstore code */ - if (littleEndian) - newDstFormat = &_mesa_texformat_rgba8888_rev; - else - newDstFormat = &_mesa_texformat_rgba8888; + newDstFormat = &_mesa_texformat_rgba8888; k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat, newDstFormat, dstAddr, @@ -2716,6 +2706,28 @@ _mesa_texstore_srgba8(TEXSTORE_PARAMS) } +GLboolean +_mesa_texstore_sargb8(TEXSTORE_PARAMS) +{ + const struct gl_texture_format *newDstFormat; + GLboolean k; + + ASSERT(dstFormat == &_mesa_texformat_sargb8); + + /* reuse normal rgba texstore code */ + newDstFormat = &_mesa_texformat_argb8888; + + k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat, + newDstFormat, dstAddr, + dstXoffset, dstYoffset, dstZoffset, + dstRowStride, dstImageOffsets, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, + srcAddr, srcPacking); + return k; +} + + GLboolean _mesa_texstore_sl8(TEXSTORE_PARAMS) { @@ -2741,17 +2753,13 @@ _mesa_texstore_sl8(TEXSTORE_PARAMS) GLboolean _mesa_texstore_sla8(TEXSTORE_PARAMS) { - const GLboolean littleEndian = _mesa_little_endian(); const struct gl_texture_format *newDstFormat; GLboolean k; ASSERT(dstFormat == &_mesa_texformat_sla8); /* reuse normal luminance/alpha texstore code */ - if (littleEndian) - newDstFormat = &_mesa_texformat_al88; - else - newDstFormat = &_mesa_texformat_al88_rev; + newDstFormat = &_mesa_texformat_al88; k = _mesa_texstore_al88(ctx, dims, baseInternalFormat, newDstFormat, dstAddr, @@ -3581,6 +3589,7 @@ is_srgb_teximage(const struct gl_texture_image *texImage) switch (texImage->TexFormat->MesaFormat) { case MESA_FORMAT_SRGB8: case MESA_FORMAT_SRGBA8: + case MESA_FORMAT_SARGB8: case MESA_FORMAT_SL8: case MESA_FORMAT_SLA8: return GL_TRUE; @@ -3713,6 +3722,10 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level, MEMCPY(dest, (const GLubyte *) texImage->Data + row * rowstride, comps * width * sizeof(GLubyte)); + /* FIXME: isn't it necessary to still do component assigning + according to format/type? */ + /* FIXME: need to do something else for compressed srgb textures + (currently will return values converted to linear) */ } #endif /* FEATURE_EXT_texture_sRGB */ else { diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h index c9edf14dbc..8dc1c963cd 100644 --- a/src/mesa/main/texstore.h +++ b/src/mesa/main/texstore.h @@ -3,6 +3,7 @@ * Version: 6.5.1 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -71,6 +72,7 @@ extern GLboolean _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS); #if FEATURE_EXT_texture_sRGB extern GLboolean _mesa_texstore_srgb8(TEXSTORE_PARAMS); extern GLboolean _mesa_texstore_srgba8(TEXSTORE_PARAMS); +extern GLboolean _mesa_texstore_sargb8(TEXSTORE_PARAMS); extern GLboolean _mesa_texstore_sl8(TEXSTORE_PARAMS); extern GLboolean _mesa_texstore_sla8(TEXSTORE_PARAMS); #endif -- cgit v1.2.3