Repository navigation
Expand file tree
/
Copy pathLogger.cpp
More file actions
210 lines (194 loc) · 5.59 KB
/
Copy pathLogger.cpp
File metadata and controls
210 lines (194 loc) · 5.59 KB
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
#include "Logger.h"
#include <sstream>
#include <iostream>
#include <GLFW/glfw3.h>
#ifndef __gl_h_
#include <glad/glad.h>
#endif
#include "CommonUtils.h"
#include "LogStream.h"
#include "ErrorHandling.h"
OWUtils::Time::time_point Logger::previous_seconds;
const static OWUtils::Time::duration gInterval = std::chrono::milliseconds(1000);
int Logger::frame_count = 0;
Logger::Logger()
{}
void Logger::update_fps_counter(GLFWwindow* window) const
{
OWUtils::Time::time_point current_seconds = OWUtils::Time::now();
OWUtils::Time::duration elapsed = current_seconds - previous_seconds;
// limit text updates
if (elapsed > gInterval)
{
previous_seconds = current_seconds;
OWUtils::Float xx = std::chrono::duration<float>(elapsed).count();
unsigned int fps = static_cast<unsigned int>(frame_count / xx);
std::stringstream ss;
ss << "opengl @ fps: " << fps << "\n";
glfwSetWindowTitle(window, ss.str().c_str());
frame_count = 0;
}
frame_count++;
}
void Logger::log_gl_params() const
{
LogStream tee(LogStreamLevel::ImportantInfo);
GLenum params[] = {
GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
GL_MAX_CUBE_MAP_TEXTURE_SIZE,
GL_MAX_DRAW_BUFFERS,
GL_MAX_FRAGMENT_UNIFORM_COMPONENTS,
GL_MAX_TEXTURE_IMAGE_UNITS,
GL_MAX_TEXTURE_SIZE,
GL_MAX_VARYING_FLOATS,
GL_MAX_VERTEX_ATTRIBS,
GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,
GL_MAX_VERTEX_UNIFORM_COMPONENTS,
GL_MAX_VIEWPORT_DIMS,
GL_STEREO,
};
const char* names[] = {
"GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS",
"GL_MAX_CUBE_MAP_TEXTURE_SIZE",
"GL_MAX_DRAW_BUFFERS",
"GL_MAX_FRAGMENT_UNIFORM_COMPONENTS",
"GL_MAX_TEXTURE_IMAGE_UNITS",
"GL_MAX_TEXTURE_SIZE",
"GL_MAX_VARYING_FLOATS",
"GL_MAX_VERTEX_ATTRIBS",
"GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS",
"GL_MAX_VERTEX_UNIFORM_COMPONENTS",
"GL_MAX_VIEWPORT_DIMS",
"GL_STEREO",
};
tee << "GL Context Params:\n";
// integers - only works if the order is 0-10 integer return types6
for (int i = 0; i < 10; i++)
{
int v = 0;
glGetIntegerv(params[i], &v);
tee << names[i] << " " << v << "\n";
}
// others
int v[2];
v[0] = v[1] = 0;
glGetIntegerv(params[10], v);
tee << names[10] << " " << v[0] << " " << v[1] << "\n";
unsigned char s = 0;
glGetBooleanv(params[11], &s);
tee << names[11] << " " << s << "\n";
const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
const GLubyte* version = glGetString(GL_VERSION); // version as a string
tee << "Renderer: " << renderer << "\n";
tee << "OpenGL version supported: " << version << "\n";
tee << "-----------------------------\n";
}
std::string Logger::toString(GLenum type)
{
switch (type)
{
case GL_BOOL: return "bool";
case GL_INT: return "int";
case GL_FLOAT: return "float";
case GL_FLOAT_VEC2: return "vec2";
case GL_FLOAT_VEC3: return "vec3";
case GL_FLOAT_VEC4: return "vec4";
case GL_FLOAT_MAT2: return "mat2";
case GL_FLOAT_MAT3: return "mat3";
case GL_FLOAT_MAT4: return "mat4";
case GL_SAMPLER_2D: return "sampler2D";
case GL_SAMPLER_3D: return "sampler3D";
case GL_SAMPLER_CUBE: return "samplerCube";
case GL_SAMPLER_2D_SHADOW: return "sampler2DShadow";
default: break;
}
return "other";
}
void Logger::print_all(GLuint programme)
{
LogStream tee(LogStreamLevel::ImportantInfo);
tee << "--------------------\nshader programme " << programme << " info:\n";
int params = -1;
glGetProgramiv(programme, GL_LINK_STATUS, ¶ms);
tee << "GL_LINK_STATUS = " << params << "\n";
glGetProgramiv(programme, GL_ATTACHED_SHADERS, ¶ms);
tee << "GL_ATTACHED_SHADERS = " << params << "\n";
glGetProgramiv(programme, GL_ACTIVE_ATTRIBUTES, ¶ms);
tee << "GL_ACTIVE_ATTRIBUTES = " << params << "\n";
for (int i = 0; i < params; i++)
{
char name[64];
int max_length = 64;
int actual_length = 0;
int size = 0;
GLenum type;
glGetActiveAttrib(programme, i, max_length, &actual_length, &size, &type, name);
if (size > 1)
{
for (int j = 0; j < size; j++)
{
std::stringstream long_name;
long_name << name << "[" << j << "]\n";
int location = glGetAttribLocation(programme, long_name.str().c_str());
tee << " " << i << ") type:" << toString(type)
<< " name:" << long_name.str().c_str()
<< " location:" << location << "\n";
}
}
else
{
int location = glGetAttribLocation(programme, name);
tee << " " << i << ") type:" << toString(type)
<< " name:" << name
<< " location:" << location << "\n";
}
}
glGetProgramiv(programme, GL_ACTIVE_UNIFORMS, ¶ms);
tee << "GL_ACTIVE_UNIFORMS = " << params << "\n";
for (int i = 0; i < params; i++)
{
char name[64];
int max_length = 64;
int actual_length = 0;
int size = 0;
GLenum type;
glGetActiveUniform(programme, i, max_length, &actual_length, &size, &type, name);
if (size > 1)
{
for (int j = 0; j < size; j++)
{
std::stringstream long_name;
long_name << name << "[" << j << "]\n";
int location = glGetUniformLocation(programme, long_name.str().c_str());
tee << " " << i << ") type:" << toString(type)
<< " name:" << long_name.str().c_str()
<< " location:" << location << "\n";
}
}
else {
int location = glGetUniformLocation(programme, name);
tee << " " << i << ") type:" << toString(type)
<< " name:" << name
<< " location:" << location << "\n";
}
}
}
std::string Logger::versionString() const
{
std::string ss = glfwGetVersionString();
if (ss.size())
{
return ss;
}
else
{
std::string s = "OpenGL first program ";
GLenum e = glGetError();
if (e == GL_INVALID_ENUM)
s += OWOpenglErrorToString(e);
else if (e == GL_INVALID_OPERATION)
s += OWOpenglErrorToString(e);
else s += "NULL";
return s;
}
}