diff options
author | rtk0c <[email protected]> | 2021-05-06 21:56:40 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-05-06 21:56:40 -0700 |
commit | 1fd1e4b5f2418e3ac2909658993bfedb615537ec (patch) | |
tree | 6de080d2273890f8a74d7fcd3572bb44f44ac545 /core/src/Entrypoint | |
parent | 538e804fc9beb83e711a210ffbb6badc15f285d5 (diff) |
Change brace style to on new line, add initial deliveries view when an order entry is selected
Diffstat (limited to 'core/src/Entrypoint')
-rw-r--r-- | core/src/Entrypoint/Backend.hpp | 3 | ||||
-rw-r--r-- | core/src/Entrypoint/Backend_DirectX11.cpp | 36 | ||||
-rw-r--r-- | core/src/Entrypoint/Backend_DirectX12.cpp | 48 | ||||
-rw-r--r-- | core/src/Entrypoint/Backend_Metal.mm | 18 | ||||
-rw-r--r-- | core/src/Entrypoint/Backend_OpenGL2.cpp | 21 | ||||
-rw-r--r-- | core/src/Entrypoint/Backend_OpenGL3.cpp | 21 | ||||
-rw-r--r-- | core/src/Entrypoint/Backend_Vulkan.cpp | 42 | ||||
-rw-r--r-- | core/src/Entrypoint/main.cpp | 19 |
8 files changed, 140 insertions, 68 deletions
diff --git a/core/src/Entrypoint/Backend.hpp b/core/src/Entrypoint/Backend.hpp index 9ceccb1..ca391e6 100644 --- a/core/src/Entrypoint/Backend.hpp +++ b/core/src/Entrypoint/Backend.hpp @@ -2,7 +2,8 @@ #include <memory> -class RenderingBackend { +class RenderingBackend +{ public: // Implemented in Backend_OpenGL2.cpp static std::unique_ptr<RenderingBackend> CreateOpenGL2Backend(); diff --git a/core/src/Entrypoint/Backend_DirectX11.cpp b/core/src/Entrypoint/Backend_DirectX11.cpp index 8d46bf4..4dc33f7 100644 --- a/core/src/Entrypoint/Backend_DirectX11.cpp +++ b/core/src/Entrypoint/Backend_DirectX11.cpp @@ -11,7 +11,8 @@ // 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; @@ -22,7 +23,8 @@ private: ID3D11RenderTargetView* mMainRenderTargetView = nullptr; public: - DirectX11Backend() { + DirectX11Backend() + { ImGui_ImplWin32_EnableDpiAwareness(); wc.cbSize = sizeof(WNDCLASSEX); @@ -68,7 +70,8 @@ public: ImGui_ImplDX11_Init(mD3dDevice, mD3dDeviceContext); } - virtual ~DirectX11Backend() { + virtual ~DirectX11Backend() + { ImGui_ImplDX11_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); @@ -78,7 +81,8 @@ public: ::UnregisterClass(wc.lpszClassName, wc.hInstance); } - virtual void RunUntilWindowClose(void (*windowContent)()) { + virtual void RunUntilWindowClose(void (*windowContent)()) + { while (true) { MSG msg; bool done = false; @@ -109,7 +113,8 @@ public: } private: - bool CreateDeviceD3D() { + bool CreateDeviceD3D() + { // Setup swap chain DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(sd)); @@ -142,7 +147,8 @@ private: return true; } - void CleanupDeviceD3D() { + void CleanupDeviceD3D() + { CleanupRenderTarget(); if (mSwapChain) { mSwapChain->Release(); @@ -158,21 +164,24 @@ 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); @@ -190,7 +199,8 @@ 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; } @@ -221,7 +231,8 @@ private: } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() { +std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx11Backend() +{ try { return std::make_unique<DirectX11Backend>(); } catch (std::exception& e) { @@ -231,7 +242,8 @@ 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/core/src/Entrypoint/Backend_DirectX12.cpp b/core/src/Entrypoint/Backend_DirectX12.cpp index c0492c2..fd4a531 100644 --- a/core/src/Entrypoint/Backend_DirectX12.cpp +++ b/core/src/Entrypoint/Backend_DirectX12.cpp @@ -15,9 +15,11 @@ 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; }; @@ -42,7 +44,8 @@ private: D3D12_CPU_DESCRIPTOR_HANDLE mMainRenderTargetDescriptor[kNumBackBuffers] = {}; public: - DirectX12Backend() { + DirectX12Backend() + { ImGui_ImplWin32_EnableDpiAwareness(); wc.cbSize = sizeof(WNDCLASSEX); @@ -88,7 +91,8 @@ public: ImGui_ImplDX12_Init(mD3dDevice, kNumFramesInFlight, DXGI_FORMAT_R8G8B8A8_UNORM, mD3dSrvDescHeap, mD3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), mD3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); } - virtual ~DirectX12Backend() { + virtual ~DirectX12Backend() + { WaitForLastSubmittedFrame(); // Cleanup @@ -101,7 +105,8 @@ public: ::UnregisterClass(wc.lpszClassName, wc.hInstance); } - virtual void RunUntilWindowClose(void (*windowContent)()) { + virtual void RunUntilWindowClose(void (*windowContent)()) + { while (true) { MSG msg; bool done = false; @@ -161,7 +166,8 @@ public: } private: - bool CreateDeviceD3D() { + bool CreateDeviceD3D() + { // Setup swap chain DXGI_SWAP_CHAIN_DESC1 sd; { @@ -260,7 +266,8 @@ private: return true; } - void CleanupDeviceD3D() { + void CleanupDeviceD3D() + { CleanupRenderTarget(); if (mSwapChain) { mSwapChain->Release(); @@ -304,7 +311,8 @@ private: } } - void CreateRenderTarget() { + void CreateRenderTarget() + { for (UINT i = 0; i < kNumBackBuffers; i++) { ID3D12Resource* pBackBuffer = nullptr; @@ -314,7 +322,8 @@ private: } } - void CleanupRenderTarget() { + void CleanupRenderTarget() + { WaitForLastSubmittedFrame(); for (UINT i = 0; i < kNumBackBuffers; i++) @@ -324,7 +333,8 @@ private: } } - void WaitForLastSubmittedFrame() { + void WaitForLastSubmittedFrame() + { FrameContext* frameCtx = &mFrameContext[mFrameIndex % kNumFramesInFlight]; UINT64 fenceValue = frameCtx->FenceValue; @@ -339,7 +349,8 @@ private: WaitForSingleObject(mFenceEvent, INFINITE); } - FrameContext* WaitForNextFrameResources() { + FrameContext* WaitForNextFrameResources() + { UINT nextFrameIndex = mFrameIndex + 1; mFrameIndex = nextFrameIndex; @@ -361,7 +372,8 @@ 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; @@ -385,7 +397,8 @@ 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); @@ -403,7 +416,8 @@ 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; } @@ -437,7 +451,8 @@ private: } }; -std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() { +std::unique_ptr<RenderingBackend> RenderingBackend::CreateDx12Backend() +{ try { return std::make_unique<DirectX12Backend>(); } catch (std::exception& e) { @@ -447,7 +462,8 @@ 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/core/src/Entrypoint/Backend_Metal.mm b/core/src/Entrypoint/Backend_Metal.mm index a1f4993..276bef2 100644 --- a/core/src/Entrypoint/Backend_Metal.mm +++ b/core/src/Entrypoint/Backend_Metal.mm @@ -2,22 +2,27 @@ #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) { @@ -27,7 +32,8 @@ 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/core/src/Entrypoint/Backend_OpenGL2.cpp b/core/src/Entrypoint/Backend_OpenGL2.cpp index 422ad91..8c56b81 100644 --- a/core/src/Entrypoint/Backend_OpenGL2.cpp +++ b/core/src/Entrypoint/Backend_OpenGL2.cpp @@ -12,12 +12,14 @@ # define IMGUI_IMPL_OPENGL_LOADER_GLAD # 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."); @@ -41,7 +43,8 @@ public: ImGui_ImplOpenGL2_Init(); } - virtual ~OpenGL2Backend() { + virtual ~OpenGL2Backend() + { ImGui_ImplOpenGL2_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); @@ -50,7 +53,8 @@ public: glfwTerminate(); } - virtual void RunUntilWindowClose(void (*windowContent)()) { + virtual void RunUntilWindowClose(void (*windowContent)()) + { while (!glfwWindowShouldClose(mWindow)) { glfwPollEvents(); @@ -76,12 +80,14 @@ 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) { @@ -91,7 +97,8 @@ 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/core/src/Entrypoint/Backend_OpenGL3.cpp b/core/src/Entrypoint/Backend_OpenGL3.cpp index 36a0cb3..50dc78f 100644 --- a/core/src/Entrypoint/Backend_OpenGL3.cpp +++ b/core/src/Entrypoint/Backend_OpenGL3.cpp @@ -12,12 +12,14 @@ # define IMGUI_IMPL_OPENGL_LOADER_GLAD # 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."); @@ -57,7 +59,8 @@ public: ImGui_ImplOpenGL3_Init(glslVersion); } - virtual ~OpenGL3Backend() { + virtual ~OpenGL3Backend() + { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); @@ -66,7 +69,8 @@ public: glfwTerminate(); } - virtual void RunUntilWindowClose(void (*windowContent)()) { + virtual void RunUntilWindowClose(void (*windowContent)()) + { while (!glfwWindowShouldClose(mWindow)) { glfwPollEvents(); @@ -91,12 +95,14 @@ 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) { @@ -106,7 +112,8 @@ 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/core/src/Entrypoint/Backend_Vulkan.cpp b/core/src/Entrypoint/Backend_Vulkan.cpp index 9d79acf..de3b5ca 100644 --- a/core/src/Entrypoint/Backend_Vulkan.cpp +++ b/core/src/Entrypoint/Backend_Vulkan.cpp @@ -12,7 +12,8 @@ # include <backend/imgui_impl_vulkan.h> # include <backend/imgui_impl_vulkan.cpp> -class VulkanBackend : public RenderingBackend { +class VulkanBackend : public RenderingBackend +{ private: GLFWwindow* mWindow; @@ -31,7 +32,8 @@ private: bool mSwapChainRebuild = false; public: - VulkanBackend() { + VulkanBackend() + { glfwSetErrorCallback(&GlfwErrorCallback); if (!glfwInit()) { throw std::runtime_error("Failed to initialize GLFW."); @@ -80,7 +82,8 @@ public: ImGui_ImplVulkan_Init(&init_info, mMainWindowData.RenderPass); } - virtual ~VulkanBackend() { + virtual ~VulkanBackend() + { auto err = vkDeviceWaitIdle(mDevice); CheckVkResults(err); ImGui_ImplVulkan_Shutdown(); @@ -94,7 +97,8 @@ public: glfwTerminate(); } - virtual void RunUntilWindowClose(void (*windowContent)()) override { + virtual void RunUntilWindowClose(void (*windowContent)()) override + { // Upload Fonts { // Use any command queue @@ -158,7 +162,8 @@ 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 @@ -267,7 +272,8 @@ 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 @@ -291,7 +297,8 @@ 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; @@ -356,7 +363,8 @@ private: } } - void FramePresent(ImGui_ImplVulkanH_Window* wd) { + void FramePresent(ImGui_ImplVulkanH_Window* wd) + { if (mSwapChainRebuild) { return; } @@ -378,18 +386,21 @@ 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; @@ -402,12 +413,14 @@ 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) { @@ -417,7 +430,8 @@ 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; } diff --git a/core/src/Entrypoint/main.cpp b/core/src/Entrypoint/main.cpp index 8f9832c..2d0238e 100644 --- a/core/src/Entrypoint/main.cpp +++ b/core/src/Entrypoint/main.cpp @@ -21,7 +21,8 @@ namespace fs = std::filesystem; using namespace std::literals::string_literals; using namespace std::literals::string_view_literals; -static std::unique_ptr<RenderingBackend> CreateDefaultBackend() { +static std::unique_ptr<RenderingBackend> CreateDefaultBackend() +{ #if PLATFORM_WIN32 # if BUILD_CORE_WITH_DX12_BACKEND if (auto backend = RenderingBackend::CreateDx12Backend()) { @@ -72,7 +73,8 @@ static std::unique_ptr<RenderingBackend> CreateDefaultBackend() { return nullptr; } -static std::unique_ptr<RenderingBackend> CreateBackend(std::string_view option) { +static std::unique_ptr<RenderingBackend> CreateBackend(std::string_view option) +{ if (option == "default") { return CreateDefaultBackend(); } else if (option == "opengl2") { @@ -96,7 +98,8 @@ static std::unique_ptr<RenderingBackend> CreateBackend(std::string_view option) } } -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ argparse::ArgumentParser parser; parser.add_argument("--global-data-directory") .help("Directory in which global data (such as recently used projects) are saved to. Use 'default' to use the default directory on each platform.") @@ -159,10 +162,16 @@ int main(int argc, char* argv[]) { GlobalStates::Init(); } } - DEFER { GlobalStates::Shutdown(); }; + DEFER + { + GlobalStates::Shutdown(); + }; UIState::Init(); - DEFER { UIState::Shutdown(); }; + DEFER + { + UIState::Shutdown(); + }; // Main loop backend->RunUntilWindowClose(&UI::MainWindow); |