Drain errors in [E]GLCheck via loop

This commit is contained in:
vittorioromeo 2024-09-26 15:10:04 +02:00 committed by Chris Thrasher
parent 7cec342b2b
commit eb4a2dbe0f
2 changed files with 54 additions and 28 deletions

View File

@ -29,10 +29,15 @@
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/Graphics/GLExtensions.hpp>
#include <SFML/System/Err.hpp>
#include <filesystem>
#include <string_view>
#include <type_traits>
namespace sf::priv
{
////////////////////////////////////////////////////////////
@ -56,16 +61,24 @@ bool glCheckError(const std::filesystem::path& file, unsigned int line, std::str
#define glCheck(...) \
[](auto&& glCheckInternalFunction) \
{ \
if (const GLenum glCheckInternalError = glGetError(); glCheckInternalError != GL_NO_ERROR) \
sf::err() << "OpenGL error (" << glCheckInternalError << ") detected during glCheck call" << std::endl; \
\
if constexpr (!std::is_void_v<decltype(glCheckInternalFunction())>) \
{ \
const auto glCheckInternalReturnValue = glCheckInternalFunction(); \
sf::priv::glCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__); \
\
while (!sf::priv::glCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__)) \
/* no-op */; \
\
return glCheckInternalReturnValue; \
} \
else \
{ \
glCheckInternalFunction(); \
sf::priv::glCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__); \
\
while (!sf::priv::glCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__)) \
/* no-op */; \
} \
}([&]() { return __VA_ARGS__; })
#else

View File

@ -29,8 +29,13 @@
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/System/Err.hpp>
#include <glad/egl.h>
#include <filesystem>
#include <string_view>
#include <type_traits>
namespace sf::priv
@ -57,16 +62,24 @@ bool eglCheckError(const std::filesystem::path& file, unsigned int line, std::st
#define eglCheck(...) \
[](auto&& eglCheckInternalFunction) \
{ \
if (const EGLint eglCheckInternalError = eglGetError(); eglCheckInternalError != EGL_SUCCESS) \
sf::err() << "EGL error (" << eglCheckInternalError << ") detected during eglCheck call" << std::endl; \
\
if constexpr (!std::is_void_v<decltype(eglCheckInternalFunction())>) \
{ \
const auto eglCheckInternalReturnValue = eglCheckInternalFunction(); \
sf::priv::eglCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__); \
\
while (!sf::priv::eglCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__)) \
/* no-op */; \
\
return eglCheckInternalReturnValue; \
} \
else \
{ \
eglCheckInternalFunction(); \
sf::priv::eglCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__); \
\
while (!sf::priv::eglCheckError(__FILE__, static_cast<unsigned int>(__LINE__), #__VA_ARGS__)) \
/* no-op */; \
} \
}([&]() { return __VA_ARGS__; })