This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
133 lines (100 loc) · 2.89 KB
/
main.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
122
123
124
125
126
127
128
129
130
131
132
133
#include "code/DataManager.h"
#include "code/CpuIdw.h"
#include "code/CpuIdwBase.h"
#include "code/CpuIdwThreaded.h"
#include "code/FullscreenHelper.h"
#include "code/GpuIdwGlobalMemory.cuh"
#include "code/GpuIdwTexture.cuh"
#include "code/HelpPrint.h"
#include "code/Utils.h"
int currentWidth = 1920;
int currentHeight= 1200;
std::vector<CpuIdwBase*> idws;
bool cpuKernelsEnabled = false;
DataManager data;
/// Refresh all idws method
void refreshIdws(){
for (int i = idws.size() - 1; i >= 0; --i)
delete idws[i];
idws.clear();
if (cpuKernelsEnabled) {
idws.push_back(new CpuIdw(currentWidth, currentHeight));
idws.push_back(new CpuIdwThreaded(currentWidth, currentHeight));
}
idws.push_back(new GpuIdwGlobalMemory(currentWidth, currentHeight));
idws.push_back(new GpuIdwTexture(currentWidth, currentHeight, false));
//this must be initialized after glut has been initialized ...
idws.push_back(new GpuIdwTexture(currentWidth, currentHeight, true));
data.setNumberOfIdws(idws.size());
};
void drawImage() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
idws[data.getCurrentIdw()]->drawOpengl(data);
glutSwapBuffers();
}
void idleFunc() {
idws[data.getCurrentIdw()]->refresh(data, true);
data.setChangeDone();
glutPostRedisplay();
}
void reshape(int w, int h) {
fmt::print("{} {}\n", w,h);
if (w < 256 || h < 256) {
glutReshapeWindow(256, 256);
return;
}
if (w % 2 == 1 && h % 2 == 1) {
glutReshapeWindow(w+1, h + 1);
} else if (w % 2 == 1) {
glutReshapeWindow(w + 1,h);
} else if (h % 2 == 1) {
glutReshapeWindow(w, h + 1);
} else {
currentWidth = w;
currentHeight = h;
refreshIdws();
}
}
static void handleKeys(const unsigned char key, const int x, const int y) {
if (FullscreenHelper::handleKeys(key, x, y)) return;
if (HelpPrint::handleKeys(key, x, y)) return;
if (key == 'v') {
Utils::toggleVsync();
return;
}
if (key == 'g') {
cpuKernelsEnabled = !cpuKernelsEnabled;
refreshIdws();
return;
}
data.handleKeys(key, x, y);
}
static void handleSpecialKeys(const int key, const int x, const int y) {
data.handleSpecialKeys(key, x, y);
}
static void handleMouse(const int button, const int state, const int x, const int y) {
data.handleMouse(button, state, x, currentHeight - y);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(currentWidth, currentHeight);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("idw");
glutDisplayFunc(drawImage);
glutKeyboardFunc(handleKeys);
glutSpecialFunc(handleSpecialKeys);
glutMouseFunc(handleMouse);
glutIdleFunc(idleFunc);
//glutReshapeFunc(reshape);
HelpPrint::print();
Utils::setVSync(0);
refreshIdws();
try {
glutMainLoop();
} catch (const std::exception& e) {
fmt::print(fg(fmt::color::red), "Global exception handler!\n");
fmt::print(fg(fmt::color::red), "{}", e.what());
}
return 0;
}