2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "texformat.h"
38 const char *_mesa_prim_name
[GL_POLYGON
+4] = {
50 "inside unkown primitive",
55 _mesa_print_state( const char *msg
, GLuint state
)
58 "%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",
61 (state
& _NEW_MODELVIEW
) ? "ctx->ModelView, " : "",
62 (state
& _NEW_PROJECTION
) ? "ctx->Projection, " : "",
63 (state
& _NEW_TEXTURE_MATRIX
) ? "ctx->TextureMatrix, " : "",
64 (state
& _NEW_COLOR_MATRIX
) ? "ctx->ColorMatrix, " : "",
65 (state
& _NEW_ACCUM
) ? "ctx->Accum, " : "",
66 (state
& _NEW_COLOR
) ? "ctx->Color, " : "",
67 (state
& _NEW_DEPTH
) ? "ctx->Depth, " : "",
68 (state
& _NEW_EVAL
) ? "ctx->Eval/EvalMap, " : "",
69 (state
& _NEW_FOG
) ? "ctx->Fog, " : "",
70 (state
& _NEW_HINT
) ? "ctx->Hint, " : "",
71 (state
& _NEW_LIGHT
) ? "ctx->Light, " : "",
72 (state
& _NEW_LINE
) ? "ctx->Line, " : "",
73 (state
& _NEW_PIXEL
) ? "ctx->Pixel, " : "",
74 (state
& _NEW_POINT
) ? "ctx->Point, " : "",
75 (state
& _NEW_POLYGON
) ? "ctx->Polygon, " : "",
76 (state
& _NEW_POLYGONSTIPPLE
) ? "ctx->PolygonStipple, " : "",
77 (state
& _NEW_SCISSOR
) ? "ctx->Scissor, " : "",
78 (state
& _NEW_TEXTURE
) ? "ctx->Texture, " : "",
79 (state
& _NEW_TRANSFORM
) ? "ctx->Transform, " : "",
80 (state
& _NEW_VIEWPORT
) ? "ctx->Viewport, " : "",
81 (state
& _NEW_PACKUNPACK
) ? "ctx->Pack/Unpack, " : "",
82 (state
& _NEW_ARRAY
) ? "ctx->Array, " : "",
83 (state
& _NEW_RENDERMODE
) ? "ctx->RenderMode, " : "",
84 (state
& _NEW_BUFFERS
) ? "ctx->Visual, ctx->DrawBuffer,, " : "");
90 _mesa_print_tri_caps( const char *name
, GLuint flags
)
93 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
96 (flags
& DD_FLATSHADE
) ? "flat-shade, " : "",
97 (flags
& DD_SEPARATE_SPECULAR
) ? "separate-specular, " : "",
98 (flags
& DD_TRI_LIGHT_TWOSIDE
) ? "tri-light-twoside, " : "",
99 (flags
& DD_TRI_TWOSTENCIL
) ? "tri-twostencil, " : "",
100 (flags
& DD_TRI_UNFILLED
) ? "tri-unfilled, " : "",
101 (flags
& DD_TRI_STIPPLE
) ? "tri-stipple, " : "",
102 (flags
& DD_TRI_OFFSET
) ? "tri-offset, " : "",
103 (flags
& DD_TRI_SMOOTH
) ? "tri-smooth, " : "",
104 (flags
& DD_LINE_SMOOTH
) ? "line-smooth, " : "",
105 (flags
& DD_LINE_STIPPLE
) ? "line-stipple, " : "",
106 (flags
& DD_LINE_WIDTH
) ? "line-wide, " : "",
107 (flags
& DD_POINT_SMOOTH
) ? "point-smooth, " : "",
108 (flags
& DD_POINT_SIZE
) ? "point-size, " : "",
109 (flags
& DD_POINT_ATTEN
) ? "point-atten, " : "",
110 (flags
& DD_TRI_CULL_FRONT_BACK
) ? "cull-all, " : ""
116 * Print information about this Mesa version and build options.
118 void _mesa_print_info( void )
120 _mesa_debug(NULL
, "Mesa GL_VERSION = %s\n",
121 (char *) _mesa_GetString(GL_VERSION
));
122 _mesa_debug(NULL
, "Mesa GL_RENDERER = %s\n",
123 (char *) _mesa_GetString(GL_RENDERER
));
124 _mesa_debug(NULL
, "Mesa GL_VENDOR = %s\n",
125 (char *) _mesa_GetString(GL_VENDOR
));
126 _mesa_debug(NULL
, "Mesa GL_EXTENSIONS = %s\n",
127 (char *) _mesa_GetString(GL_EXTENSIONS
));
129 _mesa_debug(NULL
, "Mesa thread-safe: YES\n");
131 _mesa_debug(NULL
, "Mesa thread-safe: NO\n");
133 #if defined(USE_X86_ASM)
134 _mesa_debug(NULL
, "Mesa x86-optimized: YES\n");
136 _mesa_debug(NULL
, "Mesa x86-optimized: NO\n");
138 #if defined(USE_SPARC_ASM)
139 _mesa_debug(NULL
, "Mesa sparc-optimized: YES\n");
141 _mesa_debug(NULL
, "Mesa sparc-optimized: NO\n");
147 * Set the debugging flags.
149 * \param debug debug string
151 * If compiled with debugging support then search for keywords in \p debug and
152 * enables the verbose debug output of the respective feature.
154 static void add_debug_flags( const char *debug
)
157 struct debug_option
{
161 static const struct debug_option debug_opt
[] = {
162 { "varray", VERBOSE_VARRAY
},
163 { "tex", VERBOSE_TEXTURE
},
164 { "imm", VERBOSE_IMMEDIATE
},
165 { "pipe", VERBOSE_PIPELINE
},
166 { "driver", VERBOSE_DRIVER
},
167 { "state", VERBOSE_STATE
},
168 { "api", VERBOSE_API
},
169 { "list", VERBOSE_DISPLAY_LIST
},
170 { "lighting", VERBOSE_LIGHTING
},
171 { "disassem", VERBOSE_DISASSEM
}
176 for (i
= 0; i
< Elements(debug_opt
); i
++) {
177 if (_mesa_strstr(debug
, debug_opt
[i
].name
))
178 MESA_VERBOSE
|= debug_opt
[i
].flag
;
183 if (_mesa_strstr(debug
, "flush"))
184 MESA_DEBUG_FLAGS
|= DEBUG_ALWAYS_FLUSH
;
186 #if defined(_FPU_GETCW) && defined(_FPU_SETCW)
187 if (_mesa_strstr(debug
, "fpexceptions")) {
188 /* raise FP exceptions */
191 mask
&= ~(_FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
192 | _FPU_MASK_OM
| _FPU_MASK_UM
);
204 _mesa_init_debug( GLcontext
*ctx
)
209 ctx
->NoDither
= _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
211 if (_mesa_getenv("MESA_DEBUG")) {
212 _mesa_debug(ctx
, "MESA_NO_DITHER set - dithering disabled\n");
214 ctx
->Color
.DitherFlag
= GL_FALSE
;
217 c
= _mesa_getenv("MESA_DEBUG");
221 c
= _mesa_getenv("MESA_VERBOSE");
231 write_ppm(const char *filename
, const GLubyte
*buffer
, int width
, int height
,
232 int comps
, int rcomp
, int gcomp
, int bcomp
)
234 FILE *f
= fopen( filename
, "w" );
237 const GLubyte
*ptr
= buffer
;
239 fprintf(f
,"# ppm-file created by osdemo.c\n");
240 fprintf(f
,"%i %i\n", width
,height
);
243 f
= fopen( filename
, "ab" ); /* reopen in binary append mode */
244 for (y
=height
-1; y
>=0; y
--) {
245 for (x
=0; x
<width
; x
++) {
246 i
= (y
*width
+ x
) * comps
;
247 fputc(ptr
[i
+rcomp
], f
); /* write red */
248 fputc(ptr
[i
+gcomp
], f
); /* write green */
249 fputc(ptr
[i
+bcomp
], f
); /* write blue */
258 * Write level[0] image to a ppm file.
261 write_texture_image(struct gl_texture_object
*texObj
)
263 const struct gl_texture_image
*img
= texObj
->Image
[0][0];
268 sprintf(s
, "/tmp/teximage%u.ppm", texObj
->Name
);
270 switch (img
->TexFormat
->MesaFormat
) {
271 case MESA_FORMAT_RGBA8888
:
272 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 4, 3, 2, 1);
274 case MESA_FORMAT_ARGB8888
:
275 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 4, 2, 1, 0);
278 printf("XXXX unsupported mesa tex format %d in %s\n",
279 img
->TexFormat
->MesaFormat
, __FUNCTION__
);
285 static GLboolean DumpImages
;
289 dump_texture_cb(GLuint id
, void *data
, void *userData
)
291 struct gl_texture_object
*texObj
= (struct gl_texture_object
*) data
;
295 printf("Texture %u\n", texObj
->Name
);
296 printf(" Target 0x%x\n", texObj
->Target
);
297 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
298 struct gl_texture_image
*texImg
= texObj
->Image
[0][i
];
300 printf(" Image %u: %d x %d x %d at %p\n", i
,
301 texImg
->Width
, texImg
->Height
, texImg
->Depth
, texImg
->Data
);
302 if (DumpImages
&& i
== 0) {
303 write_texture_image(texObj
);
311 * Print basic info about all texture objext to stdout.
312 * If dumpImages is true, write PPM of level[0] image to a file.
315 _mesa_dump_textures(GLboolean dumpImages
)
317 GET_CURRENT_CONTEXT(ctx
);
318 DumpImages
= dumpImages
;
319 _mesa_HashDeleteAll(ctx
->Shared
->TexObjects
, dump_texture_cb
, ctx
);