From 77b3e83795cb6858e7352bfed6d4cac4ed919c66 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Tue, 4 Jun 2024 23:52:12 +0200 Subject: [PATCH 1/2] Send OpenGL errors to log on debug builds --- libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp index 385ddca065..c4d205ad1e 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp @@ -12,7 +12,9 @@ #include #include #include +#include +#include "glad/glad.h" Q_LOGGING_CATEGORY(gpugl45logging, "hifi.gpu.gl45") using namespace gpu; @@ -21,9 +23,27 @@ using namespace gpu::gl45; GLint GL45Backend::MAX_COMBINED_SHADER_STORAGE_BLOCKS{ 0 }; GLint GL45Backend::MAX_UNIFORM_LOCATIONS{ 0 }; +#ifndef QT_NO_DEBUG +static void post_call_callback_gl(const char *name, void *funcptr, int len_args, ...) { + (void)funcptr; + (void)len_args; + + GLenum error_code = glad_glGetError(); + if (error_code != GL_NO_ERROR) { + qCWarning(gpugl45logging) << "OpenGL error" << error_code << "in" << name; + } +} +#endif + + static void staticInit() { static std::once_flag once; std::call_once(once, [&] { +#ifndef QT_NO_DEBUG + // This sets the post call callback to a logging function. By default it prints on + // stderr and skips our log. It only exists in debug builds. + glad_set_post_callback(&post_call_callback_gl); +#endif glGetIntegerv(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &GL45Backend::MAX_COMBINED_SHADER_STORAGE_BLOCKS); glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &GL45Backend::MAX_UNIFORM_LOCATIONS); }); @@ -82,7 +102,7 @@ void GL45Backend::do_drawIndexed(const Batch& batch, size_t paramOffset) { uint32 startIndex = batch._params[paramOffset + 0]._uint; GLenum glType = gl::ELEMENT_TYPE_TO_GL[_input._indexBufferType]; - + auto typeByteSize = TYPE_SIZE[_input._indexBufferType]; GLvoid* indexBufferByteOffset = reinterpret_cast(startIndex * typeByteSize + _input._indexBufferOffset); @@ -148,7 +168,7 @@ void GL45Backend::do_drawIndexedInstanced(const Batch& batch, size_t paramOffset GLenum glType = gl::ELEMENT_TYPE_TO_GL[_input._indexBufferType]; auto typeByteSize = TYPE_SIZE[_input._indexBufferType]; GLvoid* indexBufferByteOffset = reinterpret_cast(startIndex * typeByteSize + _input._indexBufferOffset); - + if (isStereo()) { GLint trueNumInstances = 2 * numInstances; From af2bafe04a305c248227cee703a0daff8a80d04e Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Wed, 5 Jun 2024 00:18:45 +0200 Subject: [PATCH 2/2] Found a better constant to test --- libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp index c4d205ad1e..d65e8b0af9 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp @@ -23,7 +23,7 @@ using namespace gpu::gl45; GLint GL45Backend::MAX_COMBINED_SHADER_STORAGE_BLOCKS{ 0 }; GLint GL45Backend::MAX_UNIFORM_LOCATIONS{ 0 }; -#ifndef QT_NO_DEBUG +#ifdef GLAD_DEBUG static void post_call_callback_gl(const char *name, void *funcptr, int len_args, ...) { (void)funcptr; (void)len_args; @@ -39,7 +39,7 @@ static void post_call_callback_gl(const char *name, void *funcptr, int len_args, static void staticInit() { static std::once_flag once; std::call_once(once, [&] { -#ifndef QT_NO_DEBUG +#ifdef GLAD_DEBUG // This sets the post call callback to a logging function. By default it prints on // stderr and skips our log. It only exists in debug builds. glad_set_post_callback(&post_call_callback_gl);