diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index c3f4c63df..5096767c5 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -1500,9 +1500,12 @@ clutter_init_with_args (int *argc, if (argc && *argc > 0 && *argv) g_set_prgname ((*argv)[0]); - group = clutter_get_option_group (); context = g_option_context_new (parameter_string); + group = clutter_get_option_group (); + g_option_context_add_group (context, group); + + group = cogl_get_option_group (); g_option_context_add_group (context, group); if (entries) @@ -1536,7 +1539,7 @@ clutter_parse_args (int *argc, char ***argv) { GOptionContext *option_context; - GOptionGroup *clutter_group; + GOptionGroup *clutter_group, *cogl_group; GError *error = NULL; gboolean ret = TRUE; @@ -1552,6 +1555,9 @@ clutter_parse_args (int *argc, clutter_group = clutter_get_option_group (); g_option_context_set_main_group (option_context, clutter_group); + cogl_group = cogl_get_option_group (); + g_option_context_add_group (option_context, cogl_group); + if (!g_option_context_parse (option_context, argc, argv, &error)) { if (error) diff --git a/clutter/cogl/cogl-debug.h b/clutter/cogl/cogl-debug.h new file mode 100644 index 000000000..815dcbc4f --- /dev/null +++ b/clutter/cogl/cogl-debug.h @@ -0,0 +1,45 @@ +#ifndef __COGL_DEBUG_H__ +#define __COGL_DEBUG_H__ + +#include + +G_BEGIN_DECLS + +typedef enum { + COGL_DEBUG_MISC = 1 << 0, + COGL_DEBUG_TEXTURE = 1 << 1, + COGL_DEBUG_MATERIAL = 1 << 2, + COGL_DEBUG_SHADER = 1 << 3, + COGL_DEBUG_OFFSCREEN = 1 << 4, + COGL_DEBUG_DRAW = 1 << 5 +} CoglDebugFlags; + +#ifdef COGL_ENABLE_DEBUG + +#ifdef __GNUC__ +#define COGL_NOTE(type,x,a...) G_STMT_START { \ + if (cogl_debug_flags & COGL_DEBUG_##type) { \ + g_message ("[" #type "] " G_STRLOC ": " x, ##a); \ + } } G_STMT_END + +#else +#define COGL_NOTE(type,...) G_STMT_START { \ + if (cogl_debug_flags & COGL_DEBUG_##type) { \ + gchar *_fmt = g_strdup_printf (__VA_ARGS__); \ + g_message ("[" #type "] " G_STRLOC ": %s", _fmt); \ + g_free (_fmt); \ + } } G_STMT_END + +#endif /* __GNUC__ */ + +#else /* !COGL_ENABLE_DEBUG */ + +#define COGL_NOTE(type,...) + +#endif /* COGL_ENABLE_DEBUG */ + +extern guint cogl_debug_flags; + +G_END_DECLS + +#endif /* __COGL_DEBUG_H__ */ diff --git a/clutter/cogl/cogl.h.in b/clutter/cogl/cogl.h.in index 06c32a546..f1388537a 100644 --- a/clutter/cogl/cogl.h.in +++ b/clutter/cogl/cogl.h.in @@ -26,10 +26,10 @@ #ifndef __COGL_H__ #define __COGL_H__ -#define __COGL_H_INSIDE__ - #include +#define __COGL_H_INSIDE__ + #include #include @@ -43,6 +43,7 @@ #include #include #include +#include #include G_BEGIN_DECLS @@ -70,6 +71,19 @@ gboolean cogl_create_context (void); */ void cogl_destroy_context (void); +/** + * cogl_get_option_group: + * + * Retrieves the #GOptionGroup used by COGL to parse the command + * line options. Clutter uses this to handle the COGL command line + * options during its initialization process. + * + * Return value: a #GOptionGroup + * + * Since: 1.0 + */ +GOptionGroup * cogl_get_option_group (void); + /* Misc */ /** * cogl_get_features: diff --git a/clutter/cogl/common/Makefile.am b/clutter/cogl/common/Makefile.am index 8777defc6..7a322326a 100644 --- a/clutter/cogl/common/Makefile.am +++ b/clutter/cogl/common/Makefile.am @@ -35,4 +35,5 @@ libclutter_cogl_common_la_SOURCES = \ cogl-vertex-buffer.c \ cogl-matrix.c \ cogl-material.c \ - cogl-material-private.h + cogl-material-private.h \ + cogl-debug.c diff --git a/clutter/cogl/common/cogl-debug.c b/clutter/cogl/common/cogl-debug.c new file mode 100644 index 000000000..863da3b4a --- /dev/null +++ b/clutter/cogl/common/cogl-debug.c @@ -0,0 +1,98 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "cogl-debug.h" + +#ifdef COGL_ENABLE_DEBUG +static const GDebugKey cogl_debug_keys[] = { + { "misc", COGL_DEBUG_MISC }, + { "texture", COGL_DEBUG_TEXTURE }, + { "material", COGL_DEBUG_MATERIAL }, + { "shader", COGL_DEBUG_SHADER }, + { "offscreen", COGL_DEBUG_OFFSCREEN }, + { "draw", COGL_DEBUG_DRAW } +}; + +static const gint n_cogl_debug_keys = G_N_ELEMENTS (cogl_debug_keys); +#endif /* COGL_ENABLE_DEBUG */ + +guint cogl_debug_flags = 0; + +#ifdef COGL_ENABLE_DEBUG +static gboolean +cogl_arg_debug_cb (const char *key, + const char *value, + gpointer user_data) +{ + cogl_debug_flags |= + g_parse_debug_string (value, + cogl_debug_keys, + n_cogl_debug_keys); + return TRUE; +} + +static gboolean +cogl_arg_no_debug_cb (const char *key, + const char *value, + gpointer user_data) +{ + cogl_debug_flags &= + ~g_parse_debug_string (value, + cogl_debug_keys, + n_cogl_debug_keys); + return TRUE; +} +#endif /* CLUTTER_ENABLE_DEBUG */ + +static GOptionEntry cogl_args[] = { +#ifdef COGL_ENABLE_DEBUG + { "cogl-debug", 0, 0, G_OPTION_ARG_CALLBACK, cogl_arg_debug_cb, + N_("COGL debugging flags to set"), "FLAGS" }, + { "cogl-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, cogl_arg_no_debug_cb, + N_("COGL debugging flags to unset"), "FLAGS" }, +#endif /* COGL_ENABLE_DEBUG */ + { NULL, }, +}; + +static gboolean +pre_parse_hook (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + const char *env_string; + +#ifdef COGL_ENABLE_DEBUG + env_string = g_getenv ("COGL_DEBUG"); + if (env_string != NULL) + { + cogl_debug_flags = + g_parse_debug_string (env_string, + cogl_debug_keys, + n_cogl_debug_keys); + env_string = NULL; + } +#endif /* COGL_ENABLE_DEBUG */ + + return TRUE; +} + +GOptionGroup * +cogl_get_option_group (void) +{ + GOptionGroup *group; + + group = g_option_group_new ("cogl", + _("COGL Options"), + _("Show COGL options"), + NULL, NULL); + + g_option_group_set_parse_hooks (group, pre_parse_hook, NULL); + g_option_group_add_entries (group, cogl_args); + g_option_group_set_translation_domain (group, GETTEXT_PACKAGE); + + return group; +} diff --git a/clutter/cogl/gl/Makefile.am b/clutter/cogl/gl/Makefile.am index 394629ce9..12e2ee92a 100644 --- a/clutter/cogl/gl/Makefile.am +++ b/clutter/cogl/gl/Makefile.am @@ -12,7 +12,8 @@ libclutterinclude_HEADERS = \ $(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h \ $(top_builddir)/clutter/cogl/cogl-material.h \ - $(top_builddir)/clutter/cogl/cogl-matrix.h + $(top_builddir)/clutter/cogl/cogl-matrix.h \ + $(top_builddir)/clutter/cogl/cogl-debug.h INCLUDES = \ -I$(top_srcdir) \ @@ -44,6 +45,7 @@ libclutter_cogl_la_SOURCES = \ $(top_builddir)/clutter/cogl/cogl-shader.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-types.h \ + $(top_builddir)/clutter/cogl/cogl-debug.h \ cogl-internal.h \ cogl-texture-private.h \ cogl-fbo.h \ diff --git a/clutter/cogl/gles/Makefile.am b/clutter/cogl/gles/Makefile.am index a33fbbe5d..1ec4ae789 100644 --- a/clutter/cogl/gles/Makefile.am +++ b/clutter/cogl/gles/Makefile.am @@ -12,7 +12,8 @@ libclutterinclude_HEADERS = \ $(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h \ $(top_builddir)/clutter/cogl/cogl-material.h \ - $(top_builddir)/clutter/cogl/cogl-matrix.h + $(top_builddir)/clutter/cogl/cogl-matrix.h \ + $(top_builddir)/clutter/cogl/cogl-debug.h INCLUDES = \ -I$(top_srcdir) \ @@ -44,6 +45,7 @@ libclutter_cogl_la_SOURCES = \ $(top_builddir)/clutter/cogl/cogl-shader.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-types.h \ + $(top_builddir)/clutter/cogl/cogl-debug.h \ cogl-internal.h \ cogl-texture-private.h \ cogl-fbo.h \ diff --git a/configure.ac b/configure.ac index 38c322817..7c6ed8d9e 100644 --- a/configure.ac +++ b/configure.ac @@ -569,12 +569,12 @@ AC_ARG_ENABLE(debug, if test "x$enable_debug" = "xyes"; then test "$cflags_set" = set || CFLAGS="$CFLAGS -g" - CLUTTER_DEBUG_CFLAGS="-DCLUTTER_ENABLE_DEBUG" + CLUTTER_DEBUG_CFLAGS="-DCLUTTER_ENABLE_DEBUG -DCOGL_ENABLE_DEBUG" else if test "x$enable_debug" = "xno"; then CLUTTER_DEBUG_CFLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS -DG_DISABLE_CAST_CHECKS" else # minimum - CLUTTER_DEBUG_CFLAGS="-DCLUTTER_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS" + CLUTTER_DEBUG_CFLAGS="-DCLUTTER_ENABLE_DEBUG -DCOGL_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS" fi fi