]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/gtkutil/glwidget.cpp
Merge branch 'uis/lightfix' into 'master'
[xonotic/netradiant.git] / libs / gtkutil / glwidget.cpp
index 52cec49cf2a58d329001a7ad12a2e1ad7dfc4926..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;
 
 ui::GLArea g_shared{ui::null};
 
-void _glwidget_context_created(ui::GLArea self, void *data)
+static void _glwidget_context_created(ui::GLArea self, void *data)
 {
     if (++g_context_count == 1) {
         g_shared = self;
@@ -42,35 +42,34 @@ void _glwidget_context_created(ui::GLArea self, void *data)
         glwidget_make_current(g_shared);
         GlobalOpenGL().contextValid = true;
 
-        GLWidget_sharedContextCreated();
+        sharedContextCreated();
     }
 }
 
-void _glwidget_context_destroyed(ui::GLArea self, void *data)
+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
 
 #include <gtk/gtk.h>
 
-GdkGLContext *glwidget_context_created(ui::GLArea self)
+static GdkGLContext *glwidget_context_created(ui::GLArea self)
 {
     _glwidget_context_created(self, nullptr);
     return gtk_gl_area_get_context(self);
@@ -78,9 +77,9 @@ GdkGLContext *glwidget_context_created(ui::GLArea self)
 
 ui::GLArea glwidget_new(bool zbuffer)
 {
-    auto self = ui::GLArea(GTK_GL_AREA(gtk_gl_area_new()));
+    auto self = ui::GLArea::from(GTK_GL_AREA(gtk_gl_area_new()));
     gtk_gl_area_set_has_depth_buffer(self, zbuffer);
-    gtk_gl_area_set_auto_render(self, false);
+    gtk_gl_area_set_auto_render(self, true); // FIXME
 
     self.connect("realize", G_CALLBACK(glwidget_context_created), nullptr);
     return self;
@@ -92,12 +91,12 @@ bool glwidget_make_current(ui::GLArea self)
 //        glwidget_context_created(self);
 //    }
     gtk_gl_area_make_current(self);
-    auto valid = GlobalOpenGL().contextValid;
     return true;
 }
 
 void glwidget_swap_buffers(ui::GLArea self)
 {
+    g_assert(GTK_IS_GL_AREA(self));
     gtk_gl_area_queue_render(self);
 }
 
@@ -116,21 +115,21 @@ struct config_t {
 };
 typedef const config_t *configs_iterator;
 
-int config_rgba32[] = {
+static int config_rgba32[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 24,
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-int config_rgba[] = {
+static int config_rgba[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 16,
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-const config_t configs[] = {
+static const config_t configs[] = {
         {
                 "colour-buffer = 32bpp, depth-buffer = none",
                 config_rgba32,
@@ -141,7 +140,7 @@ const config_t configs[] = {
         }
 };
 
-GdkGLConfig *glconfig_new()
+static GdkGLConfig *glconfig_new()
 {
     for (configs_iterator i = configs, end = configs + 2; i != end; ++i) {
         if (auto glconfig = gdk_gl_config_new(i->attribs)) {
@@ -153,7 +152,7 @@ GdkGLConfig *glconfig_new()
     return gdk_gl_config_new_by_mode((GdkGLConfigMode) (GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE));
 }
 
-int config_rgba32_depth32[] = {
+static int config_rgba32_depth32[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE,
@@ -163,7 +162,7 @@ int config_rgba32_depth32[] = {
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-int config_rgba32_depth24[] = {
+static int config_rgba32_depth24[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 24,
@@ -171,7 +170,7 @@ int config_rgba32_depth24[] = {
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-int config_rgba32_depth16[] = {
+static int config_rgba32_depth16[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 24,
@@ -179,7 +178,7 @@ int config_rgba32_depth16[] = {
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-int config_rgba32_depth[] = {
+static int config_rgba32_depth[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 24,
@@ -187,7 +186,7 @@ int config_rgba32_depth[] = {
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-int config_rgba_depth16[] = {
+static int config_rgba_depth16[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 16,
@@ -195,7 +194,7 @@ int config_rgba_depth16[] = {
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-int config_rgba_depth[] = {
+static int config_rgba_depth[] = {
         GDK_GL_RGBA,
         GDK_GL_DOUBLEBUFFER,
         GDK_GL_BUFFER_SIZE, 16,
@@ -203,7 +202,7 @@ int config_rgba_depth[] = {
         GDK_GL_ATTRIB_LIST_NONE,
 };
 
-const config_t configs_with_depth[] =
+static const config_t configs_with_depth[] =
         {
                 {
                         "colour-buffer = 32bpp, depth-buffer = 32bpp",
@@ -231,7 +230,7 @@ const config_t configs_with_depth[] =
                 },
         };
 
-GdkGLConfig *glconfig_new_with_depth()
+static GdkGLConfig *glconfig_new_with_depth()
 {
     for (configs_iterator i = configs_with_depth, end = configs_with_depth + 6; i != end; ++i) {
         if (auto glconfig = gdk_gl_config_new(i->attribs)) {
@@ -243,7 +242,7 @@ GdkGLConfig *glconfig_new_with_depth()
     return gdk_gl_config_new_by_mode((GdkGLConfigMode) (GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH));
 }
 
-int glwidget_context_created(ui::GLArea self, void *data)
+static int glwidget_context_created(ui::GLArea self, void *data)
 {
     _glwidget_context_created(self, data);
     return false;
@@ -255,7 +254,7 @@ int glwidget_context_destroyed(ui::GLArea self, void *data)
     return false;
 }
 
-bool glwidget_enable_gl(ui::GLArea self, ui::Widget root, gpointer data)
+static bool glwidget_enable_gl(ui::GLArea self, ui::Widget root, gpointer data)
 {
     if (!root && !gtk_widget_is_gl_capable(self)) {
         const auto zbuffer = g_object_get_data(G_OBJECT(self), "zbuffer");