From b82ccc3b4ec851d24da60f931548f03617236440 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 13 Jun 2016 16:43:33 +0200 Subject: [PATCH] Reverted 6912 with minor changes (LockCtx requires to specify canvas that locks a context). --- 3d-viewer/3d_canvas.cpp | 2 +- 3d-viewer/3d_draw.cpp | 2 +- 3d-viewer/3d_model_viewer/c3d_model_viewer.cpp | 4 ++-- common/gal/opengl/opengl_gal.cpp | 8 ++++---- common/gl_context_mgr.cpp | 12 ++++-------- include/gl_context_mgr.h | 5 +---- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index b2b1d95dfe..cdd1abd49e 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -117,7 +117,7 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList ) : EDA_3D_CANVAS::~EDA_3D_CANVAS() { - GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC ); + GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); ClearLists(); m_init = false; diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index 40c4381b86..ebd0a4953e 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -302,7 +302,7 @@ void EDA_3D_CANVAS::Redraw() // Display build time at the end of build unsigned strtime = GetRunningMicroSecs(); - GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC ); + GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); // Set the OpenGL viewport according to the client size of this canvas. // This is done here rather than in a wxSizeEvent handler because our diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp index 105fc749ff..ee2f4355dd 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp @@ -101,7 +101,7 @@ C3D_MODEL_VIEWER::C3D_MODEL_VIEWER( wxWindow *aParent, C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER() { - GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC ); + GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER" ) ); @@ -205,7 +205,7 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event ) // "Makes the OpenGL state that is represented by the OpenGL rendering // context context current, i.e. it will be used by all subsequent OpenGL calls. // This function may only be called when the window is shown on screen" - GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC ); + GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); // Set the OpenGL viewport according to the client size of this canvas. // This is done here rather than in a wxSizeEvent handler because our diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 717b034a43..998a4a3f7f 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -143,7 +143,7 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, OPENGL_GAL::~OPENGL_GAL() { - GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext ); + GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext, this ); --instanceCounter; glFlush(); @@ -165,7 +165,7 @@ OPENGL_GAL::~OPENGL_GAL() // Are we destroying the last GAL instance? if( instanceCounter == 0 ) { - GL_CONTEXT_MANAGER::Get().LockCtx( glMainContext ); + GL_CONTEXT_MANAGER::Get().LockCtx( glMainContext, this ); if( isBitmapFontLoaded ) { @@ -193,7 +193,7 @@ void OPENGL_GAL::BeginDrawing() prof_start( &totalRealTime ); #endif /* __WXDEBUG__ */ - GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext ); + GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext, this ); #ifdef RETINA_OPENGL_PATCH const float scaleFactor = GetBackingScaleFactor(); @@ -346,7 +346,7 @@ void OPENGL_GAL::EndDrawing() void OPENGL_GAL::BeginUpdate() { - GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext ); + GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext, this ); cachedManager->Map(); } diff --git a/common/gl_context_mgr.cpp b/common/gl_context_mgr.cpp index 4b048cc607..af2863be36 100644 --- a/common/gl_context_mgr.cpp +++ b/common/gl_context_mgr.cpp @@ -58,7 +58,6 @@ void GL_CONTEXT_MANAGER::DestroyCtx( wxGLContext* aContext ) if( m_glCtx == aContext ) { m_glCtx = NULL; - m_glCanvas = NULL; } } @@ -79,12 +78,8 @@ void GL_CONTEXT_MANAGER::LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas ) m_glCtxMutex.lock(); wxGLCanvas* canvas = aCanvas ? aCanvas : m_glContexts.at( aContext ); - if( aContext != m_glCtx || canvas != m_glCanvas ) - { - canvas->SetCurrent( *aContext ); - m_glCanvas = canvas; - m_glCtx = aContext; - } + canvas->SetCurrent( *aContext ); + m_glCtx = aContext; } @@ -95,6 +90,7 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext ) if( m_glCtx == aContext ) { m_glCtxMutex.unlock(); + m_glCtx = NULL; } else { @@ -104,7 +100,7 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext ) GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER() - : m_glCtx( NULL ), m_glCanvas( NULL ) + : m_glCtx( NULL ) { } diff --git a/include/gl_context_mgr.h b/include/gl_context_mgr.h index de45cfab62..1d74fefc2b 100644 --- a/include/gl_context_mgr.h +++ b/include/gl_context_mgr.h @@ -71,7 +71,7 @@ public: * @param aCanvas (optional) allows caller to bind the context to a non-parent canvas * (e.g. when a few canvases share a single GL context). */ - void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas = NULL ); + void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas ); /** * Function UnlockCtx @@ -88,9 +88,6 @@ private: ///> Currently bound GL context. wxGLContext* m_glCtx; - ///> The canvas that uses the current GL context. - wxGLCanvas* m_glCanvas; - ///> Lock to prevent unexpected GL context switching. MUTEX m_glCtxMutex;