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.
This commit is contained in:
Damien Lespiau 2009-11-14 14:59:59 +00:00 committed by Robert Bragg
parent 037f7a29d1
commit df44c2e9e4
13 changed files with 91 additions and 26 deletions

View File

@ -58,6 +58,7 @@ cogl_create_context (void)
/* Init default values */ /* Init default values */
_context->feature_flags = 0; _context->feature_flags = 0;
_context->feature_flags_private = 0;
_context->features_cached = FALSE; _context->features_cached = FALSE;
/* Initialise the driver specific state */ /* Initialise the driver specific state */

View File

@ -45,6 +45,7 @@ typedef struct
{ {
/* Features cache */ /* Features cache */
CoglFeatureFlags feature_flags; CoglFeatureFlags feature_flags;
CoglFeatureFlagsPrivate feature_flags_private;
gboolean features_cached; gboolean features_cached;
CoglHandle default_material; CoglHandle default_material;

View File

@ -59,6 +59,9 @@ struct _CoglFeatureData
const char *extension_names; const char *extension_names;
/* A set of feature flags to enable if the extension is available */ /* A set of feature flags to enable if the extension is available */
CoglFeatureFlags feature_flags; 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 /* A list of functions required for this feature. Terminated with a
NULL name */ NULL name */
const CoglFeatureFunction *functions; const CoglFeatureFunction *functions;

View File

@ -174,4 +174,12 @@ _cogl_xlib_handle_event (XEvent *xevent);
#endif /* COGL_HAS_XLIB_SUPPORT */ #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 */ #endif /* __COGL_INTERNAL_H */

View File

@ -507,6 +507,17 @@ cogl_features_available (CoglFeatureFlags features)
return (ctx->feature_flags & features) == 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 /* XXX: This function should either be replaced with one returning
* integers, or removed/deprecated and make the * integers, or removed/deprecated and make the
* _cogl_framebuffer_get_viewport* functions public. * _cogl_framebuffer_get_viewport* functions public.

View File

@ -27,7 +27,7 @@
#include "cogl-context.h" #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) \ #define COGL_FEATURE_FUNCTION(ret, name, args) \
_context->drv.pf_ ## name = NULL; _context->drv.pf_ ## name = NULL;
#define COGL_FEATURE_END() #define COGL_FEATURE_END()

View File

@ -30,7 +30,7 @@
#define APIENTRY #define APIENTRY
#endif #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) \ #define COGL_FEATURE_FUNCTION(ret, name, args) \
ret (APIENTRY * pf_ ## name) args; ret (APIENTRY * pf_ ## name) args;

View File

@ -30,7 +30,8 @@ COGL_FEATURE_BEGIN (offscreen, 255, 255,
functions */ functions */
"ARB:\0EXT\0", "ARB:\0EXT\0",
"framebuffer_object\0", "framebuffer_object\0",
COGL_FEATURE_OFFSCREEN) COGL_FEATURE_OFFSCREEN,
0)
COGL_FEATURE_FUNCTION (void, glGenRenderbuffers, COGL_FEATURE_FUNCTION (void, glGenRenderbuffers,
(GLsizei n, (GLsizei n,
GLuint *renderbuffers)) GLuint *renderbuffers))
@ -74,7 +75,8 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (offscreen_blit, 255, 255, COGL_FEATURE_BEGIN (offscreen_blit, 255, 255,
"EXT\0", "EXT\0",
"framebuffer_blit\0", "framebuffer_blit\0",
COGL_FEATURE_OFFSCREEN_BLIT) COGL_FEATURE_OFFSCREEN_BLIT,
0)
COGL_FEATURE_FUNCTION (void, glBlitFramebuffer, COGL_FEATURE_FUNCTION (void, glBlitFramebuffer,
(GLint srcX0, (GLint srcX0,
GLint srcY0, GLint srcY0,
@ -91,7 +93,8 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (offscreen_multisample, 255, 255, COGL_FEATURE_BEGIN (offscreen_multisample, 255, 255,
"EXT\0", "EXT\0",
"framebuffer_multisample\0", "framebuffer_multisample\0",
COGL_FEATURE_OFFSCREEN_MULTISAMPLE) COGL_FEATURE_OFFSCREEN_MULTISAMPLE,
0)
COGL_FEATURE_FUNCTION (void, glRenderbufferStorageMultisample, COGL_FEATURE_FUNCTION (void, glRenderbufferStorageMultisample,
(GLenum target, (GLenum target,
GLsizei samples, GLsizei samples,
@ -99,10 +102,31 @@ COGL_FEATURE_FUNCTION (void, glRenderbufferStorageMultisample,
GLsizei width, GLsizei width,
GLsizei height)) GLsizei height))
COGL_FEATURE_END () COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (read_pixels_async, 2, 1, COGL_FEATURE_BEGIN (read_pixels_async, 2, 1,
"EXT\0", "EXT\0",
"pixel_buffer_object\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 () COGL_FEATURE_END ()
/* The function names in OpenGL 2.0 are different so we can't easily /* 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" "shader_objects\0"
"vertex_shader\0" "vertex_shader\0"
"fragment_shader\0", "fragment_shader\0",
COGL_FEATURE_SHADERS_GLSL) COGL_FEATURE_SHADERS_GLSL,
0)
COGL_FEATURE_FUNCTION (GLhandleARB, glCreateProgramObject, COGL_FEATURE_FUNCTION (GLhandleARB, glCreateProgramObject,
(void)) (void))
COGL_FEATURE_FUNCTION (GLhandleARB, glCreateShaderObject, COGL_FEATURE_FUNCTION (GLhandleARB, glCreateShaderObject,
@ -247,7 +272,8 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (vbos, 1, 5, COGL_FEATURE_BEGIN (vbos, 1, 5,
"ARB\0", "ARB\0",
"vertex_buffer_object\0", "vertex_buffer_object\0",
COGL_FEATURE_VBOS) COGL_FEATURE_VBOS,
0)
COGL_FEATURE_FUNCTION (void, glGenBuffers, COGL_FEATURE_FUNCTION (void, glGenBuffers,
(GLuint n, (GLuint n,
GLuint *buffers)) GLuint *buffers))
@ -281,6 +307,7 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (in_1_2, 1, 2, COGL_FEATURE_BEGIN (in_1_2, 1, 2,
"\0", "\0",
"\0", "\0",
0,
0) 0)
COGL_FEATURE_FUNCTION (void, glDrawRangeElements, COGL_FEATURE_FUNCTION (void, glDrawRangeElements,
(GLenum mode, (GLenum mode,
@ -303,6 +330,7 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (multitexture, 1, 3, COGL_FEATURE_BEGIN (multitexture, 1, 3,
"ARB\0", "ARB\0",
"multitexture\0", "multitexture\0",
0,
0) 0)
COGL_FEATURE_FUNCTION (void, glActiveTexture, COGL_FEATURE_FUNCTION (void, glActiveTexture,
(GLenum texture)) (GLenum texture))
@ -314,6 +342,7 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (blend_func_separate, 1, 4, COGL_FEATURE_BEGIN (blend_func_separate, 1, 4,
"EXT\0", "EXT\0",
"blend_func_separate\0", "blend_func_separate\0",
0,
0) 0)
COGL_FEATURE_FUNCTION (void, glBlendFuncSeparate, COGL_FEATURE_FUNCTION (void, glBlendFuncSeparate,
(GLenum srcRGB, (GLenum srcRGB,
@ -326,6 +355,7 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (blend_equation_separate, 2, 0, COGL_FEATURE_BEGIN (blend_equation_separate, 2, 0,
"EXT\0", "EXT\0",
"blend_equation_separate\0", "blend_equation_separate\0",
0,
0) 0)
COGL_FEATURE_FUNCTION (void, glBlendEquationSeparate, COGL_FEATURE_FUNCTION (void, glBlendEquationSeparate,
(GLenum modeRGB, (GLenum modeRGB,

View File

@ -145,7 +145,8 @@ _cogl_check_driver_valid (GError **error)
/* Define a set of arrays containing the functions required from GL /* Define a set of arrays containing the functions required from GL
for each feature */ for each feature */
#define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ #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[] = { static const CoglFeatureFunction cogl_feature_ ## name ## _funcs[] = {
#define COGL_FEATURE_FUNCTION(ret, name, args) \ #define COGL_FEATURE_FUNCTION(ret, name, args) \
{ G_STRINGIFY (name), G_STRUCT_OFFSET (CoglContext, drv.pf_ ## name) }, { 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 */ /* Define an array of features */
#undef COGL_FEATURE_BEGIN #undef COGL_FEATURE_BEGIN
#define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ #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, \ { min_gl_major, min_gl_minor, namespaces, \
extension_names, feature_flags, \ extension_names, feature_flags, feature_flags_private, \
cogl_feature_ ## name ## _funcs }, cogl_feature_ ## name ## _funcs },
#undef COGL_FEATURE_FUNCTION #undef COGL_FEATURE_FUNCTION
#define COGL_FEATURE_FUNCTION(ret, name, args) #define COGL_FEATURE_FUNCTION(ret, name, args)
@ -175,6 +177,7 @@ void
_cogl_features_init (void) _cogl_features_init (void)
{ {
CoglFeatureFlags flags = 0; CoglFeatureFlags flags = 0;
CoglFeatureFlagsPrivate flags_private = 0;
const char *gl_extensions; const char *gl_extensions;
GLint max_clip_planes = 0; GLint max_clip_planes = 0;
GLint num_stencil_bits = 0; GLint num_stencil_bits = 0;
@ -219,9 +222,13 @@ _cogl_features_init (void)
if (_cogl_feature_check (cogl_feature_data + i, if (_cogl_feature_check (cogl_feature_data + i,
gl_major, gl_minor, gl_major, gl_minor,
gl_extensions)) gl_extensions))
{
flags |= cogl_feature_data[i].feature_flags; flags |= cogl_feature_data[i].feature_flags;
flags_private |= cogl_feature_data[i].feature_flags_private;
}
/* Cache features */ /* Cache features */
ctx->feature_flags = flags; ctx->feature_flags = flags;
ctx->feature_flags_private = flags_private;
ctx->features_cached = TRUE; ctx->features_cached = TRUE;
} }

View File

@ -28,7 +28,7 @@
#include "cogl-context.h" #include "cogl-context.h"
#include "cogl-gles2-wrapper.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) \ #define COGL_FEATURE_FUNCTION(ret, name, args) \
_context->drv.pf_ ## name = NULL; _context->drv.pf_ ## name = NULL;
#define COGL_FEATURE_END() #define COGL_FEATURE_END()

View File

@ -31,7 +31,7 @@
#define APIENTRY #define APIENTRY
#endif #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) \ #define COGL_FEATURE_FUNCTION(ret, name, args) \
ret (APIENTRY * pf_ ## name) args; ret (APIENTRY * pf_ ## name) args;

View File

@ -27,7 +27,8 @@
COGL_FEATURE_BEGIN (offscreen, 255, 255, COGL_FEATURE_BEGIN (offscreen, 255, 255,
"OES\0", "OES\0",
"framebuffer_object\0", "framebuffer_object\0",
COGL_FEATURE_OFFSCREEN) COGL_FEATURE_OFFSCREEN,
0)
COGL_FEATURE_FUNCTION (void, glGenRenderbuffers, COGL_FEATURE_FUNCTION (void, glGenRenderbuffers,
(GLsizei n, (GLsizei n,
GLuint *renderbuffers)) GLuint *renderbuffers))
@ -71,5 +72,6 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (element_index_uint, 255, 255, COGL_FEATURE_BEGIN (element_index_uint, 255, 255,
"OES\0", "OES\0",
"element_index_uint\0", "element_index_uint\0",
COGL_FEATURE_UNSIGNED_INT_INDICES) COGL_FEATURE_UNSIGNED_INT_INDICES,
0)
COGL_FEATURE_END () COGL_FEATURE_END ()

View File

@ -42,7 +42,8 @@ _cogl_check_driver_valid (GError **error)
/* Define a set of arrays containing the functions required from GL /* Define a set of arrays containing the functions required from GL
for each feature */ for each feature */
#define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ #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[] = { static const CoglFeatureFunction cogl_feature_ ## name ## _funcs[] = {
#define COGL_FEATURE_FUNCTION(ret, name, args) \ #define COGL_FEATURE_FUNCTION(ret, name, args) \
{ G_STRINGIFY (name), G_STRUCT_OFFSET (CoglContext, drv.pf_ ## name) }, { 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 */ /* Define an array of features */
#undef COGL_FEATURE_BEGIN #undef COGL_FEATURE_BEGIN
#define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \ #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, \ { min_gl_major, min_gl_minor, namespaces, \
extension_names, feature_flags, \ extension_names, feature_flags, feature_flags_private, \
cogl_feature_ ## name ## _funcs }, cogl_feature_ ## name ## _funcs },
#undef COGL_FEATURE_FUNCTION #undef COGL_FEATURE_FUNCTION
#define COGL_FEATURE_FUNCTION(ret, name, args) #define COGL_FEATURE_FUNCTION(ret, name, args)