-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.h
More file actions
134 lines (106 loc) · 2.82 KB
/
MainWindow.h
File metadata and controls
134 lines (106 loc) · 2.82 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
/*
* MainWindow.h
*
* Created on: Apr 10, 2020
* Author: ans
*/
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#pragma once
#define GL_GLEXT_PROTOTYPES
#include <GLFW/glfw3.h>
#include <chrono> // std::chrono
#include <cstddef> // std::size_t
#include <functional> // std::function, std::placeholders
#include <stdexcept> // std::runtime_error
#include <string> // std::string, std::to_string
#include <vector>
#include "Pixels.h"
#include "PixelTest.h"
#define UNUSED(x) (void)(x)
class MainWindow {
public:
using ResizeFunction = std::function<void(int, int)>;
using UpdateFunction = std::function<void(double)>;
enum RenderingMode {
RENDERING_MODE_PBO,
RENDERING_MODE_POINTS,
RENDERING_MODE_TEXTURE
};
MainWindow();
virtual ~MainWindow();
void init(unsigned int w, unsigned int h, const std::string& title);
bool update();
int getWidth() const;
int getHeight() const;
double getTime() const;
double getElapsedTime() const;
double getFPS() const;
RenderingMode getRenderingMode() const;
bool isKeyPressed(unsigned int code) const;
bool isKeyHeld(unsigned int code) const;
bool isKeyReleased(unsigned int code) const;
bool isKeyRepeated(unsigned int code) const;
void setRenderingMode(RenderingMode mode);
void setClearBuffer(bool clear);
void setPixelSize(unsigned short size);
void setPixelTest(const PixelTest& test);
void putPixel(
unsigned int x,
unsigned int y,
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a = 255,
bool test = true
);
void setOnUpdate(UpdateFunction callBack);
void setOnResize(ResizeFunction callBack);
void setDebugText(const std::string& text);
MainWindow(MainWindow&) = delete;
private:
void setProjection();
void clearKeys();
void initRenderingTarget();
void beginRendering();
void renderQuad();
void endRendering();
void destroyRenderingTarget();
void onFramebuffer(int w, int h);
void onKey(int key, int action);
static void callbackError(int error, const char * description);
static void callbackFramebuffer(GLFWwindow * window, int width, int height);
static void callbackKey(GLFWwindow * window, int key, int scancode, int action, int mods);
static std::string glErrorString(GLenum errorCode);
bool glfwInitialized;
GLFWwindow * windowPointer;
RenderingMode renderingMode;
unsigned int pboId;
unsigned int textureId;
Pixels pixels;
std::string title;
int width;
int height;
unsigned char bytes;
int pixelWidth;
int pixelHeight;
bool clearBuffer;
unsigned short pixelSize;
unsigned short halfPixelSize;
bool rendering;
double lastTime;
double elapsedTime;
double fps;
std::string debug;
bool debugChanged;
struct {
bool pressed;
bool held;
bool released;
bool repeated;
} keys[GLFW_KEY_LAST];
UpdateFunction onUpdate;
ResizeFunction onResize;
PixelTest pixelTest;
};
#endif /* MAINWINDOW_H_ */