From d62261e7a4444ea166e36f675a0b104c5994a8a6 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 18 Jan 2025 18:51:23 +1000 Subject: [PATCH] GPUDevice: Allow nested GL_SCOPE macros --- src/util/gpu_device.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/gpu_device.h b/src/util/gpu_device.h index 5647ede92..aecfdd605 100644 --- a/src/util/gpu_device.h +++ b/src/util/gpu_device.h @@ -1001,6 +1001,10 @@ ALWAYS_INLINE void GPUDevice::PooledTextureDeleter::operator()(GPUTexture* const g_gpu_device->RecycleTexture(std::unique_ptr(tex)); } +// C preprocessor workarounds. +#define GL_TOKEN_PASTE(x, y) x##y +#define GL_TOKEN_PASTE2(x, y) GL_TOKEN_PASTE(x, y) + // Macros for debug messages. #ifdef ENABLE_GPU_OBJECT_NAMES struct GLAutoPop @@ -1025,7 +1029,7 @@ struct GLAutoPop } }; -#define GL_SCOPE(name) GLAutoPop gl_auto_pop(name) +#define GL_SCOPE(name) GLAutoPop GL_TOKEN_PASTE2(gl_auto_pop_, __LINE__)(name) #define GL_PUSH(name) \ do \ { \ @@ -1051,7 +1055,7 @@ struct GLAutoPop (obj)->SetDebugName(name); \ } while (0) -#define GL_SCOPE_FMT(...) GLAutoPop gl_auto_pop(__VA_ARGS__) +#define GL_SCOPE_FMT(...) GLAutoPop GL_TOKEN_PASTE2(gl_auto_pop_, __LINE__)(__VA_ARGS__) #define GL_PUSH_FMT(...) \ do \ { \