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

#include <gl_context_mgr.h>

Public Member Functions

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.
 
void 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.
 
template<typename Func , typename... Args>
auto RunWithoutCtxLock (Func &&aFunction, Args &&... args)
 Run the given function first releasing the GL context lock, then restoring it.
 

Static Public Member Functions

static GL_CONTEXT_MANAGERGet ()
 Return the GL_CONTEXT_MANAGER instance (singleton).
 

Private Member Functions

 GL_CONTEXT_MANAGER ()
 
 GL_CONTEXT_MANAGER (const GL_CONTEXT_MANAGER &)
 
void operator= (const GL_CONTEXT_MANAGER &)
 

Private Attributes

std::map< wxGLContext *, wxGLCanvas * > m_glContexts
 < Map of GL contexts & their parent canvases.
 
wxGLContext * m_glCtx
 Lock to prevent unexpected GL context switching.
 
std::mutex m_glCtxMutex
 

Detailed Description

Definition at line 35 of file gl_context_mgr.h.

Constructor & Destructor Documentation

◆ GL_CONTEXT_MANAGER() [1/2]

GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER ( )
private

Definition at line 128 of file gl_context_mgr.cpp.

◆ GL_CONTEXT_MANAGER() [2/2]

GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER ( const GL_CONTEXT_MANAGER )
private

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.

Returns
Created OpenGL context.

Definition at line 38 of file gl_context_mgr.cpp.

References m_glContexts.

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

◆ DeleteAll()

void GL_CONTEXT_MANAGER::DeleteAll ( )

Destroy all managed OpenGL contexts.

This method should be called in the final deinitialization routine.

Definition at line 73 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, and m_glCtxMutex.

◆ 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 55 of file gl_context_mgr.cpp.

References m_glContexts, and m_glCtx.

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

◆ Get()

◆ GetCurrentCanvas()

wxGLCanvas * GL_CONTEXT_MANAGER::GetCurrentCanvas ( ) const
inline

Get the currently bound GL canvas.

Returns
the currently bound GL canvas.

Definition at line 104 of file gl_context_mgr.h.

◆ GetCurrentCtx()

wxGLContext * GL_CONTEXT_MANAGER::GetCurrentCtx ( ) const
inline

Get the currently bound GL context.

Returns
the currently bound GL context.

Definition at line 94 of file gl_context_mgr.h.

◆ LockCtx()

void 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).

Definition at line 86 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, and m_glCtxMutex.

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

◆ operator=()

void GL_CONTEXT_MANAGER::operator= ( const GL_CONTEXT_MANAGER )
private

◆ 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.

Definition at line 116 of file gl_context_mgr.h.

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 111 of file gl_context_mgr.cpp.

References m_glContexts, m_glCtx, and m_glCtxMutex.

Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_MODEL_VIEWER::OnPaint(), EDA_3D_CANVAS::releaseOpenGL(), 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.

Currently bound GL context.

Definition at line 138 of file gl_context_mgr.h.

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

◆ m_glCtx

wxGLContext* GL_CONTEXT_MANAGER::m_glCtx
private

Lock to prevent unexpected GL context switching.

Definition at line 141 of file gl_context_mgr.h.

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

◆ m_glCtxMutex

std::mutex GL_CONTEXT_MANAGER::m_glCtxMutex
private

Definition at line 144 of file gl_context_mgr.h.

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


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