|
@@ -2485,6 +2485,7 @@ void ImTextureData::DestroyPixels()
|
|
|
// - ImFontAtlas::CalcCustomRectUV()
|
|
|
// - ImFontAtlasGetMouseCursorTexData()
|
|
|
//-----------------------------------------------------------------------------
|
|
|
+// - ImFontAtlasBuildMain()
|
|
|
// - ImFontAtlasBuildSetupFontLoader()
|
|
|
// - ImFontAtlasBuildPreloadAllGlyphRanges()
|
|
|
// - ImFontAtlasBuildUpdatePointers()
|
|
@@ -2685,15 +2686,24 @@ static void ImFontAtlasBuildUpdateRendererHasTexturesFromContext(ImFontAtlas* at
|
|
|
}
|
|
|
|
|
|
// Called by NewFrame(). When multiple context own the atlas, only the first one calls this.
|
|
|
+// If you are calling this yourself, ensure atlas->RendererHasTexUpdates is et.
|
|
|
void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas)
|
|
|
{
|
|
|
- if (atlas->TexIsBuilt && atlas->Builder->PreloadedAllGlyphsRanges)
|
|
|
+ // Check that font atlas was built or backend support texture reload in which case we can build now
|
|
|
+ if (atlas->RendererHasTextures)
|
|
|
+ {
|
|
|
+ atlas->TexIsBuilt = true;
|
|
|
+ if (atlas->Builder == NULL) // This will only happen if fonts were not already loaded.
|
|
|
+ ImFontAtlasBuildMain(atlas);
|
|
|
+ }
|
|
|
+ else // Legacy backend
|
|
|
{
|
|
|
- ImFontAtlasBuildUpdateRendererHasTexturesFromContext(atlas);
|
|
|
- IM_ASSERT_USER_ERROR(atlas->RendererHasTextures == false,
|
|
|
- "Called ImFontAtlas::Build() before ImGuiBackendFlags_RendererHasTextures got set! With new backends: you don't need to call Build().");
|
|
|
+ IM_ASSERT_USER_ERROR(atlas->TexIsBuilt, "Backend does not support ImGuiBackendFlags_RendererHasTextures, and font atlas is not built! Update backend OR make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8().");
|
|
|
}
|
|
|
+ if (atlas->TexIsBuilt && atlas->Builder->PreloadedAllGlyphsRanges)
|
|
|
+ IM_ASSERT_USER_ERROR(atlas->RendererHasTextures == false, "Called ImFontAtlas::Build() before ImGuiBackendFlags_RendererHasTextures got set! With new backends: you don't need to call Build().");
|
|
|
|
|
|
+ // Update texture status
|
|
|
for (int tex_n = 0; tex_n < atlas->TexList.Size; tex_n++)
|
|
|
{
|
|
|
ImTextureData* tex = atlas->TexList[tex_n];
|
|
@@ -2865,6 +2875,7 @@ void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex,
|
|
|
tex->UpdateRect.y = ImMin(tex->UpdateRect.y, req.y);
|
|
|
tex->UpdateRect.w = (unsigned short)(new_x1 - tex->UpdateRect.x);
|
|
|
tex->UpdateRect.h = (unsigned short)(new_y1 - tex->UpdateRect.y);
|
|
|
+ atlas->TexIsBuilt = false;
|
|
|
|
|
|
// No need to queue if status is _WantCreate
|
|
|
if (tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantUpdates)
|
|
@@ -3206,6 +3217,7 @@ bool ImFontAtlasGetMouseCursorTexData(ImFontAtlas* atlas, ImGuiMouseCursor curso
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// When atlas->RendererHasTexUpdates == true, this is only called if no font were loaded.
|
|
|
void ImFontAtlasBuildMain(ImFontAtlas* atlas)
|
|
|
{
|
|
|
IM_ASSERT(!atlas->Locked && "Cannot modify a locked ImFontAtlas!");
|
|
@@ -3589,6 +3601,7 @@ void ImFontAtlasBuildReloadFont(ImFontAtlas* atlas, ImFont* font)
|
|
|
atlas->FontLoader->FontSrcInit(atlas, src);
|
|
|
|
|
|
ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, src); // Technically this is called for each source sub-font, tho 99.9% of the time the first one fills everything.
|
|
|
+ atlas->TexIsBuilt = false;
|
|
|
}
|
|
|
|
|
|
// Notify external systems
|
|
@@ -3684,6 +3697,7 @@ ImTextureData* ImFontAtlasBuildAddTexture(ImFontAtlas* atlas, int w, int h)
|
|
|
|
|
|
new_tex->Create(atlas->TexDesiredFormat, w, h);
|
|
|
new_tex->Status = ImTextureStatus_WantCreate;
|
|
|
+ atlas->TexIsBuilt = false;
|
|
|
|
|
|
ImFontAtlasBuildSetTexture(atlas, new_tex);
|
|
|
|
|
@@ -4037,12 +4051,12 @@ ImFontAtlasRect* ImFontAtlasPackGetRect(ImFontAtlas* atlas, ImFontAtlasRectId id
|
|
|
|
|
|
ImFontGlyph* ImFont::BuildLoadGlyph(ImWchar codepoint)
|
|
|
{
|
|
|
- if (LockDisableLoading)
|
|
|
+ ImFontAtlas* atlas = ContainerAtlas;
|
|
|
+ if (LockDisableLoading || atlas->Locked)
|
|
|
return NULL;
|
|
|
|
|
|
//char utf8_buf[5];
|
|
|
//IMGUI_DEBUG_LOG("[font] BuildAddGlyph U+%04X (%s)\n", (unsigned int)codepoint, ImTextCharToUtf8(utf8_buf, (unsigned int)codepoint));
|
|
|
- ImFontAtlas* atlas = ContainerAtlas;
|
|
|
|
|
|
// Load from single source or all sources?
|
|
|
int srcs_count = (LockSingleSrcConfigIdx != -1) ? 1 : SourcesCount;
|