a42113edcacac962204ad3317705dfbccc1cd7cf
[mesa.git] / src / mesa / main / debug.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. 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 "attrib.h"
28 #include "colormac.h"
29 #include "context.h"
30 #include "enums.h"
31 #include "formats.h"
32 #include "hash.h"
33 #include "imports.h"
34 #include "debug.h"
35 #include "get.h"
36 #include "pixelstore.h"
37 #include "readpix.h"
38 #include "texgetimage.h"
39 #include "texobj.h"
40
41
42 /**
43 * Primitive names
44 */
45 const char *_mesa_prim_name[GL_POLYGON+4] = {
46 "GL_POINTS",
47 "GL_LINES",
48 "GL_LINE_LOOP",
49 "GL_LINE_STRIP",
50 "GL_TRIANGLES",
51 "GL_TRIANGLE_STRIP",
52 "GL_TRIANGLE_FAN",
53 "GL_QUADS",
54 "GL_QUAD_STRIP",
55 "GL_POLYGON",
56 "outside begin/end",
57 "inside unkown primitive",
58 "unknown state"
59 };
60
61
62 static const char *
63 tex_target_name(GLenum tgt)
64 {
65 static const struct {
66 GLenum target;
67 const char *name;
68 } tex_targets[] = {
69 { GL_TEXTURE_1D, "GL_TEXTURE_1D" },
70 { GL_TEXTURE_2D, "GL_TEXTURE_2D" },
71 { GL_TEXTURE_3D, "GL_TEXTURE_3D" },
72 { GL_TEXTURE_CUBE_MAP, "GL_TEXTURE_CUBE_MAP" },
73 { GL_TEXTURE_RECTANGLE, "GL_TEXTURE_RECTANGLE" },
74 { GL_TEXTURE_1D_ARRAY_EXT, "GL_TEXTURE_1D_ARRAY" },
75 { GL_TEXTURE_2D_ARRAY_EXT, "GL_TEXTURE_2D_ARRAY" }
76 };
77 GLuint i;
78 for (i = 0; i < Elements(tex_targets); i++) {
79 if (tex_targets[i].target == tgt)
80 return tex_targets[i].name;
81 }
82 return "UNKNOWN TEX TARGET";
83 }
84
85
86 void
87 _mesa_print_state( const char *msg, GLuint state )
88 {
89 _mesa_debug(NULL,
90 "%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",
91 msg,
92 state,
93 (state & _NEW_MODELVIEW) ? "ctx->ModelView, " : "",
94 (state & _NEW_PROJECTION) ? "ctx->Projection, " : "",
95 (state & _NEW_TEXTURE_MATRIX) ? "ctx->TextureMatrix, " : "",
96 (state & _NEW_COLOR_MATRIX) ? "ctx->ColorMatrix, " : "",
97 (state & _NEW_ACCUM) ? "ctx->Accum, " : "",
98 (state & _NEW_COLOR) ? "ctx->Color, " : "",
99 (state & _NEW_DEPTH) ? "ctx->Depth, " : "",
100 (state & _NEW_EVAL) ? "ctx->Eval/EvalMap, " : "",
101 (state & _NEW_FOG) ? "ctx->Fog, " : "",
102 (state & _NEW_HINT) ? "ctx->Hint, " : "",
103 (state & _NEW_LIGHT) ? "ctx->Light, " : "",
104 (state & _NEW_LINE) ? "ctx->Line, " : "",
105 (state & _NEW_PIXEL) ? "ctx->Pixel, " : "",
106 (state & _NEW_POINT) ? "ctx->Point, " : "",
107 (state & _NEW_POLYGON) ? "ctx->Polygon, " : "",
108 (state & _NEW_POLYGONSTIPPLE) ? "ctx->PolygonStipple, " : "",
109 (state & _NEW_SCISSOR) ? "ctx->Scissor, " : "",
110 (state & _NEW_TEXTURE) ? "ctx->Texture, " : "",
111 (state & _NEW_TRANSFORM) ? "ctx->Transform, " : "",
112 (state & _NEW_VIEWPORT) ? "ctx->Viewport, " : "",
113 (state & _NEW_PACKUNPACK) ? "ctx->Pack/Unpack, " : "",
114 (state & _NEW_ARRAY) ? "ctx->Array, " : "",
115 (state & _NEW_RENDERMODE) ? "ctx->RenderMode, " : "",
116 (state & _NEW_BUFFERS) ? "ctx->Visual, ctx->DrawBuffer,, " : "");
117 }
118
119
120
121 void
122 _mesa_print_tri_caps( const char *name, GLuint flags )
123 {
124 _mesa_debug(NULL,
125 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
126 name,
127 flags,
128 (flags & DD_FLATSHADE) ? "flat-shade, " : "",
129 (flags & DD_SEPARATE_SPECULAR) ? "separate-specular, " : "",
130 (flags & DD_TRI_LIGHT_TWOSIDE) ? "tri-light-twoside, " : "",
131 (flags & DD_TRI_TWOSTENCIL) ? "tri-twostencil, " : "",
132 (flags & DD_TRI_UNFILLED) ? "tri-unfilled, " : "",
133 (flags & DD_TRI_STIPPLE) ? "tri-stipple, " : "",
134 (flags & DD_TRI_OFFSET) ? "tri-offset, " : "",
135 (flags & DD_TRI_SMOOTH) ? "tri-smooth, " : "",
136 (flags & DD_LINE_SMOOTH) ? "line-smooth, " : "",
137 (flags & DD_LINE_STIPPLE) ? "line-stipple, " : "",
138 (flags & DD_LINE_WIDTH) ? "line-wide, " : "",
139 (flags & DD_POINT_SMOOTH) ? "point-smooth, " : "",
140 (flags & DD_POINT_SIZE) ? "point-size, " : "",
141 (flags & DD_POINT_ATTEN) ? "point-atten, " : "",
142 (flags & DD_TRI_CULL_FRONT_BACK) ? "cull-all, " : ""
143 );
144 }
145
146
147 /**
148 * Print information about this Mesa version and build options.
149 */
150 void _mesa_print_info( void )
151 {
152 _mesa_debug(NULL, "Mesa GL_VERSION = %s\n",
153 (char *) _mesa_GetString(GL_VERSION));
154 _mesa_debug(NULL, "Mesa GL_RENDERER = %s\n",
155 (char *) _mesa_GetString(GL_RENDERER));
156 _mesa_debug(NULL, "Mesa GL_VENDOR = %s\n",
157 (char *) _mesa_GetString(GL_VENDOR));
158 _mesa_debug(NULL, "Mesa GL_EXTENSIONS = %s\n",
159 (char *) _mesa_GetString(GL_EXTENSIONS));
160 #if defined(THREADS)
161 _mesa_debug(NULL, "Mesa thread-safe: YES\n");
162 #else
163 _mesa_debug(NULL, "Mesa thread-safe: NO\n");
164 #endif
165 #if defined(USE_X86_ASM)
166 _mesa_debug(NULL, "Mesa x86-optimized: YES\n");
167 #else
168 _mesa_debug(NULL, "Mesa x86-optimized: NO\n");
169 #endif
170 #if defined(USE_SPARC_ASM)
171 _mesa_debug(NULL, "Mesa sparc-optimized: YES\n");
172 #else
173 _mesa_debug(NULL, "Mesa sparc-optimized: NO\n");
174 #endif
175 }
176
177
178 /**
179 * Set the debugging flags.
180 *
181 * \param debug debug string
182 *
183 * If compiled with debugging support then search for keywords in \p debug and
184 * enables the verbose debug output of the respective feature.
185 */
186 static void add_debug_flags( const char *debug )
187 {
188 #ifdef DEBUG
189 struct debug_option {
190 const char *name;
191 GLbitfield flag;
192 };
193 static const struct debug_option debug_opt[] = {
194 { "varray", VERBOSE_VARRAY },
195 { "tex", VERBOSE_TEXTURE },
196 { "mat", VERBOSE_MATERIAL },
197 { "pipe", VERBOSE_PIPELINE },
198 { "driver", VERBOSE_DRIVER },
199 { "state", VERBOSE_STATE },
200 { "api", VERBOSE_API },
201 { "list", VERBOSE_DISPLAY_LIST },
202 { "lighting", VERBOSE_LIGHTING },
203 { "disassem", VERBOSE_DISASSEM },
204 { "draw", VERBOSE_DRAW },
205 { "swap", VERBOSE_SWAPBUFFERS }
206 };
207 GLuint i;
208
209 MESA_VERBOSE = 0x0;
210 for (i = 0; i < Elements(debug_opt); i++) {
211 if (_mesa_strstr(debug, debug_opt[i].name))
212 MESA_VERBOSE |= debug_opt[i].flag;
213 }
214
215 /* Debug flag:
216 */
217 if (_mesa_strstr(debug, "flush"))
218 MESA_DEBUG_FLAGS |= DEBUG_ALWAYS_FLUSH;
219
220 #if defined(_FPU_GETCW) && defined(_FPU_SETCW)
221 if (_mesa_strstr(debug, "fpexceptions")) {
222 /* raise FP exceptions */
223 fpu_control_t mask;
224 _FPU_GETCW(mask);
225 mask &= ~(_FPU_MASK_IM | _FPU_MASK_DM | _FPU_MASK_ZM
226 | _FPU_MASK_OM | _FPU_MASK_UM);
227 _FPU_SETCW(mask);
228 }
229 #endif
230
231 #else
232 (void) debug;
233 #endif
234 }
235
236
237 void
238 _mesa_init_debug( GLcontext *ctx )
239 {
240 char *c;
241
242 /* Dither disable */
243 ctx->NoDither = _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
244 if (ctx->NoDither) {
245 if (_mesa_getenv("MESA_DEBUG")) {
246 _mesa_debug(ctx, "MESA_NO_DITHER set - dithering disabled\n");
247 }
248 ctx->Color.DitherFlag = GL_FALSE;
249 }
250
251 c = _mesa_getenv("MESA_DEBUG");
252 if (c)
253 add_debug_flags(c);
254
255 c = _mesa_getenv("MESA_VERBOSE");
256 if (c)
257 add_debug_flags(c);
258 }
259
260
261 /*
262 * Write ppm file
263 */
264 static void
265 write_ppm(const char *filename, const GLubyte *buffer, int width, int height,
266 int comps, int rcomp, int gcomp, int bcomp, GLboolean invert)
267 {
268 FILE *f = fopen( filename, "w" );
269 if (f) {
270 int x, y;
271 const GLubyte *ptr = buffer;
272 fprintf(f,"P6\n");
273 fprintf(f,"# ppm-file created by osdemo.c\n");
274 fprintf(f,"%i %i\n", width,height);
275 fprintf(f,"255\n");
276 fclose(f);
277 f = fopen( filename, "ab" ); /* reopen in binary append mode */
278 for (y=0; y < height; y++) {
279 for (x = 0; x < width; x++) {
280 int yy = invert ? (height - 1 - y) : y;
281 int i = (yy * width + x) * comps;
282 fputc(ptr[i+rcomp], f); /* write red */
283 fputc(ptr[i+gcomp], f); /* write green */
284 fputc(ptr[i+bcomp], f); /* write blue */
285 }
286 }
287 fclose(f);
288 }
289 }
290
291
292 /**
293 * Write a texture image to a ppm file.
294 * \param face cube face in [0,5]
295 * \param level mipmap level
296 */
297 static void
298 write_texture_image(struct gl_texture_object *texObj,
299 GLuint face, GLuint level)
300 {
301 struct gl_texture_image *img = texObj->Image[face][level];
302 if (img) {
303 GET_CURRENT_CONTEXT(ctx);
304 struct gl_pixelstore_attrib store;
305 GLubyte *buffer;
306 char s[100];
307
308 buffer = (GLubyte *) _mesa_malloc(img->Width * img->Height
309 * img->Depth * 4);
310
311 store = ctx->Pack; /* save */
312 ctx->Pack = ctx->DefaultPacking;
313
314 ctx->Driver.GetTexImage(ctx, texObj->Target, level,
315 GL_RGBA, GL_UNSIGNED_BYTE,
316 buffer, texObj, img);
317
318 /* make filename */
319 _mesa_sprintf(s, "/tmp/tex%u.l%u.f%u.ppm", texObj->Name, level, face);
320
321 _mesa_printf(" Writing image level %u to %s\n", level, s);
322 write_ppm(s, buffer, img->Width, img->Height, 4, 0, 1, 2, GL_FALSE);
323
324 ctx->Pack = store; /* restore */
325
326 _mesa_free(buffer);
327 }
328 }
329
330
331 /**
332 * Write renderbuffer image to a ppm file.
333 */
334 static void
335 write_renderbuffer_image(const struct gl_renderbuffer *rb)
336 {
337 GET_CURRENT_CONTEXT(ctx);
338 GLubyte *buffer;
339 char s[100];
340 GLenum format, type;
341
342 if (rb->_BaseFormat == GL_RGB ||
343 rb->_BaseFormat == GL_RGBA) {
344 format = GL_RGBA;
345 type = GL_UNSIGNED_BYTE;
346 }
347 else if (rb->_BaseFormat == GL_DEPTH_STENCIL) {
348 format = GL_DEPTH_STENCIL;
349 type = GL_UNSIGNED_INT_24_8;
350 }
351 else {
352 return;
353 }
354
355 buffer = (GLubyte *) _mesa_malloc(rb->Width * rb->Height * 4);
356
357 ctx->Driver.ReadPixels(ctx, 0, 0, rb->Width, rb->Height,
358 format, type, &ctx->DefaultPacking, buffer);
359
360 /* make filename */
361 _mesa_sprintf(s, "/tmp/renderbuffer%u.ppm", rb->Name);
362
363 _mesa_printf(" Writing renderbuffer image to %s\n", s);
364 write_ppm(s, buffer, rb->Width, rb->Height, 4, 0, 1, 2, GL_TRUE);
365
366 _mesa_free(buffer);
367 }
368
369
370 /** How many texture images (mipmap levels, faces) to write to files */
371 #define WRITE_NONE 0
372 #define WRITE_ONE 1
373 #define WRITE_ALL 2
374
375 static GLuint WriteImages;
376
377
378 static void
379 dump_texture(struct gl_texture_object *texObj, GLuint writeImages)
380 {
381 const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
382 GLboolean written = GL_FALSE;
383 GLuint i, j;
384
385 _mesa_printf("Texture %u\n", texObj->Name);
386 _mesa_printf(" Target %s\n", tex_target_name(texObj->Target));
387 for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
388 for (j = 0; j < numFaces; j++) {
389 struct gl_texture_image *texImg = texObj->Image[j][i];
390 if (texImg) {
391 _mesa_printf(" Face %u level %u: %d x %d x %d, format %s at %p\n",
392 j, i,
393 texImg->Width, texImg->Height, texImg->Depth,
394 _mesa_get_format_name(texImg->TexFormat),
395 texImg->Data);
396 if (writeImages == WRITE_ALL ||
397 (writeImages == WRITE_ONE && !written)) {
398 write_texture_image(texObj, j, i);
399 written = GL_TRUE;
400 }
401 }
402 }
403 }
404 }
405
406
407 /**
408 * Dump a single texture.
409 */
410 void
411 _mesa_dump_texture(GLuint texture, GLuint writeImages)
412 {
413 GET_CURRENT_CONTEXT(ctx);
414 struct gl_texture_object *texObj = _mesa_lookup_texture(ctx, texture);
415 if (texObj) {
416 dump_texture(texObj, writeImages);
417 }
418 }
419
420
421 static void
422 dump_texture_cb(GLuint id, void *data, void *userData)
423 {
424 struct gl_texture_object *texObj = (struct gl_texture_object *) data;
425 (void) userData;
426 dump_texture(texObj, WriteImages);
427 }
428
429
430 /**
431 * Print basic info about all texture objext to stdout.
432 * If dumpImages is true, write PPM of level[0] image to a file.
433 */
434 void
435 _mesa_dump_textures(GLuint writeImages)
436 {
437 GET_CURRENT_CONTEXT(ctx);
438 WriteImages = writeImages;
439 _mesa_HashWalk(ctx->Shared->TexObjects, dump_texture_cb, ctx);
440 }
441
442
443 static void
444 dump_renderbuffer(const struct gl_renderbuffer *rb, GLboolean writeImage)
445 {
446 _mesa_printf("Renderbuffer %u: %u x %u IntFormat = %s\n",
447 rb->Name, rb->Width, rb->Height,
448 _mesa_lookup_enum_by_nr(rb->InternalFormat));
449 if (writeImage) {
450 write_renderbuffer_image(rb);
451 }
452 }
453
454
455 static void
456 dump_renderbuffer_cb(GLuint id, void *data, void *userData)
457 {
458 const struct gl_renderbuffer *rb = (const struct gl_renderbuffer *) data;
459 (void) userData;
460 dump_renderbuffer(rb, WriteImages);
461 }
462
463
464 /**
465 * Print basic info about all renderbuffers to stdout.
466 * If dumpImages is true, write PPM of level[0] image to a file.
467 */
468 void
469 _mesa_dump_renderbuffers(GLboolean writeImages)
470 {
471 GET_CURRENT_CONTEXT(ctx);
472 WriteImages = writeImages;
473 _mesa_HashWalk(ctx->Shared->RenderBuffers, dump_renderbuffer_cb, ctx);
474 }
475
476
477
478 void
479 _mesa_dump_color_buffer(const char *filename)
480 {
481 GET_CURRENT_CONTEXT(ctx);
482 const GLuint w = ctx->DrawBuffer->Width;
483 const GLuint h = ctx->DrawBuffer->Height;
484 GLubyte *buf;
485
486 buf = (GLubyte *) _mesa_malloc(w * h * 4);
487
488 _mesa_PushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
489 _mesa_PixelStorei(GL_PACK_ALIGNMENT, 1);
490 _mesa_PixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
491
492 _mesa_ReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buf);
493
494 _mesa_printf("ReadBuffer %p 0x%x DrawBuffer %p 0x%x\n",
495 ctx->ReadBuffer->_ColorReadBuffer,
496 ctx->ReadBuffer->ColorReadBuffer,
497 ctx->DrawBuffer->_ColorDrawBuffers[0],
498 ctx->DrawBuffer->ColorDrawBuffer[0]);
499 _mesa_printf("Writing %d x %d color buffer to %s\n", w, h, filename);
500 write_ppm(filename, buf, w, h, 4, 0, 1, 2, GL_TRUE);
501
502 _mesa_PopClientAttrib();
503
504 _mesa_free(buf);
505 }
506
507
508 void
509 _mesa_dump_depth_buffer(const char *filename)
510 {
511 GET_CURRENT_CONTEXT(ctx);
512 const GLuint w = ctx->DrawBuffer->Width;
513 const GLuint h = ctx->DrawBuffer->Height;
514 GLuint *buf;
515 GLubyte *buf2;
516 GLuint i;
517
518 buf = (GLuint *) _mesa_malloc(w * h * 4); /* 4 bpp */
519 buf2 = (GLubyte *) _mesa_malloc(w * h * 3); /* 3 bpp */
520
521 _mesa_PushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
522 _mesa_PixelStorei(GL_PACK_ALIGNMENT, 1);
523 _mesa_PixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
524
525 _mesa_ReadPixels(0, 0, w, h, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, buf);
526
527 /* spread 24 bits of Z across R, G, B */
528 for (i = 0; i < w * h; i++) {
529 buf2[i*3+0] = (buf[i] >> 24) & 0xff;
530 buf2[i*3+1] = (buf[i] >> 16) & 0xff;
531 buf2[i*3+2] = (buf[i] >> 8) & 0xff;
532 }
533
534 _mesa_printf("Writing %d x %d depth buffer to %s\n", w, h, filename);
535 write_ppm(filename, buf2, w, h, 3, 0, 1, 2, GL_TRUE);
536
537 _mesa_PopClientAttrib();
538
539 _mesa_free(buf);
540 _mesa_free(buf2);
541 }
542
543
544 void
545 _mesa_dump_stencil_buffer(const char *filename)
546 {
547 GET_CURRENT_CONTEXT(ctx);
548 const GLuint w = ctx->DrawBuffer->Width;
549 const GLuint h = ctx->DrawBuffer->Height;
550 GLubyte *buf;
551 GLubyte *buf2;
552 GLuint i;
553
554 buf = (GLubyte *) _mesa_malloc(w * h); /* 1 bpp */
555 buf2 = (GLubyte *) _mesa_malloc(w * h * 3); /* 3 bpp */
556
557 _mesa_PushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
558 _mesa_PixelStorei(GL_PACK_ALIGNMENT, 1);
559 _mesa_PixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
560
561 _mesa_ReadPixels(0, 0, w, h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf);
562
563 for (i = 0; i < w * h; i++) {
564 buf2[i*3+0] = buf[i];
565 buf2[i*3+1] = (buf[i] & 127) * 2;
566 buf2[i*3+2] = (buf[i] - 128) * 2;
567 }
568
569 _mesa_printf("Writing %d x %d stencil buffer to %s\n", w, h, filename);
570 write_ppm(filename, buf2, w, h, 3, 0, 1, 2, GL_TRUE);
571
572 _mesa_PopClientAttrib();
573
574 _mesa_free(buf);
575 _mesa_free(buf2);
576 }
577
578
579 /**
580 * Quick and dirty function to "print" a texture to stdout.
581 */
582 void
583 _mesa_print_texture(GLcontext *ctx, const struct gl_texture_image *img)
584 {
585 #if CHAN_TYPE != GL_UNSIGNED_BYTE
586 _mesa_problem(NULL, "PrintTexture not supported");
587 #else
588 GLuint i, j, c;
589 const GLubyte *data = (const GLubyte *) img->Data;
590
591 if (!data) {
592 _mesa_printf("No texture data\n");
593 return;
594 }
595
596 /* XXX add more formats or make into a new format utility function */
597 switch (img->TexFormat) {
598 case MESA_FORMAT_A8:
599 case MESA_FORMAT_L8:
600 case MESA_FORMAT_I8:
601 case MESA_FORMAT_CI8:
602 c = 1;
603 break;
604 case MESA_FORMAT_AL88:
605 case MESA_FORMAT_AL88_REV:
606 c = 2;
607 break;
608 case MESA_FORMAT_RGB888:
609 case MESA_FORMAT_BGR888:
610 c = 3;
611 break;
612 case MESA_FORMAT_RGBA8888:
613 case MESA_FORMAT_ARGB8888:
614 c = 4;
615 break;
616 default:
617 _mesa_problem(NULL, "error in PrintTexture\n");
618 return;
619 }
620
621 for (i = 0; i < img->Height; i++) {
622 for (j = 0; j < img->Width; j++) {
623 if (c==1)
624 _mesa_printf("%02x ", data[0]);
625 else if (c==2)
626 _mesa_printf("%02x%02x ", data[0], data[1]);
627 else if (c==3)
628 _mesa_printf("%02x%02x%02x ", data[0], data[1], data[2]);
629 else if (c==4)
630 _mesa_printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]);
631 data += (img->RowStride - img->Width) * c;
632 }
633 /* XXX use img->ImageStride here */
634 _mesa_printf("\n");
635 }
636 #endif
637 }