diff options
author | Brian Paul <[email protected]> | 2010-04-26 20:35:19 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2010-04-26 20:35:19 -0600 |
commit | 84407d7365e101c36a83fd0a58c58b0c0c57db14 (patch) | |
tree | c52f70cd8e5bb600220a86bfa5371cda1c7d41cd /src/mesa/main | |
parent | b1ceadf2ee11a961530645eec40624211298382d (diff) |
mesa: start adding GL 3.1 signed normalized texture formats
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/formats.c | 58 | ||||
-rw-r--r-- | src/mesa/main/formats.h | 14 | ||||
-rw-r--r-- | src/mesa/main/texfetch.c | 50 | ||||
-rw-r--r-- | src/mesa/main/texfetch_tmp.h | 177 | ||||
-rw-r--r-- | src/mesa/main/texformat.c | 26 | ||||
-rw-r--r-- | src/mesa/main/texstore.c | 153 |
6 files changed, 470 insertions, 8 deletions
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index d0c9c0028b2..b9796e4a423 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -637,6 +637,35 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 0, 0, 0, 0, 1, 1, 2 }, + + /* Signed 8 bits / channel */ + { + MESA_FORMAT_SIGNED_R8, /* Name */ + "MESA_FORMAT_SIGNED_R8", /* StrName */ + GL_RGBA, /* BaseFormat */ + GL_SIGNED_NORMALIZED, /* DataType */ + 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ + 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 1 /* BlockWidth/Height,Bytes */ + }, + { + MESA_FORMAT_SIGNED_RG88, + "MESA_FORMAT_SIGNED_RG88", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_SIGNED_RGBX8888, + "MESA_FORMAT_SIGNED_RGBX8888", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 8, 8, 8, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 /* 4 bpp, but no alpha */ + }, { MESA_FORMAT_SIGNED_RGBA8888, "MESA_FORMAT_SIGNED_RGBA8888", @@ -655,6 +684,35 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 0, 0, 0, 0, 1, 1, 4 }, + + /* Signed 16 bits / channel */ + { + MESA_FORMAT_SIGNED_R_16, + "MESA_FORMAT_SIGNED_R_16", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 16, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_SIGNED_RG_16, + "MESA_FORMAT_SIGNED_RG_16", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_SIGNED_RGB_16, + "MESA_FORMAT_SIGNED_RGB_16", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 16, 16, 16, 0, + 0, 0, 0, 0, 0, + 1, 1, 6 + }, { MESA_FORMAT_SIGNED_RGBA_16, "MESA_FORMAT_SIGNED_RGBA_16", diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h index 0eeeb8b2bac..97e1fc5df46 100644 --- a/src/mesa/main/formats.h +++ b/src/mesa/main/formats.h @@ -130,13 +130,21 @@ typedef enum MESA_FORMAT_INTENSITY_FLOAT16, /*@}*/ + /* msb <------ TEXEL BITS -----------> lsb */ + /* ---- ---- ---- ---- ---- ---- ---- ---- */ /** * \name Signed fixed point texture formats. */ /*@{*/ - MESA_FORMAT_DUDV8, - MESA_FORMAT_SIGNED_RGBA8888, - MESA_FORMAT_SIGNED_RGBA8888_REV, + MESA_FORMAT_DUDV8, /* DUDU DUDU DVDV DVDV */ + MESA_FORMAT_SIGNED_R8, /* RRRR RRRR */ + MESA_FORMAT_SIGNED_RG88, /* RRRR RRRR GGGG GGGG */ + MESA_FORMAT_SIGNED_RGBX8888, /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */ + MESA_FORMAT_SIGNED_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */ + MESA_FORMAT_SIGNED_RGBA8888_REV,/*AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */ + MESA_FORMAT_SIGNED_R_16, + MESA_FORMAT_SIGNED_RG_16, + MESA_FORMAT_SIGNED_RGB_16, MESA_FORMAT_SIGNED_RGBA_16, /*@}*/ diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c index 323850e1981..48a22c19455 100644 --- a/src/mesa/main/texfetch.c +++ b/src/mesa/main/texfetch.c @@ -560,6 +560,27 @@ texfetch_funcs[MESA_FORMAT_COUNT] = NULL }, { + MESA_FORMAT_SIGNED_R8, + fetch_texel_1d_signed_r8, + fetch_texel_2d_signed_r8, + fetch_texel_3d_signed_r8, + store_texel_signed_r8 + }, + { + MESA_FORMAT_SIGNED_RG88, + fetch_texel_1d_signed_rg88, + fetch_texel_2d_signed_rg88, + fetch_texel_3d_signed_rg88, + store_texel_signed_rg88 + }, + { + MESA_FORMAT_SIGNED_RGBX8888, + fetch_texel_1d_signed_rgbx8888, + fetch_texel_2d_signed_rgbx8888, + fetch_texel_3d_signed_rgbx8888, + store_texel_signed_rgbx8888 + }, + { MESA_FORMAT_SIGNED_RGBA8888, fetch_texel_1d_signed_rgba8888, fetch_texel_2d_signed_rgba8888, @@ -574,11 +595,32 @@ texfetch_funcs[MESA_FORMAT_COUNT] = store_texel_signed_rgba8888_rev }, { + MESA_FORMAT_SIGNED_R_16, + fetch_texel_1d_signed_r_16, + fetch_texel_2d_signed_r_16, + fetch_texel_3d_signed_r_16, + store_texel_signed_r_16 + }, + { + MESA_FORMAT_SIGNED_RG_16, + fetch_texel_1d_signed_rg_16, + fetch_texel_2d_signed_rg_16, + fetch_texel_3d_signed_rg_16, + store_texel_signed_rg_16 + }, + { + MESA_FORMAT_SIGNED_RGB_16, + fetch_texel_1d_signed_rgb_16, + fetch_texel_2d_signed_rgb_16, + fetch_texel_3d_signed_rgb_16, + store_texel_signed_rgb_16 + }, + { MESA_FORMAT_SIGNED_RGBA_16, - NULL, /* XXX to do */ - NULL, - NULL, - NULL + fetch_texel_1d_signed_rgba_16, + fetch_texel_2d_signed_rgba_16, + fetch_texel_3d_signed_rgba_16, + store_texel_signed_rgba_16 }, }; diff --git a/src/mesa/main/texfetch_tmp.h b/src/mesa/main/texfetch_tmp.h index b11ed5c39a3..4df2b19181a 100644 --- a/src/mesa/main/texfetch_tmp.h +++ b/src/mesa/main/texfetch_tmp.h @@ -1209,6 +1209,76 @@ static void FETCH(dudv8)(const struct gl_texture_image *texImage, texel[ACOMP] = 0; } + +/* MESA_FORMAT_SIGNED_R8 ***********************************************/ + +static void FETCH(signed_r8)( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1); + texel[RCOMP] = BYTE_TO_FLOAT_TEX( s ); + texel[GCOMP] = 0.0F; + texel[BCOMP] = 0.0F; + texel[ACOMP] = 1.0F; +} + +#if DIM == 3 +static void store_texel_signed_r8(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLbyte *rgba = (const GLbyte *) texel; + GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1); + *dst = rgba[RCOMP]; +} +#endif + + +/* MESA_FORMAT_SIGNED_RG88 ***********************************************/ + +static void FETCH(signed_rg88)( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1); + texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) ); + texel[BCOMP] = 0.0F; + texel[ACOMP] = 1.0F; +} + +#if DIM == 3 +static void store_texel_signed_rg88(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLbyte *rg = (const GLbyte *) texel; + GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 2); + *dst = PACK_COLOR_88(rg[RCOMP], rg[GCOMP]); +} +#endif + + +/* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/ + +static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); + texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); + texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); + texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + texel[ACOMP] = 1.0f; +} + +#if DIM == 3 +static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLbyte *rgba = (const GLbyte *) texel; + GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1); + *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255); +} +#endif + + /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/ static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage, @@ -1253,6 +1323,113 @@ static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage, +/* MESA_FORMAT_SIGNED_R_16 ***********************************************/ + +static void +FETCH(signed_r_16)(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1); + texel[RCOMP] = SHORT_TO_FLOAT_TEX( s ); + texel[GCOMP] = 0.0F; + texel[BCOMP] = 0.0F; + texel[ACOMP] = 1.0F; +} + +#if DIM == 3 +static void +store_texel_signed_r_16(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLshort *rgba = (const GLshort *) texel; + GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1); + *dst = rgba[0]; +} +#endif + + +/* MESA_FORMAT_SIGNED_RG_16 ***********************************************/ + +static void +FETCH(signed_rg_16)(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2); + texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); + texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); + texel[BCOMP] = 0.0F; + texel[ACOMP] = 1.0F; +} + +#if DIM == 3 +static void +store_texel_signed_rg_16(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLshort *rgba = (const GLshort *) texel; + GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2); + dst[0] = rgba[RCOMP]; + dst[1] = rgba[GCOMP]; +} +#endif + + +/* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/ + +static void +FETCH(signed_rgb_16)(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3); + texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); + texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); + texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[3] ); + texel[ACOMP] = 1.0F; +} + +#if DIM == 3 +static void +store_texel_signed_rgb_16(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLshort *rgba = (const GLshort *) texel; + GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3); + dst[0] = rgba[RCOMP]; + dst[1] = rgba[GCOMP]; + dst[2] = rgba[BCOMP]; +} +#endif + + +/* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/ + +static void +FETCH(signed_rgba_16)(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4); + texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); + texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); + texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[3] ); + texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[4] ); +} + +#if DIM == 3 +static void +store_texel_signed_rgba_16(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLshort *rgba = (const GLshort *) texel; + GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4); + dst[0] = rgba[RCOMP]; + dst[1] = rgba[GCOMP]; + dst[2] = rgba[BCOMP]; + dst[3] = rgba[ACOMP]; +} +#endif + + + /* MESA_FORMAT_YCBCR *********************************************************/ /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats. diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c index 096945a6432..06e6fd92fca 100644 --- a/src/mesa/main/texformat.c +++ b/src/mesa/main/texformat.c @@ -294,6 +294,32 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, } } + if (ctx->VersionMajor * 10 + ctx->VersionMinor >= 31) { + switch (internalFormat) { + case GL_RED_SNORM: + case GL_R8_SNORM: + return MESA_FORMAT_SIGNED_R8; + case GL_RG_SNORM: + case GL_RG8_SNORM: + return MESA_FORMAT_SIGNED_RG88; + case GL_RGB_SNORM: + case GL_RGB8_SNORM: + return MESA_FORMAT_SIGNED_RGBX8888; + case GL_RGBA_SNORM: + case GL_RGBA8_SNORM: + return MESA_FORMAT_SIGNED_RGBA8888; + case GL_R16_SNORM: + return MESA_FORMAT_SIGNED_R_16; + case GL_RG16_SNORM: + return MESA_FORMAT_SIGNED_RG_16; + case GL_RGB16_SNORM: + return MESA_FORMAT_SIGNED_RGB_16; + case GL_RGBA16_SNORM: + return MESA_FORMAT_SIGNED_RGBA_16; + default: + ; /* fall-through */ + } + } #if FEATURE_EXT_texture_sRGB if (ctx->Extensions.EXT_texture_sRGB) { diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 65e3fcaa953..94c0894de1f 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -2551,6 +2551,147 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS) return GL_TRUE; } + +/** + * Store a texture in MESA_FORMAT_SIGNED_R8 format. + */ +static GLboolean +_mesa_texstore_signed_r8(TEXSTORE_PARAMS) +{ + const GLuint texelBytes = _mesa_get_format_bytes(dstFormat); + const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); + + ASSERT(dstFormat == MESA_FORMAT_SIGNED_R8); + ASSERT(texelBytes == 1); + + /* XXX look at adding optimized paths */ + { + /* general path */ + const GLfloat *tempImage = make_temp_float_image(ctx, dims, + baseInternalFormat, + baseFormat, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, + srcPacking); + const GLfloat *srcRow = tempImage; + GLint img, row, col; + if (!tempImage) + return GL_FALSE; + _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight); + for (img = 0; img < srcDepth; img++) { + GLubyte *dstRow = (GLubyte *) dstAddr + + dstImageOffsets[dstZoffset + img] * texelBytes + + dstYoffset * dstRowStride + + dstXoffset * texelBytes; + for (row = 0; row < srcHeight; row++) { + GLubyte *dstB = (GLubyte *) dstRow; + for (col = 0; col < srcWidth; col++) { + dstB[col] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]); + } + dstRow += dstRowStride; + } + } + free((void *) tempImage); + } + return GL_TRUE; +} + + +/** + * Store a texture in MESA_FORMAT_SIGNED_RG88 format. + */ +static GLboolean +_mesa_texstore_signed_rg88(TEXSTORE_PARAMS) +{ + const GLuint texelBytes = _mesa_get_format_bytes(dstFormat); + const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); + + ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG88); + ASSERT(texelBytes == 1); + + /* XXX look at adding optimized paths */ + { + /* general path */ + const GLfloat *tempImage = make_temp_float_image(ctx, dims, + baseInternalFormat, + baseFormat, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, + srcPacking); + const GLfloat *srcRow = tempImage; + GLint img, row, col; + if (!tempImage) + return GL_FALSE; + _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight); + for (img = 0; img < srcDepth; img++) { + GLubyte *dstRow = (GLubyte *) dstAddr + + dstImageOffsets[dstZoffset + img] * texelBytes + + dstYoffset * dstRowStride + + dstXoffset * texelBytes; + for (row = 0; row < srcHeight; row++) { + GLushort *dstUS = (GLushort *) dstRow; + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow[RCOMP]), + FLOAT_TO_BYTE_TEX(srcRow[GCOMP])); + } + dstRow += dstRowStride; + } + } + free((void *) tempImage); + } + return GL_TRUE; +} + + +/** + * Store a texture in MESA_FORMAT_SIGNED_RGBX8888. + */ +static GLboolean +_mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS) +{ + const GLuint texelBytes = _mesa_get_format_bytes(dstFormat); + const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); + + ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBX8888); + ASSERT(texelBytes == 4); + + { + /* general path */ + const GLfloat *tempImage = make_temp_float_image(ctx, dims, + baseInternalFormat, + baseFormat, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, + srcPacking); + const GLfloat *srcRow = tempImage; + GLint img, row, col; + if (!tempImage) + return GL_FALSE; + _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight); + for (img = 0; img < srcDepth; img++) { + GLubyte *dstRow = (GLubyte *) dstAddr + + dstImageOffsets[dstZoffset + img] * texelBytes + + dstYoffset * dstRowStride + + dstXoffset * texelBytes; + for (row = 0; row < srcHeight; row++) { + GLuint *dstUI = (GLuint *) dstRow; + for (col = 0; col < srcWidth; col++) { + dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]), + FLOAT_TO_BYTE_TEX(srcRow[GCOMP]), + FLOAT_TO_BYTE_TEX(srcRow[BCOMP]), + 0xff ); + srcRow += 4; + } + dstRow += dstRowStride; + } + } + free((void *) tempImage); + } + return GL_TRUE; +} + + + /** * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV */ @@ -2672,6 +2813,7 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS) return GL_TRUE; } + /** * Store a combined depth/stencil texture image. */ @@ -3197,9 +3339,18 @@ texstore_funcs[MESA_FORMAT_COUNT] = { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 }, { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 }, { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 }, + + { MESA_FORMAT_SIGNED_R8, _mesa_texstore_signed_r8 }, + { MESA_FORMAT_SIGNED_RG88, _mesa_texstore_signed_rg88 }, + { MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 }, + { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 }, { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 }, - { MESA_FORMAT_SIGNED_RGBA_16, NULL }, + + { MESA_FORMAT_SIGNED_R_16, NULL/*_mesa_texstore_signed_r16*/ }, + { MESA_FORMAT_SIGNED_RG_16, NULL/*_mesa_texstore_signed_rg16*/ }, + { MESA_FORMAT_SIGNED_RGB_16, NULL/*_mesa_texstore_signed_rgb16*/ }, + { MESA_FORMAT_SIGNED_RGBA_16, NULL/*_mesa_texstore_signed_rgba16*/ }, }; |