imgui fixed!

This commit is contained in:
Asuro
2025-02-21 22:12:12 +01:00
parent dc12510fcb
commit edde743542
5 changed files with 40 additions and 86 deletions

View File

@@ -194,11 +194,11 @@ namespace Game
void GameRendering::Setup()
{
Log("Game rendering setup...");
Log("--- RENDERING STARTUP ---");
SharedData& shared = GetShared();
bgfx::Init init;
init.type = bgfx::RendererType::Vulkan;
init.type = bgfx::RendererType::Direct3D12;
init.debug = true;
init.platformData.nwh = shared.Window.Handle;
init.platformData.ndt = nullptr;
@@ -209,6 +209,7 @@ namespace Game
LastWidth = shared.Window.WindowWidth;
LastHeight = shared.Window.WindowHeight;
Log("%i by %i", init.resolution.width, init.resolution.height);
if (!bgfx::init(init))
@@ -219,8 +220,9 @@ namespace Game
{
Log("BGFX setup succeded!");
}
// bgfx::setDebug(BGFX_DEBUG_TEXT);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);
bgfx::setDebug(BGFX_DEBUG_TEXT);
bgfx::setViewClear(MainViewID, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3399FFff, 1.0f, 0);
bgfx::setViewRect(MainViewID, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight);
DefaultSampler = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler);
Textures[0].Handle =
@@ -229,7 +231,8 @@ namespace Game
LoadMesh(Models[0], "models/cube.gltf");
LoadMesh(Models[1], "models/zurg.gltf");
Materials[0] = Material::LoadFromShader("vert", "frag", Textures[0].Handle, Textures[0].SamplerHandle);
Materials[0] =
Material::LoadFromShader("vert", "frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle);
imguiCreate();
if (!ImGui_ImplSDL3_InitForOther(shared.Window.SDLWindow))
@@ -257,17 +260,22 @@ namespace Game
{
SharedData& shared = GetShared();
// Handle events
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);
// TODO: why does this break stuff??
// ImGui::DockSpaceOverViewport();
ImGui::ShowDemoWindow();
// Resize if necessary
if (shared.Window.WindowWidth != LastWidth || shared.Window.WindowHeight != LastHeight)
{
bgfx::reset(shared.Window.WindowWidth, shared.Window.WindowHeight, ResetFlags);
bgfx::setViewRect(MainViewID, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight);
LastWidth = shared.Window.WindowWidth;
LastHeight = shared.Window.WindowHeight;
}
// Reload shaders if necessary
FileChangeNotification* shaderChange = nullptr;
@@ -292,19 +300,18 @@ namespace Game
}
}
}
if (shared.Window.WindowWidth != LastWidth || shared.Window.WindowHeight != LastHeight)
{
bgfx::reset(shared.Window.WindowWidth, shared.Window.WindowHeight, ResetFlags);
LastWidth = shared.Window.WindowWidth;
LastHeight = shared.Window.WindowHeight;
}
imguiBeginFrame(20);
ImGui_ImplSDL3_NewFrame();
// TODO: why does this break stuff??
ImGui::DockSpaceOverViewport(0, 0, ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::ShowDemoWindow();
{
GetInstance().GameLevel.Update();
}
auto& IO = ImGui::GetIO();
// Set view and projection matrix for view 0.
GetInstance().GameLevel.Update();
// TODO: Move player stuff to level
{
float proj[16];
bx::mtxProj(proj,
@@ -318,16 +325,13 @@ namespace Game
if (player.Mode == PlayerMode::Freefly)
{
player.FreeflyCamTransform.UpdateMatrix();
bgfx::setViewTransform(0, player.FreeflyCamTransform.M.M, proj);
bgfx::setViewTransform(MainViewID, player.FreeflyCamTransform.M.M, proj);
}
else
{
player.PlayerCamTransform.UpdateMatrix();
bgfx::setViewTransform(0, player.PlayerCamTransform.M.M, proj);
bgfx::setViewTransform(MainViewID, player.PlayerCamTransform.M.M, proj);
}
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight);
}
GetInstance().GameLevel.Cubes.Render(Models, Materials);
@@ -359,10 +363,8 @@ namespace Game
bgfx::shutdown();
}
Material Material::LoadFromShader(const char* vertPath,
const char* fragPath,
bgfx::TextureHandle tex,
bgfx::UniformHandle sampler)
Material Material::LoadFromShader(
const char* vertPath, const char* fragPath, uint32_t view, bgfx::TextureHandle tex, bgfx::UniformHandle sampler)
{
BX_ASSERT(vertPath != nullptr && fragPath != nullptr, "Invalid shader path!");
bgfx::ShaderHandle vertexShader = loadShader(vertPath);
@@ -376,6 +378,7 @@ namespace Game
mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_testColor", bgfx::UniformType::Vec4);
mat.Textures[0].Handle = tex;
mat.Textures[0].SamplerHandle = sampler;
mat.ViewID = view;
return mat;
}
} // namespace Game