Add setObjectLabel for naming OpenGL functions

Add `OPENGL_PRINTF_FORMAT` and `OPENGL_PRINTF_FORMAT_ATTR` macros for providing
printf diagnostic information across platforms.
This commit is contained in:
Wunkolo 2023-06-19 23:31:14 -07:00
parent c042dbc293
commit 1251cecc88

View file

@ -20,6 +20,7 @@
#pragma once
#include <array>
#include <cassert>
#include <cstdarg>
#include <functional>
#include <initializer_list>
#include <iostream>
@ -43,6 +44,15 @@
#include <span>
#endif
#ifdef _MSC_VER
#include <sal.h>
#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 <class...>
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;