// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - OpenGL Renderer" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #ifdef NAZARA_PLATFORM_WINDOWS #include #endif #include namespace Nz { struct OpenGLImpl { DynLib opengl32Lib; }; static std::unique_ptr s_impl; bool OpenGL::Initialize() { if (s_impl) return true; auto impl = std::make_unique(); if (!impl->opengl32Lib.Load("opengl32" NAZARA_DYNLIB_EXTENSION)) { NazaraError("Failed to load opengl32 library, is OpenGL installed on your system?"); return false; } std::unique_ptr loader; #ifdef NAZARA_PLATFORM_WINDOWS try { loader = std::make_unique(impl->opengl32Lib); } catch (const std::exception& e) { NazaraWarning(std::string("Failed to load WGL: ") + e.what()); } #endif if (!loader) { NazaraError("Failed to initialize OpenGL loader"); return false; } s_impl = std::move(impl); return true; } bool OpenGL::IsInitialized() { return s_impl != nullptr; } void OpenGL::Uninitialize() { if (!s_impl) return; s_impl.reset(); } }