KiCad PCB EDA Suite
gl_context_mgr.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef GL_CONTEXT_MANAGER_H
26 #define GL_CONTEXT_MANAGER_H
27 
28 #include <wx/glcanvas.h>
29 #include <ki_mutex.h>
30 #include <map>
31 
33 {
34 public:
39  static GL_CONTEXT_MANAGER& Get();
40 
48  wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = NULL );
49 
56  void DestroyCtx( wxGLContext* aContext );
57 
63  void DeleteAll();
64 
74  void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas );
75 
82  void UnlockCtx( wxGLContext* aContext );
83 
84 private:
86  std::map<wxGLContext*, wxGLCanvas*> m_glContexts;
87 
89  wxGLContext* m_glCtx;
90 
93 
94  // Singleton
97  void operator=( const GL_CONTEXT_MANAGER& );
98 };
99 
100 #endif /* GL_CONTEXT_MANAGER_H */
101 
void operator=(const GL_CONTEXT_MANAGER &)
void DeleteAll()
Function DeleteAll destroys all managed OpenGL contexts.
std::map< wxGLContext *, wxGLCanvas * > m_glContexts
Map of GL contexts & their parent canvases.
MUTEX m_glCtxMutex
Lock to prevent unexpected GL context switching.
boost::interprocess::interprocess_mutex MUTEX
Establish KiCad MUTEX choices here in this file: typedef MUTEX and typedef MUTLOCK.
Definition: ki_mutex.h:42
wxGLContext * m_glCtx
Currently bound GL context.
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=NULL)
Function CreateCtx creates a managed OpenGL context.