Files
OpenVulkano/openVulkanoCpp/Host/PlatformProducer.hpp
2020-05-16 00:56:22 +02:00

53 lines
1.6 KiB
C++

#pragma once
#include <stdexcept>
#include "../Base/Logger.hpp"
#include "../Base/PlatformEnums.hpp"
#include "../Base/IPlatform.hpp"
#include "../Vulkan/Renderer.hpp"
#include "GLFW/PlatformGLFW.hpp"
namespace openVulkanoCpp
{
/**
* \brief Helper class the produces all the platform depending classes
*/
class PlatformProducer
{
public:
/**
* \brief Creates the renderer for the given render api
* \param renderApi The render api that should be used
* \return The created Renderer.
* \throws std::runtime_error if the render api is not supported
*/
static IRenderer* CreateRenderManager(RenderAPI::RenderApi renderApi)
{
switch (renderApi)
{
case RenderAPI::VULKAN: return new Vulkan::Renderer();
default:
Logger::RENDER->error("Unsupported render api requested! Requested %d", static_cast<int>(renderApi));
throw std::runtime_error("Unsupported render api requested!");
}
}
/**
* \brief Creates a platform that fits best for the current environment
* \param renderApi The render api that should be used when searching for the best suited platform provider
* \return The created platform
* \throws std::runtime_error if the render api is not supported
*/
static IPlatform* CreatePlatform(RenderAPI::RenderApi renderApi)
{
switch (renderApi)
{
case RenderAPI::VULKAN: return new GLFW::PlatformGLFW();
default:
Logger::MANAGER->error("Unsupported render api requested! Requested %d", static_cast<int>(renderApi));
throw std::runtime_error("Unsupported render api requested!");
}
}
};
}