light/modules/renderer/private/graphics_context.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

#include <renderer/gl/graphics_context.hpp>
#include <renderer/graphics_context.hpp>
#ifdef LIGHT_PLATFORM_WINDOWS
#include <renderer/dx/graphics_context.hpp>
#include <renderer/dx/shared_context.hpp>
#endif
2025-07-11 00:05:48 +03:30
namespace lt {
GraphicsContext *GraphicsContext::s_context = nullptr;
GraphicsContext::~GraphicsContext() = default;
auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *window_handle) -> Scope<GraphicsContext>
{
delete s_context;
if (api == GraphicsAPI::Default)
{
#if defined(LIGHT_PLATFORM_WINDOWS)
api = GraphicsAPI::DirectX;
#elif defined(LIGHT_PLATFORM_LINUX)
api = GraphicsAPI::OpenGL;
#elif defined(LIGHT_PLATFORM_MAC)
api = GraphicsAPI::OpenGL;
#endif
}
auto scope_gfx = Scope<GraphicsContext> {};
switch (api)
{
// opengl
case GraphicsAPI::OpenGL:
scope_gfx = create_scope<glGraphicsContext>(window_handle);
s_context = scope_gfx.get();
break;
// directx
case GraphicsAPI::DirectX:
2025-07-11 14:05:59 +03:30
lt_win(
scope_gfx = create_scope<dxGraphicsContext>(window_handle); s_context = scope_gfx.get();
break;
)
default
2025-07-11 02:12:55 +03:30
: ensure(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
// TODO(Light): Stringifier::graphics_api_to_string(api),
"TODO"
);
return nullptr;
}
return std::move(scope_gfx);
}
2025-07-11 00:05:48 +03:30
} // namespace lt