From: Braden M. <br...@us...> - 2006-10-01 05:48:27
|
Update of /cvsroot/openvrml/openvrml/lib/gtkglext/gtk In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7146/lib/gtkglext/gtk Added Files: Tag: OpenVRML-0_16-BRANCH .cvsignore Makefile.am gtkgl.h gtkgldebug.h gtkgldefs.h gtkglext.def gtkglinit.c gtkglinit.h gtkglprivate.h gtkglversion.c gtkglversion.h.in gtkglwidget.c gtkglwidget.h Log Message: Build/package the GtkPlug application separately from the Mozilla plug-in. The Mozilla plug-in is just one possible client for this application. --- NEW FILE: .cvsignore --- Makefile.in --- NEW FILE: gtkglinit.c --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include <string.h> #include <stdlib.h> #include "gtkglprivate.h" #include "gtkglinit.h" static gboolean gtk_gl_initialized = FALSE; guint gtk_gl_debug_flags = 0; /* Global GtkGLExt debug flag */ #ifdef G_ENABLE_DEBUG static const GDebugKey gtk_gl_debug_keys[] = { {"misc", GTK_GL_DEBUG_MISC}, {"func", GTK_GL_DEBUG_FUNC} }; static const guint gtk_gl_ndebug_keys = G_N_ELEMENTS (gtk_gl_debug_keys); #endif /* G_ENABLE_DEBUG */ /** * gtk_gl_parse_args: * @argc: the number of command line arguments. * @argv: the array of command line arguments. * * Parses command line arguments, and initializes global * attributes of GtkGLExt. * * Any arguments used by GtkGLExt are removed from the array and * @argc and @argv are updated accordingly. * * You shouldn't call this function explicitely if you are using * gtk_gl_init(), or gtk_gl_init_check(). * * Return value: %TRUE if initialization succeeded, otherwise %FALSE. **/ gboolean gtk_gl_parse_args (int *argc, char ***argv) { const gchar *env_string; if (gtk_gl_initialized) return TRUE; /* * If window manager doesn't watch the WM_COLORMAP_WINDOWS property on * the top-level window, we have to set OpenGL window's colormap to the * top-level window, especially in color index mode (color index mode * uses own private colormap). */ env_string = g_getenv ("GTK_GL_INSTALL_COLORMAP"); if (env_string != NULL) { _gtk_gl_widget_install_toplevel_cmap = (atoi (env_string) != 0); env_string = NULL; } #ifdef G_ENABLE_DEBUG env_string = g_getenv ("GTK_GL_DEBUG"); if (env_string != NULL) { gtk_gl_debug_flags = g_parse_debug_string (env_string, gtk_gl_debug_keys, gtk_gl_ndebug_keys); env_string = NULL; } #endif /* G_ENABLE_DEBUG */ if (argc && argv) { gint i, j, k; for (i = 1; i < *argc;) { if (strcmp ("--gtk-gl-install-colormap", (*argv)[i]) == 0) { _gtk_gl_widget_install_toplevel_cmap = TRUE; (*argv)[i] = NULL; } #ifdef G_ENABLE_DEBUG else if ((strcmp ("--gtk-gl-debug", (*argv)[i]) == 0) || (strncmp ("--gtk-gl-debug=", (*argv)[i], 15) == 0)) { gchar *equal_pos = strchr ((*argv)[i], '='); if (equal_pos != NULL) { gtk_gl_debug_flags |= g_parse_debug_string (equal_pos+1, gtk_gl_debug_keys, gtk_gl_ndebug_keys); } else if ((i + 1) < *argc && (*argv)[i + 1]) { gtk_gl_debug_flags |= g_parse_debug_string ((*argv)[i+1], gtk_gl_debug_keys, gtk_gl_ndebug_keys); (*argv)[i] = NULL; i += 1; } (*argv)[i] = NULL; } else if ((strcmp ("--gtk-gl-no-debug", (*argv)[i]) == 0) || (strncmp ("--gtk-gl-no-debug=", (*argv)[i], 18) == 0)) { gchar *equal_pos = strchr ((*argv)[i], '='); if (equal_pos != NULL) { gtk_gl_debug_flags &= ~g_parse_debug_string (equal_pos+1, gtk_gl_debug_keys, gtk_gl_ndebug_keys); } else if ((i + 1) < *argc && (*argv)[i + 1]) { gtk_gl_debug_flags &= ~g_parse_debug_string ((*argv)[i+1], gtk_gl_debug_keys, gtk_gl_ndebug_keys); (*argv)[i] = NULL; i += 1; } (*argv)[i] = NULL; } #endif /* G_ENABLE_DEBUG */ i += 1; } for (i = 1; i < *argc; i++) { for (k = i; k < *argc; k++) if ((*argv)[k] != NULL) break; if (k > i) { k -= i; for (j = i + k; j < *argc; j++) (*argv)[j-k] = (*argv)[j]; *argc -= k; } } } /* Set the 'initialized' flag. */ gtk_gl_initialized = TRUE; return TRUE; } /** * gtk_gl_init_check: * @argc: Address of the <parameter>argc</parameter> parameter of your * <function>main()</function> function. Changed if any arguments * were handled. * @argv: Address of the <parameter>argv</parameter> parameter of * <function>main()</function>. Any parameters understood by * gtk_gl_init() are stripped before return. * * This function does the same work as gtk_gl_init() with only * a single change: It does not terminate the program if the library can't be * initialized. Instead it returns %FALSE on failure. * * This way the application can fall back to some other means of communication * with the user - for example a curses or command line interface. * * Return value: %TRUE if the GUI has been successfully initialized, * %FALSE otherwise. **/ gboolean gtk_gl_init_check (int *argc, char ***argv) { /* Init GdkGLExt library. */ if (!gdk_gl_init_check (argc, argv)) return FALSE; /* Parse args and init GtkGLExt library. */ if (!gtk_gl_parse_args (argc, argv)) { g_warning ("GtkGLExt library initialization fails."); return FALSE; } return TRUE; } /** * gtk_gl_init: * @argc: Address of the <parameter>argc</parameter> parameter of your * <function>main()</function> function. Changed if any arguments * were handled. * @argv: Address of the <parameter>argv</parameter> parameter of * <function>main()</function>. Any parameters understood by * gtk_gl_init() are stripped before return. * * Call this function before using any other GtkGLExt functions in your * applications. It will initialize everything needed to operate the library * and parses some standard command line options. @argc and * @argv are adjusted accordingly so your own code will * never see those standard arguments. * * <note><para> * This function will terminate your program if it was unable to initialize * the library for some reason. If you want your program to fall back to a * textual interface you want to call gtk_gl_init_check() instead. * </para></note> **/ void gtk_gl_init (int *argc, char ***argv) { if (!gtk_gl_init_check (argc, argv)) exit (1); } --- NEW FILE: gtkglversion.c --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "gtkglversion.h" const guint gtkglext_major_version = GTKGLEXT_MAJOR_VERSION; const guint gtkglext_minor_version = GTKGLEXT_MINOR_VERSION; const guint gtkglext_micro_version = GTKGLEXT_MICRO_VERSION; const guint gtkglext_interface_age = GTKGLEXT_INTERFACE_AGE; const guint gtkglext_binary_age = GTKGLEXT_BINARY_AGE; --- NEW FILE: gtkgl.h --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_H__ #define __GTK_GL_H__ #include <gdk/gdkgl.h> #include <gtk/gtkgldefs.h> #include <gtk/gtkglversion.h> #include <gtk/gtkglinit.h> #include <gtk/gtkglwidget.h> #endif /* __GTK_GL_H__ */ --- NEW FILE: gtkgldefs.h --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_DEFS_H__ #define __GTK_GL_DEFS_H__ #include <glib.h> G_BEGIN_DECLS #ifdef G_OS_WIN32 # ifdef GTK_GL_COMPILATION # define GTK_GL_VAR __declspec(dllexport) # else # define GTK_GL_VAR extern __declspec(dllimport) # endif #else # define GTK_GL_VAR extern #endif G_END_DECLS #endif /* __GTK_GL_DEFS_H__ */ --- NEW FILE: gtkglinit.h --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_INIT_H__ #define __GTK_GL_INIT_H__ #include <gdk/gdk.h> #include <gdk/gdkgl.h> G_BEGIN_DECLS /* * Initialization routines. */ gboolean gtk_gl_parse_args (int *argc, char ***argv); gboolean gtk_gl_init_check (int *argc, char ***argv); void gtk_gl_init (int *argc, char ***argv); G_END_DECLS #endif /* __GTK_GL_INIT_H__ */ --- NEW FILE: gtkglext.def --- EXPORTS gtk_gl_debug_flags gtk_gl_init gtk_gl_init_check gtk_gl_parse_args gtk_widget_create_gl_context gtk_widget_get_gl_config gtk_widget_get_gl_context gtk_widget_get_gl_window gtk_widget_is_gl_capable gtk_widget_set_gl_capability gtkglext_binary_age gtkglext_interface_age gtkglext_major_version gtkglext_micro_version gtkglext_minor_version --- NEW FILE: gtkglwidget.h --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_WIDGET_H__ #define __GTK_GL_WIDGET_H__ #include <gdk/gdk.h> #include <gdk/gdkgl.h> #include <gtk/gtkwidget.h> G_BEGIN_DECLS gboolean gtk_widget_set_gl_capability (GtkWidget *widget, GdkGLConfig *glconfig, GdkGLContext *share_list, gboolean direct, int render_type); gboolean gtk_widget_is_gl_capable (GtkWidget *widget); GdkGLConfig *gtk_widget_get_gl_config (GtkWidget *widget); GdkGLContext *gtk_widget_create_gl_context (GtkWidget *widget, GdkGLContext *share_list, gboolean direct, int render_type); GdkGLContext *gtk_widget_get_gl_context (GtkWidget *widget); GdkGLWindow *gtk_widget_get_gl_window (GtkWidget *widget); #define gtk_widget_get_gl_drawable(widget) \ GDK_GL_DRAWABLE (gtk_widget_get_gl_window (widget)) G_END_DECLS #endif /* __GTK_GL_WIDGET_H__ */ --- NEW FILE: Makefile.am --- ## -*- Makefile -*- ## Makefile.am for gtkglext/gtk EXTRA_DIST = \ gtkglversion.h.in \ gtkglext.def if PLATFORM_WIN32 no_undefined = -no-undefined endif if OS_WIN32 gtkglext_def = gtkglext.def gtkglext_win32_symbols = -export-symbols $(gtkglext_def) endif if MS_LIB_AVAILABLE noinst_DATA = gtkglext-win32-@GTKGLEXT_API_VERSION@.lib gtkglext-win32-@GTKGLEXT_API_VERSION@.lib: libgtkglext-win32-@GTKGLEXT_API_VERSION@.la $(gtkglext_def) lib -name:libgtkglext-win32-@GTKGLEXT_API_VERSION@-@LT_CURRENT_MINUS_AGE@.dll -def:$(gtkglext_def) -out:$@ install-ms-lib: $(INSTALL) gtkglext-win32-@GTKGLEXT_API_VERSION@.lib $(DESTDIR)$(libdir) uninstall-ms-lib: -rm $(DESTDIR)$(libdir)/gtkglext-win32-@GTKGLEXT_API_VERSION@.lib else install-ms-lib: uninstall-ms-lib: endif common_includes = \ -DG_LOG_DOMAIN=\"GtkGLExt\" \ -DGTK_GL_COMPILATION \ -I$(top_srcdir) \ -I$(top_builddir)/gdk \ $(GTKGLEXT_DEBUG_FLAGS) \ $(GTKGLEXT_DEP_CFLAGS) \ -DG_DISABLE_DEPRECATED \ -DGDK_DISABLE_DEPRECATED \ -DGDK_PIXBUF_DISABLE_DEPRECATED \ -DGTK_DISABLE_DEPRECATED common_ldflags = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ -export-dynamic \ -rpath $(libdir) \ $(no_undefined) \ @LIBTOOL_EXPORT_OPTIONS@ \ $(gtkglext_win32_symbols) common_libadd = \ $(top_builddir)/gdk/$(gdkglext_targetlib) \ $(GTKGLEXT_DEP_LIBS) # # setup source file variables # gtkglext_public_h_sources = \ gtkgl.h \ gtkgldefs.h \ gtkglversion.h \ gtkglinit.h \ gtkglwidget.h gtkglext_private_h_sources = \ gtkglprivate.h gtkglext_c_sources = \ gtkglversion.c \ gtkglinit.c \ gtkglwidget.c gtkglext_headers = \ $(gtkglext_public_h_sources) \ gtkgldebug.h gtkglext_sources = \ $(gtkglext_private_h_sources) \ $(gtkglext_c_sources) # # setup GtkGLExt sources and their dependancies # gtkglextincludedir = $(includedir)/gtkglext-@GTKGLEXT_API_VERSION@/gtk noinst_HEADERS = $(gtkglext_headers) INCLUDES = $(common_includes) noinst_LTLIBRARIES = $(gtkglext_targetlib) EXTRA_LTLIBRARIES = \ libgtkglext-x11-@API_MJ@.@API_MI@.la \ libgtkglext-win32-@API_MJ@.@API_MI@.la libgtkglext_x11_@API_MJ@_@API_MI@_la_SOURCES = $(gtkglext_sources) libgtkglext_x11_@API_MJ@_@API_MI@_la_LDFLAGS = $(common_ldflags) libgtkglext_x11_@API_MJ@_@API_MI@_la_LIBADD = $(common_libadd) libgtkglext_win32_@API_MJ@_@API_MI@_la_SOURCES = $(gtkglext_sources) libgtkglext_win32_@API_MJ@_@API_MI@_la_LDFLAGS = $(common_ldflags) libgtkglext_win32_@API_MJ@_@API_MI@_la_LIBADD = $(common_libadd) libgtkglext_win32_@API_MJ@_@API_MI@_la_DEPENDENCIES = $(gtkglext_def) --- NEW FILE: gtkglversion.h.in --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_VERSION_H__ #define __GTK_GL_VERSION_H__ #include <glib.h> #include <gtk/gtkgldefs.h> G_BEGIN_DECLS /* * Compile time version. */ #define GTKGLEXT_MAJOR_VERSION (@GTKGLEXT_MAJOR_VERSION@) #define GTKGLEXT_MINOR_VERSION (@GTKGLEXT_MINOR_VERSION@) #define GTKGLEXT_MICRO_VERSION (@GTKGLEXT_MICRO_VERSION@) #define GTKGLEXT_INTERFACE_AGE (@GTKGLEXT_INTERFACE_AGE@) #define GTKGLEXT_BINARY_AGE (@GTKGLEXT_BINARY_AGE@) /* * Check whether a GtkGLExt version equal to or greater than * major.minor.micro is present. */ #define GTKGLEXT_CHECK_VERSION(major, minor, micro) \ (GTKGLEXT_MAJOR_VERSION > (major) || \ (GTKGLEXT_MAJOR_VERSION == (major) && GTKGLEXT_MINOR_VERSION > (minor)) || \ (GTKGLEXT_MAJOR_VERSION == (major) && GTKGLEXT_MINOR_VERSION == (minor) && \ GTKGLEXT_MICRO_VERSION >= (micro))) /* * Library version. */ GTK_GL_VAR const guint gtkglext_major_version; GTK_GL_VAR const guint gtkglext_minor_version; GTK_GL_VAR const guint gtkglext_micro_version; GTK_GL_VAR const guint gtkglext_interface_age; GTK_GL_VAR const guint gtkglext_binary_age; G_END_DECLS #endif /* __GTK_GL_VERSION_H__ */ --- NEW FILE: gtkglprivate.h --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_PRIVATE_H__ #define __GTK_GL_PRIVATE_H__ #include <gtk/gtkgldefs.h> #include <gtk/gtkgldebug.h> G_BEGIN_DECLS /* Install colormap to top-level window. */ extern gboolean _gtk_gl_widget_install_toplevel_cmap; G_END_DECLS #endif /* __GTK_GL_PRIVATE_H__ */ --- NEW FILE: gtkgldebug.h --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef __GTK_GL_DEBUG_H__ #define __GTK_GL_DEBUG_H__ #include <glib.h> #include <gtk/gtkgldefs.h> G_BEGIN_DECLS typedef enum { GTK_GL_DEBUG_MISC = 1 << 0, GTK_GL_DEBUG_FUNC = 1 << 1 } GtkGLDebugFlag; #ifdef G_ENABLE_DEBUG #define GTK_GL_NOTE(type, action) G_STMT_START { \ if (gtk_gl_debug_flags & GTK_GL_DEBUG_##type) \ { action; }; } G_STMT_END #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 # define __func__ __FUNCTION__ # else # define __func__ "<unknown>" # endif #endif #define GTK_GL_NOTE_FUNC() G_STMT_START { \ if (gtk_gl_debug_flags & GTK_GL_DEBUG_FUNC) \ g_message (" - %s ()", __func__); } G_STMT_END #define GTK_GL_NOTE_FUNC_PRIVATE() G_STMT_START { \ if (gtk_gl_debug_flags & GTK_GL_DEBUG_FUNC) \ g_message (" -- %s ()", __func__); } G_STMT_END #else /* !G_ENABLE_DEBUG */ #define GTK_GL_NOTE(type, action) #define GTK_GL_NOTE_FUNC() #define GTK_GL_NOTE_FUNC_PRIVATE() #endif /* G_ENABLE_DEBUG */ GTK_GL_VAR guint gtk_gl_debug_flags; G_END_DECLS #endif /* __GTK_GL_DEBUG_H__ */ --- NEW FILE: gtkglwidget.c --- /* GtkGLExt - OpenGL Extension to GTK+ * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include <gtk/gtkmain.h> #include "gtkglprivate.h" #include "gtkglwidget.h" typedef struct { GdkGLConfig *glconfig; GdkGLContext *share_list; gboolean direct; int render_type; GdkGLContext *glcontext; gulong unrealize_handler; guint is_realized : 1; } GLWidgetPrivate; static const gchar quark_gl_private_string[] = "gtk-gl-widget-private"; static GQuark quark_gl_private = 0; gboolean _gtk_gl_widget_install_toplevel_cmap = FALSE; static void gtk_gl_widget_realize (GtkWidget *widget, GLWidgetPrivate *private); static gboolean gtk_gl_widget_configure_event (GtkWidget *widget, GdkEventConfigure *event, GLWidgetPrivate *private); static void gtk_gl_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation, GLWidgetPrivate *private); static void gtk_gl_widget_unrealize (GtkWidget *widget, GLWidgetPrivate *private); static void gtk_gl_widget_parent_set (GtkWidget *widget, GtkObject *old_parent, GdkColormap *colormap); static void gtk_gl_widget_style_set (GtkWidget *widget, GtkStyle *previous_style, gpointer user_data); static void gl_widget_private_destroy (GLWidgetPrivate *private); /* * Signal handlers. */ static void gtk_gl_widget_realize (GtkWidget *widget, GLWidgetPrivate *private) { GdkGLWindow *glwindow; GTK_GL_NOTE_FUNC_PRIVATE (); /* * Set OpenGL-capability to widget->window, then connect some signal * handlers. */ if (!gdk_window_is_gl_capable (widget->window)) { glwindow = gdk_window_set_gl_capability (widget->window, private->glconfig, NULL); if (glwindow == NULL) { g_warning ("cannot set OpenGL-capability to widget->window\n"); return; } /* Connect "unrealize" signal handler. */ if (private->unrealize_handler == 0) private->unrealize_handler = g_signal_connect (G_OBJECT (widget), "unrealize", G_CALLBACK (gtk_gl_widget_unrealize), private); } private->is_realized = TRUE; } static gboolean gtk_gl_widget_configure_event (GtkWidget *widget, GdkEventConfigure *event, GLWidgetPrivate *private) { GTK_GL_NOTE_FUNC_PRIVATE (); if (!private->is_realized) { /* Realize if OpenGL-capable window is not realized yet. */ gtk_gl_widget_realize (widget, private); } return FALSE; } static void gtk_gl_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation, GLWidgetPrivate *private) { GdkGLDrawable *gldrawable; GTK_GL_NOTE_FUNC_PRIVATE (); /* * Synchronize OpenGL and window resizing request streams. */ if (GTK_WIDGET_REALIZED (widget) && private->is_realized) { gldrawable = gdk_window_get_gl_drawable (widget->window); gdk_gl_drawable_wait_gdk (gldrawable); } } static void gtk_gl_widget_unrealize (GtkWidget *widget, GLWidgetPrivate *private) { GTK_GL_NOTE_FUNC_PRIVATE (); /* * Destroy OpenGL rendering context. */ if (private->glcontext != NULL) { gdk_gl_context_destroy (private->glcontext); private->glcontext = NULL; } /* * Remove OpenGL-capability from widget->window. */ if (GTK_WIDGET_REALIZED (widget)) gdk_window_unset_gl_capability (widget->window); private->is_realized = FALSE; } static void gtk_gl_widget_parent_set (GtkWidget *widget, GtkObject *old_parent, GdkColormap *colormap) { GtkWidget *toplevel; GTK_GL_NOTE_FUNC_PRIVATE (); /* * Try to install colormap to the top-level window. */ toplevel = gtk_widget_get_toplevel (widget); if (GTK_WIDGET_TOPLEVEL (toplevel) && !GTK_WIDGET_REALIZED (toplevel)) { GTK_GL_NOTE (MISC, g_message (" - Install colormap to the top-level window.")); gtk_widget_set_colormap (toplevel, colormap); } } static void gtk_gl_widget_style_set (GtkWidget *widget, GtkStyle *previous_style, gpointer user_data) { GTK_GL_NOTE_FUNC_PRIVATE (); /* * Set a background of "None" on window to avoid AIX X server crash. */ if (GTK_WIDGET_REALIZED (widget)) { GTK_GL_NOTE (MISC, g_message (" - window->bg_pixmap = %p", ((GdkWindowObject *) (widget->window))->bg_pixmap)); gdk_window_set_back_pixmap (widget->window, NULL, FALSE); GTK_GL_NOTE (MISC, g_message (" - window->bg_pixmap = %p", ((GdkWindowObject *) (widget->window))->bg_pixmap)); } } static void gl_widget_private_destroy (GLWidgetPrivate *private) { GTK_GL_NOTE_FUNC_PRIVATE (); g_object_unref (G_OBJECT (private->glconfig)); if (private->share_list != NULL) g_object_unref (G_OBJECT (private->share_list)); g_free (private); } /** * gtk_widget_set_gl_capability: * @widget: the #GtkWidget to be used as the rendering area. * @glconfig: a #GdkGLConfig. * @share_list: the #GdkGLContext with which to share display lists and texture * objects. NULL indicates that no sharing is to take place. * @direct: whether rendering is to be done with a direct connection to * the graphics system. * @render_type: GDK_GL_RGBA_TYPE or GDK_GL_COLOR_INDEX_TYPE (currently not * used). * * Set the OpenGL-capability to the @widget. * This function prepares the widget for its use with OpenGL. * * Return value: TRUE if it is successful, FALSE otherwise. **/ gboolean gtk_widget_set_gl_capability (GtkWidget *widget, GdkGLConfig *glconfig, GdkGLContext *share_list, gboolean direct, int render_type) { GdkColormap *colormap; GLWidgetPrivate *private; GTK_GL_NOTE_FUNC (); g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); g_return_val_if_fail (!GTK_WIDGET_NO_WINDOW (widget), FALSE); g_return_val_if_fail (!GTK_WIDGET_REALIZED (widget), FALSE); g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); /* * Init quark. */ if (quark_gl_private == 0) quark_gl_private = g_quark_from_static_string (quark_gl_private_string); /* * Already OpenGL-capable? */ if (gtk_widget_is_gl_capable (widget)) return TRUE; /* * Set OpenGL-capable colormap. */ colormap = gdk_gl_config_get_colormap (glconfig); gtk_widget_set_colormap (widget, colormap); /* Install colormap to the top-level window. */ if (_gtk_gl_widget_install_toplevel_cmap) { /* * If window manager doesn't watch the WM_COLORMAP_WINDOWS property on * the top-level window, we have to set OpenGL window's colormap to the * top-level window, especially in color index mode (color index mode * uses own private colormap). */ /* Signal handler to set colormap to the top-level window. */ g_signal_connect (G_OBJECT (widget), "parent_set", G_CALLBACK (gtk_gl_widget_parent_set), colormap); /* If given widget has the top-level window, colormap is set here. */ gtk_gl_widget_parent_set (widget, NULL, colormap); } /* * Disable backing store feature of the widget. */ gtk_widget_set_double_buffered (widget, FALSE); /* * "style_set" signal handler to set a background of "None" on window. * (relates AIX X server crash) */ g_signal_connect_after (G_OBJECT (widget), "style_set", G_CALLBACK (gtk_gl_widget_style_set), NULL); /* * Set GL widget's private data. */ private = g_new (GLWidgetPrivate, 1); private->glconfig = glconfig; g_object_ref (G_OBJECT (private->glconfig)); if (share_list != NULL && GDK_IS_GL_CONTEXT (share_list)) { private->share_list = share_list; g_object_ref (G_OBJECT (private->share_list)); } else { private->share_list = NULL; } private->direct = direct; private->render_type = render_type; private->glcontext = NULL; private->unrealize_handler = 0; private->is_realized = FALSE; g_object_set_qdata_full (G_OBJECT (widget), quark_gl_private, private, (GDestroyNotify) gl_widget_private_destroy); /* * Connect signal handlers to realize OpenGL-capable widget. */ g_signal_connect (G_OBJECT (widget), "realize", G_CALLBACK (gtk_gl_widget_realize), private); /* gtk_drawing_area sends configure_event when it is realized. */ g_signal_connect (G_OBJECT (widget), "configure_event", G_CALLBACK (gtk_gl_widget_configure_event), private); /* * Connect "size_allocate" signal handler to synchronize OpenGL and * window resizing request streams. */ g_signal_connect (G_OBJECT (widget), "size_allocate", G_CALLBACK (gtk_gl_widget_size_allocate), private); return TRUE; } /** * gtk_widget_is_gl_capable: * @widget: a #GtkWidget. * * Returns whether the @widget is OpenGL-capable. * * Return value: TRUE if the @widget is OpenGL-capable, FALSE otherwise. **/ gboolean gtk_widget_is_gl_capable (GtkWidget *widget) { g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); return (g_object_get_qdata (G_OBJECT (widget), quark_gl_private) != NULL); } /** * gtk_widget_get_gl_config: * @widget: a #GtkWidget. * * Returns the #GdkGLConfig referred by the @widget. * * Return value: the #GdkGLConfig. **/ GdkGLConfig * gtk_widget_get_gl_config (GtkWidget *widget) { GLWidgetPrivate *private; g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); private = g_object_get_qdata (G_OBJECT (widget), quark_gl_private); if (private == NULL) return NULL; return private->glconfig; } /** * gtk_widget_create_gl_context: * @widget: a #GtkWidget. * @share_list: the #GdkGLContext with which to share display lists and texture * objects. NULL indicates that no sharing is to take place. * @direct: whether rendering is to be done with a direct connection to * the graphics system. * @render_type: GDK_GL_RGBA_TYPE or GDK_GL_COLOR_INDEX_TYPE (currently not * used). * * Creates a new #GdkGLContext with the appropriate #GdkGLDrawable * for this widget. The GL context must be freed when you're * finished with it. See also gtk_widget_get_gl_context(). * * Return value: the new #GdkGLContext. **/ GdkGLContext * gtk_widget_create_gl_context (GtkWidget *widget, GdkGLContext *share_list, gboolean direct, int render_type) { GdkGLDrawable *gldrawable; GdkGLContext *glcontext; GTK_GL_NOTE_FUNC (); g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL); gldrawable = gdk_window_get_gl_drawable (widget->window); if (gldrawable == NULL) return NULL; /* * Create OpenGL rendering context. */ glcontext = gdk_gl_context_new (gldrawable, share_list, direct, render_type); if (glcontext == NULL) { g_warning ("cannot create GdkGLContext\n"); return NULL; } return glcontext; } /** * gtk_widget_get_gl_context: * @widget: a #GtkWidget. * * Returns the #GdkGLContext with the appropriate #GdkGLDrawable * for this widget. Unlike the GL context returned by * gtk_widget_create_gl_context(), this context is owned by the widget. * * #GdkGLContext is needed for the function gdk_gl_drawable_begin, * or for sharing display lists (see gtk_widget_set_gl_capability()). * * Return value: the #GdkGLContext. **/ GdkGLContext * gtk_widget_get_gl_context (GtkWidget *widget) { GLWidgetPrivate *private; g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL); private = g_object_get_qdata (G_OBJECT (widget), quark_gl_private); if (private == NULL) return NULL; if (private->glcontext == NULL) private->glcontext = gtk_widget_create_gl_context (widget, private->share_list, private->direct, private->render_type); return private->glcontext; } /** * gtk_widget_get_gl_window: * @widget: a #GtkWidget. * * Returns the #GdkGLWindow owned by the @widget. * * Return value: the #GdkGLWindow. **/ GdkGLWindow * gtk_widget_get_gl_window (GtkWidget *widget) { g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL); return gdk_window_get_gl_window (widget->window); } |