Rename SystemDriver to WindowDriver and removed LinuxSystemDriver

Hopefully the last time I change my mind on what I want these to be
called. Reason behind this change is to minimize scope of a single
module. The WindowDriver should really only handle stuff related to
windows. If we need OS level functionality (e.g. get_os_name), that
should be the responsibility of the OS driver (or whatever that ends
being called). Remember, composition over inheritance.
This commit is contained in:
2025-04-03 04:47:22 +10:00
parent 595f8a26de
commit 5e7c94ba8f
12 changed files with 49 additions and 124 deletions

View File

@@ -22,11 +22,10 @@ endif ()
set(ENGINE_SRC set(ENGINE_SRC
core/debug.cpp core/debug.cpp
drivers/dx12/render_driver.cpp drivers/dx12/render_driver.cpp
drivers/linux/system_driver.cpp
drivers/linux/wayland/system_driver.cpp
drivers/linux/x11/system_driver.cpp
drivers/windows/system_driver.cpp
drivers/vulkan/render_driver.cpp drivers/vulkan/render_driver.cpp
drivers/wayland/window_driver.cpp
drivers/win32/window_driver.cpp
drivers/x11/window_driver.cpp
platform/system.cpp platform/system.cpp
render/renderer.cpp render/renderer.cpp
render/render_device.cpp render/render_device.cpp
@@ -42,18 +41,9 @@ FetchContent_Declare(
) )
FetchContent_MakeAvailable(spdlog) FetchContent_MakeAvailable(spdlog)
FetchContent_Declare(
SDL3
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG 22422f7748d5128135995ed34c8f8012861c7332 # preview-3.1.8
FIND_PACKAGE_ARGS NAMES SDL3
)
FetchContent_MakeAvailable(SDL3)
set(ENGINE_INCLUDES_PRIVATE set(ENGINE_INCLUDES_PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src
$<$<BOOL:${NOVA_VULKAN}>:${Vulkan_INCLUDE_DIRS}> $<$<BOOL:${NOVA_VULKAN}>:${Vulkan_INCLUDE_DIRS}>
${SDL3_INCLUDE_DIRS}
) )
set(ENGINE_INCLUDES_PUBLIC set(ENGINE_INCLUDES_PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
@@ -61,7 +51,6 @@ set(ENGINE_INCLUDES_PUBLIC
) )
set(ENGINE_LIBS_PRIVATE set(ENGINE_LIBS_PRIVATE
$<$<BOOL:${NOVA_VULKAN}>:Vulkan::Vulkan> $<$<BOOL:${NOVA_VULKAN}>:Vulkan::Vulkan>
SDL3::SDL3
) )
set(ENGINE_LIBS_PUBLIC set(ENGINE_LIBS_PUBLIC
spdlog::spdlog spdlog::spdlog

View File

@@ -7,13 +7,13 @@
#pragma once #pragma once
#include <nova/api.h> #include <nova/api.h>
#include <nova/platform/system_driver.h> #include <nova/platform/window_driver.h>
namespace Nova { namespace Nova {
class NOVA_API System { class NOVA_API System {
public: public:
static void init(); static void init();
static void shutdown(); static void shutdown();
static SystemDriver* get_driver(); static WindowDriver* get_driver();
}; };
} // namespace Nova } // namespace Nova

View File

@@ -9,9 +9,9 @@
#include <nova/api.h> #include <nova/api.h>
namespace Nova { namespace Nova {
class NOVA_API SystemDriver { class NOVA_API WindowDriver {
public: public:
virtual ~SystemDriver() = default; virtual ~WindowDriver() = default;
[[nodiscard]] virtual const char* get_surface_extension() const = 0; [[nodiscard]] virtual const char* get_surface_extension() const = 0;
}; };

View File

@@ -1,49 +0,0 @@
/**
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifdef NOVA_LINUX
#include "drivers/linux/system_driver.h"
#include "drivers/linux/wayland/system_driver.h" // IWYU pragma: keep
#include "drivers/linux/x11/system_driver.h" // IWYU pragma: keep
#include <nova/core/debug.h>
using namespace Nova;
LinuxSystemDriver::LinuxSystemDriver() {
NOVA_AUTO_TRACE();
}
LinuxSystemDriver::~LinuxSystemDriver() {
NOVA_AUTO_TRACE();
}
const char* LinuxSystemDriver::get_surface_extension() const {
NOVA_WARN("System driver does not support surfaces");
return nullptr;
}
std::unique_ptr<SystemDriver> LinuxSystemDriver::get_default_driver() {
NOVA_AUTO_TRACE();
#ifdef NOVA_WAYLAND
if (std::getenv("WAYLAND_DISPLAY")) {
return std::make_unique<WaylandSystemDriver>();
}
#endif
#ifdef NOVA_X11
if (std::getenv("DISPLAY")) {
return std::make_unique<X11SystemDriver>();
}
#endif
NOVA_WARN("Unsupported display server");
return std::make_unique<LinuxSystemDriver>();
}
#endif // NOVA_LINUX

View File

@@ -1,27 +0,0 @@
/**
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once
#ifdef NOVA_LINUX
#include <nova/platform/system_driver.h>
#include <memory>
namespace Nova {
class LinuxSystemDriver : public SystemDriver {
public:
LinuxSystemDriver();
~LinuxSystemDriver() override;
[[nodiscard]] const char* get_surface_extension() const override;
static std::unique_ptr<SystemDriver> get_default_driver();
};
} // namespace Nova
#endif // NOVA_LINUX

View File

@@ -6,7 +6,7 @@
#ifdef NOVA_WAYLAND #ifdef NOVA_WAYLAND
#include "drivers/linux/wayland/system_driver.h" #include "drivers/wayland/window_driver.h"
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
@@ -17,15 +17,15 @@
using namespace Nova; using namespace Nova;
WaylandSystemDriver::WaylandSystemDriver() { WaylandWindowDriver::WaylandWindowDriver() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
} }
WaylandSystemDriver::~WaylandSystemDriver() { WaylandWindowDriver::~WaylandWindowDriver() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
} }
const char* WaylandSystemDriver::get_surface_extension() const { const char* WaylandWindowDriver::get_surface_extension() const {
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME; return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
#else #else

View File

@@ -8,13 +8,13 @@
#ifdef NOVA_WAYLAND #ifdef NOVA_WAYLAND
#include "drivers/linux/system_driver.h" #include <nova/platform/window_driver.h>
namespace Nova { namespace Nova {
class WaylandSystemDriver final : public LinuxSystemDriver { class WaylandWindowDriver final : public WindowDriver {
public: public:
WaylandSystemDriver(); WaylandWindowDriver();
~WaylandSystemDriver() override; ~WaylandWindowDriver() override;
[[nodiscard]] const char* get_surface_extension() const override; [[nodiscard]] const char* get_surface_extension() const override;
}; };

View File

@@ -6,7 +6,7 @@
#ifdef NOVA_WINDOWS #ifdef NOVA_WINDOWS
#include "drivers/windows/system_driver.h" #include "drivers/win32/window_driver.h"
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
@@ -17,15 +17,15 @@
using namespace Nova; using namespace Nova;
WindowsSystemDriver::WindowsSystemDriver() { Win32WindowDriver::Win32WindowDriver() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
} }
WindowsSystemDriver::~WindowsSystemDriver() { Win32WindowDriver::~Win32WindowDriver() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
} }
const char* WindowsSystemDriver::get_surface_extension() const { const char* Win32WindowDriver::get_surface_extension() const {
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
return VK_KHR_WIN32_SURFACE_EXTENSION_NAME; return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
#else #else

View File

@@ -8,14 +8,14 @@
#ifdef NOVA_WINDOWS #ifdef NOVA_WINDOWS
#include <nova/platform/system_driver.h> #include <nova/platform/window_driver.h>
#include <windows.h> #include <windows.h>
namespace Nova { namespace Nova {
class WindowsSystemDriver final : public SystemDriver { class Win32WindowDriver final : public WindowDriver {
public: public:
WindowsSystemDriver(); Win32WindowDriver();
~WindowsSystemDriver() override; ~Win32WindowDriver() override;
[[nodiscard]] const char* get_surface_extension() const override; [[nodiscard]] const char* get_surface_extension() const override;
}; };

View File

@@ -6,7 +6,7 @@
#ifdef NOVA_X11 #ifdef NOVA_X11
#include "drivers/linux/x11/system_driver.h" #include "drivers/x11/window_driver.h"
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
@@ -17,15 +17,15 @@
using namespace Nova; using namespace Nova;
X11SystemDriver::X11SystemDriver() { X11WindowDriver::X11WindowDriver() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
} }
X11SystemDriver::~X11SystemDriver() { X11WindowDriver::~X11WindowDriver() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
} }
const char* X11SystemDriver::get_surface_extension() const { const char* X11WindowDriver::get_surface_extension() const {
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
return VK_KHR_XLIB_SURFACE_EXTENSION_NAME; return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
#else #else

View File

@@ -8,15 +8,14 @@
#ifdef NOVA_X11 #ifdef NOVA_X11
#include "drivers/linux/system_driver.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <nova/platform/window_driver.h>
namespace Nova { namespace Nova {
class X11SystemDriver final : public LinuxSystemDriver { class X11WindowDriver final : public WindowDriver {
public: public:
X11SystemDriver(); X11WindowDriver();
~X11SystemDriver() override; ~X11WindowDriver() override;
[[nodiscard]] const char* get_surface_extension() const override; [[nodiscard]] const char* get_surface_extension() const override;
}; };

View File

@@ -4,8 +4,9 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#include "drivers/linux/system_driver.h" // IWYU pragma: keep #include "drivers/wayland/window_driver.h" // IWYU pragma: keep
#include "drivers/windows/system_driver.h" // IWYU pragma: keep #include "drivers/win32/window_driver.h" // IWYU pragma: keep
#include "drivers/x11/window_driver.h" // IWYU pragma: keep
#include <nova/core/debug.h> #include <nova/core/debug.h>
#include <nova/platform/system.h> #include <nova/platform/system.h>
@@ -14,7 +15,7 @@
using namespace Nova; using namespace Nova;
static std::unique_ptr<SystemDriver> s_driver; static std::unique_ptr<WindowDriver> s_driver;
void System::init() { void System::init() {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
@@ -23,7 +24,19 @@ void System::init() {
#ifdef NOVA_WINDOWS #ifdef NOVA_WINDOWS
s_driver = std::make_unique<WindowsSystemDriver>(); s_driver = std::make_unique<WindowsSystemDriver>();
#elif NOVA_LINUX #elif NOVA_LINUX
s_driver = LinuxSystemDriver::get_default_driver(); #ifdef NOVA_WAYLAND
if (std::getenv("WAYLAND_DISPLAY")) {
s_driver = std::make_unique<WaylandWindowDriver>();
return;
}
#endif
#ifdef NOVA_X11
if (std::getenv("DISPLAY")) {
s_driver = std::make_unique<X11WindowDriver>();
return;
}
#endif
throw std::runtime_error("No suitable display server found");
#else #else
throw std::runtime_error("Unsupported platform"); throw std::runtime_error("Unsupported platform");
#endif #endif
@@ -34,7 +47,7 @@ void System::shutdown() {
s_driver.reset(); s_driver.reset();
} }
SystemDriver* System::get_driver() { WindowDriver* System::get_driver() {
NOVA_ASSERT(s_driver); NOVA_ASSERT(s_driver);
return s_driver.get(); return s_driver.get();
} }