OpenGL: Implement device
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
// 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 <Nazara/OpenGLRenderer/OpenGL.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLLoader.hpp>
|
||||
#endif
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct OpenGLImpl
|
||||
{
|
||||
DynLib opengl32Lib;
|
||||
};
|
||||
|
||||
static std::unique_ptr<OpenGLImpl> s_impl;
|
||||
|
||||
bool OpenGL::Initialize()
|
||||
{
|
||||
if (s_impl)
|
||||
return true;
|
||||
|
||||
auto impl = std::make_unique<OpenGLImpl>();
|
||||
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<GL::Loader> loader;
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||
try
|
||||
{
|
||||
loader = std::make_unique<GL::WGLLoader>(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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,63 +2,68 @@
|
||||
// This file is part of the "Nazara Engine - OpenGL Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#if 0
|
||||
|
||||
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPipeline.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
|
||||
#include <Nazara/Renderer/CommandPool.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLShaderStage.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLTextureSampler.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
OpenGLDevice::OpenGLDevice(GL::Loader& loader) :
|
||||
m_loader(loader)
|
||||
{
|
||||
m_referenceContext = loader.CreateContext({});
|
||||
if (!m_referenceContext)
|
||||
throw std::runtime_error("failed to create reference context");
|
||||
}
|
||||
|
||||
OpenGLDevice::~OpenGLDevice() = default;
|
||||
|
||||
std::unique_ptr<GL::Context> OpenGLDevice::CreateContext(const GL::ContextParams& params) const
|
||||
{
|
||||
return m_loader.CreateContext(params, m_referenceContext.get());
|
||||
}
|
||||
|
||||
std::unique_ptr<GL::Context> OpenGLDevice::CreateContext(const GL::ContextParams& params, WindowHandle handle) const
|
||||
{
|
||||
return m_loader.CreateContext(params, handle, m_referenceContext.get());
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractBuffer> OpenGLDevice::InstantiateBuffer(BufferType type)
|
||||
{
|
||||
return std::make_unique<OpenGLBuffer>(*this, type);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandPool> OpenGLDevice::InstantiateCommandPool(QueueType queueType)
|
||||
{
|
||||
return std::make_unique<OpenGLCommandPool>(*this, queueType);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::unique_ptr<RenderPipeline> OpenGLDevice::InstantiateRenderPipeline(RenderPipelineInfo pipelineInfo)
|
||||
{
|
||||
return std::make_unique<OpenGLRenderPipeline>(*this, std::move(pipelineInfo));
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderPipelineLayout> OpenGLDevice::InstantiateRenderPipelineLayout(RenderPipelineLayoutInfo pipelineLayoutInfo)
|
||||
{
|
||||
auto pipelineLayout = std::make_shared<OpenGLRenderPipelineLayout>();
|
||||
if (!pipelineLayout->Create(*this, std::move(pipelineLayoutInfo)))
|
||||
return {};
|
||||
|
||||
return pipelineLayout;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStageImpl> OpenGLDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
auto stage = std::make_shared<OpenGLShaderStage>();
|
||||
if (!stage->Create(*this, type, lang, source, sourceSize))
|
||||
return {};
|
||||
|
||||
return stage;
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> OpenGLDevice::InstantiateTexture(const TextureInfo& params)
|
||||
{
|
||||
return std::make_unique<OpenGLTexture>(*this, params);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::unique_ptr<TextureSampler> OpenGLDevice::InstantiateTextureSampler(const TextureSamplerInfo& params)
|
||||
{
|
||||
return std::make_unique<OpenGLTextureSampler>(*this, params);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,33 +7,39 @@
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Renderer/RenderSurface.hpp>
|
||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGL.hpp>
|
||||
#include <Nazara/OpenGLRenderer/DummySurface.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.hpp>
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLLoader.hpp>
|
||||
#endif
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
OpenGLRenderer::~OpenGLRenderer()
|
||||
{
|
||||
OpenGL::Uninitialize();
|
||||
m_device.reset();
|
||||
m_loader.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<RenderSurface> OpenGLRenderer::CreateRenderSurfaceImpl()
|
||||
{
|
||||
return {};
|
||||
return std::make_unique<DummySurface>();
|
||||
}
|
||||
|
||||
std::unique_ptr<RenderWindowImpl> OpenGLRenderer::CreateRenderWindowImpl()
|
||||
{
|
||||
return {};
|
||||
return std::make_unique<OpenGLRenderWindow>();
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderDevice> OpenGLRenderer::InstanciateRenderDevice(std::size_t deviceIndex)
|
||||
{
|
||||
//assert(deviceIndex < m_physDevices.size());
|
||||
//return OpenGL::SelectDevice(m_physDevices[deviceIndex]);
|
||||
return {};
|
||||
assert(deviceIndex == 0);
|
||||
return m_device;
|
||||
}
|
||||
|
||||
bool OpenGLRenderer::IsBetterThan(const RendererImpl* other) const
|
||||
@@ -46,7 +52,36 @@ namespace Nz
|
||||
|
||||
bool OpenGLRenderer::Prepare(const ParameterList& parameters)
|
||||
{
|
||||
return OpenGL::Initialize();
|
||||
if (!m_opengl32Lib.Load("opengl32" NAZARA_DYNLIB_EXTENSION))
|
||||
{
|
||||
NazaraError("Failed to load opengl32 library, is OpenGL installed on your system?");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<GL::Loader> loader;
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||
try
|
||||
{
|
||||
loader = std::make_unique<GL::WGLLoader>(m_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;
|
||||
}
|
||||
|
||||
m_loader = std::move(loader);
|
||||
|
||||
m_device = std::make_shared<OpenGLDevice>(*m_loader);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderAPI OpenGLRenderer::QueryAPI() const
|
||||
|
||||
Reference in New Issue
Block a user