From 058d29ed9a3e971049c0d9d99f1cf571bfb0efae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 31 Aug 2020 19:56:04 +0200 Subject: GHOST: Enable debug context on offscreen context too This was a long standing TODO. This was also preventing debug callbacks form other context than the main window. --- intern/ghost/GHOST_C-api.h | 3 ++- intern/ghost/GHOST_ISystem.h | 2 +- intern/ghost/intern/GHOST_C-api.cpp | 5 +++-- intern/ghost/intern/GHOST_System.h | 2 +- intern/ghost/intern/GHOST_SystemCocoa.h | 2 +- intern/ghost/intern/GHOST_SystemCocoa.mm | 2 +- intern/ghost/intern/GHOST_SystemNULL.h | 2 +- intern/ghost/intern/GHOST_SystemSDL.cpp | 2 +- intern/ghost/intern/GHOST_SystemSDL.h | 2 +- intern/ghost/intern/GHOST_SystemWayland.cpp | 2 +- intern/ghost/intern/GHOST_SystemWayland.h | 2 +- intern/ghost/intern/GHOST_SystemWin32.cpp | 4 ++-- intern/ghost/intern/GHOST_SystemWin32.h | 2 +- intern/ghost/intern/GHOST_SystemX11.cpp | 12 +++++++----- intern/ghost/intern/GHOST_SystemX11.h | 2 +- source/blender/draw/tests/shaders_test.cc | 3 ++- source/blender/windowmanager/intern/wm_window.c | 7 ++++++- 17 files changed, 33 insertions(+), 23 deletions(-) diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index f23742a9166..2046b55c97f 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -202,7 +202,8 @@ extern GHOST_WindowHandle GHOST_CreateDialogWindow(GHOST_SystemHandle systemhand * \param platform_support_callback An optional callback to check platform support * \return A handle to the new context ( == NULL if creation failed). */ -extern GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle); +extern GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle, + GHOST_GLSettings glSettings); /** * Dispose of a context. diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index 04e9d5e4e14..63018a9cee8 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -265,7 +265,7 @@ class GHOST_ISystem { * Never explicitly delete the context, use disposeContext() instead. * \return The new context (or 0 if creation failed). */ - virtual GHOST_IContext *createOffscreenContext() = 0; + virtual GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) = 0; /** * Dispose of a context. diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index 843684b6d2e..e4bb908fec8 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -135,11 +135,12 @@ void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle, system->getAllDisplayDimensions(*width, *height); } -GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle) +GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle, + GHOST_GLSettings glSettings) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; - return (GHOST_ContextHandle)system->createOffscreenContext(); + return (GHOST_ContextHandle)system->createOffscreenContext(glSettings); } GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle, diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index e29a9ba0c29..d5b23d76016 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -115,7 +115,7 @@ class GHOST_System : public GHOST_ISystem { * Never explicitly delete the context, use disposeContext() instead. * \return The new context (or 0 if creation failed). */ - virtual GHOST_IContext *createOffscreenContext() = 0; + virtual GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) = 0; /** * Returns whether a window is valid. diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h index 8e36cebb88a..b89edf8835d 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -116,7 +116,7 @@ class GHOST_SystemCocoa : public GHOST_System { * Never explicitly delete the context, use disposeContext() instead. * \return The new context (or 0 if creation failed). */ - GHOST_IContext *createOffscreenContext(); + GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings); /** * Dispose of a context. diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 5592078e20e..467f59defea 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -765,7 +765,7 @@ GHOST_IWindow *GHOST_SystemCocoa::createWindow(const char *title, * Never explicitly delete the context, use #disposeContext() instead. * \return The new context (or 0 if creation failed). */ -GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext() +GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext(GHOST_GLSettings glSettings) { GHOST_Context *context = new GHOST_ContextCGL(false, NULL, NULL, NULL); if (context->initializeDrawingContext()) diff --git a/intern/ghost/intern/GHOST_SystemNULL.h b/intern/ghost/intern/GHOST_SystemNULL.h index 5becf110b15..faeffffed9e 100644 --- a/intern/ghost/intern/GHOST_SystemNULL.h +++ b/intern/ghost/intern/GHOST_SystemNULL.h @@ -81,7 +81,7 @@ class GHOST_SystemNULL : public GHOST_System { void getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const { /* nop */ } - GHOST_IContext *createOffscreenContext() + GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) { return NULL; } diff --git a/intern/ghost/intern/GHOST_SystemSDL.cpp b/intern/ghost/intern/GHOST_SystemSDL.cpp index b32ec4306e8..1769c432d96 100644 --- a/intern/ghost/intern/GHOST_SystemSDL.cpp +++ b/intern/ghost/intern/GHOST_SystemSDL.cpp @@ -139,7 +139,7 @@ GHOST_TUns8 GHOST_SystemSDL::getNumDisplays() const return SDL_GetNumVideoDisplays(); } -GHOST_IContext *GHOST_SystemSDL::createOffscreenContext() +GHOST_IContext *GHOST_SystemSDL::createOffscreenContext(GHOST_GLSettings glSettings) { GHOST_Context *context = new GHOST_ContextSDL(0, NULL, diff --git a/intern/ghost/intern/GHOST_SystemSDL.h b/intern/ghost/intern/GHOST_SystemSDL.h index 4b2c52f8282..57e8d17861d 100644 --- a/intern/ghost/intern/GHOST_SystemSDL.h +++ b/intern/ghost/intern/GHOST_SystemSDL.h @@ -72,7 +72,7 @@ class GHOST_SystemSDL : public GHOST_System { void getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const; - GHOST_IContext *createOffscreenContext(); + GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings); GHOST_TSuccess disposeContext(GHOST_IContext *context); diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 31110694ea6..81d9824ed26 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -1481,7 +1481,7 @@ void GHOST_SystemWayland::getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUn getMainDisplayDimensions(width, height); } -GHOST_IContext *GHOST_SystemWayland::createOffscreenContext() +GHOST_IContext *GHOST_SystemWayland::createOffscreenContext(GHOST_GLSettings glSettings) { /* Create new off-screen window. */ wl_surface *os_surface = wl_compositor_create_surface(compositor()); diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h index 30ee7679287..10b9ef6bd62 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.h +++ b/intern/ghost/intern/GHOST_SystemWayland.h @@ -62,7 +62,7 @@ class GHOST_SystemWayland : public GHOST_System { void getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const override; - GHOST_IContext *createOffscreenContext() override; + GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) override; GHOST_TSuccess disposeContext(GHOST_IContext *context) override; diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index f59b106afd6..533e51db355 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -328,9 +328,9 @@ GHOST_IWindow *GHOST_SystemWin32::createWindow(const char *title, * Never explicitly delete the window, use #disposeContext() instead. * \return The new context (or 0 if creation failed). */ -GHOST_IContext *GHOST_SystemWin32::createOffscreenContext() +GHOST_IContext *GHOST_SystemWin32::createOffscreenContext(GHOST_GLSettings glSettings) { - bool debug_context = false; /* TODO: inform as a parameter */ + const bool debug_context = (glSettings.flags & GHOST_glDebugContext) != 0; GHOST_Context *context; diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h index 24925b9c403..86916b3aeeb 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.h +++ b/intern/ghost/intern/GHOST_SystemWin32.h @@ -142,7 +142,7 @@ class GHOST_SystemWin32 : public GHOST_System { * Never explicitly delete the window, use disposeContext() instead. * \return The new context (or 0 if creation failed). */ - GHOST_IContext *createOffscreenContext(); + GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings); /** * Dispose of a context. diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index c0676618101..2a07e02706b 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -394,7 +394,7 @@ GHOST_IWindow *GHOST_SystemX11::createWindow(const char *title, * Never explicitly delete the context, use disposeContext() instead. * \return The new context (or 0 if creation failed). */ -GHOST_IContext *GHOST_SystemX11::createOffscreenContext() +GHOST_IContext *GHOST_SystemX11::createOffscreenContext(GHOST_GLSettings glSettings) { // During development: // try 4.x compatibility profile @@ -406,6 +406,8 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext() // try 3.3 core profile // no fallbacks + const bool debug_context = (glSettings.flags & GHOST_glDebugContext) != 0; + #if defined(WITH_GL_PROFILE_CORE) { const char *version_major = (char *)glewGetString(GLEW_VERSION_MAJOR); @@ -446,7 +448,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext() 4, minor, GHOST_OPENGL_EGL_CONTEXT_FLAGS | - (false ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0), + (debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0), GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY, EGL_OPENGL_API); #else @@ -458,7 +460,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext() 4, minor, GHOST_OPENGL_GLX_CONTEXT_FLAGS | - (false ? GLX_CONTEXT_DEBUG_BIT_ARB : 0), + (debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0), GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY); #endif @@ -476,7 +478,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext() 3, 3, GHOST_OPENGL_EGL_CONTEXT_FLAGS | - (false ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0), + (debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0), GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY, EGL_OPENGL_API); #else @@ -488,7 +490,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext() 3, 3, GHOST_OPENGL_GLX_CONTEXT_FLAGS | - (false ? GLX_CONTEXT_DEBUG_BIT_ARB : 0), + (debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0), GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY); #endif diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h index ad58138d416..a852675acfb 100644 --- a/intern/ghost/intern/GHOST_SystemX11.h +++ b/intern/ghost/intern/GHOST_SystemX11.h @@ -153,7 +153,7 @@ class GHOST_SystemX11 : public GHOST_System { * Never explicitly delete the context, use disposeContext() instead. * \return The new context (or 0 if creation failed). */ - GHOST_IContext *createOffscreenContext(); + GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings); /** * Dispose of a context. diff --git a/source/blender/draw/tests/shaders_test.cc b/source/blender/draw/tests/shaders_test.cc index b2f1020ed98..c991b791686 100644 --- a/source/blender/draw/tests/shaders_test.cc +++ b/source/blender/draw/tests/shaders_test.cc @@ -24,8 +24,9 @@ class DrawTest : public ::testing::Test { void SetUp() override { + GHOST_GLSettings glSettings = {0}; ghost_system = GHOST_CreateSystem(); - ghost_context = GHOST_CreateOpenGLContext(ghost_system); + ghost_context = GHOST_CreateOpenGLContext(ghost_system, glSettings); context = GPU_context_create(0); GPU_init(); DRW_draw_state_init_gtests(GPU_SHADER_CFG_DEFAULT); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 04d5aeb337d..0e19f79e659 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -2485,7 +2485,12 @@ void *WM_opengl_context_create(void) */ BLI_assert(BLI_thread_is_main()); BLI_assert(GPU_framebuffer_active_get() == GPU_framebuffer_back_get()); - return GHOST_CreateOpenGLContext(g_system); + + GHOST_GLSettings glSettings = {0}; + if (G.debug & G_DEBUG_GPU) { + glSettings.flags |= GHOST_glDebugContext; + } + return GHOST_CreateOpenGLContext(g_system, glSettings); } void WM_opengl_context_dispose(void *context) -- cgit v1.2.3