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 #include "gdkmemorytexture.h"
27 
28 G_BEGIN_DECLS
29 
30 /* Version requirements for EGL contexts.
31  *
32  * If you add support for EGL to your backend, please require this.
33  */
34 #define GDK_EGL_MIN_VERSION_MAJOR (1)
35 #define GDK_EGL_MIN_VERSION_MINOR (4)
36 
37 typedef enum {
38   GDK_GL_NONE = 0,
39   GDK_GL_EGL,
40   GDK_GL_GLX,
41   GDK_GL_WGL,
42   GDK_GL_CGL
43 } GdkGLBackend;
44 
45 #define GDK_GL_CONTEXT_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT, GdkGLContextClass))
46 #define GDK_IS_GL_CONTEXT_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT))
47 #define GDK_GL_CONTEXT_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT, GdkGLContextClass))
48 
49 typedef struct _GdkGLContextClass       GdkGLContextClass;
50 
51 struct _GdkGLContext
52 {
53   GdkDrawContext parent_instance;
54 
55   /* We store the old drawn areas to support buffer-age optimizations */
56   cairo_region_t *old_updated_area[2];
57 };
58 
59 struct _GdkGLContextClass
60 {
61   GdkDrawContextClass parent_class;
62 
63   GdkGLBackend        backend_type;
64 
65   gboolean              (* realize)                             (GdkGLContext          *context,
66                                                                  GError               **error);
67 
68   gboolean              (* make_current)                        (GdkGLContext          *context,
69                                                                  gboolean               surfaceless);
70   gboolean              (* clear_current)                       (GdkGLContext          *context);
71   cairo_region_t *      (* get_damage)                          (GdkGLContext          *context);
72 
73   gboolean              (* is_shared)                           (GdkGLContext          *self,
74                                                                  GdkGLContext          *other);
75 };
76 
77 typedef struct {
78   guint program;
79   guint position_location;
80   guint uv_location;
81   guint map_location;
82   guint flip_location;
83 } GdkGLContextProgram;
84 
85 typedef struct {
86   guint vertex_array_object;
87   guint tmp_framebuffer;
88   guint tmp_vertex_buffer;
89 
90   GdkGLContextProgram texture_2d_quad_program;
91   GdkGLContextProgram texture_rect_quad_program;
92 
93   GdkGLContextProgram *current_program;
94 
95   guint is_legacy : 1;
96   guint use_es : 1;
97 } GdkGLContextPaintData;
98 
99 gboolean                gdk_gl_backend_can_be_used              (GdkGLBackend     backend_type,
100                                                                  GError         **error);
101 void                    gdk_gl_backend_use                      (GdkGLBackend     backend_type);
102 
103 GdkGLContext *          gdk_gl_context_new_for_surface          (GdkSurface      *surface);
104 
105 void                    gdk_gl_context_set_is_legacy            (GdkGLContext    *context,
106                                                                  gboolean         is_legacy);
107 
108 void                    gdk_gl_context_upload_texture           (GdkGLContext    *context,
109                                                                  const guchar    *data,
110                                                                  int              width,
111                                                                  int              height,
112                                                                  int              stride,
113                                                                  GdkMemoryFormat  data_format,
114                                                                  guint            texture_target);
115 GdkGLContextPaintData * gdk_gl_context_get_paint_data           (GdkGLContext    *context);
116 gboolean                gdk_gl_context_use_texture_rectangle    (GdkGLContext    *context);
117 gboolean                gdk_gl_context_has_unpack_subimage      (GdkGLContext    *context);
118 void                    gdk_gl_context_push_debug_group         (GdkGLContext    *context,
119                                                                  const char      *message);
120 void                    gdk_gl_context_push_debug_group_printf  (GdkGLContext    *context,
121                                                                  const char      *format,
122                                                                  ...)  G_GNUC_PRINTF (2, 3);
123 void                    gdk_gl_context_pop_debug_group          (GdkGLContext    *context);
124 void                    gdk_gl_context_label_object             (GdkGLContext    *context,
125                                                                  guint            identifier,
126                                                                  guint            name,
127                                                                  const char      *label);
128 void                    gdk_gl_context_label_object_printf      (GdkGLContext    *context,
129                                                                  guint            identifier,
130                                                                  guint            name,
131                                                                  const char      *format,
132                                                                 ...)  G_GNUC_PRINTF (4, 5);
133 
134 gboolean                gdk_gl_context_has_debug                (GdkGLContext    *self) G_GNUC_PURE;
135 
136 gboolean                gdk_gl_context_use_es_bgra              (GdkGLContext    *context);
137 
138 typedef struct {
139   float x1, y1, x2, y2;
140   float u1, v1, u2, v2;
141 } GdkTexturedQuad;
142 
143 void                    gdk_gl_texture_quads                    (GdkGLContext    *context,
144                                                                  guint            texture_target,
145                                                                  int              n_quads,
146                                                                  GdkTexturedQuad *quads,
147                                                                  gboolean         flip_colors);
148 
149 
150 G_END_DECLS
151 
152 #endif /* __GDK_GL_CONTEXT_PRIVATE_H__ */
153