AA branch: AddConvexPolyFilled() store normals on stack

This commit is contained in:
ocornut 2015-07-05 18:05:55 -06:00
parent a74ca9025f
commit c09af38804

View File

@ -9232,20 +9232,6 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
{ {
// Anti-aliased Fill // Anti-aliased Fill
const float AA_SIZE = 1.0f; const float AA_SIZE = 1.0f;
// Temporary buffer
GTempPolyData.resize(points_count);
ImVec2* temp_normals = &GTempPolyData[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 ImU32 col_trans = col & 0x00ffffff;
const int idx_count = (points_count-2)*3 + points_count*6; const int idx_count = (points_count-2)*3 + points_count*6;
const int vtx_count = (points_count*2); const int vtx_count = (points_count*2);
@ -9260,6 +9246,18 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
idx_write += 3; 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++) for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++)
{ {
// Average normals // Average normals