-/* $Id: osmesa.c,v 1.46 2001/02/12 18:32:26 brianp Exp $ */
+/* $Id: osmesa.c,v 1.47 2001/02/19 20:01:42 brianp Exp $ */
/*
* Mesa 3-D graphics library
ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
+ ctx->Driver.CopyTexImage1D = _mesa_copy_teximage1d;
+ ctx->Driver.CopyTexImage2D = _mesa_copy_teximage2d;
+ ctx->Driver.CopyTexSubImage1D = _mesa_copy_texsubimage1d;
+ ctx->Driver.CopyTexSubImage2D = _mesa_copy_texsubimage2d;
+ ctx->Driver.CopyTexSubImage3D = _mesa_copy_texsubimage3d;
ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
-/* $Id: xm_dd.c,v 1.14 2001/02/06 21:42:49 brianp Exp $ */
+/* $Id: xm_dd.c,v 1.15 2001/02/19 20:01:42 brianp Exp $ */
/*
* Mesa 3-D graphics library
ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
+ ctx->Driver.CopyTexImage1D = _mesa_copy_teximage1d;
+ ctx->Driver.CopyTexImage2D = _mesa_copy_teximage2d;
+ ctx->Driver.CopyTexSubImage1D = _mesa_copy_texsubimage1d;
+ ctx->Driver.CopyTexSubImage2D = _mesa_copy_texsubimage2d;
+ ctx->Driver.CopyTexSubImage3D = _mesa_copy_texsubimage3d;
ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
/*
-/* $Id: dd.h,v 1.52 2001/02/15 01:33:52 keithw Exp $ */
+/* $Id: dd.h,v 1.53 2001/02/19 20:02:37 brianp Exp $ */
/*
* Mesa 3-D graphics library
struct gl_texture_object *texObj,
struct gl_texture_image *texImage );
/* Called by glTexImage1/2/3D.
- * Will not be called if any glPixelTransfer operations are enabled.
* Arguments:
* <target>, <level>, <format>, <type> and <pixels> are user specified.
* <packing> indicates the image packing of pixels.
* width, height, depth, border and internalFormat information.
* <retainInternalCopy> is returned by this function and indicates whether
* core Mesa should keep an internal copy of the texture image.
- * Return GL_TRUE if operation completed, return GL_FALSE if core Mesa
- * should do the job. If GL_FALSE is returned, this function will be
- * called a second time after the texture image has been unpacked into
- * GLubytes. It may be easier for the driver to handle then.
+ * Drivers should call a fallback routine from texstore.c if needed.
*/
void (*TexSubImage1D)( GLcontext *ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage );
/* Called by glTexSubImage1/2/3D.
- * Will not be called if any glPixelTransfer operations are enabled.
* Arguments:
* <target>, <level>, <xoffset>, <yoffset>, <zoffset>, <width>, <height>,
* <depth>, <format>, <type> and <pixels> are user specified.
* <texObj> is the target texture object.
* <texImage> is the target texture image. It will have the texture
* width, height, border and internalFormat information.
- * Return GL_TRUE if operation completed, return GL_FALSE if core Mesa
- * should do the job. If GL_FALSE is returned, then TexImage1/2/3D will
- * be called with the complete texture image.
+ * The driver should use a fallback routine from texstore.c if needed.
*/
- GLboolean (*CopyTexImage1D)( GLcontext *ctx, GLenum target, GLint level,
- GLenum internalFormat, GLint x, GLint y,
- GLsizei width, GLint border );
- GLboolean (*CopyTexImage2D)( GLcontext *ctx, GLenum target, GLint level,
- GLenum internalFormat, GLint x, GLint y,
- GLsizei width, GLsizei height, GLint border );
+ void (*CopyTexImage1D)( GLcontext *ctx, GLenum target, GLint level,
+ GLenum internalFormat, GLint x, GLint y,
+ GLsizei width, GLint border );
+ void (*CopyTexImage2D)( GLcontext *ctx, GLenum target, GLint level,
+ GLenum internalFormat, GLint x, GLint y,
+ GLsizei width, GLsizei height, GLint border );
/* Called by glCopyTexImage1D and glCopyTexImage2D.
- * Will not be called if any glPixelTransfer operations are enabled.
- * Return GL_TRUE if operation completed, return GL_FALSE if core Mesa
- * should do the job.
- */
-
- GLboolean (*CopyTexSubImage1D)( GLcontext *ctx, GLenum target, GLint level,
- GLint xoffset,
- GLint x, GLint y, GLsizei width );
- GLboolean (*CopyTexSubImage2D)( GLcontext *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint x, GLint y,
- GLsizei width, GLsizei height );
- GLboolean (*CopyTexSubImage3D)( GLcontext *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y,
- GLsizei width, GLsizei height );
+ * Drivers should use a fallback routine from texstore.c if needed.
+ */
+
+ void (*CopyTexSubImage1D)( GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset,
+ GLint x, GLint y, GLsizei width );
+ void (*CopyTexSubImage2D)( GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height );
+ void (*CopyTexSubImage3D)( GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height );
/* Called by glCopyTexSubImage1/2/3D.
- * Will not be called if any glPixelTransfer operations are enabled.
- * Return GL_TRUE if operation completed, return GL_FALSE if core Mesa
- * should do the job.
+ * Drivers should use a fallback routine from texstore.c if needed.
*/
GLboolean (*TestProxyTexImage)(GLcontext *ctx, GLenum target,
-/* $Id: teximage.c,v 1.77 2001/02/17 18:41:01 brianp Exp $ */
+/* $Id: teximage.c,v 1.78 2001/02/19 20:01:41 brianp Exp $ */
/*
* Mesa 3-D graphics library
struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
+ if (ctx->NewState & _NEW_PIXEL)
+ gl_update_state(ctx);
+
/* XXX should test internal format */
if (is_color_format(format)) {
_mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
if (width == 0 || !pixels)
return; /* no-op, not an error */
- if (ctx->NewState & _NEW_PIXEL)
- gl_update_state(ctx);
-
ASSERT(ctx->Driver.TexSubImage1D);
(*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width,
format, type, pixels, &ctx->Unpack,
struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
+ if (ctx->NewState & _NEW_PIXEL)
+ gl_update_state(ctx);
+
/* XXX should test internal format */
if (is_color_format(format)) {
_mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
if (width == 0 || height == 0 || !pixels)
return; /* no-op, not an error */
- if (ctx->NewState & _NEW_PIXEL)
- gl_update_state(ctx);
-
ASSERT(ctx->Driver.TexSubImage2D);
(*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset,
width, height, format, type, pixels,
struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
+ if (ctx->NewState & _NEW_PIXEL)
+ gl_update_state(ctx);
+
if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
width, height, depth, format, type)) {
return; /* error was detected */
if (width == 0 || height == 0 || height == 0 || !pixels)
return; /* no-op, not an error */
- if (ctx->NewState & _NEW_PIXEL)
- gl_update_state(ctx);
-
ASSERT(ctx->Driver.TexSubImage3D);
(*ctx->Driver.TexSubImage3D)(ctx, target, level,
xoffset, yoffset, zoffset,
-/*
- * Read an RGBA image from the frame buffer.
- * This is used by glCopyTex[Sub]Image[12]D().
- * Input: ctx - the context
- * x, y - lower left corner
- * width, height - size of region to read
- * Return: pointer to block of GL_RGBA, GLchan data.
- */
-static GLchan *
-read_color_image( GLcontext *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height )
-{
- GLint stride, i;
- GLchan *image, *dst;
-
- image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan));
- if (!image)
- return NULL;
-
- /* Select buffer to read from */
- (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
-
- RENDER_START(ctx);
-
- dst = image;
- stride = width * 4;
- for (i = 0; i < height; i++) {
- gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
- (GLchan (*)[4]) dst );
- dst += stride;
- }
-
- RENDER_FINISH(ctx);
-
- /* Read from draw buffer (the default) */
- (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
-
- return image;
-}
-
-
-
void
_mesa_CopyTexImage1D( GLenum target, GLint level,
GLenum internalFormat,
GLint x, GLint y,
GLsizei width, GLint border )
{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
GLsizei postConvWidth = width;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
postConvWidth, 1, border))
return;
- if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage1D
- || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level,
- internalFormat, x, y, width, border)) {
- struct gl_pixelstore_attrib unpackSave;
-
- /* get image from framebuffer */
- GLchan *image = read_color_image( ctx, x, y, width, 1 );
- if (!image) {
- gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" );
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ if (!texImage) {
+ texImage = _mesa_alloc_texture_image();
+ set_tex_image(texObj, target, level, texImage);
+ if (!texImage) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
return;
}
+ }
+ else if (texImage->Data) {
+ /* free the old texture data */
+ FREE(texImage->Data);
+ texImage->Data = NULL;
+ }
- /* call glTexImage1D to redefine the texture */
- unpackSave = ctx->Unpack;
- ctx->Unpack = _mesa_native_packing;
- (*ctx->Exec->TexImage1D)( target, level, internalFormat, width,
- border, GL_RGBA, GL_UNSIGNED_BYTE, image );
- ctx->Unpack = unpackSave;
+ clear_teximage_fields(texImage); /* not really needed, but helpful */
+ init_teximage_fields(ctx, texImage, postConvWidth, 1, 1,
+ border, internalFormat);
- FREE(image);
- }
+
+ ASSERT(ctx->Driver.CopyTexImage1D);
+ (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat,
+ x, y, width, border);
+
+ /* state update */
+ texObj->Complete = GL_FALSE;
+ ctx->NewState |= _NEW_TEXTURE;
}
GLint x, GLint y, GLsizei width, GLsizei height,
GLint border )
{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
GLsizei postConvWidth = width, postConvHeight = height;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
postConvWidth, postConvHeight, border))
return;
- if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage2D
- || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level,
- internalFormat, x, y, width, height, border)) {
- struct gl_pixelstore_attrib unpackSave;
-
- /* get image from framebuffer */
- GLchan *image = read_color_image( ctx, x, y, width, height );
- if (!image) {
- gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D" );
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ if (!texImage) {
+ texImage = _mesa_alloc_texture_image();
+ set_tex_image(texObj, target, level, texImage);
+ if (!texImage) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
return;
}
+ }
+ else if (texImage->Data) {
+ /* free the old texture data */
+ FREE(texImage->Data);
+ texImage->Data = NULL;
+ }
- /* call glTexImage2D to redefine the texture */
- unpackSave = ctx->Unpack;
- ctx->Unpack = _mesa_native_packing;
- (ctx->Exec->TexImage2D)( target, level, internalFormat, width,
- height, border, GL_RGBA, GL_UNSIGNED_BYTE, image );
- ctx->Unpack = unpackSave;
+ clear_teximage_fields(texImage); /* not really needed, but helpful */
+ init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1,
+ border, internalFormat);
- FREE(image);
- }
+ ASSERT(ctx->Driver.CopyTexImage2D);
+ (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat,
+ x, y, width, height, border);
+
+ /* state update */
+ texObj->Complete = GL_FALSE;
+ ctx->NewState |= _NEW_TEXTURE;
}
xoffset, 0, 0, postConvWidth, 1))
return;
- if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage1D
- || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level,
- xoffset, x, y, width)) {
- struct gl_texture_unit *texUnit;
- struct gl_texture_image *teximage;
- struct gl_pixelstore_attrib unpackSave;
- GLchan *image;
-
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- teximage = texUnit->Current1D->Image[level];
- assert(teximage);
-
- /* get image from frame buffer */
- image = read_color_image(ctx, x, y, width, 1);
- if (!image) {
- gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D" );
- return;
- }
-
- /* now call glTexSubImage1D to do the real work */
- unpackSave = ctx->Unpack;
- ctx->Unpack = _mesa_native_packing;
- _mesa_TexSubImage1D(target, level, xoffset, width,
- GL_RGBA, GL_UNSIGNED_BYTE, image);
- ctx->Unpack = unpackSave;
-
- FREE(image);
- }
+ ASSERT(ctx->Driver.CopyTexSubImage1D);
+ (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width);
}
postConvWidth, postConvHeight))
return;
- if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage2D
- || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level,
- xoffset, yoffset, x, y, width, height )) {
- struct gl_texture_unit *texUnit;
- struct gl_texture_image *teximage;
- struct gl_pixelstore_attrib unpackSave;
- GLchan *image;
-
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- teximage = texUnit->Current2D->Image[level];
- assert(teximage);
-
- /* get image from frame buffer */
- image = read_color_image(ctx, x, y, width, height);
- if (!image) {
- gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" );
- return;
- }
-
- /* now call glTexSubImage2D to do the real work */
- unpackSave = ctx->Unpack;
- ctx->Unpack = _mesa_native_packing;
- _mesa_TexSubImage2D(target, level, xoffset, yoffset, width, height,
- GL_RGBA, GL_UNSIGNED_BYTE, image);
- ctx->Unpack = unpackSave;
-
- FREE(image);
- }
+ ASSERT(ctx->Driver.CopyTexSubImage2D);
+ (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level,
+ xoffset, yoffset, x, y, width, height);
}
zoffset, postConvWidth, postConvHeight))
return;
- if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage3D
- || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level,
- xoffset, yoffset, zoffset, x, y, width, height )) {
- struct gl_texture_unit *texUnit;
- struct gl_texture_image *teximage;
- struct gl_pixelstore_attrib unpackSave;
- GLchan *image;
-
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- teximage = texUnit->Current3D->Image[level];
- assert(teximage);
-
- /* get image from frame buffer */
- image = read_color_image(ctx, x, y, width, height);
- if (!image) {
- gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" );
- return;
- }
-
- /* now call glTexSubImage2D to do the real work */
- unpackSave = ctx->Unpack;
- ctx->Unpack = _mesa_native_packing;
- _mesa_TexSubImage3D(target, level, xoffset, yoffset, zoffset,
- width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);
- ctx->Unpack = unpackSave;
-
- FREE(image);
- }
+ ASSERT(ctx->Driver.CopyTexSubImage3D);
+ (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level,
+ xoffset, yoffset, zoffset,
+ x, y, width, height);
}
-/* $Id: texstore.c,v 1.6 2001/02/17 18:41:01 brianp Exp $ */
+/* $Id: texstore.c,v 1.7 2001/02/19 20:01:42 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "mem.h"
#include "teximage.h"
#include "texstore.h"
-
+#include "swrast/s_depth.h" /* XXX this is kind of a cheat */
+#include "swrast/s_span.h"
/*
rgba[RCOMP] = src[0];
rgba[GCOMP] = src[1];
rgba[BCOMP] = src[2];
+ rgba[ACOMP] = CHAN_MAX;
return;
}
case GL_ALPHA:
{
const GLchan *src = (GLchan *) img->Data + i;
GLchan *rgba = (GLchan *) texel;
+ rgba[RCOMP] = 0;
+ rgba[GCOMP] = 0;
+ rgba[BCOMP] = 0;
rgba[ACOMP] = src[0];
return;
}
case GL_LUMINANCE:
+ {
+ const GLchan *src = (GLchan *) img->Data + i;
+ GLchan *rgba = (GLchan *) texel;
+ rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
+ rgba[ACOMP] = CHAN_MAX;
+ return;
+ }
case GL_INTENSITY:
{
const GLchan *src = (GLchan *) img->Data + i;
GLchan *rgba = (GLchan *) texel;
rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
+ rgba[ACOMP] = src[0];
return;
}
case GL_LUMINANCE_ALPHA:
const GLchan *src = (GLchan *) img->Data + i * 2;
GLchan *rgba = (GLchan *) texel;
rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
rgba[ACOMP] = src[1];
return;
}
rgba[RCOMP] = src[0];
rgba[GCOMP] = src[1];
rgba[BCOMP] = src[2];
+ rgba[ACOMP] = CHAN_MAX;
return;
}
case GL_ALPHA:
{
const GLchan *src = (GLchan *) img->Data + (img->Width * j + i);
GLchan *rgba = (GLchan *) texel;
+ rgba[RCOMP] = 0;
+ rgba[GCOMP] = 0;
+ rgba[BCOMP] = 0;
rgba[ACOMP] = src[0];
return;
}
case GL_LUMINANCE:
+ {
+ const GLchan *src = (GLchan *) img->Data + (img->Width * j + i);
+ GLchan *rgba = (GLchan *) texel;
+ rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
+ rgba[ACOMP] = CHAN_MAX;
+ return;
+ }
case GL_INTENSITY:
{
const GLchan *src = (GLchan *) img->Data + (img->Width * j + i);
GLchan *rgba = (GLchan *) texel;
rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
+ rgba[ACOMP] = src[0];
return;
}
case GL_LUMINANCE_ALPHA:
{
const GLchan *src = (GLchan *) img->Data + (img->Width * j + i) * 2;
GLchan *rgba = (GLchan *) texel;
- rgba[RCOMP] = src[0];
+ rgba[RCOMP] = 0;
+ rgba[GCOMP] = 0;
+ rgba[BCOMP] = 0;
rgba[ACOMP] = src[1];
return;
}
rgba[RCOMP] = src[0];
rgba[GCOMP] = src[1];
rgba[BCOMP] = src[2];
+ rgba[ACOMP] = CHAN_MAX;
return;
}
case GL_ALPHA:
const GLchan *src = (GLchan *) img->Data
+ (rectArea * k + width * j + i);
GLchan *rgba = (GLchan *) texel;
+ rgba[RCOMP] = 0;
+ rgba[GCOMP] = 0;
+ rgba[BCOMP] = 0;
rgba[ACOMP] = src[0];
return;
}
case GL_LUMINANCE:
+ {
+ const GLchan *src = (GLchan *) img->Data
+ + (rectArea * k + width * j + i);
+ GLchan *rgba = (GLchan *) texel;
+ rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
+ rgba[ACOMP] = CHAN_MAX;
+ return;
+ }
case GL_INTENSITY:
{
const GLchan *src = (GLchan *) img->Data
+ (rectArea * k + width * j + i);
GLchan *rgba = (GLchan *) texel;
rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
+ rgba[ACOMP] = src[0];
return;
}
case GL_LUMINANCE_ALPHA:
+ (rectArea * k + width * j + i) * 2;
GLchan *rgba = (GLchan *) texel;
rgba[RCOMP] = src[0];
+ rgba[GCOMP] = src[0];
+ rgba[BCOMP] = src[0];
rgba[ACOMP] = src[1];
return;
}
+
+/*
+ * Read an RGBA image from the frame buffer.
+ * This is used by glCopyTex[Sub]Image[12]D().
+ * Input: ctx - the context
+ * x, y - lower left corner
+ * width, height - size of region to read
+ * Return: pointer to block of GL_RGBA, GLchan data.
+ */
+static GLchan *
+read_color_image( GLcontext *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height )
+{
+ GLint stride, i;
+ GLchan *image, *dst;
+
+ image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan));
+ if (!image)
+ return NULL;
+
+ /* Select buffer to read from */
+ (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+ ctx->Pixel.DriverReadBuffer );
+
+ RENDER_START(ctx);
+
+ dst = image;
+ stride = width * 4;
+ for (i = 0; i < height; i++) {
+ gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
+ (GLchan (*)[4]) dst );
+ dst += stride;
+ }
+
+ RENDER_FINISH(ctx);
+
+ /* Read from draw buffer (the default) */
+ (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+ ctx->Color.DriverDrawBuffer );
+
+ return image;
+}
+
+
+/*
+ * As above, but read data from depth buffer.
+ */
+static GLfloat *
+read_depth_image( GLcontext *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height )
+{
+ GLint i;
+ GLfloat *image, *dst;
+
+ image = (GLfloat *) MALLOC(width * height * sizeof(GLfloat));
+ if (!image)
+ return NULL;
+
+ RENDER_START(ctx);
+
+ dst = image;
+ for (i = 0; i < height; i++) {
+ _mesa_read_depth_span_float(ctx, width, x, y + i, dst);
+ dst += width;
+ }
+
+ RENDER_FINISH(ctx);
+
+ return image;
+}
+
+
+
+static GLboolean
+is_depth_format(GLenum format)
+{
+ switch (format) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16_SGIX:
+ case GL_DEPTH_COMPONENT24_SGIX:
+ case GL_DEPTH_COMPONENT32_SGIX:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/*
+ * Fallback for Driver.CopyTexImage1D().
+ */
+void
+_mesa_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLint border )
+{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ ASSERT(texObj);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ ASSERT(texImage);
+
+ ASSERT(ctx->Driver.TexImage1D);
+
+ if (is_depth_format(internalFormat)) {
+ /* read depth image from framebuffer */
+ GLfloat *image = read_depth_image(ctx, x, y, width, 1);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
+ return;
+ }
+
+ /* call glTexImage1D to redefine the texture */
+ (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat,
+ width, border,
+ GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+ else {
+ /* read RGBA image from framebuffer */
+ GLchan *image = read_color_image(ctx, x, y, width, 1);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
+ return;
+ }
+
+ /* call glTexImage1D to redefine the texture */
+ (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat,
+ width, border,
+ GL_RGBA, CHAN_TYPE, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+}
+
+
+/*
+ * Fallback for Driver.CopyTexImage2D().
+ */
+void
+_mesa_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLint border )
+{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ ASSERT(texObj);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ ASSERT(texImage);
+
+ ASSERT(ctx->Driver.TexImage2D);
+
+ if (is_depth_format(internalFormat)) {
+ /* read depth image from framebuffer */
+ GLfloat *image = read_depth_image(ctx, x, y, width, height);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
+ return;
+ }
+
+ /* call glTexImage2D to redefine the texture */
+ (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat,
+ width, height, border,
+ GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+ else {
+ /* read RGBA image from framebuffer */
+ GLchan *image = read_color_image(ctx, x, y, width, height);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
+ return;
+ }
+
+ /* call glTexImage2D to redefine the texture */
+ (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat,
+ width, height, border,
+ GL_RGBA, CHAN_TYPE, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+}
+
+
+/*
+ * Fallback for Driver.CopyTexSubImage1D().
+ */
+void
+_mesa_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y, GLsizei width)
+{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ ASSERT(texObj);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ ASSERT(texImage);
+
+ ASSERT(ctx->Driver.TexImage1D);
+
+ if (is_depth_format(texImage->IntFormat)) {
+ /* read depth image from framebuffer */
+ GLfloat *image = read_depth_image(ctx, x, y, width, 1);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D");
+ return;
+ }
+
+ /* call glTexImage1D to redefine the texture */
+ (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width,
+ GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+ else {
+ GLchan *image = read_color_image(ctx, x, y, width, 1);
+ if (!image) {
+ gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D" );
+ return;
+ }
+
+ /* now call glTexSubImage1D to do the real work */
+ (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width,
+ GL_RGBA, CHAN_TYPE, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+}
+
+
+/*
+ * Fallback for Driver.CopyTexSubImage2D().
+ */
+void
+_mesa_copy_texsubimage2d( GLcontext *ctx,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ ASSERT(texObj);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ ASSERT(texImage);
+
+ ASSERT(ctx->Driver.TexImage2D);
+
+ if (is_depth_format(texImage->IntFormat)) {
+ /* read depth image from framebuffer */
+ GLfloat *image = read_depth_image(ctx, x, y, width, height);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D");
+ return;
+ }
+
+ /* call glTexImage1D to redefine the texture */
+ (*ctx->Driver.TexSubImage2D)(ctx, target, level,
+ xoffset, yoffset, width, height,
+ GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+ else {
+ /* read RGBA image from framebuffer */
+ GLchan *image = read_color_image(ctx, x, y, width, height);
+ if (!image) {
+ gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" );
+ return;
+ }
+
+ /* now call glTexSubImage2D to do the real work */
+ (*ctx->Driver.TexSubImage2D)(ctx, target, level,
+ xoffset, yoffset, width, height,
+ GL_RGBA, CHAN_TYPE, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+}
+
+
+/*
+ * Fallback for Driver.CopyTexSubImage3D().
+ */
+void
+_mesa_copy_texsubimage3d( GLcontext *ctx,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ ASSERT(texObj);
+ texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
+ ASSERT(texImage);
+
+ ASSERT(ctx->Driver.TexImage3D);
+
+ if (is_depth_format(texImage->IntFormat)) {
+ /* read depth image from framebuffer */
+ GLfloat *image = read_depth_image(ctx, x, y, width, height);
+ if (!image) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage3D");
+ return;
+ }
+
+ /* call glTexImage1D to redefine the texture */
+ (*ctx->Driver.TexSubImage3D)(ctx, target, level,
+ xoffset, yoffset, zoffset, width, height, 1,
+ GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+ else {
+ /* read RGBA image from framebuffer */
+ GLchan *image = read_color_image(ctx, x, y, width, height);
+ if (!image) {
+ gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage3D" );
+ return;
+ }
+
+ /* now call glTexSubImage3D to do the real work */
+ (*ctx->Driver.TexSubImage3D)(ctx, target, level,
+ xoffset, yoffset, zoffset, width, height, 1,
+ GL_RGBA, CHAN_TYPE, image,
+ &_mesa_native_packing, texObj, texImage);
+ FREE(image);
+ }
+}
+
+
+
/*
* Fallback for Driver.CompressedTexImage1D()
*/
-/* $Id: texstore.h,v 1.1 2001/02/06 21:42:48 brianp Exp $ */
+/* $Id: texstore.h,v 1.2 2001/02/19 20:01:42 brianp Exp $ */
/*
* Mesa 3-D graphics library
struct gl_texture_image *texImage);
+extern void
+_mesa_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLint border);
+
+extern void
+_mesa_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLint border);
+
+
+extern void
+_mesa_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y, GLsizei width);
+
+extern void
+_mesa_copy_texsubimage2d(GLcontext *ctx,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height);
+
+extern void
+_mesa_copy_texsubimage3d(GLcontext *ctx,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height);
+
+
extern void
_mesa_store_compressed_teximage1d(GLcontext *ctx, GLenum target, GLint level,