From 94a432275b8ce29fa1dfb36439cfaf325e12a1ab Mon Sep 17 00:00:00 2001 From: thedmd Date: Sat, 26 May 2018 13:10:04 +0200 Subject: [PATCH] ImDrawList: Internals: Add ability to scale anti-alias fringe. This enable users to keep geometry sharp while scaling vertex buffer content. --- imgui.h | 1 + imgui_draw.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/imgui.h b/imgui.h index c4459a0e..6fc77321 100644 --- a/imgui.h +++ b/imgui.h @@ -2333,6 +2333,7 @@ struct ImDrawList ImVector _Path; // [Internal] current path building ImDrawCmdHeader _CmdHeader; // [Internal] template of active commands. Fields should match those of CmdBuffer.back(). ImDrawListSplitter _Splitter; // [Internal] for channels api (note: prefer using your own persistent instance of ImDrawListSplitter!) + float _FringeScale; // [Internal] anti-alias fringe is scaled by this value, this helps to keep things sharp while zooming at vertex buffer content // If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui) ImDrawList(const ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 947825a9..1e6a27f7 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -405,6 +405,7 @@ void ImDrawList::_ResetForNewFrame() _Path.resize(0); _Splitter.Clear(); CmdBuffer.push_back(ImDrawCmd()); + _FringeScale = 1.0f; } void ImDrawList::_ClearFreeMemory() @@ -680,12 +681,12 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 const ImVec2 opaque_uv = _Data->TexUvWhitePixel; const int count = closed ? points_count : points_count - 1; // The number of line segments we need to draw - const bool thick_line = (thickness > 1.0f); + const bool thick_line = (thickness > _FringeScale); if (Flags & ImDrawListFlags_AntiAliasedLines) { // Anti-aliased stroke - const float AA_SIZE = 1.0f; + const float AA_SIZE = _FringeScale; const ImU32 col_trans = col & ~IM_COL32_A_MASK; // Thicknesses <1.0 should behave like thickness 1.0 @@ -696,7 +697,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 // Do we want to draw this line using a texture? // - For now, only draw integer-width lines using textures to avoid issues with the way scaling occurs, could be improved. // - If AA_SIZE is not 1.0f we cannot use the texture path. - const bool use_texture = (Flags & ImDrawListFlags_AntiAliasedLinesUseTex) && (integer_thickness < IM_DRAWLIST_TEX_LINES_WIDTH_MAX) && (fractional_thickness <= 0.00001f); + const bool use_texture = (Flags & ImDrawListFlags_AntiAliasedLinesUseTex) && (integer_thickness < IM_DRAWLIST_TEX_LINES_WIDTH_MAX) && (fractional_thickness <= 0.00001f) && (AA_SIZE == 1.0f); // We should never hit this, because NewFrame() doesn't set ImDrawListFlags_AntiAliasedLinesUseTex unless ImFontAtlasFlags_NoBakedLines is off IM_ASSERT_PARANOID(!use_texture || !(_Data->Font->ContainerAtlas->Flags & ImFontAtlasFlags_NoBakedLines)); @@ -938,7 +939,7 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun if (Flags & ImDrawListFlags_AntiAliasedFill) { // Anti-aliased Fill - const float AA_SIZE = 1.0f; + const float AA_SIZE = _FringeScale; const ImU32 col_trans = col & ~IM_COL32_A_MASK; const int idx_count = (points_count - 2)*3 + points_count * 6; const int vtx_count = (points_count * 2);