Texture-based round corners: Added sampling offset and bitmask for generated radii

This commit is contained in:
Ben Carter 2020-06-10 11:06:30 +09:00 committed by ocornut
parent 75f5aaaa1c
commit b175371325
2 changed files with 8 additions and 5 deletions

View File

@ -3372,7 +3372,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)
{
@ -3483,8 +3483,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 X<Y region of the texture contains the data for filled corners, the X>Y region
// the data for stroked ones. We add half of FONT_ATLAS_ROUNDED_CORNER_TEX_CENTER_PADDING so that

View File

@ -2899,13 +2899,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)