diff options
Diffstat (limited to 'app/source/Cplt/ImGuiBackend')
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend.hpp | 3 | ||||
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend_DirectX11.cpp | 38 | ||||
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend_DirectX12.cpp | 48 | ||||
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend_Metal.mm | 18 | ||||
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend_OpenGL2.cpp | 21 | ||||
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend_OpenGL3.cpp | 21 | ||||
-rw-r--r-- | app/source/Cplt/ImGuiBackend/Backend_Vulkan.cpp | 42 |
7 files changed, 64 insertions, 127 deletions
diff --git a/app/source/Cplt/ImGuiBackend/Backend.hpp b/app/source/Cplt/ImGuiBackend/Backend.hpp index ca391e6..9ceccb1 100644 --- a/app/source/Cplt/ImGuiBackend/Backend.hpp +++ b/app/source/Cplt/ImGuiBackend/Backend.hpp @@ -2,8 +2,7 @@ #include <memory> -class RenderingBackend -{ +class RenderingBackend { public: // Implemented in Backend_OpenGL2.cpp static std::unique_ptr<RenderingBackend> CreateOpenGL2Backend(); diff --git a/app/source/Cplt/ImGuiBackend/Backend_DirectX11.cpp b/app/source/Cplt/ImGuiBackend/Backend_DirectX11.cpp index 4dc33f7..6dcf674 100644 --- a/app/source/Cplt/ImGuiBackend/Backend_DirectX11.cpp +++ b/app/source/Cplt/ImGuiBackend/Backend_DirectX11.cpp @@ -11,8 +11,7 @@ // Forward declare message handler from imgui_impl_win32.cpp extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -class DirectX11Backend : public RenderingBackend -{ +class DirectX11Backend : public RenderingBackend { private: HWND hWnd; WNDCLASSEX wc; @@ -23,8 +22,7 @@ private: ID3D11RenderTargetView* mMainRenderTargetView = nullptr; public: - DirectX11Backend() - { + DirectX11Backend() { ImGui_ImplWin32_EnableDpiAwareness(); wc.cbSize = sizeof(WNDCLASSEX); @@ -70,8 +68,7 @@ public: ImGui_ImplDX11_Init(mD3dDevice, mD3dDeviceContext); } - virtual ~DirectX11Backend() - { + virtual ~DirectX11Backend() { ImGui_ImplDX11_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); @@ -81,8 +78,7 @@ public: ::UnregisterClass(wc.lpszClassName, wc.hInstance); } - virtual void RunUntilWindowClose(void (*windowContent)()) - { + virtual void RunUntilWindowClose(void (*windowContent)()) { while (true) { MSG msg; bool done = false; @@ -113,8 +109,7 @@ public: } private: - bool CreateDeviceD3D() - { + bool CreateDeviceD3D() { // Setup swap chain DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(sd)); @@ -133,7 +128,7 @@ private: sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; UINT createDeviceFlags = 0; - //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; + // createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; D3D_FEATURE_LEVEL featureLevel; const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, @@ -147,8 +142,7 @@ private: return true; } - void CleanupDeviceD3D() - { + void CleanupDeviceD3D() { CleanupRenderTarget(); if (mSwapChain) { mSwapChain->Release(); @@ -164,24 +158,21 @@ private: } } - void CreateRenderTarget() - { + void CreateRenderTarget() { ID3D11Texture2D* pBackBuffer; mSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); mD3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &mMainRenderTargetView); pBackBuffer->Release(); } - void CleanupRenderTarget() - { + void CleanupRenderTarget() { if (mMainRenderTargetView) { mMainRenderTargetView->Release(); mMainRenderTargetView = nullptr; } } - static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) - { + static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DirectX11Backend* self; if (uMsg == WM_NCCREATE) { auto lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam); @@ -199,8 +190,7 @@ private: } } - LRESULT WndProc(UINT msg, WPARAM wParam, LPARAM lParam) - { + LRESULT WndProc(UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) { return true; } @@ -231,8 +221,7 @@ private: } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() { try { return std::make_unique<DirectX11Backend>(); } catch (std::exception& e) { @@ -242,8 +231,7 @@ std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() #else // ^^ BUILD_CORE_WITH_DX11_BACKEND | BUILD_CORE_WITH_DX11_BACKEND vv -std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() { return nullptr; } diff --git a/app/source/Cplt/ImGuiBackend/Backend_DirectX12.cpp b/app/source/Cplt/ImGuiBackend/Backend_DirectX12.cpp index fd4a531..c0492c2 100644 --- a/app/source/Cplt/ImGuiBackend/Backend_DirectX12.cpp +++ b/app/source/Cplt/ImGuiBackend/Backend_DirectX12.cpp @@ -15,11 +15,9 @@ constexpr int kNumBackBuffers = 3; // Forward declare message handler from imgui_impl_win32.cpp extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -class DirectX12Backend : public RenderingBackend -{ +class DirectX12Backend : public RenderingBackend { private: - struct FrameContext - { + struct FrameContext { ID3D12CommandAllocator* CommandAllocator; UINT64 FenceValue; }; @@ -44,8 +42,7 @@ private: D3D12_CPU_DESCRIPTOR_HANDLE mMainRenderTargetDescriptor[kNumBackBuffers] = {}; public: - DirectX12Backend() - { + DirectX12Backend() { ImGui_ImplWin32_EnableDpiAwareness(); wc.cbSize = sizeof(WNDCLASSEX); @@ -91,8 +88,7 @@ public: ImGui_ImplDX12_Init(mD3dDevice, kNumFramesInFlight, DXGI_FORMAT_R8G8B8A8_UNORM, mD3dSrvDescHeap, mD3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), mD3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); } - virtual ~DirectX12Backend() - { + virtual ~DirectX12Backend() { WaitForLastSubmittedFrame(); // Cleanup @@ -105,8 +101,7 @@ public: ::UnregisterClass(wc.lpszClassName, wc.hInstance); } - virtual void RunUntilWindowClose(void (*windowContent)()) - { + virtual void RunUntilWindowClose(void (*windowContent)()) { while (true) { MSG msg; bool done = false; @@ -166,8 +161,7 @@ public: } private: - bool CreateDeviceD3D() - { + bool CreateDeviceD3D() { // Setup swap chain DXGI_SWAP_CHAIN_DESC1 sd; { @@ -266,8 +260,7 @@ private: return true; } - void CleanupDeviceD3D() - { + void CleanupDeviceD3D() { CleanupRenderTarget(); if (mSwapChain) { mSwapChain->Release(); @@ -311,8 +304,7 @@ private: } } - void CreateRenderTarget() - { + void CreateRenderTarget() { for (UINT i = 0; i < kNumBackBuffers; i++) { ID3D12Resource* pBackBuffer = nullptr; @@ -322,8 +314,7 @@ private: } } - void CleanupRenderTarget() - { + void CleanupRenderTarget() { WaitForLastSubmittedFrame(); for (UINT i = 0; i < kNumBackBuffers; i++) @@ -333,8 +324,7 @@ private: } } - void WaitForLastSubmittedFrame() - { + void WaitForLastSubmittedFrame() { FrameContext* frameCtx = &mFrameContext[mFrameIndex % kNumFramesInFlight]; UINT64 fenceValue = frameCtx->FenceValue; @@ -349,8 +339,7 @@ private: WaitForSingleObject(mFenceEvent, INFINITE); } - FrameContext* WaitForNextFrameResources() - { + FrameContext* WaitForNextFrameResources() { UINT nextFrameIndex = mFrameIndex + 1; mFrameIndex = nextFrameIndex; @@ -372,8 +361,7 @@ private: return frameCtx; } - void ResizeSwapChain(int width, int height) - { + void ResizeSwapChain(int width, int height) { DXGI_SWAP_CHAIN_DESC1 sd; mSwapChain->GetDesc1(&sd); sd.Width = width; @@ -397,8 +385,7 @@ private: assert(mSwapChainWaitableObject != nullptr); } - static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) - { + static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DirectX12Backend* self; if (uMsg == WM_NCCREATE) { auto lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam); @@ -416,8 +403,7 @@ private: } } - LRESULT WndProc(UINT msg, WPARAM wParam, LPARAM lParam) - { + LRESULT WndProc(UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) { return true; } @@ -451,8 +437,7 @@ private: } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() { try { return std::make_unique<DirectX12Backend>(); } catch (std::exception& e) { @@ -462,8 +447,7 @@ std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() #else // ^^ BUILD_CORE_WITH_DX12_BACKEND | BUILD_CORE_WITH_DX12_BACKEND vv -std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() { return nullptr; } diff --git a/app/source/Cplt/ImGuiBackend/Backend_Metal.mm b/app/source/Cplt/ImGuiBackend/Backend_Metal.mm index 276bef2..a1f4993 100644 --- a/app/source/Cplt/ImGuiBackend/Backend_Metal.mm +++ b/app/source/Cplt/ImGuiBackend/Backend_Metal.mm @@ -2,27 +2,22 @@ #if BUILD_CORE_WITH_METAL_BACKEND -class MetalBackend : public RenderingBackend -{ +class MetalBackend : public RenderingBackend { public: - MetalBackend() - { + MetalBackend() { // TODO } - virtual ~MetalBackend() - { + virtual ~MetalBackend() { // TODO } - virtual void RunUntilWindowClose(void (*windowContent)()) - { + virtual void RunUntilWindowClose(void (*windowContent)()) { // TODO } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateMetalBackend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateMetalBackend() { try { return std::make_unique<MetalBackend>(); } catch (std::exception& e) { @@ -32,8 +27,7 @@ std::unique_ptr<RenderingBackend> RenderingBackend::CreateMetalBackend() #else // ^^ BUILD_CORE_WITH_METAL_BACKEND | BUILD_CORE_WITH_METAL_BACKEND vv -std::unique_ptr<RenderingBackend> RenderingBackend::CreateMetalBackend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateMetalBackend() { return nullptr; } diff --git a/app/source/Cplt/ImGuiBackend/Backend_OpenGL2.cpp b/app/source/Cplt/ImGuiBackend/Backend_OpenGL2.cpp index 943a527..e9d05a5 100644 --- a/app/source/Cplt/ImGuiBackend/Backend_OpenGL2.cpp +++ b/app/source/Cplt/ImGuiBackend/Backend_OpenGL2.cpp @@ -13,14 +13,12 @@ # define IMGUI_IMPL_OPENGL_LOADER_CUSTOM # include <backend/imgui_impl_opengl2.cpp> -class OpenGL2Backend : public RenderingBackend -{ +class OpenGL2Backend : public RenderingBackend { private: GLFWwindow* mWindow; public: - OpenGL2Backend() - { + OpenGL2Backend() { glfwSetErrorCallback(&GlfwErrorCallback); if (!glfwInit()) { throw std::runtime_error("Failed to initialize GLFW."); @@ -44,8 +42,7 @@ public: ImGui_ImplOpenGL2_Init(); } - virtual ~OpenGL2Backend() - { + virtual ~OpenGL2Backend() { ImGui_ImplOpenGL2_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); @@ -54,8 +51,7 @@ public: glfwTerminate(); } - virtual void RunUntilWindowClose(void (*windowContent)()) - { + virtual void RunUntilWindowClose(void (*windowContent)()) { while (!glfwWindowShouldClose(mWindow)) { glfwPollEvents(); @@ -81,14 +77,12 @@ public: } } - static void GlfwErrorCallback(int errorCode, const char* message) - { + static void GlfwErrorCallback(int errorCode, const char* message) { std::cerr << "GLFW Error " << errorCode << ": " << message << "\n"; } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend() { try { return std::make_unique<OpenGL2Backend>(); } catch (std::exception& e) { @@ -98,8 +92,7 @@ std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend() #else // ^^ BUILD_CORE_WITH_OPENGL2_BACKEND | !BUILD_CORE_WITH_OPENGL2_BACKEND vv -std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend() { return nullptr; } diff --git a/app/source/Cplt/ImGuiBackend/Backend_OpenGL3.cpp b/app/source/Cplt/ImGuiBackend/Backend_OpenGL3.cpp index 9a7d67f..c2b6e20 100644 --- a/app/source/Cplt/ImGuiBackend/Backend_OpenGL3.cpp +++ b/app/source/Cplt/ImGuiBackend/Backend_OpenGL3.cpp @@ -13,14 +13,12 @@ # define IMGUI_IMPL_OPENGL_LOADER_CUSTOM # include <backend/imgui_impl_opengl3.cpp> -class OpenGL3Backend : public RenderingBackend -{ +class OpenGL3Backend : public RenderingBackend { private: GLFWwindow* mWindow; public: - OpenGL3Backend() - { + OpenGL3Backend() { glfwSetErrorCallback(&GlfwErrorCallback); if (!glfwInit()) { throw std::runtime_error("Failed to initialize GLFW."); @@ -60,8 +58,7 @@ public: ImGui_ImplOpenGL3_Init(glslVersion); } - virtual ~OpenGL3Backend() - { + virtual ~OpenGL3Backend() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); @@ -70,8 +67,7 @@ public: glfwTerminate(); } - virtual void RunUntilWindowClose(void (*windowContent)()) - { + virtual void RunUntilWindowClose(void (*windowContent)()) { while (!glfwWindowShouldClose(mWindow)) { glfwPollEvents(); @@ -96,14 +92,12 @@ public: } } - static void GlfwErrorCallback(int errorCode, const char* message) - { + static void GlfwErrorCallback(int errorCode, const char* message) { std::cerr << "GLFW Error " << errorCode << ": " << message << "\n"; } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL3Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL3Backend() { try { return std::make_unique<OpenGL3Backend>(); } catch (std::exception& e) { @@ -113,8 +107,7 @@ std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL3Backend() #else // ^^ BUILD_CORE_WITH_OPENGL3_BACKEND | !BUILD_CORE_WITH_OPENGL3_BACKEND vv -std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL3Backend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL3Backend() { return nullptr; } diff --git a/app/source/Cplt/ImGuiBackend/Backend_Vulkan.cpp b/app/source/Cplt/ImGuiBackend/Backend_Vulkan.cpp index 3694f05..6532b37 100644 --- a/app/source/Cplt/ImGuiBackend/Backend_Vulkan.cpp +++ b/app/source/Cplt/ImGuiBackend/Backend_Vulkan.cpp @@ -12,8 +12,7 @@ # include <backend/imgui_impl_vulkan.h> # include <backend/imgui_impl_vulkan.cpp> -class VulkanBackend : public RenderingBackend -{ +class VulkanBackend : public RenderingBackend { private: GLFWwindow* mWindow; @@ -32,8 +31,7 @@ private: bool mSwapChainRebuild = false; public: - VulkanBackend() - { + VulkanBackend() { glfwSetErrorCallback(&GlfwErrorCallback); if (!glfwInit()) { throw std::runtime_error("Failed to initialize GLFW."); @@ -82,8 +80,7 @@ public: ImGui_ImplVulkan_Init(&init_info, mMainWindowData.RenderPass); } - virtual ~VulkanBackend() - { + virtual ~VulkanBackend() { auto err = vkDeviceWaitIdle(mDevice); CheckVkResults(err); ImGui_ImplVulkan_Shutdown(); @@ -97,8 +94,7 @@ public: glfwTerminate(); } - virtual void RunUntilWindowClose(void (*windowContent)()) override - { + virtual void RunUntilWindowClose(void (*windowContent)()) override { // Upload Fonts { // Use any command queue @@ -162,8 +158,7 @@ public: } private: - void SetupVulkan(const char** extensions, uint32_t extensions_count) - { + void SetupVulkan(const char** extensions, uint32_t extensions_count) { VkResult err; // Create Vulkan Instance @@ -272,8 +267,7 @@ private: } } - void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height) - { + void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height) { wd->Surface = surface; // Check for WSI support @@ -297,8 +291,7 @@ private: ImGui_ImplVulkanH_CreateOrResizeWindow(mInstance, mPhysicalDevice, mDevice, wd, mQueueFamily, mAllocator, width, height, mMinImageCount); } - void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* drawData) - { + void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* drawData) { VkResult err; VkSemaphore imageAcquiredSemaphore = wd->FrameSemaphores[wd->SemaphoreIndex].ImageAcquiredSemaphore; @@ -363,8 +356,7 @@ private: } } - void FramePresent(ImGui_ImplVulkanH_Window* wd) - { + void FramePresent(ImGui_ImplVulkanH_Window* wd) { if (mSwapChainRebuild) { return; } @@ -386,21 +378,18 @@ private: wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores } - void CleanupVulkan() - { + void CleanupVulkan() { vkDestroyDescriptorPool(mDevice, mDescriptorPool, mAllocator); vkDestroyDevice(mDevice, mAllocator); vkDestroyInstance(mInstance, mAllocator); } - void CleanupVulkanWindow() - { + void CleanupVulkanWindow() { ImGui_ImplVulkanH_DestroyWindow(mInstance, mDevice, &mMainWindowData, mAllocator); } - static void CheckVkResults(VkResult err) - { + static void CheckVkResults(VkResult err) { if (err == 0) return; std::string message; @@ -413,14 +402,12 @@ private: std::cerr << message << '\n'; } } - static void GlfwErrorCallback(int errorCode, const char* message) - { + static void GlfwErrorCallback(int errorCode, const char* message) { std::cerr << "GLFW Error " << errorCode << ": " << message << "\n"; } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateVulkanBackend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateVulkanBackend() { try { return std::make_unique<VulkanBackend>(); } catch (std::exception& e) { @@ -430,8 +417,7 @@ std::unique_ptr<RenderingBackend> RenderingBackend::CreateVulkanBackend() #else // ^^ BUILD_CORE_WITH_VULKAN_BACKEND | ~BUILD_CORE_WITH_VULKAN_BACKEND vv -std::unique_ptr<RenderingBackend> RenderingBackend::CreateVulkanBackend() -{ +std::unique_ptr<RenderingBackend> RenderingBackend::CreateVulkanBackend() { return nullptr; } |