diff options
author | gareth <gareth> | 2001-02-28 16:03:01 +0000 |
---|---|---|
committer | gareth <gareth> | 2001-02-28 16:03:01 +0000 |
commit | cb1055f1994446d51a50fa18351d35bca7c04117 (patch) | |
tree | c502f8d2200387173955753fa39d3f4dd3483d13 | |
parent | ff45cdc11280a7603a1a3655bc80ca21a98a520a (diff) |
Fix GetTexImage in radeon, tdfx drivers.tdfx-3-1-0-20010301-freeze
-rw-r--r-- | xc/extras/Mesa/src/texutil.c | 257 | ||||
-rw-r--r-- | xc/extras/Mesa/src/texutil.h | 9 | ||||
-rw-r--r-- | xc/extras/Mesa/src/types.h | 9 | ||||
-rw-r--r-- | xc/lib/GL/mesa/src/drv/radeon/radeon_tex.c | 49 | ||||
-rw-r--r-- | xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c | 110 |
5 files changed, 258 insertions, 176 deletions
diff --git a/xc/extras/Mesa/src/texutil.c b/xc/extras/Mesa/src/texutil.c index 6dd36c057..12f01a913 100644 --- a/xc/extras/Mesa/src/texutil.c +++ b/xc/extras/Mesa/src/texutil.c @@ -31,6 +31,7 @@ #else #include "glheader.h" #include "context.h" +#include "enums.h" #include "image.h" #include "mem.h" #include "texformat.h" @@ -62,6 +63,19 @@ typedef void (*unconvert_func)( struct gl_texture_convert *convert ); #define CONVERT_STRIDE_BIT 0x1 #define CONVERT_PACKING_BIT 0x2 +#ifdef __GNUC__ +#define ERROR_STRING __FUNCTION__ +#else +#define ERROR_STRING __FILE__ ":" __LINE__ +#endif +#define UNCONVERT_ERROR( format ) \ +do { \ + static char buffer[128]; \ + sprintf( buffer, "illegal format %s in " ERROR_STRING "\n", \ + gl_lookup_enum_by_nr( format ) ); \ + gl_problem( NULL, buffer ); \ +} while (0) + /* ================================================================ @@ -146,14 +160,32 @@ static void unconvert_teximage_rgba8888( struct gl_texture_convert *convert ) { const GLubyte *src = (const GLubyte *)convert->srcImage; - GLuint *dst = (GLuint *)convert->dstImage; GLint texels, i; texels = convert->width * convert->height * convert->depth; - for ( i = 0 ; i < texels ; i++ ) { - *dst++ = PACK_COLOR_8888( src[0], src[1], src[2], src[3] ); - src += 4; + switch ( convert->format ) { + case GL_RGBA: { + GLuint *dst = (GLuint *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = PACK_COLOR_8888( src[0], src[1], src[2], src[3] ); + src += 4; + } + break; + } + case GL_RGB: { + GLubyte *dst = (GLubyte *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = src[3]; + *dst++ = src[2]; + *dst++ = src[1]; + src += 4; + } + break; + } + default: + UNCONVERT_ERROR( convert->format ); + break; } } @@ -222,8 +254,29 @@ CONVERT_ABGR8888( texsubimage3d ) static void unconvert_teximage_abgr8888( struct gl_texture_convert *convert ) { - MEMCPY( convert->dstImage, convert->srcImage, - convert->width * convert->height * convert->depth * 4 ); + const GLubyte *src = (const GLubyte *)convert->srcImage; + GLint texels, i; + + texels = convert->width * convert->height * convert->depth; + + switch ( convert->format ) { + case GL_RGBA: + MEMCPY( convert->dstImage, src, texels * 4 ); + break; + case GL_RGB: { + GLubyte *dst = (GLubyte *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = src[0]; + *dst++ = src[1]; + *dst++ = src[2]; + src += 4; + } + break; + } + default: + UNCONVERT_ERROR( convert->format ); + break; + } } @@ -309,14 +362,32 @@ static void unconvert_teximage_argb8888( struct gl_texture_convert *convert ) { const GLubyte *src = (const GLubyte *)convert->srcImage; - GLuint *dst = (GLuint *)convert->dstImage; GLint texels, i; texels = convert->width * convert->height * convert->depth; - for ( i = 0 ; i < texels ; i++ ) { - *dst++ = PACK_COLOR_8888( src[3], src[0], src[1], src[2] ); - src += 4; + switch ( convert->format ) { + case GL_RGBA: { + GLuint *dst = (GLuint *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = PACK_COLOR_8888( src[3], src[0], src[1], src[2] ); + src += 4; + } + break; + } + case GL_RGB: { + GLubyte *dst = (GLubyte *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = src[2]; + *dst++ = src[1]; + *dst++ = src[0]; + src += 4; + } + break; + } + default: + UNCONVERT_ERROR( convert->format ); + break; } } @@ -346,18 +417,7 @@ convert_texsubimage3d_rgb888( struct gl_texture_convert *convert ) static void unconvert_teximage_rgb888( struct gl_texture_convert *convert ) { - const GLubyte *src = (const GLubyte *)convert->srcImage; - GLubyte *dst = (GLubyte *)convert->dstImage; - GLint texels, i; - - texels = convert->width * convert->height * convert->depth; - - for ( i = 0 ; i < texels ; i++ ) { - *dst++ = src[2]; - *dst++ = src[1]; - *dst++ = src[0]; - src += 3; - } + UNCONVERT_ERROR( convert->format ); } @@ -386,8 +446,7 @@ convert_texsubimage3d_bgr888( struct gl_texture_convert *convert ) static void unconvert_teximage_bgr888( struct gl_texture_convert *convert ) { - MEMCPY( convert->dstImage, convert->srcImage, - convert->width * convert->height * convert->depth * 3 ); + UNCONVERT_ERROR( convert->format ); } @@ -482,11 +541,27 @@ unconvert_teximage_rgb565( struct gl_texture_convert *convert ) texels = convert->width * convert->height * convert->depth; - for ( i = 0 ; i < texels ; i++ ) { - GLushort s = *src++; - *dst++ = ((s >> 8) & 0xf8) * 255 / 0xf8; - *dst++ = ((s >> 3) & 0xfc) * 255 / 0xfc; - *dst++ = ((s << 3) & 0xf8) * 255 / 0xf8; + switch ( convert->format ) { + case GL_RGBA: + for ( i = 0 ; i < texels ; i++ ) { + GLushort s = *src++; + *dst++ = ((s >> 8) & 0xf8) * 255 / 0xf8; + *dst++ = ((s >> 3) & 0xfc) * 255 / 0xfc; + *dst++ = ((s << 3) & 0xf8) * 255 / 0xf8; + *dst++ = 0xff; + } + break; + case GL_RGB: + for ( i = 0 ; i < texels ; i++ ) { + GLushort s = *src++; + *dst++ = ((s >> 8) & 0xf8) * 255 / 0xf8; + *dst++ = ((s >> 3) & 0xfc) * 255 / 0xfc; + *dst++ = ((s << 3) & 0xf8) * 255 / 0xf8; + } + break; + default: + UNCONVERT_ERROR( convert->format ); + break; } } @@ -563,12 +638,19 @@ unconvert_teximage_argb4444( struct gl_texture_convert *convert ) texels = convert->width * convert->height * convert->depth; - for ( i = 0 ; i < texels ; i++ ) { - GLushort s = *src++; - *dst++ = ((s >> 8) & 0xf) * 255 / 0xf; - *dst++ = ((s >> 4) & 0xf) * 255 / 0xf; - *dst++ = ((s ) & 0xf) * 255 / 0xf; - *dst++ = ((s >> 12) & 0xf) * 255 / 0xf; + switch ( convert->format ) { + case GL_RGBA: + for ( i = 0 ; i < texels ; i++ ) { + GLushort s = *src++; + *dst++ = ((s >> 8) & 0xf) * 255 / 0xf; + *dst++ = ((s >> 4) & 0xf) * 255 / 0xf; + *dst++ = ((s ) & 0xf) * 255 / 0xf; + *dst++ = ((s >> 12) & 0xf) * 255 / 0xf; + } + break; + default: + UNCONVERT_ERROR( convert->format ); + break; } } @@ -645,12 +727,19 @@ unconvert_teximage_argb1555( struct gl_texture_convert *convert ) texels = convert->width * convert->height * convert->depth; - for ( i = 0 ; i < texels ; i++ ) { - GLushort s = *src++; - *dst++ = ((s >> 10) & 0xf8) * 255 / 0xf8; - *dst++ = ((s >> 5) & 0xf8) * 255 / 0xf8; - *dst++ = ((s ) & 0xf8) * 255 / 0xf8; - *dst++ = ((s >> 15) & 0x01) * 255; + switch ( convert->format ) { + case GL_RGBA: + for ( i = 0 ; i < texels ; i++ ) { + GLushort s = *src++; + *dst++ = ((s >> 10) & 0xf8) * 255 / 0xf8; + *dst++ = ((s >> 5) & 0xf8) * 255 / 0xf8; + *dst++ = ((s ) & 0xf8) * 255 / 0xf8; + *dst++ = ((s >> 15) & 0x01) * 255; + } + break; + default: + UNCONVERT_ERROR( convert->format ); + break; } } @@ -676,11 +765,11 @@ unconvert_teximage_argb1555( struct gl_texture_convert *convert ) #define CONVERT_TEXEL( src ) \ - PACK_COLOR_88( 0x00, src[0] ) + PACK_COLOR_88( src[0], 0x00 ) #define CONVERT_TEXEL_DWORD( src ) \ - ((PACK_COLOR_88( 0x00, src[0] )) | \ - (PACK_COLOR_88( 0x00, src[1] ) << 16)) + ((PACK_COLOR_88( src[0], 0x00 )) | \ + (PACK_COLOR_88( src[1], 0x00 ) << 16)) #define SRC_TEXEL_BYTES 1 @@ -690,11 +779,11 @@ unconvert_teximage_argb1555( struct gl_texture_convert *convert ) #define CONVERT_TEXEL( src ) \ - PACK_COLOR_88( src[0], 0xff ) + PACK_COLOR_88( 0xff, src[0] ) #define CONVERT_TEXEL_DWORD( src ) \ - ((PACK_COLOR_88( src[0], 0xff )) | \ - (PACK_COLOR_88( src[1], 0xff ) << 16)) + ((PACK_COLOR_88( 0xff, src[0] )) | \ + (PACK_COLOR_88( 0xff, src[1] ) << 16)) #define SRC_TEXEL_BYTES 1 @@ -740,8 +829,35 @@ CONVERT_AL88( texsubimage3d ) static void unconvert_teximage_al88( struct gl_texture_convert *convert ) { - MEMCPY( convert->dstImage, convert->srcImage, - convert->width * convert->height * convert->depth * 2 ); + const GLubyte *src = (const GLubyte *)convert->srcImage; + GLint texels, i; + + texels = convert->width * convert->height * convert->depth; + + switch ( convert->format ) { + case GL_LUMINANCE_ALPHA: + MEMCPY( convert->dstImage, src, texels * 2 ); + break; + case GL_ALPHA: { + GLubyte *dst = (GLubyte *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = src[1]; + src += 2; + } + break; + } + case GL_LUMINANCE: { + GLubyte *dst = (GLubyte *)convert->dstImage; + for ( i = 0 ; i < texels ; i++ ) { + *dst++ = src[0]; + src += 2; + } + break; + } + default: + UNCONVERT_ERROR( convert->format ); + break; + } } @@ -770,18 +886,7 @@ convert_texsubimage3d_rgb332( struct gl_texture_convert *convert ) static void unconvert_teximage_rgb332( struct gl_texture_convert *convert ) { - const GLubyte *src = (const GLubyte *)convert->srcImage; - GLubyte *dst = (GLubyte *)convert->dstImage; - GLint texels, i; - - texels = convert->width * convert->height * convert->depth; - - for ( i = 0 ; i < texels ; i++ ) { - GLushort s = *src++; - *dst++ = (s & 0xe0) * 255 / 0xe0; - *dst++ = (s & 0x1c) * 255 / 0x1c; - *dst++ = (s & 0x03) * 255 / 0x03; - } + UNCONVERT_ERROR( convert->format ); } @@ -834,8 +939,22 @@ CONVERT_CI8( texsubimage3d ) static void unconvert_teximage_ci8( struct gl_texture_convert *convert ) { - MEMCPY( convert->dstImage, convert->srcImage, - convert->width * convert->height * convert->depth ); + const GLubyte *src = (const GLubyte *)convert->srcImage; + GLint texels; + + texels = convert->width * convert->height * convert->depth; + + switch ( convert->format ) { + case GL_ALPHA: + case GL_LUMINANCE: + case GL_INTENSITY: + case GL_COLOR_INDEX: + MEMCPY( convert->dstImage, src, texels ); + break; + default: + UNCONVERT_ERROR( convert->format ); + break; + } } @@ -1048,8 +1167,7 @@ _mesa_convert_texsubimage3d( GLint mesaFormat, -void _mesa_unconvert_teximage1d( GLint mesaFormat, - GLint width, GLenum format, GLenum type, +void _mesa_unconvert_teximage1d( GLint mesaFormat, GLenum format, GLint width, const GLvoid *srcImage, GLvoid *dstImage ) { struct gl_texture_convert convert; @@ -1066,16 +1184,14 @@ void _mesa_unconvert_teximage1d( GLint mesaFormat, convert.height = 1; convert.depth = 1; convert.format = format; - convert.type = type; convert.srcImage = srcImage; convert.dstImage = dstImage; return gl_unconvert_teximage_tab[mesaFormat]( &convert ); } -void _mesa_unconvert_teximage2d( GLint mesaFormat, +void _mesa_unconvert_teximage2d( GLint mesaFormat, GLenum format, GLint width, GLint height, - GLenum format, GLenum type, const GLvoid *srcImage, GLvoid *dstImage ) { struct gl_texture_convert convert; @@ -1092,16 +1208,14 @@ void _mesa_unconvert_teximage2d( GLint mesaFormat, convert.height = height; convert.depth = 1; convert.format = format; - convert.type = type; convert.srcImage = srcImage; convert.dstImage = dstImage; return gl_unconvert_teximage_tab[mesaFormat]( &convert ); } -void _mesa_unconvert_teximage3d( GLint mesaFormat, +void _mesa_unconvert_teximage3d( GLint mesaFormat, GLenum format, GLint width, GLint height, GLint depth, - GLenum format, GLenum type, const GLvoid *srcImage, GLvoid *dstImage ) { struct gl_texture_convert convert; @@ -1118,7 +1232,6 @@ void _mesa_unconvert_teximage3d( GLint mesaFormat, convert.height = height; convert.depth = depth; convert.format = format; - convert.type = type; convert.srcImage = srcImage; convert.dstImage = dstImage; diff --git a/xc/extras/Mesa/src/texutil.h b/xc/extras/Mesa/src/texutil.h index 98b7f5363..a3e842667 100644 --- a/xc/extras/Mesa/src/texutil.h +++ b/xc/extras/Mesa/src/texutil.h @@ -62,20 +62,17 @@ _mesa_convert_texsubimage3d( GLint mesaFormat, /* Deprecated in 3.5: */ extern void -_mesa_unconvert_teximage1d( GLint mesaFormat, - GLint width, GLenum format, GLenum type, +_mesa_unconvert_teximage1d( GLint mesaFormat, GLenum format, GLint width, const GLvoid *srcImage, GLvoid *dstImage ); extern void -_mesa_unconvert_teximage2d( GLint mesaFormat, +_mesa_unconvert_teximage2d( GLint mesaFormat, GLenum format, GLint width, GLint height, - GLenum format, GLenum type, const GLvoid *srcImage, GLvoid *dstImage ); extern void -_mesa_unconvert_teximage3d( GLint mesaFormat, +_mesa_unconvert_teximage3d( GLint mesaFormat, GLenum format, GLint width, GLint height, GLint depth, - GLenum format, GLenum type, const GLvoid *srcImage, GLvoid *dstImage ); /* Nearest filtering only (for broken hardware that can't support diff --git a/xc/extras/Mesa/src/types.h b/xc/extras/Mesa/src/types.h index 1182f0535..3f507ca35 100644 --- a/xc/extras/Mesa/src/types.h +++ b/xc/extras/Mesa/src/types.h @@ -194,15 +194,6 @@ struct gl_texture_image { * GL_COLOR_INDEX only */ GLenum IntFormat; /* Internal format as given by the user */ -#if 0 - GLubyte RedBits; /* Bits per texel component */ - GLubyte GreenBits; /* These are initialized by Mesa but */ - GLubyte BlueBits; /* may be reassigned by the device */ - GLubyte AlphaBits; /* driver to indicate the true texture */ - GLubyte LuminanceBits; /* color resolution. */ - GLubyte IntensityBits; - GLubyte IndexBits; -#endif GLuint Border; /* 0 or 1 */ GLuint Width; /* = 2^WidthLog2 + 2*Border */ GLuint Height; /* = 2^HeightLog2 + 2*Border */ diff --git a/xc/lib/GL/mesa/src/drv/radeon/radeon_tex.c b/xc/lib/GL/mesa/src/drv/radeon/radeon_tex.c index 184cbd709..0d61f1aa8 100644 --- a/xc/lib/GL/mesa/src/drv/radeon/radeon_tex.c +++ b/xc/lib/GL/mesa/src/drv/radeon/radeon_tex.c @@ -664,6 +664,53 @@ radeonDDTexSubImage3D( GLcontext *ctx, GLenum target, GLint level, /* ================================================================ + * DEPRECATED... + */ + +static GLvoid *radeonDDGetTexImage( GLcontext *ctx, GLenum target, GLint level, + const struct gl_texture_object *texObj, + GLenum *formatOut, GLenum *typeOut, + GLboolean *freeImageOut ) +{ + const struct gl_texture_image *texImage = texObj->Image[level]; + const struct gl_texture_format *texFormat = texImage->TexFormat; + radeonTexObjPtr t = (radeonTexObjPtr)texObj->DriverData; + GLubyte *data; + + if ( !t || !t->image[level].data ) + return NULL; + + data = (GLubyte *) MALLOC( texImage->Width * texImage->Height * 4 ); + if ( !data ) + return NULL; + + fprintf( stderr, " in=%d out=%s\n", + texFormat->IntFormat, gl_lookup_enum_by_nr( texImage->Format ) ); + + switch ( target ) { + case GL_TEXTURE_1D: + _mesa_unconvert_teximage1d( texFormat->IntFormat, texImage->Format, + texImage->Width, + t->image[level].data, data ); + break; + case GL_TEXTURE_2D: + _mesa_unconvert_teximage2d( texFormat->IntFormat, texImage->Format, + texImage->Width, texImage->Height, + t->image[level].data, data ); + break; + default: + return NULL; + } + + *formatOut = texImage->Format; + *typeOut = GL_UNSIGNED_BYTE; + *freeImageOut = GL_TRUE; + + return data; +} + + +/* ================================================================ * Texture state callbacks */ @@ -839,7 +886,7 @@ void radeonDDInitTextureFuncs( GLcontext *ctx ) ctx->Driver.TexSubImage1D = radeonDDTexSubImage1D; ctx->Driver.TexSubImage2D = radeonDDTexSubImage2D; ctx->Driver.TexSubImage3D = NULL /*radeonDDTexSubImage3D*/; - ctx->Driver.GetTexImage = NULL /*radeonDDGetTexImage*/; + ctx->Driver.GetTexImage = radeonDDGetTexImage; ctx->Driver.TexEnv = radeonDDTexEnv; ctx->Driver.TexParameter = radeonDDTexParameter; ctx->Driver.BindTexture = radeonDDBindTexture; diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c index 947fb957e..e0f2d2eb0 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c @@ -1004,109 +1004,43 @@ tdfxDDTestProxyTexImage( GLcontext *ctx, GLenum target, } -/* - * Return a texture image to Mesa. This is either to satisfy +/* Return a texture image to Mesa. This is either to satisfy * a glGetTexImage() call or to prepare for software texturing. */ static GLvoid * tdfxDDGetTexImage( GLcontext *ctx, GLenum target, GLint level, - const struct gl_texture_object *texObj, - GLenum *formatOut, GLenum * typeOut, - GLboolean *freeImageOut ) + const struct gl_texture_object *texObj, + GLenum *formatOut, GLenum *typeOut, + GLboolean *freeImageOut ) { + const struct gl_texture_image *texImage = texObj->Image[level]; + const struct gl_texture_format *texFormat = texImage->TexFormat; tdfxTexObjPtr t = TDFX_TEXTURE_DATA(texObj); tdfxTexImagePtr image; + GLubyte *data; if ( target != GL_TEXTURE_2D ) return NULL; - if ( !t ) return NULL; -#if 0 + image = &t->image[level]; + if ( !image->original.data ) + return NULL; - t = TDFX_TEXTURE_DATA(texObj); - mml = &t->mipmapLevel[level]; - if (image->data) { - MesaIntTexFormat mesaFormat; - GLenum glFormat; - struct gl_texture_image *texImage = texObj->Image[level]; - GLint srcStride; - void *uncompressedImage = NULL; - - GLubyte *data = - (GLubyte *) MALLOC(texImage->Width * texImage->Height * 4); - if (!data) - return NULL; - - uncompressedImage = (void *)image->data; - switch (image->glideFormat) { - case GR_TEXFMT_INTENSITY_8: - mesaFormat = MESA_I8; - glFormat = GL_INTENSITY; - srcStride = image->width; - break; - case GR_TEXFMT_ALPHA_INTENSITY_88: - mesaFormat = MESA_A8_L8; - glFormat = GL_LUMINANCE_ALPHA; - srcStride = image->width; - break; - case GR_TEXFMT_ALPHA_8: - if (texImage->Format == GL_INTENSITY) { - mesaFormat = MESA_I8; - glFormat = GL_INTENSITY; - } - else { - mesaFormat = MESA_A8; - glFormat = GL_ALPHA; - } - srcStride = image->width; - break; - case GR_TEXFMT_RGB_565: - mesaFormat = MESA_R5_G6_B5; - glFormat = GL_RGB; - srcStride = image->width * 2; - break; - case GR_TEXFMT_ARGB_8888: - mesaFormat = MESA_A8_R8_G8_B8; - glFormat = GL_RGBA; - srcStride = image->width * 4; - break; - case GR_TEXFMT_ARGB_4444: - mesaFormat = MESA_A4_R4_G4_B4; - glFormat = GL_RGBA; - srcStride = image->width * 2; - break; - case GR_TEXFMT_ARGB_1555: - mesaFormat = MESA_A1_R5_G5_B5; - glFormat = GL_RGBA; - srcStride = image->width * 2; - break; - case GR_TEXFMT_P_8: - mesaFormat = MESA_C8; - glFormat = GL_COLOR_INDEX; - srcStride = image->width; - break; - default: - gl_problem(NULL, "Bad glideFormat in tdfxDDGetTexImage"); - return NULL; - } - _mesa_unconvert_teximage(mesaFormat, image->width, image->height, - uncompressedImage, srcStride, texImage->Width, - texImage->Height, glFormat, data); - if (uncompressedImage != image->data) { - FREE(uncompressedImage); - } - *formatOut = glFormat; - *typeOut = GL_UNSIGNED_BYTE; - *freeImageOut = GL_TRUE; - return data; - } - else -#endif - { + data = (GLubyte *) MALLOC( texImage->Width * texImage->Height * 4 ); + if ( !data ) return NULL; - } + + _mesa_unconvert_teximage2d( texFormat->IntFormat, texImage->Format, + texImage->Width, texImage->Height, + image->original.data, data ); + + *formatOut = texImage->Format; + *typeOut = GL_UNSIGNED_BYTE; + *freeImageOut = GL_TRUE; + + return data; } |