[Cogl] [PATCH 1/3] Add env vars to trick Cogl to think extensions are disabled

Neil Roberts neil at linux.intel.com
Wed Jul 4 08:15:21 PDT 2012


This adds two new debug environment variables:

COGL_DEBUG_DISABLE_GL_EXTENSIONS and
COGL_DEBUG_GL_VERSION

The first one is a list of GL extension names separated by commas.
When set Cogl will assume any extension listed here is not available
by removing it from the string returned from
glGetString(GL_EXTENSIONS).

The second overrides the value returned from glGetString(GL_VERSION).

These are sometimes useful for debugging Cogl to test the various
combinations of extensions.
---
 cogl/cogl-context-private.h   |  6 ++++
 cogl/cogl-context.c           | 80 +++++++++++++++++++++++++++++++++++++++++++
 cogl/cogl-debug.c             | 16 +++++++--
 cogl/cogl-gpu-info.c          |  2 +-
 cogl/driver/gl/cogl-gl.c      | 10 +++---
 cogl/driver/gles/cogl-gles.c  |  6 ++--
 cogl/winsys/cogl-winsys-wgl.c |  2 +-
 7 files changed, 109 insertions(+), 13 deletions(-)

diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h
index ffa5da9..0be6000 100644
--- a/cogl/cogl-context-private.h
+++ b/cogl/cogl-context-private.h
@@ -340,4 +340,10 @@ void
 _cogl_context_set_current_modelview_entry (CoglContext *context,
                                            CoglMatrixEntry *entry);
 
+const char *
+_cogl_context_get_gl_extensions (CoglContext *context);
+
+const char *
+_cogl_context_get_gl_version (CoglContext *context);
+
 #endif /* __COGL_CONTEXT_PRIVATE_H */
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 4973d64..62b4269 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -602,3 +602,83 @@ _cogl_context_set_current_modelview_entry (CoglContext *context,
     _cogl_matrix_entry_unref (context->current_modelview_entry);
   context->current_modelview_entry = entry;
 }
+
+const char *
+_cogl_context_get_gl_extensions (CoglContext *context)
+{
+#ifdef COGL_ENABLE_DEBUG
+  const char *disabled_extensions;
+
+  if ((disabled_extensions = g_getenv ("COGL_DEBUG_DISABLE_GL_EXTENSIONS")))
+    {
+      static CoglUserDataKey extensions_key;
+      const char *enabled_extensions;
+      char **split_enabled_extensions;
+      char **split_disabled_extensions;
+      char **e, **d;
+      GString *result;
+
+      /* We need to return a const string so we'll attach the results
+       * to the CoglContext to avoid leaking the generated string.
+       * This string is only used for debugging so we are using
+       * cogl_object_set_user_data instead of adding an explicit
+       * member to CoglContext to avoid making the struct bigger */
+
+      enabled_extensions =
+        cogl_object_get_user_data (COGL_OBJECT (context), &extensions_key);
+      if (enabled_extensions)
+        return enabled_extensions;
+
+      enabled_extensions = (const char *) context->glGetString (GL_EXTENSIONS);
+
+      split_enabled_extensions = g_strsplit (enabled_extensions,
+                                             " ",
+                                             0 /* no max tokens */);
+      split_disabled_extensions = g_strsplit (disabled_extensions,
+                                              ",",
+                                              0 /* no max tokens */);
+      result = g_string_new (NULL);
+
+      for (e = split_enabled_extensions; *e; e++)
+        {
+          for (d = split_disabled_extensions; *d; d++)
+            if (!strcmp (*e, *d))
+              break;
+          if (*d == NULL)
+            {
+              if (result->len > 0)
+                g_string_append_c (result, ' ');
+              g_string_append (result, *e);
+            }
+        }
+
+      enabled_extensions = result->str;
+
+      g_string_free (result, FALSE);
+      g_strfreev (split_enabled_extensions);
+      g_strfreev (split_disabled_extensions);
+
+      cogl_object_set_user_data (COGL_OBJECT (context),
+                                 &extensions_key,
+                                 (void *) enabled_extensions,
+                                 (CoglUserDataDestroyCallback) g_free);
+
+      return enabled_extensions;
+    }
+  else
+#endif
+    return (const char *) context->glGetString (GL_EXTENSIONS);
+}
+
+const char *
+_cogl_context_get_gl_version (CoglContext *context)
+{
+#ifdef COGL_ENABLE_DEBUG
+  const char *version_override;
+
+  if ((version_override = g_getenv ("COGL_DEBUG_GL_VERSION")))
+    return version_override;
+#endif
+
+  return (const char *) context->glGetString (GL_VERSION);
+}
diff --git a/cogl/cogl-debug.c b/cogl/cogl-debug.c
index 5161b4c..d3aced0 100644
--- a/cogl/cogl-debug.c
+++ b/cogl/cogl-debug.c
@@ -171,17 +171,27 @@ _cogl_parse_debug_string (const char *value,
     }
   else if (g_ascii_strcasecmp (value, "help") == 0)
     {
-      g_printerr ("\n\n%28s\n", _("Supported debug values:"));
+      g_printerr ("\n\n%34s\n", _("Supported debug values:"));
 #define OPT(MASK_NAME, GROUP, NAME, NAME_FORMATTED, DESCRIPTION) \
-      g_printerr ("%28s %s\n", NAME ":", g_dgettext (GETTEXT_PACKAGE, \
+      g_printerr ("%34s %s\n", NAME ":", g_dgettext (GETTEXT_PACKAGE, \
                                                      DESCRIPTION));
 #include "cogl-debug-options.h"
-      g_printerr ("\n%28s\n", _("Special debug values:"));
+      g_printerr ("\n%34s\n", _("Special debug values:"));
       OPT (IGNORED, "ignored", "all", "ignored", \
            N_("Enables all non-behavioural debug options"));
       OPT (IGNORED, "ignored", "verbose", "ignored", \
            N_("Enables all non-behavioural debug options"));
 #undef OPT
+
+      g_printerr ("\n"
+                  "%34s\n"
+                  " COGL_DEBUG_DISABLE_GL_EXTENSIONS: %s\n"
+                  "            COGL_DEBUG_GL_VERSION: %s\n",
+                  _("Additional environment variables:"),
+                  _("Comma-separated list of GL extensions to pretend are "
+                    "disabled"),
+                  _("Override the GL version that Cogl will assume the driver "
+                    "supports"));
       exit (1);
     }
   else
diff --git a/cogl/cogl-gpu-info.c b/cogl/cogl-gpu-info.c
index 53e5bb2..8e64d04 100644
--- a/cogl/cogl-gpu-info.c
+++ b/cogl/cogl-gpu-info.c
@@ -482,7 +482,7 @@ _cogl_gpu_info_init (CoglContext *ctx,
   int i;
 
   strings.renderer_string = (const char *) ctx->glGetString (GL_RENDERER);
-  strings.version_string = (const char *) ctx->glGetString (GL_VERSION);
+  strings.version_string = _cogl_context_get_gl_version (ctx);
   strings.vendor_string = (const char *) ctx->glGetString (GL_VENDOR);
 
   /* Determine the driver package */
diff --git a/cogl/driver/gl/cogl-gl.c b/cogl/driver/gl/cogl-gl.c
index ce0c9bc..0f833eb 100644
--- a/cogl/driver/gl/cogl-gl.c
+++ b/cogl/driver/gl/cogl-gl.c
@@ -255,7 +255,7 @@ _cogl_get_gl_version (CoglContext *ctx,
   int major = 0, minor = 0;
 
   /* Get the OpenGL version number */
-  if ((version_string = (const char *) ctx->glGetString (GL_VERSION)) == NULL)
+  if ((version_string = _cogl_context_get_gl_version (ctx)) == NULL)
     return FALSE;
 
   /* Extract the major number */
@@ -303,7 +303,7 @@ check_gl_version (CoglContext *ctx,
   if (COGL_CHECK_GL_VERSION (major, minor, 1, 3))
     return TRUE;
 
-  gl_extensions = (const char*) ctx->glGetString (GL_EXTENSIONS);
+  gl_extensions = _cogl_context_get_gl_extensions (ctx);
 
   /* OpenGL 1.2 is only supported if we have the multitexturing
      extension */
@@ -362,8 +362,8 @@ _cogl_driver_update_features (CoglContext *ctx,
              "  GL_EXTENSIONS: %s",
              ctx->glGetString (GL_VENDOR),
              ctx->glGetString (GL_RENDERER),
-             ctx->glGetString (GL_VERSION),
-             ctx->glGetString (GL_EXTENSIONS));
+             _cogl_context_get_gl_version (ctx),
+             _cogl_context_get_gl_extensions (ctx));
 
   _cogl_get_gl_version (ctx, &gl_major, &gl_minor);
 
@@ -379,7 +379,7 @@ _cogl_driver_update_features (CoglContext *ctx,
   if (COGL_CHECK_GL_VERSION (gl_major, gl_minor, 1, 4))
     COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_MIRRORED_REPEAT, TRUE);
 
-  gl_extensions = (const char *)ctx->glGetString (GL_EXTENSIONS);
+  gl_extensions = _cogl_context_get_gl_extensions (ctx);
 
   _cogl_feature_check_ext_functions (ctx,
                                      gl_major,
diff --git a/cogl/driver/gles/cogl-gles.c b/cogl/driver/gles/cogl-gles.c
index 8f1e91d..d6a8feb 100644
--- a/cogl/driver/gles/cogl-gles.c
+++ b/cogl/driver/gles/cogl-gles.c
@@ -218,12 +218,12 @@ _cogl_driver_update_features (CoglContext *context,
              "  GL_EXTENSIONS: %s",
              context->glGetString (GL_VENDOR),
              context->glGetString (GL_RENDERER),
-             context->glGetString (GL_VERSION),
-             context->glGetString (GL_EXTENSIONS));
+             _cogl_context_get_gl_version (context),
+             _cogl_context_get_gl_extensions (context));
 
   _cogl_gpu_info_init (context, &context->gpu);
 
-  gl_extensions = (const char*) context->glGetString (GL_EXTENSIONS);
+  gl_extensions = _cogl_context_get_gl_extensions (context);
 
   _cogl_feature_check_ext_functions (context,
                                      -1 /* GL major version */,
diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c
index 61cd335..418e728 100644
--- a/cogl/winsys/cogl-winsys-wgl.c
+++ b/cogl/winsys/cogl-winsys-wgl.c
@@ -580,7 +580,7 @@ get_wgl_extensions_string (HDC dc)
      extensions isn't supported then we can at least fake it to
      support the swap control extension */
   if (_cogl_check_extension ("WGL_EXT_swap_control",
-                             (char *) ctx->glGetString (GL_EXTENSIONS)))
+                             _cogl_context_get_gl_extensions (ctx)))
     return "WGL_EXT_swap_control";
 
   return NULL;
-- 
1.7.11.3.g3c3efa5



More information about the Cogl mailing list