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.
 

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()

◆ 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

◆ 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 91 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 94 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 97 of file gl_context_mgr.h.

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


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