43 wxGLContext* context =
nullptr;
47 wxGLContextAttrs attrs;
48 attrs.PlatformDefaults().LoseOnReset().EndList();
52 context =
new wxGLContext( aCanvas, aOther, &attrs );
54 if( !context->IsOK() )
68 context =
new wxGLContext( aCanvas, aOther );
70 if( !context->IsOK() )
77 wxLogTrace(
traceGalContext, wxS(
"Created GL context %p on canvas %p, lose on reset %d" ), context,
78 aCanvas, loseOnReset ? 1 : 0 );
80 m_glContexts.insert( std::make_pair( context, aCanvas ) );
124 wxCHECK( aContext &&
m_glContexts.count( aContext ) > 0,
false );
127 wxGLCanvas* canvas = aCanvas ? aCanvas :
m_glContexts.at( aContext );
128 bool current =
false;
130#if defined( __WXMSW__ )
132 if( wglGetCurrentContext() == aContext->GetGLRC() && wglGetCurrentDC() == canvas->GetHDC() )
135#elif defined( __WXGTK__ )
137 if( canvas->GTKGetDrawingWindow() )
140 current = canvas->SetCurrent( *aContext );
145 wxLogTrace(
traceGalContext, wxS(
"Could not make GL context %p current on canvas %p" ),
157 wxCHECK( aContext &&
m_glContexts.count( aContext ) > 0, );
166 wxFAIL_MSG( wxString::Format( wxS(
"Trying to unlock GL context mutex from "
167 "a wrong context: aContext %p m_glCtx %p" ), aContext,
m_glCtx ) );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
wxGLContext * m_glCtx
Currently bound GL context.
std::mutex m_glCtxMutex
Lock to prevent unexpected GL context switching.
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.
std::set< const wxGLContext * > m_loseOnResetContexts
Contexts created with the lose-on-reset notification strategy.
std::map< wxGLContext *, wxGLCanvas * > m_glContexts
Map of GL contexts & their parent canvases.
bool LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
void DeleteAll()
Destroy all managed OpenGL contexts.
bool IsLoseOnReset(const wxGLContext *aContext) const
static bool resetRecoveryEnabled()
bool m_EnableGLResetRecovery
Create OpenGL contexts that report GPU resets so the canvases can rebuild themselves instead of freez...
const wxChar *const traceGalContext
Flag to enable debug output of GAL context binding.
wxLogTrace helper definitions.