-/* $Id: texstore.c,v 1.17 2001/03/21 01:08:37 brianp Exp $ */
+/* $Id: texstore.c,v 1.18 2001/03/21 16:44:08 brianp Exp $ */
/*
* Mesa 3-D graphics library
*/
void
_mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
- GLenum texFormat, GLvoid *texDestAddr,
+ GLenum texDestFormat, GLvoid *texDestAddr,
GLint srcWidth, GLint srcHeight, GLint srcDepth,
GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
GLint dstRowStride, GLint dstImageStride,
ASSERT(srcAddr);
ASSERT(srcPacking);
- texComponents = components_in_intformat(texFormat);
+ texComponents = components_in_intformat(texDestFormat);
/* try common 2D texture cases first */
if (!ctx->_ImageTransferState && dimensions == 2 && srcType == CHAN_TYPE) {
- if (srcFormat == texFormat) {
+ if (srcFormat == texDestFormat) {
/* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
* GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy().
*/
}
return; /* all done */
}
- else if (srcFormat == GL_RGBA && texFormat == GL_RGB) {
+ else if (srcFormat == GL_RGBA && texDestFormat == GL_RGB) {
/* commonly used by Quake */
const GLchan *src = (const GLchan *) _mesa_image_address(
srcPacking, srcAddr, srcWidth, srcHeight,
/*
* General case solutions
*/
- if (texFormat == GL_COLOR_INDEX) {
+ if (texDestFormat == GL_COLOR_INDEX) {
/* color index texture */
const GLenum texType = CHAN_TYPE;
GLint img, row;
dest += dstImageStride;
}
}
- else if (texFormat == GL_DEPTH_COMPONENT) {
+ else if (texDestFormat == GL_DEPTH_COMPONENT) {
/* Depth texture (shadow maps) */
GLint img, row;
GLubyte *dest = (GLubyte *) texDestAddr
for (row = 0; row < convHeight; row++) {
_mesa_pack_float_rgba_span(ctx, convWidth,
(const GLfloat (*)[4]) srcf,
- texFormat, CHAN_TYPE,
+ texDestFormat, CHAN_TYPE,
dest, &_mesa_native_packing,
ctx->_ImageTransferState
& IMAGE_POST_CONVOLUTION_BITS);
const GLvoid *srcRow = _mesa_image_address(srcPacking,
srcAddr, srcWidth, srcHeight,
srcFormat, srcType, img, row, 0);
- _mesa_unpack_chan_color_span(ctx, srcWidth, texFormat, destRow,
- srcFormat, srcType, srcRow, srcPacking,
- ctx->_ImageTransferState);
+ _mesa_unpack_chan_color_span(ctx, srcWidth, texDestFormat,
+ destRow, srcFormat, srcType, srcRow,
+ srcPacking, ctx->_ImageTransferState);
destRow += dstRowStride;
}
dest += dstImageStride;
-/* $Id: texstore.h,v 1.4 2001/03/21 01:08:37 brianp Exp $ */
+/* $Id: texstore.h,v 1.5 2001/03/21 16:44:08 brianp Exp $ */
/*
* Mesa 3-D graphics library
extern void
_mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions,
- GLenum texFormat, GLvoid *texDestAddr,
+ GLenum texDestFormat, GLvoid *texDestAddr,
GLint srcWidth, GLint srcHeight, GLint srcDepth,
GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
GLint dstRowStride, GLint dstImageStride,
-/* $Id: texutil.c,v 1.16 2001/03/18 13:40:58 gareth Exp $ */
+/* $Id: texutil.c,v 1.17 2001/03/21 16:44:08 brianp Exp $ */
/*
* Mesa 3-D graphics library
GLint xoffset, yoffset, zoffset; /* Subimage offset */
GLint width, height, depth; /* Subimage region */
- GLint imageWidth, imageHeight; /* Full image dimensions */
- GLenum format, type;
+ GLint dstImageWidth, dstImageHeight; /* Dest image size */
+ /* Needed for subimage replacement */
+ GLenum format, type; /* Source (user) format and type */
const struct gl_pixelstore_attrib *packing;
return gl_convert_texsubimage2d_tab[mesaFormat]( &convert );
}
+
+/*
+ * Convert a user's 2D image into a texture image. This basically repacks
+ * pixel data into the special texture formats used by core Mesa and the DRI
+ * drivers. This function can do full images or subimages.
+ *
+ * We return a boolean because this function may not accept some kinds of
+ * source image formats and/or types. For example, if the incoming
+ * format/type = GL_BGR, GL_UNSIGNED_INT this function probably won't
+ * be able to do the conversion.
+ *
+ * In that case, the incoming image should first be simplified to one of
+ * the "canonical" formats (GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
+ * GL_INTENSITY, GL_RGB, GL_RGBA) and types (GL_CHAN). We can do that
+ * with the _mesa_transfer_teximage() function. That function will also
+ * do image transfer operations such as scale/bias and convolution.
+ *
+ * Input:
+ * mesaFormat - one of the MESA_FORMAT_* values from texformat.h
+ * xoffset, yoffset - position in dest image to put data
+ * width, height - incoming image size, also size of dest region.
+ * dstImageWidth - width (row stride) of dest image in pixels
+ * format, type - incoming image format and type
+ * packing - describes incoming image packing
+ * srcImage - pointer to source image
+ * destImage - pointer to dest image
+ */
GLboolean
_mesa_convert_texsubimage2d( GLint mesaFormat,
GLint xoffset, GLint yoffset,
GLint width, GLint height,
- GLint imageWidth,
+ GLint destImageWidth,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *packing,
const GLvoid *srcImage, GLvoid *dstImage )
convert.yoffset = yoffset;
convert.width = width;
convert.height = height;
- convert.imageWidth = imageWidth;
+ convert.dstImageWidth = destImageWidth;
convert.format = format;
convert.type = type;
convert.packing = packing;
if ( convert_needs_packing( packing, format, type ) )
convert.index |= CONVERT_PACKING_BIT;
- if ( width != imageWidth )
+ if ( width != destImageWidth )
convert.index |= CONVERT_STRIDE_BIT;
return gl_convert_texsubimage2d_tab[mesaFormat]( &convert );
_mesa_convert_texsubimage3d( GLint mesaFormat,
GLint xoffset, GLint yoffset, GLint zoffset,
GLint width, GLint height, GLint depth,
- GLint imageWidth, GLint imageHeight,
+ GLint dstImageWidth, GLint dstImageHeight,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *packing,
const GLvoid *srcImage, GLvoid *dstImage )
convert.width = width;
convert.height = height;
convert.depth = depth;
- convert.imageWidth = imageWidth;
- convert.imageHeight = imageHeight;
+ convert.dstImageWidth = dstImageWidth;
+ convert.dstImageHeight = dstImageHeight;
convert.format = format;
convert.type = type;
convert.packing = packing;
if ( convert_needs_packing( packing, format, type ) )
convert.index |= CONVERT_PACKING_BIT;
- if ( width != imageWidth || height != imageHeight )
+ if ( width != dstImageWidth || height != dstImageHeight )
convert.index |= CONVERT_STRIDE_BIT;
return gl_convert_texsubimage3d_tab[mesaFormat]( &convert );
-/* $Id: texutil_tmp.h,v 1.4 2001/03/20 10:18:13 joukj Exp $ */
+/* $Id: texutil_tmp.h,v 1.5 2001/03/21 16:44:08 brianp Exp $ */
/*
* Mesa 3-D graphics library
#define DST_TEXEL_BYTES (4 / DST_TEXELS_PER_DWORD)
#define DST_ROW_WIDTH (convert->width * DST_TEXEL_BYTES)
-#define DST_ROW_STRIDE (convert->imageWidth * DST_TEXEL_BYTES)
-#define DST_IMG_STRIDE (convert->imageWidth * \
- convert->imageHeight * DST_TEXEL_BYTES)
+#define DST_ROW_STRIDE (convert->dstImageWidth * DST_TEXEL_BYTES)
+#define DST_IMG_STRIDE (convert->dstImageWidth * \
+ convert->dstImageHeight * DST_TEXEL_BYTES)
/* ================================================================
- * PRE: No pixelstore attribs, width == imageWidth.
+ * PRE: No pixelstore attribs, width == dstImageWidth.
*/
static GLboolean
TAG(texsubimage2d)( struct gl_texture_convert *convert )
{
const GLubyte *src = (const GLubyte *)convert->srcImage;
GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
- (convert->yoffset * convert->imageWidth +
+ (convert->yoffset * convert->dstImageWidth +
convert->xoffset) * DST_TEXEL_BYTES);
GLint dwords, i;
(void) dwords; (void) i;
return GL_TRUE;
}
-/* PRE: As above, height == imageHeight also.
+/* PRE: As above, height == dstImageHeight also.
*/
static GLboolean
TAG(texsubimage3d)( struct gl_texture_convert *convert )
/* ================================================================
- * PRE: No pixelstore attribs, width != imageWidth.
+ * PRE: No pixelstore attribs, width != dstImageWidth.
*/
static GLboolean
TAG(texsubimage2d_stride)( struct gl_texture_convert *convert )
{
const GLubyte *src = (const GLubyte *)convert->srcImage;
DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
- (convert->yoffset * convert->imageWidth +
+ (convert->yoffset * convert->dstImageWidth +
convert->xoffset) * DST_TEXEL_BYTES);
GLint adjust;
GLint row, col;
- adjust = convert->imageWidth - convert->width;
+ adjust = convert->dstImageWidth - convert->width;
if ( DBG ) {
fprintf( stderr, __FUNCTION__ ":\n" );
fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
convert->xoffset, convert->yoffset, convert->width,
- convert->height, convert->imageWidth );
+ convert->height, convert->dstImageWidth );
fprintf( stderr, " adjust=%d\n", adjust );
}
return GL_TRUE;
}
-/* PRE: As above, or height != imageHeight also.
+/* PRE: As above, or height != dstImageHeight also.
*/
static GLboolean
TAG(texsubimage3d_stride)( struct gl_texture_convert *convert )
{
const GLubyte *src = (const GLubyte *)convert->srcImage;
DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
- ((convert->zoffset * convert->imageHeight +
- convert->yoffset) * convert->imageWidth +
+ ((convert->zoffset * convert->dstImageHeight +
+ convert->yoffset) * convert->dstImageWidth +
convert->xoffset) * DST_TEXEL_BYTES);
GLint adjust;
GLint row, col, img;
- adjust = convert->imageWidth - convert->width;
+ adjust = convert->dstImageWidth - convert->width;
if ( DBG ) {
fprintf( stderr, __FUNCTION__ ":\n" );
fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
convert->xoffset, convert->yoffset, convert->width,
- convert->height, convert->imageWidth );
+ convert->height, convert->dstImageWidth );
fprintf( stderr, " adjust=%d\n", adjust );
}
/* ================================================================
- * PRE: Require pixelstore attribs, width == imageWidth.
+ * PRE: Require pixelstore attribs, width == dstImageWidth.
*/
static GLboolean
TAG(texsubimage2d_pack)( struct gl_texture_convert *convert )
return GL_TRUE;
}
-/* PRE: as above, height == imageHeight also.
+/* PRE: as above, height == dstImageHeight also.
*/
static GLboolean
TAG(texsubimage3d_pack)( struct gl_texture_convert *convert )
/* ================================================================
- * PRE: Require pixelstore attribs, width != imageWidth.
+ * PRE: Require pixelstore attribs, width != dstImageWidth.
*/
static GLboolean
TAG(texsubimage2d_stride_pack)( struct gl_texture_convert *convert )
_mesa_image_row_stride( convert->packing, convert->width,
convert->format, convert->type );
DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
- (convert->yoffset * convert->imageWidth +
+ (convert->yoffset * convert->dstImageWidth +
convert->xoffset) * DST_TEXEL_BYTES);
GLint adjust;
GLint row, col;
(void) col;
- adjust = convert->imageWidth - convert->width;
+ adjust = convert->dstImageWidth - convert->width;
if ( DBG ) {
fprintf( stderr, __FUNCTION__ ":\n" );
fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
convert->xoffset, convert->yoffset, convert->width,
- convert->height, convert->imageWidth );
+ convert->height, convert->dstImageWidth );
fprintf( stderr, " adjust=%d\n", adjust );
}
#ifdef CONVERT_DIRECT
MEMCPY( dst, src, DST_ROW_WIDTH );
src += srcRowStride;
- dst += convert->imageWidth;
+ dst += convert->dstImageWidth;
#else
const GLubyte *srcRow = src;
for ( col = 0 ; col < convert->width ; col++ ) {
return GL_TRUE;
}
-/* PRE: As above, or height != imageHeight also.
+/* PRE: As above, or height != dstImageHeight also.
*/
static GLboolean
TAG(texsubimage3d_stride_pack)( struct gl_texture_convert *convert )
_mesa_image_row_stride( convert->packing, convert->width,
convert->format, convert->type );
DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
- ((convert->zoffset * convert->imageHeight +
- convert->yoffset) * convert->imageWidth +
+ ((convert->zoffset * convert->dstImageHeight +
+ convert->yoffset) * convert->dstImageWidth +
convert->xoffset) * DST_TEXEL_BYTES);
GLint adjust;
GLint row, col, img;
(void) col;
- adjust = convert->imageWidth - convert->width;
+ adjust = convert->dstImageWidth - convert->width;
if ( DBG ) {
fprintf( stderr, __FUNCTION__ ":\n" );
fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
convert->xoffset, convert->yoffset, convert->width,
- convert->height, convert->imageWidth );
+ convert->height, convert->dstImageWidth );
fprintf( stderr, " adjust=%d\n", adjust );
}
#ifdef CONVERT_DIRECT
MEMCPY( dst, src, DST_ROW_WIDTH );
src += srcRowStride;
- dst += convert->imageWidth;
+ dst += convert->dstImageWidth;
#else
const GLubyte *srcRow = src;
for ( col = 0 ; col < convert->width ; col++ ) {