summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorPaul Trojahn <paul.trojahn@gmail.com>2019-10-08 20:52:30 +0200
committerPaul Trojahn <paul.trojahn@gmail.com>2019-10-11 10:26:53 +0200
commitbdaedb601ce3f3bd87cc8fb773ae8ac912fd457b (patch)
tree184dd2d6c3728864a8c6ea228dff24cca20c6693 /drivers
parent2078dcbe15e7b1a25bc06b0834a007d63c7ccd01 (diff)
Fix draw_rect
OpenGL uses the diamond exit rule to rasterize lines. If we don't shift the points down and to the right by 0.5, the line can sometimes miss a pixel when it shouldn't. The final fragment of a line isn't drawn. By drawing the lines clockwise, we can avoid a missing pixel in the rectangle. See section 3.4.1 in the OpenGL 1.5 specification. Fixes #32279
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.cpp6
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp6
2 files changed, 8 insertions, 4 deletions
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp
index 6be48a4c58..740f641e1e 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.cpp
+++ b/drivers/gles2/rasterizer_canvas_gles2.cpp
@@ -494,8 +494,10 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur
if (line->width <= 1) {
Vector2 verts[2] = {
- Vector2(line->from.x, line->from.y),
- Vector2(line->to.x, line->to.y)
+ // Offset the line slightly to make sure we always draw the pixel at the from coordinate.
+ // Without this, corners of rectangles might be missing a pixel. (See diamond exit rule and #32657)
+ Vector2(Math::floor(line->from.x) + 0.5, Math::floor(line->from.y) + 0.5),
+ Vector2(Math::floor(line->to.x) + 0.5, Math::floor(line->to.y) + 0.5)
};
#ifdef GLES_OVER_GL
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index edffe852a2..e09ba755ea 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -548,8 +548,10 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur
if (line->width <= 1) {
Vector2 verts[2] = {
- Vector2(line->from.x, line->from.y),
- Vector2(line->to.x, line->to.y)
+ // Offset the line slightly to make sure we always draw the pixel at the from coordinate.
+ // Without this, corners of rectangles might be missing a pixel. (See diamond exit rule and #32657)
+ Vector2(Math::floor(line->from.x) + 0.5, Math::floor(line->from.y) + 0.5),
+ Vector2(Math::floor(line->to.x) + 0.5, Math::floor(line->to.y) + 0.5)
};
#ifdef GLES_OVER_GL