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 8836c868a4
commit 56dd71dba0
13 changed files with 91 additions and 26 deletions

View File

@ -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 */

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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.

View File

@ -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()

View File

@ -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;

View File

@ -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,

View File

@ -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;
}

View File

@ -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()

View File

@ -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;

View File

@ -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 ()

View File

@ -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)