From 49db9f4f775c2308c31bc3bacf64cd9263f70b55 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sat, 17 Oct 2009 00:31:26 +0100 Subject: [PATCH] [clip-stack] Handle flipped rectangles in try_pushing_rect_as_window_rect() We were ignoring the possibility that the current modelview matrix may flip the incoming rectangle in which case we didn't calculate a valid scissor rectangle for clipping. This fixes: http://bugzilla.o-hand.com/show_bug.cgi?id=1809 (Clipping doesn't work within an FBO) --- cogl/cogl-clip-stack.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c index 8cf59d197..e9a7571cc 100644 --- a/cogl/cogl-clip-stack.c +++ b/cogl/cogl-clip-stack.c @@ -203,6 +203,15 @@ try_pushing_rect_as_window_rect (float x_offset, cogl_get_modelview_matrix (&matrix); + /* If the modelview meets these constraints then a transformed rectangle + * should still be a rectangle when it reaches screen coordinates. + * + * FIXME: we are are making certain assumptions about the projection + * matrix a.t.m and should really be looking at the combined modelview + * and projection matrix. + * FIXME: we don't consider rotations that are a multiple of 90 degrees + * which could be quite common. + */ if (matrix.xy != 0 || matrix.xz != 0 || matrix.yx != 0 || matrix.yz != 0 || matrix.zx != 0 || matrix.zy != 0) @@ -214,6 +223,15 @@ try_pushing_rect_as_window_rect (float x_offset, transform_point (&matrix, &matrix_p, v, &_x0, &_y0); transform_point (&matrix, &matrix_p, v, &_x1, &_y1); + /* Consider that the modelview matrix may flip the rectangle + * along the x or y axis... */ +#define SWAP(A,B) do { float tmp = B; B = A; A = tmp; } while (0) + if (_x0 > _x1) + SWAP (_x0, _x1); + if (_y0 > _y1) + SWAP (_y0, _y1); +#undef SWAP + cogl_clip_push_window_rect (_x0, _y0, _x1 - _x0, _y1 - _y0); return TRUE; }