Skip to content

Commit abb1f8c

Browse files
committed
ImDrawList: Add LegacyPolyline flag for backward compatibility
1 parent 869263d commit abb1f8c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

imgui.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ ImGuiStyle::ImGuiStyle()
13091309
AntiAliasedLines = true; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU.
13101310
AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering).
13111311
AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.).
1312+
LegacyPolyline = false; // Enable fallback to legacy AddPolyline() to trade feature and precission for speed.
13121313
CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
13131314
CircleTessellationMaxError = 0.30f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry.
13141315

@@ -4774,6 +4775,8 @@ static void SetupDrawListSharedData()
47744775
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedLinesUseTex;
47754776
if (g.Style.AntiAliasedFill)
47764777
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedFill;
4778+
if (g.Style.LegacyPolyline)
4779+
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_LegacyPolyline;
47774780
if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset)
47784781
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset;
47794782
}

imgui.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,7 @@ struct ImGuiStyle
21792179
bool AntiAliasedLines; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList).
21802180
bool AntiAliasedLinesUseTex; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering). Latched at the beginning of the frame (copied to ImDrawList).
21812181
bool AntiAliasedFill; // Enable anti-aliased edges around filled shapes (rounded rectangles, circles, etc.). Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList).
2182+
bool LegacyPolyline; // Enable fallback to legacy AddPolyline() to trade feature and precission for speed.
21822183
float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
21832184
float CircleTessellationMaxError; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry.
21842185
ImVec4 Colors[ImGuiCol_COUNT];
@@ -3022,6 +3023,7 @@ enum ImDrawListFlags_
30223023
ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, // Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering (NOT point/nearest filtering).
30233024
ImDrawListFlags_AntiAliasedFill = 1 << 2, // Enable anti-aliased edge around filled shapes (rounded rectangles, circles).
30243025
ImDrawListFlags_AllowVtxOffset = 1 << 3, // Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled.
3026+
ImDrawListFlags_LegacyPolyline = 1 << 4, // (Legacy) For AddPolyline() to trade features and precission for a bit of extra performance.
30253027
};
30263028

30273029
// Draw command list
@@ -3116,7 +3118,7 @@ struct ImDrawList
31163118
inline void PathLineToMergeDuplicate(const ImVec2& pos) { if (_Path.Size == 0 || memcmp(&_Path.Data[_Path.Size - 1], &pos, 8) != 0) _Path.push_back(pos); }
31173119
inline void PathFillConvex(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col); _Path.Size = 0; }
31183120
inline void PathFillConcave(ImU32 col) { AddConcavePolyFilled(_Path.Data, _Path.Size, col); _Path.Size = 0; }
3119-
inline void PathStroke(ImU32 col, ImDrawFlags flags = 0, float thickness = 1.0f, float miter_limit = -1.0f) { AddPolyline(_Path.Data, _Path.Size, col, flags, thickness, miter_limit); _Path.Size = 0; }
3121+
inline void PathStroke(ImU32 col, ImDrawFlags flags = 0, float thickness = 1.0f, float miter_limit = -1.0f) { if (Flags & ImDrawListFlags_LegacyPolyline) AddPolylineLegacy(_Path.Data, _Path.Size, col, flags, thickness); else AddPolyline(_Path.Data, _Path.Size, col, flags, thickness, miter_limit); _Path.Size = 0; }
31203122
IMGUI_API void PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments = 0);
31213123
IMGUI_API void PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle
31223124
IMGUI_API void PathEllipticalArcTo(const ImVec2& center, const ImVec2& radius, float rot, float a_min, float a_max, int num_segments = 0); // Ellipse

imgui_demo.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -8021,6 +8021,11 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
80218021
HelpMarker("Faster lines using texture data. Require backend to render with bilinear filtering (not point/nearest filtering).");
80228022

80238023
ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill);
8024+
8025+
ImGui::Checkbox("Legacy polyline", &style.LegacyPolyline);
8026+
ImGui::SameLine();
8027+
HelpMarker("Legacy polyline is faster for drawing lots of geometry, but does lack of features and robustness.");
8028+
80248029
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
80258030
ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f");
80268031
if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f;

0 commit comments

Comments
 (0)