1 // gtk_glue_gtkglext.cpp: Gnome ToolKit glue of some sort, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20
21 #ifdef HAVE_CONFIG_H
22 #include "gnashconfig.h"
23 #endif
24
25 #include "gtk_glue_gtkglext.h"
26 #include "log.h"
27 #include "opengl/Renderer_ogl.h"
28
29 using namespace std;
30
31 namespace gnash
32 {
33
GtkGlExtGlue()34 GtkGlExtGlue::GtkGlExtGlue()
35 {
36 GNASH_REPORT_FUNCTION;
37 }
38
~GtkGlExtGlue()39 GtkGlExtGlue::~GtkGlExtGlue()
40 {
41 // GNASH_REPORT_FUNCTION;
42 if (_glconfig) {
43 g_object_unref (G_OBJECT (_glconfig));
44 _glconfig = nullptr;
45 }
46
47 GdkGLContext *glcontext = gtk_widget_get_gl_context (_drawing_area);
48 if (glcontext) {
49 g_object_unref (G_OBJECT (glcontext));
50 glcontext = nullptr;
51 }
52 }
53
54 bool
init(int argc,char ** argv[])55 GtkGlExtGlue::init(int argc, char** argv[])
56 {
57 // GNASH_REPORT_FUNCTION;
58
59 gtk_gl_init (&argc, argv);
60
61 gint major, minor;
62 gdk_gl_query_version (&major, &minor);
63 log_debug ("OpenGL extension version - %d.%d", (int)major, (int)minor);
64
65 GdkGLConfigMode glcmode = (GdkGLConfigMode)(GDK_GL_MODE_RGB |
66 GDK_GL_MODE_STENCIL |
67 GDK_GL_MODE_DOUBLE |
68 GDK_GL_MODE_ACCUM);
69 _glconfig = gdk_gl_config_new_by_mode (glcmode);
70
71 if (!_glconfig) {
72 log_error (_("Cannot find the double-buffered visual.\n"
73 "Trying single-buffered visual."));
74
75 glcmode = (GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH);
76 _glconfig = gdk_gl_config_new_by_mode (glcmode);
77 if (!_glconfig) {
78 log_error (_("No appropriate OpenGL-capable visual found."));
79 gtk_main_quit(); // XXX
80 } else {
81 log_debug ("Got single-buffered visual.");
82 }
83 } else {
84 log_debug ("Got double-buffered visual.");
85 }
86
87 return true;
88 }
89
90
91 void
prepDrawingArea(GtkWidget * drawing_area)92 GtkGlExtGlue::prepDrawingArea(GtkWidget *drawing_area)
93 {
94 // GNASH_REPORT_FUNCTION;
95 _drawing_area = drawing_area;
96 gtk_widget_set_gl_capability(_drawing_area, _glconfig,
97 nullptr, TRUE, GDK_GL_RGBA_TYPE);
98 }
99
100 Renderer*
createRenderHandler()101 GtkGlExtGlue::createRenderHandler()
102 {
103 // GNASH_REPORT_FUNCTION;
104 GdkGLContext *glcontext = gtk_widget_get_gl_context (_drawing_area);
105 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (_drawing_area);
106
107 // Attach our OpenGL context to the drawing_area.
108 gdk_gl_drawable_make_current(gldrawable, glcontext);
109
110 Renderer* renderer = renderer::opengl::create_handler(true);
111
112 return renderer;
113 }
114
115 void
render()116 GtkGlExtGlue::render()
117 {
118 // GNASH_REPORT_FUNCTION;
119 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (_drawing_area);
120 if (gdk_gl_drawable_is_double_buffered (gldrawable)) {
121 gdk_gl_drawable_swap_buffers (gldrawable);
122 } else {
123 glFlush();
124 }
125 }
126
127 void
configure(GtkWidget * const widget,GdkEventConfigure * const event)128 GtkGlExtGlue::configure(GtkWidget *const widget, GdkEventConfigure *const event)
129 {
130 GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
131 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
132 if (gdk_gl_drawable_make_current(gldrawable, glcontext)) {
133 glViewport (event->x, event->y, event->width, event->height);
134 }
135 }
136
137
138 } // namespace gnash
139
140 // local Variables:
141 // mode: C++
142 // indent-tabs-mode: nil
143 // End:
144