From 8d8cf317d560d7d26d9bcc101226dc400706ea36 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Thu, 2 May 2024 18:05:42 -0300 Subject: [PATCH] opengl+windows: work around a performance issue with lines. --- src/modules/graphics/Polyline.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/modules/graphics/Polyline.cpp b/src/modules/graphics/Polyline.cpp index f9537067d..e768687c4 100644 --- a/src/modules/graphics/Polyline.cpp +++ b/src/modules/graphics/Polyline.cpp @@ -471,13 +471,19 @@ void Polyline::draw(love::graphics::Graphics *gfx) void Polyline::fill_color_array(Color32 constant_color, STf_RGBAub *attributes, int count) { + // Note: assigning each element individually seems to be needed to avoid + // performance issues in OpenGL + Windows. VS' compiler is likely doing + // something that doesn't play nice with write-combined memory from the + // graphics driver, when assigning a whole struct after modifying it, or + // when using memcpy. for (int i = 0; i < count; ++i) { - Color32 c = constant_color; - c.a *= (i+1) % 2; // avoids branching. equiv to if (i%2 == 1) c.a = 0; attributes[i].s = 0.0f; attributes[i].t = 0.0f; - attributes[i].color = c; + attributes[i].color.r = constant_color.r; + attributes[i].color.g = constant_color.g; + attributes[i].color.b = constant_color.b; + attributes[i].color.a = constant_color.a * ((i + 1) % 2); // avoids branching. equiv to if (i%2 == 1) c.a = 0; } } @@ -485,11 +491,12 @@ void NoneJoinPolyline::fill_color_array(Color32 constant_color, STf_RGBAub *attr { for (int i = 0; i < count; ++i) { - Color32 c = constant_color; - c.a *= (i & 3) < 2; // if (i % 4 == 2 || i % 4 == 3) c.a = 0 attributes[i].s = 0.0f; attributes[i].t = 0.0f; - attributes[i].color = c; + attributes[i].color.r = constant_color.r; + attributes[i].color.g = constant_color.g; + attributes[i].color.b = constant_color.b; + attributes[i].color.a = constant_color.a * ((i & 3) < 2); // if (i % 4 == 2 || i % 4 == 3) c.a = 0 } }