From 0e18b146055efd18029c4ac5553fd1e53dfbbfc8 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 14 Dec 2017 11:44:48 +0100 Subject: [PATCH] added debug-event-markers for opengl so that you're able to set markers for renderdoc or other gpu debuggers what your program is currently doing --- src/external/glad.h | 25 +++++++++++++++++++++++++ src/rlgl.c | 8 ++++++++ src/rlgl.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/src/external/glad.h b/src/external/glad.h index ab5947e6..70dbc739 100644 --- a/src/external/glad.h +++ b/src/external/glad.h @@ -3446,6 +3446,19 @@ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC)(GLenum sfactorRGB, GLenum GLAPI PFNGLBLENDFUNCSEPARATEEXTPROC glad_glBlendFuncSeparateEXT; #define glBlendFuncSeparateEXT glad_glBlendFuncSeparateEXT #endif +#ifndef GL_EXT_debug_marker +#define GL_EXT_debug_marker 1 +GLAPI int GLAD_GL_EXT_debug_marker; +typedef void (APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC)(GLsizei length, const GLchar *marker); +GLAPI PFNGLINSERTEVENTMARKEREXTPROC glad_glInsertEventMarkerEXT; +#define glInsertEventMarkerEXT glad_glInsertEventMarkerEXT +typedef void (APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC)(GLsizei length, const GLchar *marker); +GLAPI PFNGLPUSHGROUPMARKEREXTPROC glad_glPushGroupMarkerEXT; +#define glPushGroupMarkerEXT glad_glPushGroupMarkerEXT +typedef void (APIENTRYP PFNGLPOPGROUPMARKEREXTPROC)(void); +GLAPI PFNGLPOPGROUPMARKEREXTPROC glad_glPopGroupMarkerEXT; +#define glPopGroupMarkerEXT glad_glPopGroupMarkerEXT +#endif #ifndef GL_EXT_framebuffer_blit #define GL_EXT_framebuffer_blit 1 GLAPI int GLAD_GL_EXT_framebuffer_blit; @@ -4209,6 +4222,7 @@ int GLAD_GL_ARB_vertex_shader; int GLAD_GL_ARB_vertex_attrib_binding; int GLAD_GL_ARB_vertex_program; int GLAD_GL_EXT_texture_compression_s3tc; +int GLAD_GL_EXT_debug_marker; int GLAD_GL_EXT_texture_swizzle; int GLAD_GL_ARB_texture_multisample; int GLAD_GL_ARB_texture_rg; @@ -4391,6 +4405,9 @@ PFNGLGETVARIANTARRAYOBJECTIVATIPROC glad_glGetVariantArrayObjectivATI; PFNGLBLENDCOLOREXTPROC glad_glBlendColorEXT; PFNGLBLENDEQUATIONSEPARATEEXTPROC glad_glBlendEquationSeparateEXT; PFNGLBLENDFUNCSEPARATEEXTPROC glad_glBlendFuncSeparateEXT; +PFNGLINSERTEVENTMARKEREXTPROC glad_glInsertEventMarkerEXT; +PFNGLPUSHGROUPMARKEREXTPROC glad_glPushGroupMarkerEXT; +PFNGLPOPGROUPMARKEREXTPROC glad_glPopGroupMarkerEXT; PFNGLBLITFRAMEBUFFEREXTPROC glad_glBlitFramebufferEXT; PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC glad_glRenderbufferStorageMultisampleEXT; PFNGLISRENDERBUFFEREXTPROC glad_glIsRenderbufferEXT; @@ -5190,6 +5207,12 @@ static void load_GL_EXT_blend_func_separate(GLADloadproc load) { if(!GLAD_GL_EXT_blend_func_separate) return; glad_glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC)load("glBlendFuncSeparateEXT"); } +static void load_GL_EXT_debug_marker(GLADloadproc load) { + if(!GLAD_GL_EXT_debug_marker) return; + glad_glInsertEventMarkerEXT = (PFNGLINSERTEVENTMARKEREXTPROC)load("glInsertEventMarkerEXT"); + glad_glPushGroupMarkerEXT = (PFNGLPUSHGROUPMARKEREXTPROC)load("glPushGroupMarkerEXT"); + glad_glPopGroupMarkerEXT = (PFNGLPOPGROUPMARKEREXTPROC)load("glPopGroupMarkerEXT"); +} static void load_GL_EXT_framebuffer_blit(GLADloadproc load) { if(!GLAD_GL_EXT_framebuffer_blit) return; glad_glBlitFramebufferEXT = (PFNGLBLITFRAMEBUFFEREXTPROC)load("glBlitFramebufferEXT"); @@ -5316,6 +5339,7 @@ static int find_extensionsGL(void) { GLAD_GL_EXT_blend_color = has_ext("GL_EXT_blend_color"); GLAD_GL_EXT_blend_equation_separate = has_ext("GL_EXT_blend_equation_separate"); GLAD_GL_EXT_blend_func_separate = has_ext("GL_EXT_blend_func_separate"); + GLAD_GL_EXT_debug_marker = has_ext("GL_EXT_debug_marker"); GLAD_GL_EXT_framebuffer_blit = has_ext("GL_EXT_framebuffer_blit"); GLAD_GL_EXT_framebuffer_multisample = has_ext("GL_EXT_framebuffer_multisample"); GLAD_GL_EXT_framebuffer_multisample_blit_scaled = has_ext("GL_EXT_framebuffer_multisample_blit_scaled"); @@ -5430,6 +5454,7 @@ int gladLoadGLLoader(GLADloadproc load) { load_GL_EXT_blend_color(load); load_GL_EXT_blend_equation_separate(load); load_GL_EXT_blend_func_separate(load); + load_GL_EXT_debug_marker(load); load_GL_EXT_framebuffer_blit(load); load_GL_EXT_framebuffer_multisample(load); load_GL_EXT_framebuffer_object(load); diff --git a/src/rlgl.c b/src/rlgl.c index 5db6f1cc..e34e48da 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -307,6 +307,8 @@ static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays; //static PFNGLISVERTEXARRAYOESPROC glIsVertexArray; // NOTE: Fails in WebGL, omitted #endif +static bool debugMarkerSupported = false; + // Compressed textures support flags static bool texCompDXTSupported = false; // DDS texture compression support static bool texNPOTSupported = false; // NPOT textures full support @@ -1135,6 +1137,10 @@ void rlglInit(int width, int height) glGetFloatv(0x84FF, &maxAnisotropicLevel); // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT } + if(strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) { + debugMarkerSupported = true; + } + // Clamp mirror wrap mode supported if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texClampMirrorSupported = true; } @@ -1160,6 +1166,8 @@ void rlglInit(int width, int height) if (texAnisotropicFilterSupported) TraceLog(LOG_INFO, "[EXTENSION] Anisotropic textures filtering supported (max: %.0fX)", maxAnisotropicLevel); if (texClampMirrorSupported) TraceLog(LOG_INFO, "[EXTENSION] Clamp mirror wrap texture mode supported"); + if (debugMarkerSupported) TraceLog(LOG_INFO, "[EXTENSION] Debug Marker supported"); + // Initialize buffers, default shaders and default textures //---------------------------------------------------------- diff --git a/src/rlgl.h b/src/rlgl.h index a54a912f..93afb44e 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -440,6 +440,9 @@ void rlUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update ve void rlDrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform void rlUnloadMesh(Mesh *mesh); // Unload mesh data from CPU and GPU +// Debug Marker for Analysis +void rlSetMarker(const char *text); + // NOTE: There is a set of shader related functions that are available to end user, // to avoid creating function wrappers through core module, they have been directly declared in raylib.h