| 
    KiCad PCB EDA Suite
    
   | 
 
#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.   | |
| 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.   | |
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 36 of file gl_context_mgr.h.
      
  | 
  inline | 
Definition at line 40 of file gl_context_mgr.h.
References m_glCtx.
| 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 30 of file gl_context_mgr.cpp.
References m_glContexts.
Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_MODEL_VIEWER::OnPaint(), KIGFX::OPENGL_GAL::OPENGL_GAL(), and EDA_3D_CANVAS::RenderToFrameBuffer().
| void GL_CONTEXT_MANAGER::DeleteAll | ( | ) | 
Destroy all managed OpenGL contexts.
This method should be called in the final deinitialization routine.
Definition at line 65 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 47 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().
      
  | 
  inline | 
Get the currently bound GL canvas.
Definition at line 103 of file gl_context_mgr.h.
References m_glContexts, and m_glCtx.
Referenced by RunWithoutCtxLock().
      
  | 
  inline | 
Get the currently bound GL context.
Definition at line 93 of file gl_context_mgr.h.
References m_glCtx.
Referenced by RunWithoutCtxLock().
| 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 78 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_CANVAS::RenderToFrameBuffer(), RunWithoutCtxLock(), EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER(), and KIGFX::OPENGL_GAL::~OPENGL_GAL().
      
  | 
  inline | 
Run the given function first releasing the GL context lock, then restoring it.
| aFunction | is the function to be executed. | 
Definition at line 115 of file gl_context_mgr.h.
References GetCurrentCanvas(), GetCurrentCtx(), LockCtx(), result, and UnlockCtx().
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 103 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(), EDA_3D_CANVAS::RenderToFrameBuffer(), RunWithoutCtxLock(), 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 137 of file gl_context_mgr.h.
Referenced by CreateCtx(), DeleteAll(), DestroyCtx(), GetCurrentCanvas(), LockCtx(), and UnlockCtx().
      
  | 
  private | 
Lock to prevent unexpected GL context switching.
Definition at line 140 of file gl_context_mgr.h.
Referenced by DeleteAll(), DestroyCtx(), GetCurrentCanvas(), GetCurrentCtx(), GL_CONTEXT_MANAGER(), LockCtx(), and UnlockCtx().
      
  | 
  private | 
Definition at line 143 of file gl_context_mgr.h.
Referenced by DeleteAll(), LockCtx(), and UnlockCtx().