diff options
author | Brian Paul <brianp@vmware.com> | 2009-10-24 11:52:31 -0600 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-10-24 11:52:36 -0600 |
commit | 5c8282769601ba30c00f04dac15d1dad6d67db6e (patch) | |
tree | 4342feafd07c9bc0125aaf0a0b4271dba3a1aaaa /src/mesa | |
parent | 1ad9671db7bd60fa84266f30f46555b4e45bcb08 (diff) |
mesa: simplify _mesa_compressed_row_stride(), _mesa_compressed_image_address()
_mesa_compressed_row_stride() can go away soon.
_mesa_compressed_image_address() can be generalized and moved to formats.c
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/texcompress.c | 91 |
1 files changed, 15 insertions, 76 deletions
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index 76f2f232f4..b07265d6d8 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -212,40 +212,7 @@ _mesa_compressed_texture_size_glenum(GLcontext *ctx, GLint _mesa_compressed_row_stride(gl_format mesaFormat, GLsizei width) { - GLint stride; - - switch (mesaFormat) { -#if FEATURE_texture_fxt1 - case MESA_FORMAT_RGB_FXT1: - case MESA_FORMAT_RGBA_FXT1: - stride = ((width + 7) / 8) * 16; /* 16 bytes per 8x4 tile */ - break; -#endif -#if FEATURE_texture_s3tc - case MESA_FORMAT_RGB_DXT1: - case MESA_FORMAT_RGBA_DXT1: -#if FEATURE_EXT_texture_sRGB - case MESA_FORMAT_SRGB_DXT1: - case MESA_FORMAT_SRGBA_DXT1: -#endif - stride = ((width + 3) / 4) * 8; /* 8 bytes per 4x4 tile */ - break; - case MESA_FORMAT_RGBA_DXT3: - case MESA_FORMAT_RGBA_DXT5: -#if FEATURE_EXT_texture_sRGB - case MESA_FORMAT_SRGBA_DXT3: - case MESA_FORMAT_SRGBA_DXT5: -#endif - stride = ((width + 3) / 4) * 16; /* 16 bytes per 4x4 tile */ - break; -#endif - default: - _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_row_stride"); - return 0; - } - - assert(stride == _mesa_format_row_stride(mesaFormat, width)); - + GLint stride = _mesa_format_row_stride(mesaFormat, width); return stride; } @@ -253,58 +220,30 @@ _mesa_compressed_row_stride(gl_format mesaFormat, GLsizei width) /* * Return the address of the pixel at (col, row, img) in a * compressed texture image. - * \param col, row, img - image position (3D) + * \param col, row, img - image position (3D), should be a multiple of the + * format's block size. * \param format - compressed image format - * \param width - image width + * \param width - image width (stride) in pixels * \param image - the image address - * \return address of pixel at (row, col) + * \return address of pixel at (row, col, img) */ GLubyte * _mesa_compressed_image_address(GLint col, GLint row, GLint img, gl_format mesaFormat, GLsizei width, const GLubyte *image) { - GLubyte *addr; + /* XXX only 2D images implemented, not 3D */ + const GLuint blockSize = _mesa_get_format_bytes(mesaFormat); + GLuint bw, bh; + GLint offset; - (void) img; + _mesa_get_format_block_size(mesaFormat, &bw, &bh); - /* We try to spot a "complete" subtexture "above" ROW, COL; - * this texture is given by appropriate rounding of WIDTH x ROW. - * Then we just add the amount left (usually on the left). - * - * Example for X*Y microtiles (Z bytes each) - * offset = Z * (((width + X - 1) / X) * (row / Y) + col / X); - */ + ASSERT(col % bw == 0); + ASSERT(row % bh == 0); - switch (mesaFormat) { -#if FEATURE_texture_fxt1 - case MESA_FORMAT_RGB_FXT1: - case MESA_FORMAT_RGBA_FXT1: - addr = (GLubyte *) image + 16 * (((width + 7) / 8) * (row / 4) + col / 8); - break; -#endif -#if FEATURE_texture_s3tc - case MESA_FORMAT_RGB_DXT1: - case MESA_FORMAT_RGBA_DXT1: -#if FEATURE_EXT_texture_sRGB - case MESA_FORMAT_SRGB_DXT1: - case MESA_FORMAT_SRGBA_DXT1: -#endif - addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4); - break; - case MESA_FORMAT_RGBA_DXT3: - case MESA_FORMAT_RGBA_DXT5: -#if FEATURE_EXT_texture_sRGB - case MESA_FORMAT_SRGBA_DXT3: - case MESA_FORMAT_SRGBA_DXT5: -#endif - addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4); - break; -#endif - default: - _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_image_address"); - addr = NULL; - } + offset = ((width + bw - 1) / bw) * (row / bh) + col / bw; + offset *= blockSize; - return addr; + return (GLubyte *) image + offset; } |