From 4084e3c215d4db6370422fc718217bade7445618 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 9 Nov 2004 01:03:49 +0000 Subject: [PATCH] added _mesa_clip_drawpixels() and _mesa_clip_readpixels() --- src/mesa/main/image.c | 98 ++++++++++++++++++++++++++++++++++++++++++- src/mesa/main/image.h | 16 ++++++- 2 files changed, 112 insertions(+), 2 deletions(-) diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index fcc5d4e3b44..f781687c0fa 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 c0c65fe5ef2..6ebdbdee727 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 -- 2.30.2