From c09af388040f9f317220fcf3dc8c4da6bcbaf7ad Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 5 Jul 2015 18:05:55 -0600 Subject: [PATCH] AA branch: AddConvexPolyFilled() store normals on stack --- imgui.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7da9ff82..78551465 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9232,20 +9232,6 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun { // Anti-aliased Fill const float AA_SIZE = 1.0f; - - // Temporary buffer - GTempPolyData.resize(points_count); - ImVec2* temp_normals = >empPolyData[0]; - for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) - { - const ImVec2& p0 = points[i0]; - const ImVec2& p1 = points[i1]; - ImVec2 diff = p1 - p0; - diff *= ImInvLength(diff, 1.0f); - temp_normals[i0].x = diff.y; - temp_normals[i0].y = -diff.x; - } - const ImU32 col_trans = col & 0x00ffffff; const int idx_count = (points_count-2)*3 + points_count*6; const int vtx_count = (points_count*2); @@ -9260,6 +9246,18 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun idx_write += 3; } + // Compute normals + ImVec2* temp_normals = (ImVec2*)alloca(points_count * sizeof(ImVec2)); + for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) + { + const ImVec2& p0 = points[i0]; + const ImVec2& p1 = points[i1]; + ImVec2 diff = p1 - p0; + diff *= ImInvLength(diff, 1.0f); + temp_normals[i0].x = diff.y; + temp_normals[i0].y = -diff.x; + } + for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { // Average normals