From c247268499d2bf387fee0397bd76e5fb889fc5a1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Mar 2006 02:17:15 +0000 Subject: [PATCH] added _mesa_clip_to_region() --- src/mesa/main/image.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/mesa/main/image.h | 8 +++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index 0a117a967b6..263ce8ef64c 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -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; +} diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h index e31959565af..7953192c52f 100644 --- a/src/mesa/main/image.h +++ b/src/mesa/main/image.h @@ -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