From ad7e7ae1cd65e1df26bb156054e4e230d8f5a587 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 4 Jun 2020 14:48:52 +0200 Subject: [PATCH] Added tech ENABLE_OPENGL_ERROR_LOGGING -> log opengl errors when SLIC3R_LOGLEVEL=5 --- src/libslic3r/Technologies.hpp | 3 +++ src/slic3r/GUI/3DScene.cpp | 27 +++++++++++++++++++++++++++ src/slic3r/GUI/3DScene.hpp | 7 +++++++ 3 files changed, 37 insertions(+) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 0c5720c6b..e0d534e00 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -48,5 +48,8 @@ // Enable smoothing of objects normals #define ENABLE_SMOOTH_NORMALS (0 && ENABLE_2_3_0_ALPHA1) +// Enable error logging for OpenGL calls when SLIC3R_LOGLEVEL >= 5 +#define ENABLE_OPENGL_ERROR_LOGGING (1 && ENABLE_2_3_0_ALPHA1) + #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index dc57500c4..4b3864552 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -39,6 +39,32 @@ #include +#if ENABLE_OPENGL_ERROR_LOGGING +void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char* function_name) +{ +#if NDEBUG + if (Slic3r::get_logging_level() < 5) + return; +#endif // NDEBUG + + GLenum err = glGetError(); + if (err == GL_NO_ERROR) + return; + const char* sErr = 0; + switch (err) { + case GL_INVALID_ENUM: sErr = "Invalid Enum"; break; + case GL_INVALID_VALUE: sErr = "Invalid Value"; break; + // be aware that GL_INVALID_OPERATION is generated if glGetError is executed between the execution of glBegin and the corresponding execution of glEnd + case GL_INVALID_OPERATION: sErr = "Invalid Operation"; break; + case GL_STACK_OVERFLOW: sErr = "Stack Overflow"; break; + case GL_STACK_UNDERFLOW: sErr = "Stack Underflow"; break; + case GL_OUT_OF_MEMORY: sErr = "Out Of Memory"; break; + default: sErr = "Unknown"; break; + } + BOOST_LOG_TRIVIAL(error) << "OpenGL error in " << file_name << ":" << line << ", function " << function_name << "() : " << (int)err << " - " << sErr; + assert(false); +} +#else #ifdef HAS_GLSAFE void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name) { @@ -60,6 +86,7 @@ void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char assert(false); } #endif +#endif // ENABLE_OPENGL_ERROR_LOGGING namespace Slic3r { diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index da111d7aa..410a3fbcd 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -10,6 +10,12 @@ #include +#if ENABLE_OPENGL_ERROR_LOGGING +extern void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char* function_name); +inline void glAssertRecentCall() { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } +#define glsafe(cmd) do { cmd; glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false) +#define glcheck() do { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false) +#else #ifndef NDEBUG #define HAS_GLSAFE #endif @@ -24,6 +30,7 @@ inline void glAssertRecentCall() { } #define glsafe(cmd) cmd #define glcheck() #endif +#endif // ENABLE_OPENGL_ERROR_LOGGING namespace Slic3r { namespace GUI {