OpenGL: Rework contexts
This commit is contained in:
parent
3b24d020e8
commit
0fa095e8f7
|
|
@ -1,39 +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
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_OPENGLRENDERER_GLCONTEXT_HPP
|
|
||||||
#define NAZARA_OPENGLRENDERER_GLCONTEXT_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Nz::GL
|
|
||||||
{
|
|
||||||
struct ContextParams
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class GLContext
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GLContext() = default;
|
|
||||||
virtual ~GLContext();
|
|
||||||
|
|
||||||
virtual bool Activate() = 0;
|
|
||||||
|
|
||||||
virtual bool Create(const ContextParams& params) = 0;
|
|
||||||
|
|
||||||
virtual void EnableVerticalSync(bool enabled) = 0;
|
|
||||||
|
|
||||||
virtual void SwapBuffers() = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/GLContext.inl>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,12 +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/Wrapper/GLContext.hpp>
|
|
||||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz::Vk
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
|
||||||
|
|
@ -4,28 +4,65 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef NAZARA_OPENGLRENDERER_CONTEXT_HPP
|
#ifndef NAZARA_OPENGLRENDERER_CONTEXTIMPL_HPP
|
||||||
#define NAZARA_OPENGLRENDERER_CONTEXT_HPP
|
#define NAZARA_OPENGLRENDERER_CONTEXTIMPL_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/GLContext.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
|
||||||
#include <memory>
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace Nz::GL
|
namespace Nz::GL
|
||||||
{
|
{
|
||||||
|
enum class ContextType
|
||||||
|
{
|
||||||
|
OpenGL,
|
||||||
|
OpenGL_ES
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ContextParams
|
||||||
|
{
|
||||||
|
ContextType type = ContextType::OpenGL_ES;
|
||||||
|
bool doubleBuffering = true;
|
||||||
|
unsigned int bitsPerPixel = 32;
|
||||||
|
unsigned int depthBits = 24;
|
||||||
|
unsigned int glMajorVersion = 0;
|
||||||
|
unsigned int glMinorVersion = 0;
|
||||||
|
unsigned int sampleCount = 1;
|
||||||
|
unsigned int stencilBits = 8;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Loader;
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Context() = default;
|
Context() = default;
|
||||||
Context(const Context&) = delete;
|
virtual ~Context();
|
||||||
Context(Context&& object) noexcept = default;
|
|
||||||
~Context() = default;
|
|
||||||
|
|
||||||
Context& operator=(const Context&) = delete;
|
virtual bool Activate() = 0;
|
||||||
Context& operator=(Context&& object) noexcept = default;
|
|
||||||
|
|
||||||
private:
|
virtual void EnableVerticalSync(bool enabled) = 0;
|
||||||
std::unique_ptr<GLContext> m_impl;
|
|
||||||
|
inline const ContextParams& GetParams() const;
|
||||||
|
|
||||||
|
inline bool IsExtensionSupported(const std::string& extension) const;
|
||||||
|
|
||||||
|
bool Initialize(const ContextParams& params);
|
||||||
|
|
||||||
|
virtual void SwapBuffers() = 0;
|
||||||
|
|
||||||
|
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
|
||||||
|
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC)
|
||||||
|
#undef NAZARA_OPENGLRENDERER_FUNC
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const Loader& GetLoader() = 0;
|
||||||
|
|
||||||
|
virtual bool ImplementFallback(const std::string_view& function) = 0;
|
||||||
|
|
||||||
|
std::unordered_set<std::string> m_supportedExtensions;
|
||||||
|
ContextParams m_params;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@
|
||||||
|
|
||||||
namespace Nz::GL
|
namespace Nz::GL
|
||||||
{
|
{
|
||||||
|
inline const ContextParams& Context::GetParams() const
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Context::IsExtensionSupported(const std::string& extension) const
|
||||||
|
{
|
||||||
|
return m_supportedExtensions.find(extension) != m_supportedExtensions.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#ifndef NAZARA_OPENGLRENDERER_COREFUNCTIONS_HPP
|
#ifndef NAZARA_OPENGLRENDERER_COREFUNCTIONS_HPP
|
||||||
#define NAZARA_OPENGLRENDERER_COREFUNCTIONS_HPP
|
#define NAZARA_OPENGLRENDERER_COREFUNCTIONS_HPP
|
||||||
|
|
||||||
|
#define GL_GLES_PROTOTYPES 0
|
||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
|
|
||||||
// OpenGL core
|
// OpenGL core
|
||||||
|
|
@ -28,6 +29,7 @@
|
||||||
cb(glBufferSubData, PFNGLBUFFERSUBDATAPROC) \
|
cb(glBufferSubData, PFNGLBUFFERSUBDATAPROC) \
|
||||||
cb(glClear, PFNGLCLEARPROC) \
|
cb(glClear, PFNGLCLEARPROC) \
|
||||||
cb(glClearColor, PFNGLCLEARCOLORPROC) \
|
cb(glClearColor, PFNGLCLEARCOLORPROC) \
|
||||||
|
cb(glClearDepthf, PFNGLCLEARDEPTHFPROC) \
|
||||||
cb(glClearStencil, PFNGLCLEARSTENCILPROC) \
|
cb(glClearStencil, PFNGLCLEARSTENCILPROC) \
|
||||||
cb(glCreateProgram, PFNGLCREATEPROGRAMPROC) \
|
cb(glCreateProgram, PFNGLCREATEPROGRAMPROC) \
|
||||||
cb(glCreateShader, PFNGLCREATESHADERPROC) \
|
cb(glCreateShader, PFNGLCREATESHADERPROC) \
|
||||||
|
|
@ -104,6 +106,7 @@
|
||||||
cb(glSamplerParameterf, PFNGLSAMPLERPARAMETERFPROC) \
|
cb(glSamplerParameterf, PFNGLSAMPLERPARAMETERFPROC) \
|
||||||
cb(glSamplerParameteri, PFNGLSAMPLERPARAMETERIPROC) \
|
cb(glSamplerParameteri, PFNGLSAMPLERPARAMETERIPROC) \
|
||||||
cb(glScissor, PFNGLSCISSORPROC) \
|
cb(glScissor, PFNGLSCISSORPROC) \
|
||||||
|
cb(glShaderBinary, PFNGLSHADERBINARYPROC) \
|
||||||
cb(glShaderSource, PFNGLSHADERSOURCEPROC) \
|
cb(glShaderSource, PFNGLSHADERSOURCEPROC) \
|
||||||
cb(glStencilFunc, PFNGLSTENCILFUNCPROC) \
|
cb(glStencilFunc, PFNGLSTENCILFUNCPROC) \
|
||||||
cb(glStencilFuncSeparate, PFNGLSTENCILFUNCSEPARATEPROC) \
|
cb(glStencilFuncSeparate, PFNGLSTENCILFUNCSEPARATEPROC) \
|
||||||
|
|
|
||||||
|
|
@ -1,52 +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
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_OPENGLRENDERER_CONTEXTIMPL_HPP
|
|
||||||
#define NAZARA_OPENGLRENDERER_CONTEXTIMPL_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Nz::GL
|
|
||||||
{
|
|
||||||
struct ContextParams
|
|
||||||
{
|
|
||||||
bool doubleBuffering = true;
|
|
||||||
unsigned int sampleCount = 1;
|
|
||||||
unsigned int bitsPerPixel = 32;
|
|
||||||
unsigned int depthBits = 24;
|
|
||||||
unsigned int stencilBits = 8;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Loader;
|
|
||||||
|
|
||||||
class GLContext
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GLContext() = default;
|
|
||||||
virtual ~GLContext();
|
|
||||||
|
|
||||||
virtual bool Activate() = 0;
|
|
||||||
|
|
||||||
virtual bool Create(const ContextParams& params) = 0;
|
|
||||||
|
|
||||||
virtual void EnableVerticalSync(bool enabled) = 0;
|
|
||||||
|
|
||||||
bool LoadCoreFunctions(Loader& loader);
|
|
||||||
|
|
||||||
virtual void SwapBuffers() = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
|
|
||||||
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC)
|
|
||||||
#undef NAZARA_OPENGLRENDERER_FUNC
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/GLContext.inl>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,12 +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/Wrapper/GLContext.hpp>
|
|
||||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz::Vk
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/DynLib.hpp>
|
#include <Nazara/Core/DynLib.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/GLContext.hpp>
|
#include <Nazara/Platform/WindowHandle.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLLoader.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Win32/Win32Helper.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Win32/Win32Helper.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
@ -23,30 +23,37 @@ namespace Nz::GL
|
||||||
{
|
{
|
||||||
class WGLLoader;
|
class WGLLoader;
|
||||||
|
|
||||||
class WGLContext : public GLContext
|
class WGLContext : public Context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WGLContext(WGLLoader& loader);
|
WGLContext(const WGLLoader& loader);
|
||||||
WGLContext(const WGLContext&) = delete;
|
WGLContext(const WGLContext&) = delete;
|
||||||
WGLContext(WGLContext&&) = delete;
|
WGLContext(WGLContext&&) = delete;
|
||||||
~WGLContext();
|
~WGLContext();
|
||||||
|
|
||||||
bool Activate() override;
|
bool Activate() override;
|
||||||
|
|
||||||
bool Create(const ContextParams& params) override;
|
bool Create(const WGLContext* baseContext, const ContextParams& params, const WGLContext* shareContext = nullptr);
|
||||||
|
bool Create(const WGLContext* baseContext, const ContextParams& params, WindowHandle window, const WGLContext* shareContext = nullptr);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
void EnableVerticalSync(bool enabled) override;
|
void EnableVerticalSync(bool enabled) override;
|
||||||
|
|
||||||
|
inline bool HasPlatformExtension(const std::string& str) const;
|
||||||
|
|
||||||
void SwapBuffers() override;
|
void SwapBuffers() override;
|
||||||
|
|
||||||
WGLContext& operator=(const WGLContext&) = delete;
|
WGLContext& operator=(const WGLContext&) = delete;
|
||||||
WGLContext& operator=(WGLContext&&) = delete;
|
WGLContext& operator=(WGLContext&&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool CreateInternal(const WGLContext* baseContext, const ContextParams& params, const WGLContext* shareContext = nullptr);
|
||||||
|
bool ImplementFallback(const std::string_view& function) override;
|
||||||
|
|
||||||
void Desactivate();
|
void Desactivate();
|
||||||
|
const Loader& GetLoader() override;
|
||||||
bool LoadWGLExt();
|
bool LoadWGLExt();
|
||||||
bool SetPixelFormat(const ContextParams& params);
|
bool SetPixelFormat();
|
||||||
|
|
||||||
#define NAZARA_OPENGLRENDERER_FUNC(name, sig)
|
#define NAZARA_OPENGLRENDERER_FUNC(name, sig)
|
||||||
#define NAZARA_OPENGLRENDERER_EXT_BEGIN(ext)
|
#define NAZARA_OPENGLRENDERER_EXT_BEGIN(ext)
|
||||||
|
|
@ -58,8 +65,16 @@ namespace Nz::GL
|
||||||
#undef NAZARA_OPENGLRENDERER_EXT_FUNC
|
#undef NAZARA_OPENGLRENDERER_EXT_FUNC
|
||||||
#undef NAZARA_OPENGLRENDERER_FUNC
|
#undef NAZARA_OPENGLRENDERER_FUNC
|
||||||
|
|
||||||
std::unordered_set<std::string> m_supportedExtensions;
|
struct Fallback
|
||||||
WGLLoader& m_loader;
|
{
|
||||||
|
using glClearDepthProc = void(*)(double depth);
|
||||||
|
|
||||||
|
glClearDepthProc glClearDepth;
|
||||||
|
};
|
||||||
|
Fallback fallbacks; //< m_ omitted
|
||||||
|
|
||||||
|
std::unordered_set<std::string> m_supportedPlatformExtensions;
|
||||||
|
const WGLLoader& m_loader;
|
||||||
HDC m_deviceContext;
|
HDC m_deviceContext;
|
||||||
HGLRC m_handle;
|
HGLRC m_handle;
|
||||||
HWNDHandle m_window;
|
HWNDHandle m_window;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,12 @@
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz::Vk
|
namespace Nz::GL
|
||||||
{
|
{
|
||||||
|
inline bool WGLContext::HasPlatformExtension(const std::string& str) const
|
||||||
|
{
|
||||||
|
return m_supportedPlatformExtensions.find(str) != m_supportedPlatformExtensions.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/DynLib.hpp>
|
#include <Nazara/Core/DynLib.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
||||||
|
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#undef WIN32_LEAN_AND_MEAN //< Redefined by OpenGL header (ty Khronos)
|
#undef WIN32_LEAN_AND_MEAN //< Redefined by OpenGL header (ty Khronos)
|
||||||
|
|
@ -23,9 +24,10 @@ namespace Nz::GL
|
||||||
WGLLoader(DynLib& openglLib);
|
WGLLoader(DynLib& openglLib);
|
||||||
~WGLLoader() = default;
|
~WGLLoader() = default;
|
||||||
|
|
||||||
std::unique_ptr<GLContext> CreateContext() override;
|
std::unique_ptr<Context> CreateContext(const ContextParams& params, Context* shareContext) const override;
|
||||||
|
std::unique_ptr<Context> CreateContext(const ContextParams& params, WindowHandle handle, Context* shareContext) const override;
|
||||||
|
|
||||||
GLFunction LoadFunction(const char* name) override;
|
GLFunction LoadFunction(const char* name) const override;
|
||||||
|
|
||||||
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
|
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
|
||||||
#define NAZARA_OPENGLRENDERER_EXT_BEGIN(ext)
|
#define NAZARA_OPENGLRENDERER_EXT_BEGIN(ext)
|
||||||
|
|
@ -41,6 +43,7 @@ namespace Nz::GL
|
||||||
private:
|
private:
|
||||||
DynLib m_gdi32Lib;
|
DynLib m_gdi32Lib;
|
||||||
DynLib& m_opengl32Lib;
|
DynLib& m_opengl32Lib;
|
||||||
|
WGLContext m_baseContext;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue