diff options
author | marha <marha@users.sourceforge.net> | 2011-09-09 08:40:24 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-09-09 08:40:24 +0200 |
commit | f9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4 (patch) | |
tree | f64cc9b70b0e0d7212d3b1e64f804a3dbc6cfa3b /mesalib/src/mesa | |
parent | 23a7aebae0a742d94ffe2304357dcc1234a99155 (diff) | |
download | vcxsrv-f9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4.tar.gz vcxsrv-f9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4.tar.bz2 vcxsrv-f9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4.zip |
mesa git update 9 sep 2011
Diffstat (limited to 'mesalib/src/mesa')
-rw-r--r-- | mesalib/src/mesa/SConscript | 1 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/driverfuncs.c | 2 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta.c | 492 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta.h | 7 | ||||
-rw-r--r-- | mesalib/src/mesa/main/compiler.h | 31 | ||||
-rw-r--r-- | mesalib/src/mesa/main/format_unpack.c | 1494 | ||||
-rw-r--r-- | mesalib/src/mesa/main/format_unpack.h | 49 | ||||
-rw-r--r-- | mesalib/src/mesa/main/formats.c | 64 | ||||
-rw-r--r-- | mesalib/src/mesa/main/formats.h | 7 | ||||
-rw-r--r-- | mesalib/src/mesa/main/mipmap.c | 85 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texcompress.c | 89 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texcompress.h | 5 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texgetimage.c | 177 | ||||
-rw-r--r-- | mesalib/src/mesa/sources.mak | 1 |
14 files changed, 2289 insertions, 215 deletions
diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript index 64b706534..dfc8bd441 100644 --- a/mesalib/src/mesa/SConscript +++ b/mesalib/src/mesa/SConscript @@ -72,6 +72,7 @@ main_sources = [ 'main/ffvertex_prog.c', 'main/fog.c', 'main/formats.c', + 'main/format_unpack.c', 'main/framebuffer.c', 'main/get.c', 'main/getstring.c', diff --git a/mesalib/src/mesa/drivers/common/driverfuncs.c b/mesalib/src/mesa/drivers/common/driverfuncs.c index 6484d284d..36ed4f892 100644 --- a/mesalib/src/mesa/drivers/common/driverfuncs.c +++ b/mesalib/src/mesa/drivers/common/driverfuncs.c @@ -94,7 +94,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver) driver->TexSubImage1D = _mesa_store_texsubimage1d; driver->TexSubImage2D = _mesa_store_texsubimage2d; driver->TexSubImage3D = _mesa_store_texsubimage3d; - driver->GetTexImage = _mesa_get_teximage; + driver->GetTexImage = _mesa_meta_GetTexImage; driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D; driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D; driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D; diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c index ad04d369f..2ebcd35bd 100644 --- a/mesalib/src/mesa/drivers/common/meta.c +++ b/mesalib/src/mesa/drivers/common/meta.c @@ -59,6 +59,7 @@ #include "main/stencil.h" #include "main/texobj.h" #include "main/texenv.h" +#include "main/texgetimage.h" #include "main/teximage.h" #include "main/texparam.h" #include "main/texstate.h" @@ -259,6 +260,18 @@ struct gen_mipmap_state GLuint FBO; }; + +/** + * State for texture decompression + */ +struct decompress_state +{ + GLuint ArrayObj; + GLuint VBO, FBO, RBO; + GLint Width, Height; +}; + + #define MAX_META_OPS_DEPTH 2 /** * All per-context meta state. @@ -278,6 +291,7 @@ struct gl_meta_state struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */ struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */ struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */ + struct decompress_state Decompress; /**< For texture decompression */ }; @@ -2477,6 +2491,160 @@ _mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target, /** + * Compute the texture coordinates for the four vertices of a quad for + * drawing a 2D texture image or slice of a cube/3D texture. + * \param faceTarget GL_TEXTURE_1D/2D/3D or cube face name + * \param slice slice of a 1D/2D array texture or 3D texture + * \param width width of the texture image + * \param height height of the texture image + * \param coords0/1/2/3 returns the computed texcoords + */ +static void +setup_texture_coords(GLenum faceTarget, + GLint slice, + GLint width, + GLint height, + GLfloat coords0[3], + GLfloat coords1[3], + GLfloat coords2[3], + GLfloat coords3[3]) +{ + static const GLfloat st[4][2] = { + {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f} + }; + GLuint i; + GLfloat r; + + switch (faceTarget) { + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_2D_ARRAY: + if (faceTarget == GL_TEXTURE_3D) + r = 1.0F / slice; + else if (faceTarget == GL_TEXTURE_2D_ARRAY) + r = slice; + else + r = 0.0F; + coords0[0] = 0.0F; /* s */ + coords0[1] = 0.0F; /* t */ + coords0[2] = r; /* r */ + coords1[0] = 1.0F; + coords1[1] = 0.0F; + coords1[2] = r; + coords2[0] = 1.0F; + coords2[1] = 1.0F; + coords2[2] = r; + coords3[0] = 0.0F; + coords3[1] = 1.0F; + coords3[2] = r; + break; + case GL_TEXTURE_RECTANGLE_ARB: + coords0[0] = 0.0F; /* s */ + coords0[1] = 0.0F; /* t */ + coords0[2] = 0.0F; /* r */ + coords1[0] = width; + coords1[1] = 0.0F; + coords1[2] = 0.0F; + coords2[0] = width; + coords2[1] = height; + coords2[2] = 0.0F; + coords3[0] = 0.0F; + coords3[1] = height; + coords3[2] = 0.0F; + break; + case GL_TEXTURE_1D_ARRAY: + coords0[0] = 0.0F; /* s */ + coords0[1] = slice; /* t */ + coords0[2] = 0.0F; /* r */ + coords1[0] = 1.0f; + coords1[1] = slice; + coords1[2] = 0.0F; + coords2[0] = 1.0F; + coords2[1] = slice; + coords2[2] = 0.0F; + coords3[0] = 0.0F; + coords3[1] = slice; + coords3[2] = 0.0F; + break; + + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + /* loop over quad verts */ + for (i = 0; i < 4; i++) { + /* Compute sc = +/-scale and tc = +/-scale. + * Not +/-1 to avoid cube face selection ambiguity near the edges, + * though that can still sometimes happen with this scale factor... + */ + const GLfloat scale = 0.9999f; + const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale; + const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale; + GLfloat *coord; + + switch (i) { + case 0: + coord = coords0; + break; + case 1: + coord = coords1; + break; + case 2: + coord = coords2; + break; + case 3: + coord = coords3; + break; + default: + assert(0); + } + + switch (faceTarget) { + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + coord[0] = 1.0f; + coord[1] = -tc; + coord[2] = -sc; + break; + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + coord[0] = -1.0f; + coord[1] = -tc; + coord[2] = sc; + break; + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + coord[0] = sc; + coord[1] = 1.0f; + coord[2] = tc; + break; + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + coord[0] = sc; + coord[1] = -1.0f; + coord[2] = -tc; + break; + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + coord[0] = sc; + coord[1] = -tc; + coord[2] = 1.0f; + break; + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + coord[0] = -sc; + coord[1] = -tc; + coord[2] = -1.0f; + break; + default: + assert(0); + } + } + break; + default: + assert(0 && "unexpected target in meta setup_texture_coords()"); + } +} + + +/** * Called via ctx->Driver.GenerateMipmap() * Note: We don't yet support 3D textures, 1D/2D array textures or texture * borders. @@ -2487,7 +2655,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, { struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap; struct vertex { - GLfloat x, y, s, t, r; + GLfloat x, y, tex[3]; }; struct vertex verts[4]; const GLuint baseLevel = texObj->BaseLevel; @@ -2503,7 +2671,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, const GLuint original_active_unit = ctx->Texture.CurrentUnit; GLenum faceTarget; GLuint dstLevel; - GLuint border = 0; + const GLuint border = 0; + const GLint slice = 0; if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) { _mesa_generate_mipmap(ctx, target, texObj); @@ -2539,7 +2708,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, /* setup vertex arrays */ _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); - _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(s)); + _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(tex)); _mesa_EnableClientState(GL_VERTEX_ARRAY); _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); } @@ -2562,98 +2731,27 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, _mesa_set_enable(ctx, target, GL_TRUE); - /* setup texcoords once (XXX what about border?) */ - switch (faceTarget) { - case GL_TEXTURE_1D: - case GL_TEXTURE_2D: - verts[0].s = 0.0F; - verts[0].t = 0.0F; - verts[0].r = 0.0F; - verts[1].s = 1.0F; - verts[1].t = 0.0F; - verts[1].r = 0.0F; - verts[2].s = 1.0F; - verts[2].t = 1.0F; - verts[2].r = 0.0F; - verts[3].s = 0.0F; - verts[3].t = 1.0F; - verts[3].r = 0.0F; - break; - case GL_TEXTURE_3D: - abort(); - break; - default: - /* cube face */ - { - static const GLfloat st[4][2] = { - {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f} - }; - GLuint i; - - /* loop over quad verts */ - for (i = 0; i < 4; i++) { - /* Compute sc = +/-scale and tc = +/-scale. - * Not +/-1 to avoid cube face selection ambiguity near the edges, - * though that can still sometimes happen with this scale factor... - */ - const GLfloat scale = 0.9999f; - const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale; - const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale; - - switch (faceTarget) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - verts[i].s = 1.0f; - verts[i].t = -tc; - verts[i].r = -sc; - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - verts[i].s = -1.0f; - verts[i].t = -tc; - verts[i].r = sc; - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - verts[i].s = sc; - verts[i].t = 1.0f; - verts[i].r = tc; - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - verts[i].s = sc; - verts[i].t = -1.0f; - verts[i].r = -tc; - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - verts[i].s = sc; - verts[i].t = -tc; - verts[i].r = 1.0f; - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - verts[i].s = -sc; - verts[i].t = -tc; - verts[i].r = -1.0f; - break; - default: - assert(0); - } - } - } - } - - _mesa_set_enable(ctx, target, GL_TRUE); + /* setup texcoords (XXX what about border?) */ + setup_texture_coords(faceTarget, + 0.0, 0.0, /* width, height never used here */ + slice, + verts[0].tex, + verts[1].tex, + verts[2].tex, + verts[3].tex); /* setup vertex positions */ - { - verts[0].x = 0.0F; - verts[0].y = 0.0F; - verts[1].x = 1.0F; - verts[1].y = 0.0F; - verts[2].x = 1.0F; - verts[2].y = 1.0F; - verts[3].x = 0.0F; - verts[3].y = 1.0F; + verts[0].x = 0.0F; + verts[0].y = 0.0F; + verts[1].x = 1.0F; + verts[1].y = 0.0F; + verts[2].x = 1.0F; + verts[2].y = 1.0F; + verts[3].x = 0.0F; + verts[3].y = 1.0F; - /* upload new vertex data */ - _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); - } + /* upload new vertex data */ + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); /* setup projection matrix */ _mesa_MatrixMode(GL_PROJECTION); @@ -2939,3 +3037,213 @@ _mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level, copy_tex_sub_image(ctx, 3, target, level, xoffset, yoffset, zoffset, x, y, width, height); } + + +/** + * Decompress a texture image by drawing a quad with the compressed + * texture and reading the pixels out of the color buffer. + * \param slice which slice of a 3D texture or layer of a 1D/2D texture + * \param destFormat format, ala glReadPixels + * \param destType type, ala glReadPixels + * \param dest destination buffer + * \param destRowLength dest image rowLength (ala GL_PACK_ROW_LENGTH) + */ +static void +decompress_texture_image(struct gl_context *ctx, + struct gl_texture_image *texImage, + GLuint slice, + GLenum destFormat, GLenum destType, + GLvoid *dest, GLint destRowLength) +{ + struct decompress_state *decompress = &ctx->Meta->Decompress; + struct gl_texture_object *texObj = texImage->TexObject; + const GLint width = texImage->Width; + const GLint height = texImage->Height; + const GLenum target = texObj->Target; + GLenum faceTarget; + struct vertex { + GLfloat x, y, tex[3]; + }; + struct vertex verts[4]; + GLuint fboDrawSave, fboReadSave; + + if (slice > 0) { + assert(target == GL_TEXTURE_3D || + target == GL_TEXTURE_2D_ARRAY); + } + + if (target == GL_TEXTURE_CUBE_MAP) { + faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + texImage->Face; + } + else { + faceTarget = target; + } + + /* save fbo bindings (not saved by _mesa_meta_begin()) */ + fboDrawSave = ctx->DrawBuffer->Name; + fboReadSave = ctx->ReadBuffer->Name; + + _mesa_meta_begin(ctx, MESA_META_ALL); + + /* Create/bind FBO/renderbuffer */ + if (decompress->FBO == 0) { + _mesa_GenFramebuffersEXT(1, &decompress->FBO); + _mesa_GenRenderbuffersEXT(1, &decompress->RBO); + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, decompress->FBO); + _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, decompress->RBO); + _mesa_FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_RENDERBUFFER_EXT, + decompress->RBO); + } + else { + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, decompress->FBO); + } + + /* alloc dest surface */ + if (width != decompress->Width || height != decompress->Height) { + _mesa_RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, + width, height); + decompress->Width = width; + decompress->Height = height; + } + + /* setup VBO data */ + if (decompress->ArrayObj == 0) { + /* create vertex array object */ + _mesa_GenVertexArrays(1, &decompress->ArrayObj); + _mesa_BindVertexArray(decompress->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &decompress->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, decompress->VBO); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + NULL, GL_DYNAMIC_DRAW_ARB); + + /* setup vertex arrays */ + _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(tex)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else { + _mesa_BindVertexArray(decompress->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, decompress->VBO); + } + + setup_texture_coords(faceTarget, slice, width, height, + verts[0].tex, + verts[1].tex, + verts[2].tex, + verts[3].tex); + + /* setup vertex positions */ + verts[0].x = 0.0F; + verts[0].y = 0.0F; + verts[1].x = width; + verts[1].y = 0.0F; + verts[2].x = width; + verts[2].y = height; + verts[3].x = 0.0F; + verts[3].y = height; + + /* upload new vertex data */ + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + + /* setup texture state */ + _mesa_BindTexture(target, texObj->Name); + _mesa_Enable(target); + + { + /* save texture object state */ + const GLenum minFilterSave = texObj->Sampler.MinFilter; + const GLenum magFilterSave = texObj->Sampler.MagFilter; + const GLint baseLevelSave = texObj->BaseLevel; + const GLint maxLevelSave = texObj->MaxLevel; + const GLenum wrapSSave = texObj->Sampler.WrapS; + const GLenum wrapTSave = texObj->Sampler.WrapT; + const GLenum srgbSave = texObj->Sampler.sRGBDecode; + + /* restrict sampling to the texture level of interest */ + _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, texImage->Level); + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, texImage->Level); + /* nearest filtering */ + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + /* No sRGB decode or encode.*/ + if (ctx->Extensions.EXT_texture_sRGB_decode) { + _mesa_TexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT, + GL_SKIP_DECODE_EXT); + } + if (ctx->Extensions.EXT_framebuffer_sRGB) { + _mesa_Disable(GL_FRAMEBUFFER_SRGB_EXT); + } + + /* render quad w/ texture into renderbuffer */ + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + /* Restore texture object state, the texture binding will + * be restored by _mesa_meta_end(). + */ + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave); + if (target != GL_TEXTURE_RECTANGLE_ARB) { + _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave); + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave); + } + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave); + if (ctx->Extensions.EXT_texture_sRGB_decode) { + _mesa_TexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT, srgbSave); + } + } + + /* read pixels from renderbuffer */ + ctx->Pack.RowLength = destRowLength; + _mesa_ReadPixels(0, 0, width, height, destFormat, destType, dest); + + _mesa_meta_end(ctx); + + /* restore fbo bindings */ + if (fboDrawSave == fboReadSave) { + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboDrawSave); + } + else { + _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fboDrawSave); + _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fboReadSave); + } +} + + +/** + * This is just a wrapper around _mesa_get_tex_image() and + * decompress_texture_image(). Meta functions should not be directly called + * from core Mesa. + */ +void +_mesa_meta_GetTexImage(struct gl_context *ctx, GLenum target, GLint level, + GLenum format, GLenum type, GLvoid *pixels, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) +{ + /* We can only use the decompress-with-blit method here if the texels are + * unsigned, normalized values. We could handle signed and unnormalized + * with floating point renderbuffers... + */ + if (_mesa_is_format_compressed(texImage->TexFormat) && + _mesa_get_format_datatype(texImage->TexFormat) + == GL_UNSIGNED_NORMALIZED) { + const GLuint slice = 0; /* only 2D compressed textures for now */ + /* Need to unlock the texture here to prevent deadlock... */ + _mesa_unlock_texture(ctx, texObj); + decompress_texture_image(ctx, texImage, slice, format, type, pixels, + ctx->Pack.RowLength); + /* ... and relock it */ + _mesa_lock_texture(ctx, texObj); + } + else { + _mesa_get_teximage(ctx, target, level, format, type, pixels, + texObj, texImage); + } +} diff --git a/mesalib/src/mesa/drivers/common/meta.h b/mesalib/src/mesa/drivers/common/meta.h index 9a92613c4..9d634ae56 100644 --- a/mesalib/src/mesa/drivers/common/meta.h +++ b/mesalib/src/mesa/drivers/common/meta.h @@ -121,4 +121,11 @@ _mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level, GLint x, GLint y, GLsizei width, GLsizei height); +extern void +_mesa_meta_GetTexImage(struct gl_context *ctx, GLenum target, GLint level, + GLenum format, GLenum type, GLvoid *pixels, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage); + + #endif /* META_H */ diff --git a/mesalib/src/mesa/main/compiler.h b/mesalib/src/mesa/main/compiler.h index 8ed1c6fa6..89d6cda91 100644 --- a/mesalib/src/mesa/main/compiler.h +++ b/mesalib/src/mesa/main/compiler.h @@ -114,29 +114,30 @@ extern "C" { /** * Function inlining */ -#ifndef INLINE -# if defined(__GNUC__) -# define INLINE __inline__ -# elif defined(__MSC__) -# define INLINE __inline +#ifndef inline +# ifdef __cplusplus + /* C++ supports inline keyword */ +# elif defined(__GNUC__) +# define inline __inline__ # elif defined(_MSC_VER) -# define INLINE __inline +# define inline __inline # elif defined(__ICL) -# define INLINE __inline +# define inline __inline # elif defined(__INTEL_COMPILER) -# define INLINE inline + /* Intel compiler supports inline keyword */ # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100) -# define INLINE __inline +# define inline __inline # elif defined(__SUNPRO_C) && defined(__C99FEATURES__) -# define INLINE inline -# define __inline inline -# define __inline__ inline -# elif (__STDC_VERSION__ >= 199901L) /* C99 */ -# define INLINE inline + /* C99 supports inline keyword */ +# elif (__STDC_VERSION__ >= 199901L) + /* C99 supports inline keyword */ # else -# define INLINE +# define inline # endif #endif +#ifndef INLINE +# define INLINE inline +#endif /** diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c new file mode 100644 index 000000000..c5146f72d --- /dev/null +++ b/mesalib/src/mesa/main/format_unpack.c @@ -0,0 +1,1494 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (c) 2011 VMware, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include "colormac.h" +#include "format_unpack.h" +#include "macros.h" +#include "../../gallium/auxiliary/util/u_format_rgb9e5.h" +#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" + + +/** + * 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) pow((cs + 0.055) / 1.055, 2.4); + } + } + tableReady = GL_TRUE; + } + return table[cs8]; +} + + +typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[4]); + + +static void +unpack_RGBA8888(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) ); + dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); + dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); + dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); +} + +static void +unpack_RGBA8888_REV(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); + dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); + dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); +} + +static void +unpack_ARGB8888(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); + dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); + dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); +} + +static void +unpack_ARGB8888_REV(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); + dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) ); + dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); +} + +static void +unpack_XRGB8888(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); + dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); + dst[ACOMP] = 1.0f; +} + +static void +unpack_XRGB8888_REV(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); + dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) ); + dst[ACOMP] = 1.0f; +} + +static void +unpack_RGB888(const void *src, GLfloat dst[4]) +{ + const GLubyte *s = (const GLubyte *) src; + dst[RCOMP] = UBYTE_TO_FLOAT( s[2] ); + dst[GCOMP] = UBYTE_TO_FLOAT( s[1] ); + dst[BCOMP] = UBYTE_TO_FLOAT( s[0] ); + dst[ACOMP] = 1.0F; +} + +static void +unpack_BGR888(const void *src, GLfloat dst[4]) +{ + const GLubyte *s = (const GLubyte *) src; + dst[RCOMP] = UBYTE_TO_FLOAT( s[0] ); + dst[GCOMP] = UBYTE_TO_FLOAT( s[1] ); + dst[BCOMP] = UBYTE_TO_FLOAT( s[2] ); + dst[ACOMP] = 1.0F; +} + +static void +unpack_RGB565(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F); + dst[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F); + dst[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F); + dst[ACOMP] = 1.0F; +} + +static void +unpack_RGB565_REV(const void *src, GLfloat dst[4]) +{ + GLushort s = *((const GLushort *) src); + s = (s >> 8) | (s << 8); /* byte swap */ + dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) ); + dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) ); + dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); + dst[ACOMP] = 1.0F; +} + +static void +unpack_ARGB4444(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F); + dst[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F); + dst[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F); + dst[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F); +} + +static void +unpack_ARGB4444_REV(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F); + dst[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F); + dst[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F); + dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F); +} + +static void +unpack_RGBA5551(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F); + dst[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F); + dst[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F); + dst[ACOMP] = ((s ) & 0x01) * 1.0F; +} + +static void +unpack_ARGB1555(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F); + dst[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F); + dst[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F); + dst[ACOMP] = ((s >> 15) & 0x01) * 1.0F; +} + +static void +unpack_ARGB1555_REV(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) ); + dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) ); + dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); + dst[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 ); +} + +static void +unpack_AL44(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = (s & 0xf) * (1.0F / 15.0F); + dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F); +} + +static void +unpack_AL88(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = UBYTE_TO_FLOAT( s & 0xff ); + dst[ACOMP] = UBYTE_TO_FLOAT( s >> 8 ); +} + +static void +unpack_AL88_REV(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = UBYTE_TO_FLOAT( s >> 8 ); + dst[ACOMP] = UBYTE_TO_FLOAT( s & 0xff ); +} + +static void +unpack_AL1616(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = USHORT_TO_FLOAT( s & 0xffff ); + dst[ACOMP] = USHORT_TO_FLOAT( s >> 16 ); +} + +static void +unpack_AL1616_REV(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = USHORT_TO_FLOAT( s >> 16 ); + dst[ACOMP] = USHORT_TO_FLOAT( s & 0xffff ); +} + +static void +unpack_RGB332(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F); + dst[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F); + dst[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F); + dst[ACOMP] = 1.0F; +} + + +static void +unpack_A8(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = 0.0F; + dst[ACOMP] = UBYTE_TO_FLOAT(s); +} + +static void +unpack_A16(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = 0.0F; + dst[ACOMP] = USHORT_TO_FLOAT(s); +} + +static void +unpack_L8(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = UBYTE_TO_FLOAT(s); + dst[ACOMP] = 1.0F; +} + +static void +unpack_L16(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = USHORT_TO_FLOAT(s); + dst[ACOMP] = 1.0F; +} + +static void +unpack_I8(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = + dst[ACOMP] = UBYTE_TO_FLOAT(s); +} + +static void +unpack_I16(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = + dst[ACOMP] = USHORT_TO_FLOAT(s); +} + +static void +unpack_YCBCR(const void *src, GLfloat dst[4]) +{ + const GLuint i = 0; + const GLushort *src0 = (const GLushort *) src; + const GLushort *src1 = src0 + 1; /* odd */ + const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */ + const GLubyte cb = *src0 & 0xff; /* chroma U */ + const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */ + const GLubyte cr = *src1 & 0xff; /* chroma V */ + const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */ + GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128); + GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128); + GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128); + r *= (1.0F / 255.0F); + g *= (1.0F / 255.0F); + b *= (1.0F / 255.0F); + dst[RCOMP] = CLAMP(r, 0.0F, 1.0F); + dst[GCOMP] = CLAMP(g, 0.0F, 1.0F); + dst[BCOMP] = CLAMP(b, 0.0F, 1.0F); + dst[ACOMP] = 1.0F; +} + +static void +unpack_YCBCR_REV(const void *src, GLfloat dst[4]) +{ + const GLuint i = 0; + const GLushort *src0 = (const GLushort *) src; + const GLushort *src1 = src0 + 1; /* odd */ + const GLubyte y0 = *src0 & 0xff; /* luminance */ + const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */ + const GLubyte y1 = *src1 & 0xff; /* luminance */ + const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */ + const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */ + GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128); + GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128); + GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128); + r *= (1.0F / 255.0F); + g *= (1.0F / 255.0F); + b *= (1.0F / 255.0F); + dst[RCOMP] = CLAMP(r, 0.0F, 1.0F); + dst[GCOMP] = CLAMP(g, 0.0F, 1.0F); + dst[BCOMP] = CLAMP(b, 0.0F, 1.0F); + dst[ACOMP] = 1.0F; +} + +static void +unpack_R8(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[0] = UBYTE_TO_FLOAT(s); + dst[1] = dst[2] = 0.0F; + dst[3] = 1.0F; +} + +static void +unpack_RG88(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 ); + dst[BCOMP] = 0.0; + dst[ACOMP] = 1.0; +} + +static void +unpack_RG88_REV(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff ); + dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 ); + dst[BCOMP] = 0.0; + dst[ACOMP] = 1.0; +} + +static void +unpack_R16(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = USHORT_TO_FLOAT(s); + dst[GCOMP] = 0.0; + dst[BCOMP] = 0.0; + dst[ACOMP] = 1.0; +} + +static void +unpack_RG1616(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = USHORT_TO_FLOAT( s & 0xffff ); + dst[GCOMP] = USHORT_TO_FLOAT( s >> 16 ); + dst[BCOMP] = 0.0; + dst[ACOMP] = 1.0; +} + +static void +unpack_RG1616_REV(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = USHORT_TO_FLOAT( s >> 16 ); + dst[GCOMP] = USHORT_TO_FLOAT( s & 0xffff ); + dst[BCOMP] = 0.0; + dst[ACOMP] = 1.0; +} + +static void +unpack_ARGB2101010(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F); + dst[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F); + dst[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F); + dst[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F); +} + + +static void +unpack_Z24_S8(const void *src, GLfloat dst[4]) +{ + /* only return Z, not stencil data */ + const GLuint s = *((const GLuint *) src); + const GLfloat scale = 1.0F / (GLfloat) 0xffffff; + dst[0] = dst[1] = dst[2] = (s >> 8) * scale; + dst[3] = 1.0F; + ASSERT(dst[0] >= 0.0F); + ASSERT(dst[0] <= 1.0F); +} + +static void +unpack_S8_Z24(const void *src, GLfloat dst[4]) +{ + /* only return Z, not stencil data */ + const GLuint s = *((const GLuint *) src); + const GLfloat scale = 1.0F / (GLfloat) 0xffffff; + dst[0] = dst[1] = dst[2] = (s & 0x00ffffff) * scale; + dst[3] = 1.0F; + ASSERT(dst[0] >= 0.0F); + ASSERT(dst[0] <= 1.0F); +} + +static void +unpack_Z16(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[0] = dst[1] = dst[2] = s * (1.0F / 65535.0F); + dst[3] = 1.0F; +} + +static void +unpack_X8_Z24(const void *src, GLfloat dst[4]) +{ + unpack_S8_Z24(src, dst); +} + +static void +unpack_Z24_X8(const void *src, GLfloat dst[4]) +{ + unpack_Z24_S8(src, dst); +} + +static void +unpack_Z32(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[0] = dst[1] = dst[2] = s * (1.0F / 0xffffffff); + dst[3] = 1.0F; +} + +static void +unpack_Z32_FLOAT(const void *src, GLfloat dst[4]) +{ + const GLfloat s = *((const GLfloat *) src); + dst[0] = dst[1] = dst[2] = s; + dst[3] = 1.0F; +} + +static void +unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[4]) +{ + const GLfloat s = *((const GLfloat *) src); + dst[0] = dst[1] = dst[2] = s; + dst[3] = 1.0F; +} + + +static void +unpack_S8(const void *src, GLfloat dst[4]) +{ + /* should never be used */ + dst[0] = dst[1] = dst[2] = 0.0F; + dst[3] = 1.0F; +} + + +static void +unpack_SRGB8(const void *src, GLfloat dst[4]) +{ + const GLubyte *s = (const GLubyte *) src; + dst[RCOMP] = nonlinear_to_linear(s[2]); + dst[GCOMP] = nonlinear_to_linear(s[1]); + dst[BCOMP] = nonlinear_to_linear(s[0]); + dst[ACOMP] = 1.0F; +} + +static void +unpack_SRGBA8(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = nonlinear_to_linear( (s >> 24) ); + dst[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); + dst[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); + dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */ +} + +static void +unpack_SARGB8(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); + dst[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); + dst[BCOMP] = nonlinear_to_linear( (s ) & 0xff ); + dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */ +} + +static void +unpack_SL8(const void *src, GLfloat dst[4]) +{ + const GLubyte s = *((const GLubyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = nonlinear_to_linear(s); + dst[ACOMP] = 1.0F; +} + +static void +unpack_SLA8(const void *src, GLfloat dst[4]) +{ + const GLubyte *s = (const GLubyte *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = nonlinear_to_linear(s[0]); + dst[ACOMP] = UBYTE_TO_FLOAT(s[1]); /* linear */ +} + +static void +unpack_SRGB_DXT1(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_SRGBA_DXT1(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_SRGBA_DXT3(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_SRGBA_DXT5(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_RGB_FXT1(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_RGBA_FXT1(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_RGB_DXT1(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_RGBA_DXT1(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_RGBA_DXT3(const void *src, GLfloat dst[4]) +{ +} + +static void +unpack_RGBA_DXT5(const void *src, GLfloat dst[4]) +{ +} + + +static void +unpack_RGBA_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = s[0]; + dst[GCOMP] = s[1]; + dst[BCOMP] = s[2]; + dst[ACOMP] = s[3]; +} + +static void +unpack_RGBA_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = _mesa_half_to_float(s[0]); + dst[GCOMP] = _mesa_half_to_float(s[1]); + dst[BCOMP] = _mesa_half_to_float(s[2]); + dst[ACOMP] = _mesa_half_to_float(s[3]); +} + +static void +unpack_RGB_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = s[0]; + dst[GCOMP] = s[1]; + dst[BCOMP] = s[2]; + dst[ACOMP] = 1.0F; +} + +static void +unpack_RGB_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = _mesa_half_to_float(s[0]); + dst[GCOMP] = _mesa_half_to_float(s[1]); + dst[BCOMP] = _mesa_half_to_float(s[2]); + dst[ACOMP] = 1.0F; +} + +static void +unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = 0.0F; + dst[ACOMP] = s[0]; +} + +static void +unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = 0.0F; + dst[ACOMP] = _mesa_half_to_float(s[0]); +} + +static void +unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = s[0]; + dst[ACOMP] = 1.0F; +} + +static void +unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = _mesa_half_to_float(s[0]); + dst[ACOMP] = 1.0F; +} + +static void +unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = s[0]; + dst[ACOMP] = s[1]; +} + +static void +unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = _mesa_half_to_float(s[0]); + dst[ACOMP] = _mesa_half_to_float(s[1]); +} + +static void +unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = + dst[ACOMP] = s[0]; +} + +static void +unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = + dst[ACOMP] = s[0]; +} + +static void +unpack_R_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = s[0]; + dst[GCOMP] = 0.0F; + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + +static void +unpack_R_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = _mesa_half_to_float(s[0]); + dst[GCOMP] = 0.0F; + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + +static void +unpack_RG_FLOAT32(const void *src, GLfloat dst[4]) +{ + const GLfloat *s = (const GLfloat *) src; + dst[RCOMP] = s[0]; + dst[GCOMP] = s[1]; + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + +static void +unpack_RG_FLOAT16(const void *src, GLfloat dst[4]) +{ + const GLhalfARB *s = (const GLhalfARB *) src; + dst[RCOMP] = _mesa_half_to_float(s[0]); + dst[GCOMP] = _mesa_half_to_float(s[1]); + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + + +static void +unpack_RGBA_INT8(const void *src, GLfloat dst[4]) +{ + const GLbyte *s = (const GLbyte *) src; + dst[RCOMP] = (GLfloat) s[0]; + dst[GCOMP] = (GLfloat) s[1]; + dst[BCOMP] = (GLfloat) s[2]; + dst[ACOMP] = (GLfloat) s[3]; +} + +static void +unpack_RGBA_INT16(const void *src, GLfloat dst[4]) +{ + const GLshort *s = (const GLshort *) src; + dst[RCOMP] = (GLfloat) s[0]; + dst[GCOMP] = (GLfloat) s[1]; + dst[BCOMP] = (GLfloat) s[2]; + dst[ACOMP] = (GLfloat) s[3]; +} + +static void +unpack_RGBA_INT32(const void *src, GLfloat dst[4]) +{ + const GLint *s = (const GLint *) src; + dst[RCOMP] = (GLfloat) s[0]; + dst[GCOMP] = (GLfloat) s[1]; + dst[BCOMP] = (GLfloat) s[2]; + dst[ACOMP] = (GLfloat) s[3]; +} + +static void +unpack_RGBA_UINT8(const void *src, GLfloat dst[4]) +{ + const GLubyte *s = (const GLubyte *) src; + dst[RCOMP] = (GLfloat) s[0]; + dst[GCOMP] = (GLfloat) s[1]; + dst[BCOMP] = (GLfloat) s[2]; + dst[ACOMP] = (GLfloat) s[3]; +} + +static void +unpack_RGBA_UINT16(const void *src, GLfloat dst[4]) +{ + const GLushort *s = (const GLushort *) src; + dst[RCOMP] = (GLfloat) s[0]; + dst[GCOMP] = (GLfloat) s[1]; + dst[BCOMP] = (GLfloat) s[2]; + dst[ACOMP] = (GLfloat) s[3]; +} + +static void +unpack_RGBA_UINT32(const void *src, GLfloat dst[4]) +{ + const GLuint *s = (const GLuint *) src; + dst[RCOMP] = (GLfloat) s[0]; + dst[GCOMP] = (GLfloat) s[1]; + dst[BCOMP] = (GLfloat) s[2]; + dst[ACOMP] = (GLfloat) s[3]; +} + +static void +unpack_DUDV8(const void *src, GLfloat dst[4]) +{ + const GLbyte *s = (const GLbyte *) src; + dst[RCOMP] = BYTE_TO_FLOAT(s[0]); + dst[GCOMP] = BYTE_TO_FLOAT(s[1]); + dst[BCOMP] = 0; + dst[ACOMP] = 0; +} + +static void +unpack_SIGNED_R8(const void *src, GLfloat dst[4]) +{ + const GLbyte s = *((const GLbyte *) src); + dst[RCOMP] = BYTE_TO_FLOAT_TEX( s ); + dst[GCOMP] = 0.0F; + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + +static void +unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLushort *) src); + dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) ); + dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + +static void +unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); + dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); + dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + dst[ACOMP] = 1.0f; +} + +static void +unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); + dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); + dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) ); +} + +static void +unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[4]) +{ + const GLuint s = *((const GLuint *) src); + dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) ); + dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); + dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); +} + +static void +unpack_SIGNED_R16(const void *src, GLfloat dst[4]) +{ + const GLshort s = *((const GLshort *) src); + dst[RCOMP] = SHORT_TO_FLOAT_TEX( s ); + dst[GCOMP] = 0.0F; + dst[BCOMP] = 0.0F; + dst[ACOMP] = 1.0F; +} + +static void +unpack_SIGNED_GR1616(const void *src, GLfloat dst[4]) +{ + /* XXX TODO */ +} + +static void +unpack_SIGNED_RGB_16(const void *src, GLfloat dst[4]) +{ + const GLshort *s = (const GLshort *) src; + dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); + dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); + dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] ); + dst[ACOMP] = 1.0F; +} + +static void +unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[4]) +{ + const GLshort *s = (const GLshort *) src; + dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); + dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); + dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] ); + dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] ); +} + +static void +unpack_RGBA_16(const void *src, GLfloat dst[4]) +{ + const GLshort *s = (const GLshort *) src; + dst[RCOMP] = USHORT_TO_FLOAT( s[0] ); + dst[GCOMP] = USHORT_TO_FLOAT( s[1] ); + dst[BCOMP] = USHORT_TO_FLOAT( s[2] ); + dst[ACOMP] = USHORT_TO_FLOAT( s[3] ); +} + +static void +unpack_RED_RGTC1(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_RG_RGTC2(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_L_LATC1(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_LA_LATC2(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[4]) +{ + /* XXX to do */ +} + +static void +unpack_SIGNED_A8(const void *src, GLfloat dst[4]) +{ + const GLbyte s = *((const GLbyte *) src); + dst[RCOMP] = 0.0F; + dst[GCOMP] = 0.0F; + dst[BCOMP] = 0.0F; + dst[ACOMP] = BYTE_TO_FLOAT_TEX( s ); +} + +static void +unpack_SIGNED_L8(const void *src, GLfloat dst[4]) +{ + const GLbyte s = *((const GLbyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = BYTE_TO_FLOAT_TEX( s ); + dst[ACOMP] = 1.0F; +} + +static void +unpack_SIGNED_AL88(const void *src, GLfloat dst[4]) +{ + const GLushort s = *((const GLshort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) ); + dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); +} + +static void +unpack_SIGNED_I8(const void *src, GLfloat dst[4]) +{ + const GLbyte s = *((const GLbyte *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = + dst[ACOMP] = BYTE_TO_FLOAT_TEX( s ); +} + +static void +unpack_SIGNED_A16(const void *src, GLfloat dst[4]) +{ + const GLshort s = *((const GLshort *) src); + dst[RCOMP] = 0.0F; + dst[GCOMP] = 0.0F; + dst[BCOMP] = 0.0F; + dst[ACOMP] = SHORT_TO_FLOAT_TEX( s ); +} + +static void +unpack_SIGNED_L16(const void *src, GLfloat dst[4]) +{ + const GLshort s = *((const GLshort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = SHORT_TO_FLOAT_TEX( s ); + dst[ACOMP] = 1.0F; +} + +static void +unpack_SIGNED_AL1616(const void *src, GLfloat dst[4]) +{ + const GLshort *s = (const GLshort *) src; + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); + dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] ); +} + +static void +unpack_SIGNED_I16(const void *src, GLfloat dst[4]) +{ + const GLshort s = *((const GLshort *) src); + dst[RCOMP] = + dst[GCOMP] = + dst[BCOMP] = + dst[ACOMP] = SHORT_TO_FLOAT_TEX( s ); +} + +static void +unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[4]) +{ + const GLuint *s = (const GLuint *) src; + rgb9e5_to_float3(*s, dst); + dst[ACOMP] = 1.0F; +} + +static void +unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[4]) +{ + const GLuint *s = (const GLuint *) src; + r11g11b10f_to_float3(*s, dst); + dst[ACOMP] = 1.0F; +} + + +/** + * Return the unpacker function for the given format. + */ +static unpack_rgba_func +get_unpack_rgba_function(gl_format format) +{ + static unpack_rgba_func table[MESA_FORMAT_COUNT]; + static GLboolean initialized = GL_FALSE; + + if (!initialized) { + table[MESA_FORMAT_NONE] = NULL; + + table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888; + table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV; + table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888; + table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV; + table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888; + table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV; + table[MESA_FORMAT_RGB888] = unpack_RGB888; + table[MESA_FORMAT_BGR888] = unpack_BGR888; + table[MESA_FORMAT_RGB565] = unpack_RGB565; + table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV; + table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444; + table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV; + table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551; + table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555; + table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV; + table[MESA_FORMAT_AL44] = unpack_AL44; + table[MESA_FORMAT_AL88] = unpack_AL88; + table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV; + table[MESA_FORMAT_AL1616] = unpack_AL1616; + table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV; + table[MESA_FORMAT_RGB332] = unpack_RGB332; + table[MESA_FORMAT_A8] = unpack_A8; + table[MESA_FORMAT_A16] = unpack_A16; + table[MESA_FORMAT_L8] = unpack_L8; + table[MESA_FORMAT_L16] = unpack_L16; + table[MESA_FORMAT_I8] = unpack_I8; + table[MESA_FORMAT_I16] = unpack_I16; + table[MESA_FORMAT_YCBCR] = unpack_YCBCR; + table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV; + table[MESA_FORMAT_R8] = unpack_R8; + table[MESA_FORMAT_RG88] = unpack_RG88; + table[MESA_FORMAT_RG88_REV] = unpack_RG88_REV; + table[MESA_FORMAT_R16] = unpack_R16; + table[MESA_FORMAT_RG1616] = unpack_RG1616; + table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV; + table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010; + table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8; + table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24; + table[MESA_FORMAT_Z16] = unpack_Z16; + table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24; + table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8; + table[MESA_FORMAT_Z32] = unpack_Z32; + table[MESA_FORMAT_S8] = unpack_S8; + table[MESA_FORMAT_SRGB8] = unpack_SRGB8; + table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8; + table[MESA_FORMAT_SARGB8] = unpack_SARGB8; + table[MESA_FORMAT_SL8] = unpack_SL8; + table[MESA_FORMAT_SLA8] = unpack_SLA8; + table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1; + table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1; + table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3; + table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5; + + table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1; + table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1; + table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1; + table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1; + table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3; + table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5; + + table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32; + table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16; + table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32; + table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16; + table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32; + table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16; + table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32; + table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16; + table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32; + table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16; + table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32; + table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16; + table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32; + table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16; + table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32; + table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16; + + table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8; + table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16; + table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32; + table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8; + table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16; + table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32; + + table[MESA_FORMAT_DUDV8] = unpack_DUDV8; + table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8; + table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV; + table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888; + table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888; + table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV; + table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16; + table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616; + table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16; + table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16; + table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16; + + table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1; + table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1; + table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2; + table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2; + + table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1; + table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1; + table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2; + table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2; + + table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8; + table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8; + table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88; + table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8; + table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16; + table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16; + table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616; + table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16; + + table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT; + table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT; + + table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT; + table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8; + + initialized = GL_TRUE; + } + + return table[format]; +} + + +void +_mesa_unpack_rgba_row(gl_format format, GLuint n, + const void *src, GLfloat dst[][4]) +{ + unpack_rgba_func unpack = get_unpack_rgba_function(format); + GLuint srcStride = _mesa_get_format_bytes(format); + const GLubyte *srcPtr = (GLubyte *) src; + GLuint i; + + for (i = 0; i < n; i++) { + unpack(srcPtr, dst[i]); + srcPtr += srcStride; + } +} + + + +/** + * Unpack a 2D rect of pixels returning float RGBA colors. + * \param format the source image format + * \param src start address of the source image + * \param srcRowStride source image row stride in bytes + * \param dst start address of the dest image + * \param dstRowStride dest image row stride in bytes + * \param x source image start X pos + * \param y source image start Y pos + * \param width width of rect region to convert + * \param height height of rect region to convert + */ +void +_mesa_unpack_rgba_block(gl_format format, + const void *src, GLint srcRowStride, + GLfloat dst[][4], GLint dstRowStride, + GLuint x, GLuint y, GLuint width, GLuint height) +{ + unpack_rgba_func unpack = get_unpack_rgba_function(format); + const GLuint srcPixStride = _mesa_get_format_bytes(format); + const GLuint dstPixStride = 4 * sizeof(GLfloat); + const GLubyte *srcRow, *srcPix; + GLubyte *dstRow; + GLfloat *dstPix; + GLuint i, j; + + /* XXX needs to be fixed for compressed formats */ + + srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x; + dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x; + + for (i = 0; i < height; i++) { + srcPix = srcRow; + dstPix = (GLfloat *) dstRow; + + for (j = 0; j < width; j++) { + unpack(srcPix, dstPix); + srcPix += srcPixStride; + dstPix += dstPixStride; + } + + dstRow += dstRowStride; + srcRow += srcRowStride; + } +} + + + + +typedef void (*unpack_float_z_func)(const void *src, GLfloat *dst); + +static void +unpack_float_z_Z24_S8(const void *src, GLfloat *dst) +{ + /* only return Z, not stencil data */ + const GLuint s = *((const GLuint *) src); + const GLfloat scale = 1.0F / (GLfloat) 0xffffff; + *dst = (s >> 8) * scale; + ASSERT(*dst >= 0.0F); + ASSERT(*dst <= 1.0F); +} + +static void +unpack_float_z_S8_Z24(const void *src, GLfloat *dst) +{ + /* only return Z, not stencil data */ + const GLuint s = *((const GLuint *) src); + const GLfloat scale = 1.0F / (GLfloat) 0xffffff; + *dst = (s & 0x00ffffff) * scale; + ASSERT(*dst >= 0.0F); + ASSERT(*dst <= 1.0F); +} + +static void +unpack_float_z_Z16(const void *src, GLfloat *dst) +{ + const GLushort s = *((const GLushort *) src); + *dst = s * (1.0F / 65535.0F); +} + +static void +unpack_float_z_X8_Z24(const void *src, GLfloat *dst) +{ + unpack_float_z_S8_Z24(src, dst); +} + +static void +unpack_float_z_Z24_X8(const void *src, GLfloat *dst) +{ + unpack_float_z_Z24_S8(src, dst); +} + +static void +unpack_float_z_Z32(const void *src, GLfloat *dst) +{ + const GLuint s = *((const GLuint *) src); + *dst = s * (1.0F / 0xffffffff); +} + +static void +unpack_float_z_Z32X24S8(const void *src, GLfloat *dst) +{ + *dst = *((const GLfloat *) src); +} + + + +void +_mesa_unpack_float_z_row(gl_format format, GLuint n, + const void *src, GLfloat *dst) +{ + unpack_float_z_func unpack; + GLuint srcStride = _mesa_get_format_bytes(format); + const GLubyte *srcPtr = (GLubyte *) src; + GLuint i; + + switch (format) { + case MESA_FORMAT_Z24_S8: + unpack = unpack_float_z_Z24_S8; + break; + case MESA_FORMAT_S8_Z24: + unpack = unpack_float_z_S8_Z24; + break; + case MESA_FORMAT_Z16: + unpack = unpack_float_z_Z16; + break; + case MESA_FORMAT_X8_Z24: + unpack = unpack_float_z_X8_Z24; + break; + case MESA_FORMAT_Z24_X8: + unpack = unpack_float_z_Z24_X8; + break; + case MESA_FORMAT_Z32: + unpack = unpack_float_z_Z32; + break; + case MESA_FORMAT_Z32_FLOAT_X24S8: + unpack = unpack_float_z_Z32X24S8; + break; + default: + _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row", + _mesa_get_format_name(format)); + return; + } + + for (i = 0; i < n; i++) { + unpack(srcPtr, &dst[i]); + srcPtr += srcStride; + } +} + + + +typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst); + +static void +unpack_uint_z_Z24_S8(const void *src, GLuint *dst) +{ + /* only return Z, not stencil data */ + const GLuint s = *((const GLuint *) src); + *dst = (s >> 8); +} + +static void +unpack_uint_z_S8_Z24(const void *src, GLuint *dst) +{ + /* only return Z, not stencil data */ + const GLuint s = *((const GLuint *) src); + *dst = s & 0x00ffffff; +} + +static void +unpack_uint_z_Z16(const void *src, GLuint *dst) +{ + *dst = *((const GLushort *) src); +} + +static void +unpack_uint_z_X8_Z24(const void *src, GLuint *dst) +{ + unpack_uint_z_S8_Z24(src, dst); +} + +static void +unpack_uint_z_Z24_X8(const void *src, GLuint *dst) +{ + unpack_uint_z_Z24_S8(src, dst); +} + +static void +unpack_uint_z_Z32(const void *src, GLuint *dst) +{ + *dst = *((const GLuint *) src); +} + + +void +_mesa_unpack_uint_z_row(gl_format format, GLuint n, + const void *src, GLuint *dst) +{ + unpack_uint_z_func unpack; + GLuint srcStride = _mesa_get_format_bytes(format); + const GLubyte *srcPtr = (GLubyte *) src; + GLuint i; + + switch (format) { + case MESA_FORMAT_Z24_S8: + unpack = unpack_uint_z_Z24_S8; + break; + case MESA_FORMAT_S8_Z24: + unpack = unpack_uint_z_S8_Z24; + break; + case MESA_FORMAT_Z16: + unpack = unpack_uint_z_Z16; + break; + case MESA_FORMAT_X8_Z24: + unpack = unpack_uint_z_X8_Z24; + break; + case MESA_FORMAT_Z24_X8: + unpack = unpack_uint_z_Z24_X8; + break; + case MESA_FORMAT_Z32: + unpack = unpack_uint_z_Z32; + break; + default: + _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row", + _mesa_get_format_name(format)); + return; + } + + for (i = 0; i < n; i++) { + unpack(srcPtr, &dst[i]); + srcPtr += srcStride; + } +} + + diff --git a/mesalib/src/mesa/main/format_unpack.h b/mesalib/src/mesa/main/format_unpack.h new file mode 100644 index 000000000..c37727d91 --- /dev/null +++ b/mesalib/src/mesa/main/format_unpack.h @@ -0,0 +1,49 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (c) 2011 VMware, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef FORMAT_UNPACK_H +#define FORMAT_UNPACK_H + +extern void +_mesa_unpack_rgba_row(gl_format format, GLuint n, + const void *src, GLfloat dst[][4]); + + +extern void +_mesa_unpack_rgba_block(gl_format format, + const void *src, GLint srcRowStride, + GLfloat dst[][4], GLint dstRowStride, + GLuint x, GLuint y, GLuint width, GLuint height); + + +extern void +_mesa_unpack_float_z_row(gl_format format, GLuint n, + const void *src, GLfloat *dst); + + +void +_mesa_unpack_uint_z_row(gl_format format, GLuint n, + const void *src, GLuint *dst); + + +#endif /* FORMAT_UNPACK_H */ diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c index c6634c458..11d670689 100644 --- a/mesalib/src/mesa/main/formats.c +++ b/mesalib/src/mesa/main/formats.c @@ -1343,6 +1343,70 @@ _mesa_get_srgb_format_linear(gl_format format) /** + * If the given format is a compressed format, return a corresponding + * uncompressed format. + */ +gl_format +_mesa_get_uncompressed_format(gl_format format) +{ + switch (format) { + case MESA_FORMAT_RGB_FXT1: + return MESA_FORMAT_RGB888; + case MESA_FORMAT_RGBA_FXT1: + return MESA_FORMAT_RGBA8888; + case MESA_FORMAT_RGB_DXT1: + case MESA_FORMAT_SRGB_DXT1: + return MESA_FORMAT_RGB888; + case MESA_FORMAT_RGBA_DXT1: + case MESA_FORMAT_SRGBA_DXT1: + return MESA_FORMAT_RGBA8888; + case MESA_FORMAT_RGBA_DXT3: + case MESA_FORMAT_SRGBA_DXT3: + return MESA_FORMAT_RGBA8888; + case MESA_FORMAT_RGBA_DXT5: + case MESA_FORMAT_SRGBA_DXT5: + return MESA_FORMAT_RGBA8888; + case MESA_FORMAT_RED_RGTC1: + return MESA_FORMAT_R8; + case MESA_FORMAT_SIGNED_RED_RGTC1: + return MESA_FORMAT_SIGNED_R8; + case MESA_FORMAT_RG_RGTC2: + return MESA_FORMAT_RG88; + case MESA_FORMAT_SIGNED_RG_RGTC2: + return MESA_FORMAT_SIGNED_RG88_REV; + case MESA_FORMAT_L_LATC1: + return MESA_FORMAT_L8; + case MESA_FORMAT_SIGNED_L_LATC1: + return MESA_FORMAT_SIGNED_L8; + case MESA_FORMAT_LA_LATC2: + return MESA_FORMAT_AL88; + case MESA_FORMAT_SIGNED_LA_LATC2: + return MESA_FORMAT_SIGNED_AL88; + default: +#ifdef DEBUG + assert(!_mesa_is_format_compressed(format)); +#endif + return format; + } +} + + +GLuint +_mesa_format_num_components(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + return ((info->RedBits > 0) + + (info->GreenBits > 0) + + (info->BlueBits > 0) + + (info->AlphaBits > 0) + + (info->LuminanceBits > 0) + + (info->IntensityBits > 0) + + (info->DepthBits > 0) + + (info->StencilBits > 0)); +} + + +/** * Return number of bytes needed to store an image of the given size * in the given format. */ diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h index 75d93deba..610204cb3 100644 --- a/mesalib/src/mesa/main/formats.h +++ b/mesalib/src/mesa/main/formats.h @@ -266,4 +266,11 @@ _mesa_test_formats(void); extern gl_format _mesa_get_srgb_format_linear(gl_format format); +extern gl_format +_mesa_get_uncompressed_format(gl_format format); + +extern GLuint +_mesa_format_num_components(gl_format format); + + #endif /* FORMATS_H */ diff --git a/mesalib/src/mesa/main/mipmap.c b/mesalib/src/mesa/main/mipmap.c index cf9d522f2..869243d1c 100644 --- a/mesalib/src/mesa/main/mipmap.c +++ b/mesalib/src/mesa/main/mipmap.c @@ -1985,50 +1985,45 @@ generate_mipmap_uncompressed(struct gl_context *ctx, GLenum target, static void generate_mipmap_compressed(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj, - const struct gl_texture_image *srcImage, + struct gl_texture_image *srcImage, GLuint maxLevel) { GLint level; gl_format temp_format; - GLenum datatype; - GLuint comps; - GLuint row; GLint components; GLuint temp_src_stride, temp_dst_stride; /* in bytes */ GLchan *temp_src = NULL, *temp_dst = NULL; + GLenum temp_datatype; + GLenum temp_base_format; - /* Choose the format we will do _mesa_generate_mipmap_level() in, - * and uncompress the firstImage into a temporary of that format. - */ + /* only two types of compressed textures at this time */ assert(texObj->Target == GL_TEXTURE_2D || texObj->Target == GL_TEXTURE_CUBE_MAP_ARB); - if (srcImage->_BaseFormat == GL_RGB) { - temp_format = MESA_FORMAT_RGB888; - components = 3; - } else if (srcImage->_BaseFormat == GL_RED) { - temp_format = MESA_FORMAT_R8; - components = 1; - } else if (srcImage->_BaseFormat == GL_RG) { - temp_format = MESA_FORMAT_RG88; - components = 2; - } else if (srcImage->_BaseFormat == GL_RGBA) { - temp_format = MESA_FORMAT_RGBA8888; - components = 4; - } else if (srcImage->_BaseFormat == GL_LUMINANCE) { - temp_format = MESA_FORMAT_L8; - components = 1; - } else if (srcImage->_BaseFormat == GL_LUMINANCE_ALPHA) { - temp_format = MESA_FORMAT_AL88; - components = 2; - } else { - _mesa_problem(ctx, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps"); - return; + /* + * Choose a format for the temporary, uncompressed base image. + * Then, get number of components, choose temporary image datatype, + * and get base format. + */ + temp_format = _mesa_get_uncompressed_format(srcImage->TexFormat); + + components = _mesa_format_num_components(temp_format); + + /* Revisit this if we get compressed formats with >8 bits per component */ + if (_mesa_get_format_datatype(srcImage->TexFormat) + == GL_SIGNED_NORMALIZED) { + temp_datatype = GL_BYTE; + } + else { + temp_datatype = GL_UNSIGNED_BYTE; } - /* allocate storage for uncompressed GL_RGB or GL_RGBA images */ - temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width); + temp_base_format = _mesa_get_format_base_format(temp_format); + + + /* allocate storage for the temporary, uncompressed image */ /* 20 extra bytes, just be safe when calling last FetchTexel */ + temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width); temp_src = (GLubyte *) malloc(temp_src_stride * srcImage->Height + 20); if (!temp_src) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps"); @@ -2036,16 +2031,20 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target, } /* decompress base image to the temporary */ - for (row = 0; row < srcImage->Height; row++) { - GLuint col; - GLchan *dst = (GLchan *) temp_src + temp_src_stride * row; - for (col = 0; col < srcImage->Width; col++) { - srcImage->FetchTexelc(srcImage, col, row, 0, dst); - dst += components; - } + { + /* save pixel packing mode */ + struct gl_pixelstore_attrib save = ctx->Pack; + /* use default/tight packing parameters */ + ctx->Pack = ctx->DefaultPacking; + + /* Get the uncompressed image */ + ctx->Driver.GetTexImage(ctx, target, texObj->BaseLevel, + temp_base_format, temp_datatype, + temp_src, texObj, srcImage); + /* restore packing mode */ + ctx->Pack = save; } - _mesa_format_to_type_and_comps(temp_format, &datatype, &comps); for (level = texObj->BaseLevel; level < maxLevel; level++) { /* generate image[level+1] from image[level] */ @@ -2086,7 +2085,10 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target, return; } - _mesa_generate_mipmap_level(target, datatype, comps, border, + /* Free old image data */ + ctx->Driver.FreeTextureImageBuffer(ctx, dstImage); + + _mesa_generate_mipmap_level(target, temp_datatype, components, border, srcWidth, srcHeight, srcDepth, temp_src, temp_src_stride / components, dstWidth, dstHeight, dstDepth, @@ -2100,8 +2102,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target, ctx->Driver.TexImage2D(ctx, target, level + 1, srcImage->InternalFormat, dstWidth, dstHeight, border, - _mesa_get_format_base_format(temp_format), - GL_UNSIGNED_BYTE, + temp_base_format, temp_datatype, temp_dst, &ctx->DefaultPacking, texObj, dstImage); /* swap src and dest pointers */ @@ -2130,7 +2131,7 @@ void _mesa_generate_mipmap(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj) { - const struct gl_texture_image *srcImage; + struct gl_texture_image *srcImage; GLint maxLevel; ASSERT(texObj); diff --git a/mesalib/src/mesa/main/texcompress.c b/mesalib/src/mesa/main/texcompress.c index 42bd1eee5..4e5c14cbb 100644 --- a/mesalib/src/mesa/main/texcompress.c +++ b/mesalib/src/mesa/main/texcompress.c @@ -37,6 +37,9 @@ #include "mfeatures.h" #include "mtypes.h" #include "texcompress.h" +#include "texcompress_fxt1.h" +#include "texcompress_rgtc.h" +#include "texcompress_s3tc.h" /** @@ -259,7 +262,6 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) n += 4; } } - return n; #if FEATURE_ES1 || FEATURE_ES2 if (formats) { @@ -278,6 +280,8 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) n += 10; } #endif + + return n; } @@ -437,3 +441,86 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, return (GLubyte *) image + offset; } + + +/** + * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image. + */ +void +_mesa_decompress_image(gl_format format, GLuint width, GLuint height, + const GLubyte *src, GLint srcRowStride, + GLfloat *dest) +{ + void (*fetch)(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel); + struct gl_texture_image texImage; /* dummy teximage */ + GLuint i, j; + + /* setup dummy texture image info */ + memset(&texImage, 0, sizeof(texImage)); + texImage.Data = (void *) src; + texImage.RowStride = srcRowStride; + + switch (format) { + /* DXT formats */ + case MESA_FORMAT_RGB_DXT1: + fetch = _mesa_fetch_texel_2d_f_rgb_dxt1; + break; + case MESA_FORMAT_RGBA_DXT1: + fetch = _mesa_fetch_texel_2d_f_rgba_dxt1; + break; + case MESA_FORMAT_RGBA_DXT3: + fetch = _mesa_fetch_texel_2d_f_rgba_dxt3; + break; + case MESA_FORMAT_RGBA_DXT5: + fetch = _mesa_fetch_texel_2d_f_rgba_dxt5; + break; + + /* FXT1 formats */ + case MESA_FORMAT_RGB_FXT1: + fetch = _mesa_fetch_texel_2d_f_rgb_fxt1; + break; + case MESA_FORMAT_RGBA_FXT1: + fetch = _mesa_fetch_texel_2d_f_rgba_fxt1; + break; + + /* Red/RG formats */ + case MESA_FORMAT_RED_RGTC1: + fetch = _mesa_fetch_texel_2d_f_red_rgtc1; + break; + case MESA_FORMAT_SIGNED_RED_RGTC1: + fetch = _mesa_fetch_texel_2d_f_signed_red_rgtc1; + break; + case MESA_FORMAT_RG_RGTC2: + fetch = _mesa_fetch_texel_2d_f_rg_rgtc2; + break; + case MESA_FORMAT_SIGNED_RG_RGTC2: + fetch = _mesa_fetch_texel_2d_f_signed_rg_rgtc2; + break; + + /* L/LA formats */ + case MESA_FORMAT_L_LATC1: + fetch = _mesa_fetch_texel_2d_f_l_latc1; + break; + case MESA_FORMAT_SIGNED_L_LATC1: + fetch = _mesa_fetch_texel_2d_f_signed_l_latc1; + break; + case MESA_FORMAT_LA_LATC2: + fetch = _mesa_fetch_texel_2d_f_la_latc2; + break; + case MESA_FORMAT_SIGNED_LA_LATC2: + fetch = _mesa_fetch_texel_2d_f_signed_la_latc2; + break; + + default: + _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()"); + return; + } + + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + fetch(&texImage, i, j, 0, dest); + dest += 4; + } + } +} diff --git a/mesalib/src/mesa/main/texcompress.h b/mesalib/src/mesa/main/texcompress.h index 375cf90c8..2c357068c 100644 --- a/mesalib/src/mesa/main/texcompress.h +++ b/mesalib/src/mesa/main/texcompress.h @@ -50,6 +50,11 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, gl_format mesaFormat, GLsizei width, const GLubyte *image); +extern void +_mesa_decompress_image(gl_format format, GLuint width, GLuint height, + const GLubyte *src, GLint srcRowStride, + GLfloat *dest); + #else /* _HAVE_FULL_GL */ /* no-op macros */ diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c index 99ace91a9..2830dda86 100644 --- a/mesalib/src/mesa/main/texgetimage.c +++ b/mesalib/src/mesa/main/texgetimage.c @@ -34,13 +34,14 @@ #include "enums.h" #include "context.h" #include "formats.h" +#include "format_unpack.h" #include "image.h" #include "mfeatures.h" #include "mtypes.h" #include "pack.h" #include "pbo.h" +#include "texcompress.h" #include "texgetimage.h" -#include "texfetch.h" #include "teximage.h" @@ -75,8 +76,9 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions, const GLint width = texImage->Width; const GLint height = texImage->Height; const GLint depth = texImage->Depth; - GLint img, row, col; + GLint img, row; GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat)); + const GLint texelSize = _mesa_get_format_bytes(texImage->TexFormat); if (!depthRow) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); @@ -88,11 +90,12 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions, void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, width, height, format, type, img, row, 0); - assert(dest); + const GLubyte *src = (GLubyte *) texImage->Data + + (texImage->ImageOffsets[img] + + texImage->RowStride * row) * texelSize; + + _mesa_unpack_float_z_row(texImage->TexFormat, width, src, depthRow); - for (col = 0; col < width; col++) { - texImage->FetchTexelf(texImage, col, row, img, depthRow + col); - } _mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack); } } @@ -173,95 +176,141 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions, /** - * glGetTexImage for (s)RGBA, Luminance, etc. pixels. - * This is the slow way since we use texture sampling. + * glGetTexImage for color formats (RGBA, RGB, alpha, LA, etc). + * Compressed textures are handled here as well. */ static void get_tex_rgba(struct gl_context *ctx, GLuint dimensions, GLenum format, GLenum type, GLvoid *pixels, struct gl_texture_image *texImage) { - const GLint width = texImage->Width; - const GLint height = texImage->Height; - const GLint depth = texImage->Depth; - const GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat); + /* don't want to apply sRGB -> RGB conversion here so override the format */ + const gl_format texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat); + const GLuint width = texImage->Width; + const GLuint height = texImage->Height; + const GLuint depth = texImage->Depth; + const GLenum dataType = _mesa_get_format_datatype(texFormat); + const GLenum baseFormat = _mesa_get_format_base_format(texFormat); /* Normally, no pixel transfer ops are performed during glGetTexImage. * The only possible exception is component clamping to [0,1]. */ GLbitfield transferOps = 0x0; - GLint img, row; - GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat)); - const GLboolean is_sampler_srgb_decode = - _mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB && - texImage->TexObject->Sampler.sRGBDecode == GL_DECODE_EXT; - - if (!rgba) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); - return; - } - /* Clamping does not apply to GetTexImage (final conversion)? - * Looks like we need clamp though when going from format - * containing negative values to unsigned format. + /* In general, clamping does not apply to glGetTexImage, except when + * the returned type of the image can't hold negative values. */ - if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) { - transferOps |= IMAGE_CLAMP_BIT; - } - else if (!type_with_negative_values(type) && - (dataType == GL_FLOAT || - dataType == GL_SIGNED_NORMALIZED)) { - transferOps |= IMAGE_CLAMP_BIT; + if (!type_with_negative_values(type)) { + /* the returned image type can't have negative values */ + if (dataType == GL_FLOAT || + dataType == GL_SIGNED_NORMALIZED || + format == GL_LUMINANCE || + format == GL_LUMINANCE_ALPHA) { + transferOps |= IMAGE_CLAMP_BIT; + } } - /* glGetTexImage always returns sRGB data for sRGB textures. Make sure the - * fetch functions return sRGB data without linearizing it. - */ - if (is_sampler_srgb_decode) { - texImage->TexObject->Sampler.sRGBDecode = GL_SKIP_DECODE_EXT; - _mesa_set_fetch_functions(texImage, dimensions); - } + if (_mesa_is_format_compressed(texFormat)) { + /* Decompress into temp buffer, then pack into user buffer */ + GLfloat *tempImage, *srcRow; + GLuint row; - for (img = 0; img < depth; img++) { + tempImage = (GLfloat *) malloc(texImage->Width * texImage->Height * + texImage->Depth * 4 * sizeof(GLfloat)); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()"); + return; + } + + _mesa_decompress_image(texFormat, texImage->Width, texImage->Height, + texImage->Data, texImage->RowStride, tempImage); + + if (baseFormat == GL_LUMINANCE || + baseFormat == GL_LUMINANCE_ALPHA) { + /* Set green and blue to zero since the pack function here will + * compute L=R+G+B. + */ + GLuint i; + for (i = 0; i < width * height; i++) { + tempImage[i * 4 + GCOMP] = tempImage[i * 4 + BCOMP] = 0.0f; + } + } + + srcRow = tempImage; for (row = 0; row < height; row++) { void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, width, height, format, type, - img, row, 0); - GLint col; + 0, row, 0); + + _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow, + format, type, dest, &ctx->Pack, transferOps); + srcRow += width * 4; + } + + free(tempImage); + } + else { + /* No decompression needed */ + const GLint texelSize = _mesa_get_format_bytes(texFormat); + GLuint img, row; + GLfloat (*rgba)[4]; + + rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat)); + if (!rgba) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()"); + return; + } + + for (img = 0; img < depth; img++) { + for (row = 0; row < height; row++) { + void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, + width, height, format, type, + img, row, 0); + const GLubyte *src = (const GLubyte *) texImage->Data + + (texImage->ImageOffsets[img] + + texImage->RowStride * row) * texelSize; + + _mesa_unpack_rgba_row(texFormat, width, src, rgba); - for (col = 0; col < width; col++) { - texImage->FetchTexelf(texImage, col, row, img, rgba[col]); if (texImage->_BaseFormat == GL_ALPHA) { - rgba[col][RCOMP] = 0.0F; - rgba[col][GCOMP] = 0.0F; - rgba[col][BCOMP] = 0.0F; + GLint col; + for (col = 0; col < width; col++) { + rgba[col][RCOMP] = 0.0F; + rgba[col][GCOMP] = 0.0F; + rgba[col][BCOMP] = 0.0F; + } } else if (texImage->_BaseFormat == GL_LUMINANCE) { - rgba[col][GCOMP] = 0.0F; - rgba[col][BCOMP] = 0.0F; - rgba[col][ACOMP] = 1.0F; + GLint col; + for (col = 0; col < width; col++) { + rgba[col][GCOMP] = 0.0F; + rgba[col][BCOMP] = 0.0F; + rgba[col][ACOMP] = 1.0F; + } } else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) { - rgba[col][GCOMP] = 0.0F; - rgba[col][BCOMP] = 0.0F; + GLint col; + for (col = 0; col < width; col++) { + rgba[col][GCOMP] = 0.0F; + rgba[col][BCOMP] = 0.0F; + } } else if (texImage->_BaseFormat == GL_INTENSITY) { - rgba[col][GCOMP] = 0.0F; - rgba[col][BCOMP] = 0.0F; - rgba[col][ACOMP] = 1.0F; + GLint col; + for (col = 0; col < width; col++) { + rgba[col][GCOMP] = 0.0F; + rgba[col][BCOMP] = 0.0F; + rgba[col][ACOMP] = 1.0F; + } } + + _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, + format, type, dest, + &ctx->Pack, transferOps); } - _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, - format, type, dest, - &ctx->Pack, transferOps); } - } - if (is_sampler_srgb_decode) { - texImage->TexObject->Sampler.sRGBDecode = GL_DECODE_EXT; - _mesa_set_fetch_functions(texImage, dimensions); + free(rgba); } - - free(rgba); } diff --git a/mesalib/src/mesa/sources.mak b/mesalib/src/mesa/sources.mak index deff7bd78..71f708f1e 100644 --- a/mesalib/src/mesa/sources.mak +++ b/mesalib/src/mesa/sources.mak @@ -43,6 +43,7 @@ MAIN_SOURCES = \ main/ffvertex_prog.c \ main/fog.c \ main/formats.c \ + main/format_unpack.c \ main/framebuffer.c \ main/get.c \ main/getstring.c \ |