Add basic EGL support

This commit is contained in:
Jérôme Leclercq
2020-09-01 18:46:35 +02:00
parent 07a02ecfcd
commit ef737a8ecd
29 changed files with 1122 additions and 94 deletions

View File

@@ -36,6 +36,8 @@ namespace Nz
bool Prepare(const ParameterList& parameters) override;
private:
std::unique_ptr<GL::Loader> SelectLoader();
DynLib m_opengl32Lib;
std::shared_ptr<OpenGLDevice> m_device;
std::unique_ptr<GL::Loader> m_loader;

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
@@ -90,7 +91,7 @@ namespace Nz::GL
class Loader;
class Context
class NAZARA_OPENGLRENDERER_API Context
{
public:
inline Context(const OpenGLDevice* device);

View File

@@ -0,0 +1,79 @@
// 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_EGLCONTEXT_HPP
#define NAZARA_OPENGLRENDERER_EGLCONTEXT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLFunctions.hpp>
#include <string>
#include <type_traits>
#include <unordered_set>
namespace Nz::GL
{
class EGLLoader;
// This class isn't called EGLContext to prevent a conflict with EGLContext from EGL
class NAZARA_OPENGLRENDERER_API EGLContextBase : public Context
{
public:
inline EGLContextBase(const OpenGLDevice* device, const EGLLoader& loader);
EGLContextBase(const EGLContextBase&) = delete;
EGLContextBase(EGLContextBase&&) = delete;
~EGLContextBase();
virtual bool Create(const ContextParams& params, const EGLContextBase* shareContext = nullptr);
virtual bool Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext = nullptr);
virtual void Destroy();
void EnableVerticalSync(bool enabled) override;
inline bool HasPlatformExtension(const std::string& str) const;
void SwapBuffers() override;
EGLContextBase& operator=(const EGLContextBase&) = delete;
EGLContextBase& operator=(EGLContextBase&&) = delete;
protected:
bool BindAPI();
bool ChooseConfig(EGLConfig* configs, std::size_t maxConfigCount, std::size_t* configCount);
bool CreateInternal(EGLConfig config, const EGLContextBase* shareContext = nullptr);
bool InitDisplay();
const EGLLoader& m_loader;
EGLDisplay m_display;
EGLSurface m_surface;
private:
bool ImplementFallback(const std::string_view& function) override;
bool Activate() const override;
void Desactivate() const override;
const Loader& GetLoader() override;
bool LoadEGLExt();
struct Fallback
{
using glClearDepthProc = void(*)(double depth);
glClearDepthProc glClearDepth;
};
Fallback fallbacks; //< m_ omitted
std::unordered_set<std::string> m_supportedPlatformExtensions;
EGLContext m_handle;
};
}
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.inl>
#endif

View File

@@ -0,0 +1,25 @@
// 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/EGL/EGLContextBase.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz::GL
{
inline EGLContextBase::EGLContextBase(const OpenGLDevice* device, const EGLLoader& loader) :
Context(device),
m_loader(loader),
m_display(EGL_NO_DISPLAY),
m_surface(EGL_NO_SURFACE),
m_handle(EGL_NO_CONTEXT)
{
}
inline bool EGLContextBase::HasPlatformExtension(const std::string& str) const
{
return m_supportedPlatformExtensions.find(str) != m_supportedPlatformExtensions.end();
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -0,0 +1,31 @@
// 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_EGLFUNCTIONS_HPP
#define NAZARA_OPENGLRENDERER_EGLFUNCTIONS_HPP
#include <GLES3/gl3.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#define NAZARA_OPENGLRENDERER_FOREACH_EGL_FUNC(func, extBegin, extEnd, extFunc) \
func(eglBindAPI, PFNEGLBINDAPIPROC) \
func(eglChooseConfig, PFNEGLCHOOSECONFIGPROC) \
func(eglCreateContext, PFNEGLCREATECONTEXTPROC) \
func(eglCreatePbufferSurface, PFNEGLCREATEPBUFFERSURFACEPROC) \
func(eglCreateWindowSurface, PFNEGLCREATEWINDOWSURFACEPROC) \
func(eglDestroyContext, PFNEGLDESTROYCONTEXTPROC) \
func(eglDestroySurface, PFNEGLDESTROYSURFACEPROC) \
func(eglGetDisplay, PFNEGLGETDISPLAYPROC) \
func(eglGetError, PFNEGLGETERRORPROC) \
func(eglGetProcAddress, PFNEGLGETPROCADDRESSPROC) \
func(eglInitialize, PFNEGLINITIALIZEPROC) \
func(eglMakeCurrent, PFNEGLMAKECURRENTPROC) \
func(eglQueryString, PFNEGLQUERYSTRINGPROC) \
func(eglSwapBuffers, PFNEGLSWAPBUFFERSPROC) \
func(eglTerminate, PFNEGLTERMINATEPROC)
#endif

View File

@@ -0,0 +1,50 @@
// 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_EGLLOADER_HPP
#define NAZARA_OPENGLRENDERER_EGLLOADER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLFunctions.hpp>
#include <string>
namespace Nz::GL
{
class NAZARA_OPENGLRENDERER_API EGLLoader : public Loader
{
public:
EGLLoader(DynLib& openglLib);
~EGLLoader() = default;
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const override;
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, WindowHandle handle, Context* shareContext) const override;
GLFunction LoadFunction(const char* name) const override;
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
#define NAZARA_OPENGLRENDERER_EXT_BEGIN(ext)
#define NAZARA_OPENGLRENDERER_EXT_END()
#define NAZARA_OPENGLRENDERER_EXT_FUNC(name, sig)
NAZARA_OPENGLRENDERER_FOREACH_EGL_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_EXT_BEGIN, NAZARA_OPENGLRENDERER_EXT_END, NAZARA_OPENGLRENDERER_EXT_FUNC)
#undef NAZARA_OPENGLRENDERER_EXT_BEGIN
#undef NAZARA_OPENGLRENDERER_EXT_END
#undef NAZARA_OPENGLRENDERER_EXT_FUNC
#undef NAZARA_OPENGLRENDERER_FUNC
static const char* TranslateError(EGLint errorId);
private:
DynLib m_eglLib;
};
}
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.inl>
#endif

View File

@@ -0,0 +1,12 @@
// 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/EGL/EGLLoader.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz::Vk
{
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -0,0 +1,33 @@
// 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_EGLCONTEXTWAYLAND_HPP
#define NAZARA_OPENGLRENDERER_EGLCONTEXTWAYLAND_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
namespace Nz::GL
{
class EGLContextWayland final : public EGLContextBase
{
public:
using EGLContextBase::EGLContextBase;
EGLContextWayland(const EGLContextWayland&) = default;
EGLContextWayland(EGLContextWayland&&) = default;
~EGLContextWayland() = default;
bool Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext = nullptr) override;
void Destroy() override;
EGLContextWayland& operator=(const EGLContextWayland&) = default;
EGLContextWayland& operator=(EGLContextWayland&&) = default;
};
}
#include <Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextWayland.inl>
#endif

View File

@@ -0,0 +1,12 @@
// 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/Linux/EGLContextWayland.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz::GL
{
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -0,0 +1,33 @@
// 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_EGLCONTEXTWIN32_HPP
#define NAZARA_OPENGLRENDERER_EGLCONTEXTWIN32_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
namespace Nz::GL
{
class EGLContextX11 final : public EGLContextBase
{
public:
using EGLContextBase::EGLContextBase;
EGLContextX11(const EGLContextX11&) = default;
EGLContextX11(EGLContextX11&&) = default;
~EGLContextX11() = default;
bool Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext = nullptr) override;
void Destroy() override;
EGLContextX11& operator=(const EGLContextX11&) = default;
EGLContextX11& operator=(EGLContextX11&&) = default;
};
}
#include <Nazara/OpenGLRenderer/Wrapper/Linux/EGLContextX11.inl>
#endif

View File

@@ -0,0 +1,12 @@
// 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/Linux/EGLContextX11.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz::GL
{
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -10,20 +10,19 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/WGL/Win32Helper.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Win32/Win32Helper.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLFunctions.hpp>
#include <string>
#include <type_traits>
#include <unordered_set>
#undef WIN32_LEAN_AND_MEAN //< Redefined by OpenGL header (ty Khronos)
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLFunctions.hpp>
namespace Nz::GL
{
class WGLLoader;
class WGLContext : public Context
class NAZARA_OPENGLRENDERER_API WGLContext : public Context
{
public:
inline WGLContext(const OpenGLDevice* device, const WGLLoader& loader);

View File

@@ -7,6 +7,8 @@
#ifndef NAZARA_OPENGLRENDERER_WGLFUNCTIONS_HPP
#define NAZARA_OPENGLRENDERER_WGLFUNCTIONS_HPP
#undef WIN32_LEAN_AND_MEAN //< Redefined by wgl.h header (ty Khronos)
#include <GLES3/gl3.h>
#include <GL/wgl.h>
#include <GL/wglext.h>

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.hpp>
#include <string>
@@ -18,7 +19,7 @@
namespace Nz::GL
{
class WGLLoader : public Loader
class NAZARA_OPENGLRENDERER_API WGLLoader : public Loader
{
public:
WGLLoader(DynLib& openglLib);

View File

@@ -0,0 +1,38 @@
// 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_EGLCONTEXTWIN32_HPP
#define NAZARA_OPENGLRENDERER_EGLCONTEXTWIN32_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Win32/Win32Helper.hpp>
namespace Nz::GL
{
class EGLContextWin32 final : public EGLContextBase
{
public:
using EGLContextBase::EGLContextBase;
EGLContextWin32(const EGLContextWin32&) = default;
EGLContextWin32(EGLContextWin32&&) = default;
~EGLContextWin32() = default;
bool Create(const ContextParams& params, const EGLContextBase* shareContext = nullptr);
bool Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext = nullptr) override;
void Destroy() override;
EGLContextWin32& operator=(const EGLContextWin32&) = default;
EGLContextWin32& operator=(EGLContextWin32&&) = default;
private:
HWNDHandle m_ownedWindow;
};
}
#include <Nazara/OpenGLRenderer/Wrapper/Win32/EGLContextWin32.inl>
#endif

View File

@@ -0,0 +1,12 @@
// 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/Win32/EGLContextWin32.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz::GL
{
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -0,0 +1,54 @@
// 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_WGLFUNCTIONS_HPP
#define NAZARA_OPENGLRENDERER_WGLFUNCTIONS_HPP
#undef WIN32_LEAN_AND_MEAN //< Redefined by wgl.h header (ty Khronos)
#include <GLES3/gl3.h>
#include <GL/wgl.h>
#include <GL/wglext.h>
#define NAZARA_OPENGLRENDERER_FOREACH_WGL_FUNC(func, extBegin, extEnd, extFunc) \
func(wglCreateContext, PFNWGLCREATECONTEXTPROC) \
func(wglDeleteContext, PFNWGLDELETECONTEXTPROC) \
func(wglGetCurrentContext, PFNWGLGETCURRENTCONTEXTPROC) \
func(wglGetProcAddress, PFNWGLGETPROCADDRESSPROC) \
func(wglMakeCurrent, PFNWGLMAKECURRENTPROC) \
func(wglShareLists, PFNWGLSHARELISTSPROC) \
\
extBegin(WGL_ARB_create_context) \
extFunc(wglCreateContextAttribsARB, PFNWGLCREATECONTEXTATTRIBSARBPROC) \
extEnd() \
\
extBegin(WGL_ARB_pixel_format) \
extFunc(wglChoosePixelFormatARB, PFNWGLCHOOSEPIXELFORMATARBPROC) \
extEnd() \
\
extBegin(WGL_EXT_pixel_format) \
extFunc(wglChoosePixelFormatEXT, PFNWGLCHOOSEPIXELFORMATEXTPROC) \
extEnd() \
\
extBegin(WGL_ARB_extensions_string) \
extFunc(wglGetExtensionsStringARB, PFNWGLGETEXTENSIONSSTRINGARBPROC) \
extEnd() \
\
extBegin(WGL_EXT_extensions_string) \
extFunc(wglGetExtensionsStringEXT, PFNWGLGETEXTENSIONSSTRINGEXTPROC) \
extEnd() \
\
extBegin(WGL_EXT_swap_control) \
extFunc(wglSwapIntervalEXT, PFNWGLSWAPINTERVALEXTPROC) \
extEnd()
#define NAZARA_OPENGLRENDERER_FOREACH_GDI32_FUNC(func) \
func(ChoosePixelFormat, PFNCHOOSEPIXELFORMATPROC) \
func(DescribePixelFormat, PFNDESCRIBEPIXELFORMATPROC) \
func(SetPixelFormat, PFNSETPIXELFORMATPROC) \
func(SwapBuffers, PFNSWAPBUFFERSPROC) \
#endif

View File

@@ -8,6 +8,8 @@
#define NAZARA_OPENGLRENDERER_WIN32HELPER_HPP
#include <Nazara/Prerequisites.hpp>
#include <memory>
#include <type_traits>
#include <windows.h>
namespace Nz::GL