aboutsummaryrefslogtreecommitdiffstats
path: root/src/glut/ggi/debug.h
blob: da329a1d9b26b1f05d3f37026f51b0aacb41f2ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* $Id: debug.h,v 1.1 2000/11/19 07:41:26 jtaylor Exp $
******************************************************************************

   GGIMesa debugging macros

   Copyright (C) 1998-1999 Marcus Sundberg	[marcus@ggi-project.org]
   Copyright (C) 1999-2000 Jon Taylor		[taylorj@ggi-project.org]
  
   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************
*/

#ifndef _GGI_GLUT_INTERNAL_DEBUG_H
#define _GGI_GLUT_INTERNAL_DEBUG_H

#define DEBUG

#include <stdio.h>
#include <stdarg.h>
#include <ggi/types.h>
#include <ggi/gg.h>


__BEGIN_DECLS

/* Exported variables */
#ifdef BUILDING_GGIGLUT
extern uint32     _ggiglutDebugState;
extern int        _ggiglutDebugSync;
#else
IMPORTVAR uint32  _ggiglutDebugState;
IMPORTVAR int     _ggiglutDebugSync;
#endif

__END_DECLS


/* Debugging types
 * bit 0 is reserved! */

#define GGIGLUTDEBUG_CORE		(1<<1)	/*   2 */
#define GGIGLUTDEBUG_MODE		(1<<2)	/*   4 */
#define GGIGLUTDEBUG_COLOR		(1<<3)	/*   8 */
#define GGIGLUTDEBUG_DRAW		(1<<4)	/*  16 */
#define GGIGLUTDEBUG_MISC		(1<<5)	/*  32 */
#define GGIGLUTDEBUG_LIBS		(1<<6)	/*  64 */
#define GGIGLUTDEBUG_EVENTS		(1<<7)	/* 128 */

#define GGIGLUTDEBUG_ALL	0xffffffff

#ifdef __GNUC__

#ifdef DEBUG
#define GGIGLUTDPRINT(form,args...)	   if (_ggiglutDebugState) { ggDPrintf(_ggiglutDebugSync, "GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_CORE(form,args...)   if (_ggiglutDebugState & GGIGLUTDEBUG_CORE) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_MODE(form,args...)   if (_ggiglutDebugState & GGIGLUTDEBUG_MODE) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_COLOR(form,args...)  if (_ggiglutDebugState & GGIGLUTDEBUG_COLOR) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_DRAW(form,args...)   if (_ggiglutDebugState & GGIGLUTDEBUG_DRAW) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_MISC(form,args...)   if (_ggiglutDebugState & GGIGLUTDEBUG_MISC) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_LIBS(form,args...)   if (_ggiglutDebugState & GGIGLUTDEBUG_LIBS) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#define GGIGLUTDPRINT_EVENTS(form,args...) if (_ggiglutDebugState & GGIGLUTDEBUG_EVENTS) { ggDPrintf(_ggiglutDebugSync,"GGIGLUT",form, ##args); }
#else /* DEBUG */
#define GGIGLUTDPRINT(form,args...)		do{}while(0)
#define GGIGLUTDPRINT_CORE(form,args...)	do{}while(0)
#define GGIGLUTDPRINT_MODE(form,args...)	do{}while(0)
#define GGIGLUTDPRINT_COLOR(form,args...)	do{}while(0)
#define GGIGLUTDPRINT_DRAW(form,args...)	do{}while(0)
#define GGIGLUTDPRINT_MISC(form,args...)	do{}while(0)
#define GGIGLUTDPRINT_LIBS(form,args...)	do{}while(0)
#define GGIGLUTDPRINT_EVENTS(form,args...)	do{}while(0)
#endif /* DEBUG */

#else /* __GNUC__ */

__BEGIN_DECLS

static inline void GGIGLUTDPRINT(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_CORE(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_CORE) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_MODE(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_MODE) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_COLOR(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_COLOR) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_DRAW(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_DRAW) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_MISC(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_MISC) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_LIBS(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_LIBS) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

static inline void GGIGLUTDPRINT_EVENTS(const char *form,...)
{
#ifdef DEBUG
	if (_ggiDebugState & GGIDEBUG_EVENTS) {
		va_list args;

		fprintf(stderr, "GGIGLUT: ");
		va_start(args, form);
		vfprintf(stderr, form, args);
		va_end(args);
		if (_ggiglutDebugSync) fflush(stderr);
	}
#endif
}

__END_DECLS

#endif /* __GNUC__ */

#ifdef DEBUG
#define GGIGLUT_ASSERT(x,str) \
{ if (!(x)) { \
	fprintf(stderr,"GGIGLUT:%s:%d: INTERNAL ERROR: %s\n",__FILE__,__LINE__,str); \
	exit(1); \
} }
#define GGIGLUT_APPASSERT(x,str) \
{ if (!(x)) { \
	fprintf(stderr,"GGIGLUT:%s:%d: APPLICATION ERROR: %s\n",__FILE__,__LINE__,str); \
	exit(1); \
} }
#else /* DEBUG */
#define GGIGLUT_ASSERT(x,str)	do{}while(0)
#define GGIGLUT_APPASSERT(x,str)	do{}while(0)
#endif /* DEBUG */

#ifdef DEBUG
# define GGIGLUTD0(x)	x
#else
# define GGIGLUTD0(x)	/* empty */
#endif

#ifdef GGIGLUTDLEV
# if GGIGLUTDLEV == 1
#  define GGIGLUTD1(x)	x
#  define GGIGLUTD2(x)	/* empty */
#  define GGIGLUTD3(x)	/* empty */
# elif GGIGLUTDLEV == 2
#  define GGIGLUTD1(x)	x
#  define GGIGLUTD2(x)	x
#  define GGIGLUTD3(x)	/* empty */
# elif GGIGLUTDLEV > 2
#  define GGIGLUTD1(x)	x
#  define GGIGLUTD2(x)	x
#  define GGIGLUTD3(x)	x
# endif
#else
# define GGIGLUTD1(x)	/* empty */
# define GGIGLUTD2(x)	/* empty */
# define GGIGLUTD3(x)	/* empty */
#endif

#endif /* _GGI_MESA_INTERNAL_DEBUG_H */