1/* GDK - The GIMP Drawing Kit
2 *
3 * gdkglcontextprivate.h: GL context abstraction
4 *
5 * Copyright © 2014 Emmanuele Bassi
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __GDK_GL_CONTEXT_PRIVATE_H__
22#define __GDK_GL_CONTEXT_PRIVATE_H__
23
24#include "gdkglcontext.h"
25#include "gdkdrawcontextprivate.h"
26
27G_BEGIN_DECLS
28
29/* Version requirements for EGL contexts.
30 *
31 * If you add support for EGL to your backend, please require this.
32 */
33#define GDK_EGL_MIN_VERSION_MAJOR (1)
34#define GDK_EGL_MIN_VERSION_MINOR (4)
35
36typedef enum {
37 GDK_GL_NONE = 0,
38 GDK_GL_EGL,
39 GDK_GL_GLX,
40 GDK_GL_WGL,
41 GDK_GL_CGL
42} GdkGLBackend;
43
44#define GDK_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT, GdkGLContextClass))
45#define GDK_IS_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT))
46#define GDK_GL_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT, GdkGLContextClass))
47
48typedef struct _GdkGLContextClass GdkGLContextClass;
49
50struct _GdkGLContext
51{
52 GdkDrawContext parent_instance;
53
54 /* We store the old drawn areas to support buffer-age optimizations */
55 cairo_region_t *old_updated_area[2];
56};
57
58struct _GdkGLContextClass
59{
60 GdkDrawContextClass parent_class;
61
62 GdkGLBackend backend_type;
63
64 GdkGLAPI (* realize) (GdkGLContext *context,
65 GError **error);
66
67 gboolean (* make_current) (GdkGLContext *context,
68 gboolean surfaceless);
69 gboolean (* clear_current) (GdkGLContext *context);
70 cairo_region_t * (* get_damage) (GdkGLContext *context);
71
72 gboolean (* is_shared) (GdkGLContext *self,
73 GdkGLContext *other);
74
75 guint (* get_default_framebuffer) (GdkGLContext *self);
76};
77
78typedef struct {
79 guint program;
80 guint position_location;
81 guint uv_location;
82 guint map_location;
83 guint flip_location;
84} GdkGLContextProgram;
85
86typedef struct {
87 guint vertex_array_object;
88 guint tmp_framebuffer;
89 guint tmp_vertex_buffer;
90
91 GdkGLContextProgram texture_2d_quad_program;
92 GdkGLContextProgram texture_rect_quad_program;
93
94 GdkGLContextProgram *current_program;
95
96 guint is_legacy : 1;
97 guint use_es : 1;
98} GdkGLContextPaintData;
99
100gboolean gdk_gl_backend_can_be_used (GdkGLBackend backend_type,
101 GError **error);
102void gdk_gl_backend_use (GdkGLBackend backend_type);
103
104void gdk_gl_context_clear_current_if_surface (GdkSurface *surface);
105
106GdkGLContext * gdk_gl_context_new (GdkDisplay *display,
107 GdkSurface *surface);
108
109gboolean gdk_gl_context_is_api_allowed (GdkGLContext *self,
110 GdkGLAPI api,
111 GError **error);
112void gdk_gl_context_set_is_legacy (GdkGLContext *context,
113 gboolean is_legacy);
114
115gboolean gdk_gl_context_check_version (GdkGLContext *context,
116 int required_gl_major,
117 int required_gl_minor,
118 int required_gles_major,
119 int required_gles_minor);
120
121gboolean gdk_gl_context_has_unpack_subimage (GdkGLContext *context);
122void gdk_gl_context_push_debug_group (GdkGLContext *context,
123 const char *message);
124void gdk_gl_context_push_debug_group_printf (GdkGLContext *context,
125 const char *format,
126 ...) G_GNUC_PRINTF (2, 3);
127void gdk_gl_context_pop_debug_group (GdkGLContext *context);
128void gdk_gl_context_label_object (GdkGLContext *context,
129 guint identifier,
130 guint name,
131 const char *label);
132void gdk_gl_context_label_object_printf (GdkGLContext *context,
133 guint identifier,
134 guint name,
135 const char *format,
136 ...) G_GNUC_PRINTF (4, 5);
137
138gboolean gdk_gl_context_has_debug (GdkGLContext *self) G_GNUC_PURE;
139
140gboolean gdk_gl_context_use_es_bgra (GdkGLContext *context);
141
142gboolean gdk_gl_context_has_vertex_half_float (GdkGLContext *self) G_GNUC_PURE;
143
144G_END_DECLS
145
146#endif /* __GDK_GL_CONTEXT_PRIVATE_H__ */
147

source code of gtk/gdk/gdkglcontextprivate.h