Use shared font atlas and fix crash when opening overlay in some games.

merge-requests/50/head
Mr_Goldberg 2022-08-21 03:45:11 -04:00
parent de6805dd8b
commit c9a102ee30
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
9 changed files with 25 additions and 20 deletions

View File

@ -39,7 +39,8 @@ class Renderer_Hook
public: public:
Renderer_Hook(): Renderer_Hook():
OverlayProc(&DefaultOverlayProc), OverlayProc(&DefaultOverlayProc),
OverlayHookReady(&DefaultOverlayHookReady) OverlayHookReady(&DefaultOverlayHookReady),
ImGuiFontAtlas(nullptr)
{} {}
static void DefaultOverlayProc() {} static void DefaultOverlayProc() {}
@ -47,6 +48,7 @@ public:
std::function<void()> OverlayProc; std::function<void()> OverlayProc;
std::function<void(bool)> OverlayHookReady; std::function<void(bool)> OverlayHookReady;
void *ImGuiFontAtlas;
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ToggleKey> toggle_keys) = 0; virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ToggleKey> toggle_keys) = 0;
virtual bool IsStarted() = 0; virtual bool IsStarted() = 0;
// Returns a Handle to the renderer image ressource or nullptr if it failed to create the resource, the handle can be used in ImGui's Image calls, image_buffer must be RGBA ordered // Returns a Handle to the renderer image ressource or nullptr if it failed to create the resource, the handle can be used in ImGui's Image calls, image_buffer must be RGBA ordered

View File

@ -84,7 +84,7 @@ void OpenGLX_Hook::_PrepareForOverlay(Display* display, GLXDrawable drawable)
{ {
if( !_Initialized ) if( !_Initialized )
{ {
ImGui::CreateContext(); ImGui::CreateContext((ImFontAtlas *)ImGuiFontAtlas);
ImGui_ImplOpenGL3_Init(); ImGui_ImplOpenGL3_Init();
//int attributes[] = { //can't be const b/c X11 doesn't like it. Not sure if that's intentional or just stupid. //int attributes[] = { //can't be const b/c X11 doesn't like it. Not sure if that's intentional or just stupid.

View File

@ -128,7 +128,8 @@ Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_resu
i_have_lobby(false), i_have_lobby(false),
show_achievements(false), show_achievements(false),
show_settings(false), show_settings(false),
_renderer(nullptr) _renderer(nullptr),
fonts_atlas(nullptr)
{ {
strncpy(username_text, settings->get_local_name(), sizeof(username_text)); strncpy(username_text, settings->get_local_name(), sizeof(username_text));
@ -709,11 +710,10 @@ void Steam_Overlay::BuildNotifications(int width, int height)
void Steam_Overlay::CreateFonts() void Steam_Overlay::CreateFonts()
{ {
//TODO: remove from dx_whatever hook if (fonts_atlas) return;
if(ImGui::GetCurrentContext() == nullptr)
ImGui::CreateContext(); ImFontAtlas *Fonts = new ImFontAtlas();
ImGuiIO& io = ImGui::GetIO();
ImFontConfig fontcfg; ImFontConfig fontcfg;
float font_size = 16.0; float font_size = 16.0;
@ -727,7 +727,7 @@ void Steam_Overlay::CreateFonts()
font_builder.AddText(x.description.c_str()); font_builder.AddText(x.description.c_str());
} }
font_builder.AddRanges(io.Fonts->GetGlyphRangesDefault()); font_builder.AddRanges(Fonts->GetGlyphRangesDefault());
ImVector<ImWchar> ranges; ImVector<ImWchar> ranges;
font_builder.BuildRanges(&ranges); font_builder.BuildRanges(&ranges);
@ -744,11 +744,11 @@ void Steam_Overlay::CreateFonts()
ImFont *font = NULL; ImFont *font = NULL;
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
font = io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\micross.ttf", font_size, &fontcfg); font = Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\micross.ttf", font_size, &fontcfg);
#endif #endif
if (!font) { if (!font) {
font = io.Fonts->AddFontDefault(&fontcfg); font = Fonts->AddFontDefault(&fontcfg);
} }
font_notif = font_default = font; font_notif = font_default = font;
@ -757,15 +757,16 @@ void Steam_Overlay::CreateFonts()
PRINT_DEBUG("loading extra fonts\n"); PRINT_DEBUG("loading extra fonts\n");
fontcfg.MergeMode = true; fontcfg.MergeMode = true;
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\simsun.ttc", font_size, &fontcfg); Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\simsun.ttc", font_size, &fontcfg);
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\malgun.ttf", font_size, &fontcfg); Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\malgun.ttf", font_size, &fontcfg);
#endif #endif
} }
io.Fonts->Build(); Fonts->Build();
fonts_atlas = (void *)Fonts;
ImGuiStyle& style = ImGui::GetStyle(); // ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 0.0; // Disable round window // style.WindowRounding = 0.0; // Disable round window
reset_LastError(); reset_LastError();
} }
@ -1048,6 +1049,7 @@ void Steam_Overlay::RunCallbacks()
auto callback = std::bind(&Steam_Overlay::OpenOverlayHook, this, std::placeholders::_1); auto callback = std::bind(&Steam_Overlay::OpenOverlayHook, this, std::placeholders::_1);
PRINT_DEBUG("start renderer\n", _renderer); PRINT_DEBUG("start renderer\n", _renderer);
std::set<ingame_overlay::ToggleKey> keys = {ingame_overlay::ToggleKey::SHIFT, ingame_overlay::ToggleKey::TAB}; std::set<ingame_overlay::ToggleKey> keys = {ingame_overlay::ToggleKey::SHIFT, ingame_overlay::ToggleKey::TAB};
_renderer->ImGuiFontAtlas = fonts_atlas;
bool started = _renderer->StartHook(callback, keys); bool started = _renderer->StartHook(callback, keys);
PRINT_DEBUG("tried to start renderer %u\n", started); PRINT_DEBUG("tried to start renderer %u\n", started);
} }

View File

@ -102,6 +102,7 @@ class Steam_Overlay
std::string show_url; std::string show_url;
std::vector<Overlay_Achievement> achievements; std::vector<Overlay_Achievement> achievements;
bool show_achievements, show_settings; bool show_achievements, show_settings;
void *fonts_atlas;
bool disable_forced, local_save, warning_forced; bool disable_forced, local_save, warning_forced;
uint32_t appid; uint32_t appid;

View File

@ -115,7 +115,7 @@ void DX10_Hook::_PrepareForOverlay(IDXGISwapChain* pSwapChain)
pDevice->CreateRenderTargetView(pBackBuffer, nullptr, &mainRenderTargetView); pDevice->CreateRenderTargetView(pBackBuffer, nullptr, &mainRenderTargetView);
pBackBuffer->Release(); pBackBuffer->Release();
ImGui::CreateContext(); ImGui::CreateContext((ImFontAtlas *)ImGuiFontAtlas);
ImGui_ImplDX10_Init(pDevice); ImGui_ImplDX10_Init(pDevice);
Windows_Hook::Inst()->SetInitialWindowSize(desc.OutputWindow); Windows_Hook::Inst()->SetInitialWindowSize(desc.OutputWindow);

View File

@ -147,7 +147,7 @@ void DX11_Hook::_PrepareForOverlay(IDXGISwapChain* pSwapChain)
return; return;
if(ImGui::GetCurrentContext() == nullptr) if(ImGui::GetCurrentContext() == nullptr)
ImGui::CreateContext(); ImGui::CreateContext((ImFontAtlas *)ImGuiFontAtlas);
ImGui_ImplDX11_Init(pDevice, pContext); ImGui_ImplDX11_Init(pDevice, pContext);

View File

@ -264,7 +264,7 @@ void DX12_Hook::_PrepareForOverlay(IDXGISwapChain* pSwapChain, ID3D12CommandQueu
//auto heaps = std::move(get_free_texture_heap()); //auto heaps = std::move(get_free_texture_heap());
ImGui::CreateContext(); ImGui::CreateContext((ImFontAtlas *)ImGuiFontAtlas);
ImGui_ImplDX12_Init(pDevice, bufferCount, DXGI_FORMAT_R8G8B8A8_UNORM, pSrvDescHeap, ImGui_ImplDX12_Init(pDevice, bufferCount, DXGI_FORMAT_R8G8B8A8_UNORM, pSrvDescHeap,
pSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), pSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
pSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); pSrvDescHeap->GetGPUDescriptorHandleForHeapStart());

View File

@ -133,7 +133,7 @@ void DX9_Hook::_PrepareForOverlay(IDirect3DDevice9 *pDevice, HWND destWindow)
pDevice->AddRef(); pDevice->AddRef();
_pDevice = pDevice; _pDevice = pDevice;
ImGui::CreateContext(); ImGui::CreateContext((ImFontAtlas *)ImGuiFontAtlas);
ImGui_ImplDX9_Init(pDevice); ImGui_ImplDX9_Init(pDevice);
_LastWindow = destWindow; _LastWindow = destWindow;

View File

@ -86,7 +86,7 @@ void OpenGL_Hook::_PrepareForOverlay(HDC hDC)
if (!_Initialized) if (!_Initialized)
{ {
ImGui::CreateContext(); ImGui::CreateContext((ImFontAtlas *)ImGuiFontAtlas);
ImGui_ImplOpenGL3_Init(); ImGui_ImplOpenGL3_Init();
_LastWindow = hWnd; _LastWindow = hWnd;