diff options
author | waker <wakeroid@gmail.com> | 2013-08-15 20:38:57 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2013-08-15 20:38:57 +0200 |
commit | 60b4644d37583566563641185d13aaa1a453f908 (patch) | |
tree | d0f1bb918840647b0e9f18b22b3c270e6d8601ec | |
parent | 1ab7955320ef408889a220bd87af33ccc7de7a52 (diff) |
gtkui: added experimental gtkglext port to GTK3, fixed GTK3 build errors
65 files changed, 8579 insertions, 10 deletions
diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am index f2b8df06..7979bec9 100644 --- a/plugins/gtkui/Makefile.am +++ b/plugins/gtkui/Makefile.am @@ -95,18 +95,75 @@ endif endif if HAVE_GTK3 -ddb_gui_GTK3_la_SOURCES = $(GTKUI_SOURCES) +GTKGLEXT_SOURCES = \ + gtkglext-gtk3/gtk/gtkglinit.c\ + gtkglext-gtk3/gtk/gtkglversion.c\ + gtkglext-gtk3/gtk/gtkglwidget.c\ + gtkglext-gtk3/gtk/gtkgldebug.h\ + gtkglext-gtk3/gtk/gtkgldefs.h\ + gtkglext-gtk3/gtk/gtkgl.h\ + gtkglext-gtk3/gtk/gtkglinit.h\ + gtkglext-gtk3/gtk/gtkglprivate.h\ + gtkglext-gtk3/gtk/gtkglwidget.h\ + gtkglext-gtk3/gdk/gdkglconfig.c\ + gtkglext-gtk3/gdk/gdkglconfigimpl.c\ + gtkglext-gtk3/gdk/gdkglcontext.c\ + gtkglext-gtk3/gdk/gdkglcontextimpl.c\ + gtkglext-gtk3/gdk/gdkgldrawable.c\ + gtkglext-gtk3/gdk/gdkglinit.c\ + gtkglext-gtk3/gdk/gdkglquery.c\ + gtkglext-gtk3/gdk/gdkglversion.c\ + gtkglext-gtk3/gdk/gdkglwindow.c\ + gtkglext-gtk3/gdk/gdkglwindowimpl.c\ + gtkglext-gtk3/gdk/gdkglconfig.h\ + gtkglext-gtk3/gdk/gdkglconfigimpl.h\ + gtkglext-gtk3/gdk/gdkglcontext.h\ + gtkglext-gtk3/gdk/gdkglcontextimpl.h\ + gtkglext-gtk3/gdk/gdkgldebug.h\ + gtkglext-gtk3/gdk/gdkgldefs.h\ + gtkglext-gtk3/gdk/gdkgldrawable.h\ + gtkglext-gtk3/gdk/gdkgl.h\ + gtkglext-gtk3/gdk/gdkglinit.h\ + gtkglext-gtk3/gdk/gdkglprivate.h\ + gtkglext-gtk3/gdk/gdkglquery.h\ + gtkglext-gtk3/gdk/gdkgltokens.h\ + gtkglext-gtk3/gdk/gdkgltypes.h\ + gtkglext-gtk3/gdk/gdkglwindow.h\ + gtkglext-gtk3/gdk/gdkglwindowimpl.h\ + gtkglext-gtk3/gdk/x11/gdkglconfig-x11.c\ + gtkglext-gtk3/gdk/x11/gdkglcontext-x11.c\ + gtkglext-gtk3/gdk/x11/gdkglquery-x11.c\ + gtkglext-gtk3/gdk/x11/gdkglwindow-x11.c\ + gtkglext-gtk3/gdk/x11/gdkx11glconfig.c\ + gtkglext-gtk3/gdk/x11/gdkx11glcontext.c\ + gtkglext-gtk3/gdk/x11/gdkx11glwindow.c\ + gtkglext-gtk3/gdk/x11/gdkglconfig-x11.h\ + gtkglext-gtk3/gdk/x11/gdkglcontext-x11.h\ + gtkglext-gtk3/gdk/x11/gdkglprivate-x11.h\ + gtkglext-gtk3/gdk/x11/gdkglquery-x11.h\ + gtkglext-gtk3/gdk/x11/gdkglwindow-x11.h\ + gtkglext-gtk3/gdk/x11/gdkglx.h\ + gtkglext-gtk3/gdk/x11/gdkx11glconfig.h\ + gtkglext-gtk3/gdk/x11/gdkx11glcontext.h\ + gtkglext-gtk3/gdk/x11/gdkx11glquery.h\ + gtkglext-gtk3/gdk/x11/gdkx11glwindow.h + +GTKGLEXT_CFLAGS = -I@top_srcdir@/plugins/gtkui/gtkglext-gtk3 -I@top_srcdir@/plugins/gtkui/gtkglext-gtk3/gdk -DGTK_GL_COMPILATION -DGDK_GL_COMPILATION +GTKGLEXT_LIBS = -lGL + +ddb_gui_GTK3_la_SOURCES = $(GTKUI_SOURCES) $(GTKGLEXT_SOURCES) ddb_gui_GTK3_la_LDFLAGS = -module + if STATICLINK GTK_ROOT_300=@top_srcdir@/$(LIB)/gtk-3.0.0 -ddb_gui_GTK3_la_LIBADD = $(LDADD) -L$(GTK_ROOT_300)/lib -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -lfreetype -lfontconfig $(SM_LIBADD) +ddb_gui_GTK3_la_LIBADD = $(LDADD) -L$(GTK_ROOT_300)/lib -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -lfreetype -lfontconfig $(SM_LIBADD) $(GTKGLEXT_LIBS) -ddb_gui_GTK3_la_CFLAGS = -std=c99 -I$(GTK_ROOT_300)/include/gtk-3.0 -I$(GTK_ROOT_300)/include/pango-1.0 -I$(GTK_ROOT_300)/include/gio-unix-2.0/ -I$(GTK_ROOT_300)/include/atk-1.0 -I$(GTK_ROOT_300)/include/cairo -I$(GTK_ROOT_300)/include/gdk-pixbuf-2.0 -I$(GTK_ROOT_300)/include/freetype2 -I$(GTK_ROOT_300)/include/glib-2.0 -I$(GTK_ROOT_300)/lib/glib-2.0/include $(SM_CFLAGS) +ddb_gui_GTK3_la_CFLAGS = -std=c99 -I$(GTK_ROOT_300)/include/gtk-3.0 -I$(GTK_ROOT_300)/include/pango-1.0 -I$(GTK_ROOT_300)/include/gio-unix-2.0/ -I$(GTK_ROOT_300)/include/atk-1.0 -I$(GTK_ROOT_300)/include/cairo -I$(GTK_ROOT_300)/include/gdk-pixbuf-2.0 -I$(GTK_ROOT_300)/include/freetype2 -I$(GTK_ROOT_300)/include/glib-2.0 -I$(GTK_ROOT_300)/lib/glib-2.0/include $(SM_CFLAGS) $(GTKGLEXT_CFLAGS) else -ddb_gui_GTK3_la_LIBADD = $(LDADD) $(GTK3_DEPS_LIBS) $(SM_LIBADD) -ddb_gui_GTK3_la_CFLAGS = -std=c99 $(GTK3_DEPS_CFLAGS) $(SM_CFLAGS) +ddb_gui_GTK3_la_LIBADD = $(LDADD) $(GTK3_DEPS_LIBS) $(SM_LIBADD) $(GTKGLEXT_LIBS) +ddb_gui_GTK3_la_CFLAGS = -std=c99 $(GTK3_DEPS_CFLAGS) $(SM_CFLAGS) $(GTKGLEXT_CFLAGS) endif endif diff --git a/plugins/gtkui/ddbcellrenderertextmultiline.c b/plugins/gtkui/ddbcellrenderertextmultiline.c index c6d39881..0312a35f 100644 --- a/plugins/gtkui/ddbcellrenderertextmultiline.c +++ b/plugins/gtkui/ddbcellrenderertextmultiline.c @@ -360,7 +360,7 @@ popdown_timeout (gpointer data) priv->entry_menu_popdown_timeout = 0; - if (!GTK_WIDGET_HAS_FOCUS (priv->entry)) + if (!gtk_widget_has_focus (priv->entry)) ddb_cell_renderer_text_multiline_gtk_cell_renderer_text_editing_done (priv->entry, data); return FALSE; diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c index 25190423..13ea8e6e 100644 --- a/plugins/gtkui/ddblistview.c +++ b/plugins/gtkui/ddblistview.c @@ -1233,7 +1233,7 @@ ddb_listview_list_render_row_background (DdbListview *ps, cairo_t *cr, DdbListvi gtk_paint_flat_box (gtk_widget_get_style (treeview), cr, GTK_STATE_SELECTED, GTK_SHADOW_NONE, treeview, even ? "cell_even_ruled" : "cell_odd_ruled", x-1, y-1, w+1, h+1); #else gtk_paint_flat_box (gtk_widget_get_style (treeview), ps->list->window, GTK_STATE_SELECTED, GTK_SHADOW_NONE, NULL, treeview, even ? "cell_even_ruled" : "cell_odd_ruled", x, y, w, h); -// if (GTK_WIDGET_HAS_FOCUS (ps->list)) { +// if (gtk_widget_has_focus (ps->list)) { // gtk_paint_focus (gtk_widget_get_style (treeview), ps->list->window, GTK_STATE_SELECTED, NULL, treeview, "treeview", x, y, w, h); // } #endif @@ -1254,7 +1254,7 @@ ddb_listview_list_render_row_background (DdbListview *ps, cairo_t *cr, DdbListvi #endif } } - if (cursor && GTK_WIDGET_HAS_FOCUS (ps->list)) { + if (cursor && gtk_widget_has_focus (ps->list)) { // not all gtk engines/themes render focus rectangle in treeviews // but we want it anyway //treeview->style->fg_gc[GTK_STATE_NORMAL] diff --git a/plugins/gtkui/gtkglext-gtk3/AUTHORS b/plugins/gtkui/gtkglext-gtk3/AUTHORS new file mode 100644 index 00000000..871761dc --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/AUTHORS @@ -0,0 +1,28 @@ +Maintainers +=========== + +Stéphane Brunet <stephane@stephanebrunet.net> + +Ralf Corsépius <rc040203@freenet.de> + +Braden McDaniel <braden@endoframe.com> + + +Original Author +=============== + +Naofumi Yasufuku (安福 尚文) <naofumi@users.sourceforge.net> + + +Contributors +============ + +Alif Wahid <awah005@users.sourceforge.net> + * Port of viewlw, the LightWave 3D object viewer demo, that comes + with the GtkGLArea. The program is originally written by Janne Lof. + * rotating-square.c, coolwave.c, coolwave2.c, template.c and + scribble-gl.c demo programs. + +Igor Fernandez de Bustos <impfedei@bi.ehu.es> + * Documentations. + diff --git a/plugins/gtkui/gtkglext-gtk3/COPYING b/plugins/gtkui/gtkglext-gtk3/COPYING new file mode 100644 index 00000000..d60c31a9 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/plugins/gtkui/gtkglext-gtk3/COPYING.LIB b/plugins/gtkui/gtkglext-gtk3/COPYING.LIB new file mode 100644 index 00000000..cf9b6b99 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/COPYING.LIB @@ -0,0 +1,510 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations +below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. +^L + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it +becomes a de-facto standard. To achieve this, non-free programs must +be allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. +^L + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control +compilation and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. +^L + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. +^L + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least + three years, to give the same user the materials specified in + Subsection 6a, above, for a charge no more than the cost of + performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. +^L + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. +^L + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply, and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License +may add an explicit geographical distribution limitation excluding those +countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. +^L + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS +^L + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms +of the ordinary General Public License). + + To apply these terms, attach the following notices to the library. +It is safest to attach them to the start of each source file to most +effectively convey the exclusion of warranty; and each file should +have at least the "copyright" line and a pointer to where the full +notice is found. + + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or +your school, if any, to sign a "copyright disclaimer" for the library, +if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James + Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/plugins/gtkui/gtkglext-gtk3/README b/plugins/gtkui/gtkglext-gtk3/README new file mode 100644 index 00000000..b34f7a42 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/README @@ -0,0 +1,146 @@ + + + G t k G L E x t + + - OpenGL Extension to GTK + + +General Information +=================== + +GtkGLExt is an OpenGL extension to GTK. + +This package is composed of GdkGLExt library and GtkGLExt library. +GdkGLExt library provides the GDK objects which support OpenGL +rendering in GTK. GtkGLExt library provides the GtkWidget API add-ons +to make GTK+ widgets OpenGL-capable. + +The official web site is: + http://projects.gnome.org/gtkglext/ + + +Licensing +========= + +GtkGLExt libraries are released under the terms of the GNU Lesser +General Public License (GNU LGPL). While components and programs +included with this release are licensed under the terms of the GNU +General Public License (GNU GPL). + + +Supported Platforms +=================== + +Currently GtkGLExt supports + + * UNIX and UNIX-like platforms + Tested under Linux, FreeBSD, IRIX, and Mac OS X. + + * Win32 platforms + Tested under Windows XP & 2000 Professional using MinGW/Cygwin + environment. + + +Requirements +============ + + * GNU C compiler + + * GNU make + + * GTK 2.0 or later (http://www.gtk.org/) + + * OpenGL or Mesa (http://www.mesa3d.org/) + + * GTK-Doc (http://www.gtk.org/rdp/) [optional] + + +Multihead Support +================= + +Multihead support requires GTK+ 2.1 or above. + +If GtkGLExt is already installed, you can check whether installed +GtkGLExt library supports multihead using the following command. + + $ pkg-config --variable=multihead gtkglext-3.0 + + +Installation +============ + +To build and install GtkGLExt, type follows (use GNU make) + + $ ./configure --prefix=/foo/bar (other options...) + $ make (or gmake) + $ make install + +To compile example programs, type + + $ make examples + +Please read INSTALL or type "./configure --help" for more details. + + +Configure Options +================= + +OpenGL options + + --with-gl-prefix=DIR OpenGL (Mesa) is installed in DIR [default=auto] + --with-gl-includedir=DIR OpenGL (Mesa) headers are in DIR [default=auto] + --with-gl-libdir=DIR OpenGL (Mesa) libraries are in DIR [default=auto] + +Debug options + + --enable-debug=[no/minimum/yes] turn on debugging [default=minimum] + +Window system options + + --with-gdktarget=[x11/win32] select GDK target + +Auto-generation files options + + --disable-rebuilds disable all source autogeneration rules + +Documentation options + + --enable-gtk-doc use gtk-doc to build documentation [default=no] + --with-html-dir=PATH path to installed docs + + +Building the Git Version of GtkGLExt +==================================== + +GtkGLExt's GNOME Git repository can be checked out anonymously: + + $ git clone git://git.gnome.org/gtkglext + +When you are working on the Git version of GtkGLExt, you can use autogen.sh +for generating configure script and Makefiles. + + $ env ACLOCAL_FLAGS='-I /pkgconfig/share/aclocal -I /gtk/share/aclocal' \ + ./autogen.sh --prefix=${HOME}/gtkglext \ + --enable-debug=yes + $ make + $ make install + $ make examples + +You may have to set ACLOCAL_FLAGS environment variable for some m4 +macros used in configure.ac. + +The following versions of the GNU autotools are required. + + autoconf 2.54 and above + automake 1.7.x + libtool 1.5 + + +Contact +======= + +Any patches, bug fixes and improvements are always welcome ;-) + + * Home: http://projects.gnome.org/gtkglext/ + * Mailing List: http://mail.gnome.org/mailman/listinfo/gtkglext-list/ + * Bugs & Patches: Use GNOME Bugzilla at https://bugzilla.gnome.org/enter_bug.cgi?product=gtkglext diff --git a/plugins/gtkui/gtkglext-gtk3/config.h b/plugins/gtkui/gtkglext-gtk3/config.h new file mode 100644 index 00000000..38d10a17 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/config.h @@ -0,0 +1,128 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if the system has the type `GLhalfNV'. */ +#define HAVE_GLHALFNV 1 + +/* Define to 1 if the system has the type `GLXFBConfigIDSGIX'. */ +#define HAVE_GLXFBCONFIGIDSGIX 1 + +/* Define to 1 if the system has the type `GLXFBConfigSGIX'. */ +#define HAVE_GLXFBCONFIGSGIX 1 + +/* Define to 1 if the system has the type `GLXPbufferSGIX'. */ +#define HAVE_GLXPBUFFERSGIX 1 + +/* Define to 1 if the system has the type `GLXVideoSourceSGIX'. */ +#define HAVE_GLXVIDEOSOURCESGIX 1 + +/* Define to 1 if you have the <GL/glu.h> header file. */ +#define HAVE_GL_GLU_H 1 + +/* Define to 1 if you have the <GL/gl.h> header file. */ +#define HAVE_GL_GL_H 1 + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#define HAVE_MALLOC 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the <OpenGL/glu.h> header file. */ +/* #undef HAVE_OPENGL_GLU_H */ + +/* Define to 1 if you have the <OpenGL/gl.h> header file. */ +/* #undef HAVE_OPENGL_GL_H */ + +/* Define if you have POSIX threads libraries and header files. */ +#define HAVE_PTHREAD 1 + +/* Define to 1 if you have the `sqrt' function. */ +#define HAVE_SQRT 1 + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchr' function. */ +#define HAVE_STRCHR 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strrchr' function. */ +#define HAVE_STRRCHR 1 + +/* Define to 1 if you have the `strstr' function. */ +#define HAVE_STRSTR 1 + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Use nonstandard varargs form for the GLU tesselator callback */ +/* #undef HAVE_VARARGS_GLU_TESSCB */ + +/* Define to 1 if you have the <windows.h> header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if the system has the type `__GLXextFuncPtr'. */ +#define HAVE___GLXEXTFUNCPTR 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "gtkglext-list@gnome.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "gtkglext" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "gtkglext 2.99.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "gtkglext" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.99.0" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if the X Window System is missing or not being used. */ +/* #undef X_DISPLAY_MISSING */ + +/* Define to rpl_malloc if the replacement function should be used. */ +/* #undef malloc */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgl.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgl.h new file mode 100644 index 00000000..b996f5b0 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgl.h @@ -0,0 +1,40 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_H__ +#define __GDK_GL_H__ + +#define __GDKGL_H_INSIDE__ + +#include "gdkglext-config.h" + +#include "gdkgldefs.h" +#include "gdkglversion.h" +#include "gdkgltokens.h" +#include "gdkgltypes.h" +#include "gdkglenumtypes.h" +#include "gdkglinit.h" +#include "gdkglquery.h" +#include "gdkglconfig.h" +#include "gdkglcontext.h" +#include "gdkgldrawable.h" +#include "gdkglwindow.h" + +#undef __GDKGL_H_INSIDE__ + +#endif /* __GDK_GL_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfig.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfig.c new file mode 100644 index 00000000..6fa328b7 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfig.c @@ -0,0 +1,603 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "gdkglprivate.h" +#include "gdkglconfig.h" + +#include <gdk/gdk.h> + +#ifdef GDKGLEXT_WINDOWING_X11 +#include "x11/gdkx11glconfig.h" +#include "x11/gdkglconfig-x11.h" +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 +#include "win32/gdkwin32glconfig.h" +#include "win32/gdkglconfig-win32.h" +#endif + +G_DEFINE_TYPE (GdkGLConfig, \ + gdk_gl_config, \ + G_TYPE_OBJECT) + +static void +gdk_gl_config_init (GdkGLConfig *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_gl_config_class_init (GdkGLConfigClass *klass) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static GdkGLConfig * +gdk_gl_config_new_ci (GdkScreen *screen, + GdkGLConfigMode mode) +{ + GdkGLConfig *glconfig = NULL; + static const int buf_size_list[] = { 16, 12, 8, 4, 2, 1, 0 }; + int list[32]; + int n = 0; + int i; + + list[n++] = GDK_GL_BUFFER_SIZE; + list[n++] = 1; + if (mode & GDK_GL_MODE_DOUBLE) + { + list[n++] = GDK_GL_DOUBLEBUFFER; + } + if (mode & GDK_GL_MODE_STEREO) + { + list[n++] = GDK_GL_STEREO; + } + if (mode & GDK_GL_MODE_DEPTH) + { + list[n++] = GDK_GL_DEPTH_SIZE; + list[n++] = 1; + } + if (mode & GDK_GL_MODE_STENCIL) + { + list[n++] = GDK_GL_STENCIL_SIZE; + list[n++] = 1; + } + + /* from GLUT */ + /* glXChooseVisual specify GLX_BUFFER_SIZE prefers the + "smallest index buffer of at least the specified size". + This would be reasonable if GLUT allowed the user to + specify the required buffe size, but GLUT's display mode + is too simplistic (easy to use?). GLUT should try to find + the "largest". So start with a large buffer size and + shrink until we find a matching one that exists. */ + + for (i = 0; buf_size_list[i]; i++) + { + /* XXX Assumes list[1] is where GDK_GL_BUFFER_SIZE parameter is. */ + list[1] = buf_size_list[i]; + + glconfig = gdk_gl_config_new_for_screen (screen, list, n); + + if (glconfig != NULL) + return glconfig; + } + + return NULL; +} + +static GdkGLConfig * +gdk_gl_config_new_rgb (GdkScreen *screen, + GdkGLConfigMode mode) +{ + int list[32]; + int n = 0; + + list[n++] = GDK_GL_RGBA; + list[n++] = GDK_GL_RED_SIZE; + list[n++] = 1; + list[n++] = GDK_GL_GREEN_SIZE; + list[n++] = 1; + list[n++] = GDK_GL_BLUE_SIZE; + list[n++] = 1; + if (mode & GDK_GL_MODE_ALPHA) + { + list[n++] = GDK_GL_ALPHA_SIZE; + list[n++] = 1; + } + if (mode & GDK_GL_MODE_DOUBLE) + { + list[n++] = GDK_GL_DOUBLEBUFFER; + } + if (mode & GDK_GL_MODE_STEREO) + { + list[n++] = GDK_GL_STEREO; + } + if (mode & GDK_GL_MODE_DEPTH) + { + list[n++] = GDK_GL_DEPTH_SIZE; + list[n++] = 1; + } + if (mode & GDK_GL_MODE_STENCIL) + { + list[n++] = GDK_GL_STENCIL_SIZE; + list[n++] = 1; + } + if (mode & GDK_GL_MODE_ACCUM) + { + list[n++] = GDK_GL_ACCUM_RED_SIZE; + list[n++] = 1; + list[n++] = GDK_GL_ACCUM_GREEN_SIZE; + list[n++] = 1; + list[n++] = GDK_GL_ACCUM_BLUE_SIZE; + list[n++] = 1; + if (mode & GDK_GL_MODE_ALPHA) + { + list[n++] = GDK_GL_ACCUM_ALPHA_SIZE; + list[n++] = 1; + } + } + + return gdk_gl_config_new_for_screen (screen, list, n); +} + +static GdkGLConfig * +gdk_gl_config_new_by_mode_common (GdkScreen *screen, + GdkGLConfigMode mode) +{ + GdkGLConfig *glconfig; + +#define _GL_CONFIG_NEW_BY_MODE(__screen, __mode) \ + ( ((__mode) & GDK_GL_MODE_INDEX) ? \ + gdk_gl_config_new_ci (__screen, __mode) : \ + gdk_gl_config_new_rgb (__screen, __mode) ) + + glconfig = _GL_CONFIG_NEW_BY_MODE (screen, mode); + if (glconfig == NULL) + { + /* Fallback cases when can't get exactly what was asked for... */ + if (!(mode & GDK_GL_MODE_DOUBLE)) + { + /* If we can't find a single buffered visual, try looking + for a double buffered visual. We can treat a double + buffered visual as a single buffered visual by changing + the draw buffer to GL_FRONT and treating any swap + buffers as no-ops. */ + mode |= GDK_GL_MODE_DOUBLE; + glconfig = _GL_CONFIG_NEW_BY_MODE (screen, mode); + if (glconfig != NULL) + glconfig->impl->as_single_mode = TRUE; + } + } + +#undef _GL_CONFIG_NEW_BY_MODE + + return glconfig; +} + +/** + * gdk_gl_config_new_by_mode: + * @mode: display mode bit mask. + * + * Returns an OpenGL frame buffer configuration that match the specified + * display mode. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_config_new_by_mode (GdkGLConfigMode mode) +{ + GdkScreen *screen; + + screen = gdk_screen_get_default (); + + return gdk_gl_config_new_by_mode_common (screen, mode); +} + +/** + * gdk_gl_config_new_by_mode_for_screen: + * @screen: target screen. + * @mode: display mode bit mask. + * + * Returns an OpenGL frame buffer configuration that match the specified + * display mode. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_config_new_by_mode_for_screen (GdkScreen *screen, + GdkGLConfigMode mode) +{ + return gdk_gl_config_new_by_mode_common (screen, mode); +} + +/** + * gdk_gl_config_get_layer_plane: + * @glconfig: a #GdkGLConfig. + * + * Gets the layer plane (level) of the frame buffer. + * Zero is the default frame buffer. + * Positive layer planes correspond to frame buffers that overlay the default + * buffer, and negative layer planes correspond to frame buffers that underlie + * the default frame buffer. + * + * Return value: layer plane. + **/ +gint +gdk_gl_config_get_layer_plane (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), 0); + + return glconfig->impl->layer_plane; +} + +/** + * gdk_gl_config_get_n_aux_buffers: + * @glconfig: a #GdkGLConfig. + * + * Gets the number of auxiliary color buffers. + * + * Return value: number of auxiliary color buffers. + **/ +gint +gdk_gl_config_get_n_aux_buffers (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), 0); + + return glconfig->impl->n_aux_buffers; +} + +/** + * gdk_gl_config_get_n_sample_buffers: + * @glconfig: a #GdkGLConfig. + * + * Gets the number of multisample buffers. + * + * Return value: number of multisample buffers. + **/ +gint +gdk_gl_config_get_n_sample_buffers (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), 0); + + return glconfig->impl->n_sample_buffers; +} + +/** + * gdk_gl_config_is_rgba: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configured frame buffer is RGBA mode. + * + * Return value: TRUE if the configured frame buffer is RGBA mode, FALSE + * otherwise. + **/ +gboolean +gdk_gl_config_is_rgba (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return glconfig->impl->is_rgba; +} + +/** + * gdk_gl_config_is_double_buffered: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configuration supports the double-buffered visual. + * + * Return value: TRUE if the double-buffered visual is supported, FALSE + * otherwise. + **/ +gboolean +gdk_gl_config_is_double_buffered (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return (glconfig->impl->is_double_buffered && (!glconfig->impl->as_single_mode)); +} + +/** + * gdk_gl_config_is_stereo: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configuration supports the stereo visual. + * + * Return value: TRUE if the stereo visual is supported, FALSE otherwise. + **/ +gboolean +gdk_gl_config_is_stereo (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return glconfig->impl->is_stereo; +} + +/** + * gdk_gl_config_has_alpha: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configured color buffer has alpha bits. + * + * Return value: TRUE if the color buffer has alpha bits, FALSE otherwise. + **/ +gboolean +gdk_gl_config_has_alpha (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return glconfig->impl->has_alpha; +} + +/** + * gdk_gl_config_has_depth_buffer: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configured frame buffer has depth buffer. + * + * Return value: TRUE if the frame buffer has depth buffer, FALSE otherwise. + **/ +gboolean +gdk_gl_config_has_depth_buffer (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return glconfig->impl->has_depth_buffer; +} + +/** + * gdk_gl_config_has_stencil_buffer: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configured frame buffer has stencil buffer. + * + * Return value: TRUE if the frame buffer has stencil buffer, FALSE otherwise. + **/ +gboolean +gdk_gl_config_has_stencil_buffer (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return glconfig->impl->has_stencil_buffer; +} + +/** + * gdk_gl_config_has_accum_buffer: + * @glconfig: a #GdkGLConfig. + * + * Returns whether the configured frame buffer has accumulation buffer. + * + * Return value: TRUE if the frame buffer has accumulation buffer, FALSE + * otherwise. + **/ +gboolean +gdk_gl_config_has_accum_buffer (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return glconfig->impl->has_accum_buffer; +} + +/** + * gdk_gl_config_new: + * @attrib_list: (array length=n_attribs): a list of attribute/value pairs. + * @n_attribs: the number of attributes and values in attrib_list. + * + * Returns an OpenGL frame buffer configuration that match the specified + * attributes. + * + * attrib_list is a int array that contains the attribute/value pairs. + * Available attributes are: + * GDK_GL_USE_GL, GDK_GL_BUFFER_SIZE, GDK_GL_LEVEL, GDK_GL_RGBA, + * GDK_GL_DOUBLEBUFFER, GDK_GL_STEREO, GDK_GL_AUX_BUFFERS, + * GDK_GL_RED_SIZE, GDK_GL_GREEN_SIZE, GDK_GL_BLUE_SIZE, GDK_GL_ALPHA_SIZE, + * GDK_GL_DEPTH_SIZE, GDK_GL_STENCIL_SIZE, GDK_GL_ACCUM_RED_SIZE, + * GDK_GL_ACCUM_GREEN_SIZE, GDK_GL_ACCUM_BLUE_SIZE, GDK_GL_ACCUM_ALPHA_SIZE. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_config_new (const int *attrib_list, gsize n_attribs) +{ + return gdk_gl_config_new_for_display(gdk_display_get_default(), + attrib_list, + n_attribs); +} + +/** + * gdk_gl_config_new_for_display: + * @screen: target display. + * @attrib_list: (array length=n_attribs): a list of attribute/value pairs. + * @n_attribs: the number of attributes and values in attrib_list. + * + * Returns an OpenGL frame buffer configuration that match the specified + * attributes. + * + * attrib_list is a int array that contains the attribute/value pairs. + * Available attributes are: + * GDK_GL_USE_GL, GDK_GL_BUFFER_SIZE, GDK_GL_LEVEL, GDK_GL_RGBA, + * GDK_GL_DOUBLEBUFFER, GDK_GL_STEREO, GDK_GL_AUX_BUFFERS, + * GDK_GL_RED_SIZE, GDK_GL_GREEN_SIZE, GDK_GL_BLUE_SIZE, GDK_GL_ALPHA_SIZE, + * GDK_GL_DEPTH_SIZE, GDK_GL_STENCIL_SIZE, GDK_GL_ACCUM_RED_SIZE, + * GDK_GL_ACCUM_GREEN_SIZE, GDK_GL_ACCUM_BLUE_SIZE, GDK_GL_ACCUM_ALPHA_SIZE. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_config_new_for_display (GdkDisplay *display, + const int *attrib_list, + gsize n_attribs) +{ + GdkGLConfig *glconfig = NULL; + +#ifdef GDKGLEXT_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY(display)) + { + glconfig = gdk_x11_gl_config_new_for_display(display, + attrib_list, + n_attribs); + } + else +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 + if (GDK_IS_WIN32_DISPLAY(display)) + { + glconfig = gdk_win32_gl_config_new_for_display(display, + attrib_list, + n_attribs); + } + else +#endif + { + g_warning("Unsupported GDK backend"); + } + + return glconfig; +} + +/** + * gdk_gl_config_new_for_screen: + * @screen: target screen. + * @attrib_list: (array length=n_attribs): a list of attribute/value pairs. + * @n_attribs: the number of attributes and values in attrib_list. + * + * Returns an OpenGL frame buffer configuration that match the specified + * attributes. + * + * attrib_list is a int array that contains the attribute/value pairs. + * Available attributes are: + * GDK_GL_USE_GL, GDK_GL_BUFFER_SIZE, GDK_GL_LEVEL, GDK_GL_RGBA, + * GDK_GL_DOUBLEBUFFER, GDK_GL_STEREO, GDK_GL_AUX_BUFFERS, + * GDK_GL_RED_SIZE, GDK_GL_GREEN_SIZE, GDK_GL_BLUE_SIZE, GDK_GL_ALPHA_SIZE, + * GDK_GL_DEPTH_SIZE, GDK_GL_STENCIL_SIZE, GDK_GL_ACCUM_RED_SIZE, + * GDK_GL_ACCUM_GREEN_SIZE, GDK_GL_ACCUM_BLUE_SIZE, GDK_GL_ACCUM_ALPHA_SIZE. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_config_new_for_screen (GdkScreen *screen, + const int *attrib_list, + gsize n_attribs) +{ + GdkDisplay *display; + GdkGLConfig *glconfig = NULL; + + /* The linker returns undefined symbol '_gdk_win32_screen_get_type' + * for win32 builds when using GDK_IS_WIN32_SCREEN. Thus we lookup + * the screen's display and test the display instead. + */ + + display = gdk_screen_get_display(screen); + g_return_val_if_fail(display != NULL, NULL); + +#ifdef GDKGLEXT_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY(display)) + { + glconfig = gdk_x11_gl_config_new_for_screen(screen, + attrib_list, + n_attribs); + } + else +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 + if (GDK_IS_WIN32_DISPLAY(display)) + { + glconfig = gdk_win32_gl_config_new_for_screen(screen, + attrib_list, + n_attribs); + } + else +#endif + { + g_warning("Unsupported GDK backend"); + } + + return glconfig; +} + +/** + * gdk_gl_config_get_screen: + * @glconfig: a #GdkGLConfig. + * + * Gets #GdkScreen. + * + * Return value: the #GdkScreen. + **/ +GdkScreen * +gdk_gl_config_get_screen (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return GDK_GL_CONFIG_IMPL_GET_CLASS (glconfig->impl)->get_screen (glconfig); +} + +/** + * gdk_gl_config_get_attrib: + * @glconfig: a #GdkGLConfig. + * @attribute: the attribute to be returned. + * @value: returns the requested value. + * + * Gets information about a OpenGL frame buffer configuration. + * + * Return value: TRUE if it succeeded, FALSE otherwise. + **/ +gboolean +gdk_gl_config_get_attrib (GdkGLConfig *glconfig, + int attribute, + int *value) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return GDK_GL_CONFIG_IMPL_GET_CLASS (glconfig->impl)->get_attrib (glconfig, attribute, value); +} + +/** + * gdk_gl_config_get_visual: + * @glconfig: a #GdkGLConfig. + * + * Gets the #GdkVisual that is appropriate for the OpenGL frame buffer + * configuration. + * + * Return value: the appropriate #GdkVisual. + **/ +GdkVisual * +gdk_gl_config_get_visual (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return GDK_GL_CONFIG_IMPL_GET_CLASS (glconfig->impl)->get_visual (glconfig); +} + +/** + * gdk_gl_config_get_depth: + * @glconfig: a #GdkGLConfig. + * + * Gets the color depth of the OpenGL-capable visual. + * + * Return value: number of bits per pixel + **/ +gint +gdk_gl_config_get_depth (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), FALSE); + + return GDK_GL_CONFIG_IMPL_GET_CLASS (glconfig->impl)->get_depth (glconfig); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfig.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfig.h new file mode 100644 index 00000000..58e59178 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfig.h @@ -0,0 +1,127 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_CONFIG_H__ +#define __GDK_GL_CONFIG_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgltypes.h> + +#include <gdk/gdk.h> + +G_BEGIN_DECLS + +/* + * Display mode bit masks. + */ +typedef enum +{ + GDK_GL_MODE_RGB = 0, + GDK_GL_MODE_RGBA = 0, /* same as RGB */ + GDK_GL_MODE_INDEX = 1 << 0, + GDK_GL_MODE_SINGLE = 0, + GDK_GL_MODE_DOUBLE = 1 << 1, + GDK_GL_MODE_STEREO = 1 << 2, + GDK_GL_MODE_ALPHA = 1 << 3, + GDK_GL_MODE_DEPTH = 1 << 4, + GDK_GL_MODE_STENCIL = 1 << 5, + GDK_GL_MODE_ACCUM = 1 << 6, + GDK_GL_MODE_MULTISAMPLE = 1 << 7 /* not supported yet */ +} GdkGLConfigMode; + +struct _GdkGLConfigImpl; +typedef struct _GdkGLConfigClass GdkGLConfigClass; + +#define GDK_TYPE_GL_CONFIG (gdk_gl_config_get_type ()) +#define GDK_GL_CONFIG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_CONFIG, GdkGLConfig)) +#define GDK_GL_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONFIG, GdkGLConfigClass)) +#define GDK_IS_GL_CONFIG(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_CONFIG)) +#define GDK_IS_GL_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONFIG)) +#define GDK_GL_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONFIG, GdkGLConfigClass)) + +struct _GdkGLConfig +{ + GObject parent_instance; + + struct _GdkGLConfigImpl *impl; +}; + +struct _GdkGLConfigClass +{ + GObjectClass parent_class; +}; + +GType gdk_gl_config_get_type (void); + +#ifndef GDK_MULTIHEAD_SAFE +GdkGLConfig *gdk_gl_config_new (const int *attrib_list, + gsize n_attribs); +#endif /* GDK_MULTIHEAD_SAFE */ + +GdkGLConfig *gdk_gl_config_new_for_display (GdkDisplay *display, + const int *attrib_list, + gsize n_attribs); + +GdkGLConfig *gdk_gl_config_new_for_screen (GdkScreen *screen, + const int *attrib_list, + gsize n_attribs); + +#ifndef GDK_MULTIHEAD_SAFE +GdkGLConfig *gdk_gl_config_new_by_mode (GdkGLConfigMode mode); +#endif /* GDK_MULTIHEAD_SAFE */ + +GdkGLConfig *gdk_gl_config_new_by_mode_for_screen (GdkScreen *screen, + GdkGLConfigMode mode); + +GdkScreen *gdk_gl_config_get_screen (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_get_attrib (GdkGLConfig *glconfig, + int attribute, + int *value); + +GdkVisual *gdk_gl_config_get_visual (GdkGLConfig *glconfig); + +gint gdk_gl_config_get_depth (GdkGLConfig *glconfig); + +gint gdk_gl_config_get_layer_plane (GdkGLConfig *glconfig); + +gint gdk_gl_config_get_n_aux_buffers (GdkGLConfig *glconfig); + +gint gdk_gl_config_get_n_sample_buffers (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_is_rgba (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_is_double_buffered (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_is_stereo (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_has_alpha (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_has_depth_buffer (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_has_stencil_buffer (GdkGLConfig *glconfig); + +gboolean gdk_gl_config_has_accum_buffer (GdkGLConfig *glconfig); + +G_END_DECLS + +#endif /* __GDK_GL_CONFIG_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfigimpl.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfigimpl.c new file mode 100644 index 00000000..c74ad43a --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfigimpl.c @@ -0,0 +1,70 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gdk/gdk.h> /* for gdk_error_trap_(push|pop) () */ + +#include "gdkgldebug.h" +#include "gdkglconfigimpl.h" + +G_DEFINE_TYPE (GdkGLConfigImpl, gdk_gl_config_impl, G_TYPE_OBJECT); + +static void +gdk_gl_config_impl_init (GdkGLConfigImpl *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + self->layer_plane = 0; + self->n_aux_buffers = 0; + self->n_sample_buffers = 0; + self->is_rgba = 0; + self->is_double_buffered = 0; + self->as_single_mode = 0; + self->is_stereo = 0; + self->has_alpha = 0; + self->has_depth_buffer = 0; + self->has_stencil_buffer = 0; + self->has_accum_buffer = 0; +} + +static void +gdk_gl_config_impl_finalize (GObject *object) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + G_OBJECT_CLASS (gdk_gl_config_impl_parent_class)->finalize (object); +} + +static void +gdk_gl_config_impl_class_init (GdkGLConfigImplClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + klass->create_gl_window = NULL; + klass->get_screen = NULL; + klass->get_attrib = NULL; + klass->get_visual = NULL; + klass->get_depth = NULL; + + object_class->finalize = gdk_gl_config_impl_finalize; +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfigimpl.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfigimpl.h new file mode 100644 index 00000000..9a034055 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglconfigimpl.h @@ -0,0 +1,74 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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 __GDK_GL_CONFIG_IMPL_H__ +#define __GDK_GL_CONFIG_IMPL_H__ + +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +#define GDK_TYPE_GL_CONFIG_IMPL (gdk_gl_config_impl_get_type ()) +#define GDK_GL_CONFIG_IMPL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_CONFIG_IMPL, GdkGLConfigImpl)) +#define GDK_GL_CONFIG_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONFIG_IMPL, GdkGLConfigImplClass)) +#define GDK_IS_GL_CONFIG_IMPL(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_CONFIG_IMPL)) +#define GDK_IS_GL_CONFIG_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONFIG_IMPL)) +#define GDK_GL_CONFIG_IMPL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONFIG_IMPL, GdkGLConfigImplClass)) + +typedef struct _GdkGLConfigImpl +{ + GObject parent; + + gint layer_plane; + + gint n_aux_buffers; + + gint n_sample_buffers; + + guint is_rgba : 1; + guint is_double_buffered : 1; + guint as_single_mode : 1; + guint is_stereo : 1; + guint has_alpha : 1; + guint has_depth_buffer : 1; + guint has_stencil_buffer : 1; + guint has_accum_buffer : 1; +} GdkGLConfigImpl; + +typedef struct _GdkGLConfigImplClass +{ + GObjectClass parent_class; + + GdkGLWindow* (*create_gl_window) (GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list); + + GdkScreen* (*get_screen) (GdkGLConfig *glconfig); + gboolean (*get_attrib) (GdkGLConfig *glconfig, + int attribute, + int *value); + GdkVisual* (*get_visual) (GdkGLConfig *glconfig); + gint (*get_depth) (GdkGLConfig *glconfig); + +} GdkGLConfigImplClass; + +GType gdk_gl_config_impl_get_type (void); + +G_END_DECLS + +#endif /* __GDK_GL_CONFIG_IMPL_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontext.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontext.c new file mode 100644 index 00000000..4196c44f --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontext.c @@ -0,0 +1,254 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#ifdef GDKGLEXT_WINDOWING_X11 +#include <gdk/gdkx.h> +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 +#include <gdk/gdkwin32.h> +#endif + +#include "gdkglprivate.h" +#include "gdkgldrawable.h" +#include "gdkglconfig.h" +#include "gdkglcontext.h" +#include "gdkglcontextimpl.h" + +#ifdef GDKGLEXT_WINDOWING_X11 +#include "x11/gdkglcontext-x11.h" +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 +#include "win32/gdkglcontext-win32.h" +#endif + +gboolean _gdk_gl_context_force_indirect = FALSE; + +G_DEFINE_TYPE (GdkGLContext, \ + gdk_gl_context, \ + G_TYPE_OBJECT) + +static void +gdk_gl_context_init (GdkGLContext *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_gl_context_class_init (GdkGLContextClass *klass) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +/** + * gdk_gl_context_new: + * @gldrawable: a #GdkGLDrawable. + * @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. + * + * Creates a new OpenGL rendering context. + * + * Return value: the new #GdkGLContext. + **/ +GdkGLContext * +gdk_gl_context_new (GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type) +{ + g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), NULL); + + return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->create_gl_context (gldrawable, + share_list, + direct, + render_type); +} + +/** + * gdk_gl_context_copy: + * @glcontext: a #GdkGLContext. + * @src: the source context. + * @mask: which portions of @src state are to be copied to @glcontext. + * + * Copy state from @src rendering context to @glcontext. + * + * @mask contains the bitwise-OR of the same symbolic names that are passed to + * the glPushAttrib() function. You can use GL_ALL_ATTRIB_BITS to copy all the + * rendering state information. + * + * Return value: FALSE if it fails, TRUE otherwise. + **/ +gboolean +gdk_gl_context_copy (GdkGLContext *glcontext, + GdkGLContext *src, + unsigned long mask) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->copy_gl_context_impl (glcontext, + src, + mask); +} + +/** + * gdk_gl_context_get_gl_drawable: + * @glcontext: a #GdkGLContext. + * + * Gets #GdkGLDrawable to which the @glcontext is bound. + * + * Return value: the #GdkGLDrawable or NULL if no #GdkGLDrawable is bound. + **/ +GdkGLDrawable * +gdk_gl_context_get_gl_drawable (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->get_gl_drawable (glcontext); +} + +/** + * gdk_gl_context_get_gl_config: + * @glcontext: a #GdkGLContext. + * + * Gets #GdkGLConfig with which the @glcontext is configured. + * + * Return value: the #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_context_get_gl_config (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->get_gl_config (glcontext); +} + +/** + * gdk_gl_context_get_share_list: + * @glcontext: a #GdkGLContext. + * + * Gets #GdkGLContext with which the @glcontext shares the display lists and + * texture objects. + * + * Return value: the #GdkGLContext. + **/ +GdkGLContext * +gdk_gl_context_get_share_list (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->get_share_list(glcontext); +} + +/** + * gdk_gl_context_is_direct: + * @glcontext: a #GdkGLContext. + * + * Returns whether the @glcontext is a direct rendering context. + * + * Return value: TRUE if the @glcontext is a direct rendering contest. + **/ +gboolean +gdk_gl_context_is_direct (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->is_direct(glcontext); +} + +/** + * gdk_gl_context_get_render_type: + * @glcontext: a #GdkGLContext. + * + * Gets render_type of the @glcontext. + * + * Return value: GDK_GL_RGBA_TYPE. + **/ +int +gdk_gl_context_get_render_type (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->get_render_type(glcontext); +} + +gboolean +gdk_gl_context_make_current(GdkGLContext *glcontext, + GdkGLDrawable *draw, + GdkGLDrawable *read) +{ + g_return_val_if_fail (GDK_IS_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->make_current(glcontext, + draw, + read); +} + +/** + * gdk_gl_context_release_current: + * + * Releases the current #GdkGLContext. + **/ +void +gdk_gl_context_release_current () +{ + GdkGLContext *glcontext = gdk_gl_context_get_current(); + + g_return_if_fail(glcontext != NULL); + + if (GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->make_uncurrent) + GDK_GL_CONTEXT_IMPL_GET_CLASS (glcontext->impl)->make_uncurrent(glcontext); +} + +/** + * gdk_gl_context_get_current: + * + * Returns the current #GdkGLContext. + * + * Return value: the current #GdkGLContext or NULL if there is no current + * context. + **/ +GdkGLContext * +gdk_gl_context_get_current () +{ + /* + * There can only be one current context. So we try each target + * and take the first non-NULL result. Hopefully the underlying + * GL implementation behaves accordingly. But we probalby need + * a better strategy here. + */ + + GdkGLContext *current = NULL; + +#ifdef GDKGLEXT_WINDOWING_X11 + current = _gdk_x11_gl_context_impl_get_current(); +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 + if (current == NULL) + { + current = _gdk_win32_gl_context_impl_get_current(); + } +#endif + + return current; +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontext.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontext.h new file mode 100644 index 00000000..0ddd5194 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontext.h @@ -0,0 +1,84 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_CONTEXT_H__ +#define __GDK_GL_CONTEXT_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgltypes.h> + +G_BEGIN_DECLS + +struct _GdkGLContextImpl; +typedef struct _GdkGLContextClass GdkGLContextClass; + +#define GDK_TYPE_GL_CONTEXT (gdk_gl_context_get_type ()) +#define GDK_GL_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_CONTEXT, GdkGLContext)) +#define GDK_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT, GdkGLContextClass)) +#define GDK_IS_GL_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_CONTEXT)) +#define GDK_IS_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT)) +#define GDK_GL_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT, GdkGLContextClass)) + +struct _GdkGLContext +{ + GObject parent_instance; + + struct _GdkGLContextImpl *impl; +}; + +struct _GdkGLContextClass +{ + GObjectClass parent_class; +}; + +GType gdk_gl_context_get_type (void); + +GdkGLContext *gdk_gl_context_new (GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type); + +gboolean gdk_gl_context_copy (GdkGLContext *glcontext, + GdkGLContext *src, + unsigned long mask); + +GdkGLDrawable *gdk_gl_context_get_gl_drawable (GdkGLContext *glcontext); + +GdkGLConfig *gdk_gl_context_get_gl_config (GdkGLContext *glcontext); + +GdkGLContext *gdk_gl_context_get_share_list (GdkGLContext *glcontext); + +gboolean gdk_gl_context_is_direct (GdkGLContext *glcontext); + +int gdk_gl_context_get_render_type (GdkGLContext *glcontext); + +gboolean gdk_gl_context_make_current (GdkGLContext *glcontext, + GdkGLDrawable *draw, + GdkGLDrawable *read); + +void gdk_gl_context_release_current (void); + +GdkGLContext *gdk_gl_context_get_current (void); + +G_END_DECLS + +#endif /* __GDK_GL_CONTEXT_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontextimpl.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontextimpl.c new file mode 100644 index 00000000..fdf51375 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontextimpl.c @@ -0,0 +1,59 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gdk/gdk.h> /* for gdk_error_trap_(push|pop) () */ + +#include "gdkgldebug.h" +#include "gdkglcontextimpl.h" + +G_DEFINE_TYPE (GdkGLContextImpl, gdk_gl_context_impl, G_TYPE_OBJECT); + +static void +gdk_gl_context_impl_init (GdkGLContextImpl *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_gl_context_impl_finalize (GObject *object) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + G_OBJECT_CLASS (gdk_gl_context_impl_parent_class)->finalize (object); +} + +static void +gdk_gl_context_impl_class_init (GdkGLContextImplClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + klass->copy_gl_context_impl = NULL; + klass->get_gl_drawable = NULL; + klass->get_gl_config = NULL; + klass->get_share_list = NULL; + klass->is_direct = NULL; + klass->get_render_type = NULL; + + object_class->finalize = gdk_gl_context_impl_finalize; +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontextimpl.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontextimpl.h new file mode 100644 index 00000000..b6feb6fd --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglcontextimpl.h @@ -0,0 +1,61 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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 __GDK_GL_CONTEXT_IMPL_H__ +#define __GDK_GL_CONTEXT_IMPL_H__ + +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +#define GDK_TYPE_GL_CONTEXT_IMPL (gdk_gl_context_impl_get_type ()) +#define GDK_GL_CONTEXT_IMPL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_CONTEXT_IMPL, GdkGLContextImpl)) +#define GDK_GL_CONTEXT_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT_IMPL, GdkGLContextImplClass)) +#define GDK_IS_GL_CONTEXT_IMPL(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_CONTEXT_IMPL)) +#define GDK_IS_GL_CONTEXT_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT_IMPL)) +#define GDK_GL_CONTEXT_IMPL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT_IMPL, GdkGLContextImplClass)) + +typedef struct _GdkGLContextImpl +{ + GObject parent; +} GdkGLContextImpl; + +typedef struct _GdkGLContextImplClass +{ + GObjectClass parent_class; + + gboolean (*copy_gl_context_impl) (GdkGLContext *glcontext, + GdkGLContext *src, + unsigned long mask); + GdkGLDrawable* (*get_gl_drawable) (GdkGLContext *glcontext); + GdkGLConfig* (*get_gl_config) (GdkGLContext *glcontext); + GdkGLContext* (*get_share_list) (GdkGLContext *glcontext); + gboolean (*is_direct) (GdkGLContext *glcontext); + int (*get_render_type) (GdkGLContext *glcontext); + gboolean (*make_current)(GdkGLContext *glcontext, + GdkGLDrawable *draw, + GdkGLDrawable *read); + void (*make_uncurrent)(GdkGLContext *glcontext); + +} GdkGLContextImplClass; + +GType gdk_gl_context_impl_get_type (void); + +G_END_DECLS + +#endif /* __GDK_GL_CONTEXT_IMPL_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldebug.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldebug.h new file mode 100644 index 00000000..4a8a8663 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldebug.h @@ -0,0 +1,73 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_DEBUG_H__ +#define __GDK_GL_DEBUG_H__ + +#include <glib.h> + +#include <gdk/gdkgldefs.h> + +G_BEGIN_DECLS + +typedef enum { + GDK_GL_DEBUG_MISC = 1 << 0, + GDK_GL_DEBUG_FUNC = 1 << 1, + GDK_GL_DEBUG_IMPL = 1 << 2 +} GdkGLDebugFlag; + +#ifdef G_ENABLE_DEBUG + +#define GDK_GL_NOTE(type, action) G_STMT_START { \ + if (gdk_gl_debug_flags & GDK_GL_DEBUG_##type) \ + { action; }; } G_STMT_END + +#if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "<unknown>" +# endif +#endif + +#define GDK_GL_NOTE_FUNC() G_STMT_START { \ + if (gdk_gl_debug_flags & GDK_GL_DEBUG_FUNC) \ + g_message (" - %s ()", __func__); } G_STMT_END + +#define GDK_GL_NOTE_FUNC_PRIVATE() G_STMT_START { \ + if (gdk_gl_debug_flags & GDK_GL_DEBUG_FUNC) \ + g_message (" -- %s ()", __func__); } G_STMT_END + +#define GDK_GL_NOTE_FUNC_IMPL(func) G_STMT_START { \ + if (gdk_gl_debug_flags & GDK_GL_DEBUG_IMPL) \ + g_message (" ** %s ()", (func)); } G_STMT_END + +#else /* !G_ENABLE_DEBUG */ + +#define GDK_GL_NOTE(type, action) +#define GDK_GL_NOTE_FUNC() +#define GDK_GL_NOTE_FUNC_PRIVATE() +#define GDK_GL_NOTE_FUNC_IMPL(func) + +#endif /* G_ENABLE_DEBUG */ + +GDK_GL_VAR guint gdk_gl_debug_flags; + +G_END_DECLS + +#endif /* __GDK_GL_DEBUG_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldefs.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldefs.h new file mode 100644 index 00000000..e5f54c7c --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldefs.h @@ -0,0 +1,44 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_DEFS_H__ +#define __GDK_GL_DEFS_H__ + +#include <glib.h> + +#include <gdkglext-config.h> + +G_BEGIN_DECLS + +#ifdef G_OS_WIN32 +# ifdef GDK_GL_COMPILATION +# define GDK_GL_VAR __declspec(dllexport) +# else +# define GDK_GL_VAR extern __declspec(dllimport) +# endif +#else +# define GDK_GL_VAR extern +#endif + +G_END_DECLS + +#endif /* __GDK_GL_DEFS_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldrawable.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldrawable.c new file mode 100644 index 00000000..86b1749c --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldrawable.c @@ -0,0 +1,126 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <gdk/gdk.h> + +#include "gdkglprivate.h" +#include "gdkglcontext.h" +#include "gdkgldrawable.h" + +GType +gdk_gl_drawable_get_type (void) +{ + static GType type = 0; + + if (!type) + { + static const GTypeInfo type_info = { + sizeof (GdkGLDrawableClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL + }; + + type = g_type_register_static (G_TYPE_INTERFACE, + "GdkGLDrawable", + &type_info, 0); + } + + return type; +} + +/** + * gdk_gl_drawable_is_double_buffered: + * @gldrawable: a #GdkGLDrawable. + * + * Returns whether the @gldrawable supports the double-buffered visual. + * + * Return value: TRUE if the double-buffered visual is supported, + * FALSE otherwise. + **/ +gboolean +gdk_gl_drawable_is_double_buffered (GdkGLDrawable *gldrawable) +{ + g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), FALSE); + + return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->is_double_buffered (gldrawable); +} + +/** + * gdk_gl_drawable_swap_buffers: + * @gldrawable: a #GdkGLDrawable. + * + * Exchange front and back buffers. + * + **/ +void +gdk_gl_drawable_swap_buffers (GdkGLDrawable *gldrawable) +{ + g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable)); + + GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->swap_buffers (gldrawable); +} + +/** + * gdk_gl_drawable_wait_gl: + * @gldrawable: a #GdkGLDrawable. + * + * Complete OpenGL execution prior to subsequent GDK drawing calls. + * + **/ +void +gdk_gl_drawable_wait_gl (GdkGLDrawable *gldrawable) +{ + g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable)); + + GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->wait_gl (gldrawable); +} + +/** + * gdk_gl_drawable_wait_gdk: + * @gldrawable: a #GdkGLDrawable. + * + * Complete GDK drawing execution prior to subsequent OpenGL calls. + * + **/ +void +gdk_gl_drawable_wait_gdk (GdkGLDrawable *gldrawable) +{ + g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable)); + + GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->wait_gdk (gldrawable); +} + +/** + * gdk_gl_drawable_get_gl_config: + * @gldrawable: a #GdkGLDrawable. + * + * Gets #GdkGLConfig with which the @gldrawable is configured. + * + * Return value: the #GdkGLConfig. + **/ +GdkGLConfig * +gdk_gl_drawable_get_gl_config (GdkGLDrawable *gldrawable) +{ + g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), NULL); + + return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->get_gl_config (gldrawable); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldrawable.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldrawable.h new file mode 100644 index 00000000..e69aa61f --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgldrawable.h @@ -0,0 +1,70 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_DRAWABLE_H__ +#define __GDK_GL_DRAWABLE_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgltypes.h> + +G_BEGIN_DECLS + +typedef struct _GdkGLDrawableClass GdkGLDrawableClass; + +#define GDK_TYPE_GL_DRAWABLE (gdk_gl_drawable_get_type ()) +#define GDK_GL_DRAWABLE(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), GDK_TYPE_GL_DRAWABLE, GdkGLDrawable)) +#define GDK_GL_DRAWABLE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), GDK_TYPE_GL_DRAWABLE, GdkGLDrawableClass)) +#define GDK_IS_GL_DRAWABLE(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), GDK_TYPE_GL_DRAWABLE)) +#define GDK_IS_GL_DRAWABLE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), GDK_TYPE_GL_DRAWABLE)) +#define GDK_GL_DRAWABLE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GDK_TYPE_GL_DRAWABLE, GdkGLDrawableClass)) + +struct _GdkGLDrawableClass +{ + GTypeInterface base_iface; + + GdkGLContext* (*create_gl_context) (GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type); + + gboolean (*is_double_buffered) (GdkGLDrawable *gldrawable); + void (*swap_buffers) (GdkGLDrawable *gldrawable); + void (*wait_gl) (GdkGLDrawable *gldrawable); + void (*wait_gdk) (GdkGLDrawable *gldrawable); + GdkGLConfig* (*get_gl_config) (GdkGLDrawable *gldrawable); +}; + +GType gdk_gl_drawable_get_type (void); + +gboolean gdk_gl_drawable_is_double_buffered (GdkGLDrawable *gldrawable); + +void gdk_gl_drawable_swap_buffers (GdkGLDrawable *gldrawable); + +void gdk_gl_drawable_wait_gl (GdkGLDrawable *gldrawable); + +void gdk_gl_drawable_wait_gdk (GdkGLDrawable *gldrawable); + +GdkGLConfig *gdk_gl_drawable_get_gl_config (GdkGLDrawable *gldrawable); + +G_END_DECLS + +#endif /* __GDK_GL_DRAWABLE_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglenumtypes.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglenumtypes.h new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglenumtypes.h diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglext-config.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglext-config.h new file mode 100644 index 00000000..31b3d7c8 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglext-config.h @@ -0,0 +1,27 @@ +/* gdkglext-config.h + * + * This is a generated file. Please modify `configure.ac' + */ + +#ifndef GDKGLEXT_CONFIG_H +#define GDKGLEXT_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GDKGLEXT_WINDOWING_X11 + + + + + + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GDKGLEXT_CONFIG_H */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglinit.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglinit.c new file mode 100644 index 00000000..556b1165 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglinit.c @@ -0,0 +1,226 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <string.h> + +#include "gdkglprivate.h" +#include "gdkglquery.h" +#include "gdkglinit.h" + +static gboolean gdk_gl_initialized = FALSE; + +guint gdk_gl_debug_flags = 0; /* Global GdkGLExt debug flag */ + +#ifdef G_ENABLE_DEBUG + +static const GDebugKey gdk_gl_debug_keys[] = { + {"misc", GDK_GL_DEBUG_MISC}, + {"func", GDK_GL_DEBUG_FUNC}, + {"impl", GDK_GL_DEBUG_IMPL} +}; + +static const guint gdk_gl_ndebug_keys = G_N_ELEMENTS (gdk_gl_debug_keys); + +#endif /* G_ENABLE_DEBUG */ + +/** + * gdk_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 GdkGLExt. + * + * Any arguments used by GdkGLExt are removed from the array and + * @argc and @argv are updated accordingly. + * + * You shouldn't call this function explicitely if you are using + * gdk_gl_init(), or gdk_gl_init_check(). + **/ +static void +gdk_gl_parse_args (int *argc, + char ***argv) +{ + const gchar *env_string; + + if (gdk_gl_initialized) + return; + + env_string = g_getenv ("GDK_GL_FORCE_INDIRECT"); + if (env_string != NULL) + { + _gdk_gl_context_force_indirect = !!g_ascii_strtoll (env_string, NULL, 0); + env_string = NULL; + } + +#ifdef G_ENABLE_DEBUG + env_string = g_getenv ("GDK_GL_DEBUG"); + if (env_string != NULL) + { + gdk_gl_debug_flags = g_parse_debug_string (env_string, + gdk_gl_debug_keys, + gdk_gl_ndebug_keys); + env_string = NULL; + } +#endif /* G_ENABLE_DEBUG */ + + if (argc && argv) + { + gint i, j, k; + + for (i = 1; i < *argc;) + { + if (strcmp ("--gdk-gl-force-indirect", (*argv)[i]) == 0) + { + _gdk_gl_context_force_indirect = TRUE; + (*argv)[i] = NULL; + } +#ifdef G_ENABLE_DEBUG + else if ((strcmp ("--gdk-gl-debug", (*argv)[i]) == 0) || + (strncmp ("--gdk-gl-debug=", (*argv)[i], 15) == 0)) + { + gchar *equal_pos = strchr ((*argv)[i], '='); + + if (equal_pos != NULL) + { + gdk_gl_debug_flags |= g_parse_debug_string (equal_pos+1, + gdk_gl_debug_keys, + gdk_gl_ndebug_keys); + } + else if ((i + 1) < *argc && (*argv)[i + 1]) + { + gdk_gl_debug_flags |= g_parse_debug_string ((*argv)[i+1], + gdk_gl_debug_keys, + gdk_gl_ndebug_keys); + (*argv)[i] = NULL; + i += 1; + } + (*argv)[i] = NULL; + } + else if ((strcmp ("--gdk-gl-no-debug", (*argv)[i]) == 0) || + (strncmp ("--gdk-gl-no-debug=", (*argv)[i], 18) == 0)) + { + gchar *equal_pos = strchr ((*argv)[i], '='); + + if (equal_pos != NULL) + { + gdk_gl_debug_flags &= ~g_parse_debug_string (equal_pos+1, + gdk_gl_debug_keys, + gdk_gl_ndebug_keys); + } + else if ((i + 1) < *argc && (*argv)[i + 1]) + { + gdk_gl_debug_flags &= ~g_parse_debug_string ((*argv)[i+1], + gdk_gl_debug_keys, + gdk_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. */ + gdk_gl_initialized = TRUE; +} + +/** + * gdk_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 + * gdk_gl_init() are stripped before return. + * + * This function does the same work as gdk_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 +gdk_gl_init_check (int *argc, + char ***argv) +{ + /* Parse args and init GdkGLExt library. */ + gdk_gl_parse_args (argc, argv); + + /* Is OpenGL supported? */ + if (!gdk_gl_query_extension ()) + { + g_warning ("Window system doesn't support OpenGL."); + return FALSE; + } + + return TRUE; +} + +/** + * gdk_gl_init: + * @argc: Address of the <parameter>argc</parameter> parameter of your + * main() function. Changed if any arguments were handled. + * @argv: Address of the <parameter>argv</parameter> parameter of + * main(). Any parameters understood by gdk_gl_init() are stripped + * before return. + * + * Call this function before using any other GdkGLExt 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 + * gdk_gl_init_check() instead.</para></note> + **/ +void +gdk_gl_init (int *argc, + char ***argv) +{ + if (!gdk_gl_init_check (argc, argv)) + g_error ("GdkGLExt library initialization fails."); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglinit.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglinit.h new file mode 100644 index 00000000..d3fe0549 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglinit.h @@ -0,0 +1,43 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_INIT_H__ +#define __GDK_GL_INIT_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgltypes.h> + +G_BEGIN_DECLS + +/* + * Initialization routines. + */ + +gboolean gdk_gl_init_check (int *argc, + char ***argv); + +void gdk_gl_init (int *argc, + char ***argv); + +G_END_DECLS + +#endif /* __GDK_GL_INIT_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglprivate.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglprivate.h new file mode 100644 index 00000000..9bdafc98 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglprivate.h @@ -0,0 +1,46 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_PRIVATE_H__ +#define __GDK_GL_PRIVATE_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgldebug.h> +#include <gdk/gdkgltokens.h> +#include <gdk/gdkgltypes.h> +#include <gdk/gdkgldrawable.h> + +G_BEGIN_DECLS + +#define _GDK_GL_CONCAT(x, y) x##y + +#define _GDK_GL_CONFIG_AS_SINGLE_MODE(glconfig) ((glconfig->impl)->as_single_mode) + +void _gdk_gl_window_get_size (GdkGLDrawable *gldrawable, + gint *width, + gint *height); + +void _gdk_gl_print_gl_info (void); + +/* Internal globals */ + +extern gboolean _gdk_gl_context_force_indirect; + +G_END_DECLS + +#endif /* __GDK_GL_PRIVATE_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglquery.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglquery.c new file mode 100644 index 00000000..341abc78 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglquery.c @@ -0,0 +1,271 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <stdlib.h> +#include <string.h> + +#include "gdkglprivate.h" +#include "gdkglquery.h" + +#ifdef G_OS_WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include <windows.h> +#endif + +#ifdef GDK_WINDOWING_QUARTZ +#include <OpenGL/gl.h> +#else +#include <GL/gl.h> +#endif + +#ifdef GDKGLEXT_WINDOWING_X11 +#include <gdk/gdkx.h> +#include "x11/gdkglquery-x11.h" +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 +#include <gdk/gdkwin32.h> +#include "win32/gdkglquery-win32.h" +#endif + +/* + * This code is based on glutExtensionSupported(). + */ + +/** + * gdk_gl_query_gl_extension: + * @extension: name of OpenGL extension. + * + * Determines whether a given OpenGL extension is supported. + * + * There must be a valid current rendering context to call + * gdk_gl_query_gl_extension(). + * + * gdk_gl_query_gl_extension() returns information about OpenGL extensions + * only. This means that window system dependent extensions (for example, + * GLX extensions) are not reported by gdk_gl_query_gl_extension(). + * + * Return value: TRUE if the OpenGL extension is supported, FALSE if not + * supported. + **/ +gboolean +gdk_gl_query_gl_extension (const char *extension) +{ + static const GLubyte *extensions = NULL; + const GLubyte *start; + GLubyte *where, *terminator; + + /* Extension names should not have spaces. */ + where = (GLubyte *) strchr (extension, ' '); + if (where || *extension == '\0') + return FALSE; + + if (extensions == NULL) + extensions = glGetString (GL_EXTENSIONS); + + /* It takes a bit of care to be fool-proof about parsing the + OpenGL extensions string. Don't be fooled by sub-strings, + etc. */ + start = extensions; + for (;;) + { + /* If your application crashes in the strstr routine below, + you are probably calling gdk_gl_query_gl_extension without + having a current window. Calling glGetString without + a current OpenGL context has unpredictable results. + Please fix your program. */ + where = (GLubyte *) strstr ((const char *) start, extension); + if (where == NULL) + break; + + terminator = where + strlen (extension); + + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') + { + GDK_GL_NOTE (MISC, g_message (" - %s - supported", extension)); + return TRUE; + } + + start = terminator; + } + + GDK_GL_NOTE (MISC, g_message (" - %s - not supported", extension)); + + return FALSE; +} + +/** + * gdk_gl_query_extension: + * + * Indicates whether the window system supports the OpenGL extension + * (GLX, WGL, etc.). + * + * Return value: TRUE if OpenGL is supported, FALSE otherwise. + **/ +gboolean +gdk_gl_query_extension (void) +{ + return gdk_gl_query_extension_for_display(gdk_display_get_default()); +} + +/** + * gdk_gl_query_extension_for_display: + * @display: the #GdkDisplay where the query is sent to. + * + * Indicates whether the window system supports the OpenGL extension + * (GLX, WGL, etc.). + * + * Return value: TRUE if OpenGL is supported, FALSE otherwise. + **/ +gboolean +gdk_gl_query_extension_for_display (GdkDisplay *display) +{ + gboolean supp = FALSE; + +#ifdef GDKGLEXT_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY(display)) + { + supp = _gdk_x11_gl_query_extension_for_display(display); + } + else +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 + if (GDK_IS_WIN32_DISPLAY(display)) + { + supp = _gdk_win32_gl_query_extension_for_display(display); + } + else +#endif + { + g_warning("Unsupported GDK backend"); + } + + return supp; +} + +/** + * gdk_gl_query_version: + * @major: returns the major version number of the OpenGL extension. + * @minor: returns the minor version number of the OpenGL extension. + * + * Returns the version numbers of the OpenGL extension to the window system. + * + * In the X Window System, it returns the GLX version. + * + * In the Microsoft Windows, it returns the Windows version. + * + * Return value: FALSE if it fails, TRUE otherwise. + **/ +gboolean +gdk_gl_query_version (int *major, + int *minor) +{ + return gdk_gl_query_version_for_display(gdk_display_get_default(), major, minor); +} + +/** + * gdk_gl_query_version_for_display: + * @display: the #GdkDisplay where the query is sent to. + * @major: returns the major version number of the OpenGL extension. + * @minor: returns the minor version number of the OpenGL extension. + * + * Returns the version numbers of the OpenGL extension to the window system. + * + * In the X Window System, it returns the GLX version. + * + * In the Microsoft Windows, it returns the Windows version. + * + * Return value: FALSE if it fails, TRUE otherwise. + **/ +gboolean +gdk_gl_query_version_for_display (GdkDisplay *display, + int *major, + int *minor) +{ + gboolean succ = FALSE; + +#ifdef GDKGLEXT_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY(display)) + { + succ = _gdk_x11_gl_query_version_for_display(display, major, minor); + } + else +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 + if (GDK_IS_WIN32_DISPLAY(display)) + { + succ = _gdk_win32_gl_query_version_for_display(display, major, minor); + } + else +#endif + { + g_warning("Unsupported GDK backend"); + } + + return succ; +} + +/** + * gdk_gl_get_proc_address: + * @proc_name: function name. + * + * Returns the address of the OpenGL, GLU, or GLX function. + * + * Return value: the address of the function named by @proc_name. + **/ +GdkGLProc +gdk_gl_get_proc_address (const char *proc_name) +{ + GdkGLProc addr = NULL; + +#ifdef GDKGLEXT_WINDOWING_X11 + if (!addr) + { + addr = _gdk_x11_gl_get_proc_address(proc_name); + } +#endif +#ifdef GDKGLEXT_WINDOWING_WIN32 + if (!addr) + { + addr = _gdk_win32_gl_get_proc_address(proc_name); + } +#endif + + return addr; +} + +/*< private >*/ +void +_gdk_gl_print_gl_info (void) +{ + static gboolean done = FALSE; + + if (!done) + { + g_message (" -- GL_VENDOR : %s", glGetString (GL_VENDOR)); + g_message (" -- GL_RENDERER : %s", glGetString (GL_RENDERER)); + g_message (" -- GL_VERSION : %s", glGetString (GL_VERSION)); + g_message (" -- GL_EXTENSIONS : %s", glGetString (GL_EXTENSIONS)); + + done = TRUE; + } +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglquery.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglquery.h new file mode 100644 index 00000000..4235813c --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglquery.h @@ -0,0 +1,52 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_QUERY_H__ +#define __GDK_GL_QUERY_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgltypes.h> + +G_BEGIN_DECLS + +#ifndef GDK_MULTIHEAD_SAFE +gboolean gdk_gl_query_extension (void); +#endif /* GDK_MULTIHEAD_SAFE */ + +gboolean gdk_gl_query_extension_for_display (GdkDisplay *display); + +#ifndef GDK_MULTIHEAD_SAFE +gboolean gdk_gl_query_version (int *major, + int *minor); +#endif /* GDK_MULTIHEAD_SAFE */ + +gboolean gdk_gl_query_version_for_display (GdkDisplay *display, + int *major, + int *minor); + +gboolean gdk_gl_query_gl_extension (const char *extension); + +GdkGLProc gdk_gl_get_proc_address (const char *proc_name); + +G_END_DECLS + +#endif /* __GDK_GL_QUERY_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgltokens.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgltokens.h new file mode 100644 index 00000000..5d9a025c --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgltokens.h @@ -0,0 +1,248 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_TOKENS_H__ +#define __GDK_GL_TOKENS_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Success return value + */ +#define GDK_GL_SUCCESS 0 /* same as 'Success' of X11 */ + +/* + * Attribute list terminator + */ +#define GDK_GL_ATTRIB_LIST_NONE 0 /* same as 'None' of X11 */ + +/* + * This source is based on the OpenGL(R) Sample Implementation by SGI. + */ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * Visual Config Attributes. + */ +typedef enum +{ + GDK_GL_USE_GL = 1, /* support GLX rendering */ + GDK_GL_BUFFER_SIZE = 2, /* depth of the color buffer */ + GDK_GL_LEVEL = 3, /* level in plane stacking */ + GDK_GL_RGBA = 4, /* true if RGBA mode */ + GDK_GL_DOUBLEBUFFER = 5, /* double buffering supported */ + GDK_GL_STEREO = 6, /* stereo buffering supported */ + GDK_GL_AUX_BUFFERS = 7, /* number of aux buffers */ + GDK_GL_RED_SIZE = 8, /* number of red component bits */ + GDK_GL_GREEN_SIZE = 9, /* number of green component bits */ + GDK_GL_BLUE_SIZE = 10, /* number of blue component bits */ + GDK_GL_ALPHA_SIZE = 11, /* number of alpha component bits */ + GDK_GL_DEPTH_SIZE = 12, /* number of depth bits */ + GDK_GL_STENCIL_SIZE = 13, /* number of stencil bits */ + GDK_GL_ACCUM_RED_SIZE = 14, /* number of red accum bits */ + GDK_GL_ACCUM_GREEN_SIZE = 15, /* number of green accum bits */ + GDK_GL_ACCUM_BLUE_SIZE = 16, /* number of blue accum bits */ + GDK_GL_ACCUM_ALPHA_SIZE = 17, /* number of alpha accum bits */ + + /* + * FBConfig-specific attributes. + * [ GLX 1.3 and later ] + */ + GDK_GL_CONFIG_CAVEAT = 0x20, + GDK_GL_X_VISUAL_TYPE = 0x22, + GDK_GL_TRANSPARENT_TYPE = 0x23, + GDK_GL_TRANSPARENT_INDEX_VALUE = 0x24, + GDK_GL_TRANSPARENT_RED_VALUE = 0x25, + GDK_GL_TRANSPARENT_GREEN_VALUE = 0x26, + GDK_GL_TRANSPARENT_BLUE_VALUE = 0x27, + GDK_GL_TRANSPARENT_ALPHA_VALUE = 0x28, + GDK_GL_DRAWABLE_TYPE = 0x8010, + GDK_GL_RENDER_TYPE = 0x8011, + GDK_GL_X_RENDERABLE = 0x8012, + GDK_GL_FBCONFIG_ID = 0x8013, + GDK_GL_VISUAL_ID = 0x800B, + GDK_GL_SCREEN = 0x800C, + + /* + * Multisampling configuration attributes. + * [ GLX 1.4 and later ] + */ + GDK_GL_SAMPLE_BUFFERS = 100000, + GDK_GL_SAMPLES = 100001 + +} GdkGLConfigAttrib; + +/* + * Generic "don't care" value. + * [ GLX 1.3 and later ] + */ +#define GDK_GL_DONT_CARE 0xFFFFFFFF + +/* + * "none" value. + * [ GLX 1.3 and later ] + */ +#define GDK_GL_NONE 0x8000 + +/* + * GLX_CONFIG_CAVEAT attribute values. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_CONFIG_CAVEAT_DONT_CARE = (int)0xFFFFFFFF, /* GDK_GL_DONT_CARE */ + GDK_GL_CONFIG_CAVEAT_NONE = 0x8000, /* GDK_GL_NONE */ + GDK_GL_SLOW_CONFIG = 0x8001, + GDK_GL_NON_CONFORMANT_CONFIG = 0x800D +} GdkGLConfigCaveat; + +/* + * GLX_X_VISUAL_TYPE attribute values. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_VISUAL_TYPE_DONT_CARE = (int)0xFFFFFFFF, /* GDK_GL_DONT_CARE */ + GDK_GL_TRUE_COLOR = 0x8002, + GDK_GL_DIRECT_COLOR = 0x8003, +} GdkGLVisualType; + +/* + * GLX_TRANSPARENT_TYPE attribute values. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_TRANSPARENT_NONE = 0x8000, /* GDK_GL_NONE */ + GDK_GL_TRANSPARENT_RGB = 0x8008, +} GdkGLTransparentType; + +/* + * GLX_DRAWABLE_TYPE bits. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_WINDOW_BIT = 1 << 0, /* 0x00000001 */ +} GdkGLDrawableTypeMask; + +/* + * GLX_RENDER_TYPE bits. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_RGBA_BIT = 1 << 0, /* 0x00000001 */ +} GdkGLRenderTypeMask; + +/* + * Buffer mask bits. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_FRONT_LEFT_BUFFER_BIT = 1 << 0, /* 0x00000001 */ + GDK_GL_FRONT_RIGHT_BUFFER_BIT = 1 << 1, /* 0x00000002 */ + GDK_GL_BACK_LEFT_BUFFER_BIT = 1 << 2, /* 0x00000004 */ + GDK_GL_BACK_RIGHT_BUFFER_BIT = 1 << 3, /* 0x00000008 */ + GDK_GL_AUX_BUFFERS_BIT = 1 << 4, /* 0x00000010 */ + GDK_GL_DEPTH_BUFFER_BIT = 1 << 5, /* 0x00000020 */ + GDK_GL_STENCIL_BUFFER_BIT = 1 << 6, /* 0x00000040 */ + GDK_GL_ACCUM_BUFFER_BIT = 1 << 7 /* 0x00000080 */ +} GdkGLBufferMask; + +/* + * Error return values from glXGetConfig. Success is indicated by + * a value of 0. + */ +typedef enum +{ + GDK_GL_BAD_SCREEN = 1, /* screen # is bad */ + GDK_GL_BAD_ATTRIBUTE = 2, /* attribute to get is bad */ + GDK_GL_NO_EXTENSION = 3, /* no glx extension on server */ + GDK_GL_BAD_VISUAL = 4, /* visual # not known by GLX */ + GDK_GL_BAD_CONTEXT = 5, /* returned only by import_context EXT? */ + GDK_GL_BAD_VALUE = 6, /* returned only by glXSwapIntervalSGI? */ + GDK_GL_BAD_ENUM = 7 /* unused? */ +} GdkGLConfigError; + +/* + * glXCreateNewContext render_type attribute values. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_RGBA_TYPE = 0x8014, +} GdkGLRenderType; + +/* + * glXQueryDrawable attributes. + * [ GLX 1.3 and later ] + */ +typedef enum +{ + GDK_GL_PRESERVED_CONTENTS = 0x801B, + GDK_GL_WIDTH = 0x801D, + GDK_GL_HEIGHT = 0x801E, + GDK_GL_EVENT_MASK = 0x801F +} GdkGLDrawableAttrib; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __GDK_GL_TOKENS_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkgltypes.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgltypes.h new file mode 100644 index 00000000..c1bfc1d0 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkgltypes.h @@ -0,0 +1,45 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_TYPES_H__ +#define __GDK_GL_TYPES_H__ + +#include <gdk/gdk.h> + +G_BEGIN_DECLS + +/* + * Forward declarations of commonly used types + */ + +typedef void (*GdkGLProc)(void); + +typedef struct _GdkGLConfig GdkGLConfig; +typedef struct _GdkGLContext GdkGLContext; + +typedef struct _GdkGLDrawable GdkGLDrawable; + +typedef struct _GdkGLWindow GdkGLWindow; + +G_END_DECLS + +#endif /* __GDK_GL_TYPES_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglversion.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglversion.c new file mode 100644 index 00000000..972dae37 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglversion.c @@ -0,0 +1,88 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "gdkglversion.h" + +/** + * gdk_gl_get_major_version: + * + * Returns the GtkGLExt library major version number. + * + * Returns: The major version number of the GtkGLExt library. + **/ +int +gdk_gl_get_major_version (void) +{ + return (GDKGLEXT_MAJOR_VERSION); +} + +/** + * gdk_gl_get_minor_version: + * + * Returns the GtkGLExt library minor version number. + * + * Returns: The minor version number of the GtkGLExt library. + **/ +int +gdk_gl_get_minor_version (void) +{ + return (GDKGLEXT_MINOR_VERSION); +} + +/** + * gdk_gl_get_micro_version: + * + * Returns the GtkGLExt library micro version number. + * + * Returns: The micro version number of the GtkGLExt library. + **/ +int +gdk_gl_get_micro_version (void) +{ + return (GDKGLEXT_MICRO_VERSION); +} + +/** + * gdk_gl_get_interface_age: + * + * Returns the GtkGLExt library interface age. + * + * Returns: The interface age of the GtkGLExt library. + **/ +int +gdk_gl_get_interface_age (void) +{ + return (GDKGLEXT_INTERFACE_AGE); +} + +/** + * gdk_gl_get_binary_age: + * + * Returns the GtkGLExt library binary age. + * + * Returns: The binary age of the GtkGLExt library. + **/ +int +gdk_gl_get_binary_age (void) +{ + return (GDKGLEXT_BINARY_AGE); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglversion.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglversion.h new file mode 100644 index 00000000..40f5ca33 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglversion.h @@ -0,0 +1,68 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_VERSION_H__ +#define __GDK_GL_VERSION_H__ + +#include <glib.h> + +#include <gdk/gdkgldefs.h> + +G_BEGIN_DECLS + +/* + * Compile time version. + */ +#define GDKGLEXT_MAJOR_VERSION (2) +#define GDKGLEXT_MINOR_VERSION (99) +#define GDKGLEXT_MICRO_VERSION (0) +#define GDKGLEXT_INTERFACE_AGE (0) +#define GDKGLEXT_BINARY_AGE (9900) + +/* + * Check whether a GdkGLExt version equal to or greater than + * major.minor.micro is present. + */ +#define GDKGLEXT_CHECK_VERSION(major, minor, micro) \ + (GDKGLEXT_MAJOR_VERSION > (major) || \ + (GDKGLEXT_MAJOR_VERSION == (major) && GDKGLEXT_MINOR_VERSION > (minor)) || \ + (GDKGLEXT_MAJOR_VERSION == (major) && GDKGLEXT_MINOR_VERSION == (minor) && \ + GDKGLEXT_MICRO_VERSION >= (micro))) + +int +gdk_gl_get_major_version (void); + +int +gdk_gl_get_minor_version (void); + +int +gdk_gl_get_micro_version (void); + +int +gdk_gl_get_interface_age (void); + +int +gdk_gl_get_binary_age (void); + +G_END_DECLS + +#endif /* __GDK_GL_VERSION_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindow.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindow.c new file mode 100644 index 00000000..ca65ee7e --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindow.c @@ -0,0 +1,347 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <gdk/gdk.h> + +#include "gdkglprivate.h" +#include "gdkglconfig.h" +#include "gdkglconfigimpl.h" +#include "gdkglwindow.h" +#include "gdkglwindowimpl.h" + +static GdkGLContext *_gdk_gl_window_create_gl_context (GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type); +static gboolean _gdk_gl_window_is_double_buffered (GdkGLDrawable *gldrawable); +static void _gdk_gl_window_swap_buffers (GdkGLDrawable *gldrawable); +static void _gdk_gl_window_wait_gl (GdkGLDrawable *gldrawable); +static void _gdk_gl_window_wait_gdk (GdkGLDrawable *gldrawable); +static GdkGLConfig *_gdk_gl_window_get_gl_config (GdkGLDrawable *gldrawable); + +static void gdk_gl_window_gl_drawable_interface_init (GdkGLDrawableClass *iface); + +G_DEFINE_TYPE_EXTENDED (GdkGLWindow, + gdk_gl_window, + G_TYPE_OBJECT, + 0, + G_IMPLEMENT_INTERFACE ( + GDK_TYPE_GL_DRAWABLE, + gdk_gl_window_gl_drawable_interface_init)) + +static void +gdk_gl_window_init (GdkGLWindow *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + self->window = NULL; +} + +static void +gdk_gl_window_finalize (GObject *object) +{ + GdkGLWindow *glwindow = GDK_GL_WINDOW (object); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (glwindow->window != NULL) + g_object_remove_weak_pointer (G_OBJECT (glwindow->window), + (gpointer *) &(glwindow->window)); + + G_OBJECT_CLASS (gdk_gl_window_parent_class)->finalize (object); +} + +static void +gdk_gl_window_class_init (GdkGLWindowClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + object_class->finalize = gdk_gl_window_finalize; +} + +static void +gdk_gl_window_gl_drawable_interface_init (GdkGLDrawableClass *iface) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + iface->create_gl_context = _gdk_gl_window_create_gl_context; + iface->is_double_buffered = _gdk_gl_window_is_double_buffered; + iface->swap_buffers = _gdk_gl_window_swap_buffers; + iface->wait_gl = _gdk_gl_window_wait_gl; + iface->wait_gdk = _gdk_gl_window_wait_gdk; + iface->get_gl_config = _gdk_gl_window_get_gl_config; +} + +static GdkGLContext * +_gdk_gl_window_create_gl_context (GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type) +{ + GdkGLWindow *glwindow; + + g_return_val_if_fail(GDK_IS_GL_WINDOW(gldrawable), NULL); + + glwindow = GDK_GL_WINDOW (gldrawable); + + return GDK_GL_WINDOW_IMPL_GET_CLASS (glwindow->impl)->create_gl_context (glwindow, + share_list, + direct, + render_type); +} + +static gboolean +_gdk_gl_window_is_double_buffered (GdkGLDrawable *gldrawable) +{ + GdkGLWindow *glwindow; + + g_return_val_if_fail(GDK_IS_GL_WINDOW(gldrawable), FALSE); + + glwindow = GDK_GL_WINDOW (gldrawable); + + return GDK_GL_WINDOW_IMPL_GET_CLASS (glwindow->impl)->is_double_buffered (glwindow); +} + +static void +_gdk_gl_window_swap_buffers (GdkGLDrawable *gldrawable) +{ + GdkGLWindow *glwindow; + + g_return_if_fail(GDK_IS_GL_WINDOW(gldrawable)); + + glwindow = GDK_GL_WINDOW (gldrawable); + + GDK_GL_WINDOW_IMPL_GET_CLASS (glwindow->impl)->swap_buffers (glwindow); +} + +static void +_gdk_gl_window_wait_gl (GdkGLDrawable *gldrawable) +{ + GdkGLWindow *glwindow; + + g_return_if_fail(GDK_IS_GL_WINDOW(gldrawable)); + + glwindow = GDK_GL_WINDOW (gldrawable); + + GDK_GL_WINDOW_IMPL_GET_CLASS (glwindow->impl)->wait_gl (glwindow); +} + +static void +_gdk_gl_window_wait_gdk (GdkGLDrawable *gldrawable) +{ + GdkGLWindow *glwindow; + + g_return_if_fail(GDK_IS_GL_WINDOW(gldrawable)); + + glwindow = GDK_GL_WINDOW (gldrawable); + + GDK_GL_WINDOW_IMPL_GET_CLASS (glwindow->impl)->wait_gdk (glwindow); +} + +static GdkGLConfig * +_gdk_gl_window_get_gl_config (GdkGLDrawable *gldrawable) +{ + GdkGLWindow *glwindow; + + g_return_val_if_fail(GDK_IS_GL_WINDOW(gldrawable), NULL); + + glwindow = GDK_GL_WINDOW (gldrawable); + + return GDK_GL_WINDOW_IMPL_GET_CLASS (glwindow->impl)->get_gl_config (glwindow); +} + +/** + * gdk_gl_window_new: + * @glconfig: a #GdkGLConfig. + * @window: the #GdkWindow to be used as the rendering area. + * @attrib_list: this must be set to NULL or empty (first attribute of None). + * + * Creates an on-screen rendering area. + * attrib_list is currently unused. This must be set to NULL or empty + * (first attribute of None). See GLX 1.3 spec. + * + * Return value: the new #GdkGLWindow. + **/ +GdkGLWindow * +gdk_gl_window_new (GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list) +{ + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), NULL); + + return GDK_GL_CONFIG_IMPL_GET_CLASS (glconfig->impl)->create_gl_window (glconfig, + window, + attrib_list); +} + +/** + * gdk_gl_window_get_window: + * @glwindow: a #GdkGLWindow. + * + * Returns the #GdkWindow associated with @glwindow. + * + * Return value: the #GdkWindow associated with @glwindow. + **/ +GdkWindow * +gdk_gl_window_get_window (GdkGLWindow *glwindow) +{ + g_return_val_if_fail (GDK_IS_GL_WINDOW (glwindow), NULL); + + return glwindow->window; +} + +/* + * OpenGL extension to GdkWindow + */ + +static const gchar quark_gl_window_string[] = "gdk-gl-window-gl-window"; +static GQuark quark_gl_window = 0; + +/** + * gdk_window_set_gl_capability: + * @window: the #GdkWindow to be used as the rendering area. + * @glconfig: a #GdkGLConfig. + * @attrib_list: this must be set to NULL or empty (first attribute of None). + * + * Set the OpenGL-capability to the @window. + * This function creates a new #GdkGLWindow held by the @window. + * attrib_list is currently unused. This must be set to NULL or empty + * (first attribute of None). + * + * Return value: the #GdkGLWindow used by the @window if it is successful, + * NULL otherwise. + **/ +GdkGLWindow * +gdk_window_set_gl_capability (GdkWindow *window, + GdkGLConfig *glconfig, + const int *attrib_list) +{ + GdkGLWindow *glwindow; + + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); + g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), NULL); + + if (quark_gl_window == 0) + quark_gl_window = g_quark_from_static_string (quark_gl_window_string); + + /* If already set */ + glwindow = g_object_get_qdata (G_OBJECT (window), quark_gl_window); + if (glwindow != NULL) + return glwindow; + + /* + * Create GdkGLWindow + */ + + glwindow = gdk_gl_window_new (glconfig, window, attrib_list); + if (glwindow == NULL) + { + g_warning ("cannot create GdkGLWindow\n"); + return NULL; + } + + g_object_set_qdata_full (G_OBJECT (window), quark_gl_window, glwindow, + (GDestroyNotify) g_object_unref); + + /* + * Set a background of "None" on window to avoid AIX X server crash + */ + + GDK_GL_NOTE (MISC, + g_message (" - window->bg_pixmap = %p", + (void*)gdk_window_get_background_pattern (window))); + + gdk_window_set_background_pattern (window, NULL); + + GDK_GL_NOTE (MISC, + g_message (" - window->bg_pixmap = %p", + (void*)gdk_window_get_background_pattern (window))); + + return glwindow; +} + +/** + * gdk_window_unset_gl_capability: + * @window: a #GdkWindow. + * + * Unset the OpenGL-capability of the @window. + * This function destroys the #GdkGLWindow held by the @window. + * + **/ +void +gdk_window_unset_gl_capability (GdkWindow *window) +{ + GdkGLWindow *glwindow; + + GDK_GL_NOTE_FUNC (); + + if (quark_gl_window == 0) + quark_gl_window = g_quark_from_static_string (quark_gl_window_string); + + /* + * Destroy OpenGL resources explicitly, then unref. + */ + + glwindow = g_object_get_qdata (G_OBJECT (window), quark_gl_window); + if (glwindow == NULL) + return; + + GDK_GL_WINDOW_IMPL_GET_CLASS(glwindow->impl)->destroy_gl_window_impl(glwindow); + + g_object_set_qdata (G_OBJECT (window), quark_gl_window, NULL); +} + +/** + * gdk_window_is_gl_capable: + * @window: a #GdkWindow. + * + * Returns whether the @window is OpenGL-capable. + * + * Return value: TRUE if the @window is OpenGL-capable, FALSE otherwise. + **/ +gboolean +gdk_window_is_gl_capable (GdkWindow *window) +{ + g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE); + + return g_object_get_qdata (G_OBJECT (window), quark_gl_window) != NULL ? TRUE : FALSE; +} + +/** + * gdk_window_get_gl_window: + * @window: a #GdkWindow. + * + * Returns the #GdkGLWindow held by the @window. + * + * Return value: the #GdkGLWindow. + **/ +GdkGLWindow * +gdk_window_get_gl_window (GdkWindow *window) +{ + g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); + + return g_object_get_qdata (G_OBJECT (window), quark_gl_window); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindow.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindow.h new file mode 100644 index 00000000..8e43b36b --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindow.h @@ -0,0 +1,88 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGL_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkgl.h> can be included directly." +#endif + +#ifndef __GDK_GL_WINDOW_H__ +#define __GDK_GL_WINDOW_H__ + +#include <gdk/gdkgldefs.h> +#include <gdk/gdkgltypes.h> + +#include <gdk/gdk.h> + +G_BEGIN_DECLS + +struct _GdkGLWindowImpl; +typedef struct _GdkGLWindowClass GdkGLWindowClass; + +#define GDK_TYPE_GL_WINDOW (gdk_gl_window_get_type ()) +#define GDK_GL_WINDOW(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_WINDOW, GdkGLWindow)) +#define GDK_GL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_WINDOW, GdkGLWindowClass)) +#define GDK_IS_GL_WINDOW(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_WINDOW)) +#define GDK_IS_GL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_WINDOW)) +#define GDK_GL_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_WINDOW, GdkGLWindowClass)) + +struct _GdkGLWindow +{ + GObject parent_instance; + + struct _GdkGLWindowImpl *impl; + + GdkWindow *window; /* Associated GdkWindow */ +}; + +struct _GdkGLWindowClass +{ + GObjectClass parent_class; +}; + +GType gdk_gl_window_get_type (void); + +/* + * attrib_list is currently unused. This must be set to NULL or empty + * (first attribute of None). See GLX 1.3 spec. + */ +GdkGLWindow *gdk_gl_window_new (GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list); + +GdkWindow *gdk_gl_window_get_window (GdkGLWindow *glwindow); + +/* + * OpenGL extension to GdkWindow + */ + +GdkGLWindow *gdk_window_set_gl_capability (GdkWindow *window, + GdkGLConfig *glconfig, + const int *attrib_list); + +void gdk_window_unset_gl_capability (GdkWindow *window); + +gboolean gdk_window_is_gl_capable (GdkWindow *window); + +GdkGLWindow *gdk_window_get_gl_window (GdkWindow *window); + +#define gdk_window_get_gl_drawable(window) \ + GDK_GL_DRAWABLE (gdk_window_get_gl_window (window)) + +G_END_DECLS + +#endif /* __GDK_GL_WINDOW_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindowimpl.c b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindowimpl.c new file mode 100644 index 00000000..5682e3d2 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindowimpl.c @@ -0,0 +1,60 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gdk/gdk.h> /* for gdk_error_trap_(push|pop) () */ + +#include "gdkgldebug.h" +#include "gdkglwindowimpl.h" + +G_DEFINE_TYPE (GdkGLWindowImpl, gdk_gl_window_impl, G_TYPE_OBJECT); + +static void +gdk_gl_window_impl_init (GdkGLWindowImpl *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_gl_window_impl_finalize (GObject *object) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + G_OBJECT_CLASS (gdk_gl_window_impl_parent_class)->finalize (object); +} + +static void +gdk_gl_window_impl_class_init (GdkGLWindowImplClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + klass->create_gl_context = NULL; + klass->is_double_buffered = NULL; + klass->swap_buffers = NULL; + klass->wait_gl = NULL; + klass->wait_gdk = NULL; + klass->get_gl_config = NULL; + klass->destroy_gl_window_impl = NULL; + + object_class->finalize = gdk_gl_window_impl_finalize; +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindowimpl.h b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindowimpl.h new file mode 100644 index 00000000..6d6780dc --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/gdkglwindowimpl.h @@ -0,0 +1,58 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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 __GDK_GL_WINDOW_IMPL_H__ +#define __GDK_GL_WINDOW_IMPL_H__ + +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +#define GDK_TYPE_GL_WINDOW_IMPL (gdk_gl_window_impl_get_type ()) +#define GDK_GL_WINDOW_IMPL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_WINDOW_IMPL, GdkGLWindowImpl)) +#define GDK_GL_WINDOW_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_WINDOW_IMPL, GdkGLWindowImplClass)) +#define GDK_IS_GL_WINDOW_IMPL(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_WINDOW_IMPL)) +#define GDK_IS_GL_WINDOW_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_WINDOW_IMPL)) +#define GDK_GL_WINDOW_IMPL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_WINDOW_IMPL, GdkGLWindowImplClass)) + +typedef struct _GdkGLWindowImpl +{ + GObject parent; +} GdkGLWindowImpl; + +typedef struct _GdkGLWindowImplClass +{ + GObjectClass parent_class; + + GdkGLContext* (*create_gl_context) (GdkGLWindow *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type); + gboolean (*is_double_buffered) (GdkGLWindow *glwindow); + void (*swap_buffers) (GdkGLWindow *glwindow); + void (*wait_gl) (GdkGLWindow *glwindow); + void (*wait_gdk) (GdkGLWindow *glwindow); + GdkGLConfig* (*get_gl_config) (GdkGLWindow *glwindow); + void (*destroy_gl_window_impl) (GdkGLWindow *glwindow); +} GdkGLWindowImplClass; + +GType gdk_gl_window_impl_get_type (void); + +G_END_DECLS + +#endif /* __GDK_GL_WINDOW_IMPL_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglconfig-x11.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglconfig-x11.c new file mode 100644 index 00000000..03b4d5b2 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglconfig-x11.c @@ -0,0 +1,559 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <string.h> + +#include "gdkglx.h" +#include "gdkglprivate-x11.h" +#include "gdkglconfig-x11.h" +#include "gdkglwindow-x11.h" + +#include <gdk/gdk.h> + +#ifdef HAVE_LIBXMU + +#include <X11/Xatom.h> /* for XA_RGB_DEFAULT_MAP atom */ + +#ifdef HAVE_XMU_STDCMAP_H +#include <Xmu/StdCmap.h> /* for XmuLookupStandardColormap */ +#else +#include <X11/Xmu/StdCmap.h> /* for XmuLookupStandardColormap */ +#endif + +#endif /* HAVE_LIBXMU */ + +static Display *_gdk_x11_gl_config_impl_get_xdisplay (GdkGLConfig *glconfig); +static int _gdk_x11_gl_config_impl_get_screen_number (GdkGLConfig *glconfig); +static XVisualInfo *_gdk_x11_gl_config_impl_get_xvinfo (GdkGLConfig *glconfig); +static GdkGLWindow *_gdk_x11_gl_config_impl_create_gl_window (GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list); +static GdkScreen *_gdk_x11_gl_config_impl_get_screen (GdkGLConfig *glconfig); +static gboolean _gdk_x11_gl_config_impl_get_attrib (GdkGLConfig *glconfig, + int attribute, + int *value); +static GdkVisual *_gdk_x11_gl_config_impl_get_visual (GdkGLConfig *glconfig); +static gint _gdk_x11_gl_config_impl_get_depth (GdkGLConfig *glconfig); + +G_DEFINE_TYPE (GdkGLConfigImplX11, \ + gdk_gl_config_impl_x11, \ + GDK_TYPE_GL_CONFIG_IMPL) + +static void +gdk_gl_config_impl_x11_init (GdkGLConfigImplX11 *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + self->xdisplay = NULL; + self->screen_num = 0; + self->xvinfo = NULL; + self->screen = 0; +} + +static void +gdk_gl_config_impl_x11_finalize (GObject *object) +{ + GdkGLConfigImplX11 *x11_impl = GDK_GL_CONFIG_IMPL_X11 (object); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + XFree (x11_impl->xvinfo); + + G_OBJECT_CLASS (gdk_gl_config_impl_x11_parent_class)->finalize (object); +} + +static void +gdk_gl_config_impl_x11_class_init (GdkGLConfigImplX11Class *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + klass->get_xdisplay = _gdk_x11_gl_config_impl_get_xdisplay; + klass->get_screen_number = _gdk_x11_gl_config_impl_get_screen_number; + klass->get_xvinfo = _gdk_x11_gl_config_impl_get_xvinfo; + + klass->parent_class.create_gl_window = _gdk_x11_gl_config_impl_create_gl_window; + klass->parent_class.get_screen = _gdk_x11_gl_config_impl_get_screen; + klass->parent_class.get_attrib = _gdk_x11_gl_config_impl_get_attrib; + klass->parent_class.get_visual = _gdk_x11_gl_config_impl_get_visual; + klass->parent_class.get_depth = _gdk_x11_gl_config_impl_get_depth; + + object_class->finalize = gdk_gl_config_impl_x11_finalize; +} + +static void +gdk_x11_gl_config_impl_init_attrib (GdkGLConfig *glconfig) +{ + GdkGLConfigImplX11 *x11_impl; + int value; + + x11_impl = GDK_GL_CONFIG_IMPL_X11 (glconfig->impl); + +#define _GET_CONFIG(__attrib) \ + glXGetConfig (x11_impl->xdisplay, x11_impl->xvinfo, __attrib, &value) + + /* RGBA mode? */ + _GET_CONFIG (GLX_RGBA); + glconfig->impl->is_rgba = value ? TRUE : FALSE; + + /* Layer plane. */ + _GET_CONFIG (GLX_LEVEL); + glconfig->impl->layer_plane = value; + + /* Double buffering is supported? */ + _GET_CONFIG (GLX_DOUBLEBUFFER); + glconfig->impl->is_double_buffered = value ? TRUE : FALSE; + + /* Stereo is supported? */ + _GET_CONFIG (GLX_STEREO); + glconfig->impl->is_stereo = value ? TRUE : FALSE; + + /* Number of aux buffers */ + _GET_CONFIG (GLX_AUX_BUFFERS); + glconfig->impl->n_aux_buffers = value; + + /* Has alpha bits? */ + _GET_CONFIG (GLX_ALPHA_SIZE); + glconfig->impl->has_alpha = value ? TRUE : FALSE; + + /* Has depth buffer? */ + _GET_CONFIG (GLX_DEPTH_SIZE); + glconfig->impl->has_depth_buffer = value ? TRUE : FALSE; + + /* Has stencil buffer? */ + _GET_CONFIG (GLX_STENCIL_SIZE); + glconfig->impl->has_stencil_buffer = value ? TRUE : FALSE; + + /* Has accumulation buffer? */ + _GET_CONFIG (GLX_ACCUM_RED_SIZE); + glconfig->impl->has_accum_buffer = value ? TRUE : FALSE; + + /* Number of multisample buffers (not supported yet) */ + glconfig->impl->n_sample_buffers = 0; + +#undef _GET_CONFIG +} + +static int * +glx_attrib_list_from_attrib_list (const gint *attrib_list, gsize n_attribs) +{ + static const guchar has_param[] = + { + [GDK_GL_BUFFER_SIZE] = 1, + [GDK_GL_LEVEL] = 1, + [GDK_GL_AUX_BUFFERS] = 1, + [GDK_GL_RED_SIZE] = 1, + [GDK_GL_GREEN_SIZE] = 1, + [GDK_GL_BLUE_SIZE] = 1, + [GDK_GL_ALPHA_SIZE] = 1, + [GDK_GL_DEPTH_SIZE] = 1, + [GDK_GL_STENCIL_SIZE] = 1, + [GDK_GL_ACCUM_RED_SIZE] = 1, + [GDK_GL_ACCUM_GREEN_SIZE] = 1, + [GDK_GL_ACCUM_BLUE_SIZE] = 1, + [GDK_GL_ACCUM_ALPHA_SIZE] = 1 + }; + + static const int glx_attrib_of_attrib[] = + { + [GDK_GL_USE_GL] = GLX_USE_GL, + [GDK_GL_BUFFER_SIZE] = GLX_BUFFER_SIZE, + [GDK_GL_LEVEL] = GLX_LEVEL, + [GDK_GL_RGBA] = GLX_RGBA, + [GDK_GL_DOUBLEBUFFER] = GLX_DOUBLEBUFFER, + [GDK_GL_STEREO] = GLX_STEREO, + [GDK_GL_AUX_BUFFERS] = GLX_AUX_BUFFERS, + [GDK_GL_RED_SIZE] = GLX_RED_SIZE, + [GDK_GL_GREEN_SIZE] = GLX_GREEN_SIZE, + [GDK_GL_BLUE_SIZE] = GLX_BLUE_SIZE, + [GDK_GL_ALPHA_SIZE] = GLX_ALPHA_SIZE, + [GDK_GL_DEPTH_SIZE] = GLX_DEPTH_SIZE, + [GDK_GL_STENCIL_SIZE] = GLX_STENCIL_SIZE, + [GDK_GL_ACCUM_RED_SIZE] = GLX_ACCUM_RED_SIZE, + [GDK_GL_ACCUM_GREEN_SIZE] = GLX_ACCUM_GREEN_SIZE, + [GDK_GL_ACCUM_BLUE_SIZE] = GLX_ACCUM_BLUE_SIZE, + [GDK_GL_ACCUM_ALPHA_SIZE] = GLX_ACCUM_ALPHA_SIZE + }; + + int *glx_attrib_list; + gsize attrib_index; + gsize glx_attrib_index; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + glx_attrib_list = g_malloc( sizeof(*glx_attrib_list)*(n_attribs+3) ); + + if (!glx_attrib_list) + goto err_g_malloc; + + for (attrib_index = 0, glx_attrib_index = 0; (attrib_index < n_attribs) && attrib_list[attrib_index]; ++attrib_index) + { + switch (attrib_list[attrib_index]) + { + case GDK_GL_USE_GL: + /* legacy from GLX 1.2 and always true; will be removed */ + case GDK_GL_RGBA: + /* not supported anymore */ + break; + + default: + glx_attrib_list[glx_attrib_index++] = glx_attrib_of_attrib[attrib_list[attrib_index]]; + if ( has_param[attrib_list[attrib_index]] ) + { + ++attrib_index; + if (attrib_index == n_attribs) + goto err_n_attribs; + glx_attrib_list[glx_attrib_index++] = attrib_list[attrib_index]; + } + break; + } + } + + glx_attrib_list[glx_attrib_index++] = GLX_RGBA; + glx_attrib_list[glx_attrib_index++] = GLX_USE_GL; + glx_attrib_list[glx_attrib_index++] = None; + + return glx_attrib_list; + +err_n_attribs: + g_free(glx_attrib_list); +err_g_malloc: + return NULL; +} + +static GdkGLConfig * +gdk_x11_gl_config_impl_new_common (GdkGLConfig *glconfig, + GdkScreen *screen, + const int *attrib_list, + gsize n_attribs) +{ + GdkGLConfigImplX11 *x11_impl; + + Display *xdisplay; + int screen_num; + int *glx_attrib_list; + XVisualInfo *xvinfo; + int is_rgba; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + xdisplay = GDK_SCREEN_XDISPLAY (screen); + screen_num = GDK_SCREEN_XNUMBER (screen); + + GDK_GL_NOTE (MISC, _gdk_x11_gl_print_glx_info (xdisplay, screen_num)); + + /* + * Find an OpenGL-capable visual. + */ + + glx_attrib_list = glx_attrib_list_from_attrib_list(attrib_list, n_attribs); + + if (glx_attrib_list == NULL) + goto err_glx_attrib_list_from_attrib_list; + + GDK_GL_NOTE_FUNC_IMPL ("glXChooseVisual"); + + xvinfo = glXChooseVisual (xdisplay, screen_num, glx_attrib_list); + + if (xvinfo == NULL) + goto err_glXChooseVisual; + + GDK_GL_NOTE (MISC, + g_message (" -- glXChooseVisual: screen number = %d", xvinfo->screen)); + GDK_GL_NOTE (MISC, + g_message (" -- glXChooseVisual: visual id = 0x%lx", xvinfo->visualid)); + + /* + * Instantiate the GdkGLConfigImplX11 object. + */ + + x11_impl = g_object_new (GDK_TYPE_GL_CONFIG_IMPL_X11, NULL); + + x11_impl->xdisplay = xdisplay; + x11_impl->screen_num = screen_num; + x11_impl->xvinfo = xvinfo; + + x11_impl->screen = screen; + + /* RGBA mode? */ + glXGetConfig (xdisplay, xvinfo, GLX_RGBA, &is_rgba); + + /* + * Init GdkGLConfig + */ + glconfig->impl = GDK_GL_CONFIG_IMPL (x11_impl); + + /* + * Init configuration attributes. + */ + + gdk_x11_gl_config_impl_init_attrib (glconfig); + + g_free(glx_attrib_list); + + return glconfig; + +err_glXChooseVisual: + g_free(glx_attrib_list); +err_glx_attrib_list_from_attrib_list: + return NULL; +} + +GdkGLConfig * +_gdk_x11_gl_config_impl_new (GdkGLConfig *glconfig, + const int *attrib_list, + gsize n_attribs) +{ + GdkScreen *screen; + + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG(glconfig), NULL); + g_return_val_if_fail (attrib_list != NULL, NULL); + + screen = gdk_screen_get_default (); + + return gdk_x11_gl_config_impl_new_common (glconfig, screen, attrib_list, n_attribs); +} + +GdkGLConfig * +_gdk_x11_gl_config_impl_new_for_screen (GdkGLConfig *glconfig, + GdkScreen *screen, + const int *attrib_list, + gsize n_attribs) +{ + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG(glconfig), NULL); + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + g_return_val_if_fail (attrib_list != NULL, NULL); + + return gdk_x11_gl_config_impl_new_common (glconfig, screen, attrib_list, n_attribs); +} + +/* + * XVisualInfo returned by this function should be freed by XFree (). + */ +static XVisualInfo * +gdk_x11_gl_get_xvinfo (Display *xdisplay, + int screen_num, + VisualID xvisualid) +{ + XVisualInfo xvinfo_template; + XVisualInfo *xvinfo_list; + int nitems_return; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + xvinfo_template.visualid = xvisualid; + xvinfo_template.screen = screen_num; + + xvinfo_list = XGetVisualInfo (xdisplay, + VisualIDMask | VisualScreenMask, + &xvinfo_template, + &nitems_return); + + /* Returned XVisualInfo needs to be unique */ + g_assert (xvinfo_list != NULL && nitems_return == 1); + + return xvinfo_list; +} + +static GdkGLConfig * +gdk_x11_gl_config_impl_new_from_visualid_common (GdkGLConfig *glconfig, + GdkScreen *screen, + VisualID xvisualid) +{ + GdkGLConfigImplX11 *x11_impl; + + Display *xdisplay; + int screen_num; + XVisualInfo *xvinfo; + int is_rgba; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + xdisplay = GDK_SCREEN_XDISPLAY (screen); + screen_num = GDK_SCREEN_XNUMBER (screen); + + GDK_GL_NOTE (MISC, + g_message (" -- GLX_VENDOR : %s", + glXGetClientString (xdisplay, GLX_VENDOR))); + GDK_GL_NOTE (MISC, + g_message (" -- GLX_VERSION : %s", + glXGetClientString (xdisplay, GLX_VERSION))); + GDK_GL_NOTE (MISC, + g_message (" -- GLX_EXTENSIONS : %s", + glXGetClientString (xdisplay, GLX_EXTENSIONS))); + + /* + * Get XVisualInfo. + */ + + xvinfo = gdk_x11_gl_get_xvinfo (xdisplay, screen_num, xvisualid); + if (xvinfo == NULL) + return NULL; + + GDK_GL_NOTE (MISC, + g_message (" -- gdk_x11_gl_get_xvinfo: screen number = %d", xvinfo->screen)); + GDK_GL_NOTE (MISC, + g_message (" -- gdk_x11_gl_get_xvinfo: visual id = 0x%lx", xvinfo->visualid)); + + /* + * Instantiate the GdkGLConfigImplX11 object. + */ + + x11_impl = g_object_new (GDK_TYPE_GL_CONFIG_IMPL_X11, NULL); + + g_return_val_if_fail(x11_impl != NULL, NULL); + + x11_impl->xdisplay = xdisplay; + x11_impl->screen_num = screen_num; + x11_impl->xvinfo = xvinfo; + x11_impl->screen = screen; + + /* RGBA mode? */ + glXGetConfig (xdisplay, xvinfo, GLX_RGBA, &is_rgba); + + /* + * Init GdkGLConfig + */ + + glconfig->impl = GDK_GL_CONFIG_IMPL (x11_impl); + + /* + * Init configuration attributes. + */ + + gdk_x11_gl_config_impl_init_attrib (glconfig); + + return glconfig; +} + +GdkGLConfig * +_gdk_x11_gl_config_impl_new_from_visualid_for_screen (GdkGLConfig *glconfig, + GdkScreen *screen, + VisualID xvisualid) +{ + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG(glconfig), NULL); + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + return gdk_x11_gl_config_impl_new_from_visualid_common (glconfig, screen, xvisualid); +} + +static Display * +_gdk_x11_gl_config_impl_get_xdisplay (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + return GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->xdisplay; +} + +static int +_gdk_x11_gl_config_impl_get_screen_number (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), 0); + + return GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->screen_num; +} + +static XVisualInfo * +_gdk_x11_gl_config_impl_get_xvinfo (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + return GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->xvinfo; +} + +static GdkGLWindow * +_gdk_x11_gl_config_impl_create_gl_window (GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list) +{ + GdkGLWindow *glwindow; + GdkGLWindow *impl; + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + glwindow = g_object_new (GDK_TYPE_X11_GL_WINDOW, NULL); + + g_return_val_if_fail(glwindow != NULL, NULL); + + impl = _gdk_x11_gl_window_impl_new(glwindow, + glconfig, + window, + attrib_list); + if (impl == NULL) + g_object_unref(glwindow); + + g_return_val_if_fail(impl != NULL, NULL); + + return glwindow; +} + +static GdkScreen * +_gdk_x11_gl_config_impl_get_screen (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + return GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->screen; +} + +static gboolean +_gdk_x11_gl_config_impl_get_attrib (GdkGLConfig *glconfig, + int attribute, + int *value) +{ + GdkGLConfigImplX11 *x11_impl; + int ret; + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), FALSE); + + x11_impl = GDK_GL_CONFIG_IMPL_X11 (glconfig->impl); + + ret = glXGetConfig (x11_impl->xdisplay, x11_impl->xvinfo, attribute, value); + + return (ret == Success); +} + +static GdkVisual * +_gdk_x11_gl_config_impl_get_visual (GdkGLConfig *glconfig) +{ + GdkGLConfigImplX11 *x11_impl; + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + x11_impl = GDK_GL_CONFIG_IMPL_X11 (glconfig->impl); + + return gdk_x11_screen_lookup_visual(x11_impl->screen, x11_impl->xvinfo->visualid); +} + +static gint +_gdk_x11_gl_config_impl_get_depth (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), 0); + + return GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->xvinfo->depth; +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglconfig-x11.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglconfig-x11.h new file mode 100644 index 00000000..daf6b7cc --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglconfig-x11.h @@ -0,0 +1,74 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_CONFIG_X11_H__ +#define __GDK_GL_CONFIG_X11_H__ + +#include <gdk/gdkx.h> + +#include <gdk/gdkglconfig.h> +#include <gdk/gdkglconfigimpl.h> + +G_BEGIN_DECLS + +typedef struct _GdkGLConfigImplX11 GdkGLConfigImplX11; +typedef struct _GdkGLConfigImplX11Class GdkGLConfigImplX11Class; + +#define GDK_TYPE_GL_CONFIG_IMPL_X11 (gdk_gl_config_impl_x11_get_type ()) +#define GDK_GL_CONFIG_IMPL_X11(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_CONFIG_IMPL_X11, GdkGLConfigImplX11)) +#define GDK_GL_CONFIG_IMPL_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONFIG_IMPL_X11, GdkGLConfigImplX11Class)) +#define GDK_IS_GL_CONFIG_IMPL_X11(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_CONFIG_IMPL_X11)) +#define GDK_IS_GL_CONFIG_IMPL_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONFIG_IMPL_X11)) +#define GDK_GL_CONFIG_IMPL_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONFIG_IMPL_X11, GdkGLConfigImplX11Class)) + +struct _GdkGLConfigImplX11 +{ + GdkGLConfigImpl parent_instance; + + Display *xdisplay; + int screen_num; + XVisualInfo *xvinfo; + + GdkScreen *screen; +}; + +struct _GdkGLConfigImplX11Class +{ + GdkGLConfigImplClass parent_class; + + Display* (*get_xdisplay) (GdkGLConfig *glconfig); + int (*get_screen_number) (GdkGLConfig *glconfig); + XVisualInfo* (*get_xvinfo) (GdkGLConfig *glconfig); +}; + +GType gdk_gl_config_impl_x11_get_type (void); + +GdkGLConfig *_gdk_x11_gl_config_impl_new (GdkGLConfig *glconfig, + const int *attrib_list, + gsize n_attribs); +GdkGLConfig *_gdk_x11_gl_config_impl_new_for_screen (GdkGLConfig *glconfig, + GdkScreen *screen, + const int *attrib_list, + gsize n_attribs); +GdkGLConfig *_gdk_x11_gl_config_impl_new_from_visualid_for_screen (GdkGLConfig *glconfig, + GdkScreen *screen, + VisualID xvisualid); + +G_END_DECLS + +#endif /* __GDK_GL_CONFIG_X11_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglcontext-x11.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglcontext-x11.c new file mode 100644 index 00000000..5fc0be54 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglcontext-x11.c @@ -0,0 +1,591 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gdk/gdk.h> /* for gdk_error_trap_(push|pop) () */ + +#include "gdkglx.h" +#include "gdkglprivate-x11.h" +#include "gdkglconfig-x11.h" +#include "gdkglwindow-x11.h" +#include "gdkglcontext-x11.h" + +static void gdk_gl_context_insert (GdkGLContext *glcontext); +static void gdk_gl_context_remove (GdkGLContext *glcontext); +static GdkGLContext *gdk_gl_context_lookup (GLXContext glxcontext); + +static gboolean _gdk_x11_gl_context_impl_copy (GdkGLContext *glcontext, + GdkGLContext *src, + unsigned long mask); +static GdkGLDrawable* _gdk_x11_gl_context_impl_get_gl_drawable (GdkGLContext *glcontext); +static GdkGLConfig* _gdk_x11_gl_context_impl_get_gl_config (GdkGLContext *glcontext); +static GdkGLContext* _gdk_x11_gl_context_impl_get_share_list (GdkGLContext *glcontext); +static gboolean _gdk_x11_gl_context_impl_is_direct (GdkGLContext *glcontext); +static int _gdk_x11_gl_context_impl_get_render_type (GdkGLContext *glcontext); +static gboolean _gdk_x11_gl_context_impl_make_current (GdkGLContext *glcontext, + GdkGLDrawable *draw, + GdkGLDrawable *read); +static GLXContext _gdk_x11_gl_context_impl_get_glxcontext (GdkGLContext *glcontext); + +G_DEFINE_TYPE (GdkGLContextImplX11, \ + gdk_gl_context_impl_x11, \ + GDK_TYPE_GL_CONTEXT_IMPL) + +static void +gdk_gl_context_impl_x11_init (GdkGLContextImplX11 *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + self->glxcontext = NULL; + self->share_list = NULL; + self->is_direct = FALSE; + self->render_type = 0; + self->glconfig = NULL; + self->gldrawable = NULL; + self->gldrawable_read = NULL; + self->is_destroyed = 0; + self->is_foreign = 0; +} + +void +_gdk_gl_context_destroy (GdkGLContext *glcontext) +{ + GdkGLContextImplX11 *impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl); + Display *xdisplay; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (impl->is_destroyed) + return; + + gdk_gl_context_remove (glcontext); + + xdisplay = GDK_GL_CONFIG_XDISPLAY (impl->glconfig); + + if (impl->glxcontext == glXGetCurrentContext ()) + { + glXWaitGL (); + + GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent"); + glXMakeCurrent (xdisplay, None, NULL); + } + + if (!impl->is_foreign) + { + GDK_GL_NOTE_FUNC_IMPL ("glXDestroyContext"); + glXDestroyContext (xdisplay, impl->glxcontext); + impl->glxcontext = NULL; + } + + if (impl->gldrawable != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (impl->gldrawable), + (gpointer *) &(impl->gldrawable)); + impl->gldrawable = NULL; + } + + /* currently unused. */ + /* + if (impl->gldrawable_read != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (impl->gldrawable_read), + (gpointer *) &(impl->gldrawable_read)); + impl->gldrawable_read = NULL; + } + */ + + impl->is_destroyed = TRUE; +} + +static void +gdk_gl_context_impl_x11_finalize (GObject *object) +{ + GdkGLContextImplX11 *impl = GDK_GL_CONTEXT_IMPL_X11 (object); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + _gdk_gl_context_destroy (GDK_GL_CONTEXT (object)); + + g_object_unref (G_OBJECT (impl->glconfig)); + + if (impl->share_list != NULL) + g_object_unref (G_OBJECT (impl->share_list)); + + G_OBJECT_CLASS (gdk_gl_context_impl_x11_parent_class)->finalize (object); +} + +static void +gdk_gl_context_impl_x11_class_init (GdkGLContextImplX11Class *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + klass->get_glxcontext = _gdk_x11_gl_context_impl_get_glxcontext; + + klass->parent_class.copy_gl_context_impl = _gdk_x11_gl_context_impl_copy; + klass->parent_class.get_gl_drawable = _gdk_x11_gl_context_impl_get_gl_drawable; + klass->parent_class.get_gl_config = _gdk_x11_gl_context_impl_get_gl_config; + klass->parent_class.get_share_list = _gdk_x11_gl_context_impl_get_share_list; + klass->parent_class.is_direct = _gdk_x11_gl_context_impl_is_direct; + klass->parent_class.get_render_type = _gdk_x11_gl_context_impl_get_render_type; + klass->parent_class.make_current = _gdk_x11_gl_context_impl_make_current; + klass->parent_class.make_uncurrent = NULL; + + object_class->finalize = gdk_gl_context_impl_x11_finalize; +} + +static GdkGLContextImpl * +gdk_x11_gl_context_impl_new_common (GdkGLContext *glcontext, + GdkGLConfig *glconfig, + GdkGLContext *share_list, + int render_type, + GLXContext glxcontext, + gboolean is_foreign) +{ + GdkGLContextImpl *impl; + GdkGLContextImplX11 *x11_impl; + + Display *xdisplay; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + /* + * Instantiate the GdkGLContextImplX11 object. + */ + + impl = g_object_new (GDK_TYPE_GL_CONTEXT_IMPL_X11, NULL); + x11_impl = GDK_GL_CONTEXT_IMPL_X11 (impl); + + x11_impl->glxcontext = glxcontext; + + if (share_list != NULL && GDK_IS_GL_CONTEXT (share_list)) + { + x11_impl->share_list = share_list; + g_object_ref (G_OBJECT (x11_impl->share_list)); + } + else + { + x11_impl->share_list = NULL; + } + + xdisplay = GDK_GL_CONFIG_XDISPLAY (glconfig); + x11_impl->is_direct = glXIsDirect (xdisplay, glxcontext) ? TRUE : FALSE; + + x11_impl->render_type = render_type; + + x11_impl->glconfig = glconfig; + g_object_ref (G_OBJECT (x11_impl->glconfig)); + + x11_impl->gldrawable = NULL; + x11_impl->gldrawable_read = NULL; + + x11_impl->is_foreign = is_foreign; + + x11_impl->is_destroyed = FALSE; + + glcontext->impl = impl; + + /* + * Insert into the GL context hash table. + */ + + gdk_gl_context_insert (glcontext); + + return impl; +} + +/*< private >*/ +GdkGLContextImpl * +_gdk_x11_gl_context_impl_new (GdkGLContext *glcontext, + GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type) +{ + GdkGLConfig *glconfig; + GdkGLContextImplX11 *share_impl = NULL; + GLXContext share_glxcontext = NULL; + + Display *xdisplay; + XVisualInfo *xvinfo; + GLXContext glxcontext; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + /* + * Create an OpenGL rendering context. + */ + + glconfig = gdk_gl_drawable_get_gl_config (gldrawable); + + xdisplay = GDK_GL_CONFIG_XDISPLAY (glconfig); + xvinfo = GDK_GL_CONFIG_XVINFO (glconfig); + + if (share_list != NULL && GDK_IS_GL_CONTEXT (share_list)) + { + share_impl = GDK_GL_CONTEXT_IMPL_X11 (share_list->impl); + share_glxcontext = share_impl->glxcontext; + } + + GDK_GL_NOTE_FUNC_IMPL ("glXCreateContext"); + + if (_gdk_gl_context_force_indirect) + { + GDK_GL_NOTE (MISC, g_message (" -- Force indirect")); + + glxcontext = glXCreateContext (xdisplay, + xvinfo, + share_glxcontext, + False); + } + else + { + glxcontext = glXCreateContext (xdisplay, + xvinfo, + share_glxcontext, + (direct == TRUE) ? True : False); + } + if (glxcontext == NULL) + return NULL; + + GDK_GL_NOTE (MISC, + g_message (" -- Context: screen number = %d", xvinfo->screen)); + GDK_GL_NOTE (MISC, + g_message (" -- Context: visual id = 0x%lx", xvinfo->visualid)); + + /* + * Instantiate the GdkGLContextImplX11 object. + */ + + return gdk_x11_gl_context_impl_new_common (glcontext, + glconfig, + share_list, + render_type, + glxcontext, + FALSE); +} + +GdkGLContextImpl * +_gdk_x11_gl_context_impl_new_from_glxcontext (GdkGLContext *glcontext, + GdkGLConfig *glconfig, + GdkGLContext *share_list, + GLXContext glxcontext) +{ + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + g_return_val_if_fail (glxcontext != NULL, NULL); + + /* + * Instantiate the GdkGLContextImplX11 object. + */ + + return gdk_x11_gl_context_impl_new_common (glcontext, + glconfig, + share_list, + GDK_GL_RGBA_TYPE, + glxcontext, + TRUE); +} + +static gboolean +_gdk_x11_gl_context_impl_copy (GdkGLContext *glcontext, + GdkGLContext *src, + unsigned long mask) +{ + GLXContext dst_glxcontext, src_glxcontext; + GdkGLConfig *glconfig; + + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), FALSE); + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (src), FALSE); + + dst_glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext); + if (dst_glxcontext == NULL) + return FALSE; + + src_glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (src); + if (src_glxcontext == NULL) + return FALSE; + + glconfig = GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->glconfig; + + gdk_error_trap_push (); + + glXCopyContext (GDK_GL_CONFIG_XDISPLAY (glconfig), + src_glxcontext, dst_glxcontext, + mask); + + return gdk_error_trap_pop () == Success; +} + +/*< private >*/ +void +_gdk_x11_gl_context_impl_set_gl_drawable (GdkGLContext *glcontext, + GdkGLDrawable *gldrawable) +{ + GdkGLContextImplX11 *impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (impl->gldrawable == gldrawable) + return; + + if (impl->gldrawable != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (impl->gldrawable), + (gpointer *) &(impl->gldrawable)); + impl->gldrawable = NULL; + } + + if (gldrawable != NULL && GDK_IS_GL_DRAWABLE (gldrawable)) + { + impl->gldrawable = gldrawable; + g_object_add_weak_pointer (G_OBJECT (impl->gldrawable), + (gpointer *) &(impl->gldrawable)); + } +} + +/*< private >*/ +/* currently unused. */ +/* +void +_gdk_gl_context_set_gl_drawable_read (GdkGLContext *glcontext, + GdkGLDrawable *gldrawable_read) +{ + GdkGLContextImplX11 *impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (impl->gldrawable_read == gldrawable_read) + return; + + if (impl->gldrawable_read != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (impl->gldrawable_read), + (gpointer *) &(impl->gldrawable_read)); + impl->gldrawable_read = NULL; + } + + if (gldrawable_read != NULL && GDK_IS_GL_DRAWABLE (gldrawable_read)) + { + impl->gldrawable_read = gldrawable_read; + g_object_add_weak_pointer (G_OBJECT (impl->gldrawable_read), + (gpointer *) &(impl->gldrawable_read)); + } +} +*/ + +static GdkGLDrawable * +_gdk_x11_gl_context_impl_get_gl_drawable (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), NULL); + + return GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->gldrawable; +} + +static GdkGLConfig * +_gdk_x11_gl_context_impl_get_gl_config (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), NULL); + + return GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->glconfig; +} + +static GdkGLContext * +_gdk_x11_gl_context_impl_get_share_list (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), NULL); + + return GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->share_list; +} + +static gboolean +_gdk_x11_gl_context_impl_is_direct (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), FALSE); + + return GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->is_direct; +} + +static int +_gdk_x11_gl_context_impl_get_render_type (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), 0); + + return GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->render_type; +} + +static gboolean +_gdk_x11_gl_context_impl_make_current (GdkGLContext *glcontext, + GdkGLDrawable *draw, + GdkGLDrawable *read) +{ + GdkGLWindow *glwindow; + GdkGLWindowImplX11 *x11_impl; + GdkGLConfig *glconfig; + GdkWindow *window; + Window glxwindow; + GLXContext glxcontext; + + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), FALSE); + g_return_val_if_fail (GDK_IS_X11_GL_WINDOW (draw), FALSE); + + glwindow = GDK_GL_WINDOW(draw); + x11_impl = GDK_GL_WINDOW_IMPL_X11 (glwindow->impl); + glconfig = x11_impl->glconfig; + window = gdk_gl_window_get_window(glwindow); + glxwindow = x11_impl->glxwindow; + glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext); + + if (glxwindow == None || glxcontext == NULL) + return FALSE; + + GDK_GL_NOTE (MISC, + g_message (" -- Window: screen number = %d", + GDK_SCREEN_XNUMBER (gdk_window_get_screen (window)))); + GDK_GL_NOTE (MISC, + g_message (" -- Window: visual id = 0x%lx", + GDK_VISUAL_XVISUAL (gdk_window_get_visual (window))->visualid)); + + GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent"); + + if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxwindow, glxcontext)) + { + g_warning ("glXMakeCurrent() failed"); + _gdk_x11_gl_context_impl_set_gl_drawable (glcontext, NULL); + /* currently unused. */ + /* _gdk_gl_context_set_gl_drawable_read (glcontext, NULL); */ + return FALSE; + } + + _gdk_x11_gl_context_impl_set_gl_drawable (glcontext, draw); + /* currently unused. */ + /* _gdk_gl_context_set_gl_drawable_read (glcontext, read); */ + + if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig)) + { + /* We do this because we are treating a double-buffered frame + buffer as a single-buffered frame buffer because the system + does not appear to export any suitable single-buffered + visuals (in which the following are necessary). */ + glDrawBuffer (GL_FRONT); + glReadBuffer (GL_FRONT); + } + + GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ()); + + return TRUE; +} + +GdkGLContext * +_gdk_x11_gl_context_impl_get_current (void) +{ + static GdkGLContext *current = NULL; + GLXContext glxcontext; + + GDK_GL_NOTE_FUNC (); + + glxcontext = glXGetCurrentContext (); + + if (glxcontext == NULL) + return NULL; + + if (current && GDK_GL_CONTEXT_GLXCONTEXT (current) == glxcontext) + return current; + + current = gdk_gl_context_lookup (glxcontext); + + return current; +} + +GLXContext +_gdk_x11_gl_context_impl_get_glxcontext (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), NULL); + + return GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->glxcontext; +} + +/* + * GdkGLContext hash table. + */ + +static GHashTable *gl_context_ht = NULL; + +static void +gdk_gl_context_insert (GdkGLContext *glcontext) +{ + GdkGLContextImplX11 *impl; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (gl_context_ht == NULL) + { + GDK_GL_NOTE (MISC, g_message (" -- Create GL context hash table.")); + + /* We do not know the storage type of GLXContext from the GLX + specification. We assume that it is a pointer as NULL values + are specified for this type---this is consistent with the SGI + and Mesa GLX implementations. */ + gl_context_ht = g_hash_table_new (g_direct_hash, + g_direct_equal); + } + + impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl); + + g_hash_table_insert (gl_context_ht, impl->glxcontext, glcontext); +} + +static void +gdk_gl_context_remove (GdkGLContext *glcontext) +{ + GdkGLContextImplX11 *impl; + + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (gl_context_ht == NULL) + return; + + impl = GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl); + + g_hash_table_remove (gl_context_ht, impl->glxcontext); + + if (g_hash_table_size (gl_context_ht) == 0) + { + GDK_GL_NOTE (MISC, g_message (" -- Destroy GL context hash table.")); + g_hash_table_destroy (gl_context_ht); + gl_context_ht = NULL; + } +} + +static GdkGLContext * +gdk_gl_context_lookup (GLXContext glxcontext) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + if (gl_context_ht == NULL) + return NULL; + + return g_hash_table_lookup (gl_context_ht, glxcontext); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglcontext-x11.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglcontext-x11.h new file mode 100644 index 00000000..bb21cd93 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglcontext-x11.h @@ -0,0 +1,85 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_CONTEXT_X11_H__ +#define __GDK_GL_CONTEXT_X11_H__ + +#include <GL/glx.h> + +#include <gdk/gdkglcontext.h> +#include <gdk/gdkglcontextimpl.h> + +G_BEGIN_DECLS + +typedef struct _GdkGLContextImplX11 GdkGLContextImplX11; +typedef struct _GdkGLContextImplX11Class GdkGLContextImplX11Class; + +#define GDK_TYPE_GL_CONTEXT_IMPL_X11 (gdk_gl_context_impl_x11_get_type ()) +#define GDK_GL_CONTEXT_IMPL_X11(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_CONTEXT_IMPL_X11, GdkGLContextImplX11)) +#define GDK_GL_CONTEXT_IMPL_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT_IMPL_X11, GdkGLContextImplX11Class)) +#define GDK_IS_GL_CONTEXT_IMPL_X11(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_CONTEXT_IMPL_X11)) +#define GDK_IS_GL_CONTEXT_IMPL_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT_IMPL_X11)) +#define GDK_GL_CONTEXT_IMPL_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT_IMPL_X11, GdkGLContextImplX11Class)) + +struct _GdkGLContextImplX11 +{ + GdkGLContextImpl parent_instance; + + GLXContext glxcontext; + GdkGLContext *share_list; + gboolean is_direct; + int render_type; + + GdkGLConfig *glconfig; + + GdkGLDrawable *gldrawable; + GdkGLDrawable *gldrawable_read; /* currently unused. */ + + guint is_destroyed : 1; + guint is_foreign : 1; +}; + +struct _GdkGLContextImplX11Class +{ + GdkGLContextImplClass parent_class; + + GLXContext (*get_glxcontext) (GdkGLContext *glcontext); +}; + +GType gdk_gl_context_impl_x11_get_type (void); + +GdkGLContextImpl *_gdk_x11_gl_context_impl_new (GdkGLContext *glcontext, + GdkGLDrawable *gldrawable, + GdkGLContext *share_list, + gboolean direct, + int render_type); + +GdkGLContextImpl *_gdk_x11_gl_context_impl_new_from_glxcontext (GdkGLContext *glcontext, + GdkGLConfig *glconfig, + GdkGLContext *share_list, + GLXContext glxcontext); + +void _gdk_x11_gl_context_impl_set_gl_drawable (GdkGLContext *glcontext, + GdkGLDrawable *gldrawable); + +GdkGLContext * +_gdk_x11_gl_context_impl_get_current (void); + +G_END_DECLS + +#endif /* __GDK_GL_CONTEXT_X11_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglprivate-x11.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglprivate-x11.h new file mode 100644 index 00000000..3beed7a3 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglprivate-x11.h @@ -0,0 +1,39 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_PRIVATE_X11_H__ +#define __GDK_GL_PRIVATE_X11_H__ + +#include <gdk/gdkprivate.h> + +#include <gdk/gdkglprivate.h> + +G_BEGIN_DECLS + +void _gdk_x11_gl_print_glx_info (Display *xdisplay, + int screen_num); + +#define GDK_GL_CONTEXT_IS_DESTROYED(glcontext) \ + ( ((GdkGLContextImplX11 *) (glcontext->impl))->is_destroyed ) + +#define GDK_GL_WINDOW_IS_DESTROYED(glwindow) \ + ( ((GdkGLWindowImplX11 *) (glwindow->impl))->is_destroyed ) + +G_END_DECLS + +#endif /* __GDK_GL_PRIVATE_X11_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglquery-x11.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglquery-x11.c new file mode 100644 index 00000000..d2ac7ae3 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglquery-x11.c @@ -0,0 +1,417 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <string.h> + +#ifdef __APPLE__ +#include <mach-o/dyld.h> +#else /* __APPLE__ */ +#include <gmodule.h> +#endif /* __APPLE__ */ + +#include <gdk/gdk.h> + +#include "gdkglx.h" +#include "gdkglprivate-x11.h" +#include "gdkglconfig-x11.h" +#include "gdkglquery.h" + +#include "gdkglquery-x11.h" + +gboolean +_gdk_x11_gl_query_extension_for_display (GdkDisplay *display) +{ + g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE); + + return glXQueryExtension (GDK_DISPLAY_XDISPLAY (display), + NULL, NULL); +} + +gboolean +_gdk_x11_gl_query_version_for_display (GdkDisplay *display, + int *major, + int *minor) +{ + g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE); + + return glXQueryVersion (GDK_DISPLAY_XDISPLAY (display), + major, minor); +} + +/* + * This code is based on __glutIsSupportedByGLX(). + */ + +/** + * gdk_x11_gl_query_glx_extension: + * @glconfig: a #GdkGLConfig. + * @extension: name of GLX extension. + * + * Determines whether a given GLX extension is supported. + * + * Return value: TRUE if the GLX extension is supported, FALSE if not + * supported. + **/ +gboolean +gdk_x11_gl_query_glx_extension (GdkGLConfig *glconfig, + const char *extension) +{ + static const char *extensions = NULL; + const char *start; + char *where, *terminator; + int major, minor; + + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), FALSE); + + /* Extension names should not have spaces. */ + where = strchr (extension, ' '); + if (where || *extension == '\0') + return FALSE; + + if (extensions == NULL) + { + /* Be careful not to call glXQueryExtensionsString if it + looks like the server doesn't support GLX 1.1. + Unfortunately, the original GLX 1.0 didn't have the notion + of GLX extensions. */ + + glXQueryVersion (GDK_GL_CONFIG_XDISPLAY (glconfig), + &major, &minor); + + if ((major == 1 && minor < 1) || (major < 1)) + return FALSE; + + extensions = glXQueryExtensionsString (GDK_GL_CONFIG_XDISPLAY (glconfig), + GDK_GL_CONFIG_SCREEN_XNUMBER (glconfig)); + } + + /* It takes a bit of care to be fool-proof about parsing + the GLX extensions string. Don't be fooled by + sub-strings, etc. */ + start = extensions; + for (;;) + { + where = strstr (start, extension); + if (where == NULL) + break; + + terminator = where + strlen (extension); + + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') + { + GDK_GL_NOTE (MISC, g_message (" - %s - supported", extension)); + return TRUE; + } + + start = terminator; + } + + GDK_GL_NOTE (MISC, g_message (" - %s - not supported", extension)); + + return FALSE; +} + +GdkGLProc +_gdk_x11_gl_get_proc_address (const char *proc_name) +{ +#ifdef __APPLE__ + + #define _GDK_GL_LIBGL_PATH "/usr/X11R6/lib/libGL.1.dylib" + #define _GDK_GL_LIBGLU_PATH "/usr/X11R6/lib/libGLU.1.dylib" + + typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *); + static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1; + const char *image_name; + static const struct mach_header *libgl_image = NULL; + static const struct mach_header *libglu_image = NULL; + NSSymbol symbol; + char *symbol_name; + GdkGLProc proc_address; + + GDK_GL_NOTE_FUNC (); + + if (strncmp ("glu", proc_name, 3) != 0) + { + /* libGL */ + + if (libgl_image == NULL) + { + image_name = g_getenv ("GDK_GL_LIBGL_PATH"); + if (image_name == NULL) + image_name = _GDK_GL_LIBGL_PATH; + + GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name)); + + libgl_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + if (libgl_image == NULL) + { + g_warning ("Cannot add Mach-O image %s", image_name); + return NULL; + } + } + + if (glx_get_proc_address == (__glXGetProcAddressProc) -1) + { + /* + * Look up glXGetProcAddress () function. + */ + + symbol = NSLookupSymbolInImage (libgl_image, + "_glXGetProcAddress", + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + if (symbol == NULL) + { + symbol = NSLookupSymbolInImage (libgl_image, + "_glXGetProcAddressARB", + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + if (symbol == NULL) + { + symbol = NSLookupSymbolInImage (libgl_image, + "_glXGetProcAddressEXT", + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + } + } + GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s", + symbol ? "supported" : "not supported")); + if (symbol != NULL) + glx_get_proc_address = NSAddressOfSymbol (symbol); + else + glx_get_proc_address = NULL; + } + + /* Try glXGetProcAddress () */ + + if (glx_get_proc_address != NULL) + { + proc_address = glx_get_proc_address ((unsigned char *) proc_name); + GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s", + proc_address ? "succeeded" : "failed")); + if (proc_address != NULL) + return proc_address; + } + + /* Try Mach-O dyld */ + + symbol_name = g_strconcat ("_", proc_name, NULL); + + symbol = NSLookupSymbolInImage (libgl_image, + symbol_name, + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s", + symbol ? "succeeded" : "failed")); + + g_free (symbol_name); + + if (symbol != NULL) + return NSAddressOfSymbol (symbol); + } + else + { + /* libGLU */ + + if (libglu_image == NULL) + { + image_name = g_getenv ("GDK_GL_LIBGLU_PATH"); + if (image_name == NULL) + image_name = _GDK_GL_LIBGLU_PATH; + + GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name)); + + libglu_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + if (libglu_image == NULL) + { + g_warning ("Cannot add Mach-O image %s", image_name); + return NULL; + } + } + + symbol_name = g_strconcat ("_", proc_name, NULL); + + symbol = NSLookupSymbolInImage (libglu_image, + symbol_name, + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s", + symbol ? "succeeded" : "failed")); + + g_free (symbol_name); + + if (symbol != NULL) + return NSAddressOfSymbol (symbol); + } + + return NULL; + +#else /* __APPLE__ */ + + typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *); + static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1; + gchar *file_name; + GModule *module; + GdkGLProc proc_address = NULL; + + GDK_GL_NOTE_FUNC (); + + if (strncmp ("glu", proc_name, 3) != 0) + { + if (glx_get_proc_address == (__glXGetProcAddressProc) -1) + { + /* + * Look up glXGetProcAddress () function. + */ + + file_name = g_module_build_path (NULL, "GL"); + GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); + module = g_module_open (file_name, G_MODULE_BIND_LAZY); + g_free (file_name); + + if (module != NULL) + { + g_module_symbol (module, "glXGetProcAddress", + (gpointer) &glx_get_proc_address); + if (glx_get_proc_address == NULL) + { + g_module_symbol (module, "glXGetProcAddressARB", + (gpointer) &glx_get_proc_address); + if (glx_get_proc_address == NULL) + { + g_module_symbol (module, "glXGetProcAddressEXT", + (gpointer) &glx_get_proc_address); + } + } + GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s", + glx_get_proc_address ? "supported" : "not supported")); + g_module_close (module); + } + else + { + g_warning ("Cannot open %s", file_name); + glx_get_proc_address = NULL; + return NULL; + } + } + + /* Try glXGetProcAddress () */ + + if (glx_get_proc_address != NULL) + { + proc_address = glx_get_proc_address ((unsigned char *) proc_name); + GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s", + proc_address ? "succeeded" : "failed")); + if (proc_address != NULL) + return proc_address; + } + + /* Try g_module_symbol () */ + + /* libGL */ + file_name = g_module_build_path (NULL, "GL"); + GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); + module = g_module_open (file_name, G_MODULE_BIND_LAZY); + g_free (file_name); + + if (module != NULL) + { + g_module_symbol (module, proc_name, (gpointer) &proc_address); + GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", + proc_address ? "succeeded" : "failed")); + g_module_close (module); + } + else + { + g_warning ("Cannot open %s", file_name); + } + + if (proc_address == NULL) + { + /* libGLcore */ + file_name = g_module_build_path (NULL, "GLcore"); + GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); + module = g_module_open (file_name, G_MODULE_BIND_LAZY); + g_free (file_name); + + if (module != NULL) + { + g_module_symbol (module, proc_name, (gpointer) &proc_address); + GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", + proc_address ? "succeeded" : "failed")); + g_module_close (module); + } + } + } + else + { + /* libGLU */ + file_name = g_module_build_path (NULL, "GLU"); + GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); + module = g_module_open (file_name, G_MODULE_BIND_LAZY); + g_free (file_name); + + if (module != NULL) + { + g_module_symbol (module, proc_name, (gpointer) &proc_address); + GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", + proc_address ? "succeeded" : "failed")); + g_module_close (module); + } + else + { + g_warning ("Cannot open %s", file_name); + } + } + + return proc_address; + +#endif /* __APPLE__ */ +} + +/*< private >*/ +void +_gdk_x11_gl_print_glx_info (Display *xdisplay, + int screen_num) +{ + static gboolean done = FALSE; + + if (!done) + { + g_message (" -- Server GLX_VENDOR : %s", + glXQueryServerString (xdisplay, screen_num, GLX_VENDOR)); + g_message (" -- Server GLX_VERSION : %s", + glXQueryServerString (xdisplay, screen_num, GLX_VERSION)); + g_message (" -- Server GLX_EXTENSIONS : %s", + glXQueryServerString (xdisplay, screen_num, GLX_EXTENSIONS)); + + g_message (" -- Client GLX_VENDOR : %s", + glXGetClientString (xdisplay, GLX_VENDOR)); + g_message (" -- Client GLX_VERSION : %s", + glXGetClientString (xdisplay, GLX_VERSION)); + g_message (" -- Client GLX_EXTENSIONS : %s", + glXGetClientString (xdisplay, GLX_EXTENSIONS)); + + done = TRUE; + } +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglquery-x11.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglquery-x11.h new file mode 100644 index 00000000..23154099 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglquery-x11.h @@ -0,0 +1,39 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_QUERY_X11_H__ +#define __GDK_GL_QUERY_X11_H__ + +#include "gdkglquery.h" + +G_BEGIN_DECLS + +gboolean +_gdk_x11_gl_query_extension_for_display (GdkDisplay *display); + +gboolean +_gdk_x11_gl_query_version_for_display (GdkDisplay *display, + int *major, + int *minor); + +GdkGLProc +_gdk_x11_gl_get_proc_address (const char *proc_name); + +G_END_DECLS + +#endif /* __GDK_GL_QUERY_X11_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglwindow-x11.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglwindow-x11.c new file mode 100644 index 00000000..91e00383 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglwindow-x11.c @@ -0,0 +1,262 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <string.h> + +#include "gdkglx.h" +#include "gdkglprivate-x11.h" +#include "gdkglconfig-x11.h" +#include "gdkglcontext-x11.h" +#include "gdkglwindow-x11.h" + +#include <gdk/gdkglquery.h> + +static GdkGLContext *_gdk_x11_gl_window_impl_create_gl_context (GdkGLWindow *glwindow, + GdkGLContext *share_list, + gboolean direct, + int render_type); +static gboolean _gdk_x11_gl_window_impl_is_double_buffered (GdkGLWindow *glwindow); +static void _gdk_x11_gl_window_impl_swap_buffers (GdkGLWindow *glwindow); +static void _gdk_x11_gl_window_impl_wait_gl (GdkGLWindow *glwindow); +static void _gdk_x11_gl_window_impl_wait_gdk (GdkGLWindow *glwindow); +static GdkGLConfig *_gdk_x11_gl_window_impl_get_gl_config (GdkGLWindow *glwindow); +static Window _gdk_x11_gl_window_impl_get_glxwindow (GdkGLWindow *glwindow); + +G_DEFINE_TYPE (GdkGLWindowImplX11, + gdk_gl_window_impl_x11, + GDK_TYPE_GL_WINDOW_IMPL); + +static void +gdk_gl_window_impl_x11_init (GdkGLWindowImplX11 *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + self->glxwindow = None; + self->glconfig = NULL; + self->is_destroyed = 0; +} + +static void +_gdk_x11_gl_window_impl_destroy (GdkGLWindow *glwindow) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + GdkGLWindowImplX11 *x11_impl = GDK_GL_WINDOW_IMPL_X11 (glwindow->impl); + Display *xdisplay; + Bool (APIENTRY *ReleaseBuffersMESA) (Display*, GLXDrawable); + + if (x11_impl->is_destroyed) + return; + + xdisplay = GDK_GL_CONFIG_XDISPLAY (x11_impl->glconfig); + + if (x11_impl->glxwindow == glXGetCurrentDrawable ()) + { + glXWaitGL (); + + GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent"); + glXMakeCurrent (xdisplay, None, NULL); + } + + if (gdk_x11_gl_query_glx_extension (x11_impl->glconfig, "GLX_MESA_release_buffers")) + { + /* Release buffers if GLX_MESA_release_buffers is supported. */ + + ReleaseBuffersMESA = (Bool (APIENTRY *)(Display*, GLXDrawable)) + gdk_gl_get_proc_address("glXReleaseBuffersMESA"); + + GDK_GL_NOTE_FUNC_IMPL ("glXReleaseBuffersMESA"); + if (ReleaseBuffersMESA) + ReleaseBuffersMESA (xdisplay, x11_impl->glxwindow); + } + + x11_impl->glxwindow = None; + + x11_impl->is_destroyed = TRUE; +} + +static void +gdk_gl_window_impl_x11_finalize (GObject *object) +{ + GdkGLWindowImplX11 *impl = GDK_GL_WINDOW_IMPL_X11 (object); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + _gdk_x11_gl_window_impl_destroy (GDK_GL_WINDOW (object)); + + g_object_unref (G_OBJECT (impl->glconfig)); + + G_OBJECT_CLASS (gdk_gl_window_impl_x11_parent_class)->finalize (object); +} + +static void +gdk_gl_window_impl_x11_class_init (GdkGLWindowImplX11Class *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + klass->get_glxwindow = _gdk_x11_gl_window_impl_get_glxwindow; + + klass->parent_class.create_gl_context = _gdk_x11_gl_window_impl_create_gl_context; + klass->parent_class.is_double_buffered = _gdk_x11_gl_window_impl_is_double_buffered; + klass->parent_class.swap_buffers = _gdk_x11_gl_window_impl_swap_buffers; + klass->parent_class.wait_gl = _gdk_x11_gl_window_impl_wait_gl; + klass->parent_class.wait_gdk = _gdk_x11_gl_window_impl_wait_gdk; + klass->parent_class.get_gl_config = _gdk_x11_gl_window_impl_get_gl_config; + klass->parent_class.destroy_gl_window_impl = _gdk_x11_gl_window_impl_destroy; + + object_class->finalize = gdk_gl_window_impl_x11_finalize; +} + +/* + * attrib_list is currently unused. This must be set to NULL or empty + * (first attribute of None). See GLX 1.3 spec. + */ +GdkGLWindow * +_gdk_x11_gl_window_impl_new (GdkGLWindow *glwindow, + GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list) +{ + GdkGLWindowImplX11 *x11_impl; + + /* GLXWindow glxwindow; */ + Window glxwindow; + + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_X11_GL_WINDOW (glwindow), NULL); + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); + + /* + * Get X Window. + */ + + glxwindow = GDK_WINDOW_XID (window); + + /* + * Instantiate the GdkGLWindowImplX11 object. + */ + + x11_impl = g_object_new (GDK_TYPE_GL_WINDOW_IMPL_X11, NULL); + GDK_GL_NOTE_FUNC (); + + x11_impl->glxwindow = glxwindow; + x11_impl->glconfig = glconfig; + g_object_ref (G_OBJECT (x11_impl->glconfig)); + + x11_impl->is_destroyed = FALSE; + + glwindow->impl = GDK_GL_WINDOW_IMPL(x11_impl); + glwindow->window = window; + g_object_add_weak_pointer (G_OBJECT (glwindow->window), + (gpointer *) &(glwindow->window)); + + return glwindow; +} + +static GdkGLContext * +_gdk_x11_gl_window_impl_create_gl_context (GdkGLWindow *glwindow, + GdkGLContext *share_list, + gboolean direct, + int render_type) +{ + GdkGLContext *glcontext; + GdkGLContextImpl *impl; + + glcontext = g_object_new(GDK_TYPE_X11_GL_CONTEXT, NULL); + + g_return_val_if_fail(glcontext != NULL, NULL); + + impl = _gdk_x11_gl_context_impl_new(glcontext, + GDK_GL_DRAWABLE(glwindow), + share_list, + direct, + render_type); + if (impl == NULL) + g_object_unref(glcontext); + + g_return_val_if_fail(impl != NULL, NULL); + + return glcontext; +} + +static gboolean +_gdk_x11_gl_window_impl_is_double_buffered (GdkGLWindow *glwindow) +{ + g_return_val_if_fail (GDK_IS_X11_GL_WINDOW (glwindow), FALSE); + + return gdk_gl_config_is_double_buffered (GDK_GL_WINDOW_IMPL_X11 (glwindow->impl)->glconfig); +} + +static void +_gdk_x11_gl_window_impl_swap_buffers (GdkGLWindow *glwindow) +{ + Display *xdisplay; + Window glxwindow; + + g_return_if_fail (GDK_IS_X11_GL_WINDOW (glwindow)); + + xdisplay = GDK_GL_CONFIG_XDISPLAY (GDK_GL_WINDOW_IMPL_X11 (glwindow->impl)->glconfig); + glxwindow = GDK_GL_WINDOW_IMPL_X11 (glwindow->impl)->glxwindow; + + if (glxwindow == None) + return; + + GDK_GL_NOTE_FUNC_IMPL ("glXSwapBuffers"); + + glXSwapBuffers (xdisplay, glxwindow); +} + +static void +_gdk_x11_gl_window_impl_wait_gl (GdkGLWindow *glwindow) +{ + g_return_if_fail (GDK_IS_X11_GL_WINDOW (glwindow)); + + glXWaitGL (); +} + +static void +_gdk_x11_gl_window_impl_wait_gdk (GdkGLWindow *glwindow) +{ + g_return_if_fail (GDK_IS_X11_GL_WINDOW (glwindow)); + + glXWaitX (); +} + +static GdkGLConfig * +_gdk_x11_gl_window_impl_get_gl_config (GdkGLWindow *glwindow) +{ + g_return_val_if_fail (GDK_IS_X11_GL_WINDOW (glwindow), NULL); + + return GDK_GL_WINDOW_IMPL_X11 (glwindow->impl)->glconfig; +} + +static Window +_gdk_x11_gl_window_impl_get_glxwindow (GdkGLWindow *glwindow) +{ + g_return_val_if_fail (GDK_IS_X11_GL_WINDOW (glwindow), None); + + return GDK_GL_WINDOW_IMPL_X11 (glwindow->impl)->glxwindow; +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglwindow-x11.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglwindow-x11.h new file mode 100644 index 00000000..8c16517d --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglwindow-x11.h @@ -0,0 +1,68 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_WINDOW_X11_H__ +#define __GDK_GL_WINDOW_X11_H__ + +#include <gdk/gdkx.h> + +#include <gdk/gdkglwindow.h> +#include <gdk/gdkglwindowimpl.h> + +G_BEGIN_DECLS + +typedef struct _GdkGLWindowImplX11 GdkGLWindowImplX11; +typedef struct _GdkGLWindowImplX11Class GdkGLWindowImplX11Class; + +#define GDK_TYPE_GL_WINDOW_IMPL_X11 (gdk_gl_window_impl_x11_get_type ()) +#define GDK_GL_WINDOW_IMPL_X11(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GL_WINDOW_IMPL_X11, GdkGLWindowImplX11)) +#define GDK_GL_WINDOW_IMPL_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_WINDOW_IMPL_X11, GdkGLWindowImplX11Class)) +#define GDK_IS_GL_WINDOW_IMPL_X11(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GL_WINDOW_IMPL_X11)) +#define GDK_IS_GL_WINDOW_IMPL_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_WINDOW_IMPL_X11)) +#define GDK_GL_WINDOW_IMPL_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_WINDOW_IMPL_X11, GdkGLWindowImplX11Class)) + +struct _GdkGLWindowImplX11 +{ + GdkGLWindowImpl parent_instance; + + /* GLXWindow glxwindow; */ + Window glxwindow; + + GdkGLConfig *glconfig; + + guint is_destroyed : 1; +}; + +struct _GdkGLWindowImplX11Class +{ + GdkGLWindowImplClass parent_class; + + Window (*get_glxwindow) (GdkGLWindow *glwindow); +}; + +GType gdk_gl_window_impl_x11_get_type (void); + +GdkGLWindow * +_gdk_x11_gl_window_impl_new (GdkGLWindow *glwindow, + GdkGLConfig *glconfig, + GdkWindow *window, + const int *attrib_list); + +G_END_DECLS + +#endif /* __GDK_GL_WINDOW_X11_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglx.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglx.h new file mode 100644 index 00000000..2655e67f --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkglx.h @@ -0,0 +1,39 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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 __GDK_GL_X_H__ +#define __GDK_GL_X_H__ + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <gdk/gdkx.h> + +#include <GL/gl.h> +#include <GL/glx.h> + +#define __GDKGLX_H_INSIDE__ + +#include <gdk/x11/gdkx11glconfig.h> +#include <gdk/x11/gdkx11glcontext.h> +#include <gdk/x11/gdkx11glquery.h> +#include <gdk/x11/gdkx11glwindow.h> + +#undef __GDKGLX_H_INSIDE__ + +#endif /* __GDK_GL_X_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glconfig.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glconfig.c new file mode 100644 index 00000000..426d28f7 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glconfig.c @@ -0,0 +1,245 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <gdk/gdkgldebug.h> +#include <gdk/x11/gdkglx.h> + +#include "gdkglconfig-x11.h" + +struct _GdkX11GLConfig +{ + GdkGLConfig parent; +}; + +struct _GdkX11GLConfigClass +{ + GdkGLConfigClass parent_class; +}; + +G_DEFINE_TYPE (GdkX11GLConfig, gdk_x11_gl_config, GDK_TYPE_GL_CONFIG); + +static void +gdk_x11_gl_config_init (GdkX11GLConfig *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_x11_gl_config_finalize (GObject *object) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + G_OBJECT_CLASS (gdk_x11_gl_config_parent_class)->finalize (object); +} + +static void +gdk_x11_gl_config_class_init (GdkX11GLConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + object_class->finalize = gdk_x11_gl_config_finalize; +} + +/** + * gdk_x11_gl_config_new_for_display: + * @display: display. + * @attrib_list: (array length=n_attribs): the attribute list. + * @n_attribs: the number of attributes and values in attrib_list + * + * Creates a #GdkGLConfig on the given display. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_x11_gl_config_new_for_display(GdkDisplay *display, const int *attrib_list, gsize n_attribs) +{ + GdkGLConfig *glconfig; + GdkGLConfig *impl; + + g_return_val_if_fail(GDK_IS_X11_DISPLAY(display), NULL); + + glconfig = g_object_new(GDK_TYPE_X11_GL_CONFIG, NULL); + + g_return_val_if_fail(glconfig != NULL, NULL); + + impl = _gdk_x11_gl_config_impl_new(glconfig, attrib_list, n_attribs); + + if (impl == NULL) + g_object_unref(glconfig); + + g_return_val_if_fail(impl != NULL, NULL); + + return glconfig; +} + +/** + * gdk_x11_gl_config_new_for_screen: + * @screen: target screen. + * @attrib_list: (array length=n_attribs): the attribute list. + * @n_attribs: the number of attributes and values in attrib_list + * + * Creates a #GdkGLConfig on the given display. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_x11_gl_config_new_for_screen(GdkScreen *screen, const int *attrib_list, gsize n_attribs) +{ + GdkGLConfig *glconfig; + GdkGLConfig *impl; + + g_return_val_if_fail(GDK_IS_X11_SCREEN(screen), NULL); + + glconfig = g_object_new(GDK_TYPE_X11_GL_CONFIG, NULL); + + g_return_val_if_fail(glconfig != NULL, NULL); + + impl = _gdk_x11_gl_config_impl_new(glconfig, attrib_list, n_attribs); + + if (impl == NULL) + g_object_unref(glconfig); + + g_return_val_if_fail(impl != NULL, NULL); + + return glconfig; +} + +/** + * gdk_x11_gl_config_new_from_visualid: + * @xvisualid: visual ID. + * + * Creates #GdkGLConfig from given visual ID that specifies the OpenGL-capable + * visual. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_x11_gl_config_new_from_visualid (VisualID xvisualid) +{ + GdkScreen *screen; + GdkGLConfig *glconfig; + GdkGLConfig *impl; + + GDK_GL_NOTE_FUNC (); + + screen = gdk_screen_get_default (); + + glconfig = g_object_new(GDK_TYPE_X11_GL_CONFIG, NULL); + + g_return_val_if_fail(glconfig != NULL, NULL); + + impl = _gdk_x11_gl_config_impl_new_from_visualid_for_screen (glconfig, + screen, + xvisualid); + if (impl == NULL) + g_object_unref(glconfig); + + g_return_val_if_fail(impl != NULL, NULL); + + return glconfig; +} + +/** + * gdk_x11_gl_config_new_from_visualid_for_screen: + * @screen: target screen. + * @xvisualid: visual ID. + * + * Creates #GdkGLConfig from given visual ID that specifies the OpenGL-capable + * visual. + * + * Return value: the new #GdkGLConfig. + **/ +GdkGLConfig * +gdk_x11_gl_config_new_from_visualid_for_screen (GdkScreen *screen, + VisualID xvisualid) +{ + GdkGLConfig *glconfig; + GdkGLConfig *impl; + + GDK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + glconfig = g_object_new(GDK_TYPE_X11_GL_CONFIG, NULL); + + g_return_val_if_fail(glconfig != NULL, NULL); + + impl = _gdk_x11_gl_config_impl_new_from_visualid_for_screen (glconfig, + screen, + xvisualid); + if (impl == NULL) + g_object_unref(glconfig); + + g_return_val_if_fail(impl != NULL, NULL); + + return glconfig; +} + +/** + * gdk_x11_gl_config_get_xdisplay: + * @glconfig: a #GdkGLConfig. + * + * Gets X Display. + * + * Return value: pointer to the Display. + **/ +Display * +gdk_x11_gl_config_get_xdisplay (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + return GDK_GL_CONFIG_IMPL_X11_CLASS (glconfig)->get_xdisplay(glconfig); +} + +/** + * gdk_x11_gl_config_get_screen_number: + * @glconfig: a #GdkGLConfig. + * + * Gets X screen number. + * + * Return value: the screen number. + **/ +int +gdk_x11_gl_config_get_screen_number (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), 0); + + return GDK_GL_CONFIG_IMPL_X11_CLASS (glconfig)->get_screen_number(glconfig); +} + +/** + * gdk_x11_gl_config_get_xvinfo: + * @glconfig: a #GdkGLConfig. + * + * Gets XVisualInfo data. + * + * Return value: pointer to the XVisualInfo data. + **/ +XVisualInfo * +gdk_x11_gl_config_get_xvinfo (GdkGLConfig *glconfig) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), NULL); + + return GDK_GL_CONFIG_IMPL_X11_CLASS (glconfig)->get_xvinfo(glconfig); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glconfig.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glconfig.h new file mode 100644 index 00000000..abebd9f2 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glconfig.h @@ -0,0 +1,82 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGLX_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkglx.h> can be included directly." +#endif + +#ifndef __GDK_X11_GL_CONFIG_H__ +#define __GDK_X11_GL_CONFIG_H__ + +#include <gdk/gdkx.h> +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +#define GDK_TYPE_X11_GL_CONFIG (gdk_x11_gl_config_get_type ()) +#define GDK_X11_GL_CONFIG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_X11_GL_CONFIG, GdkX11GLConfig)) +#define GDK_X11_GL_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_X11_GL_CONFIG, GdkX11GLConfigClass)) +#define GDK_IS_X11_GL_CONFIG(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_X11_GL_CONFIG)) +#define GDK_IS_X11_GL_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_X11_GL_CONFIG)) +#define GDK_X11_GL_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_X11_GL_CONFIG, GdkX11GLConfigClass)) + +#ifdef INSIDE_GDK_GL_X11 +typedef struct _GdkX11GLConfig GdkX11GLConfig; +#else +typedef GdkGLConfig GdkX11GLConfig; +#endif +typedef struct _GdkX11GLConfigClass GdkX11GLConfigClass; + +GType gdk_x11_gl_config_get_type (void); + +GdkGLConfig *gdk_x11_gl_config_new_for_display (GdkDisplay *display, + const int *attrib_list, + gsize n_attribs); + +GdkGLConfig *gdk_x11_gl_config_new_for_screen (GdkScreen *screen, + const int *attrib_list, + gsize n_attribs); + +#ifndef GDK_MULTIHEAD_SAFE +GdkGLConfig *gdk_x11_gl_config_new_from_visualid (VisualID xvisualid); +#endif /* GDK_MULTIHEAD_SAFE */ + +GdkGLConfig *gdk_x11_gl_config_new_from_visualid_for_screen (GdkScreen *screen, + VisualID xvisualid); + +Display *gdk_x11_gl_config_get_xdisplay (GdkGLConfig *glconfig); +int gdk_x11_gl_config_get_screen_number (GdkGLConfig *glconfig); +XVisualInfo *gdk_x11_gl_config_get_xvinfo (GdkGLConfig *glconfig); + +#ifdef INSIDE_GDK_GL_X11 + +#define GDK_GL_CONFIG_XDISPLAY(glconfig) (GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->xdisplay) +#define GDK_GL_CONFIG_SCREEN_XNUMBER(glconfig) (GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->screen_num) +#define GDK_GL_CONFIG_XVINFO(glconfig) (GDK_GL_CONFIG_IMPL_X11 (glconfig->impl)->xvinfo) + +#else + +#define GDK_GL_CONFIG_XDISPLAY(glconfig) (gdk_x11_gl_config_get_xdisplay (glconfig)) +#define GDK_GL_CONFIG_SCREEN_XNUMBER(glconfig) (gdk_x11_gl_config_get_screen_number (glconfig)) +#define GDK_GL_CONFIG_XVINFO(glconfig) (gdk_x11_gl_config_get_xvinfo (glconfig)) + +#endif + +G_END_DECLS + +#endif /* __GDK_X11_GL_CONFIG_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glcontext.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glcontext.c new file mode 100644 index 00000000..5cca77d1 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glcontext.c @@ -0,0 +1,115 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <gdk/gdkgldebug.h> +#include <gdk/x11/gdkglx.h> + +#include "gdkglcontext-x11.h" + +struct _GdkX11GLContext +{ + GdkGLContext parent; +}; + +struct _GdkX11GLContextClass +{ + GdkGLContextClass parent_class; +}; + +G_DEFINE_TYPE (GdkX11GLContext, gdk_x11_gl_context, GDK_TYPE_GL_CONTEXT); + +static void +gdk_x11_gl_context_init (GdkX11GLContext *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_x11_gl_context_finalize (GObject *object) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + G_OBJECT_CLASS (gdk_x11_gl_context_parent_class)->finalize (object); +} + +static void +gdk_x11_gl_context_class_init (GdkX11GLContextClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + object_class->finalize = gdk_x11_gl_context_finalize; +} + +/** + * gdk_x11_gl_context_foreign_new: + * @glconfig: #GdkGLConfig that represents the visual the GLXContext uses. + * @share_list: the #GdkGLContext which shares display lists with the + * GLXContext, or NULL. + * @glxcontext: exsisting GLXContext. + * + * Creates #GdkGLContext from existing GLXContext. + * + * Return value: the newly-created #GdkGLContext wrapper. + **/ +GdkGLContext * +gdk_x11_gl_context_foreign_new (GdkGLConfig *glconfig, + GdkGLContext *share_list, + GLXContext glxcontext) +{ + GdkGLContext *glcontext; + GdkGLContextImpl *impl; + + GDK_GL_NOTE_FUNC (); + + glcontext = g_object_new(GDK_TYPE_GL_CONTEXT_IMPL_X11, NULL); + + g_return_val_if_fail(glcontext != NULL, NULL); + + impl = _gdk_x11_gl_context_impl_new_from_glxcontext(glcontext, + glconfig, + share_list, + glxcontext); + if (impl == NULL) + g_object_unref(glcontext); + + g_return_val_if_fail(impl != NULL, NULL); + + return glcontext; +} + +/** + * gdk_x11_gl_context_get_glxcontext: + * @glcontext: a #GdkGLContext. + * + * Gets GLXContext. + * + * Return value: the GLXContext. + **/ +GLXContext +gdk_x11_gl_context_get_glxcontext (GdkGLContext *glcontext) +{ + g_return_val_if_fail (GDK_IS_X11_GL_CONTEXT (glcontext), NULL); + + return GDK_GL_CONTEXT_IMPL_X11_CLASS (glcontext)->get_glxcontext(glcontext); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glcontext.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glcontext.h new file mode 100644 index 00000000..88c857c7 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glcontext.h @@ -0,0 +1,65 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGLX_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkglx.h> can be included directly." +#endif + +#ifndef __GDK_X11_GL_CONTEXT_H__ +#define __GDK_X11_GL_CONTEXT_H__ + +#include <gdk/gdkx.h> +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +#define GDK_TYPE_X11_GL_CONTEXT (gdk_x11_gl_context_get_type ()) +#define GDK_X11_GL_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_X11_GL_CONTEXT, GdkX11GLContext)) +#define GDK_X11_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_X11_GL_CONTEXT, GdkX11GLContextClass)) +#define GDK_IS_X11_GL_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_X11_GL_CONTEXT)) +#define GDK_IS_X11_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_X11_GL_CONTEXT)) +#define GDK_X11_GL_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_X11_GL_CONTEXT, GdkX11GLContextClass)) + +#ifdef INSIDE_GDK_GL_X11 +typedef struct _GdkX11GLContext GdkX11GLContext; +#else +typedef GdkGLContext GdkX11GLContext; +#endif +typedef struct _GdkX11GLContextClass GdkX11GLContextClass; + +GType gdk_x11_gl_context_get_type (void); + +GdkGLContext *gdk_x11_gl_context_foreign_new (GdkGLConfig *glconfig, + GdkGLContext *share_list, + GLXContext glxcontext); + +GLXContext gdk_x11_gl_context_get_glxcontext (GdkGLContext *glcontext); + +#ifdef INSIDE_GDK_GL_X11 + +#define GDK_GL_CONTEXT_GLXCONTEXT(glcontext) (GDK_GL_CONTEXT_IMPL_X11 (glcontext->impl)->glxcontext) + +#else + +#define GDK_GL_CONTEXT_GLXCONTEXT(glcontext) (gdk_x11_gl_context_get_glxcontext (glcontext)) + +#endif + +G_END_DECLS + +#endif /* __GDK_GL_GL_CONFIG_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glquery.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glquery.h new file mode 100644 index 00000000..130f0a68 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glquery.h @@ -0,0 +1,34 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGLX_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkglx.h> can be included directly." +#endif + +#ifndef __GDK_X11_GL_QUERY_H__ +#define __GDK_X11_GL_QUERY_H__ + +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +gboolean gdk_x11_gl_query_glx_extension (GdkGLConfig *glconfig, + const char *extension); +G_END_DECLS + +#endif /* __GDK_X11_GL_QUERY_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glwindow.c b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glwindow.c new file mode 100644 index 00000000..f4cc8ff0 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glwindow.c @@ -0,0 +1,80 @@ +/* GdkGLExt - OpenGL Extension to GDK + * Copyright (C) 2012 Thomas Zimmermann + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <gdk/gdkgldebug.h> +#include <gdk/x11/gdkglx.h> + +#include "gdkglwindow-x11.h" + +struct _GdkX11GLWindow +{ + GdkGLWindow parent; +}; + +struct _GdkX11GLWindowClass +{ + GdkGLWindowClass parent_class; +}; + +G_DEFINE_TYPE (GdkX11GLWindow, + gdk_x11_gl_window, + GDK_TYPE_GL_WINDOW) + +static void +gdk_x11_gl_window_init (GdkX11GLWindow *self) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); +} + +static void +gdk_x11_gl_window_finalize (GObject *object) +{ + GDK_GL_NOTE_FUNC_PRIVATE (); + + G_OBJECT_CLASS (gdk_x11_gl_window_parent_class)->finalize (object); +} + +static void +gdk_x11_gl_window_class_init (GdkX11GLWindowClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + GDK_GL_NOTE_FUNC_PRIVATE (); + + object_class->finalize = gdk_x11_gl_window_finalize; +} + +/** + * gdk_x11_gl_window_get_glxwindow: + * @glwindow: a #GdkGLWindow. + * + * Gets X Window. + * + * Return value: the Window. + **/ +Window +gdk_x11_gl_window_get_glxwindow (GdkGLWindow *glwindow) +{ + g_return_val_if_fail (GDK_IS_X11_GL_WINDOW (glwindow), None); + + return GDK_GL_WINDOW_IMPL_X11_CLASS (glwindow->impl)->get_glxwindow(glwindow); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glwindow.h b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glwindow.h new file mode 100644 index 00000000..458a0f76 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gdk/x11/gdkx11glwindow.h @@ -0,0 +1,62 @@ +/* GdkGLExt - OpenGL Extension to GDK + * 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. + */ + +#if !defined (__GDKGLX_H_INSIDE__) && !defined (GDK_GL_COMPILATION) +#error "Only <gdk/gdkglx.h> can be included directly." +#endif + +#ifndef __GDK_X11_GL_WINDOW_H__ +#define __GDK_X11_GL_WINDOW_H__ + +#include <gdk/gdkx.h> + +#include <gdk/gdkgl.h> + +G_BEGIN_DECLS + +#define GDK_TYPE_X11_GL_WINDOW (gdk_x11_gl_window_get_type ()) +#define GDK_X11_GL_WINDOW(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_X11_GL_WINDOW, GdkX11GLWindow)) +#define GDK_X11_GL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_X11_GL_WINDOW, GdkX11GLWindowClass)) +#define GDK_IS_X11_GL_WINDOW(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_X11_GL_WINDOW)) +#define GDK_IS_X11_GL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_X11_GL_WINDOW)) +#define GDK_X11_GL_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_X11_GL_WINDOW, GdkX11GLWindowClass)) + +#ifdef INSIDE_GDK_GL_X11 +typedef struct _GdkX11GLWindow GdkX11GLWindow; +#else +typedef GdkGLWindow GdkX11GLWindow; +#endif +typedef struct _GdkX11GLWindowClass GdkX11GLWindowClass; + +GType gdk_x11_gl_window_get_type (void); + +Window gdk_x11_gl_window_get_glxwindow (GdkGLWindow *glwindow); + +#ifdef INSIDE_GDK_GL_X11 + +#define GDK_GL_WINDOW_GLXWINDOW(glwindow) (GDK_GL_WINDOW_IMPL_X11 (glwindow->impl)->glxwindow) + +#else + +#define GDK_GL_WINDOW_GLXWINDOW(glwindow) (gdk_x11_gl_window_get_glxwindow (glwindow)) + +#endif + +G_END_DECLS + +#endif /* __GDK_X11_GL_WINDOW_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkgl.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkgl.h new file mode 100644 index 00000000..331327eb --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkgl.h @@ -0,0 +1,33 @@ +/* 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> + +#define __GTKGL_H_INSIDE__ + +#include "gtkgldefs.h" +#include "gtkglversion.h" +#include "gtkglinit.h" +#include "gtkglwidget.h" + +#undef __GTKGL_H_INSIDE__ + +#endif /* __GTK_GL_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkgldebug.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkgldebug.h new file mode 100644 index 00000000..9d23f72b --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkgldebug.h @@ -0,0 +1,67 @@ +/* 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__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkgldefs.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkgldefs.h new file mode 100644 index 00000000..c2b3e57a --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkgldefs.h @@ -0,0 +1,42 @@ +/* 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. + */ + +#if !defined (__GTKGL_H_INSIDE__) && !defined (GTK_GL_COMPILATION) +#error "Only <gtk/gtkgl.h> can be included directly." +#endif + +#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__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglinit.c b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglinit.c new file mode 100644 index 00000000..ba658094 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglinit.c @@ -0,0 +1,230 @@ +/* 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <string.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(). + **/ +static void +gtk_gl_parse_args (int *argc, + char ***argv) +{ + const gchar *env_string; + + if (gtk_gl_initialized) + return; + + /* + * 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). This is achieved by setting the window's + * visual. + */ + env_string = g_getenv ("GTK_GL_INSTALL_VISUAL"); + if (env_string != NULL) + { + _gtk_gl_widget_install_toplevel_visual = !!g_ascii_strtoll (env_string, NULL, 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-visual", (*argv)[i]) == 0) + { + _gtk_gl_widget_install_toplevel_visual = 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; +} + +/** + * 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. */ + gtk_gl_parse_args (argc, argv); + + 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)) + g_error ("GdkGLExt library initialization fails."); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglinit.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglinit.h new file mode 100644 index 00000000..376ef6b9 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglinit.h @@ -0,0 +1,44 @@ +/* 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. + */ + +#if !defined (__GTKGL_H_INSIDE__) && !defined (GTK_GL_COMPILATION) +#error "Only <gtk/gtkgl.h> can be included directly." +#endif + +#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_init_check (int *argc, + char ***argv); + +void gtk_gl_init (int *argc, + char ***argv); + +G_END_DECLS + +#endif /* __GTK_GL_INIT_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglprivate.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglprivate.h new file mode 100644 index 00000000..9fde29bb --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglprivate.h @@ -0,0 +1,32 @@ +/* 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 visual to top-level window. */ +extern gboolean _gtk_gl_widget_install_toplevel_visual; + +G_END_DECLS + +#endif /* __GTK_GL_PRIVATE_H__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglversion.c b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglversion.c new file mode 100644 index 00000000..8b5c5990 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglversion.c @@ -0,0 +1,29 @@ +/* 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#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; diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglversion.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglversion.h new file mode 100644 index 00000000..2dd74d81 --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglversion.h @@ -0,0 +1,62 @@ +/* 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. + */ + +#if !defined (__GTKGL_H_INSIDE__) && !defined (GTK_GL_COMPILATION) +#error "Only <gtk/gtkgl.h> can be included directly." +#endif + +#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 (2) +#define GTKGLEXT_MINOR_VERSION (99) +#define GTKGLEXT_MICRO_VERSION (0) +#define GTKGLEXT_INTERFACE_AGE (0) +#define GTKGLEXT_BINARY_AGE (9900) + +/* + * 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__ */ diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglwidget.c b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglwidget.c new file mode 100644 index 00000000..4bb372bb --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglwidget.c @@ -0,0 +1,550 @@ +/* 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "gtkglprivate.h" +#include "gtkglwidget.h" + +#include <GL/gl.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_visual = 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, + GObject *old_parent, + GdkVisual *visual); +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) +{ + GdkWindow *window; + GdkGLWindow *glwindow; + + GTK_GL_NOTE_FUNC_PRIVATE (); + + /* + * Set OpenGL-capability to widget->window, then connect some signal + * handlers. + */ + + window = gtk_widget_get_window (widget); + if (!gdk_window_is_gl_capable (window)) + { + glwindow = gdk_window_set_gl_capability (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_get_realized (widget) && private->is_realized) + { + gldrawable = gdk_window_get_gl_drawable (gtk_widget_get_window (widget)); + 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) + { + g_object_unref (private->glcontext); + private->glcontext = NULL; + } + + /* + * Remove OpenGL-capability from widget->window. + */ + + if (gtk_widget_get_realized (widget)) + gdk_window_unset_gl_capability (gtk_widget_get_window (widget)); + + private->is_realized = FALSE; +} + +static void +gtk_gl_widget_parent_set (GtkWidget *widget, + GObject *old_parent, + GdkVisual *visual) +{ + GtkWidget *toplevel; + + GTK_GL_NOTE_FUNC_PRIVATE (); + + /* + * Try to install visual to the top-level window. + */ + + toplevel = gtk_widget_get_toplevel (widget); + if (gtk_widget_is_toplevel (toplevel) && !gtk_widget_get_realized (toplevel)) + { + GTK_GL_NOTE (MISC, + g_message (" - Install visual to the top-level window.")); + + gtk_widget_set_visual (toplevel, visual); + } +} + +static void +gtk_gl_widget_style_set (GtkWidget *widget, + GtkStyle *previous_style, + gpointer user_data) +{ + GdkWindow *window; + + GTK_GL_NOTE_FUNC_PRIVATE (); + + /* + * Set a background of "None" on window to avoid AIX X server crash. + */ + + if (gtk_widget_get_realized (widget)) + { + window = gtk_widget_get_window (widget); + + GTK_GL_NOTE (MISC, + g_message (" - window->bg_pixmap = %p", + (void*)gdk_window_get_background_pattern(window))); + + gdk_window_set_background_pattern (window, NULL); + + GTK_GL_NOTE (MISC, + g_message (" - window->bg_pixmap = %p", + (void*)gdk_window_get_background_pattern(window))); + } +} + +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: (allow-none): 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. + * + * 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) +{ + GdkVisual *visual; + GLWidgetPrivate *private; + + GTK_GL_NOTE_FUNC (); + + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + g_return_val_if_fail (gtk_widget_get_has_window (widget), FALSE); + g_return_val_if_fail (!gtk_widget_get_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. + */ + + visual = gdk_gl_config_get_visual (glconfig); + + gtk_widget_set_visual (widget, visual); + + /* Install visual to the top-level window. */ + if (_gtk_gl_widget_install_toplevel_visual) + { + /* + * 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). This is achieved by setting the window's + * visual. + */ + + /* 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), + visual); + + /* If given widget has the top-level window, visual is set here. */ + gtk_gl_widget_parent_set (widget, NULL, visual); + } + + /* + * 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: (allow-none): 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. + * + * 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_get_realized (widget), NULL); + + gldrawable = gdk_window_get_gl_drawable (gtk_widget_get_window (widget)); + 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_get_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_get_realized (widget), NULL); + + return gdk_window_get_gl_window (gtk_widget_get_window (widget)); +} + +gboolean +gtk_widget_begin_gl(GtkWidget *widget) +{ + GdkGLContext *glcontext; + GdkGLWindow *glwindow; + + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + glcontext = gtk_widget_get_gl_context (widget); + glwindow = gtk_widget_get_gl_window (widget); + + return gdk_gl_context_make_current(glcontext, GDK_GL_DRAWABLE (glwindow), GDK_GL_DRAWABLE (glwindow)); +} + +void +gtk_widget_end_gl(GtkWidget *widget, gboolean do_swap) +{ + GdkGLDrawable *gldrawable; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + + gldrawable = GDK_GL_DRAWABLE (gtk_widget_get_gl_window (widget)); + + if (do_swap) + { + if (gdk_gl_drawable_is_double_buffered (gldrawable)) + gdk_gl_drawable_swap_buffers (gldrawable); + else + glFlush (); + } + + gdk_gl_context_release_current(); +} diff --git a/plugins/gtkui/gtkglext-gtk3/gtk/gtkglwidget.h b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglwidget.h new file mode 100644 index 00000000..b23b433d --- /dev/null +++ b/plugins/gtkui/gtkglext-gtk3/gtk/gtkglwidget.h @@ -0,0 +1,61 @@ +/* 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. + */ + +#if !defined (__GTKGL_H_INSIDE__) && !defined (GTK_GL_COMPILATION) +#error "Only <gtk/gtkgl.h> can be included directly." +#endif + +#ifndef __GTK_GL_WIDGET_H__ +#define __GTK_GL_WIDGET_H__ + +#include <gdk/gdk.h> +#include <gdk/gdkgl.h> +#include <gtk/gtk.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)) + +gboolean gtk_widget_begin_gl(GtkWidget *widget); + +void gtk_widget_end_gl(GtkWidget *widget, gboolean do_swap); + +G_END_DECLS + +#endif /* __GTK_GL_WIDGET_H__ */ diff --git a/plugins/gtkui/support.h b/plugins/gtkui/support.h index 2161fb55..6f8cbd6e 100644 --- a/plugins/gtkui/support.h +++ b/plugins/gtkui/support.h @@ -136,7 +136,9 @@ void gtk_widget_get_allocation (GtkWidget *widget, #define gtk_widget_set_can_focus(widget, canfocus) {if (canfocus) GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); else GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);} -#define gtk_widget_get_can_focus(widget) (GTK_WIDGET_CAN_FOCUS (widget)); +#define gtk_widget_get_can_focus(widget) (GTK_WIDGET_CAN_FOCUS (widget)) + +#define gtk_widget_has_focus(widget) (GTK_WIDGET_HAS_FOCUS (widget)) #define gtk_widget_set_can_default(widget, candefault) {if (candefault) GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT); else GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_DEFAULT);} diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c index 37e85b50..e85fb61d 100644 --- a/plugins/gtkui/widgets.c +++ b/plugins/gtkui/widgets.c @@ -2335,7 +2335,7 @@ w_spectrum_create (void) { #if !GTK_CHECK_VERSION(3,0,0) g_signal_connect_after ((gpointer) w->drawarea, "expose_event", G_CALLBACK (spectrum_expose_event), w); #else - g_signal_connect_after ((gpointer) w->drawarea, "draw", G_CALLBACK (spectrum_draw), w); + g_signal_connect_after ((gpointer) w->drawarea, "draw", G_CALLBACK (w_spectrum_draw_cb), w); #endif g_signal_connect_after (G_OBJECT (w->drawarea), "realize", G_CALLBACK (spectrum_realize), w); w_override_signals (w->base.widget, w); |