1 /* 2 Copyright (C) 2001-2006, William Joseph. 3 All Rights Reserved. 4 5 This file is part of GtkRadiant. 6 7 GtkRadiant is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 GtkRadiant is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GtkRadiant; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #if !defined(INCLUDED_GTKUTIL_GLWIDGET_H) 23 #define INCLUDED_GTKUTIL_GLWIDGET_H 24 25 extern void (*GLWidget_sharedContextCreated) (); 26 extern void (*GLWidget_sharedContextDestroyed) (); 27 28 // Forward declaration 29 typedef struct _GdkGLConfig GdkGLConfig; 30 typedef struct _GtkWidget GtkWidget; 31 typedef int gint; 32 typedef gint gboolean; 33 34 namespace gtkutil { 35 36 class GLWidget { 37 38 // The actual widget, a GTK drawing area 39 GtkWidget* _widget; 40 41 // TRUE, if this GL widget has depth-buffering enabled 42 bool _zBuffer; 43 44 // The (singleton) widget holding the context 45 //static GtkWidget* _shared; 46 47 // Holds the number of realised GL widgets 48 //static int _realisedWidgets; 49 50 public: 51 // Constructor, pass TRUE to enable depth-buffering 52 GLWidget(bool zBuffer); 53 54 // Operator cast to GtkWidget*, for packing into parent containers 55 operator GtkWidget*() const; 56 57 // Switches the GL context to the given widget 58 static bool makeCurrent(GtkWidget* widget); 59 static void swapBuffers(GtkWidget* widget); 60 61 private: 62 // As soon as the widget is packed into a parent, this callback is invoked 63 // and enables the GL drawing for this widget 64 static gboolean onHierarchyChanged(GtkWidget* widget, 65 GtkWidget* previous_toplevel, GLWidget* self); 66 67 // Called when the GTK drawing area is realised/unrealised 68 static gint onRealise(GtkWidget* widget, GLWidget* self); 69 static gint onUnRealise(GtkWidget* widget, GLWidget* self); 70 71 // Acquires a GDK GL config structure with or without depth 72 static GdkGLConfig* createGLConfigWithDepth(); 73 static GdkGLConfig* createGLConfig(); 74 }; 75 76 } // gtkutil 77 78 #endif 79