remove duplicate declaration
[mesa.git] / src / mesa / main / debug.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.5
5 *
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "mtypes.h"
27 #include "context.h"
28 #include "imports.h"
29 #include "debug.h"
30 #include "get.h"
31
32 /**
33 * Primitive names
34 */
35 const char *_mesa_prim_name[GL_POLYGON+4] = {
36 "GL_POINTS",
37 "GL_LINES",
38 "GL_LINE_LOOP",
39 "GL_LINE_STRIP",
40 "GL_TRIANGLES",
41 "GL_TRIANGLE_STRIP",
42 "GL_TRIANGLE_FAN",
43 "GL_QUADS",
44 "GL_QUAD_STRIP",
45 "GL_POLYGON",
46 "outside begin/end",
47 "inside unkown primitive",
48 "unknown state"
49 };
50
51 void
52 _mesa_print_state( const char *msg, GLuint state )
53 {
54 _mesa_debug(NULL,
55 "%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",
56 msg,
57 state,
58 (state & _NEW_MODELVIEW) ? "ctx->ModelView, " : "",
59 (state & _NEW_PROJECTION) ? "ctx->Projection, " : "",
60 (state & _NEW_TEXTURE_MATRIX) ? "ctx->TextureMatrix, " : "",
61 (state & _NEW_COLOR_MATRIX) ? "ctx->ColorMatrix, " : "",
62 (state & _NEW_ACCUM) ? "ctx->Accum, " : "",
63 (state & _NEW_COLOR) ? "ctx->Color, " : "",
64 (state & _NEW_DEPTH) ? "ctx->Depth, " : "",
65 (state & _NEW_EVAL) ? "ctx->Eval/EvalMap, " : "",
66 (state & _NEW_FOG) ? "ctx->Fog, " : "",
67 (state & _NEW_HINT) ? "ctx->Hint, " : "",
68 (state & _NEW_LIGHT) ? "ctx->Light, " : "",
69 (state & _NEW_LINE) ? "ctx->Line, " : "",
70 (state & _NEW_PIXEL) ? "ctx->Pixel, " : "",
71 (state & _NEW_POINT) ? "ctx->Point, " : "",
72 (state & _NEW_POLYGON) ? "ctx->Polygon, " : "",
73 (state & _NEW_POLYGONSTIPPLE) ? "ctx->PolygonStipple, " : "",
74 (state & _NEW_SCISSOR) ? "ctx->Scissor, " : "",
75 (state & _NEW_TEXTURE) ? "ctx->Texture, " : "",
76 (state & _NEW_TRANSFORM) ? "ctx->Transform, " : "",
77 (state & _NEW_VIEWPORT) ? "ctx->Viewport, " : "",
78 (state & _NEW_PACKUNPACK) ? "ctx->Pack/Unpack, " : "",
79 (state & _NEW_ARRAY) ? "ctx->Array, " : "",
80 (state & _NEW_RENDERMODE) ? "ctx->RenderMode, " : "",
81 (state & _NEW_BUFFERS) ? "ctx->Visual, ctx->DrawBuffer,, " : "");
82 }
83
84
85
86 void
87 _mesa_print_tri_caps( const char *name, GLuint flags )
88 {
89 _mesa_debug(NULL,
90 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
91 name,
92 flags,
93 (flags & DD_FLATSHADE) ? "flat-shade, " : "",
94 (flags & DD_SEPARATE_SPECULAR) ? "separate-specular, " : "",
95 (flags & DD_TRI_LIGHT_TWOSIDE) ? "tri-light-twoside, " : "",
96 (flags & DD_TRI_UNFILLED) ? "tri-unfilled, " : "",
97 (flags & DD_TRI_STIPPLE) ? "tri-stipple, " : "",
98 (flags & DD_TRI_OFFSET) ? "tri-offset, " : "",
99 (flags & DD_TRI_SMOOTH) ? "tri-smooth, " : "",
100 (flags & DD_LINE_SMOOTH) ? "line-smooth, " : "",
101 (flags & DD_LINE_STIPPLE) ? "line-stipple, " : "",
102 (flags & DD_LINE_WIDTH) ? "line-wide, " : "",
103 (flags & DD_POINT_SMOOTH) ? "point-smooth, " : "",
104 (flags & DD_POINT_SIZE) ? "point-size, " : "",
105 (flags & DD_POINT_ATTEN) ? "point-atten, " : "",
106 (flags & DD_TRI_CULL_FRONT_BACK) ? "cull-all, " : ""
107 );
108 }
109
110
111 void
112 _mesa_check_driver_hooks( GLcontext *ctx )
113 {
114 ASSERT(ctx->Driver.GetString);
115 ASSERT(ctx->Driver.UpdateState);
116 ASSERT(ctx->Driver.Clear);
117 ASSERT(ctx->Driver.GetBufferSize);
118 if (ctx->Visual.accumRedBits > 0) {
119 ASSERT(ctx->Driver.Accum);
120 }
121 ASSERT(ctx->Driver.DrawPixels);
122 ASSERT(ctx->Driver.ReadPixels);
123 ASSERT(ctx->Driver.CopyPixels);
124 ASSERT(ctx->Driver.Bitmap);
125 ASSERT(ctx->Driver.ResizeBuffers);
126 ASSERT(ctx->Driver.TexImage1D);
127 ASSERT(ctx->Driver.TexImage2D);
128 ASSERT(ctx->Driver.TexImage3D);
129 ASSERT(ctx->Driver.TexSubImage1D);
130 ASSERT(ctx->Driver.TexSubImage2D);
131 ASSERT(ctx->Driver.TexSubImage3D);
132 ASSERT(ctx->Driver.CopyTexImage1D);
133 ASSERT(ctx->Driver.CopyTexImage2D);
134 ASSERT(ctx->Driver.CopyTexSubImage1D);
135 ASSERT(ctx->Driver.CopyTexSubImage2D);
136 ASSERT(ctx->Driver.CopyTexSubImage3D);
137 if (ctx->Extensions.ARB_texture_compression) {
138 #if 0 /* HW drivers need these, but not SW rasterizers */
139 ASSERT(ctx->Driver.CompressedTexImage1D);
140 ASSERT(ctx->Driver.CompressedTexImage2D);
141 ASSERT(ctx->Driver.CompressedTexImage3D);
142 ASSERT(ctx->Driver.CompressedTexSubImage1D);
143 ASSERT(ctx->Driver.CompressedTexSubImage2D);
144 ASSERT(ctx->Driver.CompressedTexSubImage3D);
145 #endif
146 }
147 }
148
149 /**
150 * Print information about this Mesa version and build options.
151 */
152 void _mesa_print_info( void )
153 {
154 _mesa_debug(NULL, "Mesa GL_VERSION = %s\n",
155 (char *) _mesa_GetString(GL_VERSION));
156 _mesa_debug(NULL, "Mesa GL_RENDERER = %s\n",
157 (char *) _mesa_GetString(GL_RENDERER));
158 _mesa_debug(NULL, "Mesa GL_VENDOR = %s\n",
159 (char *) _mesa_GetString(GL_VENDOR));
160 _mesa_debug(NULL, "Mesa GL_EXTENSIONS = %s\n",
161 (char *) _mesa_GetString(GL_EXTENSIONS));
162 #if defined(THREADS)
163 _mesa_debug(NULL, "Mesa thread-safe: YES\n");
164 #else
165 _mesa_debug(NULL, "Mesa thread-safe: NO\n");
166 #endif
167 #if defined(USE_X86_ASM)
168 _mesa_debug(NULL, "Mesa x86-optimized: YES\n");
169 #else
170 _mesa_debug(NULL, "Mesa x86-optimized: NO\n");
171 #endif
172 #if defined(USE_SPARC_ASM)
173 _mesa_debug(NULL, "Mesa sparc-optimized: YES\n");
174 #else
175 _mesa_debug(NULL, "Mesa sparc-optimized: NO\n");
176 #endif
177 }
178
179
180 /**
181 * Set the debugging flags.
182 *
183 * \param debug debug string
184 *
185 * If compiled with debugging support then search for keywords in \p debug and
186 * enables the verbose debug output of the respective feature.
187 */
188 static void add_debug_flags( const char *debug )
189 {
190 #ifdef MESA_DEBUG
191 if (_mesa_strstr(debug, "varray"))
192 MESA_VERBOSE |= VERBOSE_VARRAY;
193
194 if (_mesa_strstr(debug, "tex"))
195 MESA_VERBOSE |= VERBOSE_TEXTURE;
196
197 if (_mesa_strstr(debug, "imm"))
198 MESA_VERBOSE |= VERBOSE_IMMEDIATE;
199
200 if (_mesa_strstr(debug, "pipe"))
201 MESA_VERBOSE |= VERBOSE_PIPELINE;
202
203 if (_mesa_strstr(debug, "driver"))
204 MESA_VERBOSE |= VERBOSE_DRIVER;
205
206 if (_mesa_strstr(debug, "state"))
207 MESA_VERBOSE |= VERBOSE_STATE;
208
209 if (_mesa_strstr(debug, "api"))
210 MESA_VERBOSE |= VERBOSE_API;
211
212 if (_mesa_strstr(debug, "list"))
213 MESA_VERBOSE |= VERBOSE_DISPLAY_LIST;
214
215 if (_mesa_strstr(debug, "lighting"))
216 MESA_VERBOSE |= VERBOSE_LIGHTING;
217
218 /* Debug flag:
219 */
220 if (_mesa_strstr(debug, "flush"))
221 MESA_DEBUG_FLAGS |= DEBUG_ALWAYS_FLUSH;
222 #endif
223 }
224
225
226 void
227 _mesa_init_debug( GLcontext *ctx )
228 {
229 char *c;
230
231 /* For debug/development only */
232 ctx->FirstTimeCurrent = GL_TRUE;
233
234 /* Dither disable */
235 ctx->NoDither = _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
236 if (ctx->NoDither) {
237 if (_mesa_getenv("MESA_DEBUG")) {
238 _mesa_debug(ctx, "MESA_NO_DITHER set - dithering disabled\n");
239 }
240 ctx->Color.DitherFlag = GL_FALSE;
241 }
242
243 c = _mesa_getenv("MESA_DEBUG");
244 if (c)
245 add_debug_flags(c);
246
247 c = _mesa_getenv("MESA_VERBOSE");
248 if (c)
249 add_debug_flags(c);
250 }
251