KiCad PCB EDA Suite
Loading...
Searching...
No Matches
GL_CONTEXT_MANAGER Class Reference

#include <gl_context_mgr.h>

Public Member Functions

 GL_CONTEXT_MANAGER ()
 
wxGLContext * CreateCtx (wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
 Create a managed OpenGL context.
 
void DestroyCtx (wxGLContext *aContext)
 Destroy a managed OpenGL context.
 
void DeleteAll ()
 Destroy all managed OpenGL contexts.
 
bool LockCtx (wxGLContext *aContext, wxGLCanvas *aCanvas)
 Set a context as current and prevents other canvases from switching it.
 
void UnlockCtx (wxGLContext *aContext)
 Allow other canvases to bind an OpenGL context.
 
wxGLContext * GetCurrentCtx () const
 Get the currently bound GL context.
 
wxGLCanvas * GetCurrentCanvas () const
 Get the currently bound GL canvas.
 
bool IsLoseOnReset (const wxGLContext *aContext) const
 
template<typename Func, typename... Args>
auto RunWithoutCtxLock (Func &&aFunction, Args &&... args)
 Run the given function first releasing the GL context lock, then restoring it.
 

Private Attributes

std::map< wxGLContext *, wxGLCanvas * > m_glContexts
 Map of GL contexts & their parent canvases.
 
wxGLContext * m_glCtx
 Currently bound GL context.
 
std::set< const wxGLContext * > m_loseOnResetContexts
 Contexts created with the lose-on-reset notification strategy.
 
std::mutex m_glCtxMutex
 Lock to prevent unexpected GL context switching.
 

Detailed Description

Definition at line 35 of file gl_context_mgr.h.

Constructor & Destructor Documentation

◆ GL_CONTEXT_MANAGER()

GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER ( )
inline

Definition at line 39 of file gl_context_mgr.h.

References m_glCtx.

Member Function Documentation

◆ CreateCtx()

wxGLContext * GL_CONTEXT_MANAGER::CreateCtx ( wxGLCanvas * aCanvas,
const wxGLContext * aOther = nullptr )

Create a managed OpenGL context.

It is assured that the created context is freed upon exit. See wxGLContext documentation for the parameters description.

The reset strategy is chosen here; with aOther it follows that context's strategy and returns nullptr rather than create a context whose strategy does not match.

Returns
Created OpenGL context.

Definition at line 39 of file gl_context_mgr.cpp.

References IsLoseOnReset(), m_glContexts, m_loseOnResetContexts, resetRecoveryEnabled(), and traceGalContext.

Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_MODEL_VIEWER::OnPaint(), KIGFX::OPENGL_GAL::OPENGL_GAL(), and EDA_3D_CANVAS::RenderToFrameBuffer().

◆ DeleteAll()

void GL_CONTEXT_MANAGER::DeleteAll ( )

Destroy all managed OpenGL contexts.

This method should be called in the final deinitialization routine.

Definition at line 108 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, m_glCtxMutex, and m_loseOnResetContexts.

◆ DestroyCtx()

void GL_CONTEXT_MANAGER::DestroyCtx ( wxGLContext * aContext)

Destroy a managed OpenGL context.

The context to be removed has to be created using GL_CONTEXT_MANAGER::CreateCtx() first.

Parameters
aContextis the OpenGL context to be destroyed. It will not be managed anymore.

Definition at line 89 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, and m_loseOnResetContexts.

Referenced by KIGFX::OPENGL_GAL::orphanContextGroup(), EDA_3D_CANVAS::releaseOpenGL(), EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER(), and KIGFX::OPENGL_GAL::~OPENGL_GAL().

◆ GetCurrentCanvas()

wxGLCanvas * GL_CONTEXT_MANAGER::GetCurrentCanvas ( ) const
inline

Get the currently bound GL canvas.

Returns
the currently bound GL canvas.

Definition at line 108 of file gl_context_mgr.h.

References m_glContexts, and m_glCtx.

Referenced by RunWithoutCtxLock().

◆ GetCurrentCtx()

wxGLContext * GL_CONTEXT_MANAGER::GetCurrentCtx ( ) const
inline

Get the currently bound GL context.

Returns
the currently bound GL context.

Definition at line 98 of file gl_context_mgr.h.

References m_glCtx.

Referenced by RunWithoutCtxLock().

◆ IsLoseOnReset()

bool GL_CONTEXT_MANAGER::IsLoseOnReset ( const wxGLContext * aContext) const
inline
Returns
true if aContext was created to report GPU resets. Contexts sharing objects with it must be created the same way.

Definition at line 118 of file gl_context_mgr.h.

References m_loseOnResetContexts.

Referenced by CreateCtx().

◆ LockCtx()

bool GL_CONTEXT_MANAGER::LockCtx ( wxGLContext * aContext,
wxGLCanvas * aCanvas )

Set a context as current and prevents other canvases from switching it.

Requires calling UnlockCtx() when there are no more GL calls for the context. If another canvas has already locked a GL context, then the calling process is blocked.

Parameters
aContextis the GL context to be bound.
aCanvas(optional) allows caller to bind the context to a non-parent canvas (e.g. when a few canvases share a single GL context).
Returns
true if the context was made current. When this returns false the caller must not issue any GL command, because the commands would be executed against whichever sibling context is still bound.

Definition at line 122 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, m_glCtxMutex, and traceGalContext.

Referenced by EDA_3D_CANVAS::DoRePaint(), KIGFX::OPENGL_GAL::IsResetSettled(), KIGFX::OPENGL_GAL::LockContext(), EDA_3D_MODEL_VIEWER::OnPaint(), EDA_3D_CANVAS::releaseOpenGL(), EDA_3D_CANVAS::RenderToFrameBuffer(), RunWithoutCtxLock(), EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER(), and KIGFX::OPENGL_GAL::~OPENGL_GAL().

◆ RunWithoutCtxLock()

template<typename Func, typename... Args>
auto GL_CONTEXT_MANAGER::RunWithoutCtxLock ( Func && aFunction,
Args &&... args )
inline

Run the given function first releasing the GL context lock, then restoring it.

Parameters
aFunctionis the function to be executed.
argsis the list of arguements.

Definition at line 130 of file gl_context_mgr.h.

References GetCurrentCanvas(), GetCurrentCtx(), LockCtx(), result, and UnlockCtx().

Referenced by RENDER_3D_OPENGL::Redraw().

◆ UnlockCtx()

void GL_CONTEXT_MANAGER::UnlockCtx ( wxGLContext * aContext)

Allow other canvases to bind an OpenGL context.

Parameters
aContextis the currently bound context. It is only a check to assure the right canvas wants to unlock GL context.

Definition at line 155 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, and m_glCtxMutex.

Referenced by EDA_3D_CANVAS::DoRePaint(), KIGFX::OPENGL_GAL::IsResetSettled(), EDA_3D_MODEL_VIEWER::OnPaint(), EDA_3D_CANVAS::releaseOpenGL(), EDA_3D_CANVAS::RenderToFrameBuffer(), RunWithoutCtxLock(), KIGFX::OPENGL_GAL::UnlockContext(), EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER(), and KIGFX::OPENGL_GAL::~OPENGL_GAL().

Member Data Documentation

◆ m_glContexts

std::map<wxGLContext*, wxGLCanvas*> GL_CONTEXT_MANAGER::m_glContexts
private

Map of GL contexts & their parent canvases.

Definition at line 152 of file gl_context_mgr.h.

Referenced by CreateCtx(), DeleteAll(), DestroyCtx(), GetCurrentCanvas(), LockCtx(), and UnlockCtx().

◆ m_glCtx

wxGLContext* GL_CONTEXT_MANAGER::m_glCtx
private

Currently bound GL context.

Definition at line 155 of file gl_context_mgr.h.

Referenced by DeleteAll(), DestroyCtx(), GetCurrentCanvas(), GetCurrentCtx(), GL_CONTEXT_MANAGER(), LockCtx(), and UnlockCtx().

◆ m_glCtxMutex

std::mutex GL_CONTEXT_MANAGER::m_glCtxMutex
private

Lock to prevent unexpected GL context switching.

Definition at line 161 of file gl_context_mgr.h.

Referenced by DeleteAll(), LockCtx(), and UnlockCtx().

◆ m_loseOnResetContexts

std::set<const wxGLContext*> GL_CONTEXT_MANAGER::m_loseOnResetContexts
private

Contexts created with the lose-on-reset notification strategy.

Definition at line 158 of file gl_context_mgr.h.

Referenced by CreateCtx(), DeleteAll(), DestroyCtx(), and IsLoseOnReset().


The documentation for this class was generated from the following files: