OSDN Git Service

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