Fonts: Debug display status. Fixed truncated raw texture id. Fixed FormatTextureIDForDebugDisplay(). Comments.

This commit is contained in:
ocornut
2025-05-09 21:55:07 +02:00
parent f6735c223c
commit 46fa9e8efb
3 changed files with 34 additions and 10 deletions

View File

@@ -15666,7 +15666,7 @@ static const char* FormatTextureIDForDebugDisplay(char* buf, int buf_size, const
char* buf_end = buf + buf_size;
if (cmd->TexRef._TexData != NULL)
buf += ImFormatString(buf, buf_end - buf, "#%03d: ", cmd->TexRef._TexData->UniqueID);
return FormatTextureIDForDebugDisplay(buf, (int)(buf_end - buf), cmd->GetTexID());
return FormatTextureIDForDebugDisplay(buf, (int)(buf_end - buf), cmd->TexRef.GetTexID()); // Calling TexRef::GetTexID() to avoid assert of cmd->GetTexID()
}
// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds.
@@ -15690,18 +15690,26 @@ namespace ImGuiFreeType { IMGUI_API const ImFontLoader* GetFontLoader(); IMGUI_A
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
{
ImGuiContext& g = *GImGui;
ImGuiIO& io = g.IO;
Text("Read "); SameLine(0, 0);
TextLinkOpenURL("https://www.dearimgui.com/faq/"); SameLine(0, 0);
Text(" for details on font loading.");
SeparatorText("Backend Support for Dynamic Fonts");
BeginDisabled();
CheckboxFlags("io.BackendFlags: RendererHasTextures", &GetIO().BackendFlags, ImGuiBackendFlags_RendererHasTextures);
CheckboxFlags("io.BackendFlags: RendererHasTextures", &io.BackendFlags, ImGuiBackendFlags_RendererHasTextures);
EndDisabled();
BeginDisabled((io.BackendFlags & ImGuiBackendFlags_RendererHasTextures) == 0);
SetNextItemWidth(GetFontSize() * 5);
DragFloat("io.FontGlobalScale", &io.FontGlobalScale, 0.05f, 0.5f, 5.0f);
BulletText("This is scaling font only. General scaling will come later.");
BulletText("Load an actual font that's not the default for best result!");
BulletText("Please submit feedback:"); SameLine(); TextLinkOpenURL("https://github.com/ocornut/imgui/issues/8465");
EndDisabled();
SeparatorText("Fonts");
Text("Read ");
SameLine(0, 0);
TextLinkOpenURL("https://www.dearimgui.com/faq/");
SameLine(0, 0);
Text(" for details on font loading.");
ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
Checkbox("Show font preview", &cfg->ShowFontPreview);
@@ -15845,7 +15853,8 @@ void ImGui::DebugNodeTexture(ImTextureData* tex, int int_id, const ImFontAtlasRe
}
PopStyleVar();
char texid_desc[20];
char texid_desc[30];
Text("Status = %s (%d)", ImTextureDataGetStatusName(tex->Status), tex->Status);
Text("Format = %s (%d)", ImTextureDataGetFormatName(tex->Format), tex->Format);
Text("TexID = %s", FormatTextureIDForDebugDisplay(texid_desc, IM_ARRAYSIZE(texid_desc), tex->TexID));
Text("BackendUserData = %p", tex->BackendUserData);
@@ -16545,7 +16554,7 @@ void ImGui::DebugNodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, con
continue;
}
char texid_desc[20];
char texid_desc[30];
FormatTextureIDForDebugDisplay(texid_desc, IM_ARRAYSIZE(texid_desc), pcmd);
char buf[300];
ImFormatString(buf, IM_ARRAYSIZE(buf), "DrawCmd:%5d tris, Tex %s, ClipRect (%4.0f,%4.0f)-(%4.0f,%4.0f)",

View File

@@ -2431,6 +2431,19 @@ int ImTextureDataGetFormatBytesPerPixel(ImTextureFormat format)
return 0;
}
const char* ImTextureDataGetStatusName(ImTextureStatus status)
{
switch (status)
{
case ImTextureStatus_OK: return "OK";
case ImTextureStatus_Destroyed: return "Destroyed";
case ImTextureStatus_WantCreate: return "WantCreate";
case ImTextureStatus_WantUpdates: return "WantUpdates";
case ImTextureStatus_WantDestroy: return "WantDestroy";
}
return "N/A";
}
const char* ImTextureDataGetFormatName(ImTextureFormat format)
{
switch (format)
@@ -2441,7 +2454,6 @@ const char* ImTextureDataGetFormatName(ImTextureFormat format)
return "N/A";
}
void ImTextureData::Create(ImTextureFormat format, int w, int h)
{
DestroyPixels();
@@ -3156,6 +3168,7 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed
return font;
}
// On font removal we need to remove references (otherwise we could queue removal?)
// We allow old_font == new_font which forces updating all values (e.g. sizes)
static void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont* new_font)
{
@@ -3884,6 +3897,7 @@ void ImFontAtlasUpdateDrawListsTextures(ImFontAtlas* atlas, ImTextureRef old_tex
}
// Update texture coordinates in all draw list shared context
// FIXME-NEWATLAS FIXME-OPT: Doesn't seem necessary to update for all, only one bound to current context?
void ImFontAtlasUpdateDrawListsSharedData(ImFontAtlas* atlas)
{
for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas)

View File

@@ -3823,6 +3823,7 @@ IMGUI_API void ImFontAtlasTextureBlockCopy(ImTextureData* src_tex,
IMGUI_API void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex, int x, int y, int w, int h);
IMGUI_API int ImTextureDataGetFormatBytesPerPixel(ImTextureFormat format);
IMGUI_API const char* ImTextureDataGetStatusName(ImTextureStatus status);
IMGUI_API const char* ImTextureDataGetFormatName(ImTextureFormat format);
#ifndef IMGUI_DISABLE_DEBUG_TOOLS