summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2006-04-06 04:23:58 +0000
committerBrian Paul <[email protected]>2006-04-06 04:23:58 +0000
commita9bcf751030895494fc098f8d0ff56b2496bd993 (patch)
treed737cac7b38fa8cdc805d44aea838eae67bd7307 /src/mesa/swrast
parent762c3618f52ef5033844092074c63eee545500fa (diff)
Replace MESA_FORMAT_DEPTH_COMPONENT_FLOAT32 with 32-bit integer format.
This allows render to depth texture (we don't support floating pt. Z buffers). Rename MESA_FORMAT_DEPTH_COMPONENT16/32 as MESA_FORMAT_Z16/32. Software fallback for glCopyTexImage now uses integer temporary image instead of float, eliminates a lot of float/int conversions.
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r--src/mesa/swrast/s_depth.c83
-rw-r--r--src/mesa/swrast/s_depth.h9
-rw-r--r--src/mesa/swrast/s_texstore.c35
3 files changed, 106 insertions, 21 deletions
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 061eb9c595e..ab5dbce64c5 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 6.5.1
*
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -1265,6 +1265,85 @@ _swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb,
/**
+ * As above, but return 32-bit GLuint values.
+ */
+void
+_swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
+ GLint n, GLint x, GLint y, GLuint depth[] )
+{
+ const GLfloat scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
+
+ if (!rb) {
+ /* really only doing this to prevent FP exceptions later */
+ _mesa_bzero(depth, n * sizeof(GLfloat));
+ }
+
+ ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
+
+ if (y < 0 || y >= (GLint) rb->Height ||
+ x + n <= 0 || x >= (GLint) rb->Width) {
+ /* span is completely outside framebuffer */
+ _mesa_bzero(depth, n * sizeof(GLfloat));
+ return;
+ }
+
+ if (x < 0) {
+ GLint dx = -x;
+ GLint i;
+ for (i = 0; i < dx; i++)
+ depth[i] = 0.0;
+ x = 0;
+ n -= dx;
+ depth += dx;
+ }
+ if (x + n > (GLint) rb->Width) {
+ GLint dx = x + n - (GLint) rb->Width;
+ GLint i;
+ for (i = 0; i < dx; i++)
+ depth[n - i - 1] = 0.0;
+ n -= dx;
+ }
+ if (n <= 0) {
+ return;
+ }
+
+ if (rb->DataType == GL_UNSIGNED_INT) {
+ rb->GetRow(ctx, rb, n, x, y, depth);
+ if (rb->DepthBits < 32) {
+ GLuint shift = 32 - rb->DepthBits;
+ GLint i;
+ for (i = 0; i < n; i++) {
+ GLuint z = depth[i];
+ depth[i] = z << shift; /* XXX lsb bits? */
+ }
+ }
+ }
+ else if (rb->DataType == GL_UNSIGNED_SHORT) {
+ GLushort temp[MAX_WIDTH];
+ GLint i;
+ rb->GetRow(ctx, rb, n, x, y, temp);
+ if (rb->DepthBits == 16) {
+ for (i = 0; i < n; i++) {
+ GLuint z = temp[i];
+ depth[i] = (z << 16) | z;
+ }
+ }
+ else {
+ GLuint shift = 16 - rb->DepthBits;
+ for (i = 0; i < n; i++) {
+ GLuint z = temp[i];
+ depth[i] = (z << (shift + 16)) | (z << shift); /* XXX lsb bits? */
+ }
+ }
+ }
+ else {
+ _mesa_problem(ctx, "Invalid depth renderbuffer data type");
+ }
+}
+
+
+
+/**
* Clear the given z/depth renderbuffer.
*/
void
diff --git a/src/mesa/swrast/s_depth.h b/src/mesa/swrast/s_depth.h
index a5856151f06..f93d95fa3d2 100644
--- a/src/mesa/swrast/s_depth.h
+++ b/src/mesa/swrast/s_depth.h
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 6.5.1
*
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -45,6 +45,11 @@ _swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb,
extern void
+_swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
+ GLint n, GLint x, GLint y, GLuint depth[] );
+
+
+extern void
_swrast_clear_depth_buffer( GLcontext *ctx, struct gl_renderbuffer *rb );
diff --git a/src/mesa/swrast/s_texstore.c b/src/mesa/swrast/s_texstore.c
index d6b98acf9de..a9da77ed65b 100644
--- a/src/mesa/swrast/s_texstore.c
+++ b/src/mesa/swrast/s_texstore.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 6.5.1
*
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -88,18 +88,19 @@ read_color_image( GLcontext *ctx, GLint x, GLint y,
/**
- * As above, but read data from depth buffer.
+ * As above, but read data from depth buffer. Returned as GLuints.
+ * \sa read_color_image
*/
-static GLfloat *
+static GLuint *
read_depth_image( GLcontext *ctx, GLint x, GLint y,
GLsizei width, GLsizei height )
{
struct gl_renderbuffer *rb = ctx->ReadBuffer->_DepthBuffer;
SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLfloat *image, *dst;
+ GLuint *image, *dst;
GLint i;
- image = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat));
+ image = (GLuint *) _mesa_malloc(width * height * sizeof(GLuint));
if (!image)
return NULL;
@@ -107,7 +108,7 @@ read_depth_image( GLcontext *ctx, GLint x, GLint y,
dst = image;
for (i = 0; i < height; i++) {
- _swrast_read_depth_span_float(ctx, rb, width, x, y + i, dst);
+ _swrast_read_depth_span_uint(ctx, rb, width, x, y + i, dst);
dst += width;
}
@@ -255,7 +256,7 @@ _swrast_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level,
if (is_depth_format(internalFormat)) {
/* read depth image from framebuffer */
- GLfloat *image = read_depth_image(ctx, x, y, width, 1);
+ GLuint *image = read_depth_image(ctx, x, y, width, 1);
if (!image) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
return;
@@ -263,7 +264,7 @@ _swrast_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level,
/* call glTexImage1D to redefine the texture */
ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
width, border,
- GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image,
&ctx->DefaultPacking, texObj, texImage);
_mesa_free(image);
}
@@ -326,7 +327,7 @@ _swrast_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level,
if (is_depth_format(internalFormat)) {
/* read depth image from framebuffer */
- GLfloat *image = read_depth_image(ctx, x, y, width, height);
+ GLuint *image = read_depth_image(ctx, x, y, width, height);
if (!image) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
return;
@@ -334,7 +335,7 @@ _swrast_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level,
/* call glTexImage2D to redefine the texture */
ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
width, height, border,
- GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image,
&ctx->DefaultPacking, texObj, texImage);
_mesa_free(image);
}
@@ -394,7 +395,7 @@ _swrast_copy_texsubimage1d( GLcontext *ctx, GLenum target, GLint level,
if (texImage->_BaseFormat == GL_DEPTH_COMPONENT) {
/* read depth image from framebuffer */
- GLfloat *image = read_depth_image(ctx, x, y, width, 1);
+ GLuint *image = read_depth_image(ctx, x, y, width, 1);
if (!image) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D");
return;
@@ -402,7 +403,7 @@ _swrast_copy_texsubimage1d( GLcontext *ctx, GLenum target, GLint level,
/* call glTexSubImage1D to redefine the texture */
ctx->Driver.TexSubImage1D(ctx, target, level, xoffset, width,
- GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image,
&ctx->DefaultPacking, texObj, texImage);
_mesa_free(image);
}
@@ -463,7 +464,7 @@ _swrast_copy_texsubimage2d( GLcontext *ctx,
if (texImage->_BaseFormat == GL_DEPTH_COMPONENT) {
/* read depth image from framebuffer */
- GLfloat *image = read_depth_image(ctx, x, y, width, height);
+ GLuint *image = read_depth_image(ctx, x, y, width, height);
if (!image) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D");
return;
@@ -471,7 +472,7 @@ _swrast_copy_texsubimage2d( GLcontext *ctx,
/* call glTexImage2D to redefine the texture */
ctx->Driver.TexSubImage2D(ctx, target, level,
xoffset, yoffset, width, height,
- GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image,
&ctx->DefaultPacking, texObj, texImage);
_mesa_free(image);
}
@@ -534,7 +535,7 @@ _swrast_copy_texsubimage3d( GLcontext *ctx,
if (texImage->_BaseFormat == GL_DEPTH_COMPONENT) {
/* read depth image from framebuffer */
- GLfloat *image = read_depth_image(ctx, x, y, width, height);
+ GLuint *image = read_depth_image(ctx, x, y, width, height);
if (!image) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage3D");
return;
@@ -542,7 +543,7 @@ _swrast_copy_texsubimage3d( GLcontext *ctx,
/* call glTexImage3D to redefine the texture */
ctx->Driver.TexSubImage3D(ctx, target, level,
xoffset, yoffset, zoffset, width, height, 1,
- GL_DEPTH_COMPONENT, GL_FLOAT, image,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image,
&ctx->DefaultPacking, texObj, texImage);
_mesa_free(image);
}