Don't include any GL header from the public GL headers

This splits the GL header inclusion from cogl-defines.h into a
separate headear called cogl-gl-header.h which we will only include
internally. That way we don't leak GL declarations out of our public
headers. The texture functions that were using GLenum and GLuint in
the public header have now changed to just use unsigned int. Note
however that if an EGL winsys is enabled then it will still publicly
include an EGL header. This is a bit more awkward to fix because we
have public API which returns an EGLDisplay and we can't determine
what type that is.

There is also a conformance test which just verifies that no GL header
has been included while compiling. The test isn't added to
test-conform-main because it doesn't actually test anything at
runtime.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ef5680d3fda5df929dbd0b420c8f598ded58dfee)
This commit is contained in:
Neil Roberts 2012-03-23 18:05:46 +00:00 committed by Robert Bragg
parent e85a04f0ce
commit 6400b455b8
13 changed files with 75 additions and 15 deletions

View File

@ -34,9 +34,9 @@ AM_CPPFLAGS = \
AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS)
BUILT_SOURCES += cogl-defines.h
DISTCLEANFILES += cogl-defines.h
EXTRA_DIST += cogl-defines.h.in
BUILT_SOURCES += cogl-defines.h cogl-gl-header.h
DISTCLEANFILES += cogl-defines.h cogl-gl-header.h
EXTRA_DIST += cogl-defines.h.in cogl-gl-header.h.in
# Note: The cogl-1.0/cogl-gl-1.0 files are essentially for
# compatability only. I'm not really sure who could possibly be using

View File

@ -33,6 +33,7 @@
#include "cogl-object-private.h"
#include "cogl-buffer.h"
#include "cogl-context.h"
#include "cogl-gl-header.h"
G_BEGIN_DECLS

View File

@ -49,6 +49,7 @@
#include "cogl-texture-rectangle.h"
#include "cogl-sampler-cache-private.h"
#include "cogl-gpu-info-private.h"
#include "cogl-gl-header.h"
typedef struct
{

View File

@ -29,7 +29,6 @@
#define __COGL_DEFINES_H__
#include <glib.h>
@COGL_GL_HEADER_INCLUDES@
G_BEGIN_DECLS
@ -41,9 +40,6 @@ G_BEGIN_DECLS
#define NativeWindowType EGLNativeWindowType
#endif
#ifndef GL_OES_EGL_image
#define GLeglImageOES void *
#endif
G_END_DECLS
#endif

39
cogl/cogl-gl-header.h.in Normal file
View File

@ -0,0 +1,39 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2012 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#if !defined(CLUTTER_COMPILATION)
#error "cogl-gl-header.h should only be included when compiling Cogl"
#endif
#ifndef __COGL_GL_HEADER_H__
#define __COGL_GL_HEADER_H__
#include "cogl-defines.h"
@COGL_GL_HEADER_INCLUDES@
#ifndef GL_OES_EGL_image
#define GLeglImageOES void *
#endif
#endif /* __COGL_GL_HEADER_H__ */

View File

@ -25,6 +25,7 @@
#define __COGL_INTERNAL_H
#include "cogl-bitmask.h"
#include "cogl-gl-header.h"
#ifdef COGL_HAS_XLIB_SUPPORT
#include <X11/Xutil.h>

View File

@ -26,6 +26,7 @@
#define __COGL_SAMPLER_CACHE_PRIVATE_H
#include "cogl-context.h"
#include "cogl-gl-header.h"
/* GL_ALWAYS is just used here as a value that is known not to clash
* with any valid GL wrap modes.

View File

@ -26,6 +26,7 @@
#include "cogl-handle.h"
#include "cogl-shader.h"
#include "cogl-gl-header.h"
typedef struct _CoglShader CoglShader;

View File

@ -207,12 +207,12 @@ cogl_texture_new_from_data (unsigned int width,
* Since: 0.8
*/
CoglTexture *
cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target,
GLuint width,
GLuint height,
GLuint x_pot_waste,
GLuint y_pot_waste,
cogl_texture_new_from_foreign (unsigned int gl_handle,
unsigned int gl_target,
unsigned int width,
unsigned int height,
unsigned int x_pot_waste,
unsigned int y_pot_waste,
CoglPixelFormat format);
/**
@ -353,8 +353,8 @@ cogl_texture_is_sliced (CoglTexture *texture);
*/
gboolean
cogl_texture_get_gl_texture (CoglTexture *texture,
GLuint *out_gl_handle,
GLenum *out_gl_target);
unsigned int *out_gl_handle,
unsigned int *out_gl_target);
/**
* cogl_texture_get_data:

View File

@ -35,6 +35,7 @@
/* This just includes the defines needed by the tesselator code */
#include "cogl/cogl-defines.h"
#include "cogl/cogl-gl-header.h"
typedef struct GLUtesselator GLUtesselator;

View File

@ -1120,6 +1120,7 @@ cogl/Makefile
cogl/cogl-1.0.pc
cogl/cogl-2.0-experimental.pc
cogl/cogl-defines.h
cogl/cogl-gl-header.h
cogl/cogl.rc
cogl-pango/Makefile
cogl-pango/cogl-pango-1.0.pc

View File

@ -52,6 +52,7 @@ test_sources = \
test-write-texture-formats.c \
test-point-size.c \
test-point-sprite.c \
test-no-gl-header.c \
$(NULL)
test_conformance_SOURCES = $(common_sources) $(test_sources)

View File

@ -0,0 +1,17 @@
#include <cogl/cogl.h>
#include "test-utils.h"
/* If you just include cogl/cogl.h, you shouldn't end up including any
GL headers */
#ifdef GL_TRUE
#error "Including cogl.h shouldn't be including any GL headers"
#endif
void
test_no_gl_header (void)
{
if (cogl_test_verbose ())
g_print ("OK\n");
}