KiCad PCB EDA Suite
|
#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_MANAGER & | Get () |
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 |
Definition at line 35 of file gl_context_mgr.h.
|
private |
Definition at line 128 of file gl_context_mgr.cpp.
|
private |
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.
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().
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.
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.
aContext | is 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().
|
static |
Return the GL_CONTEXT_MANAGER instance (singleton).
Definition at line 30 of file gl_context_mgr.cpp.
Referenced by EDA_3D_CANVAS::DoRePaint(), KIGFX::OPENGL_GAL::LockContext(), EDA_3D_MODEL_VIEWER::OnPaint(), KIGFX::OPENGL_GAL::OPENGL_GAL(), RENDER_3D_OPENGL::Redraw(), EDA_3D_CANVAS::releaseOpenGL(), KIGFX::OPENGL_GAL::UnlockContext(), EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER(), and KIGFX::OPENGL_GAL::~OPENGL_GAL().
|
inline |
Get the currently bound GL canvas.
Definition at line 104 of file gl_context_mgr.h.
|
inline |
Get the currently bound GL context.
Definition at line 94 of file gl_context_mgr.h.
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.
aContext | is 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().
|
private |
|
inline |
Run the given function first releasing the GL context lock, then restoring it.
aFunction | is the function to be executed. |
Definition at line 116 of file gl_context_mgr.h.
Referenced by RENDER_3D_OPENGL::Redraw().
void GL_CONTEXT_MANAGER::UnlockCtx | ( | wxGLContext * | aContext | ) |
Allow other canvases to bind an OpenGL context.
aContext | is 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().
|
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().
|
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().
|
private |
Definition at line 144 of file gl_context_mgr.h.
Referenced by DeleteAll(), LockCtx(), and UnlockCtx().