OpenGLRenderer: Get rid of std::function by using function indexes

This commit is contained in:
Jérôme Leclercq
2020-09-03 13:54:44 +02:00
parent 6848ff8b34
commit 0609a10c25
4 changed files with 45 additions and 28 deletions

View File

@@ -9,16 +9,16 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <array>
#include <string>
#include <unordered_set>
#define NAZARA_OPENGLRENDERER_DEBUG 1
namespace Nz
{
class OpenGLDevice;
@@ -91,8 +91,6 @@ namespace Nz::GL
unsigned int stencilBits = 8;
};
class Loader;
class NAZARA_OPENGLRENDERER_API Context
{
struct SymbolLoader;
@@ -118,6 +116,7 @@ namespace Nz::GL
inline const OpenGLDevice* GetDevice() const;
inline ExtensionStatus GetExtensionStatus(Extension extension) const;
inline GLFunction GetFunctionByIndex(std::size_t funcIndex) const;
inline const OpenGLVaoCache& GetVaoCache() const;
inline const ContextParams& GetParams() const;
@@ -142,11 +141,7 @@ namespace Nz::GL
void UpdateStates(const RenderStates& renderStates) const;
#if NAZARA_OPENGLRENDERER_DEBUG
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) std::function<std::remove_pointer_t<sig>> name;
#else
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
#endif
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_FUNC)
#undef NAZARA_OPENGLRENDERER_FUNC
@@ -168,6 +163,15 @@ namespace Nz::GL
private:
void GL_APIENTRY HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message) const;
enum class FunctionIndex
{
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) name,
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_FUNC)
#undef NAZARA_OPENGLRENDERER_FUNC
Count
};
struct State
{
struct Box
@@ -203,6 +207,7 @@ namespace Nz::GL
};
std::array<ExtensionStatus, UnderlyingCast(Extension::Max) + 1> m_extensionStatus;
std::array<GLFunction, UnderlyingCast(FunctionIndex::Count)> m_originalFunctionPointer;
std::unordered_set<std::string> m_supportedExtensions;
OpenGLVaoCache m_vaoCache;
const OpenGLDevice* m_device;

View File

@@ -23,6 +23,12 @@ namespace Nz::GL
return m_extensionStatus[UnderlyingCast(extension)];
}
inline GLFunction Context::GetFunctionByIndex(std::size_t funcIndex) const
{
assert(funcIndex < m_originalFunctionPointer.size());
return m_originalFunctionPointer[funcIndex];
}
inline const OpenGLVaoCache& Context::GetVaoCache() const
{
return m_vaoCache;

View File

@@ -10,7 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <memory>
namespace Nz
@@ -20,10 +19,11 @@ namespace Nz
namespace Nz::GL
{
class Context;
using GLFunction = void(*)(void);
class Context;
struct ContextParams;
class NAZARA_OPENGLRENDERER_API Loader
{
public: