+/*
+ * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include <gtk/gtk.h>
/***************************
* GtkGlExt implementation *
***************************/
-#if defined(USE_GTKGLEXT)
+#if defined(SYS_GTKGLEXT)
#include <gtk/gtkgl.h>
void gtk_gl_enable(GtkWidget *widget)
{
/**********************
* X11 implementation *
**********************/
-#elif defined(USE_GLX)
+#elif defined(SYS_X11)
#include <GL/glx.h>
#include <gdk/gdkx.h>
void gtk_gl_enable(GtkWidget *widget)
GLX_DEPTH_SIZE, 1,
None};
XVisualInfo *xvinfo = glXChooseVisual(xdisplay, nscreen, attribs);
+ if (!xvinfo)
+ g_error("GtkGl: enable - unable to get valid OpenGL Visual");
GLXContext context = glXCreateContext(xdisplay, xvinfo, NULL, False);
g_object_set_data(G_OBJECT(widget), "glcontext", context);
/************************
* Win32 implementation *
************************/
-#elif defined(USE_WGL)
+#elif defined(SYS_WIN)
#include <windows.h>
#include <gdk/gdkwin32.h>
static void on_realize(GtkWidget *widget, gpointer _)
/**************************
* Mac OSX implementation *
**************************/
-#elif defined(USE_CGL)
-void gtk_gl_enable(GtkWidget *widget) { }
-void gtk_gl_begin(GtkWidget *widget) { }
-void gtk_gl_end(GtkWidget *widget) { }
-void gtk_gl_disable(GtkWidget *widget) { }
+#elif defined(SYS_MAC)
+#include <gdk/gdkquartz.h>
+void gtk_gl_enable(GtkWidget *widget)
+{
+ g_debug("GtkGl: enable");
+
+ /* Create context */
+ NSOpenGLPixelFormatAttribute attribs[] = {
+ NSOpenGLPFAColorSize, 24,
+ NSOpenGLPFAAlphaSize, 8,
+ NSOpenGLPFADepthSize, 1,
+ NSOpenGLPFADoubleBuffer,
+ 0
+ };
+ NSOpenGLPixelFormat *pix = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
+ NSOpenGLContext *ctx = [[NSOpenGLContext alloc] initWithFormat:pix shareContext:nil];
+
+ /* Attach to widget */
+ gtk_widget_set_double_buffered(widget, FALSE);
+
+ /* Save context */
+ g_object_set_data(G_OBJECT(widget), "glcontext", ctx);
+}
+
+void gtk_gl_begin(GtkWidget *widget)
+{
+ g_debug("GtkGl: begin");
+ GtkAllocation alloc;
+ gdk_window_ensure_native(gtk_widget_get_window(widget));
+ gtk_widget_get_allocation(widget, &alloc);
+
+ NSOpenGLContext *ctx = g_object_get_data(G_OBJECT(widget), "glcontext");
+ GdkWindow *win = gtk_widget_get_window(widget);
+ NSView *view = gdk_quartz_window_get_nsview(win);
+ NSRect rect = NSMakeRect(alloc.x, alloc.y, alloc.width, alloc.height);
+
+ [ctx setView:view];
+ [ctx makeCurrentContext];
+ [ctx update];
+ [view setFrame:rect];
+}
+
+void gtk_gl_end(GtkWidget *widget)
+{
+ g_debug("GtkGl: end");
+ NSOpenGLContext *ctx = g_object_get_data(G_OBJECT(widget), "glcontext");
+ [ctx flushBuffer];
+}
+
+void gtk_gl_disable(GtkWidget *widget)
+{
+ g_debug("GtkGl: disable");
+}
/****************************