]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
libs/gtkutil/glwidget: rework a bit shared context GL callbacks
authorAntoine Fontaine <antoine.fontaine@epfl.ch>
Sun, 21 Mar 2021 22:13:49 +0000 (23:13 +0100)
committerAntoine Fontaine <antoine.fontaine@epfl.ch>
Wed, 24 Mar 2021 19:10:17 +0000 (20:10 +0100)
This turns 2 global variables into local ones

libs/gtkutil/glwidget.cpp
libs/gtkutil/glwidget.h
radiant/mainframe.cpp

index c597c4a9640a65431a3e021372fdf66843e98536..8581f7a4a4ef779a0840126e070dd40f21286e12 100644 (file)
    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
index 6a43da88ca3eb2379a10737d7e71661ea62bbd08..e407a03ec51f400b990476e0e646765887292f78 100644 (file)
 #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);
 
index f39805bfd3bf09f0896abbf9cafad7415afbb59b..4113072623c2d0dc0a6d5f224b38082040bbb3a1 100644 (file)
@@ -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 );
 }