imgui fixed!
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -46,8 +46,10 @@ namespace Game
|
||||
bgfx::UniformHandle Uniforms[8];
|
||||
Texture Textures[4];
|
||||
uint64_t State = 0;
|
||||
uint32_t ViewID = 0;
|
||||
static Material LoadFromShader(const char* vertPath,
|
||||
const char* fragPath,
|
||||
uint32_t view = 0,
|
||||
bgfx::TextureHandle = BGFX_INVALID_HANDLE,
|
||||
bgfx::UniformHandle sampler = BGFX_INVALID_HANDLE);
|
||||
};
|
||||
@@ -62,6 +64,7 @@ namespace Game
|
||||
int32_t LastWidth = 0;
|
||||
int32_t LastHeight = 0;
|
||||
uint32_t ResetFlags = BGFX_RESET_VSYNC;
|
||||
uint32_t MainViewID = 10;
|
||||
|
||||
public:
|
||||
void Setup();
|
||||
|
||||
@@ -11,22 +11,12 @@
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
// #include "../bgfx_utils.h"
|
||||
#include "imgui-helper.h"
|
||||
|
||||
#ifndef USE_ENTRY
|
||||
#define USE_ENTRY 0
|
||||
#endif // USE_ENTRY
|
||||
|
||||
#ifndef USE_LOCAL_STB
|
||||
#define USE_LOCAL_STB 1
|
||||
#endif // USE_LOCAL_STB
|
||||
|
||||
#if USE_ENTRY
|
||||
#include "../entry/entry.h"
|
||||
#include "../entry/input.h"
|
||||
#endif // USE_ENTRY
|
||||
|
||||
#include "fs_imgui_image.bin.h"
|
||||
#include "fs_ocornut_imgui.bin.h"
|
||||
#include "vs_imgui_image.bin.h"
|
||||
@@ -208,9 +198,7 @@ struct OcornutImguiContext
|
||||
m_last = bx::getHPCounter();
|
||||
|
||||
ImGui::SetAllocatorFunctions(memAlloc, memFree, NULL);
|
||||
|
||||
m_imgui = ImGui::CreateContext();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
io.DisplaySize = ImVec2(1280.0f, 720.0f);
|
||||
@@ -274,13 +262,10 @@ struct OcornutImguiContext
|
||||
bgfx::TextureFormat::BGRA8,
|
||||
0,
|
||||
bgfx::copy(data, width * height * 4));
|
||||
|
||||
// ImGui::InitDockContext();
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
// ImGui::ShutdownDockContext();
|
||||
ImGui::DestroyContext(m_imgui);
|
||||
|
||||
bgfx::destroy(s_tex);
|
||||
@@ -311,26 +296,9 @@ struct OcornutImguiContext
|
||||
style.WindowBorderSize = 0.0f;
|
||||
}
|
||||
|
||||
void beginFrame(int32_t _mx,
|
||||
int32_t _my,
|
||||
uint8_t _button,
|
||||
int32_t _scroll,
|
||||
int _width,
|
||||
int _height,
|
||||
int _inputChar,
|
||||
bgfx::ViewId _viewId)
|
||||
void beginFrame(bgfx::ViewId _viewId)
|
||||
{
|
||||
m_viewId = _viewId;
|
||||
|
||||
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);
|
||||
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
@@ -381,16 +349,9 @@ void imguiDestroy()
|
||||
s_ctx.destroy();
|
||||
}
|
||||
|
||||
void imguiBeginFrame(int32_t _mx,
|
||||
int32_t _my,
|
||||
uint8_t _button,
|
||||
int32_t _scroll,
|
||||
uint16_t _width,
|
||||
uint16_t _height,
|
||||
int _inputChar,
|
||||
bgfx::ViewId _viewId)
|
||||
void imguiBeginFrame(bgfx::ViewId _viewId)
|
||||
{
|
||||
s_ctx.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _viewId);
|
||||
s_ctx.beginFrame(_viewId);
|
||||
}
|
||||
|
||||
void imguiEndFrame()
|
||||
|
||||
@@ -28,22 +28,9 @@ namespace bx
|
||||
void imguiCreate(float _fontSize = 18.0f, bx::AllocatorI* _allocator = NULL);
|
||||
void imguiDestroy();
|
||||
|
||||
void imguiBeginFrame(int32_t _mx,
|
||||
int32_t _my,
|
||||
uint8_t _button,
|
||||
int32_t _scroll,
|
||||
uint16_t _width,
|
||||
uint16_t _height,
|
||||
int _inputChar = -1,
|
||||
bgfx::ViewId _view = 255);
|
||||
void imguiBeginFrame(bgfx::ViewId _view = 255);
|
||||
void imguiEndFrame();
|
||||
|
||||
namespace entry
|
||||
{
|
||||
class AppI;
|
||||
}
|
||||
void showExampleDialog(entry::AppI* _app, const char* _errorText = NULL);
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
#define IMGUI_FLAGS_NONE UINT8_C(0x00)
|
||||
|
||||
Reference in New Issue
Block a user