OpenGLRenderer: Improve error handling (fixes Windows/x86 compilation)
Template specialization was failing because OpenGL function type have __stdcall convention on Windows/32bits
This commit is contained in:
parent
9946c17a23
commit
a643d0fc3a
|
|
@ -95,6 +95,7 @@ namespace Nz::GL
|
||||||
{
|
{
|
||||||
ContextType type = ContextType::OpenGL_ES;
|
ContextType type = ContextType::OpenGL_ES;
|
||||||
bool doubleBuffering = true;
|
bool doubleBuffering = true;
|
||||||
|
bool wrapErrorHandling = false;
|
||||||
unsigned int bitsPerPixel = 32;
|
unsigned int bitsPerPixel = 32;
|
||||||
unsigned int depthBits = 24;
|
unsigned int depthBits = 24;
|
||||||
unsigned int glMajorVersion = 0;
|
unsigned int glMajorVersion = 0;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ namespace Nz
|
||||||
GL::ContextParams params;
|
GL::ContextParams params;
|
||||||
params.type = loader.GetPreferredContextType();
|
params.type = loader.GetPreferredContextType();
|
||||||
|
|
||||||
|
#ifdef NAZARA_OPENGLRENDERER_DEBUG
|
||||||
|
params.wrapErrorHandling = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
m_referenceContext = loader.CreateContext(this, params);
|
m_referenceContext = loader.CreateContext(this, params);
|
||||||
if (!m_referenceContext)
|
if (!m_referenceContext)
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ namespace Nz
|
||||||
OpenGLDevice& device = static_cast<OpenGLDevice&>(*m_owner.GetRenderDevice());
|
OpenGLDevice& device = static_cast<OpenGLDevice&>(*m_owner.GetRenderDevice());
|
||||||
|
|
||||||
GL::ContextParams contextParams;
|
GL::ContextParams contextParams;
|
||||||
|
#ifdef NAZARA_OPENGLRENDERER_DEBUG
|
||||||
|
contextParams.wrapErrorHandling = true;
|
||||||
|
#endif
|
||||||
//TODO: Pass render window parameters to context
|
//TODO: Pass render window parameters to context
|
||||||
|
|
||||||
m_context = device.CreateContext(contextParams, dummySurface->GetWindowHandle());
|
m_context = device.CreateContext(contextParams, dummySurface->GetWindowHandle());
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Nz::GL
|
||||||
struct GLWrapper;
|
struct GLWrapper;
|
||||||
|
|
||||||
template<typename FuncType, std::size_t FuncIndex, typename Ret, typename... Args>
|
template<typename FuncType, std::size_t FuncIndex, typename Ret, typename... Args>
|
||||||
struct GLWrapper<FuncType, FuncIndex, Ret(Args...)>
|
struct GLWrapper<FuncType, FuncIndex, Ret(GL_APIENTRYP)(Args...)>
|
||||||
{
|
{
|
||||||
static auto WrapErrorHandling()
|
static auto WrapErrorHandling()
|
||||||
{
|
{
|
||||||
|
|
@ -37,8 +37,6 @@ namespace Nz::GL
|
||||||
|
|
||||||
FuncType funcPtr = reinterpret_cast<FuncType>(context->GetFunctionByIndex(FuncIndex));
|
FuncType funcPtr = reinterpret_cast<FuncType>(context->GetFunctionByIndex(FuncIndex));
|
||||||
|
|
||||||
context->ClearErrorStack();
|
|
||||||
|
|
||||||
if constexpr (std::is_same_v<Ret, void>)
|
if constexpr (std::is_same_v<Ret, void>)
|
||||||
{
|
{
|
||||||
funcPtr(std::forward<Args>(args)...);
|
funcPtr(std::forward<Args>(args)...);
|
||||||
|
|
@ -79,16 +77,14 @@ namespace Nz::GL
|
||||||
|
|
||||||
func = reinterpret_cast<FuncType>(originalFuncPtr);
|
func = reinterpret_cast<FuncType>(originalFuncPtr);
|
||||||
|
|
||||||
#if defined(NAZARA_OPENGLRENDERER_DEBUG) && (!defined(NAZARA_COMPILER_MSVC) || defined(NAZARA_PLATFORM_x64))
|
if (func && wrapErrorHandling)
|
||||||
if (func)
|
|
||||||
{
|
{
|
||||||
if (std::strcmp(funcName, "glGetError") != 0) //< Prevent infinite recursion
|
if (std::strcmp(funcName, "glGetError") != 0) //< Prevent infinite recursion
|
||||||
{
|
{
|
||||||
using Wrapper = GLWrapper<FuncType, FuncIndex, std::remove_pointer_t<FuncType>>;
|
using Wrapper = GLWrapper<FuncType, FuncIndex, FuncType>;
|
||||||
func = Wrapper::WrapErrorHandling();
|
func = Wrapper::WrapErrorHandling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!func)
|
if (!func)
|
||||||
{
|
{
|
||||||
|
|
@ -105,6 +101,7 @@ namespace Nz::GL
|
||||||
}
|
}
|
||||||
|
|
||||||
Context& context;
|
Context& context;
|
||||||
|
bool wrapErrorHandling = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -326,6 +323,7 @@ namespace Nz::GL
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolLoader loader(*this);
|
SymbolLoader loader(*this);
|
||||||
|
loader.wrapErrorHandling = params.wrapErrorHandling;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue