From: Antoine Fontaine Date: Sun, 21 Mar 2021 22:13:49 +0000 (+0100) Subject: libs/gtkutil/glwidget: rework a bit shared context GL callbacks X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=6736a42a923644f539845a04c153fb3caf153b34 libs/gtkutil/glwidget: rework a bit shared context GL callbacks This turns 2 global variables into local ones --- diff --git a/libs/gtkutil/glwidget.cpp b/libs/gtkutil/glwidget.cpp index c597c4a9..8581f7a4 100644 --- a/libs/gtkutil/glwidget.cpp +++ b/libs/gtkutil/glwidget.cpp @@ -19,15 +19,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// OpenGL widget based on GtkGLExt +// OpenGL widget based on GtkGLExt / GtkGLArea #include "glwidget.h" #include "igl.h" -void (*GLWidget_sharedContextCreated)() = 0; - -void (*GLWidget_sharedContextDestroyed)() = 0; +// Function callbacks +static void (*sharedContextCreated)() = nullptr; +static void (*sharedContextDestroyed)() = nullptr; unsigned int g_context_count = 0; @@ -42,7 +42,7 @@ static void _glwidget_context_created(ui::GLArea self, void *data) glwidget_make_current(g_shared); GlobalOpenGL().contextValid = true; - GLWidget_sharedContextCreated(); + sharedContextCreated(); } } @@ -51,19 +51,18 @@ static void _glwidget_context_destroyed(ui::GLArea self, void *data) if (--g_context_count == 0) { GlobalOpenGL().contextValid = false; - GLWidget_sharedContextDestroyed(); + sharedContextDestroyed(); g_shared.unref(); g_shared = ui::GLArea(ui::null); } } -void glwidget_destroy_context(ui::GLArea self) -{ -} - -void glwidget_create_context(ui::GLArea self) +void glwidget_set_shared_context_constructors( + void created(), void destroyed() ) { + sharedContextCreated = created; + sharedContextDestroyed = destroyed; } #if GTK_TARGET == 3 diff --git a/libs/gtkutil/glwidget.h b/libs/gtkutil/glwidget.h index 6a43da88..e407a03e 100644 --- a/libs/gtkutil/glwidget.h +++ b/libs/gtkutil/glwidget.h @@ -24,12 +24,9 @@ #if !defined( INCLUDED_GTKUTIL_GLWIDGET_H ) #define INCLUDED_GTKUTIL_GLWIDGET_H -extern void (*GLWidget_sharedContextCreated)(); -extern void (*GLWidget_sharedContextDestroyed)(); - ui::GLArea glwidget_new(bool zbuffer); -void glwidget_create_context(ui::GLArea self); -void glwidget_destroy_context(ui::GLArea self); +void glwidget_set_shared_context_constructors( + void sharedContextCreated(), void sharedContextDestroyed() ); bool glwidget_make_current(ui::GLArea self); void glwidget_swap_buffers(ui::GLArea self); diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index f39805bf..41130726 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -3599,8 +3599,7 @@ void MainFrame_Construct(){ g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) ); GlobalEntityCreator().setCounter( &g_entityCount ); - GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated; - GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed; + glwidget_set_shared_context_constructors( GlobalGL_sharedContextCreated, GlobalGL_sharedContextDestroyed); GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver ); }