-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpenGLDebug.cpp
104 lines (83 loc) · 2.91 KB
/
OpenGLDebug.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
#include <GL/glew.h>
#include <iostream>
#include "OpenGLDebug.h"
#include "config.h"
#include "ImageUtils.h"
#include "OpenGLTexture.h"
#include "dawn.h"
using namespace std;
using namespace dawn;
using boost::any_cast;
int order = 0;
void OpenGLDebug::WriteFBO(const std::string &title)
{
#ifdef DEBUG_WRITE_FBO
GLubyte data[WINDOW_WIDTH * WINDOW_HEIGHT * 4];
glReadPixels(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, data);
ImageUtils::WriteImage(title + ".png", WINDOW_WIDTH, WINDOW_HEIGHT, data);
#endif
}
void OpenGLDebug::WriteFilterInput(Object3D *object)
{
std::stringstream ss;
ss << order++ << "_object_" << object->id() << "_input";
WriteFBO(ss.str());
}
void OpenGLDebug::WriteFilterPass(Object3D *object, unsigned int pass)
{
std::stringstream ss;
ss << order++ << "_object_" << object->id() << "_pass_" << pass;
WriteFBO(ss.str());
}
void OpenGLDebug::WriteFilterOutput(Object3D *object)
{
std::stringstream ss;
ss << order++ << "_object_" << object->id() << "_final";
WriteFBO(ss.str());
}
int orderStencil = 0;
void OpenGLDebug::WriteStencil(const std::string &title)
{
#ifdef DEBUG_WRITE_FBO
std::stringstream ss;
ss << orderStencil++ << "_stencil_" << title << ".png";
size_t s = WINDOW_WIDTH * WINDOW_HEIGHT;
GLubyte stencildata[s];
glReadPixels(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencildata);
GLubyte data[s * 4];
int j = 0;
for (int i = 0; i < s; i++) {
data[j++] = stencildata[i];
data[j++] = stencildata[i];
data[j++] = stencildata[i];
data[j++] = stencildata[i];
}
ImageUtils::WriteImage(ss.str(), WINDOW_WIDTH, WINDOW_HEIGHT, data);
#endif
}
void OpenGLDebug::PrintUniformMap(UniformMap uniforms)
{
cout << "Uniforms = {" << endl;
GLint textureUnit = 0;
for (UniformMap::iterator itr = uniforms.begin(); itr != uniforms.end(); itr++) {
uniform_t u = itr->second;
if (u.type() == typeid(int)) {
cout << "Binding " << itr->first << " as int " << any_cast<int>(u) << endl;
} else if (u.type() == typeid(float)) {
cout << "Binding " << itr->first << " as float " << any_cast<float>(u) << endl;
} else if (u.type() == typeid(vec2f)) {
cout << "Binding " << itr->first << " as vec2f " << any_cast<vec2f>(u) << endl;
} else if (u.type() == typeid(vec3f)) {
cout << "Binding " << itr->first << " as vec3f " << any_cast<vec3f>(u) << endl;
} else if (u.type() == typeid(vec4f)) {
cout << "Binding " << itr->first << " as vec4f " << any_cast<vec4f>(u) << endl;
} else if (u.type() == typeid(mat4f)) {
// cout << "Binding " << itr->first << " as mat4f " << any_cast<mat4f>(u) << endl;
} else if (u.type() == typeid(Pixmap *)) {
cout << "Binding " << itr->first << " as Pixmap " << endl;
} else if (u.type() == typeid(OpenGLTexturePtr)) {
cout << "Binding " << itr->first << " as OpenGLTexturePtr" << endl;
}
}
cout << "}" << endl;
}