From e6ebc43d725710f69094afa6ff47d91e50cce1ad Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Sun, 24 Nov 2019 11:00:02 +0100 Subject: Fixed antialiased option for Polygon2D / Line2D Polygon2D: The property wasn't used anymore after switching from canvas_item_add_polygon() to canvas_item_add_triangle_array() for drawing. Line2D: Added the same property as for Polygon2D & fixed smooth line drawing to use indices correctly. Fixes #26823 --- scene/2d/line_2d.cpp | 18 ++++++++++++++++-- scene/2d/line_2d.h | 4 ++++ scene/2d/polygon_2d.cpp | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'scene') diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index ad405fabbb..af3ed671aa 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -47,6 +47,7 @@ Line2D::Line2D() { _texture_mode = LINE_TEXTURE_NONE; _sharp_limit = 2.f; _round_precision = 8; + _antialiased = false; } Rect2 Line2D::_edit_get_rect() const { @@ -260,6 +261,15 @@ int Line2D::get_round_precision() const { return _round_precision; } +void Line2D::set_antialiased(bool p_antialiased) { + _antialiased = p_antialiased; + update(); +} + +bool Line2D::get_antialiased() const { + return _antialiased; +} + void Line2D::_draw() { if (_points.size() <= 1 || _width == 0.f) return; @@ -305,8 +315,8 @@ void Line2D::_draw() { lb.vertices, lb.colors, lb.uvs, Vector(), Vector(), - - texture_rid); + texture_rid, -1, RID(), + _antialiased); // DEBUG // Draw wireframe @@ -386,6 +396,9 @@ void Line2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_round_precision", "precision"), &Line2D::set_round_precision); ClassDB::bind_method(D_METHOD("get_round_precision"), &Line2D::get_round_precision); + ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &Line2D::set_antialiased); + ClassDB::bind_method(D_METHOD("get_antialiased"), &Line2D::get_antialiased); + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve"); @@ -401,6 +414,7 @@ void Line2D::_bind_methods() { ADD_GROUP("Border", ""); ADD_PROPERTY(PropertyInfo(Variant::REAL, "sharp_limit"), "set_sharp_limit", "get_sharp_limit"); ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision"), "set_round_precision", "get_round_precision"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased"); BIND_ENUM_CONSTANT(LINE_JOINT_SHARP); BIND_ENUM_CONSTANT(LINE_JOINT_BEVEL); diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h index 14afa463ba..10b2bf16e4 100644 --- a/scene/2d/line_2d.h +++ b/scene/2d/line_2d.h @@ -108,6 +108,9 @@ public: void set_round_precision(int precision); int get_round_precision() const; + void set_antialiased(bool p_antialiased); + bool get_antialiased() const; + protected: void _notification(int p_what); void _draw(); @@ -131,6 +134,7 @@ private: LineTextureMode _texture_mode; float _sharp_limit; int _round_precision; + bool _antialiased; }; #endif // LINE2D_H diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index 5e14959e9d..9fe67a4d7e 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -308,7 +308,7 @@ void Polygon2D::_notification(int p_what) { if (invert || polygons.size() == 0) { Vector indices = Geometry::triangulate_polygon(points); if (indices.size()) { - VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID()); + VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, RID(), antialiased); } } else { //draw individual polygons @@ -342,7 +342,7 @@ void Polygon2D::_notification(int p_what) { } if (total_indices.size()) { - VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID()); + VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, RID(), antialiased); } #if 0 -- cgit v1.2.3