diff --git a/imgui.cpp b/imgui.cpp index cb546e4ba..466ab28c7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -15420,7 +15420,8 @@ static void Platform_SetImeDataFn_DefaultImpl(ImGuiContext*, ImGuiViewport*, ImG // - RenderViewportsThumbnails() [Internal] // - DebugTextEncoding() // - MetricsHelpMarker() [Internal] -// - ShowFontAtlas() [Internal] +// - ShowFontAtlas() [Internal but called by Demo!] +// - DebugNodeTexture() [Internal] // - ShowMetricsWindow() // - DebugNodeColumns() [Internal] // - DebugNodeDrawList() [Internal] @@ -15722,18 +15723,20 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas) Text("incl. Discarded rects: %d, area: about %d px ~%dx%d px", atlas->Builder->RectsDiscardedCount, atlas->Builder->RectsDiscardedSurface, discarded_surface_sqrt, discarded_surface_sqrt); // Texture list - for (ImTextureData* tex : atlas->TexList) + // (ensure the last texture always use the same ID, so we can keep it open neatly) + for (int tex_n = 0; tex_n < atlas->TexList.Size; tex_n++) { - PushID(tex); - DebugNodeTexture(tex); - PopID(); + if (tex_n == atlas->TexList.Size - 1) + SetNextItemOpen(true, ImGuiCond_Once); + DebugNodeTexture(atlas->TexList[tex_n], atlas->TexList.Size - 1 - tex_n); } } -void ImGui::DebugNodeTexture(ImTextureData* tex) +void ImGui::DebugNodeTexture(ImTextureData* tex, int int_id) { ImGuiContext& g = *GImGui; - if (TreeNode(tex, "Texture #%03d (%dx%d pixels)", tex->UniqueID, tex->Width, tex->Height)) + PushID(int_id); + if (TreeNode("", "Texture #%03d (%dx%d pixels)", tex->UniqueID, tex->Width, tex->Height)) { ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig; Checkbox("Show used rect", &cfg->ShowTextureUsedRect); @@ -15748,12 +15751,13 @@ void ImGui::DebugNodeTexture(ImTextureData* tex) PopStyleVar(); char texid_desc[20]; - Text("Format = %d", tex->Format); + 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); Text("UseColors = %d", tex->UseColors); TreePop(); } + PopID(); } void ImGui::ShowMetricsWindow(bool* p_open) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index f154e5628..04a00c422 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2420,7 +2420,7 @@ ImFontConfig::ImFontConfig() // - ImTextureData::DestroyPixels() //----------------------------------------------------------------------------- -static int GetTextureFormatBytesPerPixel(ImTextureFormat format) +int ImTextureDataGetFormatBytesPerPixel(ImTextureFormat format) { switch (format) { @@ -2431,13 +2431,24 @@ static int GetTextureFormatBytesPerPixel(ImTextureFormat format) return 0; } +const char* ImTextureDataGetFormatName(ImTextureFormat format) +{ + switch (format) + { + case ImTextureFormat_Alpha8: return "Alpha8"; + case ImTextureFormat_RGBA32: return "RGBA32"; + } + return "N/A"; +} + + void ImTextureData::Create(ImTextureFormat format, int w, int h) { DestroyPixels(); Format = format; Width = w; Height = h; - BytesPerPixel = GetTextureFormatBytesPerPixel(format); + BytesPerPixel = ImTextureDataGetFormatBytesPerPixel(format); UseColors = false; Pixels = (unsigned char*)IM_ALLOC(Width * Height * BytesPerPixel); IM_ASSERT(Pixels != NULL); @@ -2798,7 +2809,7 @@ void ImFontAtlasTextureBlockConvert(const unsigned char* src_pixels, ImTextureFo IM_ASSERT(src_pixels != NULL && dst_pixels != NULL); if (src_fmt == dst_fmt) { - int line_sz = w * GetTextureFormatBytesPerPixel(src_fmt); + int line_sz = w * ImTextureDataGetFormatBytesPerPixel(src_fmt); for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch) memcpy(dst_pixels, src_pixels, line_sz); } diff --git a/imgui_internal.h b/imgui_internal.h index 6252ee818..c1857aafb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3625,7 +3625,7 @@ namespace ImGui IMGUI_API void DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list, const ImDrawList* draw_list, const ImDrawCmd* draw_cmd, bool show_mesh, bool show_aabb); IMGUI_API void DebugNodeFont(ImFont* font); IMGUI_API void DebugNodeFontGlyph(ImFont* font, const ImFontGlyph* glyph); - IMGUI_API void DebugNodeTexture(ImTextureData* tex); + IMGUI_API void DebugNodeTexture(ImTextureData* tex, int int_id); // ID used to facilitate persisting the "current" texture. IMGUI_API void DebugNodeStorage(ImGuiStorage* storage, const char* label); IMGUI_API void DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label); IMGUI_API void DebugNodeTable(ImGuiTable* table); @@ -3809,6 +3809,9 @@ IMGUI_API void ImFontAtlasTextureBlockFill(ImTextureData* dst_tex, IMGUI_API void ImFontAtlasTextureBlockCopy(ImTextureData* src_tex, int src_x, int src_y, ImTextureData* dst_tex, int dst_x, int dst_y, int w, int h); 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* ImTextureDataGetFormatName(ImTextureFormat format); + #ifndef IMGUI_DISABLE_DEBUG_TOOLS IMGUI_API void ImFontAtlasDebugLogTextureRequests(ImFontAtlas* atlas); #endif