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.
33 #include "texformat.h"
39 const char *_mesa_prim_name
[GL_POLYGON
+4] = {
51 "inside unkown primitive",
56 _mesa_print_state( const char *msg
, GLuint state
)
59 "%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",
62 (state
& _NEW_MODELVIEW
) ? "ctx->ModelView, " : "",
63 (state
& _NEW_PROJECTION
) ? "ctx->Projection, " : "",
64 (state
& _NEW_TEXTURE_MATRIX
) ? "ctx->TextureMatrix, " : "",
65 (state
& _NEW_COLOR_MATRIX
) ? "ctx->ColorMatrix, " : "",
66 (state
& _NEW_ACCUM
) ? "ctx->Accum, " : "",
67 (state
& _NEW_COLOR
) ? "ctx->Color, " : "",
68 (state
& _NEW_DEPTH
) ? "ctx->Depth, " : "",
69 (state
& _NEW_EVAL
) ? "ctx->Eval/EvalMap, " : "",
70 (state
& _NEW_FOG
) ? "ctx->Fog, " : "",
71 (state
& _NEW_HINT
) ? "ctx->Hint, " : "",
72 (state
& _NEW_LIGHT
) ? "ctx->Light, " : "",
73 (state
& _NEW_LINE
) ? "ctx->Line, " : "",
74 (state
& _NEW_PIXEL
) ? "ctx->Pixel, " : "",
75 (state
& _NEW_POINT
) ? "ctx->Point, " : "",
76 (state
& _NEW_POLYGON
) ? "ctx->Polygon, " : "",
77 (state
& _NEW_POLYGONSTIPPLE
) ? "ctx->PolygonStipple, " : "",
78 (state
& _NEW_SCISSOR
) ? "ctx->Scissor, " : "",
79 (state
& _NEW_TEXTURE
) ? "ctx->Texture, " : "",
80 (state
& _NEW_TRANSFORM
) ? "ctx->Transform, " : "",
81 (state
& _NEW_VIEWPORT
) ? "ctx->Viewport, " : "",
82 (state
& _NEW_PACKUNPACK
) ? "ctx->Pack/Unpack, " : "",
83 (state
& _NEW_ARRAY
) ? "ctx->Array, " : "",
84 (state
& _NEW_RENDERMODE
) ? "ctx->RenderMode, " : "",
85 (state
& _NEW_BUFFERS
) ? "ctx->Visual, ctx->DrawBuffer,, " : "");
91 _mesa_print_tri_caps( const char *name
, GLuint flags
)
94 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
97 (flags
& DD_FLATSHADE
) ? "flat-shade, " : "",
98 (flags
& DD_SEPARATE_SPECULAR
) ? "separate-specular, " : "",
99 (flags
& DD_TRI_LIGHT_TWOSIDE
) ? "tri-light-twoside, " : "",
100 (flags
& DD_TRI_TWOSTENCIL
) ? "tri-twostencil, " : "",
101 (flags
& DD_TRI_UNFILLED
) ? "tri-unfilled, " : "",
102 (flags
& DD_TRI_STIPPLE
) ? "tri-stipple, " : "",
103 (flags
& DD_TRI_OFFSET
) ? "tri-offset, " : "",
104 (flags
& DD_TRI_SMOOTH
) ? "tri-smooth, " : "",
105 (flags
& DD_LINE_SMOOTH
) ? "line-smooth, " : "",
106 (flags
& DD_LINE_STIPPLE
) ? "line-stipple, " : "",
107 (flags
& DD_LINE_WIDTH
) ? "line-wide, " : "",
108 (flags
& DD_POINT_SMOOTH
) ? "point-smooth, " : "",
109 (flags
& DD_POINT_SIZE
) ? "point-size, " : "",
110 (flags
& DD_POINT_ATTEN
) ? "point-atten, " : "",
111 (flags
& DD_TRI_CULL_FRONT_BACK
) ? "cull-all, " : ""
117 * Print information about this Mesa version and build options.
119 void _mesa_print_info( void )
121 _mesa_debug(NULL
, "Mesa GL_VERSION = %s\n",
122 (char *) _mesa_GetString(GL_VERSION
));
123 _mesa_debug(NULL
, "Mesa GL_RENDERER = %s\n",
124 (char *) _mesa_GetString(GL_RENDERER
));
125 _mesa_debug(NULL
, "Mesa GL_VENDOR = %s\n",
126 (char *) _mesa_GetString(GL_VENDOR
));
127 _mesa_debug(NULL
, "Mesa GL_EXTENSIONS = %s\n",
128 (char *) _mesa_GetString(GL_EXTENSIONS
));
130 _mesa_debug(NULL
, "Mesa thread-safe: YES\n");
132 _mesa_debug(NULL
, "Mesa thread-safe: NO\n");
134 #if defined(USE_X86_ASM)
135 _mesa_debug(NULL
, "Mesa x86-optimized: YES\n");
137 _mesa_debug(NULL
, "Mesa x86-optimized: NO\n");
139 #if defined(USE_SPARC_ASM)
140 _mesa_debug(NULL
, "Mesa sparc-optimized: YES\n");
142 _mesa_debug(NULL
, "Mesa sparc-optimized: NO\n");
148 * Set the debugging flags.
150 * \param debug debug string
152 * If compiled with debugging support then search for keywords in \p debug and
153 * enables the verbose debug output of the respective feature.
155 static void add_debug_flags( const char *debug
)
158 struct debug_option
{
162 static const struct debug_option debug_opt
[] = {
163 { "varray", VERBOSE_VARRAY
},
164 { "tex", VERBOSE_TEXTURE
},
165 { "imm", VERBOSE_IMMEDIATE
},
166 { "pipe", VERBOSE_PIPELINE
},
167 { "driver", VERBOSE_DRIVER
},
168 { "state", VERBOSE_STATE
},
169 { "api", VERBOSE_API
},
170 { "list", VERBOSE_DISPLAY_LIST
},
171 { "lighting", VERBOSE_LIGHTING
},
172 { "disassem", VERBOSE_DISASSEM
}
177 for (i
= 0; i
< Elements(debug_opt
); i
++) {
178 if (_mesa_strstr(debug
, debug_opt
[i
].name
))
179 MESA_VERBOSE
|= debug_opt
[i
].flag
;
184 if (_mesa_strstr(debug
, "flush"))
185 MESA_DEBUG_FLAGS
|= DEBUG_ALWAYS_FLUSH
;
187 #if defined(_FPU_GETCW) && defined(_FPU_SETCW)
188 if (_mesa_strstr(debug
, "fpexceptions")) {
189 /* raise FP exceptions */
192 mask
&= ~(_FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
193 | _FPU_MASK_OM
| _FPU_MASK_UM
);
205 _mesa_init_debug( GLcontext
*ctx
)
210 ctx
->NoDither
= _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE
: GL_FALSE
;
212 if (_mesa_getenv("MESA_DEBUG")) {
213 _mesa_debug(ctx
, "MESA_NO_DITHER set - dithering disabled\n");
215 ctx
->Color
.DitherFlag
= GL_FALSE
;
218 c
= _mesa_getenv("MESA_DEBUG");
222 c
= _mesa_getenv("MESA_VERBOSE");
232 write_ppm(const char *filename
, const GLubyte
*buffer
, int width
, int height
,
233 int comps
, int rcomp
, int gcomp
, int bcomp
)
235 FILE *f
= fopen( filename
, "w" );
238 const GLubyte
*ptr
= buffer
;
240 fprintf(f
,"# ppm-file created by osdemo.c\n");
241 fprintf(f
,"%i %i\n", width
,height
);
244 f
= fopen( filename
, "ab" ); /* reopen in binary append mode */
245 for (y
=height
-1; y
>=0; y
--) {
246 for (x
=0; x
<width
; x
++) {
247 i
= (y
*width
+ x
) * comps
;
248 fputc(ptr
[i
+rcomp
], f
); /* write red */
249 fputc(ptr
[i
+gcomp
], f
); /* write green */
250 fputc(ptr
[i
+bcomp
], f
); /* write blue */
259 * Write level[0] image to a ppm file.
262 write_texture_image(struct gl_texture_object
*texObj
)
264 const struct gl_texture_image
*img
= texObj
->Image
[0][0];
269 sprintf(s
, "/tmp/teximage%u.ppm", texObj
->Name
);
271 switch (img
->TexFormat
->MesaFormat
) {
272 case MESA_FORMAT_RGBA8888
:
273 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 4, 3, 2, 1);
275 case MESA_FORMAT_ARGB8888
:
276 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 4, 2, 1, 0);
278 case MESA_FORMAT_RGB888
:
279 write_ppm(s
, img
->Data
, img
->Width
, img
->Height
, 3, 2, 1, 0);
281 case MESA_FORMAT_RGB565
:
283 GLubyte
*buf2
= (GLubyte
*) _mesa_malloc(img
->Width
* img
->Height
* 3);
285 for (i
= 0; i
< img
->Width
* img
->Height
; i
++) {
287 GLushort s
= ((GLushort
*) img
->Data
)[i
];
288 r
= UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
289 g
= UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
290 b
= UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
295 write_ppm(s
, buf2
, img
->Width
, img
->Height
, 3, 2, 1, 0);
300 printf("XXXX unsupported mesa tex format %d in %s\n",
301 img
->TexFormat
->MesaFormat
, __FUNCTION__
);
307 static GLboolean DumpImages
;
311 dump_texture_cb(GLuint id
, void *data
, void *userData
)
313 struct gl_texture_object
*texObj
= (struct gl_texture_object
*) data
;
317 printf("Texture %u\n", texObj
->Name
);
318 printf(" Target 0x%x\n", texObj
->Target
);
319 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
320 struct gl_texture_image
*texImg
= texObj
->Image
[0][i
];
322 printf(" Image %u: %d x %d x %d at %p\n", i
,
323 texImg
->Width
, texImg
->Height
, texImg
->Depth
, texImg
->Data
);
324 if (DumpImages
&& i
== 0) {
325 write_texture_image(texObj
);
333 * Print basic info about all texture objext to stdout.
334 * If dumpImages is true, write PPM of level[0] image to a file.
337 _mesa_dump_textures(GLboolean dumpImages
)
339 GET_CURRENT_CONTEXT(ctx
);
340 DumpImages
= dumpImages
;
341 _mesa_HashDeleteAll(ctx
->Shared
->TexObjects
, dump_texture_cb
, ctx
);