2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
34 #include "texformat.h"
40 const char *_mesa_prim_name
[GL_POLYGON
+4] = {
52 "inside unkown primitive",
57 _mesa_print_state( const char *msg
, GLuint state
)
60 "%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",
63 (state
& _NEW_MODELVIEW
) ? "ctx->ModelView, " : "",
64 (state
& _NEW_PROJECTION
) ? "ctx->Projection, " : "",
65 (state
& _NEW_TEXTURE_MATRIX
) ? "ctx->TextureMatrix, " : "",
66 (state
& _NEW_COLOR_MATRIX
) ? "ctx->ColorMatrix, " : "",
67 (state
& _NEW_ACCUM
) ? "ctx->Accum, " : "",
68 (state
& _NEW_COLOR
) ? "ctx->Color, " : "",
69 (state
& _NEW_DEPTH
) ? "ctx->Depth, " : "",
70 (state
& _NEW_EVAL
) ? "ctx->Eval/EvalMap, " : "",
71 (state
& _NEW_FOG
) ? "ctx->Fog, " : "",
72 (state
& _NEW_HINT
) ? "ctx->Hint, " : "",
73 (state
& _NEW_LIGHT
) ? "ctx->Light, " : "",
74 (state
& _NEW_LINE
) ? "ctx->Line, " : "",
75 (state
& _NEW_PIXEL
) ? "ctx->Pixel, " : "",
76 (state
& _NEW_POINT
) ? "ctx->Point, " : "",
77 (state
& _NEW_POLYGON
) ? "ctx->Polygon, " : "",
78 (state
& _NEW_POLYGONSTIPPLE
) ? "ctx->PolygonStipple, " : "",
79 (state
& _NEW_SCISSOR
) ? "ctx->Scissor, " : "",
80 (state
& _NEW_TEXTURE
) ? "ctx->Texture, " : "",
81 (state
& _NEW_TRANSFORM
) ? "ctx->Transform, " : "",
82 (state
& _NEW_VIEWPORT
) ? "ctx->Viewport, " : "",
83 (state
& _NEW_PACKUNPACK
) ? "ctx->Pack/Unpack, " : "",
84 (state
& _NEW_ARRAY
) ? "ctx->Array, " : "",
85 (state
& _NEW_RENDERMODE
) ? "ctx->RenderMode, " : "",
86 (state
& _NEW_BUFFERS
) ? "ctx->Visual, ctx->DrawBuffer,, " : "");
92 _mesa_print_tri_caps( const char *name
, GLuint flags
)
95 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
98 (flags
& DD_FLATSHADE
) ? "flat-shade, " : "",
99 (flags
& DD_SEPARATE_SPECULAR
) ? "separate-specular, " : "",
100 (flags
& DD_TRI_LIGHT_TWOSIDE
) ? "tri-light-twoside, " : "",
101 (flags
& DD_TRI_TWOSTENCIL
) ? "tri-twostencil, " : "",
102 (flags
& DD_TRI_UNFILLED
) ? "tri-unfilled, " : "",
103 (flags
& DD_TRI_STIPPLE
) ? "tri-stipple, " : "",
104 (flags
& DD_TRI_OFFSET
) ? "tri-offset, " : "",
105 (flags
& DD_TRI_SMOOTH
) ? "tri-smooth, " : "",
106 (flags
& DD_LINE_SMOOTH
) ? "line-smooth, " : "",
107 (flags
& DD_LINE_STIPPLE
) ? "line-stipple, " : "",
108 (flags
& DD_LINE_WIDTH
) ? "line-wide, " : "",
109 (flags
& DD_POINT_SMOOTH
) ? "point-smooth, " : "",
110 (flags
& DD_POINT_SIZE
) ? "point-size, " : "",
111 (flags
& DD_POINT_ATTEN
) ? "point-atten, " : "",
112 (flags
& DD_TRI_CULL_FRONT_BACK
) ? "cull-all, " : ""
118 * Print information about this Mesa version and build options.
120 void _mesa_print_info( void )
122 _mesa_debug(NULL
, "Mesa GL_VERSION = %s\n",
123 (char *) _mesa_GetString(GL_VERSION
));
124 _mesa_debug(NULL
, "Mesa GL_RENDERER = %s\n",
125 (char *) _mesa_GetString(GL_RENDERER
));
126 _mesa_debug(NULL
, "Mesa GL_VENDOR = %s\n",
127 (char *) _mesa_GetString(GL_VENDOR
));
128 _mesa_debug(NULL
, "Mesa GL_EXTENSIONS = %s\n",
129 (char *) _mesa_GetString(GL_EXTENSIONS
));
131 _mesa_debug(NULL
, "Mesa thread-safe: YES\n");
133 _mesa_debug(NULL
, "Mesa thread-safe: NO\n");
135 #if defined(USE_X86_ASM)
136 _mesa_debug(NULL
, "Mesa x86-optimized: YES\n");
138 _mesa_debug(NULL
, "Mesa x86-optimized: NO\n");
140 #if defined(USE_SPARC_ASM)
141 _mesa_debug(NULL
, "Mesa sparc-optimized: YES\n");
143 _mesa_debug(NULL
, "Mesa sparc-optimized: NO\n");
149 * Set the debugging flags.
151 * \param debug debug string
153 * If compiled with debugging support then search for keywords in \p debug and
154 * enables the verbose debug output of the respective feature.
156 static void add_debug_flags( const char *debug
)
159 struct debug_option
{
163 static const struct debug_option debug_opt
[] = {
164 { "varray", VERBOSE_VARRAY
},
165 { "tex", VERBOSE_TEXTURE
},
166 { "imm", VERBOSE_IMMEDIATE
},
167 { "pipe", VERBOSE_PIPELINE
},
168 { "driver", VERBOSE_DRIVER
},
169 { "state", VERBOSE_STATE
},
170 { "api", VERBOSE_API
},
171 { "list", VERBOSE_DISPLAY_LIST
},
172 { "lighting", VERBOSE_LIGHTING
},
173 { "disassem", VERBOSE_DISASSEM
}
178 for (i
= 0; i
< Elements(debug_opt
); i
++) {
179 if (_mesa_strstr(debug
, debug_opt
[i
].name
))
180 MESA_VERBOSE
|= debug_opt
[i
].flag
;
185 if (_mesa_strstr(debug
, "flush"))
186 MESA_DEBUG_FLAGS
|= DEBUG_ALWAYS_FLUSH
;
188 #if defined(_FPU_GETCW) && defined(_FPU_SETCW)
189 if (_mesa_strstr(debug
, "fpexceptions")) {
190 /* raise FP exceptions */
193 mask
&= ~(_FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
194 | _FPU_MASK_OM
| _FPU_MASK_UM
);
206 _mesa_init_debug( GLcontext
*ctx
)
211 ctx
->NoDither
= _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
213 if (_mesa_getenv("MESA_DEBUG")) {
214 _mesa_debug(ctx
, "MESA_NO_DITHER set - dithering disabled\n");
216 ctx
->Color
.DitherFlag
= GL_FALSE
;
219 c
= _mesa_getenv("MESA_DEBUG");
223 c
= _mesa_getenv("MESA_VERBOSE");
233 write_ppm(const char *filename
, const GLubyte
*buffer
, int width
, int height
,
234 int comps
, int rcomp
, int gcomp
, int bcomp
)
236 FILE *f
= fopen( filename
, "w" );
239 const GLubyte
*ptr
= buffer
;
241 fprintf(f
,"# ppm-file created by osdemo.c\n");
242 fprintf(f
,"%i %i\n", width
,height
);
245 f
= fopen( filename
, "ab" ); /* reopen in binary append mode */
246 for (y
=height
-1; y
>=0; y
--) {
247 for (x
=0; x
<width
; x
++) {
248 i
= (y
*width
+ x
) * comps
;
249 fputc(ptr
[i
+rcomp
], f
); /* write red */
250 fputc(ptr
[i
+gcomp
], f
); /* write green */
251 fputc(ptr
[i
+bcomp
], f
); /* write blue */
260 * Write level[0] image to a ppm file.
263 write_texture_image(struct gl_texture_object
*texObj
)
265 const struct gl_texture_image
*img
= texObj
->Image
[0][0];
266 if (img
&& img
->Data
) {
270 sprintf(s
, "/tmp/teximage%u.ppm", texObj
->Name
);
272 switch (img
->TexFormat
->MesaFormat
) {
273 case MESA_FORMAT_RGBA8888
:
274 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 4, 3, 2, 1);
276 case MESA_FORMAT_ARGB8888
:
277 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 4, 2, 1, 0);
279 case MESA_FORMAT_RGB888
:
280 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 3, 2, 1, 0);
282 case MESA_FORMAT_RGB565
:
284 GLubyte
*buf2
= (GLubyte
*) _mesa_malloc(img
->Width
* img
->Height
* 3);
286 for (i
= 0; i
< img
->Width
* img
->Height
; i
++) {
288 GLushort s
= ((GLushort
*) img
->Data
)[i
];
289 r
= UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
290 g
= UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
291 b
= UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
296 write_ppm(s
, buf2
, img
->Width
, img
->Height
, 3, 2, 1, 0);
301 printf("XXXX unsupported mesa tex format %d in %s\n",
302 img
->TexFormat
->MesaFormat
, __FUNCTION__
);
308 static GLboolean DumpImages
;
312 dump_texture_cb(GLuint id
, void *data
, void *userData
)
314 struct gl_texture_object
*texObj
= (struct gl_texture_object
*) data
;
318 printf("Texture %u\n", texObj
->Name
);
319 printf(" Target 0x%x\n", texObj
->Target
);
320 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
321 struct gl_texture_image
*texImg
= texObj
->Image
[0][i
];
323 printf(" Image %u: %d x %d x %d at %p\n", i
,
324 texImg
->Width
, texImg
->Height
, texImg
->Depth
, texImg
->Data
);
325 if (DumpImages
&& i
== 0) {
326 write_texture_image(texObj
);
334 * Print basic info about all texture objext to stdout.
335 * If dumpImages is true, write PPM of level[0] image to a file.
338 _mesa_dump_textures(GLboolean dumpImages
)
340 GET_CURRENT_CONTEXT(ctx
);
341 DumpImages
= dumpImages
;
342 _mesa_HashWalk(ctx
->Shared
->TexObjects
, dump_texture_cb
, ctx
);
347 _mesa_dump_color_buffer(const char *filename
)
349 GET_CURRENT_CONTEXT(ctx
);
350 const GLuint w
= ctx
->DrawBuffer
->Width
;
351 const GLuint h
= ctx
->DrawBuffer
->Height
;
354 buf
= (GLubyte
*) _mesa_malloc(w
* h
* 4);
356 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT
);
357 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
358 glPixelStorei(GL_PACK_INVERT_MESA
, GL_TRUE
);
360 glReadPixels(0, 0, w
, h
, GL_RGBA
, GL_UNSIGNED_BYTE
, buf
);
362 _mesa_printf("ReadBuffer %p 0x%x DrawBuffer %p 0x%x\n",
363 ctx
->ReadBuffer
->_ColorReadBuffer
,
364 ctx
->ReadBuffer
->ColorReadBuffer
,
365 ctx
->DrawBuffer
->_ColorDrawBuffers
[0],
366 ctx
->DrawBuffer
->ColorDrawBuffer
[0]);
367 _mesa_printf("Writing %d x %d color buffer to %s\n", w
, h
, filename
);
368 write_ppm(filename
, buf
, w
, h
, 4, 0, 1, 2);
377 _mesa_dump_depth_buffer(const char *filename
)
379 GET_CURRENT_CONTEXT(ctx
);
380 const GLuint w
= ctx
->DrawBuffer
->Width
;
381 const GLuint h
= ctx
->DrawBuffer
->Height
;
386 buf
= (GLuint
*) _mesa_malloc(w
* h
* 4); /* 4 bpp */
387 buf2
= (GLubyte
*) _mesa_malloc(w
* h
* 3); /* 3 bpp */
389 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT
);
390 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
391 glPixelStorei(GL_PACK_INVERT_MESA
, GL_TRUE
);
393 glReadPixels(0, 0, w
, h
, GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, buf
);
395 /* spread 24 bits of Z across R, G, B */
396 for (i
= 0; i
< w
* h
; i
++) {
397 buf2
[i
*3+0] = (buf
[i
] >> 24) & 0xff;
398 buf2
[i
*3+1] = (buf
[i
] >> 16) & 0xff;
399 buf2
[i
*3+2] = (buf
[i
] >> 8) & 0xff;
402 _mesa_printf("Writing %d x %d depth buffer to %s\n", w
, h
, filename
);
403 write_ppm(filename
, buf2
, w
, h
, 3, 0, 1, 2);
413 _mesa_dump_stencil_buffer(const char *filename
)
415 GET_CURRENT_CONTEXT(ctx
);
416 const GLuint w
= ctx
->DrawBuffer
->Width
;
417 const GLuint h
= ctx
->DrawBuffer
->Height
;
422 buf
= (GLubyte
*) _mesa_malloc(w
* h
); /* 1 bpp */
423 buf2
= (GLubyte
*) _mesa_malloc(w
* h
* 3); /* 3 bpp */
425 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT
);
426 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
427 glPixelStorei(GL_PACK_INVERT_MESA
, GL_TRUE
);
429 glReadPixels(0, 0, w
, h
, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, buf
);
431 for (i
= 0; i
< w
* h
; i
++) {
432 buf2
[i
*3+0] = buf
[i
];
433 buf2
[i
*3+1] = (buf
[i
] & 127) * 2;
434 buf2
[i
*3+2] = (buf
[i
] - 128) * 2;
437 _mesa_printf("Writing %d x %d stencil buffer to %s\n", w
, h
, filename
);
438 write_ppm(filename
, buf2
, w
, h
, 3, 0, 1, 2);