forked from rougier/freetype-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftgl-utils.h
151 lines (128 loc) · 4.04 KB
/
ftgl-utils.h
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
/* Freetype GL - A C OpenGL Freetype engine
*
* Distributed under the OSI-approved BSD 2-Clause License. See accompanying
* file `LICENSE` for more details.
*/
#ifndef __FTGL_UTILS_H__
#define __FTGL_UTILS_H__
#include <stdio.h>
#include <stdarg.h>
#ifndef __THREAD
#if defined(__GNUC__) || defined(__clang__)
#define __THREAD __thread
#elif defined(_MSC_VER)
#define __THREAD __declspec( thread )
#else
#define __THREAD
#endif
#endif
#ifdef __cplusplus
extern "C" {
namespace ftgl {
#endif
typedef void (*error_callback_t) (const char *fmt, ...);
#ifndef IMPLEMENT_FREETYPE_GL
extern
#endif
error_callback_t log_error;
/**
* Prints input to stderr
* This is fallback function for error reporting if ftgl_set_error_callback() wans't called
*
* @param fmt cstring to be printed matching C-style printing syntax
* @param ... va_list fmt supplying arguments
*/
void
error_callback_default(const char *fmt, ...);
/**
* Set function to call on error handling
* This is fallback function for error reporting if ftgl_set_error_callback() wans't called
*
* @param error_cb callback function to call on error, see error_callback_default for reference
*/
void
set_error_callback(error_callback_t error_cb);
/*********** public error API ***********/
/**
* freetype_gl_errno is the error number if a freetype-gl function fails
* Errors < FTGL_ERR_BASE are pass-through from Freetype
*/
#ifndef IMPLEMENT_FREETYPE_GL
extern
#endif
__THREAD int freetype_gl_errno;
/**
* freetype_gl_warnings is a flag that activates output of warnings.
* Default is warnings off
*/
#ifndef IMPLEMENT_FREETYPE_GL
extern
#endif
__THREAD int freetype_gl_warnings;
/**
* freetype_gl_message is the error message if a freetype-gl function fails
*/
#ifndef IMPLEMENT_FREETYPE_GL
extern
#endif
__THREAD const char * freetype_gl_message;
/**
* FTGL_Error_String converts an errno to the message (including FT_errors)
*/
#ifndef IMPLEMENT_FREETYPE_GL
extern
#endif
const char* FTGL_Error_String( unsigned int error_code );
#ifndef FTGL_ERR_PREFIX
# define FTGL_ERR_PREFIX FTGL_Err_
#endif
#ifndef FTGL_ERR_CAT
# define FTGL_ERR_XCAT( x, y ) x ## y
# define FTGL_ERR_CAT( x, y ) FTGL_ERR_XCAT( x, y )
#endif
#define FTGL_ERR_BASE 0xE0 /* Freetype GL errors start at 0xE0 */
#ifndef IMPLEMENT_FREETYPE_GL
extern
#endif
const char* freetype_gl_errstrs[];
#define freetype_gl_error(errno) { \
freetype_gl_errno = FTGL_ERR_CAT( FTGL_ERR_PREFIX, errno); \
freetype_gl_message = freetype_gl_errstrs[freetype_gl_errno]; \
log_error("FTGL Error %s:%d: %s\n", __FILE__, __LINE__, freetype_gl_message); \
}
#define freetype_gl_error_str(errno, string) { \
freetype_gl_errno = FTGL_ERR_CAT( FTGL_ERR_PREFIX, errno); \
freetype_gl_message = freetype_gl_errstrs[freetype_gl_errno]; \
log_error("FTGL Error %s:%d: %s '%s'\n", __FILE__, __LINE__, freetype_gl_message, string); \
}
#define freetype_gl_warning(errno) { \
freetype_gl_errno = FTGL_ERR_CAT( FTGL_ERR_PREFIX, errno); \
freetype_gl_message = freetype_gl_errstrs[freetype_gl_errno]; \
if(freetype_gl_warnings) log_error("FTGL Warning %s:%d: %s\n", __FILE__, __LINE__, freetype_gl_message); \
}
#define freetype_error(errno) { \
freetype_gl_errno = errno; \
freetype_gl_message = freetype_gl_errstrs[errno]; \
log_error("Freetype Error %s:%d: %s\n", __FILE__, __LINE__, freetype_gl_message); \
}
#define FTGL_ERR_MAX FTGL_ERR_BASE+0x1F
#ifndef FTGL_ERRORDEF_
# ifndef FTGL_ERRORDEF
# define FTGL_ERRORDEF( e, v, s ) e = v,
# define FTGL_ERROR_START_LIST enum {
# define FTGL_ERROR_END_LIST FTGL_ERR_CAT( FTGL_ERR_PREFIX, Max ) };
# endif /* !FTGL_ERRORDEF */
/* this macro is used to define an error */
# define FTGL_ERRORDEF_( e, v, s ) \
FTGL_ERRORDEF( FTGL_ERR_CAT( FTGL_ERR_PREFIX, e ), v + FTGL_ERR_BASE, s )
# endif /* !FTGL_ERRORDEF_ */
#include "freetype-gl-errdef.h"
#undef FTGL_ERRORDEF_
#undef __FREETYPE_GL_ERRORS_H__
#undef FTGL_ERROR_START_LIST
#undef FTGL_ERROR_END_LIST
#ifdef __cplusplus
}
}
#endif
#endif