debug.c revision 7117f1b4
17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * Version: 6.5 47117f1b4Smrg * 57117f1b4Smrg * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. 67117f1b4Smrg * 77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 87117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 97117f1b4Smrg * to deal in the Software without restriction, including without limitation 107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 127117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 137117f1b4Smrg * 147117f1b4Smrg * The above copyright notice and this permission notice shall be included 157117f1b4Smrg * in all copies or substantial portions of the Software. 167117f1b4Smrg * 177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 207117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 217117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 227117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 237117f1b4Smrg */ 247117f1b4Smrg 257117f1b4Smrg#include "mtypes.h" 267117f1b4Smrg#include "context.h" 277117f1b4Smrg#include "imports.h" 287117f1b4Smrg#include "debug.h" 297117f1b4Smrg#include "get.h" 307117f1b4Smrg 317117f1b4Smrg/** 327117f1b4Smrg * Primitive names 337117f1b4Smrg */ 347117f1b4Smrgconst char *_mesa_prim_name[GL_POLYGON+4] = { 357117f1b4Smrg "GL_POINTS", 367117f1b4Smrg "GL_LINES", 377117f1b4Smrg "GL_LINE_LOOP", 387117f1b4Smrg "GL_LINE_STRIP", 397117f1b4Smrg "GL_TRIANGLES", 407117f1b4Smrg "GL_TRIANGLE_STRIP", 417117f1b4Smrg "GL_TRIANGLE_FAN", 427117f1b4Smrg "GL_QUADS", 437117f1b4Smrg "GL_QUAD_STRIP", 447117f1b4Smrg "GL_POLYGON", 457117f1b4Smrg "outside begin/end", 467117f1b4Smrg "inside unkown primitive", 477117f1b4Smrg "unknown state" 487117f1b4Smrg}; 497117f1b4Smrg 507117f1b4Smrgvoid 517117f1b4Smrg_mesa_print_state( const char *msg, GLuint state ) 527117f1b4Smrg{ 537117f1b4Smrg _mesa_debug(NULL, 547117f1b4Smrg "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 557117f1b4Smrg msg, 567117f1b4Smrg state, 577117f1b4Smrg (state & _NEW_MODELVIEW) ? "ctx->ModelView, " : "", 587117f1b4Smrg (state & _NEW_PROJECTION) ? "ctx->Projection, " : "", 597117f1b4Smrg (state & _NEW_TEXTURE_MATRIX) ? "ctx->TextureMatrix, " : "", 607117f1b4Smrg (state & _NEW_COLOR_MATRIX) ? "ctx->ColorMatrix, " : "", 617117f1b4Smrg (state & _NEW_ACCUM) ? "ctx->Accum, " : "", 627117f1b4Smrg (state & _NEW_COLOR) ? "ctx->Color, " : "", 637117f1b4Smrg (state & _NEW_DEPTH) ? "ctx->Depth, " : "", 647117f1b4Smrg (state & _NEW_EVAL) ? "ctx->Eval/EvalMap, " : "", 657117f1b4Smrg (state & _NEW_FOG) ? "ctx->Fog, " : "", 667117f1b4Smrg (state & _NEW_HINT) ? "ctx->Hint, " : "", 677117f1b4Smrg (state & _NEW_LIGHT) ? "ctx->Light, " : "", 687117f1b4Smrg (state & _NEW_LINE) ? "ctx->Line, " : "", 697117f1b4Smrg (state & _NEW_PIXEL) ? "ctx->Pixel, " : "", 707117f1b4Smrg (state & _NEW_POINT) ? "ctx->Point, " : "", 717117f1b4Smrg (state & _NEW_POLYGON) ? "ctx->Polygon, " : "", 727117f1b4Smrg (state & _NEW_POLYGONSTIPPLE) ? "ctx->PolygonStipple, " : "", 737117f1b4Smrg (state & _NEW_SCISSOR) ? "ctx->Scissor, " : "", 747117f1b4Smrg (state & _NEW_TEXTURE) ? "ctx->Texture, " : "", 757117f1b4Smrg (state & _NEW_TRANSFORM) ? "ctx->Transform, " : "", 767117f1b4Smrg (state & _NEW_VIEWPORT) ? "ctx->Viewport, " : "", 777117f1b4Smrg (state & _NEW_PACKUNPACK) ? "ctx->Pack/Unpack, " : "", 787117f1b4Smrg (state & _NEW_ARRAY) ? "ctx->Array, " : "", 797117f1b4Smrg (state & _NEW_RENDERMODE) ? "ctx->RenderMode, " : "", 807117f1b4Smrg (state & _NEW_BUFFERS) ? "ctx->Visual, ctx->DrawBuffer,, " : ""); 817117f1b4Smrg} 827117f1b4Smrg 837117f1b4Smrg 847117f1b4Smrg 857117f1b4Smrgvoid 867117f1b4Smrg_mesa_print_tri_caps( const char *name, GLuint flags ) 877117f1b4Smrg{ 887117f1b4Smrg _mesa_debug(NULL, 897117f1b4Smrg "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 907117f1b4Smrg name, 917117f1b4Smrg flags, 927117f1b4Smrg (flags & DD_FLATSHADE) ? "flat-shade, " : "", 937117f1b4Smrg (flags & DD_SEPARATE_SPECULAR) ? "separate-specular, " : "", 947117f1b4Smrg (flags & DD_TRI_LIGHT_TWOSIDE) ? "tri-light-twoside, " : "", 957117f1b4Smrg (flags & DD_TRI_TWOSTENCIL) ? "tri-twostencil, " : "", 967117f1b4Smrg (flags & DD_TRI_UNFILLED) ? "tri-unfilled, " : "", 977117f1b4Smrg (flags & DD_TRI_STIPPLE) ? "tri-stipple, " : "", 987117f1b4Smrg (flags & DD_TRI_OFFSET) ? "tri-offset, " : "", 997117f1b4Smrg (flags & DD_TRI_SMOOTH) ? "tri-smooth, " : "", 1007117f1b4Smrg (flags & DD_LINE_SMOOTH) ? "line-smooth, " : "", 1017117f1b4Smrg (flags & DD_LINE_STIPPLE) ? "line-stipple, " : "", 1027117f1b4Smrg (flags & DD_LINE_WIDTH) ? "line-wide, " : "", 1037117f1b4Smrg (flags & DD_POINT_SMOOTH) ? "point-smooth, " : "", 1047117f1b4Smrg (flags & DD_POINT_SIZE) ? "point-size, " : "", 1057117f1b4Smrg (flags & DD_POINT_ATTEN) ? "point-atten, " : "", 1067117f1b4Smrg (flags & DD_TRI_CULL_FRONT_BACK) ? "cull-all, " : "" 1077117f1b4Smrg ); 1087117f1b4Smrg} 1097117f1b4Smrg 1107117f1b4Smrg 1117117f1b4Smrg/** 1127117f1b4Smrg * Print information about this Mesa version and build options. 1137117f1b4Smrg */ 1147117f1b4Smrgvoid _mesa_print_info( void ) 1157117f1b4Smrg{ 1167117f1b4Smrg _mesa_debug(NULL, "Mesa GL_VERSION = %s\n", 1177117f1b4Smrg (char *) _mesa_GetString(GL_VERSION)); 1187117f1b4Smrg _mesa_debug(NULL, "Mesa GL_RENDERER = %s\n", 1197117f1b4Smrg (char *) _mesa_GetString(GL_RENDERER)); 1207117f1b4Smrg _mesa_debug(NULL, "Mesa GL_VENDOR = %s\n", 1217117f1b4Smrg (char *) _mesa_GetString(GL_VENDOR)); 1227117f1b4Smrg _mesa_debug(NULL, "Mesa GL_EXTENSIONS = %s\n", 1237117f1b4Smrg (char *) _mesa_GetString(GL_EXTENSIONS)); 1247117f1b4Smrg#if defined(THREADS) 1257117f1b4Smrg _mesa_debug(NULL, "Mesa thread-safe: YES\n"); 1267117f1b4Smrg#else 1277117f1b4Smrg _mesa_debug(NULL, "Mesa thread-safe: NO\n"); 1287117f1b4Smrg#endif 1297117f1b4Smrg#if defined(USE_X86_ASM) 1307117f1b4Smrg _mesa_debug(NULL, "Mesa x86-optimized: YES\n"); 1317117f1b4Smrg#else 1327117f1b4Smrg _mesa_debug(NULL, "Mesa x86-optimized: NO\n"); 1337117f1b4Smrg#endif 1347117f1b4Smrg#if defined(USE_SPARC_ASM) 1357117f1b4Smrg _mesa_debug(NULL, "Mesa sparc-optimized: YES\n"); 1367117f1b4Smrg#else 1377117f1b4Smrg _mesa_debug(NULL, "Mesa sparc-optimized: NO\n"); 1387117f1b4Smrg#endif 1397117f1b4Smrg} 1407117f1b4Smrg 1417117f1b4Smrg 1427117f1b4Smrg/** 1437117f1b4Smrg * Set the debugging flags. 1447117f1b4Smrg * 1457117f1b4Smrg * \param debug debug string 1467117f1b4Smrg * 1477117f1b4Smrg * If compiled with debugging support then search for keywords in \p debug and 1487117f1b4Smrg * enables the verbose debug output of the respective feature. 1497117f1b4Smrg */ 1507117f1b4Smrgstatic void add_debug_flags( const char *debug ) 1517117f1b4Smrg{ 1527117f1b4Smrg#ifdef DEBUG 1537117f1b4Smrg if (_mesa_strstr(debug, "varray")) 1547117f1b4Smrg MESA_VERBOSE |= VERBOSE_VARRAY; 1557117f1b4Smrg 1567117f1b4Smrg if (_mesa_strstr(debug, "tex")) 1577117f1b4Smrg MESA_VERBOSE |= VERBOSE_TEXTURE; 1587117f1b4Smrg 1597117f1b4Smrg if (_mesa_strstr(debug, "imm")) 1607117f1b4Smrg MESA_VERBOSE |= VERBOSE_IMMEDIATE; 1617117f1b4Smrg 1627117f1b4Smrg if (_mesa_strstr(debug, "pipe")) 1637117f1b4Smrg MESA_VERBOSE |= VERBOSE_PIPELINE; 1647117f1b4Smrg 1657117f1b4Smrg if (_mesa_strstr(debug, "driver")) 1667117f1b4Smrg MESA_VERBOSE |= VERBOSE_DRIVER; 1677117f1b4Smrg 1687117f1b4Smrg if (_mesa_strstr(debug, "state")) 1697117f1b4Smrg MESA_VERBOSE |= VERBOSE_STATE; 1707117f1b4Smrg 1717117f1b4Smrg if (_mesa_strstr(debug, "api")) 1727117f1b4Smrg MESA_VERBOSE |= VERBOSE_API; 1737117f1b4Smrg 1747117f1b4Smrg if (_mesa_strstr(debug, "list")) 1757117f1b4Smrg MESA_VERBOSE |= VERBOSE_DISPLAY_LIST; 1767117f1b4Smrg 1777117f1b4Smrg if (_mesa_strstr(debug, "lighting")) 1787117f1b4Smrg MESA_VERBOSE |= VERBOSE_LIGHTING; 1797117f1b4Smrg 1807117f1b4Smrg if (_mesa_strstr(debug, "disassem")) 1817117f1b4Smrg MESA_VERBOSE |= VERBOSE_DISASSEM; 1827117f1b4Smrg 1837117f1b4Smrg /* Debug flag: 1847117f1b4Smrg */ 1857117f1b4Smrg if (_mesa_strstr(debug, "flush")) 1867117f1b4Smrg MESA_DEBUG_FLAGS |= DEBUG_ALWAYS_FLUSH; 1877117f1b4Smrg 1887117f1b4Smrg#if defined(_FPU_GETCW) && defined(_FPU_SETCW) 1897117f1b4Smrg if (_mesa_strstr(debug, "fpexceptions")) { 1907117f1b4Smrg /* raise FP exceptions */ 1917117f1b4Smrg fpu_control_t mask; 1927117f1b4Smrg _FPU_GETCW(mask); 1937117f1b4Smrg mask &= ~(_FPU_MASK_IM | _FPU_MASK_DM | _FPU_MASK_ZM 1947117f1b4Smrg | _FPU_MASK_OM | _FPU_MASK_UM); 1957117f1b4Smrg _FPU_SETCW(mask); 1967117f1b4Smrg } 1977117f1b4Smrg#endif 1987117f1b4Smrg 1997117f1b4Smrg#else 2007117f1b4Smrg (void) debug; 2017117f1b4Smrg#endif 2027117f1b4Smrg} 2037117f1b4Smrg 2047117f1b4Smrg 2057117f1b4Smrgvoid 2067117f1b4Smrg_mesa_init_debug( GLcontext *ctx ) 2077117f1b4Smrg{ 2087117f1b4Smrg char *c; 2097117f1b4Smrg 2107117f1b4Smrg /* Dither disable */ 2117117f1b4Smrg ctx->NoDither = _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE; 2127117f1b4Smrg if (ctx->NoDither) { 2137117f1b4Smrg if (_mesa_getenv("MESA_DEBUG")) { 2147117f1b4Smrg _mesa_debug(ctx, "MESA_NO_DITHER set - dithering disabled\n"); 2157117f1b4Smrg } 2167117f1b4Smrg ctx->Color.DitherFlag = GL_FALSE; 2177117f1b4Smrg } 2187117f1b4Smrg 2197117f1b4Smrg c = _mesa_getenv("MESA_DEBUG"); 2207117f1b4Smrg if (c) 2217117f1b4Smrg add_debug_flags(c); 2227117f1b4Smrg 2237117f1b4Smrg c = _mesa_getenv("MESA_VERBOSE"); 2247117f1b4Smrg if (c) 2257117f1b4Smrg add_debug_flags(c); 2267117f1b4Smrg} 2277117f1b4Smrg 228