summaryrefslogtreecommitdiff
path: root/src/mesa/main/texcompress_fxt1.c
diff options
context:
space:
mode:
authorDaniel Borca <dborca@users.sourceforge.net>2004-04-29 09:01:41 +0000
committerDaniel Borca <dborca@users.sourceforge.net>2004-04-29 09:01:41 +0000
commitc35dcfcf0adb335a28fdb1503447655dbb809927 (patch)
treed7ca319a59660144de08be80848cb4ba45707aff /src/mesa/main/texcompress_fxt1.c
parentaf503f3438c53962c1ee65ec69c07cb584672198 (diff)
FXT1 preparations
Diffstat (limited to 'src/mesa/main/texcompress_fxt1.c')
-rw-r--r--src/mesa/main/texcompress_fxt1.c139
1 files changed, 133 insertions, 6 deletions
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index f18f717fc6..98e9158074 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -40,28 +40,142 @@
#include "texstore.h"
+GLint compress_fxt1 (GLcontext *ctx,
+ GLint srcWidth,
+ GLint srcHeight,
+ GLenum srcFormat,
+ const GLvoid *pixels,
+ GLint srcRowStride,
+ GLvoid *dst,
+ GLint dstRowStride);
+
+
+/**
+ * Called during context initialization.
+ */
void
_mesa_init_texture_fxt1( GLcontext *ctx )
{
- /* called during context initialization */
}
+/**
+ * Called via TexFormat->StoreImage to store an RGB_FXT1 texture.
+ */
static GLboolean
texstore_rgb_fxt1(STORE_PARAMS)
{
- /* XXX to do */
- return GL_FALSE;
+ const GLchan *pixels;
+ GLint srcRowStride;
+ GLubyte *dst;
+ GLint texWidth;
+ const GLchan *tempImage = NULL;
+
+ dstRowStride = _mesa_compressed_row_stride(GL_COMPRESSED_RGB_FXT1_3DFX, srcWidth);
+ texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
+
+ ASSERT(dstFormat == &_mesa_texformat_rgb_fxt1);
+ ASSERT(dstXoffset % 8 == 0);
+ ASSERT(dstYoffset % 4 == 0);
+ ASSERT(dstZoffset == 0);
+
+ /* [dBorca]
+ * we still need to pass a 4byte/pixel texture to the codec
+ */
+ if (srcFormat != GL_RGB ||
+ srcType != CHAN_TYPE ||
+ ctx->_ImageTransferState ||
+ srcPacking->SwapBytes) {
+ /* convert image to RGB/GLchan */
+ tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ /*dstFormat->BaseFormat*/GL_RGBA,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ if (!tempImage)
+ return GL_FALSE; /* out of memory */
+ _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+ pixels = tempImage;
+ srcRowStride = /*3*/4 * srcWidth;
+ srcFormat = GL_RGB;
+ }
+ else {
+ pixels = (const GLchan *) srcAddr;
+ srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
+ srcType) / sizeof(GLchan);
+ }
+
+ dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
+ GL_COMPRESSED_RGB_FXT1_3DFX,
+ texWidth, dstAddr);
+
+ compress_fxt1(ctx, srcWidth, srcHeight, srcFormat, pixels, srcRowStride,
+ dst, dstRowStride);
+
+ if (tempImage)
+ _mesa_free((void *) tempImage);
+
+ return GL_TRUE;
}
+/**
+ * Called via TexFormat->StoreImage to store an RGBA_FXT1 texture.
+ */
static GLboolean
texstore_rgba_fxt1(STORE_PARAMS)
{
- /* XXX to do */
- return GL_FALSE;
-}
+ const GLchan *pixels;
+ GLint srcRowStride;
+ GLubyte *dst;
+ GLint texWidth;
+ const GLchan *tempImage = NULL;
+
+ dstRowStride = _mesa_compressed_row_stride(GL_COMPRESSED_RGBA_FXT1_3DFX, srcWidth);
+ texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
+
+ ASSERT(dstFormat == &_mesa_texformat_rgba_dxt1);
+ ASSERT(dstXoffset % 8 == 0);
+ ASSERT(dstYoffset % 4 == 0);
+ ASSERT(dstZoffset == 0);
+
+ if (srcFormat != GL_RGBA ||
+ srcType != CHAN_TYPE ||
+ ctx->_ImageTransferState ||
+ srcPacking->SwapBytes) {
+ /* convert image to RGBA/GLchan */
+ tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ dstFormat->BaseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ if (!tempImage)
+ return GL_FALSE; /* out of memory */
+ _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+ pixels = tempImage;
+ srcRowStride = 4 * srcWidth;
+ srcFormat = GL_RGBA;
+ }
+ else {
+ pixels = (const GLchan *) srcAddr;
+ srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
+ srcType) / sizeof(GLchan);
+ }
+ dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
+ GL_COMPRESSED_RGBA_FXT1_3DFX,
+ texWidth, dstAddr);
+
+ compress_fxt1(ctx, srcWidth, srcHeight, srcFormat, pixels, srcRowStride,
+ dst, dstRowStride);
+
+ if (tempImage)
+ _mesa_free((void*) tempImage);
+
+ return GL_TRUE;
+}
static void
@@ -153,3 +267,16 @@ const struct gl_texture_format _mesa_texformat_rgba_fxt1 = {
NULL, /*impossible*/ /* FetchTexel3Df */
};
+
+GLint compress_fxt1 (GLcontext *ctx,
+ GLint srcWidth,
+ GLint srcHeight,
+ GLenum srcFormat,
+ const GLvoid *pixels,
+ GLint srcRowStride,
+ GLvoid *dst,
+ GLint dstRowStride)
+{
+ /* here be dragons */
+ return -1;
+}