diff --git a/Common/UI/Context.cpp b/Common/UI/Context.cpp index 5a14fc33c0..2d9db8c277 100644 --- a/Common/UI/Context.cpp +++ b/Common/UI/Context.cpp @@ -15,10 +15,6 @@ #include "Common/LogReporting.h" #include "Common/Render/AtlasGen.h" -// The generated atlas.. This is temporary. -std::vector genAtlasImages; -Atlas genAtlas; - UIContext::UIContext() { fontStyle_ = new UI::FontStyle(); bounds_ = Bounds(0, 0, g_display.dp_xres, g_display.dp_yres); @@ -46,15 +42,21 @@ void UIContext::Init(Draw::DrawContext *thin3d, Draw::Pipeline *uipipe, Draw::Pi void UIContext::BeginFrame() { frameStartTime_ = time_now_d(); - if (!uitexture_) { + if (atlasInvalid_ || !uitexture_) { + if (uitexture_) { + uitexture_->Release(); + } AtlasData data = atlasProvider_(draw_, AtlasChoice::General); uitexture_ = data.texture; + _dbg_assert_(uitexture_); ui_draw2d.SetAtlas(data.atlas); + atlasInvalid_ = false; } if (!fontTexture_) { AtlasData data = atlasProvider_(draw_, AtlasChoice::Font); fontTexture_ = data.texture; + _dbg_assert_(fontTexture_); ui_draw2d.SetFontAtlas(data.atlas); } diff --git a/Common/UI/Context.h b/Common/UI/Context.h index e5c4c9433c..8f1291c9e4 100644 --- a/Common/UI/Context.h +++ b/Common/UI/Context.h @@ -126,7 +126,9 @@ public: void SetTheme(const UI::Theme *theme) { this->theme = theme; } void SetAtlasProvider(UIAtlasProviderFunc func) { atlasProvider_ = func; } - + void InvalidateAtlas() { + atlasInvalid_ = true; // will cause it to be reloaded on the next frame. + } private: void GenerateUIAtlas(); @@ -154,4 +156,5 @@ private: std::vector transformStack_; UIAtlasProviderFunc atlasProvider_{}; + bool atlasInvalid_ = true; }; diff --git a/UI/DeveloperToolsScreen.cpp b/UI/DeveloperToolsScreen.cpp index 32677079fa..685dc74dc7 100644 --- a/UI/DeveloperToolsScreen.cpp +++ b/UI/DeveloperToolsScreen.cpp @@ -334,6 +334,15 @@ void DeveloperToolsScreen::CreateAudioTab(UI::LinearLayout *list) { list->Add(new CheckBox(&g_Config.bForceFfmpegForAudioDec, dev->T("Use FFMPEG for all compressed audio"))); } +void DeveloperToolsScreen::CreateUITab(UI::LinearLayout *list) { + using namespace UI; + auto dev = GetI18NCategory(I18NCat::DEVELOPER); + UIContext *uiContext = screenManager()->getUIContext(); + list->Add(new Choice(dev->T("Reload UI atlas")))->OnClick.Add([uiContext](UI::EventParams &) { + uiContext->InvalidateAtlas(); + }); +} + void DeveloperToolsScreen::CreateNetworkTab(UI::LinearLayout *list) { using namespace UI; auto dev = GetI18NCategory(I18NCat::DEVELOPER); @@ -477,6 +486,9 @@ void DeveloperToolsScreen::CreateTabs() { AddTab("Tests", dev->T("Tests"), [this](UI::LinearLayout *parent) { CreateTestsTab(parent); }); + AddTab("UI", dev->T("UI"), [this](UI::LinearLayout *parent) { + CreateUITab(parent); + }); AddTab("DumpFiles", dev->T("Dump files"), [this](UI::LinearLayout *parent) { CreateDumpFileTab(parent); }); diff --git a/UI/DeveloperToolsScreen.h b/UI/DeveloperToolsScreen.h index 2a74d437b8..5f07c2748e 100644 --- a/UI/DeveloperToolsScreen.h +++ b/UI/DeveloperToolsScreen.h @@ -24,6 +24,7 @@ private: void CreateAudioTab(UI::LinearLayout *list); void CreateGraphicsTab(UI::LinearLayout *list); void CreateNetworkTab(UI::LinearLayout *list); + void CreateUITab(UI::LinearLayout *list); void OnLoggingChanged(UI::EventParams &e); void OnOpenTexturesIniFile(UI::EventParams &e);