Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-06-11 12:49:10 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-06-11 14:55:02 +0300
commit128926a41b368e166af63515370d9c9367e3dda2 (patch)
tree54eb6a813e6e8afab6d76e65b24f597bd399af1e /intern
parent1463ec68962380b015d7cbf3f65eadbd06ff3c4a (diff)
GHOST: Delay opengl context initialization
This way they can be init in their owner thread. Contexts should not be shared accross threads. Once you make a context active on a thread it is owned by the thread. This commit only have the GLX backend updated but should not break orther platform.
Diffstat (limited to 'intern')
-rw-r--r--intern/gawain/src/gwn_vertex_array_id.cpp5
-rw-r--r--intern/ghost/intern/GHOST_ContextGLX.cpp30
-rw-r--r--intern/ghost/intern/GHOST_ContextGLX.h2
3 files changed, 29 insertions, 8 deletions
diff --git a/intern/gawain/src/gwn_vertex_array_id.cpp b/intern/gawain/src/gwn_vertex_array_id.cpp
index ad60dea7542..2ab38a8fe18 100644
--- a/intern/gawain/src/gwn_vertex_array_id.cpp
+++ b/intern/gawain/src/gwn_vertex_array_id.cpp
@@ -18,7 +18,7 @@
#include <mutex>
#include <unordered_set>
-#if TRUST_NO_ONE
+#if 0
extern "C" {
extern int BLI_thread_is_main(void); // Blender-specific function
}
@@ -68,7 +68,8 @@ static void clear_orphans(Gwn_Context* ctx)
Gwn_Context* GWN_context_create(void)
{
#if TRUST_NO_ONE
- assert(thread_is_main());
+ /* We cannot rely on this anymore. */
+ // assert(thread_is_main());
#endif
Gwn_Context* ctx = new Gwn_Context;
glGenVertexArrays(1, &ctx->default_vao);
diff --git a/intern/ghost/intern/GHOST_ContextGLX.cpp b/intern/ghost/intern/GHOST_ContextGLX.cpp
index 815189b9098..1365a1a9c24 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.cpp
+++ b/intern/ghost/intern/GHOST_ContextGLX.cpp
@@ -110,6 +110,9 @@ GHOST_TSuccess GHOST_ContextGLX::swapBuffers()
GHOST_TSuccess GHOST_ContextGLX::activateDrawingContext()
{
+ if (m_init == false) {
+ initContext();
+ }
if (m_display) {
return ::glXMakeCurrent(m_display, m_window, m_context) ? GHOST_kSuccess : GHOST_kFailure;
}
@@ -184,7 +187,8 @@ const bool GLXEW_ARB_create_context_robustness =
glxewInit();
#endif /* USE_GLXEW_INIT_WORKAROUND */
-
+ /* Only init the non-offscreen context directly */
+ const bool do_init = (m_window != None);
if (GLXEW_ARB_create_context) {
int profileBitCore = m_contextProfileMask & GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
@@ -304,12 +308,27 @@ const bool GLXEW_ARB_create_context_robustness =
GHOST_TSuccess success;
if (m_context != NULL) {
- const unsigned char *version;
-
if (!s_sharedContext)
s_sharedContext = m_context;
s_sharedCount++;
+ }
+
+ if (do_init) {
+ success = initContext();
+ }
+
+ GHOST_X11_ERROR_HANDLERS_RESTORE(handler_store);
+
+ return success;
+}
+
+GHOST_TSuccess GHOST_ContextGLX::initContext()
+{
+ GHOST_TSuccess success;
+
+ if (m_context != NULL) {
+ const unsigned char *version;
glXMakeCurrent(m_display, m_window, m_context);
@@ -341,13 +360,12 @@ const bool GLXEW_ARB_create_context_robustness =
success = GHOST_kFailure;
}
-
- GHOST_X11_ERROR_HANDLERS_RESTORE(handler_store);
+ /* We tag as init even if it fails. */
+ m_init = true;
return success;
}
-
GHOST_TSuccess GHOST_ContextGLX::releaseNativeHandles()
{
m_window = 0;
diff --git a/intern/ghost/intern/GHOST_ContextGLX.h b/intern/ghost/intern/GHOST_ContextGLX.h
index ded1b293659..b4d6a841d72 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.h
+++ b/intern/ghost/intern/GHOST_ContextGLX.h
@@ -116,6 +116,7 @@ public:
private:
void initContextGLXEW();
+ GHOST_TSuccess initContext();
Display *m_display;
GLXFBConfig m_fbconfig;
@@ -128,6 +129,7 @@ private:
const int m_contextResetNotificationStrategy;
GLXContext m_context;
+ bool m_init;
/** The first created OpenGL context (for sharing display lists) */
static GLXContext s_sharedContext;