Improve code a bit

Prevent converting back and forth the same function pointer
This commit is contained in:
Jérôme Leclercq 2020-09-03 13:58:45 +02:00
parent 0609a10c25
commit 58efffc51f
1 changed files with 6 additions and 11 deletions

View File

@ -69,11 +69,13 @@ namespace Nz::GL
template<typename FuncType, std::size_t FuncIndex, typename Func> template<typename FuncType, std::size_t FuncIndex, typename Func>
bool Load(Func& func, const char* funcName, bool mandatory, bool implementFallback = true) bool Load(Func& func, const char* funcName, bool mandatory, bool implementFallback = true)
{ {
FuncType originalFunc = LoadRaw<FuncType>(funcName); const Loader& loader = context.GetLoader();
func = originalFunc; GLFunction originalFuncPtr = loader.LoadFunction(funcName);
func = reinterpret_cast<FuncType>(originalFuncPtr);
#if NAZARA_OPENGLRENDERER_DEBUG #if NAZARA_OPENGLRENDERER_DEBUG
if (originalFunc) if (func)
{ {
if (std::strcmp(funcName, "glGetError") != 0) //< Prevent infinite recursion if (std::strcmp(funcName, "glGetError") != 0) //< Prevent infinite recursion
func = GLWrapper<std::remove_pointer_t<FuncType>>::template WrapErrorHandling<FuncType, FuncIndex>(); func = GLWrapper<std::remove_pointer_t<FuncType>>::template WrapErrorHandling<FuncType, FuncIndex>();
@ -89,18 +91,11 @@ namespace Nz::GL
} }
} }
context.m_originalFunctionPointer[FuncIndex] = reinterpret_cast<GLFunction>(originalFunc); context.m_originalFunctionPointer[FuncIndex] = originalFuncPtr;
return func != nullptr; return func != nullptr;
} }
template<typename FuncType>
FuncType LoadRaw(const char* funcName)
{
const Loader& loader = context.GetLoader();
return reinterpret_cast<FuncType>(loader.LoadFunction(funcName));
}
Context& context; Context& context;
}; };