From c2993ae56c86b5d0c7c41e6b69cb57306e0a2296 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 12 Dec 2024 23:28:12 +0100 Subject: [PATCH] Update window api, add content scale for glfw window --- openVulkanoCpp/Base/UI/IWindow.hpp | 30 +++++++++++++------------ openVulkanoCpp/Host/GLFW/WindowGLFW.cpp | 7 +++++- openVulkanoCpp/Host/GLFW/WindowGLFW.hpp | 26 +++++++++++---------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/openVulkanoCpp/Base/UI/IWindow.hpp b/openVulkanoCpp/Base/UI/IWindow.hpp index aee6a6e..876cd19 100644 --- a/openVulkanoCpp/Base/UI/IWindow.hpp +++ b/openVulkanoCpp/Base/UI/IWindow.hpp @@ -32,12 +32,14 @@ namespace OpenVulkano Math::Vector2i position{0, 0}; std::string title = "Window Title"; WindowMode windowMode = WINDOWED; + bool transparentFrameBuffer = false; + bool resizeable = true; }; class IWindow : public ICloseable { public: - virtual ~IWindow() = default; + ~IWindow() override = default; virtual void Init(RenderAPI::RenderApi renderApi) = 0; @@ -48,22 +50,22 @@ namespace OpenVulkano virtual const std::string& GetTitle() = 0; virtual void SetTitle(const std::string& title) = 0; - virtual WindowMode GetWindowMode() = 0; + [[nodiscard]] virtual WindowMode GetWindowMode() = 0; virtual void SetWindowMode(WindowMode) = 0; - inline void SetFullscreen() { SetWindowMode(FULLSCREEN); } - inline void SetWindowed() { SetWindowMode(WINDOWED); } + void SetFullscreen() { SetWindowMode(FULLSCREEN); } + void SetWindowed() { SetWindowMode(WINDOWED); } - virtual const WindowConfiguration& GetWindowConfiguration() = 0; - inline uint32_t GetWidth() { return GetSize().x; } - inline uint32_t GetHeight() { return GetSize().y; } - virtual Math::Vector2ui GetSize() = 0; + [[nodiscard]] virtual const WindowConfiguration& GetWindowConfiguration() = 0; + [[nodiscard]] uint32_t GetWidth() { return GetSize().x; } + [[nodiscard]] uint32_t GetHeight() { return GetSize().y; } + [[nodiscard]] virtual Math::Vector2ui GetSize() = 0; virtual void SetSize(uint32_t width, uint32_t height) = 0; - inline void SetSize(Math::Vector2ui size) { SetSize(size.x, size.y); } + void SetSize(const Math::Vector2ui& size) { SetSize(size.x, size.y); } virtual void SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) = 0; - virtual Math::Vector2i GetPosition() = 0; + [[nodiscard]] virtual Math::Vector2i GetPosition() = 0; virtual void SetPosition(int posX, int posY) = 0; - inline void SetPosition(Math::Vector2i pos) { SetPosition(pos.x, pos.y); }; + void SetPosition(Math::Vector2i pos) { SetPosition(pos.x, pos.y); }; virtual void SetMouseVisibility(bool hideMouse) {}; @@ -71,15 +73,15 @@ namespace OpenVulkano virtual void Hide() = 0; virtual void Show(bool show) = 0; - virtual IWindowHandler* GetWindowHandler() = 0; + [[nodiscard]] virtual IWindowHandler* GetWindowHandler() = 0; virtual void SetWindowHandler(IWindowHandler* handler) = 0; /** * \brief Gets the vulkan window implementation of the window. * \return The IVulkanWindow reference of the window. nullptr if the current Window dose not implement IVulkanWindow */ - virtual IVulkanWindow* GetVulkanWindow() = 0; - virtual IOpenGlWindow* GetOpenGlWindow() = 0; + [[nodiscard]] virtual IVulkanWindow* GetVulkanWindow() = 0; + [[nodiscard]] virtual IOpenGlWindow* GetOpenGlWindow() = 0; [[nodiscard]] virtual uint32_t GetWindowId() const = 0; diff --git a/openVulkanoCpp/Host/GLFW/WindowGLFW.cpp b/openVulkanoCpp/Host/GLFW/WindowGLFW.cpp index a4e3cd9..f775a78 100644 --- a/openVulkanoCpp/Host/GLFW/WindowGLFW.cpp +++ b/openVulkanoCpp/Host/GLFW/WindowGLFW.cpp @@ -52,10 +52,15 @@ namespace OpenVulkano::GLFW void WindowGLFW::Create() { + glfwWindowHint(GLFW_RESIZABLE, windowConfig.resizeable); glfwWindowHint(GLFW_DECORATED, (~windowConfig.windowMode) & 1); + glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, windowConfig.transparentFrameBuffer); //TODO handle full screen resolutions window = glfwCreateWindow(windowConfig.size.x, windowConfig.size.y, windowConfig.title.c_str(), GetTargetMonitor(), nullptr); if (!window) return; + float scaleX, scaleY; + glfwGetWindowContentScale(window, &scaleX, &scaleY); + contentScale = std::max(scaleX, scaleY); glfwSetWindowUserPointer(window, this); RegisterCallbacks(); } @@ -114,7 +119,7 @@ namespace OpenVulkano::GLFW throw WindowInitFailedException("Failed to initialize window"); } if (renderApi != RenderAPI::Vulkan) MakeCurrentThread(); - Logger::WINDOW->info("GLFW Window created (id: {0})", GetWindowId()); + Logger::WINDOW->info("GLFW Window created (id: {0}) with scale {}", GetWindowId(), contentScale); } void WindowGLFW::Close() diff --git a/openVulkanoCpp/Host/GLFW/WindowGLFW.hpp b/openVulkanoCpp/Host/GLFW/WindowGLFW.hpp index fc6844f..f7876ed 100644 --- a/openVulkanoCpp/Host/GLFW/WindowGLFW.hpp +++ b/openVulkanoCpp/Host/GLFW/WindowGLFW.hpp @@ -19,11 +19,11 @@ namespace OpenVulkano::GLFW { class WindowGLFW final : virtual public BaseWindow, virtual public IVulkanWindow, virtual public IOpenGlWindow { - private: InputProviderGLFW& inputProvider; GLFWwindow* window = nullptr; IWindowHandler* handler = nullptr; Math::Vector2ui currentSize = {}; + float contentScale = 1.0f; public: WindowGLFW(InputProviderGLFW& inputProvider); @@ -39,9 +39,9 @@ namespace OpenVulkano::GLFW void RegisterCallbacks() const; - static GLFWmonitor* GetPrimaryMonitor(); + [[nodiscard]] static GLFWmonitor* GetPrimaryMonitor(); - static std::vector GetMonitors(); + [[nodiscard]] static std::vector GetMonitors(); public: // IWindow implementation void Init(RenderAPI::RenderApi renderApi) override; @@ -64,27 +64,29 @@ namespace OpenVulkano::GLFW void SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) override; + [[nodiscard]] float GetContentScale() const override { return contentScale; } + void MakeCurrentThread() override; void SetWindowMode(WindowMode windowMode) override; void SetWindowHandler(IWindowHandler* handler) override; - IVulkanWindow* GetVulkanWindow() override { return this; }; + [[nodiscard]] IVulkanWindow* GetVulkanWindow() override { return this; }; - IOpenGlWindow* GetOpenGlWindow() override { return this; }; + [[nodiscard]] IOpenGlWindow* GetOpenGlWindow() override { return this; }; // Status getter - Math::Vector2ui GetSize() override; + [[nodiscard]] Math::Vector2ui GetSize() override; - Math::Vector2i GetPosition() override; + [[nodiscard]] Math::Vector2i GetPosition() override; - IWindowHandler* GetWindowHandler() override { return handler; } + [[nodiscard]] IWindowHandler* GetWindowHandler() override { return handler; } //IVulkanWindow stuff - vk::SurfaceKHR CreateSurface(const vk::Instance& instance, const vk::AllocationCallbacks* pAllocator) override; + [[nodiscard]] vk::SurfaceKHR CreateSurface(const vk::Instance& instance, const vk::AllocationCallbacks* pAllocator) override; - std::vector GetRequiredInstanceExtensions() override; + [[nodiscard]] std::vector GetRequiredInstanceExtensions() override; void* GetNativeWindowHandle() override { return window; } @@ -104,7 +106,7 @@ namespace OpenVulkano::GLFW void OnClose(); protected: - virtual void OnKeyEvent(int key, int scanCode, int action, int mods); + void OnKeyEvent(int key, int scanCode, int action, int mods); private: // Callbacks static WindowGLFW* GetWindow(GLFWwindow* window); @@ -134,6 +136,6 @@ namespace OpenVulkano::GLFW static void DropCallback(GLFWwindow* window, int count, const char** paths); public: - static std::vector GetVulkanRequiredInstanceExtensions(); + [[nodiscard]] static std::vector GetVulkanRequiredInstanceExtensions(); }; }