diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 8e3dd8554..7aa502e3d 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -41,6 +41,7 @@ set(SRC ${SRCROOT}/VideoModeImpl.hpp ${SRCROOT}/Vulkan.cpp ${INCROOT}/Vulkan.hpp + ${SRCROOT}/VulkanImpl.hpp ${SRCROOT}/Window.cpp ${INCROOT}/Window.hpp ${SRCROOT}/WindowBase.cpp @@ -66,7 +67,6 @@ if(SFML_OS_WINDOWS) ${SRCROOT}/Win32/SensorImpl.cpp ${SRCROOT}/Win32/VideoModeImpl.cpp ${SRCROOT}/Win32/VulkanImplWin32.cpp - ${SRCROOT}/Win32/VulkanImplWin32.hpp ${SRCROOT}/Win32/WindowImplWin32.cpp ${SRCROOT}/Win32/WindowImplWin32.hpp ) @@ -123,7 +123,6 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD) ${SRCROOT}/Unix/Utils.hpp ${SRCROOT}/Unix/VideoModeImpl.cpp ${SRCROOT}/Unix/VulkanImplX11.cpp - ${SRCROOT}/Unix/VulkanImplX11.hpp ${SRCROOT}/Unix/WindowImplX11.cpp ${SRCROOT}/Unix/WindowImplX11.hpp ) diff --git a/src/SFML/Window/Unix/VulkanImplX11.cpp b/src/SFML/Window/Unix/VulkanImplX11.cpp index fd67e2d66..a82107b6c 100644 --- a/src/SFML/Window/Unix/VulkanImplX11.cpp +++ b/src/SFML/Window/Unix/VulkanImplX11.cpp @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include @@ -106,7 +106,7 @@ VulkanLibraryWrapper wrapper; namespace sf::priv { //////////////////////////////////////////////////////////// -bool VulkanImplX11::isAvailable(bool requireGraphics) +bool VulkanImpl::isAvailable(bool requireGraphics) { static bool checked = false; static bool computeAvailable = false; @@ -164,7 +164,7 @@ bool VulkanImplX11::isAvailable(bool requireGraphics) //////////////////////////////////////////////////////////// -VulkanFunctionPointer VulkanImplX11::getFunction(const char* name) +VulkanFunctionPointer VulkanImpl::getFunction(const char* name) { if (!isAvailable(false)) return nullptr; @@ -174,7 +174,7 @@ VulkanFunctionPointer VulkanImplX11::getFunction(const char* name) //////////////////////////////////////////////////////////// -const std::vector& VulkanImplX11::getGraphicsRequiredInstanceExtensions() +const std::vector& VulkanImpl::getGraphicsRequiredInstanceExtensions() { static const std::vector extensions{VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}; return extensions; @@ -182,10 +182,10 @@ const std::vector& VulkanImplX11::getGraphicsRequiredInstanceExtens //////////////////////////////////////////////////////////// -bool VulkanImplX11::createVulkanSurface(const VkInstance& instance, - WindowHandle windowHandle, - VkSurfaceKHR& surface, - const VkAllocationCallbacks* allocator) +bool VulkanImpl::createVulkanSurface(const VkInstance& instance, + WindowHandle windowHandle, + VkSurfaceKHR& surface, + const VkAllocationCallbacks* allocator) { if (!isAvailable()) return false; diff --git a/src/SFML/Window/Unix/VulkanImplX11.hpp b/src/SFML/Window/Unix/VulkanImplX11.hpp deleted file mode 100644 index dd2b685dd..000000000 --- a/src/SFML/Window/Unix/VulkanImplX11.hpp +++ /dev/null @@ -1,98 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#pragma once - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - -#include - - -namespace sf::priv -{ -//////////////////////////////////////////////////////////// -/// \brief Linux (X11) implementation of Vulkan -/// -//////////////////////////////////////////////////////////// -class VulkanImplX11 -{ -public: - //////////////////////////////////////////////////////////// - /// \brief Tell whether or not the system supports Vulkan - /// - /// This function should always be called before using - /// the Vulkan features. If it returns false, then - /// any attempt to use Vulkan will fail. - /// - /// If only compute is required, set \a requireGraphics - /// to false to skip checking for the extensions necessary - /// for graphics rendering. - /// - /// \param requireGraphics - /// - /// \return True if Vulkan is supported, false otherwise - /// - //////////////////////////////////////////////////////////// - static bool isAvailable(bool requireGraphics = true); - - //////////////////////////////////////////////////////////// - /// \brief Get the address of a Vulkan function - /// - /// \param name Name of the function to get the address of - /// - /// \return Address of the Vulkan function, 0 on failure - /// - //////////////////////////////////////////////////////////// - static VulkanFunctionPointer getFunction(const char* name); - - //////////////////////////////////////////////////////////// - /// \brief Get Vulkan instance extensions required for graphics - /// - /// \return Vulkan instance extensions required for graphics - /// - //////////////////////////////////////////////////////////// - static const std::vector& getGraphicsRequiredInstanceExtensions(); - - //////////////////////////////////////////////////////////// - /// \brief Create a Vulkan rendering surface - /// - /// \param instance Vulkan instance - /// \param windowHandle Handle to the window to create the surface for - /// \param surface Created surface - /// \param allocator Allocator to use - /// - /// \return True if surface creation was successful, false otherwise - /// - //////////////////////////////////////////////////////////// - static bool createVulkanSurface(const VkInstance& instance, - WindowHandle windowHandle, - VkSurfaceKHR& surface, - const VkAllocationCallbacks* allocator); -}; - -} // namespace sf::priv diff --git a/src/SFML/Window/Vulkan.cpp b/src/SFML/Window/Vulkan.cpp index 61f0c5fe7..57b1af3e7 100644 --- a/src/SFML/Window/Vulkan.cpp +++ b/src/SFML/Window/Vulkan.cpp @@ -31,8 +31,7 @@ #if defined(SFML_SYSTEM_WINDOWS) -#include -using VulkanImplType = sf::priv::VulkanImplWin32; +#include #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) || defined(SFML_SYSTEM_OPENBSD) || \ defined(SFML_SYSTEM_NETBSD) @@ -43,8 +42,7 @@ using VulkanImplType = sf::priv::VulkanImplWin32; #else -#include -using VulkanImplType = sf::priv::VulkanImplX11; +#include #endif @@ -66,7 +64,7 @@ bool Vulkan::isAvailable([[maybe_unused]] bool requireGraphics) #else - return VulkanImplType::isAvailable(requireGraphics); + return priv::VulkanImpl::isAvailable(requireGraphics); #endif } @@ -83,7 +81,7 @@ VulkanFunctionPointer Vulkan::getFunction([[maybe_unused]] const char* name) #else - return VulkanImplType::getFunction(name); + return priv::VulkanImpl::getFunction(name); #endif } @@ -100,7 +98,7 @@ const std::vector& Vulkan::getGraphicsRequiredInstanceExtensions() #else - return VulkanImplType::getGraphicsRequiredInstanceExtensions(); + return priv::VulkanImpl::getGraphicsRequiredInstanceExtensions(); #endif } diff --git a/src/SFML/Window/VulkanImpl.hpp b/src/SFML/Window/VulkanImpl.hpp new file mode 100644 index 000000000..48ab85c83 --- /dev/null +++ b/src/SFML/Window/VulkanImpl.hpp @@ -0,0 +1,90 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#pragma once + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + +#include + + +namespace sf::priv::VulkanImpl +{ +//////////////////////////////////////////////////////////// +/// \brief Tell whether or not the system supports Vulkan +/// +/// This function should always be called before using +/// the Vulkan features. If it returns false, then +/// any attempt to use Vulkan will fail. +/// +/// If only compute is required, set \a requireGraphics +/// to false to skip checking for the extensions necessary +/// for graphics rendering. +/// +/// \param requireGraphics +/// +/// \return True if Vulkan is supported, false otherwise +/// +//////////////////////////////////////////////////////////// +[[nodiscard]] bool isAvailable(bool requireGraphics = true); + +//////////////////////////////////////////////////////////// +/// \brief Get the address of a Vulkan function +/// +/// \param name Name of the function to get the address of +/// +/// \return Address of the Vulkan function, nullptr on failure +/// +//////////////////////////////////////////////////////////// +[[nodiscard]] VulkanFunctionPointer getFunction(const char* name); + +//////////////////////////////////////////////////////////// +/// \brief Get Vulkan instance extensions required for graphics +/// +/// \return Vulkan instance extensions required for graphics +/// +//////////////////////////////////////////////////////////// +[[nodiscard]] const std::vector& getGraphicsRequiredInstanceExtensions(); + +//////////////////////////////////////////////////////////// +/// \brief Create a Vulkan rendering surface +/// +/// \param instance Vulkan instance +/// \param windowHandle Handle to the window to create the surface for +/// \param surface Created surface +/// \param allocator Allocator to use +/// +/// \return True if surface creation was successful, false otherwise +/// +//////////////////////////////////////////////////////////// +[[nodiscard]] bool createVulkanSurface(const VkInstance& instance, + WindowHandle windowHandle, + VkSurfaceKHR& surface, + const VkAllocationCallbacks* allocator); + +} // namespace sf::priv::VulkanImpl diff --git a/src/SFML/Window/Win32/VulkanImplWin32.cpp b/src/SFML/Window/Win32/VulkanImplWin32.cpp index ec16d7dcf..1804bbd48 100644 --- a/src/SFML/Window/Win32/VulkanImplWin32.cpp +++ b/src/SFML/Window/Win32/VulkanImplWin32.cpp @@ -25,7 +25,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include +#include #include @@ -105,7 +105,7 @@ VulkanLibraryWrapper wrapper; namespace sf::priv { //////////////////////////////////////////////////////////// -bool VulkanImplWin32::isAvailable(bool requireGraphics) +bool VulkanImpl::isAvailable(bool requireGraphics) { static bool checked = false; static bool computeAvailable = false; @@ -163,7 +163,7 @@ bool VulkanImplWin32::isAvailable(bool requireGraphics) //////////////////////////////////////////////////////////// -VulkanFunctionPointer VulkanImplWin32::getFunction(const char* name) +VulkanFunctionPointer VulkanImpl::getFunction(const char* name) { if (!isAvailable(false)) return nullptr; @@ -173,7 +173,7 @@ VulkanFunctionPointer VulkanImplWin32::getFunction(const char* name) //////////////////////////////////////////////////////////// -const std::vector& VulkanImplWin32::getGraphicsRequiredInstanceExtensions() +const std::vector& VulkanImpl::getGraphicsRequiredInstanceExtensions() { static const std::vector extensions{VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}; return extensions; @@ -181,10 +181,10 @@ const std::vector& VulkanImplWin32::getGraphicsRequiredInstanceExte //////////////////////////////////////////////////////////// -bool VulkanImplWin32::createVulkanSurface(const VkInstance& instance, - WindowHandle windowHandle, - VkSurfaceKHR& surface, - const VkAllocationCallbacks* allocator) +bool VulkanImpl::createVulkanSurface(const VkInstance& instance, + WindowHandle windowHandle, + VkSurfaceKHR& surface, + const VkAllocationCallbacks* allocator) { if (!isAvailable()) return false; diff --git a/src/SFML/Window/Win32/VulkanImplWin32.hpp b/src/SFML/Window/Win32/VulkanImplWin32.hpp deleted file mode 100644 index 6084f0113..000000000 --- a/src/SFML/Window/Win32/VulkanImplWin32.hpp +++ /dev/null @@ -1,98 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#pragma once - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - -#include - - -namespace sf::priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of Vulkan -/// -//////////////////////////////////////////////////////////// -class VulkanImplWin32 -{ -public: - //////////////////////////////////////////////////////////// - /// \brief Tell whether or not the system supports Vulkan - /// - /// This function should always be called before using - /// the Vulkan features. If it returns false, then - /// any attempt to use Vulkan will fail. - /// - /// If only compute is required, set \a requireGraphics - /// to false to skip checking for the extensions necessary - /// for graphics rendering. - /// - /// \param requireGraphics - /// - /// \return True if Vulkan is supported, false otherwise - /// - //////////////////////////////////////////////////////////// - static bool isAvailable(bool requireGraphics = true); - - //////////////////////////////////////////////////////////// - /// \brief Get the address of a Vulkan function - /// - /// \param name Name of the function to get the address of - /// - /// \return Address of the Vulkan function, 0 on failure - /// - //////////////////////////////////////////////////////////// - static VulkanFunctionPointer getFunction(const char* name); - - //////////////////////////////////////////////////////////// - /// \brief Get Vulkan instance extensions required for graphics - /// - /// \return Vulkan instance extensions required for graphics - /// - //////////////////////////////////////////////////////////// - static const std::vector& getGraphicsRequiredInstanceExtensions(); - - //////////////////////////////////////////////////////////// - /// \brief Create a Vulkan rendering surface - /// - /// \param instance Vulkan instance - /// \param windowHandle Handle to the window to create the surface for - /// \param surface Created surface - /// \param allocator Allocator to use - /// - /// \return True if surface creation was successful, false otherwise - /// - //////////////////////////////////////////////////////////// - static bool createVulkanSurface(const VkInstance& instance, - WindowHandle windowHandle, - VkSurfaceKHR& surface, - const VkAllocationCallbacks* allocator); -}; - -} // namespace sf::priv diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index c903a7f87..007a059d5 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -44,8 +44,7 @@ #include using WindowImplType = sf::priv::WindowImplWin32; -#include -using VulkanImplType = sf::priv::VulkanImplWin32; +#include #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) || defined(SFML_SYSTEM_OPENBSD) || \ defined(SFML_SYSTEM_NETBSD) @@ -62,8 +61,7 @@ using WindowImplType = sf::priv::WindowImplDRM; #include using WindowImplType = sf::priv::WindowImplX11; -#include -using VulkanImplType = sf::priv::VulkanImplX11; +#include #endif @@ -324,7 +322,7 @@ bool WindowImpl::createVulkanSurface([[maybe_unused]] const VkInstance& #else - return VulkanImplType::createVulkanSurface(instance, getNativeHandle(), surface, allocator); + return VulkanImpl::createVulkanSurface(instance, getNativeHandle(), surface, allocator); #endif }