OpenGL: Rework contexts

This commit is contained in:
Lynix
2020-04-19 01:35:19 +02:00
parent 3b24d020e8
commit 0fa095e8f7
10 changed files with 93 additions and 137 deletions

View File

@@ -9,8 +9,8 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/GLContext.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLLoader.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Win32/Win32Helper.hpp>
#include <string>
#include <type_traits>
@@ -23,30 +23,37 @@ namespace Nz::GL
{
class WGLLoader;
class WGLContext : public GLContext
class WGLContext : public Context
{
public:
WGLContext(WGLLoader& loader);
WGLContext(const WGLLoader& loader);
WGLContext(const WGLContext&) = delete;
WGLContext(WGLContext&&) = delete;
~WGLContext();
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 EnableVerticalSync(bool enabled) override;
inline bool HasPlatformExtension(const std::string& str) const;
void SwapBuffers() override;
WGLContext& operator=(const WGLContext&) = delete;
WGLContext& operator=(WGLContext&&) = delete;
private:
bool CreateInternal(const WGLContext* baseContext, const ContextParams& params, const WGLContext* shareContext = nullptr);
bool ImplementFallback(const std::string_view& function) override;
void Desactivate();
const Loader& GetLoader() override;
bool LoadWGLExt();
bool SetPixelFormat(const ContextParams& params);
bool SetPixelFormat();
#define NAZARA_OPENGLRENDERER_FUNC(name, sig)
#define NAZARA_OPENGLRENDERER_EXT_BEGIN(ext)
@@ -58,8 +65,16 @@ namespace Nz::GL
#undef NAZARA_OPENGLRENDERER_EXT_FUNC
#undef NAZARA_OPENGLRENDERER_FUNC
std::unordered_set<std::string> m_supportedExtensions;
WGLLoader& m_loader;
struct Fallback
{
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;
HGLRC m_handle;
HWNDHandle m_window;

View File

@@ -5,8 +5,12 @@
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.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>

View File

@@ -10,6 +10,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.hpp>
#include <string>
#undef WIN32_LEAN_AND_MEAN //< Redefined by OpenGL header (ty Khronos)
@@ -23,9 +24,10 @@ namespace Nz::GL
WGLLoader(DynLib& openglLib);
~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_EXT_BEGIN(ext)
@@ -41,6 +43,7 @@ namespace Nz::GL
private:
DynLib m_gdi32Lib;
DynLib& m_opengl32Lib;
WGLContext m_baseContext;
};
}