This commit is contained in:
Asuro
2025-02-20 23:46:10 +01:00
parent e568363ca7
commit 43d7d2d012
7 changed files with 67 additions and 53 deletions

View File

@@ -5,6 +5,8 @@
#include "../Mesh.h"
#include "Rendering.h"
#include "SDL3/SDL_events.h"
#include "backends/imgui_impl_sdl3.h"
#include "bgfx/defines.h"
#include "bx/filepath.h"
#include "bx/math.h"
@@ -228,6 +230,21 @@ namespace Game
Materials[0] = Material::LoadFromShader("vert", "frag", Textures[0].Handle, Textures[0].SamplerHandle);
imguiCreate();
if (!ImGui_ImplSDL3_InitForOther(shared.Window.SDLWindow))
{
Log("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;
if (!GetInstance().IsInitialized)
{
GetInstance().Time.StartTime = bx::getHPCounter();
@@ -236,10 +253,19 @@ namespace Game
void GameRendering::Update()
{
imguiBeginFrame(0, 0, 0, 0, 100, 100);
ImGui::ShowDemoWindow();
SharedData& shared = GetShared();
for (uint16_t i = 0; i < shared.Window.SDLEventCount; ++i)
{
ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]);
}
shared.Window.SDLEventCount = 0;
ImGui_ImplSDL3_NewFrame();
imguiBeginFrame(0, 0, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight);
ImGui::DockSpaceOverViewport();
ImGui::ShowDemoWindow();
// Reload shaders if necessary
FileChangeNotification* shaderChange = nullptr;
if (shared.Dev.ChangedShaderCount > 0)
@@ -305,6 +331,12 @@ namespace Game
}
imguiEndFrame();
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
START_PERF();
bgfx::frame();
END_PERF(shared.Window.PerfCounters, PerfCounterType::Submit, shared.Window.FrameCounter);
@@ -312,6 +344,7 @@ namespace Game
void GameRendering::Shutdown()
{
ImGui_ImplSDL3_Shutdown();
imguiDestroy();
bgfx::shutdown();
}

View File

@@ -3,6 +3,8 @@
#include <bx/string.h>
#include <cstdint>
union SDL_Event;
namespace Game
{
struct PosColorVertex

View File

@@ -322,43 +322,16 @@ struct OcornutImguiContext
{
m_viewId = _viewId;
ImGuiIO& io = ImGui::GetIO();
if (_inputChar >= 0)
{
io.AddInputCharacter(_inputChar);
}
io.DisplaySize = ImVec2((float)_width, (float)_height);
// ImGuiIO& io = ImGui::GetIO();
// io.DisplaySize = ImVec2((float)_width, (float)_height);
const int64_t now = bx::getHPCounter();
const int64_t frameTime = now - m_last;
m_last = now;
const double freq = double(bx::getHPFrequency());
io.DeltaTime = float(frameTime / freq);
io.AddMousePosEvent((float)_mx, (float)_my);
io.AddMouseButtonEvent(ImGuiMouseButton_Left, 0 != (_button & IMGUI_MBUT_LEFT));
io.AddMouseButtonEvent(ImGuiMouseButton_Right, 0 != (_button & IMGUI_MBUT_RIGHT));
io.AddMouseButtonEvent(ImGuiMouseButton_Middle, 0 != (_button & IMGUI_MBUT_MIDDLE));
io.AddMouseWheelEvent(0.0f, (float)(_scroll - m_lastScroll));
m_lastScroll = _scroll;
#if USE_ENTRY
uint8_t modifiers = inputGetModifiersState();
io.AddKeyEvent(ImGuiMod_Shift, 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift)));
io.AddKeyEvent(ImGuiMod_Ctrl, 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl)));
io.AddKeyEvent(ImGuiMod_Alt, 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt)));
io.AddKeyEvent(ImGuiMod_Super, 0 != (modifiers & (entry::Modifier::LeftMeta | entry::Modifier::RightMeta)));
for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
{
io.AddKeyEvent(m_keyMap[ii], inputGetKeyState(entry::Key::Enum(ii)));
io.SetKeyEventNativeData(m_keyMap[ii], 0, 0, ii);
}
#endif // USE_ENTRY
// const double freq = double(bx::getHPFrequency());
// io.DeltaTime = float(frameTime / freq);
ImGui::NewFrame();
// ImGuizmo::BeginFrame();
}
void endFrame()