[Bf-blender-cvs] [813f1c603f6] temp-drawcontext: Fixes for offscreen drawing context on macOS.
Brecht Van Lommel
noreply at git.blender.org
Sun Feb 25 04:19:40 CET 2018
Commit: 813f1c603f645fd94ab5c84659efd8af15aa5764
Author: Brecht Van Lommel
Date: Sun Feb 25 03:06:13 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rB813f1c603f645fd94ab5c84659efd8af15aa5764
Fixes for offscreen drawing context on macOS.
* Disable multithreaded OpenGL again, it crashes on startup.
* Fix wrong clear context call in GHOST.
* Add GPU_state_init() also for draw context, just to be sure.
* Main fix: add glFlush() to avoid unfinished draw before leaving context.
===================================================================
M intern/ghost/intern/GHOST_ContextCGL.mm
M source/blender/draw/intern/draw_manager.c
M source/blender/windowmanager/intern/wm_init_exit.c
===================================================================
diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm b/intern/ghost/intern/GHOST_ContextCGL.mm
index 598dccdaad7..46993a1cd1d 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.mm
+++ b/intern/ghost/intern/GHOST_ContextCGL.mm
@@ -35,7 +35,7 @@
#include <Cocoa/Cocoa.h>
-#define GHOST_MULTITHREADED_OPENGL
+//#define GHOST_MULTITHREADED_OPENGL
#ifdef GHOST_MULTITHREADED_OPENGL
#include <OpenGL/OpenGL.h>
@@ -174,7 +174,7 @@ GHOST_TSuccess GHOST_ContextCGL::releaseDrawingContext()
{
if (m_openGLContext != nil) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [m_openGLContext clearCurrentContext];
+ [NSOpenGLContext clearCurrentContext];
[pool drain];
return GHOST_kSuccess;
}
@@ -361,8 +361,7 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext()
#ifdef GHOST_MULTITHREADED_OPENGL
//Switch openGL to multhreaded mode
- CGLContextObj cglCtx = (CGLContextObj)[tmpOpenGLContext CGLContextObj];
- if (CGLEnable(cglCtx, kCGLCEMPEngine) == kCGLNoError)
+ if (CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine) == kCGLNoError)
if (m_debug)
fprintf(stderr, "\nSwitched OpenGL to multithreaded mode\n");
#endif
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 678f86ca469..d773ef37820 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -378,7 +378,7 @@ static void *g_ogl_context = NULL;
static Gwn_Context *g_gwn_context = NULL;
/* Mutex to lock the drw manager and avoid concurent context usage. */
-static ThreadMutex cache_rwlock = BLI_MUTEX_INITIALIZER;
+static ThreadMutex g_ogl_context_mutex = BLI_MUTEX_INITIALIZER;
#ifdef USE_GPU_SELECT
static unsigned int g_DRW_select_id = (unsigned int)-1;
@@ -4309,6 +4309,8 @@ void DRW_opengl_context_create(void)
BLI_assert(g_ogl_context == NULL); /* Ensure it's called once */
BLI_assert(BLI_thread_is_main());
+ BLI_mutex_init(&g_ogl_context_mutex);
+
immDeactivate();
/* This changes the active context. */
g_ogl_context = WM_opengl_context_create();
@@ -4327,6 +4329,7 @@ void DRW_opengl_context_destroy(void)
GWN_context_active_set(g_gwn_context);
GWN_context_discard(g_gwn_context);
WM_opengl_context_dispose(g_ogl_context);
+ BLI_mutex_end(&g_ogl_context_mutex);
}
}
@@ -4336,7 +4339,7 @@ void DRW_opengl_context_enable(void)
/* IMPORTANT: We dont support immediate mode in render mode!
* This shall remain in effect until immediate mode supports
* multiple threads. */
- BLI_mutex_lock(&cache_rwlock);
+ BLI_mutex_lock(&g_ogl_context_mutex);
if (BLI_thread_is_main()) {
immDeactivate();
}
@@ -4351,6 +4354,12 @@ void DRW_opengl_context_enable(void)
void DRW_opengl_context_disable(void)
{
if (g_ogl_context != NULL) {
+#ifdef __APPLE__
+ /* Need to flush before disabling draw context, otherwise it does not
+ * always finish drawing and viewport can be empty or partially drawn */
+ glFlush();
+#endif
+
if (BLI_thread_is_main()) {
wm_window_reset_drawable();
}
@@ -4358,7 +4367,8 @@ void DRW_opengl_context_disable(void)
WM_opengl_context_release(g_ogl_context);
GWN_context_active_set(NULL);
}
- BLI_mutex_unlock(&cache_rwlock);
+
+ BLI_mutex_unlock(&g_ogl_context_mutex);
}
}
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 3502e990cd8..20299dbb66d 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -212,6 +212,7 @@ void WM_init(bContext *C, int argc, const char **argv)
DRW_opengl_context_create();
GPU_init();
+ GPU_state_init();
GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
GPU_set_linear_mipmap(true);
More information about the Bf-blender-cvs
mailing list