// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // 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 #include #include #include #include #include #include #if defined(NAZARA_PLATFORM_WINDOWS) || defined(NAZARA_PLATFORM_LINUX) #include #endif #ifdef NAZARA_PLATFORM_WINDOWS #include #endif #include namespace Nz { OpenGLRenderer::~OpenGLRenderer() { // Free device before loader m_device.reset(); } std::unique_ptr OpenGLRenderer::CreateRenderSurfaceImpl() { return std::make_unique(); } std::unique_ptr OpenGLRenderer::CreateRenderWindowImpl(RenderWindow& owner) { return std::make_unique(owner); } std::shared_ptr OpenGLRenderer::InstanciateRenderDevice(std::size_t deviceIndex, const RenderDeviceFeatures& enabledFeatures) { assert(deviceIndex == 0); // For now, since we have to create a device to know its features, supported features are always reported as enabled // We still call ValidateFeatures in order to trigger warnings if requested features are not supported // TODO: Report disabled features as disabled (make OpenGLDeviceProxy?) RenderDeviceFeatures validatedFeatures = enabledFeatures; OpenGLDevice::ValidateFeatures(m_device->GetEnabledFeatures(), validatedFeatures); return m_device; } bool OpenGLRenderer::Prepare(const ParameterList& /*parameters*/) { std::unique_ptr loader = SelectLoader(); if (!loader) { NazaraError("Failed to initialize OpenGL loader"); return false; } m_loader = std::move(loader); m_device = std::make_shared(*m_loader); m_deviceInfos.emplace_back(m_device->GetDeviceInfo()); return true; } std::unique_ptr OpenGLRenderer::SelectLoader() { #ifdef NAZARA_PLATFORM_WINDOWS try { return std::make_unique(); } catch (const std::exception& e) { NazaraWarning(std::string("Failed to load WGL: ") + e.what()); } #endif #if defined(NAZARA_PLATFORM_WINDOWS) || defined(NAZARA_PLATFORM_LINUX) try { return std::make_unique(); } catch (const std::exception& e) { NazaraWarning(std::string("Failed to load EGL: ") + e.what()); } #endif return {}; } RenderAPI OpenGLRenderer::QueryAPI() const { return RenderAPI::OpenGL; } std::string OpenGLRenderer::QueryAPIString() const { std::ostringstream ss; ss << "OpenGL ES renderer 3.0"; return ss.str(); } UInt32 OpenGLRenderer::QueryAPIVersion() const { return 300; } const std::vector& OpenGLRenderer::QueryRenderDevices() const { return m_deviceInfos; } }