diff options
author | Brian Paul <[email protected]> | 1999-11-22 22:21:38 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 1999-11-22 22:21:38 +0000 |
commit | 4e176ff358956b773ec486a220cc21971ed97495 (patch) | |
tree | 02c41e423f33c7e8592ce5aa3df50bec8f9b76cd /src/mesa/main/drawpix.c | |
parent | 78fc78e0f68a20ae90f3d4aaf361751a9185a0b9 (diff) |
added _mesa_clip_pixelrect()
Diffstat (limited to 'src/mesa/main/drawpix.c')
-rw-r--r-- | src/mesa/main/drawpix.c | 46 |
1 files changed, 45 insertions, 1 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 */ |