diff options
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r-- | src/mesa/main/imports.c | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 20b8342064..2ac93a5237 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -979,6 +979,35 @@ _mesa_vsprintf( char *str, const char *fmt, va_list args ) /** \name Diagnostics */ /*@{*/ +static void +output_if_debug(const char *prefixString, const char *outputString) +{ + static int debug = -1; + + /* Check the MESA_DEBUG environment variable if it hasn't + * been checked yet. We only have to check it once... + */ + if (debug == -1) { + char *env = _mesa_getenv("MESA_DEBUG"); + + /* In a debug build, we print warning messages *unless* + * MESA_DEBUG is 0. In a non-debug build, we don't + * print warning messages *unless* MESA_DEBUG is + * set *to any value*. + */ +#ifdef DEBUG + debug = (env != NULL && _mesa_atoi(env) == 0) ? 0 : 1; +#else + debug = (env != NULL) ? 1 : 0; +#endif + } + + /* Now only print the string if we're required to do so. */ + if (debug) { + fprintf(stderr, "%s: %s\n", prefixString, outputString); + } +} + /** * Report a warning (a recoverable error condition) to stderr if * either DEBUG is defined or the MESA_DEBUG env var is set. @@ -989,21 +1018,14 @@ _mesa_vsprintf( char *str, const char *fmt, va_list args ) void _mesa_warning( GLcontext *ctx, const char *fmtString, ... ) { - GLboolean debug; char str[MAXSTRING]; va_list args; (void) ctx; va_start( args, fmtString ); (void) vsnprintf( str, MAXSTRING, fmtString, args ); va_end( args ); -#ifdef DEBUG - debug = GL_TRUE; /* always print warning */ -#else - debug = _mesa_getenv("MESA_DEBUG") ? GL_TRUE : GL_FALSE; -#endif - if (debug) { - fprintf(stderr, "Mesa warning: %s\n", str); - } + + output_if_debug("Mesa warning", str); } /** @@ -1123,7 +1145,7 @@ _mesa_debug( const GLcontext *ctx, const char *fmtString, ... ) va_start(args, fmtString); vsnprintf(s, MAXSTRING, fmtString, args); va_end(args); - fprintf(stderr, "Mesa: %s", s); + output_if_debug("Mesa", s); #endif /* DEBUG */ (void) ctx; (void) fmtString; |