imgui
This commit is contained in:
@@ -21,9 +21,9 @@ file(GLOB imgui_backend_sdl
|
||||
|
||||
# Engine
|
||||
file(GLOB_RECURSE sources_engine engine/*.cpp engine/*.h)
|
||||
add_executable(PuzGameEngine ${sources_engine} ${imgui_sources} ${imgui_backend_sdl})
|
||||
add_executable(PuzGameEngine ${sources_engine})
|
||||
set_property(TARGET PuzGameEngine PROPERTY CXX_STANDARD 17)
|
||||
target_include_directories(PuzGameEngine PUBLIC dependency/imgui)
|
||||
target_include_directories(PuzGameEngine PUBLIC)
|
||||
#file(COPY ${data} DESTINATION resources)
|
||||
|
||||
#target_compile_options(PuzGameEngine PUBLIC xyz)
|
||||
@@ -32,7 +32,7 @@ target_include_directories(PuzGameEngine PUBLIC dependency/imgui)
|
||||
# Game
|
||||
file(GLOB_RECURSE sources_game game/*.cpp game/*.h)
|
||||
file(GLOB source_singleheader dependency/tinygltf/stb_image.h dependency/tinygltf/stb_image_write.h dependency/tinygltf/json.hpp dependency/tinygltf/tiny_gltf.h)
|
||||
add_library(PuzGame SHARED ${sources_game} ${source_singleheader} ${imgui_sources})
|
||||
add_library(PuzGame SHARED ${sources_game} ${source_singleheader} ${imgui_sources} ${imgui_backend_sdl})
|
||||
set_property(TARGET PuzGame PROPERTY CXX_STANDARD 17)
|
||||
target_include_directories(PuzGame PUBLIC dependency/imgui)
|
||||
|
||||
@@ -45,6 +45,6 @@ SET(BGFX_BUILD_EXAMPLES OFF)
|
||||
add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/bgfx.cmake")
|
||||
|
||||
# Link
|
||||
target_link_libraries(PuzGame bx bimg bgfx)
|
||||
target_link_libraries(PuzGame bx bimg bgfx SDL3::SDL3)
|
||||
target_link_libraries(PuzGameEngine bx SDL3::SDL3)
|
||||
set_target_properties(PuzGame PROPERTIES OUTPUT_NAME "PuzGame2")
|
||||
|
||||
@@ -63,8 +63,14 @@ struct PerfCounter
|
||||
}
|
||||
};
|
||||
|
||||
class SDL_Window;
|
||||
union SDL_Event;
|
||||
|
||||
struct SharedWindowData
|
||||
{
|
||||
SDL_Window* SDLWindow = nullptr;
|
||||
SDL_Event* SDLEvents{nullptr};
|
||||
uint16_t SDLEventCount = 0;
|
||||
void* Handle = nullptr;
|
||||
int32_t WindowWidth = 1920;
|
||||
int32_t WindowHeight = 1080;
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
#include "Shared.h"
|
||||
#include "Window.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
#include <cstdio>
|
||||
#include <imgui.h>
|
||||
|
||||
void EngineWindow::Startup(SharedWindowData& shared)
|
||||
{
|
||||
@@ -29,29 +27,28 @@ void EngineWindow::Startup(SharedWindowData& shared)
|
||||
printf("Failed to get window pointer!\n");
|
||||
return;
|
||||
}
|
||||
shared.SDLWindow = Window;
|
||||
// SDL_SetWindowRelativeMouseMode(Window, true);
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
auto* imguiCtx = ImGui::CreateContext();
|
||||
if (imguiCtx == nullptr)
|
||||
{
|
||||
printf("Failed to set up imgui context!\n");
|
||||
return;
|
||||
}
|
||||
if (!ImGui_ImplSDL3_InitForVulkan(Window))
|
||||
{
|
||||
printf("Failed to set up imgui implementation!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void EngineWindow::Update(SharedWindowData& shared)
|
||||
{
|
||||
START_PERF();
|
||||
shared.SDLEvents = &EventBuffer[0];
|
||||
|
||||
SDL_Event evt;
|
||||
while (SDL_PollEvent(&evt))
|
||||
{
|
||||
ImGui_ImplSDL3_ProcessEvent(&evt);
|
||||
if (shared.SDLEventCount < MaxEventBufferSize)
|
||||
{
|
||||
EventBuffer[shared.SDLEventCount] = evt;
|
||||
++shared.SDLEventCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Warning: Skipping SDL event!\n");
|
||||
}
|
||||
|
||||
switch (evt.type)
|
||||
{
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
class EngineWindow
|
||||
{
|
||||
static constexpr uint32_t MaxEventBufferSize = 16;
|
||||
|
||||
public:
|
||||
SDL_Window* Window;
|
||||
bool CloseRequested = false;
|
||||
SDL_Event EventBuffer[MaxEventBufferSize];
|
||||
|
||||
public:
|
||||
void Startup(SharedWindowData& Shared);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <bx/string.h>
|
||||
#include <cstdint>
|
||||
|
||||
union SDL_Event;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
struct PosColorVertex
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user