Skip to content

Commit d3e8da8

Browse files
committed
ImDrawList: remove local vs member indirection as locals were deemed better.
1 parent 255820d commit d3e8da8

File tree

1 file changed

+61
-70
lines changed

1 file changed

+61
-70
lines changed

imgui_draw.cpp

+61-70
Original file line numberDiff line numberDiff line change
@@ -731,58 +731,51 @@ void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, c
731731
#define IM_POLYLINE_IDX_16_BIT 0
732732
#else
733733
#define IM_POLYLINE_IDX_16_BIT 1
734-
# endif
735-
736-
// Macros that declare, load and save write pointers as local variables
737-
#if 1 // FIXME-NEWPOLYLINE: choose local or shared write pointers
738-
#define IM_POLYLINE_PRIM_VTX_WRITE vtx_write
739-
#define IM_POLYLINE_PRIM_IDX_WRITE idx_write
740-
#define IM_POLYLINE_PRIM_IDX_BASE idx_base
741-
742-
#define IM_POLYLINE_PRIM_MAKE_LOCAL() ImDrawVert* IM_POLYLINE_PRIM_VTX_WRITE = this->_VtxWritePtr; ImDrawIdx* IM_POLYLINE_PRIM_IDX_WRITE = this->_IdxWritePtr; unsigned int IM_POLYLINE_PRIM_IDX_BASE = this->_VtxCurrentIdx
743-
#define IM_POLYLINE_PRIM_LOAD_LOCAL() IM_POLYLINE_PRIM_VTX_WRITE = this->_VtxWritePtr; IM_POLYLINE_PRIM_IDX_WRITE = this->_IdxWritePtr; IM_POLYLINE_PRIM_IDX_BASE = this->_VtxCurrentIdx
744-
#define IM_POLYLINE_PRIM_SAVE_LOCAL() this->_VtxWritePtr = IM_POLYLINE_PRIM_VTX_WRITE; this->_IdxWritePtr = IM_POLYLINE_PRIM_IDX_WRITE; this->_VtxCurrentIdx = IM_POLYLINE_PRIM_IDX_BASE
745-
#else
746-
#define IM_POLYLINE_PRIM_VTX_WRITE this->_VtxWritePtr
747-
#define IM_POLYLINE_PRIM_IDX_WRITE this->_IdxWritePtr
748-
#define IM_POLYLINE_PRIM_IDX_BASE this->_VtxCurrentIdx
749-
750-
#define IM_POLYLINE_PRIM_MAKE_LOCAL() (void)0
751-
#define IM_POLYLINE_PRIM_LOAD_LOCAL() (void)0
752-
#define IM_POLYLINE_PRIM_SAVE_LOCAL() (void)0
753734
#endif
754735

755736
// Macros that commit, split and handle vertex offset overflow
756-
#define IM_POLYLINE_PRIM_RESERVE(IDX_COUNT, VTX_COUNT) this->PrimReserve((IDX_COUNT) + IM_POLYLINE_PRIM_EXTRA_IDX_COUNT, VTX_COUNT); IM_POLYLINE_PRIM_MAKE_LOCAL()
757-
#define IM_POLYLINE_PRIM_COMMIT() \
758-
IM_POLYLINE_PRIM_SAVE_LOCAL(); \
759-
const int unused_vtx_count = (int)((this->VtxBuffer.Data + this->VtxBuffer.Size) - this->_VtxWritePtr); \
760-
const int unused_idx_count = (int)((this->IdxBuffer.Data + this->IdxBuffer.Size) - this->_IdxWritePtr); \
737+
#define IM_POLYLINE_PRIM_RESERVE(IDX_COUNT, VTX_COUNT) \
738+
this->PrimReserve((IDX_COUNT) + IM_POLYLINE_PRIM_EXTRA_IDX_COUNT, VTX_COUNT); \
739+
ImDrawVert* vtx_write = this->_VtxWritePtr; \
740+
ImDrawIdx* idx_write = this->_IdxWritePtr; \
741+
unsigned int idx_base = this->_VtxCurrentIdx;
742+
743+
#define IM_POLYLINE_PRIM_COMMIT() \
744+
this->_VtxWritePtr = vtx_write; \
745+
this->_IdxWritePtr = idx_write; \
746+
this->_VtxCurrentIdx = idx_base; \
747+
const int unused_vtx_count = (int)((this->VtxBuffer.Data + this->VtxBuffer.Size) - vtx_write); \
748+
const int unused_idx_count = (int)((this->IdxBuffer.Data + this->IdxBuffer.Size) - idx_write); \
761749
this->PrimUnreserve(unused_idx_count, unused_vtx_count)
762750

763-
#define IM_POLYLINE_PRIM_SPLT() IM_POLYLINE_PRIM_COMMIT(); this->PrimReserve(unused_idx_count, unused_vtx_count); IM_POLYLINE_PRIM_LOAD_LOCAL()
751+
#define IM_POLYLINE_PRIM_SPLIT() \
752+
IM_POLYLINE_PRIM_COMMIT(); \
753+
this->PrimReserve(unused_idx_count, unused_vtx_count); \
754+
vtx_write = this->_VtxWritePtr; \
755+
idx_write = this->_IdxWritePtr; \
756+
idx_base = this->_VtxCurrentIdx;
764757

765758
#define IM_POLYLINE_VTX_COMMIT(N) \
766759
{ \
767-
IM_ASSERT_PARANOID((IM_POLYLINE_PRIM_VTX_WRITE + (N)) <= (this->VtxBuffer.Data + this->VtxBuffer.Size) && "IM_POLYLINE_VTX_COMMIT: VtxWritePtr moved out of bounds!"); \
768-
IM_POLYLINE_PRIM_VTX_WRITE += N; \
769-
IM_POLYLINE_PRIM_IDX_BASE += N; \
760+
IM_ASSERT_PARANOID((idx_base + (N)) <= (this->VtxBuffer.Data + this->VtxBuffer.Size) && "IM_POLYLINE_VTX_COMMIT: VtxWritePtr moved out of bounds!"); \
761+
vtx_write += N; \
762+
idx_base += N; \
770763
}
771764

772765
#if IM_POLYLINE_IDX_16_BIT
773-
#define IM_POLYLINE_PRIM_HANDLE_VTX_OFFSET_OVERFLOW(NEXT_BATCH_VTX_COUNT) if (sizeof(ImDrawIdx) == 2 && ((IM_POLYLINE_PRIM_IDX_BASE) + (NEXT_BATCH_VTX_COUNT) >= (1 << 16)) && (Flags & ImDrawListFlags_AllowVtxOffset)) IM_UNLIKELY { IM_POLYLINE_PRIM_SPLT(); }
766+
#define IM_POLYLINE_PRIM_HANDLE_VTX_OFFSET_OVERFLOW(NEXT_BATCH_VTX_COUNT) if (sizeof(ImDrawIdx) == 2 && (idx_base + (NEXT_BATCH_VTX_COUNT) >= (1 << 16)) && (Flags & ImDrawListFlags_AllowVtxOffset)) IM_UNLIKELY { IM_POLYLINE_PRIM_SPLIT(); }
774767
#else
775768
#define IM_POLYLINE_PRIM_HANDLE_VTX_OFFSET_OVERFLOW(NEXT_BATCH_VTX_COUNT) (void)0
776769
#endif
777770

778771
// Macros for filling vertices
779772
#define IM_POLYLINE_VERTEX(N, X, Y, UV, C) \
780773
{ \
781-
IM_ASSERT_PARANOID((IM_POLYLINE_PRIM_VTX_WRITE + (N)) < (this->VtxBuffer.Data + this->VtxBuffer.Size) && "IM_POLYLINE_VERTEX: Writing outside of allocated buffer!"); \
782-
IM_POLYLINE_PRIM_VTX_WRITE[N].pos.x = X; \
783-
IM_POLYLINE_PRIM_VTX_WRITE[N].pos.y = Y; \
784-
IM_POLYLINE_PRIM_VTX_WRITE[N].uv = UV; \
785-
IM_POLYLINE_PRIM_VTX_WRITE[N].col = C; \
774+
IM_ASSERT_PARANOID((vtx_write + (N)) < (this->VtxBuffer.Data + this->VtxBuffer.Size) && "IM_POLYLINE_VERTEX: Writing outside of allocated buffer!"); \
775+
vtx_write[N].pos.x = X; \
776+
vtx_write[N].pos.y = Y; \
777+
vtx_write[N].uv = UV; \
778+
vtx_write[N].col = C; \
786779
}
787780

788781
// Macros for filling indices
@@ -811,7 +804,7 @@ IM_STATIC_ASSERT(2 * sizeof(ImDrawIdx) == sizeof(ImU64)); // assumption: ImU64 m
811804
I[(N) * 3 + 2] = (ImDrawIdx)(Z + C)
812805
#endif
813806

814-
#define IM_POLYLINE_TRIANGLE(N, A, B, C) (void)(N); IM_POLYLINE_TRIANGLE_EX(IM_POLYLINE_PRIM_IDX_WRITE, N, IM_POLYLINE_PRIM_IDX_BASE, A, B, C)
807+
#define IM_POLYLINE_TRIANGLE(N, A, B, C) (void)(N); IM_POLYLINE_TRIANGLE_EX(idx_write, N, idx_base, A, B, C)
815808

816809
// Extra indices to allocate for primitives
817810
#ifndef IM_POLYLINE_PRIM_EXTRA_IDX_COUNT
@@ -1020,17 +1013,17 @@ void ImDrawList::_PolylineThinAntiAliased(const ImDrawListPolyline& polyline)
10201013
const float d_x = n0.x * t; \
10211014
const float d_y = n0.y * t; \
10221015
\
1023-
IM_POLYLINE_PRIM_VTX_WRITE[0].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[0].pos.y += d_x; \
1024-
IM_POLYLINE_PRIM_VTX_WRITE[1].pos.x += d_y; IM_POLYLINE_PRIM_VTX_WRITE[1].pos.y -= d_x; \
1025-
IM_POLYLINE_PRIM_VTX_WRITE[2].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[2].pos.y += d_x; \
1016+
vtx_write[0].pos.x -= d_y; vtx_write[0].pos.y += d_x; \
1017+
vtx_write[1].pos.x += d_y; vtx_write[1].pos.y -= d_x; \
1018+
vtx_write[2].pos.x -= d_y; vtx_write[2].pos.y += d_x; \
10261019
} \
10271020
else IM_UNLIKELY \
10281021
{ \
10291022
const float d_x = n0.x * half_thickness * scale; \
10301023
const float d_y = n0.y * half_thickness * scale; \
10311024
\
1032-
IM_POLYLINE_PRIM_VTX_WRITE[0].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[0].pos.y += d_x; \
1033-
IM_POLYLINE_PRIM_VTX_WRITE[2].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[2].pos.y += d_x; \
1025+
vtx_write[0].pos.x -= d_y; vtx_write[0].pos.y += d_x; \
1026+
vtx_write[2].pos.x -= d_y; vtx_write[2].pos.y += d_x; \
10341027
} \
10351028
\
10361029
IM_POLYLINE_TRIANGLE_BEGIN(3); \
@@ -1367,10 +1360,10 @@ void ImDrawList::_PolylineThinAntiAliased(const ImDrawListPolyline& polyline)
13671360
//
13681361
// 1 join triangles
13691362
//
1370-
IM_POLYLINE_PRIM_VTX_WRITE[6].pos.x -= n1.y * polyline.fringe_width;
1371-
IM_POLYLINE_PRIM_VTX_WRITE[6].pos.y += n1.x * polyline.fringe_width;
1372-
IM_POLYLINE_PRIM_VTX_WRITE[8].pos.x -= n1.y * polyline.fringe_width;
1373-
IM_POLYLINE_PRIM_VTX_WRITE[8].pos.y += n1.x * polyline.fringe_width;
1363+
vtx_write[6].pos.x -= n1.y * polyline.fringe_width;
1364+
vtx_write[6].pos.y += n1.x * polyline.fringe_width;
1365+
vtx_write[8].pos.x -= n1.y * polyline.fringe_width;
1366+
vtx_write[8].pos.y += n1.x * polyline.fringe_width;
13741367

13751368
IM_POLYLINE_TRIANGLE_BEGIN(3);
13761369
IM_POLYLINE_TRIANGLE(0, 6, 8, 7);
@@ -1399,9 +1392,9 @@ void ImDrawList::_PolylineThinAntiAliased(const ImDrawListPolyline& polyline)
13991392
{
14001393
ImDrawVert* vtx_start = this->VtxBuffer.Data + vtx_start_idx;
14011394

1402-
vtx_start[0].pos = IM_POLYLINE_PRIM_VTX_WRITE[0].pos;
1403-
vtx_start[1].pos = IM_POLYLINE_PRIM_VTX_WRITE[1].pos;
1404-
vtx_start[2].pos = IM_POLYLINE_PRIM_VTX_WRITE[2].pos;
1395+
vtx_start[0].pos = vtx_write[0].pos;
1396+
vtx_start[1].pos = vtx_write[1].pos;
1397+
vtx_start[2].pos = vtx_write[2].pos;
14051398
}
14061399
else IM_UNLIKELY
14071400
{
@@ -1466,10 +1459,10 @@ void ImDrawList::_PolylineThickAntiAliased(const ImDrawListPolyline& polyline)
14661459
const float d_x = n0.x * t; \
14671460
const float d_y = n0.y * t; \
14681461
\
1469-
IM_POLYLINE_PRIM_VTX_WRITE[0].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[0].pos.y += d_x; \
1470-
IM_POLYLINE_PRIM_VTX_WRITE[1].pos.x += d_y; IM_POLYLINE_PRIM_VTX_WRITE[1].pos.y -= d_x; \
1471-
IM_POLYLINE_PRIM_VTX_WRITE[2].pos.x += d_y; IM_POLYLINE_PRIM_VTX_WRITE[2].pos.y -= d_x; \
1472-
IM_POLYLINE_PRIM_VTX_WRITE[3].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[3].pos.y += d_x; \
1462+
vtx_write[0].pos.x -= d_y; vtx_write[0].pos.y += d_x; \
1463+
vtx_write[1].pos.x += d_y; vtx_write[1].pos.y -= d_x; \
1464+
vtx_write[2].pos.x += d_y; vtx_write[2].pos.y -= d_x; \
1465+
vtx_write[3].pos.x -= d_y; vtx_write[3].pos.y += d_x; \
14731466
} \
14741467
else \
14751468
{ \
@@ -1478,10 +1471,10 @@ void ImDrawList::_PolylineThickAntiAliased(const ImDrawListPolyline& polyline)
14781471
const float d_outer_x = n0.x * half_fringe_thickness * scale; \
14791472
const float d_outer_y = n0.y * half_fringe_thickness * scale; \
14801473
\
1481-
IM_POLYLINE_PRIM_VTX_WRITE[0].pos.x -= d_outer_y; IM_POLYLINE_PRIM_VTX_WRITE[0].pos.y += d_outer_x; \
1482-
IM_POLYLINE_PRIM_VTX_WRITE[1].pos.x -= d_inner_y; IM_POLYLINE_PRIM_VTX_WRITE[1].pos.y += d_inner_x; \
1483-
IM_POLYLINE_PRIM_VTX_WRITE[2].pos.x -= d_inner_y; IM_POLYLINE_PRIM_VTX_WRITE[2].pos.y += d_inner_x; \
1484-
IM_POLYLINE_PRIM_VTX_WRITE[3].pos.x -= d_outer_y; IM_POLYLINE_PRIM_VTX_WRITE[3].pos.y += d_outer_x; \
1474+
vtx_write[0].pos.x -= d_outer_y; vtx_write[0].pos.y += d_outer_x; \
1475+
vtx_write[1].pos.x -= d_inner_y; vtx_write[1].pos.y += d_inner_x; \
1476+
vtx_write[2].pos.x -= d_inner_y; vtx_write[2].pos.y += d_inner_x; \
1477+
vtx_write[3].pos.x -= d_outer_y; vtx_write[3].pos.y += d_outer_x; \
14851478
} \
14861479
\
14871480
IM_POLYLINE_TRIANGLE_BEGIN(6); \
@@ -2085,10 +2078,10 @@ void ImDrawList::_PolylineThickAntiAliased(const ImDrawListPolyline& polyline)
20852078
{
20862079
ImDrawVert* vtx_start = this->VtxBuffer.Data + vtx_start_idx;
20872080

2088-
vtx_start[0].pos = IM_POLYLINE_PRIM_VTX_WRITE[0].pos;
2089-
vtx_start[1].pos = IM_POLYLINE_PRIM_VTX_WRITE[1].pos;
2090-
vtx_start[2].pos = IM_POLYLINE_PRIM_VTX_WRITE[2].pos;
2091-
vtx_start[3].pos = IM_POLYLINE_PRIM_VTX_WRITE[3].pos;
2081+
vtx_start[0].pos = vtx_write[0].pos;
2082+
vtx_start[1].pos = vtx_write[1].pos;
2083+
vtx_start[2].pos = vtx_write[2].pos;
2084+
vtx_start[3].pos = vtx_write[3].pos;
20922085
}
20932086
else IM_UNLIKELY
20942087
{
@@ -2142,8 +2135,8 @@ void ImDrawList::_PolylineAliased(const ImDrawListPolyline& polyline)
21422135
const float d_x = n0.x * half_thickness * scale; \
21432136
const float d_y = n0.y * half_thickness * scale; \
21442137
\
2145-
IM_POLYLINE_PRIM_VTX_WRITE[0].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[0].pos.y += d_x; \
2146-
IM_POLYLINE_PRIM_VTX_WRITE[1].pos.x -= d_y; IM_POLYLINE_PRIM_VTX_WRITE[1].pos.y += d_x; \
2138+
vtx_write[0].pos.x -= d_y; vtx_write[0].pos.y += d_x; \
2139+
vtx_write[1].pos.x -= d_y; vtx_write[1].pos.y += d_x; \
21472140
} \
21482141
else if (polyline.cap == ImDrawFlags_CapRound) IM_UNLIKELY \
21492142
{ \
@@ -2555,8 +2548,8 @@ void ImDrawList::_PolylineAliased(const ImDrawListPolyline& polyline)
25552548
{
25562549
ImDrawVert* vtx_start = this->VtxBuffer.Data + vtx_start_idx;
25572550

2558-
vtx_start[0].pos = IM_POLYLINE_PRIM_VTX_WRITE[0].pos;
2559-
vtx_start[1].pos = IM_POLYLINE_PRIM_VTX_WRITE[1].pos;
2551+
vtx_start[0].pos = vtx_write[0].pos;
2552+
vtx_start[1].pos = vtx_write[1].pos;
25602553
}
25612554
else IM_UNLIKELY
25622555
{
@@ -3656,7 +3649,7 @@ void ImDrawList::_RectRounded(const ImVec2& a, const ImVec2& b, ImU32 col, floa
36563649
uv, path_colors[j]); \
36573650
} \
36583651
\
3659-
IM_POLYLINE_PRIM_VTX_WRITE += path_count; \
3652+
vtx_write += path_count; \
36603653
} \
36613654
\
36623655
path_size += arc_size; \
@@ -3668,7 +3661,7 @@ void ImDrawList::_RectRounded(const ImVec2& a, const ImVec2& b, ImU32 col, floa
36683661
IM_POLYLINE_VERTEX(j, X X_SIGN path_offsets[j].x, Y Y_SIGN path_offsets[j].y, uv, path_colors[j]); \
36693662
} \
36703663
\
3671-
IM_POLYLINE_PRIM_VTX_WRITE += path_count; \
3664+
vtx_write += path_count; \
36723665
++path_size; \
36733666
}
36743667

@@ -3691,13 +3684,11 @@ void ImDrawList::_RectRounded(const ImVec2& a, const ImVec2& b, ImU32 col, floa
36913684
}
36923685
IM_POLYLINE_TRIANGLE_END(path_size * strip_count * 2 * 3);
36933686

3694-
IM_POLYLINE_PRIM_IDX_BASE += vtx_count;
3687+
idx_base += vtx_count;
36953688

36963689
for (int j = 0; j < (path_count - 1) * 6; j++)
3697-
{
3698-
if (IM_POLYLINE_PRIM_IDX_WRITE[-j - 1] >= IM_POLYLINE_PRIM_IDX_BASE)
3699-
IM_POLYLINE_PRIM_IDX_WRITE[-j - 1] -= (ImDrawIdx)vtx_count;
3700-
}
3690+
if (idx_write[-j - 1] >= idx_base)
3691+
idx_write[-j - 1] -= (ImDrawIdx)vtx_count;
37013692

37023693
IM_POLYLINE_PRIM_COMMIT();
37033694
}

0 commit comments

Comments
 (0)