Conditionally compile different drivers
This commit is contained in:
@@ -4,10 +4,17 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "drivers/linux/system_driver.h"
|
||||
#ifdef NOVA_WAYLAND
|
||||
#include "drivers/linux/wayland/system_driver.h"
|
||||
#endif
|
||||
#ifdef NOVA_X11
|
||||
#include "drivers/linux/x11/system_driver.h"
|
||||
#endif
|
||||
|
||||
#include <nova/core/debug.h>
|
||||
|
||||
#include "drivers/linux/system_driver.h"
|
||||
|
||||
using namespace Nova;
|
||||
|
||||
LinuxSystemDriver::LinuxSystemDriver() {
|
||||
@@ -17,3 +24,21 @@ LinuxSystemDriver::LinuxSystemDriver() {
|
||||
LinuxSystemDriver::~LinuxSystemDriver() {
|
||||
NOVA_AUTO_TRACE();
|
||||
}
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
@@ -8,10 +8,14 @@
|
||||
|
||||
#include <nova/platform/system_driver.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Nova {
|
||||
class LinuxSystemDriver : public SystemDriver {
|
||||
public:
|
||||
LinuxSystemDriver();
|
||||
~LinuxSystemDriver() override;
|
||||
|
||||
static std::unique_ptr<SystemDriver> get_default_driver();
|
||||
};
|
||||
} // namespace Nova
|
||||
|
||||
@@ -4,12 +4,17 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifdef NOVA_WINDOWS
|
||||
#include "drivers/windows/system_driver.h"
|
||||
#endif
|
||||
#ifdef NOVA_LINUX
|
||||
#include "drivers/linux/system_driver.h"
|
||||
#endif
|
||||
|
||||
#include <nova/core/debug.h>
|
||||
#include <nova/platform/system.h>
|
||||
|
||||
#include "drivers/linux/wayland/system_driver.h"
|
||||
#include "drivers/linux/x11/system_driver.h"
|
||||
#include "drivers/windows/system_driver.h"
|
||||
#include <memory>
|
||||
|
||||
using namespace Nova;
|
||||
|
||||
@@ -19,17 +24,12 @@ void System::init() {
|
||||
NOVA_AUTO_TRACE();
|
||||
NOVA_ASSERT(!s_driver);
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef NOVA_WINDOWS
|
||||
s_driver = std::make_unique<WindowsSystemDriver>();
|
||||
#elif NOVA_LINUX
|
||||
s_driver = LinuxSystemDriver::get_default_driver();
|
||||
#else
|
||||
if (std::getenv("WAYLAND_DISPLAY")) {
|
||||
s_driver = std::make_unique<WaylandSystemDriver>();
|
||||
} else if (std::getenv("DISPLAY")) {
|
||||
s_driver = std::make_unique<X11SystemDriver>();
|
||||
} else {
|
||||
NOVA_ERROR("Unsupported windowing system");
|
||||
s_driver = std::make_unique<LinuxSystemDriver>();
|
||||
}
|
||||
throw std::runtime_error("Unsupported platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifdef NOVA_VULKAN
|
||||
#include "drivers/vulkan/render_driver.h"
|
||||
#endif
|
||||
|
||||
#include <nova/core/debug.h>
|
||||
#include <nova/render/renderer.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "drivers/vulkan/render_driver.h"
|
||||
|
||||
using namespace Nova;
|
||||
|
||||
static std::unique_ptr<RenderDriver> s_driver;
|
||||
@@ -18,13 +20,15 @@ static std::unique_ptr<RenderDriver> s_driver;
|
||||
void Renderer::init(const RenderAPI api) {
|
||||
NOVA_AUTO_TRACE();
|
||||
NOVA_ASSERT(!s_driver);
|
||||
|
||||
switch (api) {
|
||||
#ifdef NOVA_VULKAN
|
||||
case RenderAPI::VULKAN:
|
||||
s_driver = std::make_unique<VulkanRenderDriver>();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
NOVA_ERROR("Unsupported render API");
|
||||
break;
|
||||
throw std::runtime_error("Unsupported render API");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user