10 changed files with 235 additions and 36 deletions
-
123d-viewer/3d_canvas.cpp
-
63d-viewer/3d_draw.cpp
-
43d-viewer/3d_model_viewer/c3d_model_viewer.cpp
-
1common/CMakeLists.txt
-
4common/draw_panel_gal.cpp
-
52common/gal/opengl/opengl_gal.cpp
-
84common/gl_context_mgr.cpp
-
8include/gal/opengl/opengl_gal.h
-
93include/gl_context_mgr.h
-
7pcbnew/pcbnew.cpp
@ -0,0 +1,84 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2016 CERN |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <gl_context_mgr.h>
|
|||
|
|||
GL_CONTEXT_MANAGER& GL_CONTEXT_MANAGER::Get() |
|||
{ |
|||
static GL_CONTEXT_MANAGER instance; |
|||
|
|||
return instance; |
|||
} |
|||
|
|||
wxGLContext* GL_CONTEXT_MANAGER::CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther ) |
|||
{ |
|||
wxGLContext* context = new wxGLContext( aCanvas, aOther ); |
|||
assert( context /* && context->IsOK() */ ); // IsOK() is available in wx3.1+
|
|||
assert( m_glContexts.count( context ) == 0 ); |
|||
m_glContexts.insert( std::make_pair( context, aCanvas ) ); |
|||
|
|||
return context; |
|||
} |
|||
|
|||
|
|||
void GL_CONTEXT_MANAGER::DeleteAll() |
|||
{ |
|||
for( auto& ctx : m_glContexts ) |
|||
delete ctx.first; |
|||
|
|||
m_glContexts.clear(); |
|||
} |
|||
|
|||
|
|||
void GL_CONTEXT_MANAGER::LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas ) |
|||
{ |
|||
assert( aCanvas || m_glContexts.count( aContext ) > 0 ); |
|||
|
|||
m_glCtxMutex.lock(); |
|||
wxGLCanvas* canvas = aCanvas ? aCanvas : m_glContexts.at( aContext ); |
|||
canvas->SetCurrent( *aContext ); |
|||
m_glCtx = aContext; |
|||
} |
|||
|
|||
|
|||
void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext ) |
|||
{ |
|||
assert( m_glContexts.count( aContext ) > 0 ); |
|||
|
|||
if( m_glCtx == aContext ){ |
|||
m_glCtxMutex.unlock(); |
|||
m_glCtx = NULL; |
|||
} |
|||
else |
|||
{ |
|||
wxLogDebug( "Trying to unlock GL context mutex from a wrong context" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER() |
|||
: m_glCtx( NULL ) |
|||
{ |
|||
} |
|||
|
@ -0,0 +1,93 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2016 CERN |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef GL_CONTEXT_MANAGER_H |
|||
#define GL_CONTEXT_MANAGER_H |
|||
|
|||
#include <wx/glcanvas.h> |
|||
#include <ki_mutex.h> |
|||
#include <map> |
|||
|
|||
class GL_CONTEXT_MANAGER |
|||
{ |
|||
public: |
|||
/** |
|||
* Function Get |
|||
* returns the GL_CONTEXT_MANAGER instance (singleton). |
|||
*/ |
|||
static GL_CONTEXT_MANAGER& Get(); |
|||
|
|||
/** |
|||
* Function CreateCtx |
|||
* creates a managed OpenGL context. It is assured that the created context is freed upon |
|||
* exit. |
|||
* See wxGLContext documentation for the parameters description. |
|||
* @return Created OpenGL context. |
|||
*/ |
|||
wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = NULL ); |
|||
|
|||
/** |
|||
* Function DeleteAll |
|||
* destroys all managed OpenGL contexts. This method should be called in the |
|||
* final deinitialization routine. |
|||
*/ |
|||
void DeleteAll(); |
|||
|
|||
/** |
|||
* Function LockCtx |
|||
* sets 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. |
|||
* @param aContext is the GL context to be bound. |
|||
* @param aCanvas (optional) allows caller to bind the context to a non-parent canvas |
|||
* (e.g. when a few canvases share a single GL context). |
|||
*/ |
|||
void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas = NULL ); |
|||
|
|||
/** |
|||
* Function UnlockCtx |
|||
* allows other canvases to bind an OpenGL context. |
|||
* @param aContext is the currently bound context. It is only a check to assure the right |
|||
* canvas wants to unlock GL context. |
|||
*/ |
|||
void UnlockCtx( wxGLContext* aContext ); |
|||
|
|||
private: |
|||
///> Map of GL contexts & their parent canvases. |
|||
std::map<wxGLContext*, wxGLCanvas*> m_glContexts; |
|||
|
|||
///> Currently bound GL context. |
|||
wxGLContext* m_glCtx; |
|||
|
|||
///> Lock to prevent unexpected GL context switching. |
|||
MUTEX m_glCtxMutex; |
|||
|
|||
// Singleton |
|||
GL_CONTEXT_MANAGER(); |
|||
GL_CONTEXT_MANAGER( const GL_CONTEXT_MANAGER& ); |
|||
void operator=( const GL_CONTEXT_MANAGER& ); |
|||
}; |
|||
|
|||
#endif /* GL_CONTEXT_MANAGER_H */ |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue