From ca027e1754e9d4c1c836b0c89b876f52cb8f8520 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 13:20:57 +0100 Subject: [PATCH] Skip rendering if alpha is 0.0 --- imgui.cpp | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 30a9068b..b8434f88 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1401,34 +1401,39 @@ void Render() memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); } - // Render tooltip - if (g.Tooltip[0]) + // Skip render altogether if alpha is 0.0 + // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place. + if (g.Style.Alpha > 0.0f) { - // Use a dummy window to render the tooltip - ImGui::BeginTooltip(); - ImGui::TextUnformatted(g.Tooltip); - ImGui::EndTooltip(); - } + // Render tooltip + if (g.Tooltip[0]) + { + // Use a dummy window to render the tooltip + ImGui::BeginTooltip(); + ImGui::TextUnformatted(g.Tooltip); + ImGui::EndTooltip(); + } - // Gather windows to render - g.RenderDrawLists.resize(0); - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) - window->AddToRenderList(); - } - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) - window->AddToRenderList(); - } + // Gather windows to render + g.RenderDrawLists.resize(0); + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) + window->AddToRenderList(); + } + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) + window->AddToRenderList(); + } - // Render - if (!g.RenderDrawLists.empty()) - g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); - g.RenderDrawLists.resize(0); + // Render + if (!g.RenderDrawLists.empty()) + g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); + g.RenderDrawLists.resize(0); + } } // Find the optional ## from which we stop displaying text.