make imgui optional-ish

This commit is contained in:
Till Wübbers
2025-04-29 08:46:05 +02:00
parent 02c40aeea6
commit 91e9566747
6 changed files with 74 additions and 35 deletions

View File

@@ -312,11 +312,13 @@ namespace Game
return *Instance;
}
void GameRendering::Setup()
void GameRendering::Setup(const RenderingSetup& setup)
{
LOG("--- RENDERING STARTUP ---");
ZoneScopedN("Setup");
SetupData = setup;
if (Instance != nullptr) LOG_WARN("old rendering wasn't destroyed!");
Instance = this;
SharedData& shared = GetShared();
@@ -325,6 +327,8 @@ namespace Game
init.type = bgfx::RendererType::Direct3D12;
#ifdef _DEBUG
// init.debug = true;
#else
// init.debug = false;
#endif
init.platformData.nwh = shared.Window.Handle;
init.platformData.ndt = nullptr;
@@ -354,23 +358,26 @@ namespace Game
LoadModels(Models, ModelCount);
ReloadShaders();
imguiCreate();
SetImguiStyle();
if (!ImGui_ImplSDL3_InitForOther(shared.Window.SDLWindow))
if (SetupData.UseImgui)
{
LOG_ERROR("Failed to set up imgui implementation!");
return;
}
imguiCreate();
SetImguiStyle();
if (!ImGui_ImplSDL3_InitForOther(shared.Window.SDLWindow))
{
LOG_ERROR("Failed to set up imgui implementation!");
return;
}
// ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_RendererHasViewports;
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
// ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
// auto& platIO = ImGui::GetPlatformIO();
// platIO.Renderer_CreateWindow = TODO;
// platIO.Platform_DestroyWindow = TODO;
// platIO.Platform_SetWindowSize = TODO;
// platIO.Platform_RenderWindow = TODO;
// ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_RendererHasViewports;
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
// ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
// auto& platIO = ImGui::GetPlatformIO();
// platIO.Renderer_CreateWindow = TODO;
// platIO.Platform_DestroyWindow = TODO;
// platIO.Platform_SetWindowSize = TODO;
// platIO.Platform_RenderWindow = TODO;
}
GameInstance& inst = GetInstance();
if (!inst.IsInitialized)
@@ -378,13 +385,16 @@ namespace Game
inst.Time.StartTime = bx::getHPCounter();
}
if (inst.DebugData.ImguiIniSize > 0)
if (SetupData.UseImgui)
{
ImGui::LoadIniSettingsFromMemory(inst.DebugData.ImguiIni, inst.DebugData.ImguiIniSize);
}
else
{
ImGui::LoadIniSettingsFromDisk("imgui.ini");
if (inst.DebugData.ImguiIniSize > 0)
{
ImGui::LoadIniSettingsFromMemory(inst.DebugData.ImguiIni, inst.DebugData.ImguiIniSize);
}
else
{
ImGui::LoadIniSettingsFromDisk("imgui.ini");
}
}
DitherGen(DitherTextures, DitherRecursion);
}
@@ -396,7 +406,10 @@ namespace Game
for (uint16_t i = 0; i < shared.Window.SDLEventCount; ++i)
{
ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]);
if (SetupData.UseImgui)
{
ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]);
}
}
shared.Window.SDLEventCount = 0;
@@ -505,6 +518,7 @@ namespace Game
HandleEvents();
// Start Rendering
if (SetupData.UseImgui)
{
ZoneScopedN("Imgui Start Frame");
imguiBeginFrame(20);
@@ -518,12 +532,13 @@ namespace Game
GetInstance().GameLevel.Render(MainViewID, Models, Materials, Textures);
// Finish Frame
if (SetupData.UseImgui)
{
ZoneScopedN("Imgui End Frame");
imguiEndFrame();
}
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
if (SetupData.UseImgui && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ZoneScopedN("Imgui Platform Update");
ImGui::UpdatePlatformWindows();
@@ -542,13 +557,18 @@ namespace Game
{
ZoneScopedN("Shutdown");
LOG("--- RENDERING_SHUTDOWN ---");
ImGui::SaveIniSettingsToDisk("imgui.ini");
auto& debug = GetInstance().DebugData;
const char* iniData = ImGui::SaveIniSettingsToMemory(reinterpret_cast<uint64_t*>(&debug.ImguiIniSize));
assert(debug.ImguiIniSize <= BX_COUNTOF(InstanceDebugData::ImguiIni));
bx::memCopy(debug.ImguiIni, iniData, bx::min(debug.ImguiIniSize, BX_COUNTOF(InstanceDebugData::ImguiIni)));
ImGui_ImplSDL3_Shutdown();
imguiDestroy();
if (SetupData.UseImgui)
{
ImGui::SaveIniSettingsToDisk("imgui.ini");
auto& debug = GetInstance().DebugData;
const char* iniData = ImGui::SaveIniSettingsToMemory(reinterpret_cast<uint64_t*>(&debug.ImguiIniSize));
assert(debug.ImguiIniSize <= BX_COUNTOF(InstanceDebugData::ImguiIni));
bx::memCopy(debug.ImguiIni, iniData, bx::min(debug.ImguiIniSize, BX_COUNTOF(InstanceDebugData::ImguiIni)));
ImGui_ImplSDL3_Shutdown();
imguiDestroy();
}
bgfx::shutdown();
Instance = nullptr;
}

View File

@@ -64,6 +64,11 @@ namespace Game
Debug,
};
struct RenderingSetup
{
bool UseImgui = true;
};
class GameRendering
{
public:
@@ -76,6 +81,7 @@ namespace Game
DitherData DitherTextures;
public:
RenderingSetup SetupData;
bgfx::UniformHandle DefaultSampler;
Texture Textures[MaxTextures];
Material Materials[8];
@@ -89,7 +95,7 @@ namespace Game
int32_t DitherRecursion = 1;
public:
void Setup();
void Setup(const RenderingSetup& setup);
void Update();
void HandleEvents();
void LoadTextures();