MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / ImFontAtlasUpdateNewFrame

Function ImFontAtlasUpdateNewFrame

3rdparty/imgui/src/imgui_draw.cpp:2773–2872  ·  view source on GitHub ↗

Called by NewFrame() for atlases owned by a context. If you manually manage font atlases, you'll need to call this yourself. - 'frame_count' needs to be provided because we can gc/prioritize baked fonts based on their age. - 'frame_count' may not match those of all imgui contexts using this atlas, as contexts may be updated as different frequencies. But generally you can use ImGui::GetFrameCount()

Source from the content-addressed store, hash-verified

2771// - 'frame_count' needs to be provided because we can gc/prioritize baked fonts based on their age.
2772// - 'frame_count' may not match those of all imgui contexts using this atlas, as contexts may be updated as different frequencies. But generally you can use ImGui::GetFrameCount() on one of your context.
2773void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool renderer_has_textures)
2774{
2775 IM_ASSERT(atlas->Builder == NULL || atlas->Builder->FrameCount < frame_count); // Protection against being called twice.
2776 atlas->RendererHasTextures = renderer_has_textures;
2777
2778 // Check that font atlas was built or backend support texture reload in which case we can build now
2779 if (atlas->RendererHasTextures)
2780 {
2781 atlas->TexIsBuilt = true;
2782 if (atlas->Builder == NULL) // This will only happen if fonts were not already loaded.
2783 ImFontAtlasBuildMain(atlas);
2784 }
2785 // Legacy backend
2786 if (!atlas->RendererHasTextures)
2787 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().");
2788 if (atlas->TexIsBuilt && atlas->Builder->PreloadedAllGlyphsRanges)
2789 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().");
2790
2791 // Clear BakedCurrent cache, this is important because it ensure the uncached path gets taken once.
2792 // We also rely on ImFontBaked* pointers never crossing frames.
2793 ImFontAtlasBuilder* builder = atlas->Builder;
2794 builder->FrameCount = frame_count;
2795 for (ImFont* font : atlas->Fonts)
2796 font->LastBaked = NULL;
2797
2798 // Garbage collect BakedPool
2799 if (builder->BakedDiscardedCount > 0)
2800 {
2801 int dst_n = 0, src_n = 0;
2802 for (; src_n < builder->BakedPool.Size; src_n++)
2803 {
2804 ImFontBaked* p_src = &builder->BakedPool[src_n];
2805 if (p_src->WantDestroy)
2806 continue;
2807 ImFontBaked* p_dst = &builder->BakedPool[dst_n++];
2808 if (p_dst == p_src)
2809 continue;
2810 memcpy(p_dst, p_src, sizeof(ImFontBaked));
2811 builder->BakedMap.SetVoidPtr(p_dst->BakedId, p_dst);
2812 }
2813 IM_ASSERT(dst_n + builder->BakedDiscardedCount == src_n);
2814 builder->BakedPool.Size -= builder->BakedDiscardedCount;
2815 builder->BakedDiscardedCount = 0;
2816 }
2817
2818 // Update texture status
2819 for (int tex_n = 0; tex_n < atlas->TexList.Size; tex_n++)
2820 {
2821 ImTextureData* tex = atlas->TexList[tex_n];
2822 bool remove_from_list = false;
2823 if (tex->Status == ImTextureStatus_OK)
2824 {
2825 tex->Updates.resize(0);
2826 tex->UpdateRect.x = tex->UpdateRect.y = (unsigned short)~0;
2827 tex->UpdateRect.w = tex->UpdateRect.h = 0;
2828 }
2829 if (tex->Status == ImTextureStatus_WantCreate && atlas->RendererHasTextures)
2830 IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL && "Backend set texture's TexID/BackendUserData but did not update Status to OK.");

Callers 1

Calls 7

ImFontAtlasBuildMainFunction · 0.85
IM_DELETEFunction · 0.85
SetVoidPtrMethod · 0.80
DestroyPixelsMethod · 0.80
resizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected