1 From e99770dcc31f0382cb699bbfbb8a30b21bcdb9a8 Mon Sep 17 00:00:00 2001
2 From: Neil Roberts <neil@linux.intel.com>
3 Date: Wed, 2 May 2012 13:08:01 +0100
4 Subject: [PATCH] Don't include any GL header from the public GL headers
6 This splits the GL header inclusion from cogl-defines.h into a
7 separate headear called cogl-gl-header.h which we will only include
8 internally. That way we don't leak GL declarations out of our public
9 headers. The texture functions that were using GLenum and GLuint in
10 the public header have now changed to just use unsigned int. Note
11 however that if an EGL winsys is enabled then it will still publicly
12 include an EGL header. This is a bit more awkward to fix because we
13 have public API which returns an EGLDisplay and we can't determine
16 There is also a conformance test which just verifies that no GL header
17 has been included while compiling. The test isn't added to
18 test-conform-main because it doesn't actually test anything at
21 Reviewed-by: Robert Bragg <robert@linux.intel.com>
23 (cherry picked from commit ef5680d3fda5df929dbd0b420c8f598ded58dfee)
27 cogl/cogl-context-private.h
28 cogl/cogl-sampler-cache-private.h
30 cogl/Makefile.am | 6 ++--
31 cogl/cogl-buffer-private.h | 1 +
32 cogl/cogl-context-private.h | 1 +
33 cogl/cogl-defines.h.in | 4 ---
34 cogl/cogl-gl-header.h.in | 39 +++++++++++++++++++++++++++++++++++++
35 cogl/cogl-internal.h | 1 +
36 cogl/cogl-shader-private.h | 1 +
37 cogl/cogl-texture.h | 16 +++++++-------
38 cogl/tesselator/tesselator.h | 1 +
40 tests/conform/Makefile.am | 1 +
41 tests/conform/test-no-gl-header.c | 17 ++++++++++++++++
42 12 files changed, 74 insertions(+), 15 deletions(-)
43 create mode 100644 cogl/cogl-gl-header.h.in
44 create mode 100644 tests/conform/test-no-gl-header.c
46 diff --git a/cogl/Makefile.am b/cogl/Makefile.am
47 index f6dbb0d..236963e 100644
48 --- a/cogl/Makefile.am
49 +++ b/cogl/Makefile.am
50 @@ -34,9 +34,9 @@ AM_CPPFLAGS = \
52 AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS)
54 -BUILT_SOURCES += cogl-defines.h
55 -DISTCLEANFILES += cogl-defines.h
56 -EXTRA_DIST += cogl-defines.h.in
57 +BUILT_SOURCES += cogl-defines.h cogl-gl-header.h
58 +DISTCLEANFILES += cogl-defines.h cogl-gl-header.h
59 +EXTRA_DIST += cogl-defines.h.in cogl-gl-header.h.in
61 # Note: The cogl-1.0/cogl-gl-1.0 files are essentially for
62 # compatability only. I'm not really sure who could possibly be using
63 diff --git a/cogl/cogl-buffer-private.h b/cogl/cogl-buffer-private.h
64 index 62bcf45..0457af0 100644
65 --- a/cogl/cogl-buffer-private.h
66 +++ b/cogl/cogl-buffer-private.h
68 #include "cogl-object-private.h"
69 #include "cogl-buffer.h"
70 #include "cogl-context.h"
71 +#include "cogl-gl-header.h"
75 diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h
76 index 6d92faf..f8c691e 100644
77 --- a/cogl/cogl-context-private.h
78 +++ b/cogl/cogl-context-private.h
80 #include "cogl-texture-2d.h"
81 #include "cogl-texture-3d.h"
82 #include "cogl-texture-rectangle.h"
83 +#include "cogl-gl-header.h"
87 diff --git a/cogl/cogl-defines.h.in b/cogl/cogl-defines.h.in
88 index 3d4b17d..ccdca06 100644
89 --- a/cogl/cogl-defines.h.in
90 +++ b/cogl/cogl-defines.h.in
92 #define __COGL_DEFINES_H__
95 -@COGL_GL_HEADER_INCLUDES@
99 @@ -41,9 +40,6 @@ G_BEGIN_DECLS
100 #define NativeWindowType EGLNativeWindowType
103 -#ifndef GL_OES_EGL_image
104 -#define GLeglImageOES void *
109 diff --git a/cogl/cogl-gl-header.h.in b/cogl/cogl-gl-header.h.in
111 index 0000000..30bc837
113 +++ b/cogl/cogl-gl-header.h.in
118 + * An object oriented GL/GLES Abstraction/Utility Layer
120 + * Copyright (C) 2012 Intel Corporation.
122 + * This library is free software; you can redistribute it and/or
123 + * modify it under the terms of the GNU Lesser General Public
124 + * License as published by the Free Software Foundation; either
125 + * version 2 of the License, or (at your option) any later version.
127 + * This library is distributed in the hope that it will be useful,
128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
130 + * Lesser General Public License for more details.
132 + * You should have received a copy of the GNU Lesser General Public
133 + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
138 +#if !defined(CLUTTER_COMPILATION)
139 +#error "cogl-gl-header.h should only be included when compiling Cogl"
142 +#ifndef __COGL_GL_HEADER_H__
143 +#define __COGL_GL_HEADER_H__
145 +#include "cogl-defines.h"
147 +@COGL_GL_HEADER_INCLUDES@
149 +#ifndef GL_OES_EGL_image
150 +#define GLeglImageOES void *
153 +#endif /* __COGL_GL_HEADER_H__ */
154 diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h
155 index 9019859..e40b721 100644
156 --- a/cogl/cogl-internal.h
157 +++ b/cogl/cogl-internal.h
159 #define __COGL_INTERNAL_H
161 #include "cogl-bitmask.h"
162 +#include "cogl-gl-header.h"
164 #ifdef COGL_HAS_XLIB_SUPPORT
165 #include <X11/Xutil.h>
166 diff --git a/cogl/cogl-shader-private.h b/cogl/cogl-shader-private.h
167 index 6c05b3f..06575e6 100644
168 --- a/cogl/cogl-shader-private.h
169 +++ b/cogl/cogl-shader-private.h
172 #include "cogl-handle.h"
173 #include "cogl-shader.h"
174 +#include "cogl-gl-header.h"
176 typedef struct _CoglShader CoglShader;
178 diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
179 index 4eeffb5..c73ea8a 100644
180 --- a/cogl/cogl-texture.h
181 +++ b/cogl/cogl-texture.h
182 @@ -207,12 +207,12 @@ cogl_texture_new_from_data (unsigned int width,
186 -cogl_texture_new_from_foreign (GLuint gl_handle,
190 - GLuint x_pot_waste,
191 - GLuint y_pot_waste,
192 +cogl_texture_new_from_foreign (unsigned int gl_handle,
193 + unsigned int gl_target,
194 + unsigned int width,
195 + unsigned int height,
196 + unsigned int x_pot_waste,
197 + unsigned int y_pot_waste,
198 CoglPixelFormat format);
201 @@ -353,8 +353,8 @@ cogl_texture_is_sliced (CoglTexture *texture);
204 cogl_texture_get_gl_texture (CoglTexture *texture,
205 - GLuint *out_gl_handle,
206 - GLenum *out_gl_target);
207 + unsigned int *out_gl_handle,
208 + unsigned int *out_gl_target);
211 * cogl_texture_get_data:
212 diff --git a/cogl/tesselator/tesselator.h b/cogl/tesselator/tesselator.h
213 index 69a6ece..5b651be 100644
214 --- a/cogl/tesselator/tesselator.h
215 +++ b/cogl/tesselator/tesselator.h
217 /* This just includes the defines needed by the tesselator code */
219 #include "cogl/cogl-defines.h"
220 +#include "cogl/cogl-gl-header.h"
222 typedef struct GLUtesselator GLUtesselator;
224 diff --git a/configure.ac b/configure.ac
225 index ecf3d49..99fbf1a 100644
228 @@ -1120,6 +1120,7 @@ cogl/Makefile
230 cogl/cogl-2.0-experimental.pc
232 +cogl/cogl-gl-header.h
235 cogl-pango/cogl-pango-1.0.pc
236 diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
237 index e6ffc7b..5a82b46 100644
238 --- a/tests/conform/Makefile.am
239 +++ b/tests/conform/Makefile.am
240 @@ -52,6 +52,7 @@ test_sources = \
241 test-write-texture-formats.c \
243 test-point-sprite.c \
244 + test-no-gl-header.c \
247 test_conformance_SOURCES = $(common_sources) $(test_sources)
248 diff --git a/tests/conform/test-no-gl-header.c b/tests/conform/test-no-gl-header.c
250 index 0000000..49dae6c
252 +++ b/tests/conform/test-no-gl-header.c
254 +#include <cogl/cogl.h>
256 +#include "test-utils.h"
258 +/* If you just include cogl/cogl.h, you shouldn't end up including any
261 +#error "Including cogl.h shouldn't be including any GL headers"
265 +test_no_gl_header (void)
267 + if (cogl_test_verbose ())