Refactor platform enums
This commit is contained in:
@@ -6,50 +6,108 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
namespace RenderAPI
|
||||
class RenderAPI
|
||||
{
|
||||
public:
|
||||
enum RenderApi
|
||||
{
|
||||
VULKAN = 0,
|
||||
Vulkan = 0,
|
||||
//OpenGL,
|
||||
//DirectX11,
|
||||
//DirectX12,
|
||||
//Metal,
|
||||
MAX_VALUE
|
||||
};
|
||||
|
||||
inline std::string ToString(RenderApi api)
|
||||
{
|
||||
switch (api)
|
||||
{
|
||||
case VULKAN: return "Vulkan";
|
||||
}
|
||||
return "Invalid";
|
||||
}
|
||||
}
|
||||
constexpr RenderAPI(RenderApi api) : api(api) {}
|
||||
|
||||
namespace Platform
|
||||
[[nodiscard]] constexpr std::string_view ToString() const
|
||||
{
|
||||
return magic_enum::enum_name(api);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr static RenderAPI GetFromName(std::string_view name)
|
||||
{
|
||||
return magic_enum::enum_cast<RenderApi>(name).value_or(Vulkan);
|
||||
}
|
||||
|
||||
constexpr operator std::string_view() const { return ToString(); }
|
||||
|
||||
constexpr operator RenderApi() const { return api; }
|
||||
|
||||
constexpr bool operator==(const RenderAPI other)
|
||||
{
|
||||
return other.api == api;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const RenderApi other)
|
||||
{
|
||||
return other == api;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const RenderAPI other)
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const RenderApi other)
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
RenderApi api;
|
||||
};
|
||||
|
||||
class Platform
|
||||
{
|
||||
enum Platform
|
||||
public:
|
||||
enum OS
|
||||
{
|
||||
Windows = 0, MacOS, Linux, Android, iOS, MAX_VALUE
|
||||
Windows = 0, MacOS, Linux, Android, iOS, Unknown
|
||||
};
|
||||
|
||||
inline std::string ToString(Platform os)
|
||||
constexpr Platform(OS os) : os(os) {}
|
||||
|
||||
[[nodiscard]] constexpr std::string_view ToString() const
|
||||
{
|
||||
switch (os)
|
||||
{
|
||||
case Windows: return "Windows";
|
||||
case MacOS: return "MacOS";
|
||||
case Linux: return "Linux";
|
||||
case Android: return "Android";
|
||||
case iOS: return "iOS";
|
||||
}
|
||||
return "Invalid";
|
||||
return magic_enum::enum_name(os);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr static Platform GetFromName(std::string_view name)
|
||||
{
|
||||
return magic_enum::enum_cast<OS>(name).value_or(Unknown);
|
||||
}
|
||||
|
||||
constexpr operator std::string_view() const { return ToString(); }
|
||||
|
||||
constexpr operator OS() const { return os; }
|
||||
|
||||
constexpr bool operator==(const Platform other)
|
||||
{
|
||||
return other.os == os;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const OS other)
|
||||
{
|
||||
return other == os;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const Platform other)
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const OS other)
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
OS os;
|
||||
};
|
||||
}
|
||||
@@ -99,13 +99,13 @@ namespace openVulkanoCpp::GLFW
|
||||
|
||||
void WindowGLFW::Init(RenderAPI::RenderApi renderApi)
|
||||
{
|
||||
if (renderApi == RenderAPI::VULKAN) glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
if (renderApi == RenderAPI::Vulkan) glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
Create();
|
||||
if (!window)
|
||||
{
|
||||
throw WindowInitFailedException("Failed to initialize window");
|
||||
}
|
||||
if (renderApi != RenderAPI::VULKAN) MakeCurrentThread();
|
||||
if (renderApi != RenderAPI::Vulkan) MakeCurrentThread();
|
||||
Logger::WINDOW->info("GLFW Window created (id: {0})", GetWindowId());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace openVulkanoCpp
|
||||
GraphicsAppManager::GraphicsAppManager(openVulkanoCpp::IGraphicsApp* app, RenderAPI::RenderApi renderApi)
|
||||
: app(app), renderApi(renderApi)
|
||||
{
|
||||
if (renderApi >= RenderAPI::MAX_VALUE) throw std::runtime_error("Invalid RenderAPI");
|
||||
Logger::SetupLogger();
|
||||
if (!app)
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace openVulkanoCpp
|
||||
std::string windowTitleFormat;
|
||||
|
||||
public:
|
||||
explicit GraphicsAppManager(IGraphicsApp* app, RenderAPI::RenderApi renderApi = RenderAPI::VULKAN);
|
||||
explicit GraphicsAppManager(IGraphicsApp* app, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||
|
||||
~GraphicsAppManager() noexcept override;
|
||||
|
||||
|
||||
@@ -12,24 +12,24 @@
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
IRenderer* PlatformProducer::CreateRenderManager(RenderAPI::RenderApi renderApi)
|
||||
IRenderer* PlatformProducer::CreateRenderManager(RenderAPI renderApi)
|
||||
{
|
||||
switch (renderApi)
|
||||
{
|
||||
case RenderAPI::VULKAN: return new Vulkan::Renderer();
|
||||
case RenderAPI::Vulkan: return new Vulkan::Renderer();
|
||||
default:
|
||||
Logger::RENDER->error("Unsupported render api requested! Requested %d", static_cast<int>(renderApi));
|
||||
Logger::RENDER->error("Unsupported render api requested! Requested {}", renderApi.ToString());
|
||||
throw std::runtime_error("Unsupported render api requested!");
|
||||
}
|
||||
}
|
||||
|
||||
IPlatform* PlatformProducer::CreatePlatform(RenderAPI::RenderApi renderApi)
|
||||
IPlatform* PlatformProducer::CreatePlatform(RenderAPI renderApi)
|
||||
{
|
||||
switch (renderApi)
|
||||
{
|
||||
case RenderAPI::VULKAN: return new GLFW::PlatformGLFW();
|
||||
case RenderAPI::Vulkan: return new GLFW::PlatformGLFW();
|
||||
default:
|
||||
Logger::MANAGER->error("Unsupported render api requested! Requested %d", static_cast<int>(renderApi));
|
||||
Logger::MANAGER->error("Unsupported render api requested! Requested {}", renderApi.ToString());
|
||||
throw std::runtime_error("Unsupported render api requested!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace openVulkanoCpp
|
||||
* \return The created Renderer.
|
||||
* \throws std::runtime_error if the render api is not supported
|
||||
*/
|
||||
static IRenderer* CreateRenderManager(RenderAPI::RenderApi renderApi);
|
||||
static IRenderer* CreateRenderManager(RenderAPI renderApi);
|
||||
|
||||
/**
|
||||
* \brief Creates a platform that fits best for the current environment
|
||||
@@ -34,6 +34,6 @@ namespace openVulkanoCpp
|
||||
* \return The created platform
|
||||
* \throws std::runtime_error if the render api is not supported
|
||||
*/
|
||||
static IPlatform* CreatePlatform(RenderAPI::RenderApi renderApi);
|
||||
static IPlatform* CreatePlatform(RenderAPI renderApi);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user