summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2004-11-09 01:03:49 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2004-11-09 01:03:49 +0000
commit4084e3c215d4db6370422fc718217bade7445618 (patch)
tree5527635cc6a98029f394831007dfaa7d03caca56
parent4f28c9c35a27c6171073b4045f173a6deeceb604 (diff)
added _mesa_clip_drawpixels() and _mesa_clip_readpixels()
-rw-r--r--src/mesa/main/image.c98
-rw-r--r--src/mesa/main/image.h16
2 files changed, 112 insertions, 2 deletions
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index fcc5d4e3b4..f781687c0f 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 6.2
+ * Version: 6.3
*
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
@@ -4057,3 +4057,99 @@ _mesa_unpack_image( GLsizei width, GLsizei height, GLsizei depth,
}
#endif
+
+
+/**
+ * Perform clipping for glDrawPixels. The image's window position
+ * and size, and the unpack skipPixels and skipRows are adjusted so
+ * that the image region is entirely within the window and scissor bounds.
+ *
+ * \return GL_TRUE if image is ready for drawing or
+ * GL_FALSE if image was completely clipped away (draw nothing)
+ */
+GLboolean
+_mesa_clip_drawpixels(const GLcontext *ctx,
+ GLint *destX, GLint *destY,
+ GLsizei *width, GLsizei *height,
+ GLint *skipPixels, GLint *skipRows)
+{
+ const GLframebuffer *buffer = ctx->DrawBuffer;
+
+ /* left clipping */
+ if (*destX < buffer->_Xmin) {
+ *skipPixels += (buffer->_Xmin - *destX);
+ *width -= (buffer->_Xmin - *destX);
+ *destX = buffer->_Xmin;
+ }
+ /* right clipping */
+ if (*destX + *width > buffer->_Xmax)
+ *width -= (*destX + *width - buffer->_Xmax);
+
+ if (*width <= 0)
+ return GL_FALSE;
+
+ /* bottom clipping */
+ if (*destY < buffer->_Ymin) {
+ *skipRows += (buffer->_Ymin - *destY);
+ *height -= (buffer->_Ymin - *destY);
+ *destY = buffer->_Ymin;
+ }
+ /* top clipping */
+ if (*destY + *height > buffer->_Ymax)
+ *height -= (*destY + *height - buffer->_Ymax);
+
+ if (*height <= 0)
+ return GL_TRUE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Perform clipping for glReadPixels. The image's window position
+ * and size, and the pack skipPixels and skipRows are adjusted so
+ * that the image region is entirely within the window bounds.
+ * Note: this is different from _mesa_clip_drawpixels() in that the
+ * scissor box is ignored, and we use the bounds of the current "read"
+ * surface;
+ *
+ * \return GL_TRUE if image is ready for drawing or
+ * GL_FALSE if image was completely clipped away (draw nothing)
+ */
+GLboolean
+_mesa_clip_readpixels(const GLcontext *ctx,
+ GLint *srcX, GLint *srcY,
+ GLsizei *width, GLsizei *height,
+ GLint *skipPixels, GLint *skipRows)
+{
+ const GLframebuffer *buffer = ctx->ReadBuffer;
+
+ /* left clipping */
+ if (*srcX < 0) {
+ *skipPixels += (0 - *srcX);
+ *width -= (0 - *srcX);
+ *srcX = 0;
+ }
+ /* right clipping */
+ if (*srcX + *width > buffer->Width)
+ *width -= (*srcX + *width - buffer->Width);
+
+ if (*width <= 0)
+ return GL_FALSE;
+
+ /* bottom clipping */
+ if (*srcY < 0) {
+ *skipRows += (0 - *srcY);
+ *height -= (0 - *srcY);
+ *srcY = 0;
+ }
+ /* top clipping */
+ if (*srcY + *height > buffer->Height)
+ *height -= (*srcY + *height - buffer->Height);
+
+ if (*height <= 0)
+ return GL_TRUE;
+
+ return GL_TRUE;
+}
+
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index c0c65fe5ef..6ebdbdee72 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -5,7 +5,7 @@
/*
* Mesa 3-D graphics library
- * Version: 6.1
+ * Version: 6.3
*
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
@@ -176,4 +176,18 @@ _mesa_unpack_image( GLsizei width, GLsizei height, GLsizei depth,
const struct gl_pixelstore_attrib *unpack );
+extern GLboolean
+_mesa_clip_drawpixels(const GLcontext *ctx,
+ GLint *destX, GLint *destY,
+ GLsizei *width, GLsizei *height,
+ GLint *skipPixels, GLint *skipRows);
+
+
+extern GLboolean
+_mesa_clip_readpixels(const GLcontext *ctx,
+ GLint *destX, GLint *destY,
+ GLsizei *width, GLsizei *height,
+ GLint *skipPixels, GLint *skipRows);
+
+
#endif