mirror of
https://github.com/brl/mutter.git
synced 2024-11-12 17:27:03 -05:00
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.
This commit is contained in:
parent
47f1b2ebc9
commit
1d54ecb8a1
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user