Commit 05054bed authored by Neil Roberts's avatar Neil Roberts

cogl-clip-stack: Round the coords when clipping to a window rect

The size and position of the window rectangle for clipping in
try_pushing_rect_as_window_rect is calculated by projecting the
rectangle coordinates. Due to rounding errors, this can end up with
slightly off numbers like 34.999999. These were then being cast
directly to an integer so it could end up off by one.

This uses a new macro called COGL_UTIL_NEARBYINT which is a
replacement for the C99 nearbyint function.
parent a726ef32
......@@ -37,6 +37,7 @@
#include "cogl-internal.h"
#include "cogl-framebuffer-private.h"
#include "cogl-journal-private.h"
#include "cogl-util.h"
void _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
floatVec2 nodes_max,
......@@ -483,7 +484,10 @@ try_pushing_rect_as_window_rect (float x_1,
SWAP (y_1, y_2);
#undef SWAP
cogl_clip_push_window_rectangle (x_1, y_1, x_2 - x_1, y_2 - y_1);
cogl_clip_push_window_rectangle (COGL_UTIL_NEARBYINT (x_1),
COGL_UTIL_NEARBYINT (y_1),
COGL_UTIL_NEARBYINT (x_2 - x_1),
COGL_UTIL_NEARBYINT (y_2 - y_1));
return TRUE;
}
......
......@@ -52,4 +52,12 @@ cogl_util_float_signbit (float x)
}
#endif
/* This is a replacement for the nearbyint function which always
rounds to the nearest integer. nearbyint is apparently a C99
function so it might not always be available but also it seems in
glibc it is defined as a function call so this macro could end up
faster anyway. We can't just add 0.5f because it will break for
negative numbers. */
#define COGL_UTIL_NEARBYINT(x) ((int) ((x) < 0.0f ? (x) - 0.5f : (x) + 0.5f))
#endif /* __COGL_UTIL_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment