]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Wrap GtkGLArea
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 23 Jul 2017 07:34:38 +0000 (17:34 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 31 Jul 2017 12:35:48 +0000 (22:35 +1000)
19 files changed:
CMakeLists.txt
cmake/FindGTK2.cmake [new file with mode: 0644]
cmake/FindGTK3.cmake [new file with mode: 0644]
cmake/FindGtkGLExt.cmake
include/igtkgl.h
libs/gtkutil/CMakeLists.txt
libs/gtkutil/glwidget.cpp
libs/gtkutil/glwidget.h
libs/gtkutil/xorrectangle.cpp
libs/gtkutil/xorrectangle.h
libs/uilib/CMakeLists.txt
libs/uilib/uilib.cpp
libs/uilib/uilib.h
radiant/CMakeLists.txt
radiant/camwindow.cpp
radiant/camwindow.h
radiant/texwindow.cpp
radiant/xywindow.cpp
radiant/xywindow.h

index 3cbb897b53acfc55ebbda91806b1d4a06f0d9dac..d3d230ffc2e21681cb281bd683a8e3ea3be77a61 100644 (file)
@@ -72,7 +72,8 @@ if (NOT WIN32)
 endif ()
 
 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
-set(GTK_NS "GTK2" CACHE STRING "GTK variable prefix")
+set(GTK_TARGET 2 CACHE STRING "GTK target")
+add_definitions(-DGTK_TARGET=${GTK_TARGET})
 
 #-----------------------------------------------------------------------
 # Defs
@@ -90,13 +91,18 @@ if (NOT CMAKE_BUILD_TYPE MATCHES Release)
 endif ()
 
 add_definitions(
-    -DGTK_DISABLE_SINGLE_INCLUDES
-    -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES
-    -DGSEAL_ENABLE
-    -DGTK_DISABLE_DEPRECATED
-    -DGDK_DISABLE_DEPRECATED
+        -DGTK_DISABLE_SINGLE_INCLUDES
+        -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES
+        -DGSEAL_ENABLE
 )
 
+if (GTK_TARGET EQUAL 2)
+    add_definitions(
+            -DGTK_DISABLE_DEPRECATED
+            -DGDK_DISABLE_DEPRECATED
+    )
+endif ()
+
 if (APPLE)
     option(XWINDOWS "Build against X11" ON)
     add_definitions(
diff --git a/cmake/FindGTK2.cmake b/cmake/FindGTK2.cmake
new file mode 100644 (file)
index 0000000..d3602bf
--- /dev/null
@@ -0,0 +1,9 @@
+include(FindPkgConfig)
+if (PKG_CONFIG_FOUND)
+    if (GLIB_FIND_REQUIRED)
+        set(_PACKAGE_ARGS REQUIRED)
+    else ()
+        set(_PACKAGE_ARGS "")
+    endif ()
+    pkg_check_modules(GTK2 gtk+-2.0 ${_PACKAGE_ARGS})
+endif ()
diff --git a/cmake/FindGTK3.cmake b/cmake/FindGTK3.cmake
new file mode 100644 (file)
index 0000000..96dd46b
--- /dev/null
@@ -0,0 +1,9 @@
+include(FindPkgConfig)
+if (PKG_CONFIG_FOUND)
+    if (GLIB_FIND_REQUIRED)
+        set(_PACKAGE_ARGS REQUIRED)
+    else ()
+        set(_PACKAGE_ARGS "")
+    endif ()
+    pkg_check_modules(GTK3 gtk+-3.0 ${_PACKAGE_ARGS})
+endif ()
index 7fb3e9d1bfef83e502aa4769e12522e76326d012..db1a2df8760a3fa2ff72ea4619b00bd2ade8ccde 100644 (file)
@@ -1,11 +1,10 @@
 include(FindPkgConfig)
 if (PKG_CONFIG_FOUND)
-    if (GtkGLExt_FIND_REQUIRED)
+    if (GLIB_FIND_REQUIRED)
         set(_PACKAGE_ARGS REQUIRED)
     else ()
         set(_PACKAGE_ARGS "")
     endif ()
-    pkg_check_modules(GTK gtk+-2.0 ${_PACKAGE_ARGS})
     if (XWINDOWS)
         pkg_check_modules(GTKGL gtkglext-x11-1.0 ${_PACKAGE_ARGS})
     elseif (WIN32)
index a78a05707b07f53dae3d54224099dd89db4fb21a..b4454564d12e8e1665704a36e45d94c717294943 100644 (file)
 #include <uilib/uilib.h>
 #include "generic/constant.h"
 
-typedef int gint;
-typedef gint gboolean;
-
-struct _QERGtkGLTable
-{
-       INTEGER_CONSTANT( Version, 1 );
-       STRING_CONSTANT( Name, "gtkgl" );
-
-       ui::Widget ( *glwidget_new )(gboolean zbufffer);
-       void ( *glwidget_swap_buffers )( ui::Widget widget );
-       gboolean ( *glwidget_make_current )( ui::Widget widget );
-       void ( *glwidget_destroy_context )( ui::Widget widget );
-       void ( *glwidget_create_context )( ui::Widget widget );
+template<class T>
+using func = T *;
+
+struct _QERGtkGLTable {
+    STRING_CONSTANT(Name, "gtkgl");
+    INTEGER_CONSTANT(Version, 1);
+
+    func<ui::GLArea(bool zbufffer)> glwidget_new;
+    func<void(ui::GLArea self)> glwidget_swap_buffers;
+    func<bool(ui::GLArea self)> glwidget_make_current;
+    func<void(ui::GLArea self)> glwidget_destroy_context;
+    func<void(ui::GLArea self)> glwidget_create_context;
 };
 
 #endif
index a0bb6d99f54e80e0150def240a3401af9c24812d..9ccd41b23e8ec4de65498f6e338f5b7790bd4959 100644 (file)
@@ -27,8 +27,8 @@ add_library(gtkutil
 target_include_directories(gtkutil PRIVATE uilib)
 target_link_libraries(gtkutil PRIVATE uilib)
 
-target_include_directories(gtkutil PRIVATE ${${GTK_NS}_INCLUDE_DIRS})
-target_link_libraries(gtkutil PRIVATE ${${GTK_NS}_LIBRARIES})
+target_include_directories(gtkutil PRIVATE ${GTK${GTK_TARGET}_INCLUDE_DIRS})
+target_link_libraries(gtkutil PRIVATE ${GTK${GTK_TARGET}_LIBRARIES})
 
 find_package(GtkGLExt REQUIRED)
 target_include_directories(gtkutil PRIVATE ${GTKGL_INCLUDE_DIRS})
index 0e4d75bfec5b0db3b43e6acf198690e6f44d6a6f..d732a212ab2b75e1508f9709f57df415e04e2ca6 100644 (file)
 
 #include "glwidget.h"
 
-#include "debugging/debugging.h"
-
 #include "igl.h"
 
+void (*GLWidget_sharedContextCreated)() = 0;
+
+void (*GLWidget_sharedContextDestroyed)() = 0;
+
+unsigned int g_context_count = 0;
+
+ui::GLArea g_shared{ui::null};
+
+void _glwidget_context_created(ui::GLArea self, void *data)
+{
+    if (++g_context_count == 1) {
+        g_shared = self;
+        g_object_ref(g_shared);
+
+        glwidget_make_current(g_shared);
+        GlobalOpenGL().contextValid = true;
+
+        GLWidget_sharedContextCreated();
+    }
+}
+
+void _glwidget_context_destroyed(ui::GLArea self, void *data)
+{
+    if (--g_context_count == 0) {
+        GlobalOpenGL().contextValid = false;
+
+        GLWidget_sharedContextDestroyed();
+
+        g_shared.unref();
+        g_shared = ui::GLArea(ui::null);
+    }
+}
+
+void glwidget_destroy_context(ui::GLArea self)
+{
+}
+
+void glwidget_create_context(ui::GLArea self)
+{
+}
+
+#if GTK_TARGET == 3
+
 #include <gtk/gtk.h>
-#include <gtk/gtkglwidget.h>
 
-#include "pointer.h"
+GdkGLContext *glwidget_context_created(ui::GLArea self)
+{
+    _glwidget_context_created(self, nullptr);
+    return gtk_gl_area_get_context(self);
+}
+
+ui::GLArea glwidget_new(bool zbuffer)
+{
+    auto self = ui::GLArea(GTK_GL_AREA(gtk_gl_area_new()));
+    gtk_gl_area_set_has_depth_buffer(self, zbuffer);
+    gtk_gl_area_set_auto_render(self, false);
 
-void ( *GLWidget_sharedContextCreated )() = 0;
-void ( *GLWidget_sharedContextDestroyed )() = 0;
+    self.connect("realize", G_CALLBACK(glwidget_context_created), nullptr);
+    return self;
+}
 
+bool glwidget_make_current(ui::GLArea self)
+{
+//    if (!g_context_count) {
+//        glwidget_context_created(self);
+//    }
+    gtk_gl_area_make_current(self);
+    auto valid = GlobalOpenGL().contextValid;
+    return true;
+}
 
-typedef int* attribs_t;
-struct config_t
+void glwidget_swap_buffers(ui::GLArea self)
 {
-       const char* name;
-       attribs_t attribs;
+    gtk_gl_area_queue_render(self);
+}
+
+#endif
+
+#if GTK_TARGET == 2
+
+#include <gtk/gtk.h>
+#include <gtk/gtkglwidget.h>
+
+#include "pointer.h"
+
+struct config_t {
+    const char *name;
+    int *attribs;
 };
-typedef const config_tconfigs_iterator;
+typedef const config_t *configs_iterator;
 
 int config_rgba32[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 24,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 24,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 int config_rgba[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 16,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 16,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 const config_t configs[] = {
-       {
-               "colour-buffer = 32bpp, depth-buffer = none",
-               config_rgba32,
-       },
-       {
-               "colour-buffer = 16bpp, depth-buffer = none",
-               config_rgba,
-       }
+        {
+                "colour-buffer = 32bpp, depth-buffer = none",
+                config_rgba32,
+        },
+        {
+                "colour-buffer = 16bpp, depth-buffer = none",
+                config_rgba,
+        }
 };
 
-GdkGLConfig* glconfig_new(){
-       GdkGLConfig* glconfig = 0;
-
-       for ( configs_iterator i = configs, end = configs + 2; i != end; ++i )
-       {
-               glconfig = gdk_gl_config_new( ( *i ).attribs );
-               if ( glconfig != 0 ) {
-                       globalOutputStream() << "OpenGL window configuration: " << ( *i ).name << "\n";
-                       return glconfig;
-               }
-       }
-
-       globalOutputStream() << "OpenGL window configuration: colour-buffer = auto, depth-buffer = none\n";
-       return gdk_gl_config_new_by_mode( (GdkGLConfigMode)( GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE ) );
+GdkGLConfig *glconfig_new()
+{
+    for (configs_iterator i = configs, end = configs + 2; i != end; ++i) {
+        if (auto glconfig = gdk_gl_config_new(i->attribs)) {
+            globalOutputStream() << "OpenGL window configuration: " << i->name << "\n";
+            return glconfig;
+        }
+    }
+    globalOutputStream() << "OpenGL window configuration: colour-buffer = auto, depth-buffer = none\n";
+    return gdk_gl_config_new_by_mode((GdkGLConfigMode) (GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE));
 }
 
 int config_rgba32_depth32[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 24,
-       GDK_GL_DEPTH_SIZE, 32,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE,
+        24,
+        GDK_GL_DEPTH_SIZE,
+        32,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 int config_rgba32_depth24[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 24,
-       GDK_GL_DEPTH_SIZE, 24,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 24,
+        GDK_GL_DEPTH_SIZE, 24,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 int config_rgba32_depth16[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 24,
-       GDK_GL_DEPTH_SIZE, 16,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 24,
+        GDK_GL_DEPTH_SIZE, 16,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 int config_rgba32_depth[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 24,
-       GDK_GL_DEPTH_SIZE, 1,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 24,
+        GDK_GL_DEPTH_SIZE, 1,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 int config_rgba_depth16[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 16,
-       GDK_GL_DEPTH_SIZE, 16,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 16,
+        GDK_GL_DEPTH_SIZE, 16,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 int config_rgba_depth[] = {
-       GDK_GL_RGBA,
-       GDK_GL_DOUBLEBUFFER,
-       GDK_GL_BUFFER_SIZE, 16,
-       GDK_GL_DEPTH_SIZE, 1,
-       GDK_GL_ATTRIB_LIST_NONE,
+        GDK_GL_RGBA,
+        GDK_GL_DOUBLEBUFFER,
+        GDK_GL_BUFFER_SIZE, 16,
+        GDK_GL_DEPTH_SIZE, 1,
+        GDK_GL_ATTRIB_LIST_NONE,
 };
 
 const config_t configs_with_depth[] =
+        {
+                {
+                        "colour-buffer = 32bpp, depth-buffer = 32bpp",
+                        config_rgba32_depth32,
+                },
+                {
+                        "colour-buffer = 32bpp, depth-buffer = 24bpp",
+                        config_rgba32_depth24,
+                },
+                {
+                        "colour-buffer = 32bpp, depth-buffer = 16bpp",
+                        config_rgba32_depth16,
+                },
+                {
+                        "colour-buffer = 32bpp, depth-buffer = auto",
+                        config_rgba32_depth,
+                },
+                {
+                        "colour-buffer = 16bpp, depth-buffer = 16bpp",
+                        config_rgba_depth16,
+                },
+                {
+                        "colour-buffer = auto, depth-buffer = auto",
+                        config_rgba_depth,
+                },
+        };
+
+GdkGLConfig *glconfig_new_with_depth()
 {
-       {
-               "colour-buffer = 32bpp, depth-buffer = 32bpp",
-               config_rgba32_depth32,
-       },
-       {
-               "colour-buffer = 32bpp, depth-buffer = 24bpp",
-               config_rgba32_depth24,
-       },
-       {
-               "colour-buffer = 32bpp, depth-buffer = 16bpp",
-               config_rgba32_depth16,
-       },
-       {
-               "colour-buffer = 32bpp, depth-buffer = auto",
-               config_rgba32_depth,
-       },
-       {
-               "colour-buffer = 16bpp, depth-buffer = 16bpp",
-               config_rgba_depth16,
-       },
-       {
-               "colour-buffer = auto, depth-buffer = auto",
-               config_rgba_depth,
-       },
-};
-
-GdkGLConfig* glconfig_new_with_depth(){
-       GdkGLConfig* glconfig = 0;
-
-       for ( configs_iterator i = configs_with_depth, end = configs_with_depth + 6; i != end; ++i )
-       {
-               glconfig = gdk_gl_config_new( ( *i ).attribs );
-               if ( glconfig != 0 ) {
-                       globalOutputStream() << "OpenGL window configuration: " << ( *i ).name << "\n";
-                       return glconfig;
-               }
-       }
-
-       globalOutputStream() << "OpenGL window configuration: colour-buffer = auto, depth-buffer = auto (fallback)\n";
-       return gdk_gl_config_new_by_mode( (GdkGLConfigMode)( GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_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)) {
+            globalOutputStream() << "OpenGL window configuration: " << i->name << "\n";
+            return glconfig;
+        }
+    }
+    globalOutputStream() << "OpenGL window configuration: colour-buffer = auto, depth-buffer = auto (fallback)\n";
+    return gdk_gl_config_new_by_mode((GdkGLConfigMode) (GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH));
 }
 
-unsigned int g_context_count = 0;
-
-namespace
+int glwidget_context_created(ui::GLArea self, void *data)
 {
-       ui::Widget g_shared;
+    _glwidget_context_created(self, data);
+    return false;
 }
 
-gint glwidget_context_created( ui::Widget widget, gpointer data ){
-       if ( ++g_context_count == 1 ) {
-               g_shared = widget;
-               g_object_ref( g_shared );
-
-               glwidget_make_current( g_shared );
-               GlobalOpenGL().contextValid = true;
-
-               GLWidget_sharedContextCreated();
-       }
-       return FALSE;
-}
-
-gint glwidget_context_destroyed( ui::Widget widget, gpointer data ){
-       if ( --g_context_count == 0 ) {
-               GlobalOpenGL().contextValid = false;
-
-               GLWidget_sharedContextDestroyed();
-
-               g_shared.unref();
-               g_shared = ui::Widget(nullptr);
-       }
-       return FALSE;
+int glwidget_context_destroyed(ui::GLArea self, void *data)
+{
+    _glwidget_context_destroyed(self, data);
+    return false;
 }
 
-gboolean glwidget_enable_gl( ui::Widget widget, ui::Widget widget2, gpointer data ){
-       if ( !widget2 && !gtk_widget_is_gl_capable( widget ) ) {
-               GdkGLConfig* glconfig = ( g_object_get_data( G_OBJECT( widget ), "zbuffer" ) ) ? glconfig_new_with_depth() : glconfig_new();
-               ASSERT_MESSAGE( glconfig != 0, "failed to create OpenGL config" );
-
-               gtk_widget_set_gl_capability( widget, glconfig, g_shared ? gtk_widget_get_gl_context( g_shared ) : 0,  TRUE, GDK_GL_RGBA_TYPE );
-
-               gtk_widget_realize( widget );
-               if ( !g_shared ) {
-                       g_shared = widget;
-               }
-
-               // free glconfig?
-       }
-       return FALSE;
+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");
+        GdkGLConfig *glconfig = zbuffer ? glconfig_new_with_depth() : glconfig_new();
+        ASSERT_MESSAGE(glconfig, "failed to create OpenGL config");
+
+        const auto share_list = g_shared ? gtk_widget_get_gl_context(g_shared) : nullptr;
+        gtk_widget_set_gl_capability(self, glconfig, share_list, true, GDK_GL_RGBA_TYPE);
+
+        gtk_widget_realize(self);
+        if (!g_shared) {
+            g_shared = self;
+        }
+        // free glconfig?
+    }
+    return false;
 }
 
-ui::Widget glwidget_new( gboolean zbuffer ){
-       auto widget = ui::Widget(gtk_drawing_area_new());
-
-       g_object_set_data( G_OBJECT( widget ), "zbuffer", gint_to_pointer( zbuffer ) );
+ui::GLArea glwidget_new(bool zbuffer)
+{
+    auto self = ui::GLArea(GTK_DRAWING_AREA(gtk_drawing_area_new()));
 
-       widget.connect( "hierarchy-changed", G_CALLBACK( glwidget_enable_gl ), 0 );
+    g_object_set_data(G_OBJECT(self), "zbuffer", gint_to_pointer(zbuffer));
 
-       widget.connect( "realize", G_CALLBACK( glwidget_context_created ), 0 );
-       widget.connect( "unrealize", G_CALLBACK( glwidget_context_destroyed ), 0 );
+    self.connect("hierarchy-changed", G_CALLBACK(glwidget_enable_gl), 0);
 
-       return widget;
-}
+    self.connect("realize", G_CALLBACK(glwidget_context_created), 0);
+    self.connect("unrealize", G_CALLBACK(glwidget_context_destroyed), 0);
 
-void glwidget_destroy_context( ui::Widget widget ){
+    return self;
 }
 
-void glwidget_create_context( ui::Widget widget ){
+void glwidget_swap_buffers(ui::GLArea self)
+{
+    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(self);
+    gdk_gl_drawable_swap_buffers(gldrawable);
 }
 
-void glwidget_swap_buffers( ui::Widget widget ){
-       GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable( widget );
-       gdk_gl_drawable_swap_buffers( gldrawable );
+bool glwidget_make_current(ui::GLArea self)
+{
+    GdkGLContext *glcontext = gtk_widget_get_gl_context(self);
+    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(self);
+    return gdk_gl_drawable_gl_begin(gldrawable, glcontext);
 }
 
-gboolean glwidget_make_current( ui::Widget widget ){
-       GdkGLContext *glcontext = gtk_widget_get_gl_context( widget );
-       GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable( widget );
-       return gdk_gl_drawable_gl_begin( gldrawable, glcontext );
-}
+#endif
index 3da07c3d3f35a2dc39a2f36cf4a07a9a676f442b..6a43da88ca3eb2379a10737d7e71661ea62bbd08 100644 (file)
 #if !defined( INCLUDED_GTKUTIL_GLWIDGET_H )
 #define INCLUDED_GTKUTIL_GLWIDGET_H
 
-typedef int gint;
-typedef gint gboolean;
-
-ui::Widget glwidget_new( gboolean zbuffer );
-void glwidget_swap_buffers( ui::Widget widget );
-gboolean glwidget_make_current( ui::Widget widget );
-void glwidget_destroy_context( ui::Widget widget );
-void glwidget_create_context( ui::Widget widget );
-
-extern void ( *GLWidget_sharedContextCreated )();
-extern void ( *GLWidget_sharedContextDestroyed )();
-
+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);
+bool glwidget_make_current(ui::GLArea self);
+void glwidget_swap_buffers(ui::GLArea self);
 
 #endif
index 364c24e3d585afe28a52f3e1718149a852e08fec..d9108b66880f3b838ee128ede8f6a7f8e33bb4a1 100644 (file)
@@ -28,7 +28,7 @@ void XORRectangle::draw() const
     cairo_stroke(cr);
 }
 
-XORRectangle::XORRectangle(ui::Widget widget) : m_widget(widget), cr(0)
+XORRectangle::XORRectangle(ui::GLArea widget) : m_widget(widget), cr(0)
 {
 }
 
index 8c3ca3cf03c7ced2c74e57c1f78be15a7c1097cd..2341f1f0c5005165fef67275264a065ed4f6494a 100644 (file)
@@ -64,7 +64,7 @@ class XORRectangle
 
 rectangle_t m_rectangle;
 
-ui::Widget m_widget;
+ui::GLArea m_widget;
 cairo_t *cr;
 
 bool initialised() const;
@@ -72,7 +72,7 @@ void lazy_init();
 void draw() const;
 
 public:
-XORRectangle( ui::Widget widget );
+XORRectangle( ui::GLArea widget );
 ~XORRectangle();
 void set( rectangle_t rectangle );
 };
index 68e5ee0ffcbce36a0d8523061b1151ad978c1d7f..cf300e4401331fb6451c09a35237a6066ce2d045 100644 (file)
@@ -2,9 +2,9 @@ add_library(uilib
         uilib.cpp
         )
 
-find_package(GTK2 REQUIRED)
-target_include_directories(uilib PUBLIC ${${GTK_NS}_INCLUDE_DIRS})
-target_link_libraries(uilib PUBLIC ${${GTK_NS}_LIBRARIES})
+find_package(GTK${GTK_TARGET} REQUIRED)
+target_include_directories(uilib PUBLIC ${GTK${GTK_TARGET}_INCLUDE_DIRS})
+target_link_libraries(uilib PUBLIC ${GTK${GTK_TARGET}_LIBRARIES})
 
 target_include_directories(uilib PUBLIC gtkutil)
 target_link_libraries(uilib PUBLIC gtkutil)
index 69a46b6ddccbaae253a332fd1a15d1be8f829f9c..824af8cef43a7530754664e9739df4c70739fb92 100644 (file)
@@ -328,4 +328,16 @@ namespace ui {
     TreePath::TreePath(const char *path) : TreePath(gtk_tree_path_new_from_string(path))
     {}
 
+    // Custom
+
+    guint IGLArea::on_render(GCallback pFunction, void *data)
+    {
+#if GTK_TARGET == 3
+        return this.connect("render", pFunction, data);
+#endif
+#if GTK_TARGET == 2
+        return this.connect("expose_event", pFunction, data);
+#endif
+    };
+
 }
index 925384ee752ab1451dcea601846f2305b1c52196..72470990ea8cf7c5e4804a377ae8038de97c7c58 100644 (file)
@@ -64,6 +64,14 @@ struct _GtkWidget;
 struct _GtkWindow;
 struct _GTypeInstance;
 
+#if GTK_TARGET == 3
+struct _GtkGLArea;
+#endif
+
+#if GTK_TARGET == 2
+using _GtkGLArea = struct _GtkDrawingArea;
+#endif
+
 struct ModalDialog;
 
 namespace ui {
@@ -530,6 +538,13 @@ namespace ui {
     ,
     );
 
+    // Custom
+
+    WRAP(GLArea, Widget, _GtkGLArea, (),
+    ,
+         guint on_render(GCallback pFunction, void *data);
+    );
+
 #undef WRAP
 
     // callbacks
index 1e2040daa9a272ef7792948320b3ea24e99a0e9b..05d79830fe4fa2b56bdcadedc996d9ed325cffc9 100644 (file)
@@ -100,7 +100,7 @@ target_link_libraries(radiant
     ${CMAKE_DL_LIBS}
     ${LIBXML2_LIBRARIES}
     ${OPENGL_gl_LIBRARY}
-    ${${GTK_NS}_LIBRARIES}
+    ${GTK${GTK_TARGET}_LIBRARIES}
     ${GTKGL_LIBRARIES}
     includes
     cmdlib
index 7916f81c759834faf543613bc1f5395a1d84897b..a0c49d22021fded385483fa83fe90dcf1c74ae14 100644 (file)
@@ -672,7 +672,7 @@ static Shader* m_state_select2;
 FreezePointer m_freezePointer;
 
 public:
-ui::Widget m_gl_widget;
+ui::GLArea m_gl_widget;
 ui::Window m_parent{ui::null};
 
 SelectionSystemWindowObserver* m_window_observer;
@@ -759,7 +759,7 @@ void GlobalCamera_setCamWnd( CamWnd& camwnd ){
 }
 
 
-ui::Widget CamWnd_getWidget( CamWnd& camwnd ){
+ui::GLArea CamWnd_getWidget( CamWnd& camwnd ){
        return camwnd.m_gl_widget;
 }
 
@@ -1147,7 +1147,7 @@ CamWnd::CamWnd() :
        m_view( true ),
        m_Camera( &m_view, CamWndQueueDraw( *this ) ),
        m_cameraview( m_Camera, &m_view, ReferenceCaller<CamWnd, CamWnd_Update>( *this ) ),
-       m_gl_widget( ui::Widget(glwidget_new( TRUE )) ),
+       m_gl_widget( glwidget_new( TRUE ) ),
        m_window_observer( NewWindowObserver() ),
        m_XORRectangle( m_gl_widget ),
        m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
@@ -1171,7 +1171,7 @@ CamWnd::CamWnd() :
        gtk_widget_set_can_focus( m_gl_widget, true );
 
        m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( camera_size_allocate ), this );
-       m_exposeHandler = m_gl_widget.connect( "expose_event", G_CALLBACK( camera_expose ), this );
+       m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( camera_expose ), this );
 
        Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
 
index 312cf66d8b54976fb10d8b57f4afee592c148f22..d0722a79cef512d3878e06b4b7714b80a9ca8f16 100644 (file)
@@ -34,7 +34,7 @@ void AddCameraMovedCallback( const SignalHandler& handler );
 
 void CamWnd_Update( CamWnd& camwnd );
 
-ui::Widget CamWnd_getWidget( CamWnd& camwnd );
+ui::GLArea CamWnd_getWidget( CamWnd& camwnd );
 void CamWnd_setParent( CamWnd& camwnd, ui::Window parent );
 
 void GlobalCamera_setCamWnd( CamWnd& camwnd );
index 6081d14fd10a39175de3b78158803bdfb116aeb8..4dfee3622777759777fd3d425714a966b4956c64 100644 (file)
@@ -257,7 +257,7 @@ int m_nTotalHeight;
 CopiedString shader;
 
 ui::Window m_parent{ui::null};
-ui::Widget m_gl_widget;
+ui::GLArea m_gl_widget{ui::null};
 ui::Widget m_texture_scroll;
 ui::Widget m_treeViewTree;
 ui::Widget m_treeViewTags;
@@ -1255,7 +1255,7 @@ void Texture_Draw( TextureBrowser& textureBrowser ){
 }
 
 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser ){
-       if ( textureBrowser.m_gl_widget != 0 ) {
+       if ( textureBrowser.m_gl_widget ) {
                gtk_widget_queue_draw( textureBrowser.m_gl_widget );
        }
 }
@@ -2056,7 +2056,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
                widget_set_visible( g_TextureBrowser.m_texture_scroll, g_TextureBrowser.m_showTextureScrollbar );
        }
        { // gl_widget
-               g_TextureBrowser.m_gl_widget = ui::Widget(glwidget_new( FALSE ));
+               g_TextureBrowser.m_gl_widget = glwidget_new( FALSE );
                g_object_ref( g_TextureBrowser.m_gl_widget );
 
                gtk_widget_set_events( g_TextureBrowser.m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK );
@@ -2066,7 +2066,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
                g_TextureBrowser.m_gl_widget.show();
 
                g_TextureBrowser.m_sizeHandler = g_TextureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &g_TextureBrowser );
-               g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.connect( "expose_event", G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
+               g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
 
                g_TextureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &g_TextureBrowser );
                g_TextureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &g_TextureBrowser );
index 8250115037c26edcd48b22e60016b96d13eb9243..80b0a97bf97e76282e2cfa6e45c2d5e22cd816b1 100644 (file)
@@ -834,7 +834,7 @@ XYWnd::XYWnd() :
        gtk_widget_set_can_focus( m_gl_widget, true );
 
        m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
-       m_exposeHandler = m_gl_widget.connect( "expose_event", G_CALLBACK( xywnd_expose ), this );
+       m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
 
        m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
        m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
index 3eefc11e015a4d0e15127f497e2630cda84ae4d0..cfe8f036c11f8f1bef8a20c84a3342ff87dcae8a 100644 (file)
@@ -63,7 +63,7 @@ inline const char* ViewType_getTitle( VIEWTYPE viewtype ){
 
 class XYWnd
 {
-ui::Widget m_gl_widget;
+ui::GLArea m_gl_widget;
 guint m_sizeHandler;
 guint m_exposeHandler;
 
@@ -77,7 +77,7 @@ XYWnd();
 void queueDraw(){
        m_deferredDraw.draw();
 }
-ui::Widget GetWidget(){
+ui::GLArea GetWidget(){
        return m_gl_widget;
 }