da329a1d9b26b1f05d3f37026f51b0aacb41f2ad
[mesa.git] / src / glut / ggi / debug.h
1 /* $Id: debug.h,v 1.1 2000/11/19 07:41:26 jtaylor Exp $
2 ******************************************************************************
3
4 GGIMesa debugging macros
5
6 Copyright (C) 1998-1999 Marcus Sundberg [marcus@ggi-project.org]
7 Copyright (C) 1999-2000 Jon Taylor [taylorj@ggi-project.org]
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 ******************************************************************************
27 */
28
29 #ifndef _GGI_GLUT_INTERNAL_DEBUG_H
30 #define _GGI_GLUT_INTERNAL_DEBUG_H
31
32 #define DEBUG
33
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include <ggi/types.h>
37 #include <ggi/gg.h>
38
39
40 __BEGIN_DECLS
41
42 /* Exported variables */
43 #ifdef BUILDING_GGIGLUT
44 extern uint32 _ggiglutDebugState;
45 extern int _ggiglutDebugSync;
46 #else
47 IMPORTVAR uint32 _ggiglutDebugState;
48 IMPORTVAR int _ggiglutDebugSync;
49 #endif
50
51 __END_DECLS
52
53
54 /* Debugging types
55 * bit 0 is reserved! */
56
57 #define GGIGLUTDEBUG_CORE (1<<1) /* 2 */
58 #define GGIGLUTDEBUG_MODE (1<<2) /* 4 */
59 #define GGIGLUTDEBUG_COLOR (1<<3) /* 8 */
60 #define GGIGLUTDEBUG_DRAW (1<<4) /* 16 */
61 #define GGIGLUTDEBUG_MISC (1<<5) /* 32 */
62 #define GGIGLUTDEBUG_LIBS (1<<6) /* 64 */
63 #define GGIGLUTDEBUG_EVENTS (1<<7) /* 128 */
64
65 #define GGIGLUTDEBUG_ALL 0xffffffff
66
67 #ifdef __GNUC__
68
69 #ifdef DEBUG
70 #define GGIGLUTDPRINT(form,args...) if (_ggiglutDebugState) { ggDPrintf(_ggiglutDebugSync, "GGIGLUT",form, ##args); }
71 #define GGIGLUTDPRINT_CORE(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_CORE) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
72 #define GGIGLUTDPRINT_MODE(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_MODE) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
73 #define GGIGLUTDPRINT_COLOR(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_COLOR) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
74 #define GGIGLUTDPRINT_DRAW(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_DRAW) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
75 #define GGIGLUTDPRINT_MISC(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_MISC) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
76 #define GGIGLUTDPRINT_LIBS(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_LIBS) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
77 #define GGIGLUTDPRINT_EVENTS(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_EVENTS) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
78 #else /* DEBUG */
79 #define GGIGLUTDPRINT(form,args...) do{}while(0)
80 #define GGIGLUTDPRINT_CORE(form,args...) do{}while(0)
81 #define GGIGLUTDPRINT_MODE(form,args...) do{}while(0)
82 #define GGIGLUTDPRINT_COLOR(form,args...) do{}while(0)
83 #define GGIGLUTDPRINT_DRAW(form,args...) do{}while(0)
84 #define GGIGLUTDPRINT_MISC(form,args...) do{}while(0)
85 #define GGIGLUTDPRINT_LIBS(form,args...) do{}while(0)
86 #define GGIGLUTDPRINT_EVENTS(form,args...) do{}while(0)
87 #endif /* DEBUG */
88
89 #else /* __GNUC__ */
90
91 __BEGIN_DECLS
92
93 static inline void GGIGLUTDPRINT(const char *form,...)
94 {
95 #ifdef DEBUG
96 if (_ggiDebugState) {
97 va_list args;
98
99 fprintf(stderr, "GGIGLUT: ");
100 va_start(args, form);
101 vfprintf(stderr, form, args);
102 va_end(args);
103 if (_ggiglutDebugSync) fflush(stderr);
104 }
105 #endif
106 }
107
108 static inline void GGIGLUTDPRINT_CORE(const char *form,...)
109 {
110 #ifdef DEBUG
111 if (_ggiDebugState & GGIDEBUG_CORE) {
112 va_list args;
113
114 fprintf(stderr, "GGIGLUT: ");
115 va_start(args, form);
116 vfprintf(stderr, form, args);
117 va_end(args);
118 if (_ggiglutDebugSync) fflush(stderr);
119 }
120 #endif
121 }
122
123 static inline void GGIGLUTDPRINT_MODE(const char *form,...)
124 {
125 #ifdef DEBUG
126 if (_ggiDebugState & GGIDEBUG_MODE) {
127 va_list args;
128
129 fprintf(stderr, "GGIGLUT: ");
130 va_start(args, form);
131 vfprintf(stderr, form, args);
132 va_end(args);
133 if (_ggiglutDebugSync) fflush(stderr);
134 }
135 #endif
136 }
137
138 static inline void GGIGLUTDPRINT_COLOR(const char *form,...)
139 {
140 #ifdef DEBUG
141 if (_ggiDebugState & GGIDEBUG_COLOR) {
142 va_list args;
143
144 fprintf(stderr, "GGIGLUT: ");
145 va_start(args, form);
146 vfprintf(stderr, form, args);
147 va_end(args);
148 if (_ggiglutDebugSync) fflush(stderr);
149 }
150 #endif
151 }
152
153 static inline void GGIGLUTDPRINT_DRAW(const char *form,...)
154 {
155 #ifdef DEBUG
156 if (_ggiDebugState & GGIDEBUG_DRAW) {
157 va_list args;
158
159 fprintf(stderr, "GGIGLUT: ");
160 va_start(args, form);
161 vfprintf(stderr, form, args);
162 va_end(args);
163 if (_ggiglutDebugSync) fflush(stderr);
164 }
165 #endif
166 }
167
168 static inline void GGIGLUTDPRINT_MISC(const char *form,...)
169 {
170 #ifdef DEBUG
171 if (_ggiDebugState & GGIDEBUG_MISC) {
172 va_list args;
173
174 fprintf(stderr, "GGIGLUT: ");
175 va_start(args, form);
176 vfprintf(stderr, form, args);
177 va_end(args);
178 if (_ggiglutDebugSync) fflush(stderr);
179 }
180 #endif
181 }
182
183 static inline void GGIGLUTDPRINT_LIBS(const char *form,...)
184 {
185 #ifdef DEBUG
186 if (_ggiDebugState & GGIDEBUG_LIBS) {
187 va_list args;
188
189 fprintf(stderr, "GGIGLUT: ");
190 va_start(args, form);
191 vfprintf(stderr, form, args);
192 va_end(args);
193 if (_ggiglutDebugSync) fflush(stderr);
194 }
195 #endif
196 }
197
198 static inline void GGIGLUTDPRINT_EVENTS(const char *form,...)
199 {
200 #ifdef DEBUG
201 if (_ggiDebugState & GGIDEBUG_EVENTS) {
202 va_list args;
203
204 fprintf(stderr, "GGIGLUT: ");
205 va_start(args, form);
206 vfprintf(stderr, form, args);
207 va_end(args);
208 if (_ggiglutDebugSync) fflush(stderr);
209 }
210 #endif
211 }
212
213 __END_DECLS
214
215 #endif /* __GNUC__ */
216
217 #ifdef DEBUG
218 #define GGIGLUT_ASSERT(x,str) \
219 { if (!(x)) { \
220 fprintf(stderr,"GGIGLUT:%s:%d: INTERNAL ERROR: %s\n",__FILE__,__LINE__,str); \
221 exit(1); \
222 } }
223 #define GGIGLUT_APPASSERT(x,str) \
224 { if (!(x)) { \
225 fprintf(stderr,"GGIGLUT:%s:%d: APPLICATION ERROR: %s\n",__FILE__,__LINE__,str); \
226 exit(1); \
227 } }
228 #else /* DEBUG */
229 #define GGIGLUT_ASSERT(x,str) do{}while(0)
230 #define GGIGLUT_APPASSERT(x,str) do{}while(0)
231 #endif /* DEBUG */
232
233 #ifdef DEBUG
234 # define GGIGLUTD0(x) x
235 #else
236 # define GGIGLUTD0(x) /* empty */
237 #endif
238
239 #ifdef GGIGLUTDLEV
240 # if GGIGLUTDLEV == 1
241 # define GGIGLUTD1(x) x
242 # define GGIGLUTD2(x) /* empty */
243 # define GGIGLUTD3(x) /* empty */
244 # elif GGIGLUTDLEV == 2
245 # define GGIGLUTD1(x) x
246 # define GGIGLUTD2(x) x
247 # define GGIGLUTD3(x) /* empty */
248 # elif GGIGLUTDLEV > 2
249 # define GGIGLUTD1(x) x
250 # define GGIGLUTD2(x) x
251 # define GGIGLUTD3(x) x
252 # endif
253 #else
254 # define GGIGLUTD1(x) /* empty */
255 # define GGIGLUTD2(x) /* empty */
256 # define GGIGLUTD3(x) /* empty */
257 #endif
258
259 #endif /* _GGI_MESA_INTERNAL_DEBUG_H */