1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-30 18:34:34 +01:00

Shadows: Fix to support for colored-only font atlas. (4202)

This commit is contained in:
ocornut 2021-06-07 11:46:51 +02:00 committed by ocornut
parent e1f7a81150
commit a2ee47852b

View File

@ -4063,7 +4063,7 @@ static void GaussianBlur(float* data, int size)
// Generate the actual pixel data for rounded corners in the atlas
static void ImFontAtlasBuildRenderShadowTexData(ImFontAtlas* atlas)
{
IM_ASSERT(atlas->TexPixelsAlpha8 != NULL);
IM_ASSERT(atlas->TexPixelsAlpha8 != NULL || atlas->TexPixelsRGBA32 != NULL);
IM_ASSERT(atlas->ShadowRectIds[0] >= 0 && atlas->ShadowRectIds[1] >= 0);
// Because of the blur, we have to generate the full 3x3 texture here, and then we chop that down to just the 2x2 section we need later.
@ -4110,9 +4110,13 @@ static void ImFontAtlasBuildRenderShadowTexData(ImFontAtlas* atlas)
for (int y = 0; y < shadow_tex_size; y++)
for (int x = 0; x < shadow_tex_size; x++)
{
const float alpha = tex_data[x + (y * size)];
const unsigned int offset = (int)(r.X + x) + (int)(r.Y + y) * tex_w;
atlas->TexPixelsAlpha8[offset] = (unsigned char)(0xFF * alpha);
const float alpha_f = tex_data[x + (y * size)];
const unsigned char alpha_8 = (unsigned char)(0xFF * alpha_f);
if (atlas->TexPixelsAlpha8)
atlas->TexPixelsAlpha8[offset] = alpha_8;
else
atlas->TexPixelsRGBA32[offset] = IM_COL32(255, 255, 255, alpha_8);
}
// Generate UVs for each of the nine sections, which are arranged in a 3x3 grid starting from 0 in the top-left and going across then down
@ -4180,9 +4184,13 @@ static void ImFontAtlasBuildRenderShadowTexData(ImFontAtlas* atlas)
{
const int src_x = ImClamp(x - src_x_offset, 0, size - 1);
const int src_y = ImClamp(y - src_y_offset, 0, size - 1);
const float alpha = tex_data[src_x + (src_y * size)];
const float alpha_f = tex_data[src_x + (src_y * size)];
const unsigned char alpha_8 = (unsigned char)(0xFF * alpha_f);
const unsigned int offset = (int)(r.X + x) + (int)(r.Y + y) * tex_w;
atlas->TexPixelsAlpha8[offset] = (unsigned char)(0xFF * alpha);
if (atlas->TexPixelsAlpha8)
atlas->TexPixelsAlpha8[offset] = alpha_8;
else
atlas->TexPixelsRGBA32[offset] = IM_COL32(255, 255, 255, alpha_8);
}
// Remove the padding we added