Browse Source

Move GL_CONTEXT_MANAGER to kicommon

pcb_db
Seth Hillbrand 10 months ago
parent
commit
d48c40ba26
  1. 1
      common/CMakeLists.txt
  2. 1
      common/gal/CMakeLists.txt
  3. 19
      include/gal/opengl/gl_context_mgr.h

1
common/CMakeLists.txt

@ -60,6 +60,7 @@ set( KICOMMON_SRCS
# Gal # Gal
gal/color4d.cpp gal/color4d.cpp
gal/opengl/gl_context_mgr.cpp
# Jobs # Jobs
jobs/job.cpp jobs/job.cpp
jobs/job_dispatcher.cpp jobs/job_dispatcher.cpp

1
common/gal/CMakeLists.txt

@ -34,7 +34,6 @@ set( GAL_SRCS
opengl/opengl_gal.cpp opengl/opengl_gal.cpp
opengl/gl_resources.cpp opengl/gl_resources.cpp
opengl/gl_context_mgr.cpp
opengl/shader.cpp opengl/shader.cpp
opengl/vertex_item.cpp opengl/vertex_item.cpp
opengl/vertex_container.cpp opengl/vertex_container.cpp

19
include/gal/opengl/gl_context_mgr.h

@ -27,12 +27,13 @@
#ifndef GL_CONTEXT_MANAGER_H #ifndef GL_CONTEXT_MANAGER_H
#define GL_CONTEXT_MANAGER_H #define GL_CONTEXT_MANAGER_H
#include <import_export.h>
#include <gal/gal.h> #include <gal/gal.h>
#include <wx/glcanvas.h> #include <wx/glcanvas.h>
#include <mutex> #include <mutex>
#include <map> #include <map>
class GAL_API GL_CONTEXT_MANAGER
class APIEXPORT GL_CONTEXT_MANAGER
{ {
public: public:
/** /**
@ -48,7 +49,7 @@ public:
* *
* @return Created OpenGL context. * @return Created OpenGL context.
*/ */
wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = nullptr );
APIEXPORT wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = nullptr );
/** /**
* Destroy a managed OpenGL context. * Destroy a managed OpenGL context.
@ -57,14 +58,14 @@ public:
* *
* @param aContext is the OpenGL context to be destroyed. It will not be managed anymore. * @param aContext is the OpenGL context to be destroyed. It will not be managed anymore.
*/ */
void DestroyCtx( wxGLContext* aContext );
APIEXPORT void DestroyCtx( wxGLContext* aContext );
/** /**
* Destroy all managed OpenGL contexts. * Destroy all managed OpenGL contexts.
* *
* This method should be called in the final deinitialization routine. * This method should be called in the final deinitialization routine.
*/ */
void DeleteAll();
APIEXPORT void DeleteAll();
/** /**
* Set a context as current and prevents other canvases from switching it. * Set a context as current and prevents other canvases from switching it.
@ -76,7 +77,7 @@ public:
* @param aCanvas (optional) allows caller to bind the context to a non-parent canvas * @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). * (e.g. when a few canvases share a single GL context).
*/ */
void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas );
APIEXPORT void LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas );
/** /**
* Allow other canvases to bind an OpenGL context. * Allow other canvases to bind an OpenGL context.
@ -84,14 +85,14 @@ public:
* @param aContext is the currently bound context. It is only a check to assure the right * @param aContext is the currently bound context. It is only a check to assure the right
* canvas wants to unlock GL context. * canvas wants to unlock GL context.
*/ */
void UnlockCtx( wxGLContext* aContext );
APIEXPORT void UnlockCtx( wxGLContext* aContext );
/** /**
* Get the currently bound GL context. * Get the currently bound GL context.
* *
* @return the currently bound GL context. * @return the currently bound GL context.
*/ */
wxGLContext* GetCurrentCtx() const
APIEXPORT wxGLContext* GetCurrentCtx() const
{ {
return m_glCtx; return m_glCtx;
} }
@ -101,7 +102,7 @@ public:
* *
* @return the currently bound GL canvas. * @return the currently bound GL canvas.
*/ */
wxGLCanvas* GetCurrentCanvas() const
APIEXPORT wxGLCanvas* GetCurrentCanvas() const
{ {
auto it = m_glContexts.find( m_glCtx ); auto it = m_glContexts.find( m_glCtx );
return it != m_glContexts.end() ? it->second : nullptr; return it != m_glContexts.end() ? it->second : nullptr;
@ -113,7 +114,7 @@ public:
* @param aFunction is the function to be executed. * @param aFunction is the function to be executed.
*/ */
template<typename Func, typename... Args> template<typename Func, typename... Args>
auto RunWithoutCtxLock( Func&& aFunction, Args&&... args )
APIEXPORT auto RunWithoutCtxLock( Func&& aFunction, Args&&... args )
{ {
wxGLContext* currentCtx = GetCurrentCtx(); wxGLContext* currentCtx = GetCurrentCtx();
wxGLCanvas* currentCanvas = GetCurrentCanvas(); wxGLCanvas* currentCanvas = GetCurrentCanvas();

Loading…
Cancel
Save