st/nine: Implement BumpEnvMap for ff
[mesa.git] / src / gallium / state_trackers / nine / nine_debug.c
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "nine_debug.h"
24
25 #include <ctype.h>
26
27 static const struct debug_named_value nine_debug_flags[] = {
28 { "unknown", DBG_UNKNOWN, "IUnknown implementation." },
29 { "adapter", DBG_ADAPTER, "ID3D9Adapter implementation." },
30 { "overlay", DBG_OVERLAYEXTENSION, "IDirect3D9ExOverlayExtension implementation." },
31 { "auth", DBG_AUTHENTICATEDCHANNEL, "IDirect3DAuthenticatedChannel9 implementation." },
32 { "basetex", DBG_BASETEXTURE, "IDirect3DBaseTexture9 implementation." },
33 { "crypto", DBG_CRYPTOSESSION, "IDirect3DCryptoSession9 implementation." },
34 { "cubetex", DBG_CUBETEXTURE, "IDirect3DCubeTexture9 implementation." },
35 { "device", DBG_DEVICE, "IDirect3DDevice9(Ex) implementation." },
36 { "video", DBG_DEVICEVIDEO, "IDirect3DDeviceVideo9 implementation." },
37 { "ibuf", DBG_INDEXBUFFER, "IDirect3DIndexBuffer9 implementation." },
38 { "ps", DBG_PIXELSHADER, "IDirect3DPixelShader9 implementation." },
39 { "query", DBG_QUERY, "IDirect3DQuery9 implementation." },
40 { "res", DBG_RESOURCE, "IDirect3DResource9 implementation." },
41 { "state", DBG_STATEBLOCK, "IDirect3DStateBlock9 implementation." },
42 { "surf", DBG_SURFACE, "IDirect3DSurface9 implementation." },
43 { "swap", DBG_SWAPCHAIN, "IDirect3DSwapChain9(Ex) implementation." },
44 { "tex", DBG_TEXTURE, "IDirect3DTexture9 implementation." },
45 { "vbuf", DBG_VERTEXBUFFER, "IDirect3DVertexBuffer9 implementation." },
46 { "vdecl", DBG_VERTEXDECLARATION, "IDirect3DVertexDeclaration9 implementation." },
47 { "vs", DBG_VERTEXSHADER, "IDirect3DVertexShader9 implementation." },
48 { "3dsurf", DBG_VOLUME, "IDirect3DVolume9 implementation." },
49 { "3dtex", DBG_VOLUMETEXTURE, "IDirect3DVolumeTexture9 implementation." },
50 { "shader", DBG_SHADER, "Shader token stream translator." },
51 { "ff", DBG_FF, "Fixed function emulation." },
52 { "user", DBG_USER, "User errors, both fixable and unfixable." },
53 { "error", DBG_ERROR, "Driver errors, always visible." },
54 { "warn", DBG_WARN, "Driver warnings, always visible in debug builds." },
55 DEBUG_NAMED_VALUE_END
56 };
57
58 void
59 _nine_debug_printf( unsigned long flag,
60 const char *func,
61 const char *fmt,
62 ... )
63 {
64 static boolean first = TRUE;
65 static unsigned long dbg_flags = DBG_ERROR | DBG_WARN;
66
67 if (first) {
68 first = FALSE;
69 dbg_flags |= debug_get_flags_option("NINE_DEBUG", nine_debug_flags, 0);
70 }
71 if (dbg_flags & flag) {
72 const char *f = func ? strrchr(func, '_') : NULL;
73 va_list ap;
74
75 /* inside a class this will print nine:classinlowercase:func: while
76 * outside a class (rarely used) it will just print nine:func:
77 * the reason for lower case is simply to match the filenames, as it
78 * will also strip off the "Nine" */
79 if (f && strncmp(func, "Nine", 4) == 0) {
80 char klass[96]; /* no class name is this long */
81 char *ptr = klass;
82 for (func += 4; func != f; ++func) { *ptr++ = tolower(*func); }
83 *ptr = '\0';
84
85 debug_printf("nine:%s:%s: ", klass, ++f);
86 } else if (func) {
87 debug_printf("nine:%s: ", func);
88 }
89
90 va_start(ap, fmt);
91 debug_vprintf(fmt, ap);
92 va_end(ap);
93 }
94 }
95
96 void
97 _nine_stub( const char *file,
98 const char *func,
99 unsigned line )
100 {
101 const char *r = strrchr(file, '/');
102 if (r == NULL) { r = strrchr(file, '\\'); }
103 debug_printf("nine:%s:%d: %s STUB!\n", r ? ++r : file, line, func);
104 }