From e29bfc2c86149e41e438b16ae1e19e9add04f0a7 Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Mon, 5 Apr 2021 10:42:57 -0700 Subject: [PATCH] ImGuiHelper can construct with a context (#3753) * ImGuiHelper supports client-provided context this lets impress load >1 embedded font into the font table * ImGuiHelper supports client-provided context this lets impress load >1 embedded font into the font table Co-authored-by: Philip Rideout --- libs/filagui/include/filagui/ImGuiHelper.h | 3 ++- libs/filagui/src/ImGuiHelper.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/filagui/include/filagui/ImGuiHelper.h b/libs/filagui/include/filagui/ImGuiHelper.h index e6ffe2386e..8313974c7e 100644 --- a/libs/filagui/include/filagui/ImGuiHelper.h +++ b/libs/filagui/include/filagui/ImGuiHelper.h @@ -47,7 +47,8 @@ public: using Callback = std::function; // The constructor creates its own Scene and places it in the given View. - ImGuiHelper(filament::Engine* engine, filament::View* view, const utils::Path& fontPath); + ImGuiHelper(filament::Engine* engine, filament::View* view, const utils::Path& fontPath, + ImGuiContext* imGuiContext = nullptr); ~ImGuiHelper(); // Informs ImGui of the current display size, as well as a scaling factor when scissoring. diff --git a/libs/filagui/src/ImGuiHelper.cpp b/libs/filagui/src/ImGuiHelper.cpp index 74f750559c..91b2a4e156 100644 --- a/libs/filagui/src/ImGuiHelper.cpp +++ b/libs/filagui/src/ImGuiHelper.cpp @@ -45,9 +45,10 @@ namespace filagui { #include "generated/resources/filagui_resources.h" -ImGuiHelper::ImGuiHelper(Engine* engine, filament::View* view, const Path& fontPath) : - mEngine(engine), mView(view), mScene(engine->createScene()), - mImGuiContext(ImGui::CreateContext()) { +ImGuiHelper::ImGuiHelper(Engine* engine, filament::View* view, const Path& fontPath, + ImGuiContext *imGuiContext) + : mEngine(engine), mView(view), mScene(engine->createScene()), + mImGuiContext(imGuiContext ? imGuiContext : ImGui::CreateContext()) { ImGuiIO& io = ImGui::GetIO(); // Create a simple alpha-blended 2D blitting material. @@ -63,7 +64,7 @@ ImGuiHelper::ImGuiHelper(Engine* engine, filament::View* view, const Path& fontP createAtlasTexture(engine); // For proggy, switch to NEAREST for pixel-perfect text. - if (fontPath.isEmpty()) { + if (fontPath.isEmpty() && !imGuiContext) { TextureSampler sampler(MinFilter::NEAREST, MagFilter::NEAREST); mMaterial->setDefaultParameter("albedo", mTexture, sampler); }