From 7474d320f6e1ea9bcfbaebfc3ba23de767386c20 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 24 Nov 2010 18:37:47 +0000 Subject: [PATCH] cogl-context: Get rid of the features_cached member The features_cached member of CoglContext is intended to mark when we've calculated the features so that we know if they are ready in cogl_get_features. However we always intialize the features while creating the context so features_cached will never be FALSE so it's not useful. We also had the odd behaviour that the COGL_DEBUG feature overrides were only applied in the first call to cogl_get_features. However there are other functions that use the feature flags such as cogl_features_available that don't use this function so in some cases the feature flags will be interpreted before the overrides are applied. This patch makes it always initialize the features and apply the overrides immediately while creating the context. This fixes a problem with COGL_DEBUG=disable-arbfp where the first material flushed is done before any call to cogl_get_features so it may still use ARBfp. --- cogl/cogl-context.c | 24 +++++++++++++++++++++++- cogl/cogl-context.h | 1 - cogl/cogl.c | 24 ------------------------ cogl/driver/gl/cogl-gl.c | 1 - cogl/driver/gles/cogl-gles.c | 1 - 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index 37965d119..fa8a4b1bd 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -58,6 +58,28 @@ _cogl_destroy_context_winsys (CoglContext *context); static CoglContext *_context = NULL; static gboolean gl_is_indirect = FALSE; +static void +_cogl_init_feature_overrides (CoglContext *ctx) +{ + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_VBOS)) + ctx->feature_flags &= ~COGL_FEATURE_VBOS; + + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_PBOS)) + ctx->feature_flags &= ~COGL_FEATURE_PBOS; + + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_ARBFP)) + ctx->feature_flags &= ~COGL_FEATURE_SHADERS_ARBFP; + + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_GLSL)) + ctx->feature_flags &= ~COGL_FEATURE_SHADERS_GLSL; + + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_NPOT_TEXTURES)) + ctx->feature_flags &= ~(COGL_FEATURE_TEXTURE_NPOT | + COGL_FEATURE_TEXTURE_NPOT_BASIC | + COGL_FEATURE_TEXTURE_NPOT_MIPMAP | + COGL_FEATURE_TEXTURE_NPOT_REPEAT); +} + static gboolean cogl_create_context (void) { @@ -91,7 +113,6 @@ cogl_create_context (void) /* Init default values */ _context->feature_flags = 0; _context->feature_flags_private = 0; - _context->features_cached = FALSE; _context->texture_types = NULL; _context->buffer_types = NULL; @@ -100,6 +121,7 @@ cogl_create_context (void) /* TODO: combine these two into one function */ _cogl_create_context_driver (_context); _cogl_features_init (); + _cogl_init_feature_overrides (_context); _cogl_create_context_winsys (_context); diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h index b3784d51b..0bc0248d4 100644 --- a/cogl/cogl-context.h +++ b/cogl/cogl-context.h @@ -55,7 +55,6 @@ typedef struct /* Features cache */ CoglFeatureFlags feature_flags; CoglFeatureFlagsPrivate feature_flags_private; - gboolean features_cached; CoglHandle default_pipeline; CoglHandle default_layer_0; diff --git a/cogl/cogl.c b/cogl/cogl.c index ce8326955..5df6e93dc 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -432,24 +432,6 @@ cogl_get_features (void) { _COGL_GET_CONTEXT (ctx, 0); - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_VBOS)) - ctx->feature_flags &= ~COGL_FEATURE_VBOS; - - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_PBOS)) - ctx->feature_flags &= ~COGL_FEATURE_PBOS; - - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_ARBFP)) - ctx->feature_flags &= ~COGL_FEATURE_SHADERS_ARBFP; - - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_GLSL)) - ctx->feature_flags &= ~COGL_FEATURE_SHADERS_GLSL; - - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_NPOT_TEXTURES)) - ctx->feature_flags &= ~(COGL_FEATURE_TEXTURE_NPOT | - COGL_FEATURE_TEXTURE_NPOT_BASIC | - COGL_FEATURE_TEXTURE_NPOT_MIPMAP | - COGL_FEATURE_TEXTURE_NPOT_REPEAT); - return ctx->feature_flags; } @@ -458,9 +440,6 @@ cogl_features_available (CoglFeatureFlags features) { _COGL_GET_CONTEXT (ctx, 0); - if (!ctx->features_cached) - _cogl_features_init (); - return (ctx->feature_flags & features) == features; } @@ -469,9 +448,6 @@ _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; } diff --git a/cogl/driver/gl/cogl-gl.c b/cogl/driver/gl/cogl-gl.c index a8494fe0b..b0b069f8c 100644 --- a/cogl/driver/gl/cogl-gl.c +++ b/cogl/driver/gl/cogl-gl.c @@ -233,5 +233,4 @@ _cogl_features_init (void) /* Cache features */ ctx->feature_flags = flags; ctx->feature_flags_private = flags_private; - ctx->features_cached = TRUE; } diff --git a/cogl/driver/gles/cogl-gles.c b/cogl/driver/gles/cogl-gles.c index c268f614f..1f9c9e081 100644 --- a/cogl/driver/gles/cogl-gles.c +++ b/cogl/driver/gles/cogl-gles.c @@ -117,6 +117,5 @@ _cogl_features_init (void) /* Cache features */ ctx->feature_flags = flags; - ctx->features_cached = TRUE; }