summaryrefslogtreecommitdiffstats
path: root/servers/rendering/renderer_canvas_cull.cpp
diff options
context:
space:
mode:
authorkleonc <9283098+kleonc@users.noreply.github.com>2023-01-19 13:38:15 +0100
committerkleonc <9283098+kleonc@users.noreply.github.com>2023-01-19 21:08:25 +0100
commit728c51e3627a0f6d6ff60314b47b636221ffa4f2 (patch)
tree42fddf31fc564919927f342fe722fb18cb5689c4 /servers/rendering/renderer_canvas_cull.cpp
parent122106c8446046c58c65d96132b944089ebb5602 (diff)
downloadredot-engine-728c51e3627a0f6d6ff60314b47b636221ffa4f2.tar.gz
CanvasItem::draw_polyline Support thin polylines drawn using line strip
Diffstat (limited to 'servers/rendering/renderer_canvas_cull.cpp')
-rw-r--r--servers/rendering/renderer_canvas_cull.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp
index 4265ee5518..b9e3c4f303 100644
--- a/servers/rendering/renderer_canvas_cull.cpp
+++ b/servers/rendering/renderer_canvas_cull.cpp
@@ -821,6 +821,38 @@ void RendererCanvasCull::canvas_item_add_polyline(RID p_item, const Vector<Point
Vector<int> indices;
int point_count = p_points.size();
+
+ Item::CommandPolygon *pline = canvas_item->alloc_command<Item::CommandPolygon>();
+ ERR_FAIL_COND(!pline);
+
+ if (p_width < 0) {
+ if (p_antialiased) {
+ WARN_PRINT("Antialiasing is not supported for thin polylines drawn using line strips (`p_width < 0`).");
+ }
+
+ pline->primitive = RS::PRIMITIVE_LINE_STRIP;
+
+ if (p_colors.size() == 1 || p_colors.size() == point_count) {
+ pline->polygon.create(indices, p_points, p_colors);
+ } else {
+ Vector<Color> colors;
+ if (p_colors.is_empty()) {
+ colors.push_back(color);
+ } else {
+ colors.resize(point_count);
+ Color *colors_ptr = colors.ptrw();
+ for (int i = 0; i < point_count; i++) {
+ if (i < p_colors.size()) {
+ color = p_colors[i];
+ }
+ colors_ptr[i] = color;
+ }
+ }
+ pline->polygon.create(indices, p_points, colors);
+ }
+ return;
+ }
+
int polyline_point_count = point_count * 2;
bool loop = p_points[0].is_equal_approx(p_points[point_count - 1]);
@@ -845,9 +877,6 @@ void RendererCanvasCull::canvas_item_add_polyline(RID p_item, const Vector<Point
}
}
- Item::CommandPolygon *pline = canvas_item->alloc_command<Item::CommandPolygon>();
- ERR_FAIL_COND(!pline);
-
PackedColorArray colors;
PackedVector2Array points;