1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #include <stdio.h> |
---|
3 | #include <stdarg.h> |
---|
4 | #include <syslog.h> |
---|
5 | |
---|
6 | #include <GL/glew.h> |
---|
7 | |
---|
8 | #include "nanovis.h" |
---|
9 | #include "Trace.h" |
---|
10 | |
---|
11 | static const char *syslogLevels[] = { |
---|
12 | "emergency", /* System is unusable */ |
---|
13 | "alert", /* Action must be taken immediately */ |
---|
14 | "critical", /* Critical conditions */ |
---|
15 | "error", /* Error conditions */ |
---|
16 | "warning", /* Warning conditions */ |
---|
17 | "notice", /* Normal but significant condition */ |
---|
18 | "info", /* Informational */ |
---|
19 | "debug", /* Debug-level messages */ |
---|
20 | }; |
---|
21 | |
---|
22 | void |
---|
23 | LogMessage(int priority, const char *path, int lineNum, const char* fmt, ...) |
---|
24 | { |
---|
25 | #define MSG_LEN (2047) |
---|
26 | char message[MSG_LEN+1]; |
---|
27 | const char *s; |
---|
28 | int length; |
---|
29 | va_list lst; |
---|
30 | |
---|
31 | va_start(lst, fmt); |
---|
32 | s = strrchr(path, '/'); |
---|
33 | if (s == NULL) { |
---|
34 | s = path; |
---|
35 | } else { |
---|
36 | s++; |
---|
37 | } |
---|
38 | length = snprintf(message, MSG_LEN, "%s: %s:%d ", |
---|
39 | syslogLevels[priority], s, lineNum); |
---|
40 | length += vsnprintf(message + length, MSG_LEN - length, fmt, lst); |
---|
41 | message[MSG_LEN] = '\0'; |
---|
42 | syslog(priority, message, length); |
---|
43 | } |
---|
44 | |
---|
45 | bool |
---|
46 | CheckFBO(GLenum *statusPtr) |
---|
47 | { |
---|
48 | *statusPtr = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); |
---|
49 | return (*statusPtr == GL_FRAMEBUFFER_COMPLETE_EXT); |
---|
50 | } |
---|
51 | |
---|
52 | void |
---|
53 | PrintFBOStatus(GLenum status, const char *prefix) |
---|
54 | { |
---|
55 | const char *mesg; |
---|
56 | switch(status) { |
---|
57 | case GL_FRAMEBUFFER_COMPLETE_EXT: |
---|
58 | mesg = "<<<< OK >>>>"; break; |
---|
59 | case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: |
---|
60 | mesg = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT"; break; |
---|
61 | case GL_FRAMEBUFFER_UNSUPPORTED_EXT: |
---|
62 | mesg = "GL_FRAMEBUFFER_UNSUPPORTED_EXT"; break; |
---|
63 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: |
---|
64 | mesg = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT"; break; |
---|
65 | case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: |
---|
66 | mesg = "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT"; break; |
---|
67 | case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: |
---|
68 | mesg = "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT"; break; |
---|
69 | case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: |
---|
70 | mesg = "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT"; break; |
---|
71 | case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: |
---|
72 | mesg = "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT"; break; |
---|
73 | default: |
---|
74 | TRACE("FB Status: %s: UNKNOWN framebuffer status %u\n", |
---|
75 | prefix, (unsigned int)status); |
---|
76 | return; |
---|
77 | } |
---|
78 | TRACE("FB Status: %s: %s\n", prefix, mesg); |
---|
79 | } |
---|
80 | |
---|
81 | bool |
---|
82 | CheckGL(const char *prefix) |
---|
83 | { |
---|
84 | const char *mesg; |
---|
85 | GLenum status = (GLenum)glGetError(); |
---|
86 | switch(status) { |
---|
87 | case GL_NO_ERROR: |
---|
88 | return true; |
---|
89 | case GL_INVALID_ENUM: |
---|
90 | mesg = "GL_INVALID_ENUM"; break; |
---|
91 | case GL_INVALID_VALUE: |
---|
92 | mesg = "GL_INVALID_VALUE"; break; |
---|
93 | case GL_INVALID_OPERATION: |
---|
94 | mesg = "GL_INVALID_OPERATION"; break; |
---|
95 | case GL_STACK_OVERFLOW: |
---|
96 | mesg = "GL_STACK_OVERFLOW"; break; |
---|
97 | case GL_STACK_UNDERFLOW: |
---|
98 | mesg = "GL_STACK_UNDERFLOW"; break; |
---|
99 | case GL_OUT_OF_MEMORY: |
---|
100 | mesg = "GL_OUT_OF_MEMORY"; break; |
---|
101 | case GL_INVALID_FRAMEBUFFER_OPERATION_EXT: |
---|
102 | mesg = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT"; break; |
---|
103 | default: |
---|
104 | TRACE("GL Status: %s: Unknown status %d\n", prefix, status); |
---|
105 | return false; |
---|
106 | } |
---|
107 | TRACE("GL Status: %s: %s\n", prefix, mesg); |
---|
108 | return false; |
---|
109 | } |
---|
110 | |
---|
111 | |
---|