gallium: cast to silence waring
[mesa.git] / src / gallium / auxiliary / util / u_debug_dump.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * 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
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "util/u_memory.h"
30 #include "util/u_debug.h"
31 #include "util/u_debug_dump.h"
32
33
34 #define DEBUG_DUMP_INVALID_NAME "<invalid>"
35
36
37 #if 0
38 static const char *
39 debug_dump_strip_prefix(const char *name,
40 const char *prefix)
41 {
42 const char *stripped;
43 assert(name);
44 assert(prefix);
45 stripped = name;
46 while(*prefix) {
47 if(*stripped != *prefix)
48 return name;
49
50 ++stripped;
51 ++prefix;
52 }
53 return stripped;
54 }
55 #endif
56
57 static const char *
58 debug_dump_enum_continuous(unsigned value,
59 unsigned num_names,
60 const char **names)
61 {
62 if (value >= num_names)
63 return DEBUG_DUMP_INVALID_NAME;
64 return names[value];
65 }
66
67
68 #define DEFINE_DEBUG_DUMP_CONTINUOUS(_name) \
69 const char * \
70 debug_dump_##_name(unsigned value, boolean shortened) \
71 { \
72 if(shortened) \
73 return debug_dump_enum_continuous(value, Elements(debug_dump_##_name##_short_names), debug_dump_##_name##_short_names); \
74 else \
75 return debug_dump_enum_continuous(value, Elements(debug_dump_##_name##_names), debug_dump_##_name##_names); \
76 }
77
78
79 static const char *
80 debug_dump_blend_factor_names[] = {
81 DEBUG_DUMP_INVALID_NAME, /* 0x0 */
82 "PIPE_BLENDFACTOR_ONE",
83 "PIPE_BLENDFACTOR_SRC_COLOR",
84 "PIPE_BLENDFACTOR_SRC_ALPHA",
85 "PIPE_BLENDFACTOR_DST_ALPHA",
86 "PIPE_BLENDFACTOR_DST_COLOR",
87 "PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE",
88 "PIPE_BLENDFACTOR_CONST_COLOR",
89 "PIPE_BLENDFACTOR_CONST_ALPHA",
90 "PIPE_BLENDFACTOR_SRC1_COLOR",
91 "PIPE_BLENDFACTOR_SRC1_ALPHA",
92 DEBUG_DUMP_INVALID_NAME, /* 0x0b */
93 DEBUG_DUMP_INVALID_NAME, /* 0x0c */
94 DEBUG_DUMP_INVALID_NAME, /* 0x0d */
95 DEBUG_DUMP_INVALID_NAME, /* 0x0e */
96 DEBUG_DUMP_INVALID_NAME, /* 0x0f */
97 DEBUG_DUMP_INVALID_NAME, /* 0x10 */
98 "PIPE_BLENDFACTOR_ZERO",
99 "PIPE_BLENDFACTOR_INV_SRC_COLOR",
100 "PIPE_BLENDFACTOR_INV_SRC_ALPHA",
101 "PIPE_BLENDFACTOR_INV_DST_ALPHA",
102 "PIPE_BLENDFACTOR_INV_DST_COLOR",
103 DEBUG_DUMP_INVALID_NAME, /* 0x16 */
104 "PIPE_BLENDFACTOR_INV_CONST_COLOR",
105 "PIPE_BLENDFACTOR_INV_CONST_ALPHA",
106 "PIPE_BLENDFACTOR_INV_SRC1_COLOR",
107 "PIPE_BLENDFACTOR_INV_SRC1_ALPHA"
108 };
109
110 static const char *
111 debug_dump_blend_factor_short_names[] = {
112 DEBUG_DUMP_INVALID_NAME, /* 0x0 */
113 "one",
114 "src_color",
115 "src_alpha",
116 "dst_alpha",
117 "dst_color",
118 "src_alpha_saturate",
119 "const_color",
120 "const_alpha",
121 "src1_color",
122 "src1_alpha",
123 DEBUG_DUMP_INVALID_NAME, /* 0x0b */
124 DEBUG_DUMP_INVALID_NAME, /* 0x0c */
125 DEBUG_DUMP_INVALID_NAME, /* 0x0d */
126 DEBUG_DUMP_INVALID_NAME, /* 0x0e */
127 DEBUG_DUMP_INVALID_NAME, /* 0x0f */
128 DEBUG_DUMP_INVALID_NAME, /* 0x10 */
129 "zero",
130 "inv_src_color",
131 "inv_src_alpha",
132 "inv_dst_alpha",
133 "inv_dst_color",
134 DEBUG_DUMP_INVALID_NAME, /* 0x16 */
135 "inv_const_color",
136 "inv_const_alpha",
137 "inv_src1_color",
138 "inv_src1_alpha"
139 };
140
141 DEFINE_DEBUG_DUMP_CONTINUOUS(blend_factor)
142
143
144 static const char *
145 debug_dump_blend_func_names[] = {
146 "PIPE_BLEND_ADD",
147 "PIPE_BLEND_SUBTRACT",
148 "PIPE_BLEND_REVERSE_SUBTRACT",
149 "PIPE_BLEND_MIN",
150 "PIPE_BLEND_MAX"
151 };
152
153 static const char *
154 debug_dump_blend_func_short_names[] = {
155 "add",
156 "sub",
157 "rev_sub",
158 "min",
159 "max"
160 };
161
162 DEFINE_DEBUG_DUMP_CONTINUOUS(blend_func)
163
164
165 static const char *
166 debug_dump_func_names[] = {
167 "PIPE_FUNC_NEVER",
168 "PIPE_FUNC_LESS",
169 "PIPE_FUNC_EQUAL",
170 "PIPE_FUNC_LEQUAL",
171 "PIPE_FUNC_GREATER",
172 "PIPE_FUNC_NOTEQUAL",
173 "PIPE_FUNC_GEQUAL",
174 "PIPE_FUNC_ALWAYS"
175 };
176
177 static const char *
178 debug_dump_func_short_names[] = {
179 "never",
180 "less",
181 "equal",
182 "less_equal",
183 "greater",
184 "not_equal",
185 "greater_equal",
186 "always"
187 };
188
189 DEFINE_DEBUG_DUMP_CONTINUOUS(func)
190
191
192 static const char *
193 debug_dump_tex_target_names[] = {
194 "PIPE_TEXTURE_1D",
195 "PIPE_TEXTURE_2D",
196 "PIPE_TEXTURE_3D",
197 "PIPE_TEXTURE_CUBE"
198 };
199
200 static const char *
201 debug_dump_tex_target_short_names[] = {
202 "1d",
203 "2d",
204 "3d",
205 "cube"
206 };
207
208 DEFINE_DEBUG_DUMP_CONTINUOUS(tex_target)
209
210
211 static const char *
212 debug_dump_tex_wrap_names[] = {
213 "PIPE_TEX_WRAP_REPEAT",
214 "PIPE_TEX_WRAP_CLAMP",
215 "PIPE_TEX_WRAP_CLAMP_TO_EDGE",
216 "PIPE_TEX_WRAP_CLAMP_TO_BORDER",
217 "PIPE_TEX_WRAP_MIRROR_REPEAT",
218 "PIPE_TEX_WRAP_MIRROR_CLAMP",
219 "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE",
220 "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER"
221 };
222
223 static const char *
224 debug_dump_tex_wrap_short_names[] = {
225 "repeat",
226 "clamp",
227 "clamp_to_edge",
228 "clamp_to_border",
229 "mirror_repeat",
230 "mirror_clamp",
231 "mirror_clamp_to_edge",
232 "mirror_clamp_to_border"
233 };
234
235 DEFINE_DEBUG_DUMP_CONTINUOUS(tex_wrap)
236
237
238 static const char *
239 debug_dump_tex_mipfilter_names[] = {
240 "PIPE_TEX_MIPFILTER_NEAREST",
241 "PIPE_TEX_MIPFILTER_LINEAR",
242 "PIPE_TEX_MIPFILTER_NONE"
243 };
244
245 static const char *
246 debug_dump_tex_mipfilter_short_names[] = {
247 "nearest",
248 "linear",
249 "none"
250 };
251
252 DEFINE_DEBUG_DUMP_CONTINUOUS(tex_mipfilter)
253
254
255 static const char *
256 debug_dump_tex_filter_names[] = {
257 "PIPE_TEX_FILTER_NEAREST",
258 "PIPE_TEX_FILTER_LINEAR"
259 };
260
261 static const char *
262 debug_dump_tex_filter_short_names[] = {
263 "nearest",
264 "linear"
265 };
266
267 DEFINE_DEBUG_DUMP_CONTINUOUS(tex_filter)