From 248a2ff287b762c8a59b1e3ca446646cddb15544 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Wed, 10 Jun 2020 11:06:30 +0900 Subject: [PATCH] Texture-based round corners: Added sampling offset and bitmask for generated radii --- imgui_draw.cpp | 7 ++++--- imgui_internal.h | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a4735189b..37575d777 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3835,7 +3835,7 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas) const int height = radius_index + 1 + FONT_ATLAS_ROUNDED_CORNER_TEX_CENTER_PADDING + pad * 2; ImFontRoundedCornerData corner_data; - if (ImFontAtlasRoundCornersStrokeWidthMask & (1 << stroke_width_index)) + if ((ImFontAtlasRoundCornersStrokeWidthMask & (1 << stroke_width_index)) && (ImFontAtlasRoundCornersSizeMask & (1ULL << radius_index))) { if (stroke_width_index == 0 || spare_rect_id < 0) { @@ -3946,8 +3946,9 @@ static void ImFontAtlasBuildRenderRoundCornersTexData(ImFontAtlas* atlas) { // We want the pad area to essentially contain a clamped version of the 0th row/column, so // clamp here. Not doing this results in nasty filtering artifacts at low radii. - int cx = ImMax(x, 0); - int cy = ImMax(y, 0); + const float sampling_offset = 0.25f; // Experimentally obtained offset to compensate for sampling point + float cx = ImMax(x + sampling_offset, 0.0f); + float cy = ImMax(y + sampling_offset, 0.0f); // The XY region // the data for stroked ones. We add half of FONT_ATLAS_ROUNDED_CORNER_TEX_CENTER_PADDING so that diff --git a/imgui_internal.h b/imgui_internal.h index 469806b97..dfeb89eb3 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3490,13 +3490,15 @@ IMGUI_API void ImFontAtlasBuildRender32bppRectFromString(ImFontAtlas* atlas IMGUI_API void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_multiply_factor); IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride); -// Note that stroke width increases effective radius, so (e.g.) a max radius circle will have to use the fallback path if stroke width is > 1 +// Note that stroke width increases effective radius, so (e.g.) a max radius circle will have to use the fallback path if stroke width is > 1. Note that ImFontAtlasRoundCornersSizeMask is 64 bits so this value can only go up to a maximum of 64 at present. const int ImFontAtlasRoundCornersMaxSize = 32; // Maximum size of rounded corner texture to generate in fonts +// Bit mask for which radii will have texture generated for them, starting from radius 1. Only bits up to ImFontAtlasRoundCornersMaxSize are considered. +const ImU64 ImFontAtlasRoundCornersSizeMask = (1ULL << ImFontAtlasRoundCornersMaxSize) - 1; const int ImFontAtlasRoundCornersMaxStrokeWidth = 4; // Maximum stroke width of rounded corner texture to generate in fonts // Bit mask for which stroke widths should have textures generated for them (the default of 0x0B means widths 1, 2 and 4) // Only bits up to ImFontAtlasRoundCornersMaxStrokeWidth are considered, and bit 0 (stroke width 1) must always be set // Optimally there should be an odd number of bits set, as the texture packing packs the data in pairs, with one half of one pair being occupied by the filled texture -const int ImFontAtlasRoundCornersStrokeWidthMask = 0x0B; +const ImU32 ImFontAtlasRoundCornersStrokeWidthMask = 0x0B; //----------------------------------------------------------------------------- // [SECTION] Test Engine specific hooks (imgui_test_engine)