From 1251cecc8805c625e399cd5683cac8b78421f06f Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Mon, 19 Jun 2023 23:31:14 -0700 Subject: [PATCH] Add `setObjectLabel` for naming OpenGL functions Add `OPENGL_PRINTF_FORMAT` and `OPENGL_PRINTF_FORMAT_ATTR` macros for providing printf diagnostic information across platforms. --- include/opengl.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/opengl.hpp b/include/opengl.hpp index 16ed8221..9ecbc4c6 100644 --- a/include/opengl.hpp +++ b/include/opengl.hpp @@ -20,6 +20,7 @@ #pragma once #include #include +#include #include #include #include @@ -43,6 +44,15 @@ #include #endif +#ifdef _MSC_VER +#include +#define OPENGL_PRINTF_FORMAT _Printf_format_string_ +#define OPENGL_PRINTF_FORMAT_ATTR(format_arg_index, dots_arg_index) +#else +#define OPENGL_PRINTF_FORMAT +#define OPENGL_PRINTF_FORMAT_ATTR(format_arg_index, dots_arg_index) __attribute__((__format__(__printf__, format_arg_index, dots_arg_index))) +#endif + // Uncomment the following define if you want GL objects to automatically free themselves when their lifetime ends // #define OPENGL_DESTRUCTORS @@ -53,6 +63,16 @@ namespace OpenGL { template constexpr std::false_type AlwaysFalse{}; + OPENGL_PRINTF_FORMAT_ATTR(3, 4) + static void setObjectLabel(GLenum identifier, GLuint name, OPENGL_PRINTF_FORMAT const char* format, ...) { + GLchar label[256] = {}; + va_list args; + va_start(args, format); + const GLsizei length = vsnprintf(label, std::size(label), format, args); + va_end(args); + glObjectLabel(identifier, name, length, label); + } + struct VertexArray { GLuint m_handle = 0;