-
Notifications
You must be signed in to change notification settings - Fork 0
/
ogl.cpp
121 lines (105 loc) · 3.42 KB
/
ogl.cpp
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
#include "ogl"
#include <map>
namespace ogl
{
GLFW*& GLFW::instance()
{
static GLFW* i;
return i;
}
void GLFW::errorCallback(int error, const char* description)
{
std::cerr << "GLFW error #" << error << ": " << description << std::endl;
}
void GLAPIENTRY GLFW::debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const GLvoid* userParam)
{
bool Error = false;
bool Info = false;
char const* srcS = "Unknown Source";
if(source == GL_DEBUG_SOURCE_API_ARB)
srcS = "OpenGL";
else if(source == GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
srcS = "Windows";
else if(source == GL_DEBUG_SOURCE_SHADER_COMPILER_ARB)
srcS = "Shader Compiler";
else if(source == GL_DEBUG_SOURCE_THIRD_PARTY_ARB)
srcS = "Third Party";
else if(source == GL_DEBUG_SOURCE_APPLICATION_ARB)
srcS = "Application";
else if(source == GL_DEBUG_SOURCE_OTHER_ARB)
srcS = "Other";
char const* typeS = "unknown error";
if(type == GL_DEBUG_TYPE_ERROR_ARB)
typeS = "error";
else if(type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
typeS = "deprecated behavior";
else if(type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
typeS = "undefined behavior";
else if(type == GL_DEBUG_TYPE_PORTABILITY_ARB)
typeS = "portability";
else if(type == GL_DEBUG_TYPE_PERFORMANCE_ARB)
typeS = "performance";
else if(type == GL_DEBUG_TYPE_OTHER_ARB)
{
typeS = "message";
Info = false
|| id == 131076 // NVIDIA: Small pointer value, intended to be used as an offset into a buffer? Yes.
|| (strstr(message, "info:") != nullptr);
}
char const* severityS= "unknown severity";
if(severity == GL_DEBUG_SEVERITY_HIGH_ARB)
{
severityS = "high";
Error = true;
}
else if(severity == GL_DEBUG_SEVERITY_MEDIUM_ARB)
severityS = "medium";
else if(severity == GL_DEBUG_SEVERITY_LOW_ARB)
severityS = "low";
if (Error || !Info)
std::cout << srcS << ": " << typeS << "(" << severityS << ") " << id << ": " << message << std::endl;
}
void GLFWWindow::resizeCallback(GLFWwindow *window, int w, int h)
{
auto* self = getThis<GLFWWindow>(window);
if (self && self->resize)
self->resize((unsigned) w, (unsigned) h);
}
void GLFWWindow::keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
auto* self = getThis<GLFWWindow>(window);
if (self)
{
auto pressed = action != GLFW_RELEASE;
auto repeated = action == GLFW_REPEAT;
if (self->keyboard)
self->keyboard(key, pressed, repeated);
if (self->modKeyboard)
self->modKeyboard(key, pressed, repeated, mods);
}
}
void GLFWWindow::textCallback(GLFWwindow *window, unsigned chr)
{
auto* self = getThis<GLFWWindow>(window);
if (self && self->text)
self->text(chr);
}
void GLFWWindow::mouseCallback(GLFWwindow *window, double x, double y)
{
auto* self = getThis<GLFWWindow>(window);
if (self && self->mouse)
self->mouse((int) x, (int) y);
}
void GLFWWindow::buttonsCallback(GLFWwindow *window, int button, int action, int mods)
{
auto* self = getThis<GLFWWindow>(window);
if (self && self->buttons)
self->buttons(button, action == GLFW_PRESS);
}
void GLFWWindow::scrollCallback(GLFWwindow *window, double x, double y)
{
auto* self = getThis<GLFWWindow>(window);
if (self && self->scroll)
self->scroll((int) x, (int) y);
}
} // namespace