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.
This commit is contained in:
Clément Foucault 2020-08-31 19:56:04 +02:00
parent 13b0a697a0
commit 058d29ed9a
17 changed files with 33 additions and 23 deletions

@ -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.

@ -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.

@ -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,

@ -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.

@ -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.

@ -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())

@ -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;
}

@ -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,

@ -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);

@ -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());

@ -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;

@ -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;

@ -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.

@ -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

@ -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.

@ -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);

@ -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)