mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Move GL_CONTEXT_MGR into PGM_BASE singleton
This is the second try at 5326c36a5f. The difference here is that we have moved GL_CONTEXT_MGR into kicommon first which will hopefully address some of the Windows linkage issues The GL context lock needs to be shared across kifaces. Otherwise, we can end up blocking the lock from one kiface. Unfortunately, I can't find the issue in GitLab right now for where the footprint viewer shows a blank screen after opening too many contexts. But that's what this fixes.
This commit is contained in:
parent
d48c40ba26
commit
09e30adbb1
@ -187,7 +187,8 @@ void EDA_3D_CANVAS::releaseOpenGL()
|
|||||||
{
|
{
|
||||||
if( m_glRC )
|
if( m_glRC )
|
||||||
{
|
{
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
GL_CONTEXT_MANAGER* gl_mgr = Pgm().GetGLContextManager();
|
||||||
|
gl_mgr->LockCtx( m_glRC, this );
|
||||||
|
|
||||||
delete m_3d_render_raytracing;
|
delete m_3d_render_raytracing;
|
||||||
m_3d_render_raytracing = nullptr;
|
m_3d_render_raytracing = nullptr;
|
||||||
@ -198,8 +199,8 @@ void EDA_3D_CANVAS::releaseOpenGL()
|
|||||||
// This is just a copy of a pointer, can safely be set to NULL.
|
// This is just a copy of a pointer, can safely be set to NULL.
|
||||||
m_3d_render = nullptr;
|
m_3d_render = nullptr;
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
gl_mgr->UnlockCtx( m_glRC );
|
||||||
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
|
gl_mgr->DestroyCtx( m_glRC );
|
||||||
m_glRC = nullptr;
|
m_glRC = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,6 +384,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
INFOBAR_REPORTER warningReporter( m_parentInfoBar );
|
INFOBAR_REPORTER warningReporter( m_parentInfoBar );
|
||||||
STATUSBAR_REPORTER activityReporter( m_parentStatusBar, EDA_3D_VIEWER_STATUSBAR::ACTIVITY );
|
STATUSBAR_REPORTER activityReporter( m_parentStatusBar, EDA_3D_VIEWER_STATUSBAR::ACTIVITY );
|
||||||
int64_t start_time = GetRunningMicroSecs();
|
int64_t start_time = GetRunningMicroSecs();
|
||||||
|
GL_CONTEXT_MANAGER* gl_mgr = Pgm().GetGLContextManager();
|
||||||
|
|
||||||
// "Makes the OpenGL state that is represented by the OpenGL rendering
|
// "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.
|
// context context current, i.e. it will be used by all subsequent OpenGL calls.
|
||||||
@ -390,7 +392,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
|
|
||||||
// Explicitly create a new rendering context instance for this canvas.
|
// Explicitly create a new rendering context instance for this canvas.
|
||||||
if( m_glRC == nullptr )
|
if( m_glRC == nullptr )
|
||||||
m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
|
m_glRC = gl_mgr->CreateCtx( this );
|
||||||
|
|
||||||
// CreateCtx could and does fail per sentry crash events, lets be graceful
|
// CreateCtx could and does fail per sentry crash events, lets be graceful
|
||||||
if( m_glRC == nullptr )
|
if( m_glRC == nullptr )
|
||||||
@ -401,7 +403,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
gl_mgr->LockCtx( m_glRC, this );
|
||||||
|
|
||||||
// Set the OpenGL viewport according to the client size of this canvas.
|
// Set the OpenGL viewport according to the client size of this canvas.
|
||||||
// This is done here rather than in a wxSizeEvent handler because our
|
// This is done here rather than in a wxSizeEvent handler because our
|
||||||
@ -418,7 +420,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
{
|
{
|
||||||
if( !initializeOpenGL() )
|
if( !initializeOpenGL() )
|
||||||
{
|
{
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
gl_mgr->UnlockCtx( m_glRC );
|
||||||
m_is_currently_painting.clear();
|
m_is_currently_painting.clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -440,7 +442,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
gl_mgr->UnlockCtx( m_glRC );
|
||||||
m_is_currently_painting.clear();
|
m_is_currently_painting.clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -528,7 +530,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
m_is_opengl_version_supported = false;
|
m_is_opengl_version_supported = false;
|
||||||
m_opengl_supports_raytracing = false;
|
m_opengl_supports_raytracing = false;
|
||||||
m_is_opengl_initialized = false;
|
m_is_opengl_initialized = false;
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
gl_mgr->UnlockCtx( m_glRC );
|
||||||
m_is_currently_painting.clear();
|
m_is_currently_painting.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -553,7 +555,7 @@ void EDA_3D_CANVAS::DoRePaint()
|
|||||||
// commands is displayed on the window."
|
// commands is displayed on the window."
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
gl_mgr->UnlockCtx( m_glRC );
|
||||||
|
|
||||||
if( m_mouse_was_moved || m_camera_is_moving )
|
if( m_mouse_was_moved || m_camera_is_moving )
|
||||||
{
|
{
|
||||||
|
@ -109,16 +109,17 @@ EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER( wxWindow* aParent, const wxGLAttribute
|
|||||||
EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER()
|
EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER()
|
||||||
{
|
{
|
||||||
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER" ) );
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER" ) );
|
||||||
|
GL_CONTEXT_MANAGER* gl_mgr = Pgm().GetGLContextManager();
|
||||||
|
|
||||||
if( m_glRC )
|
if( m_glRC )
|
||||||
{
|
{
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
gl_mgr->LockCtx( m_glRC, this );
|
||||||
|
|
||||||
delete m_ogl_3dmodel;
|
delete m_ogl_3dmodel;
|
||||||
m_ogl_3dmodel = nullptr;
|
m_ogl_3dmodel = nullptr;
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
gl_mgr->UnlockCtx( m_glRC );
|
||||||
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
|
gl_mgr->DestroyCtx( m_glRC );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +257,7 @@ void EDA_3D_MODEL_VIEWER::OnPaint( wxPaintEvent& event )
|
|||||||
// context context current, i.e. it will be used by all subsequent OpenGL calls.
|
// 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"
|
// This function may only be called when the window is shown on screen"
|
||||||
if( m_glRC == nullptr )
|
if( m_glRC == nullptr )
|
||||||
m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
|
m_glRC = Pgm().GetGLContextManager()->CreateCtx( this );
|
||||||
|
|
||||||
// CreateCtx could and does fail per sentry crash events, lets be graceful
|
// CreateCtx could and does fail per sentry crash events, lets be graceful
|
||||||
if( m_glRC == nullptr )
|
if( m_glRC == nullptr )
|
||||||
@ -265,7 +266,7 @@ void EDA_3D_MODEL_VIEWER::OnPaint( wxPaintEvent& event )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
Pgm().GetGLContextManager()->LockCtx( m_glRC, this );
|
||||||
|
|
||||||
// Set the OpenGL viewport according to the client size of this canvas.
|
// Set the OpenGL viewport according to the client size of this canvas.
|
||||||
// This is done here rather than in a wxSizeEvent handler because our
|
// This is done here rather than in a wxSizeEvent handler because our
|
||||||
@ -383,7 +384,7 @@ void EDA_3D_MODEL_VIEWER::OnPaint( wxPaintEvent& event )
|
|||||||
// commands is displayed on the window."
|
// commands is displayed on the window."
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
Pgm().GetGLContextManager()->UnlockCtx( m_glRC );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <3d_math.h>
|
#include <3d_math.h>
|
||||||
#include <glm/geometric.hpp>
|
#include <glm/geometric.hpp>
|
||||||
#include <lset.h>
|
#include <lset.h>
|
||||||
|
#include <pgm_base.h>
|
||||||
#include <math/util.h> // for KiROUND
|
#include <math/util.h> // for KiROUND
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -490,7 +491,7 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
|
|||||||
// Careful here!
|
// Careful here!
|
||||||
// We are in the middle of rendering and the reload method may show
|
// We are in the middle of rendering and the reload method may show
|
||||||
// a dialog box that requires the opengl context for a redraw
|
// a dialog box that requires the opengl context for a redraw
|
||||||
GL_CONTEXT_MANAGER::Get().RunWithoutCtxLock( [this, aStatusReporter, aWarningReporter]()
|
Pgm().GetGLContextManager()->RunWithoutCtxLock( [this, aStatusReporter, aWarningReporter]()
|
||||||
{
|
{
|
||||||
reload( aStatusReporter, aWarningReporter );
|
reload( aStatusReporter, aWarningReporter );
|
||||||
} );
|
} );
|
||||||
|
@ -27,14 +27,6 @@
|
|||||||
#include <wx/debug.h>
|
#include <wx/debug.h>
|
||||||
|
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER& GL_CONTEXT_MANAGER::Get()
|
|
||||||
{
|
|
||||||
static GL_CONTEXT_MANAGER instance;
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxGLContext* GL_CONTEXT_MANAGER::CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther )
|
wxGLContext* GL_CONTEXT_MANAGER::CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther )
|
||||||
{
|
{
|
||||||
wxGLContext* context = new wxGLContext( aCanvas, aOther );
|
wxGLContext* context = new wxGLContext( aCanvas, aOther );
|
||||||
@ -124,9 +116,3 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER()
|
|
||||||
: m_glCtx( nullptr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include <bitmap_base.h>
|
#include <bitmap_base.h>
|
||||||
#include <bezier_curves.h>
|
#include <bezier_curves.h>
|
||||||
#include <math/util.h> // for KiROUND
|
#include <math/util.h> // for KiROUND
|
||||||
|
#include <pgm_base.h>
|
||||||
#include <trace_helpers.h>
|
#include <trace_helpers.h>
|
||||||
|
|
||||||
#include <wx/frame.h>
|
#include <wx/frame.h>
|
||||||
@ -332,7 +333,7 @@ OPENGL_GAL::OPENGL_GAL( const KIGFX::VC_SETTINGS& aVcSettings, GAL_DISPLAY_OPTIO
|
|||||||
{
|
{
|
||||||
if( m_glMainContext == nullptr )
|
if( m_glMainContext == nullptr )
|
||||||
{
|
{
|
||||||
m_glMainContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
|
m_glMainContext = Pgm().GetGLContextManager()->CreateCtx( this );
|
||||||
|
|
||||||
if( !m_glMainContext )
|
if( !m_glMainContext )
|
||||||
throw std::runtime_error( "Could not create the main OpenGL context" );
|
throw std::runtime_error( "Could not create the main OpenGL context" );
|
||||||
@ -341,7 +342,7 @@ OPENGL_GAL::OPENGL_GAL( const KIGFX::VC_SETTINGS& aVcSettings, GAL_DISPLAY_OPTIO
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_glPrivContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this, m_glMainContext );
|
m_glPrivContext = Pgm().GetGLContextManager()->CreateCtx( this, m_glMainContext );
|
||||||
|
|
||||||
if( !m_glPrivContext )
|
if( !m_glPrivContext )
|
||||||
throw std::runtime_error( "Could not create a private OpenGL context" );
|
throw std::runtime_error( "Could not create a private OpenGL context" );
|
||||||
@ -421,7 +422,9 @@ OPENGL_GAL::OPENGL_GAL( const KIGFX::VC_SETTINGS& aVcSettings, GAL_DISPLAY_OPTIO
|
|||||||
|
|
||||||
OPENGL_GAL::~OPENGL_GAL()
|
OPENGL_GAL::~OPENGL_GAL()
|
||||||
{
|
{
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glPrivContext, this );
|
|
||||||
|
GL_CONTEXT_MANAGER* gl_mgr = Pgm().GetGLContextManager();
|
||||||
|
gl_mgr->LockCtx( m_glPrivContext, this );
|
||||||
|
|
||||||
--m_instanceCounter;
|
--m_instanceCounter;
|
||||||
glFlush();
|
glFlush();
|
||||||
@ -438,19 +441,19 @@ OPENGL_GAL::~OPENGL_GAL()
|
|||||||
delete m_tempManager;
|
delete m_tempManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glPrivContext );
|
gl_mgr->UnlockCtx( m_glPrivContext );
|
||||||
|
|
||||||
// If it was the main context, then it will be deleted
|
// If it was the main context, then it will be deleted
|
||||||
// when the last OpenGL GAL instance is destroyed (a few lines below)
|
// when the last OpenGL GAL instance is destroyed (a few lines below)
|
||||||
if( m_glPrivContext != m_glMainContext )
|
if( m_glPrivContext != m_glMainContext )
|
||||||
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glPrivContext );
|
gl_mgr->DestroyCtx( m_glPrivContext );
|
||||||
|
|
||||||
delete m_shader;
|
delete m_shader;
|
||||||
|
|
||||||
// Are we destroying the last GAL instance?
|
// Are we destroying the last GAL instance?
|
||||||
if( m_instanceCounter == 0 )
|
if( m_instanceCounter == 0 )
|
||||||
{
|
{
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glMainContext, this );
|
gl_mgr->LockCtx( m_glMainContext, this );
|
||||||
|
|
||||||
if( m_isBitmapFontLoaded )
|
if( m_isBitmapFontLoaded )
|
||||||
{
|
{
|
||||||
@ -458,8 +461,8 @@ OPENGL_GAL::~OPENGL_GAL()
|
|||||||
m_isBitmapFontLoaded = false;
|
m_isBitmapFontLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glMainContext );
|
gl_mgr->UnlockCtx( m_glMainContext );
|
||||||
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glMainContext );
|
gl_mgr->DestroyCtx( m_glMainContext );
|
||||||
m_glMainContext = nullptr;
|
m_glMainContext = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -777,7 +780,7 @@ void OPENGL_GAL::LockContext( int aClientCookie )
|
|||||||
m_isContextLocked = true;
|
m_isContextLocked = true;
|
||||||
m_lockClientCookie = aClientCookie;
|
m_lockClientCookie = aClientCookie;
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().LockCtx( m_glPrivContext, this );
|
Pgm().GetGLContextManager()->LockCtx( m_glPrivContext, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -791,7 +794,7 @@ void OPENGL_GAL::UnlockContext( int aClientCookie )
|
|||||||
|
|
||||||
m_isContextLocked = false;
|
m_isContextLocked = false;
|
||||||
|
|
||||||
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glPrivContext );
|
Pgm().GetGLContextManager()->UnlockCtx( m_glPrivContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,19 +27,17 @@
|
|||||||
#ifndef GL_CONTEXT_MANAGER_H
|
#ifndef GL_CONTEXT_MANAGER_H
|
||||||
#define GL_CONTEXT_MANAGER_H
|
#define GL_CONTEXT_MANAGER_H
|
||||||
|
|
||||||
#include <import_export.h>
|
#include <kicommon.h>
|
||||||
#include <gal/gal.h>
|
#include <gal/gal.h>
|
||||||
#include <wx/glcanvas.h>
|
#include <wx/glcanvas.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class APIEXPORT GL_CONTEXT_MANAGER
|
class KICOMMON_API GL_CONTEXT_MANAGER
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Return the GL_CONTEXT_MANAGER instance (singleton).
|
GL_CONTEXT_MANAGER() : m_glCtx( nullptr ) {}
|
||||||
*/
|
|
||||||
static GL_CONTEXT_MANAGER& Get();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a managed OpenGL context.
|
* Create a managed OpenGL context.
|
||||||
@ -49,7 +47,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return Created OpenGL context.
|
* @return Created OpenGL context.
|
||||||
*/
|
*/
|
||||||
APIEXPORT wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = nullptr );
|
wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = nullptr );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a managed OpenGL context.
|
* Destroy a managed OpenGL context.
|
||||||
@ -58,14 +56,14 @@ public:
|
|||||||
*
|
*
|
||||||
* @param aContext is the OpenGL context to be destroyed. It will not be managed anymore.
|
* @param aContext is the OpenGL context to be destroyed. It will not be managed anymore.
|
||||||
*/
|
*/
|
||||||
APIEXPORT void DestroyCtx( wxGLContext* aContext );
|
void DestroyCtx( wxGLContext* aContext );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy all managed OpenGL contexts.
|
* Destroy all managed OpenGL contexts.
|
||||||
*
|
*
|
||||||
* This method should be called in the final deinitialization routine.
|
* This method should be called in the final deinitialization routine.
|
||||||
*/
|
*/
|
||||||
APIEXPORT void DeleteAll();
|
void DeleteAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a context as current and prevents other canvases from switching it.
|
* Set a context as current and prevents other canvases from switching it.
|
||||||
@ -77,7 +75,7 @@ public:
|
|||||||
* @param aCanvas (optional) allows caller to bind the context to a non-parent canvas
|
* @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).
|
* (e.g. when a few canvases share a single GL context).
|
||||||
*/
|
*/
|
||||||
APIEXPORT void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas );
|
void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow other canvases to bind an OpenGL context.
|
* Allow other canvases to bind an OpenGL context.
|
||||||
@ -85,14 +83,14 @@ public:
|
|||||||
* @param aContext is the currently bound context. It is only a check to assure the right
|
* @param aContext is the currently bound context. It is only a check to assure the right
|
||||||
* canvas wants to unlock GL context.
|
* canvas wants to unlock GL context.
|
||||||
*/
|
*/
|
||||||
APIEXPORT void UnlockCtx( wxGLContext* aContext );
|
void UnlockCtx( wxGLContext* aContext );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently bound GL context.
|
* Get the currently bound GL context.
|
||||||
*
|
*
|
||||||
* @return the currently bound GL context.
|
* @return the currently bound GL context.
|
||||||
*/
|
*/
|
||||||
APIEXPORT wxGLContext* GetCurrentCtx() const
|
wxGLContext* GetCurrentCtx() const
|
||||||
{
|
{
|
||||||
return m_glCtx;
|
return m_glCtx;
|
||||||
}
|
}
|
||||||
@ -102,7 +100,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the currently bound GL canvas.
|
* @return the currently bound GL canvas.
|
||||||
*/
|
*/
|
||||||
APIEXPORT wxGLCanvas* GetCurrentCanvas() const
|
wxGLCanvas* GetCurrentCanvas() const
|
||||||
{
|
{
|
||||||
auto it = m_glContexts.find( m_glCtx );
|
auto it = m_glContexts.find( m_glCtx );
|
||||||
return it != m_glContexts.end() ? it->second : nullptr;
|
return it != m_glContexts.end() ? it->second : nullptr;
|
||||||
@ -114,7 +112,7 @@ public:
|
|||||||
* @param aFunction is the function to be executed.
|
* @param aFunction is the function to be executed.
|
||||||
*/
|
*/
|
||||||
template<typename Func, typename... Args>
|
template<typename Func, typename... Args>
|
||||||
APIEXPORT auto RunWithoutCtxLock( Func&& aFunction, Args&&... args )
|
auto RunWithoutCtxLock( Func&& aFunction, Args&&... args )
|
||||||
{
|
{
|
||||||
wxGLContext* currentCtx = GetCurrentCtx();
|
wxGLContext* currentCtx = GetCurrentCtx();
|
||||||
wxGLCanvas* currentCanvas = GetCurrentCanvas();
|
wxGLCanvas* currentCanvas = GetCurrentCanvas();
|
||||||
@ -143,11 +141,6 @@ private:
|
|||||||
|
|
||||||
///< Lock to prevent unexpected GL context switching.
|
///< Lock to prevent unexpected GL context switching.
|
||||||
std::mutex m_glCtxMutex;
|
std::mutex m_glCtxMutex;
|
||||||
|
|
||||||
// Singleton
|
|
||||||
GL_CONTEXT_MANAGER();
|
|
||||||
GL_CONTEXT_MANAGER( const GL_CONTEXT_MANAGER& );
|
|
||||||
void operator=( const GL_CONTEXT_MANAGER& );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* GL_CONTEXT_MANAGER_H */
|
#endif /* GL_CONTEXT_MANAGER_H */
|
||||||
|
@ -112,6 +112,8 @@ public:
|
|||||||
|
|
||||||
BS::thread_pool& GetThreadPool() { return *m_singleton.m_ThreadPool; }
|
BS::thread_pool& GetThreadPool() { return *m_singleton.m_ThreadPool; }
|
||||||
|
|
||||||
|
GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific to MacOSX (not used under Linux or Windows).
|
* Specific to MacOSX (not used under Linux or Windows).
|
||||||
*
|
*
|
||||||
|
@ -35,6 +35,10 @@ public:
|
|||||||
delete m_ThreadPool;
|
delete m_ThreadPool;
|
||||||
|
|
||||||
m_ThreadPool = nullptr;
|
m_ThreadPool = nullptr;
|
||||||
|
|
||||||
|
m_GLContextManager->DeleteAll();
|
||||||
|
delete m_GLContextManager;
|
||||||
|
m_GLContextManager = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -42,9 +46,12 @@ public:
|
|||||||
{
|
{
|
||||||
int num_threads = std::max( 0, ADVANCED_CFG::GetCfg().m_MaximumThreads );
|
int num_threads = std::max( 0, ADVANCED_CFG::GetCfg().m_MaximumThreads );
|
||||||
m_ThreadPool = new BS::thread_pool( num_threads );
|
m_ThreadPool = new BS::thread_pool( num_threads );
|
||||||
|
m_GLContextManager = new GL_CONTEXT_MANAGER();
|
||||||
}
|
}
|
||||||
|
|
||||||
BS::thread_pool* m_ThreadPool;
|
BS::thread_pool* m_ThreadPool;
|
||||||
|
GL_CONTEXT_MANAGER* m_GLContextManager;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user