From df44c2e9e499eff0e29148d4e46328621d5fde6a Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Sat, 14 Nov 2009 14:59:59 +0000 Subject: [PATCH] cogl: Introduce private feature flags and check for ARB_fp The Cogl context has now a feature_flags_private enum that will allow us to query and use OpenGL features without exposing them in the public API. The ARB_fragment_program extension is the first user of those flags. Looking for this extension only happens in the gl driver as the gles drivers will not expose them. One can use _cogl_features_available_private() to check for the availability of such private features. While at it, reindent cogl-internal.h as described in CODING_STYLE. --- clutter/cogl/cogl/cogl-context.c | 1 + clutter/cogl/cogl/cogl-context.h | 5 ++- clutter/cogl/cogl/cogl-feature-private.h | 3 ++ clutter/cogl/cogl/cogl-internal.h | 8 ++++ clutter/cogl/cogl/cogl.c | 11 +++++ .../cogl/cogl/driver/gl/cogl-context-driver.c | 2 +- .../cogl/cogl/driver/gl/cogl-context-driver.h | 2 +- .../cogl/driver/gl/cogl-feature-functions.h | 42 ++++++++++++++++--- clutter/cogl/cogl/driver/gl/cogl.c | 25 +++++++---- .../cogl/driver/gles/cogl-context-driver.c | 2 +- .../cogl/driver/gles/cogl-context-driver.h | 2 +- .../cogl/driver/gles/cogl-feature-functions.h | 6 ++- clutter/cogl/cogl/driver/gles/cogl.c | 8 ++-- 13 files changed, 91 insertions(+), 26 deletions(-) diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index 8d678f428..d9b2642ce 100644 --- a/clutter/cogl/cogl/cogl-context.c +++ b/clutter/cogl/cogl/cogl-context.c @@ -58,6 +58,7 @@ cogl_create_context (void) /* Init default values */ _context->feature_flags = 0; + _context->feature_flags_private = 0; _context->features_cached = FALSE; /* Initialise the driver specific state */ diff --git a/clutter/cogl/cogl/cogl-context.h b/clutter/cogl/cogl/cogl-context.h index 9393dd740..e03282752 100644 --- a/clutter/cogl/cogl/cogl-context.h +++ b/clutter/cogl/cogl/cogl-context.h @@ -44,8 +44,9 @@ typedef struct typedef struct { /* Features cache */ - CoglFeatureFlags feature_flags; - gboolean features_cached; + CoglFeatureFlags feature_flags; + CoglFeatureFlagsPrivate feature_flags_private; + gboolean features_cached; CoglHandle default_material; diff --git a/clutter/cogl/cogl/cogl-feature-private.h b/clutter/cogl/cogl/cogl-feature-private.h index b8530dc6c..2221ec037 100644 --- a/clutter/cogl/cogl/cogl-feature-private.h +++ b/clutter/cogl/cogl/cogl-feature-private.h @@ -59,6 +59,9 @@ struct _CoglFeatureData const char *extension_names; /* A set of feature flags to enable if the extension is available */ CoglFeatureFlags feature_flags; + /* A set of private feature flags to enable if the extension is available + * and for internal use only */ + CoglFeatureFlagsPrivate feature_flags_private; /* A list of functions required for this feature. Terminated with a NULL name */ const CoglFeatureFunction *functions; diff --git a/clutter/cogl/cogl/cogl-internal.h b/clutter/cogl/cogl/cogl-internal.h index c4169beda..511c9d5b9 100644 --- a/clutter/cogl/cogl/cogl-internal.h +++ b/clutter/cogl/cogl/cogl-internal.h @@ -174,4 +174,12 @@ _cogl_xlib_handle_event (XEvent *xevent); #endif /* COGL_HAS_XLIB_SUPPORT */ +typedef enum _CoglFeatureFlagsPrivate +{ + COGL_FEATURE_PRIVATE_ARB_FP = (1 << 0) +} CoglFeatureFlagsPrivate; + +gboolean +_cogl_features_available_private (CoglFeatureFlagsPrivate features); + #endif /* __COGL_INTERNAL_H */ diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index 35055f2d4..b6331fd85 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/cogl/cogl.c @@ -507,6 +507,17 @@ cogl_features_available (CoglFeatureFlags features) return (ctx->feature_flags & features) == features; } +gboolean +_cogl_features_available_private (CoglFeatureFlagsPrivate features) +{ + _COGL_GET_CONTEXT (ctx, 0); + + if (!ctx->features_cached) + _cogl_features_init (); + + return (ctx->feature_flags_private & features) == features; +} + /* XXX: This function should either be replaced with one returning * integers, or removed/deprecated and make the * _cogl_framebuffer_get_viewport* functions public. diff --git a/clutter/cogl/cogl/driver/gl/cogl-context-driver.c b/clutter/cogl/cogl/driver/gl/cogl-context-driver.c index ac7460b02..9524bbc72 100644 --- a/clutter/cogl/cogl/driver/gl/cogl-context-driver.c +++ b/clutter/cogl/cogl/driver/gl/cogl-context-driver.c @@ -27,7 +27,7 @@ #include "cogl-context.h" -#define COGL_FEATURE_BEGIN(a, b, c, d, e, f) +#define COGL_FEATURE_BEGIN(a, b, c, d, e, f, g) #define COGL_FEATURE_FUNCTION(ret, name, args) \ _context->drv.pf_ ## name = NULL; #define COGL_FEATURE_END() diff --git a/clutter/cogl/cogl/driver/gl/cogl-context-driver.h b/clutter/cogl/cogl/driver/gl/cogl-context-driver.h index 3699dae9d..7ae8385cb 100644 --- a/clutter/cogl/cogl/driver/gl/cogl-context-driver.h +++ b/clutter/cogl/cogl/driver/gl/cogl-context-driver.h @@ -30,7 +30,7 @@ #define APIENTRY #endif -#define COGL_FEATURE_BEGIN(a, b, c, d, e, f) +#define COGL_FEATURE_BEGIN(a, b, c, d, e, f, g) #define COGL_FEATURE_FUNCTION(ret, name, args) \ ret (APIENTRY * pf_ ## name) args; diff --git a/clutter/cogl/cogl/driver/gl/cogl-feature-functions.h b/clutter/cogl/cogl/driver/gl/cogl-feature-functions.h index 6ebf7eb34..cf4a8f38a 100644 --- a/clutter/cogl/cogl/driver/gl/cogl-feature-functions.h +++ b/clutter/cogl/cogl/driver/gl/cogl-feature-functions.h @@ -30,7 +30,8 @@ COGL_FEATURE_BEGIN (offscreen, 255, 255, functions */ "ARB:\0EXT\0", "framebuffer_object\0", - COGL_FEATURE_OFFSCREEN) + COGL_FEATURE_OFFSCREEN, + 0) COGL_FEATURE_FUNCTION (void, glGenRenderbuffers, (GLsizei n, GLuint *renderbuffers)) @@ -74,7 +75,8 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (offscreen_blit, 255, 255, "EXT\0", "framebuffer_blit\0", - COGL_FEATURE_OFFSCREEN_BLIT) + COGL_FEATURE_OFFSCREEN_BLIT, + 0) COGL_FEATURE_FUNCTION (void, glBlitFramebuffer, (GLint srcX0, GLint srcY0, @@ -91,7 +93,8 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (offscreen_multisample, 255, 255, "EXT\0", "framebuffer_multisample\0", - COGL_FEATURE_OFFSCREEN_MULTISAMPLE) + COGL_FEATURE_OFFSCREEN_MULTISAMPLE, + 0) COGL_FEATURE_FUNCTION (void, glRenderbufferStorageMultisample, (GLenum target, GLsizei samples, @@ -99,10 +102,31 @@ COGL_FEATURE_FUNCTION (void, glRenderbufferStorageMultisample, GLsizei width, GLsizei height)) COGL_FEATURE_END () + COGL_FEATURE_BEGIN (read_pixels_async, 2, 1, "EXT\0", "pixel_buffer_object\0", - COGL_FEATURE_PBOS) + COGL_FEATURE_PBOS, + 0) +COGL_FEATURE_END () + +/* ARB_fragment_program */ +COGL_FEATURE_BEGIN (arbfp, 255, 255, + "ARB\0", + "fragment_program\0", + 0, + COGL_FEATURE_PRIVATE_ARB_FP) +COGL_FEATURE_FUNCTION (void, glGenPrograms, + (GLsizei n, + GLuint *programs)) +COGL_FEATURE_FUNCTION (void, glBindProgram, + (GLenum target, + GLuint program)) +COGL_FEATURE_FUNCTION (void, glProgramString, + (GLenum target, + GLenum format, + GLsizei len, + const void *program)) COGL_FEATURE_END () /* The function names in OpenGL 2.0 are different so we can't easily @@ -112,7 +136,8 @@ COGL_FEATURE_BEGIN (shaders_glsl, 255, 255, "shader_objects\0" "vertex_shader\0" "fragment_shader\0", - COGL_FEATURE_SHADERS_GLSL) + COGL_FEATURE_SHADERS_GLSL, + 0) COGL_FEATURE_FUNCTION (GLhandleARB, glCreateProgramObject, (void)) COGL_FEATURE_FUNCTION (GLhandleARB, glCreateShaderObject, @@ -247,7 +272,8 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (vbos, 1, 5, "ARB\0", "vertex_buffer_object\0", - COGL_FEATURE_VBOS) + COGL_FEATURE_VBOS, + 0) COGL_FEATURE_FUNCTION (void, glGenBuffers, (GLuint n, GLuint *buffers)) @@ -281,6 +307,7 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (in_1_2, 1, 2, "\0", "\0", + 0, 0) COGL_FEATURE_FUNCTION (void, glDrawRangeElements, (GLenum mode, @@ -303,6 +330,7 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (multitexture, 1, 3, "ARB\0", "multitexture\0", + 0, 0) COGL_FEATURE_FUNCTION (void, glActiveTexture, (GLenum texture)) @@ -314,6 +342,7 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (blend_func_separate, 1, 4, "EXT\0", "blend_func_separate\0", + 0, 0) COGL_FEATURE_FUNCTION (void, glBlendFuncSeparate, (GLenum srcRGB, @@ -326,6 +355,7 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (blend_equation_separate, 2, 0, "EXT\0", "blend_equation_separate\0", + 0, 0) COGL_FEATURE_FUNCTION (void, glBlendEquationSeparate, (GLenum modeRGB, diff --git a/clutter/cogl/cogl/driver/gl/cogl.c b/clutter/cogl/cogl/driver/gl/cogl.c index d53982dd1..08fae7d35 100644 --- a/clutter/cogl/cogl/driver/gl/cogl.c +++ b/clutter/cogl/cogl/driver/gl/cogl.c @@ -145,7 +145,8 @@ _cogl_check_driver_valid (GError **error) /* Define a set of arrays containing the functions required from GL for each feature */ #define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ - namespaces, extension_names, feature_flags) \ + namespaces, extension_names, \ + feature_flags, feature_flags_private) \ static const CoglFeatureFunction cogl_feature_ ## name ## _funcs[] = { #define COGL_FEATURE_FUNCTION(ret, name, args) \ { G_STRINGIFY (name), G_STRUCT_OFFSET (CoglContext, drv.pf_ ## name) }, @@ -157,9 +158,10 @@ _cogl_check_driver_valid (GError **error) /* Define an array of features */ #undef COGL_FEATURE_BEGIN #define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ - namespaces, extension_names, feature_flags) \ + namespaces, extension_names, \ + feature_flags, feature_flags_private) \ { min_gl_major, min_gl_minor, namespaces, \ - extension_names, feature_flags, \ + extension_names, feature_flags, feature_flags_private, \ cogl_feature_ ## name ## _funcs }, #undef COGL_FEATURE_FUNCTION #define COGL_FEATURE_FUNCTION(ret, name, args) @@ -174,12 +176,13 @@ static const CoglFeatureData cogl_feature_data[] = void _cogl_features_init (void) { - CoglFeatureFlags flags = 0; - const char *gl_extensions; - GLint max_clip_planes = 0; - GLint num_stencil_bits = 0; - int gl_major = 0, gl_minor = 0; - int i; + CoglFeatureFlags flags = 0; + CoglFeatureFlagsPrivate flags_private = 0; + const char *gl_extensions; + GLint max_clip_planes = 0; + GLint num_stencil_bits = 0; + int gl_major = 0, gl_minor = 0; + int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -219,9 +222,13 @@ _cogl_features_init (void) if (_cogl_feature_check (cogl_feature_data + i, gl_major, gl_minor, gl_extensions)) + { flags |= cogl_feature_data[i].feature_flags; + flags_private |= cogl_feature_data[i].feature_flags_private; + } /* Cache features */ ctx->feature_flags = flags; + ctx->feature_flags_private = flags_private; ctx->features_cached = TRUE; } diff --git a/clutter/cogl/cogl/driver/gles/cogl-context-driver.c b/clutter/cogl/cogl/driver/gles/cogl-context-driver.c index 24402b176..ab1891d50 100644 --- a/clutter/cogl/cogl/driver/gles/cogl-context-driver.c +++ b/clutter/cogl/cogl/driver/gles/cogl-context-driver.c @@ -28,7 +28,7 @@ #include "cogl-context.h" #include "cogl-gles2-wrapper.h" -#define COGL_FEATURE_BEGIN(a, b, c, d, e, f) +#define COGL_FEATURE_BEGIN(a, b, c, d, e, f, g) #define COGL_FEATURE_FUNCTION(ret, name, args) \ _context->drv.pf_ ## name = NULL; #define COGL_FEATURE_END() diff --git a/clutter/cogl/cogl/driver/gles/cogl-context-driver.h b/clutter/cogl/cogl/driver/gles/cogl-context-driver.h index 4395e2457..9c473eb94 100644 --- a/clutter/cogl/cogl/driver/gles/cogl-context-driver.h +++ b/clutter/cogl/cogl/driver/gles/cogl-context-driver.h @@ -31,7 +31,7 @@ #define APIENTRY #endif -#define COGL_FEATURE_BEGIN(a, b, c, d, e, f) +#define COGL_FEATURE_BEGIN(a, b, c, d, e, f, g) #define COGL_FEATURE_FUNCTION(ret, name, args) \ ret (APIENTRY * pf_ ## name) args; diff --git a/clutter/cogl/cogl/driver/gles/cogl-feature-functions.h b/clutter/cogl/cogl/driver/gles/cogl-feature-functions.h index 1feeda263..de6a24c19 100644 --- a/clutter/cogl/cogl/driver/gles/cogl-feature-functions.h +++ b/clutter/cogl/cogl/driver/gles/cogl-feature-functions.h @@ -27,7 +27,8 @@ COGL_FEATURE_BEGIN (offscreen, 255, 255, "OES\0", "framebuffer_object\0", - COGL_FEATURE_OFFSCREEN) + COGL_FEATURE_OFFSCREEN, + 0) COGL_FEATURE_FUNCTION (void, glGenRenderbuffers, (GLsizei n, GLuint *renderbuffers)) @@ -71,5 +72,6 @@ COGL_FEATURE_END () COGL_FEATURE_BEGIN (element_index_uint, 255, 255, "OES\0", "element_index_uint\0", - COGL_FEATURE_UNSIGNED_INT_INDICES) + COGL_FEATURE_UNSIGNED_INT_INDICES, + 0) COGL_FEATURE_END () diff --git a/clutter/cogl/cogl/driver/gles/cogl.c b/clutter/cogl/cogl/driver/gles/cogl.c index 622f9b3c7..fbf8e8b3a 100644 --- a/clutter/cogl/cogl/driver/gles/cogl.c +++ b/clutter/cogl/cogl/driver/gles/cogl.c @@ -42,7 +42,8 @@ _cogl_check_driver_valid (GError **error) /* Define a set of arrays containing the functions required from GL for each feature */ #define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ - namespaces, extension_names, feature_flags) \ + namespaces, extension_names, \ + feature_flags, feature_flags_private) \ static const CoglFeatureFunction cogl_feature_ ## name ## _funcs[] = { #define COGL_FEATURE_FUNCTION(ret, name, args) \ { G_STRINGIFY (name), G_STRUCT_OFFSET (CoglContext, drv.pf_ ## name) }, @@ -54,9 +55,10 @@ _cogl_check_driver_valid (GError **error) /* Define an array of features */ #undef COGL_FEATURE_BEGIN #define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ - namespaces, extension_names, feature_flags) \ + namespaces, extension_names, \ + feature_flags, feature_flags_private) \ { min_gl_major, min_gl_minor, namespaces, \ - extension_names, feature_flags, \ + extension_names, feature_flags, feature_flags_private, \ cogl_feature_ ## name ## _funcs }, #undef COGL_FEATURE_FUNCTION #define COGL_FEATURE_FUNCTION(ret, name, args)