1 /* GdkGLExt - OpenGL Extension to GDK
2 * Copyright (C) 2002-2004 Naofumi Yasufuku
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 */
18
19 #include <gdk/gdkdrawable.h>
20
21 #include "gdkglprivate.h"
22 #include "gdkglcontext.h"
23 #include "gdkgldrawable.h"
24
25 GType
gdk_gl_drawable_get_type(void)26 gdk_gl_drawable_get_type (void)
27 {
28 static GType type = 0;
29
30 if (!type)
31 {
32 static const GTypeInfo type_info = {
33 sizeof (GdkGLDrawableClass),
34 (GBaseInitFunc) NULL,
35 (GBaseFinalizeFunc) NULL
36 };
37
38 type = g_type_register_static (G_TYPE_INTERFACE,
39 "GdkGLDrawable",
40 &type_info, 0);
41 }
42
43 return type;
44 }
45
46 /**
47 * gdk_gl_drawable_make_current:
48 * @gldrawable: a #GdkGLDrawable.
49 * @glcontext: a #GdkGLContext.
50 *
51 * Attach an OpenGL rendering context to a @gldrawable.
52 *
53 * Return value: TRUE if it is successful, FALSE otherwise.
54 **/
55 gboolean
gdk_gl_drawable_make_current(GdkGLDrawable * gldrawable,GdkGLContext * glcontext)56 gdk_gl_drawable_make_current (GdkGLDrawable *gldrawable,
57 GdkGLContext *glcontext)
58 {
59 g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), FALSE);
60
61 return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->make_context_current (gldrawable,
62 gldrawable,
63 glcontext);
64 }
65
66 /**
67 * gdk_gl_drawable_is_double_buffered:
68 * @gldrawable: a #GdkGLDrawable.
69 *
70 * Returns whether the @gldrawable supports the double-buffered visual.
71 *
72 * Return value: TRUE if the double-buffered visual is supported,
73 * FALSE otherwise.
74 **/
75 gboolean
gdk_gl_drawable_is_double_buffered(GdkGLDrawable * gldrawable)76 gdk_gl_drawable_is_double_buffered (GdkGLDrawable *gldrawable)
77 {
78 g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), FALSE);
79
80 return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->is_double_buffered (gldrawable);
81 }
82
83 /**
84 * gdk_gl_drawable_swap_buffers:
85 * @gldrawable: a #GdkGLDrawable.
86 *
87 * Exchange front and back buffers.
88 *
89 **/
90 void
gdk_gl_drawable_swap_buffers(GdkGLDrawable * gldrawable)91 gdk_gl_drawable_swap_buffers (GdkGLDrawable *gldrawable)
92 {
93 g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable));
94
95 GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->swap_buffers (gldrawable);
96 }
97
98 /**
99 * gdk_gl_drawable_wait_gl:
100 * @gldrawable: a #GdkGLDrawable.
101 *
102 * Complete OpenGL execution prior to subsequent GDK drawing calls.
103 *
104 **/
105 void
gdk_gl_drawable_wait_gl(GdkGLDrawable * gldrawable)106 gdk_gl_drawable_wait_gl (GdkGLDrawable *gldrawable)
107 {
108 g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable));
109
110 GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->wait_gl (gldrawable);
111 }
112
113 /**
114 * gdk_gl_drawable_wait_gdk:
115 * @gldrawable: a #GdkGLDrawable.
116 *
117 * Complete GDK drawing execution prior to subsequent OpenGL calls.
118 *
119 **/
120 void
gdk_gl_drawable_wait_gdk(GdkGLDrawable * gldrawable)121 gdk_gl_drawable_wait_gdk (GdkGLDrawable *gldrawable)
122 {
123 g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable));
124
125 GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->wait_gdk (gldrawable);
126 }
127
128 /**
129 * gdk_gl_drawable_gl_begin:
130 * @gldrawable: a #GdkGLDrawable.
131 * @glcontext: a #GdkGLContext.
132 *
133 * Delimits the begining of the OpenGL execution.
134 *
135 * Return value: TRUE if it is successful, FALSE otherwise.
136 **/
137 gboolean
gdk_gl_drawable_gl_begin(GdkGLDrawable * gldrawable,GdkGLContext * glcontext)138 gdk_gl_drawable_gl_begin (GdkGLDrawable *gldrawable,
139 GdkGLContext *glcontext)
140 {
141 g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), FALSE);
142
143 return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->gl_begin (gldrawable,
144 gldrawable,
145 glcontext);
146 }
147
148 /**
149 * gdk_gl_drawable_gl_end:
150 * @gldrawable: a #GdkGLDrawable.
151 *
152 * Delimits the end of the OpenGL execution.
153 *
154 **/
155 void
gdk_gl_drawable_gl_end(GdkGLDrawable * gldrawable)156 gdk_gl_drawable_gl_end (GdkGLDrawable *gldrawable)
157 {
158 g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable));
159
160 GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->gl_end (gldrawable);
161 }
162
163 /**
164 * gdk_gl_drawable_get_gl_config:
165 * @gldrawable: a #GdkGLDrawable.
166 *
167 * Gets #GdkGLConfig with which the @gldrawable is configured.
168 *
169 * Return value: the #GdkGLConfig.
170 **/
171 GdkGLConfig *
gdk_gl_drawable_get_gl_config(GdkGLDrawable * gldrawable)172 gdk_gl_drawable_get_gl_config (GdkGLDrawable *gldrawable)
173 {
174 g_return_val_if_fail (GDK_IS_GL_DRAWABLE (gldrawable), NULL);
175
176 return GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->get_gl_config (gldrawable);
177 }
178
179 /**
180 * gdk_gl_drawable_get_size:
181 * @gldrawable: a #GdkGLDrawable.
182 * @width: location to store drawable's width, or NULL.
183 * @height: location to store drawable's height, or NULL.
184 *
185 * Fills *width and *height with the size of GL drawable.
186 * width or height can be NULL if you only want the other one.
187 *
188 **/
189 void
gdk_gl_drawable_get_size(GdkGLDrawable * gldrawable,gint * width,gint * height)190 gdk_gl_drawable_get_size (GdkGLDrawable *gldrawable,
191 gint *width,
192 gint *height)
193 {
194 g_return_if_fail (GDK_IS_GL_DRAWABLE (gldrawable));
195
196 GDK_GL_DRAWABLE_GET_CLASS (gldrawable)->get_size (gldrawable, width, height);
197 }
198
199 /**
200 * gdk_gl_drawable_get_current:
201 *
202 * Returns the current #GdkGLDrawable.
203 *
204 * Return value: the current #GdkGLDrawable or NULL if there is no current drawable.
205 **/
206 GdkGLDrawable *
gdk_gl_drawable_get_current(void)207 gdk_gl_drawable_get_current (void)
208 {
209 GdkGLContext *glcontext;
210
211 GDK_GL_NOTE_FUNC ();
212
213 glcontext = gdk_gl_context_get_current ();
214 if (glcontext == NULL)
215 return NULL;
216
217 return gdk_gl_context_get_gl_drawable (glcontext);
218 }
219