diff options
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/drawpix.c | 46 | ||||
-rw-r--r-- | src/mesa/main/drawpix.h | 9 |
2 files changed, 53 insertions, 2 deletions
diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c index 4166596ed65..a3f13546441 100644 --- a/src/mesa/main/drawpix.c +++ b/src/mesa/main/drawpix.c @@ -1,4 +1,4 @@ -/* $Id: drawpix.c,v 1.7 1999/11/18 15:44:37 brianp Exp $ */ +/* $Id: drawpix.c,v 1.8 1999/11/22 22:21:38 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -45,6 +45,50 @@ /* + * Given the dest position, size and skipPixels and skipRows values + * for a glDrawPixels command, perform clipping of the image bounds + * so the result lies withing the context's buffer bounds. + * Return: GL_TRUE if image is ready for drawing + * GL_FALSE if image was completely clipped away (draw nothing) + */ +GLboolean +_mesa_clip_pixelrect(const GLcontext *ctx, + GLint *destX, GLint *destY, + GLsizei *width, GLsizei *height, + GLint *skipPixels, GLint *skipRows) +{ + /* left clipping */ + if (*destX < ctx->Buffer->Xmin) { + *skipPixels += (ctx->Buffer->Xmin - *destX); + *width -= (ctx->Buffer->Xmin - *destX); + *destX = ctx->Buffer->Xmin; + } + /* right clipping */ + if (*destX + *width > ctx->Buffer->Xmax) + *width -= (*destX + *width - ctx->Buffer->Xmax - 1); + + if (*width <= 0) + return GL_FALSE; + + /* bottom clipping */ + if (*destY < ctx->Buffer->Ymin) { + *skipRows += (ctx->Buffer->Ymin - *destY); + *height -= (ctx->Buffer->Ymin - *destY); + *destY = ctx->Buffer->Ymin; + } + /* top clipping */ + if (*destY + *height > ctx->Buffer->Ymax) + *height -= (*destY + *height - ctx->Buffer->Ymax - 1); + + if (*height <= 0) + return GL_TRUE; + + return GL_TRUE; +} + + + +/* * Try to do a fast and simple RGB(a) glDrawPixels. * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead */ diff --git a/src/mesa/main/drawpix.h b/src/mesa/main/drawpix.h index 40da8dfb2c8..3a0fd57bc17 100644 --- a/src/mesa/main/drawpix.h +++ b/src/mesa/main/drawpix.h @@ -1,4 +1,4 @@ -/* $Id: drawpix.h,v 1.2 1999/11/11 01:22:26 brianp Exp $ */ +/* $Id: drawpix.h,v 1.3 1999/11/22 22:21:38 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -32,6 +32,13 @@ #include "types.h" +extern GLboolean +_mesa_clip_pixelrect(const GLcontext *ctx, + GLint *destX, GLint *destY, + GLsizei *width, GLsizei *height, + GLint *skipPixels, GLint *skipRows); + + extern void _mesa_DrawPixels( GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels ); |