#include #include #ifdef LIGHT_PLATFORM_WINDOWS #include #include #endif #include // required for forward declaratio> #include // required for forward declaratio> #include // required for forward declaratio> #include // required for forward declaratio> #include // required for forward declaratio> #include namespace Light { GraphicsContext *GraphicsContext::s_context = nullptr; GraphicsContext::~GraphicsContext() = default; auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope { // terminate 'GraphicsContext' dependent classes if (s_context) { s_context->m_renderer.reset(); s_context->m_user_interface.reset(); delete s_context; } // determine the default api 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 } // create gfx context auto scope_gfx = Scope {}; switch (api) { // opengl case GraphicsAPI::OpenGL: scope_gfx = create_scope(windowHandle); s_context = scope_gfx.get(); break; // directx case GraphicsAPI::DirectX: lt_win(scope_gfx = create_scope(windowHandle); s_context = scope_gfx.get(); break;) default : lt_assert( false, "Invalid/unsupported 'GraphicsAPI' {}", Stringifier::graphics_api_to_string(api) ); return nullptr; } // create 'GraphicsContext' dependent classes s_context->m_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context); s_context->m_renderer = Renderer::create(windowHandle, s_context->m_shared_context); // check lt_assert(s_context->m_user_interface, "Failed to create UserInterface"); lt_assert(s_context->m_renderer, "Failed to create renderer"); return std::move(scope_gfx); } } // namespace Light