added _mesa_clip_to_region()

This commit is contained in:
Brian Paul 2006-03-20 02:17:15 +00:00
parent b2cb8920c2
commit c247268499
2 changed files with 49 additions and 2 deletions

View file

@ -2,7 +2,7 @@
* Mesa 3-D graphics library
* Version: 6.5
*
* 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"),
@ -4312,3 +4312,44 @@ _mesa_clip_readpixels(const GLcontext *ctx,
return GL_TRUE;
}
/**
* Clip the rectangle defined by (x, y, width, height) against the bounds
* specified by [xmin, xmax) and [ymin, ymax).
* \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
*/
GLboolean
_mesa_clip_to_region(GLcontext *ctx,
GLint xmin, GLint ymin,
GLint xmax, GLint ymax,
GLint *x, GLint *y,
GLsizei *width, GLsizei *height )
{
/* left clipping */
if (*x < xmin) {
*width -= (xmin - *x);
*x = xmin;
}
/* right clipping */
if (*x + *width > xmax)
*width -= (*x + *width - xmax - 1);
if (*width <= 0)
return GL_FALSE;
/* bottom (or top) clipping */
if (*y < ymin) {
*height -= (ymin - *y);
*y = ymin;
}
/* top (or bottom) clipping */
if (*y + *height > ymax)
*height -= (*y + *height - ymax - 1);
if (*height <= 0)
return GL_FALSE;
return GL_TRUE;
}

View file

@ -2,7 +2,7 @@
* Mesa 3-D graphics library
* Version: 6.5
*
* 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"),
@ -216,5 +216,11 @@ _mesa_clip_readpixels(const GLcontext *ctx,
GLsizei *width, GLsizei *height,
struct gl_pixelstore_attrib *pack);
extern GLboolean
_mesa_clip_to_region(GLcontext *ctx,
GLint xmin, GLint ymin,
GLint xmax, GLint ymax,
GLint *x, GLint *y,
GLsizei *width, GLsizei *height );
#endif