diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc index 04e8985902d..953536de460 100644 --- a/source/blender/gpu/opengl/gl_batch.cc +++ b/source/blender/gpu/opengl/gl_batch.cc @@ -327,6 +327,8 @@ void GLBatch::bind(int i_first) void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) { + GL_CHECK_ERROR("Batch Pre drawing"); + this->bind(i_first); BLI_assert(v_count > 0 && i_count > 0); @@ -353,6 +355,7 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) glDrawElementsInstancedBaseVertex( gl_type, v_count, index_type, v_first_ofs, i_count, base_index); } + GL_CHECK_ERROR("Batch Post-drawing Indexed"); } else { #ifdef __APPLE__ @@ -367,6 +370,7 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) #ifdef __APPLE__ glEnable(GL_PRIMITIVE_RESTART); #endif + GL_CHECK_ERROR("Batch Post-drawing Non-indexed"); } } diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index 11f313f639b..2ac361d28e1 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -22,6 +22,7 @@ */ #include "BLI_assert.h" +#include "BLI_system.h" #include "BLI_utildefines.h" #include "GPU_framebuffer.h" @@ -238,3 +239,37 @@ void GLContext::framebuffer_unregister(struct GPUFrameBuffer *fb) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Error Checking + * + * This is only useful for implementation that does not support the KHR_debug extension. + * \{ */ + +void GLContext::check_error(const char *info) +{ + GLenum error = glGetError(); + +#define ERROR_CASE(err) \ + case err: \ + fprintf(stderr, "GL error: %s : %s\n", #err, info); \ + BLI_system_backtrace(stderr); \ + break; + + switch (error) { + ERROR_CASE(GL_INVALID_ENUM) + ERROR_CASE(GL_INVALID_VALUE) + ERROR_CASE(GL_INVALID_OPERATION) + ERROR_CASE(GL_INVALID_FRAMEBUFFER_OPERATION) + ERROR_CASE(GL_OUT_OF_MEMORY) + ERROR_CASE(GL_STACK_UNDERFLOW) + ERROR_CASE(GL_STACK_OVERFLOW) + case GL_NO_ERROR: + break; + default: + fprintf(stderr, "Unknown GL error: %x : %s", error, info); + break; + } +} + +/** \} */ diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index ee8189255ca..e16f4bbf076 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -34,6 +34,15 @@ #include +#ifdef DEBUG +/* Enabled on MacOS by default since there is no support for debug callbacks. */ +# ifdef __APPLE__ +# define GL_CHECK_ERROR(info) GLContext::check_error(info) +# else +# define GL_CHECK_ERROR(info) +# endif +#endif + namespace blender { namespace gpu { @@ -78,6 +87,8 @@ class GLContext : public GPUContext { GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list); ~GLContext(); + static void check_error(const char *info); + void activate(void) override; void deactivate(void) override;