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;
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);
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;
// 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);
}
};
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,
}
};
-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)) {
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,
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,
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,
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,
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,
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,
GDK_GL_ATTRIB_LIST_NONE,
};
-const config_t configs_with_depth[] =
+static const config_t configs_with_depth[] =
{
{
"colour-buffer = 32bpp, depth-buffer = 32bpp",
},
};
-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)) {
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;
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");