-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.h
More file actions
126 lines (89 loc) · 3.25 KB
/
Copy pathmain.h
File metadata and controls
126 lines (89 loc) · 3.25 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
#ifndef MAIN_H
#define MAIN_H
#include <SDL2/SDL.h>
#include <cmath>
#include <map>
#include <vector>
#include "voxel.h"
#include "volume.h"
#include "vollyglm.h"
namespace volly {
struct Texture_SDL;
class Window_SDL {
public:
SDL_Window *window;
SDL_Renderer *renderer;
glm::ivec2 size;
void create(glm::ivec2 size);
void drawTexture(Texture_SDL * tex, glm::ivec2 _pos = glm::ivec2(0), glm::ivec2 _size = glm::ivec2(-1));
void clear();
};
// wrapper around SDL_Texture
struct Texture_SDL {
SDL_Texture *_texture;
glm::u8vec4 *data_stream; // This is write-only data that should only be written to between lock-unlock calls (mutexes?)
int pitch;
glm::ivec2 size;
// Assigns data_stream and allows it to be written to
void lock() {
SDL_LockTexture(_texture, NULL, (void**) &data_stream, &pitch);
}
void unlock() {
SDL_UnlockTexture(_texture);
data_stream = nullptr;
}
Texture_SDL(glm::ivec2 size, Window_SDL* win) {
this->size = size;
_texture = SDL_CreateTexture(win->renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, size.x, size.y);
data_stream = nullptr;
}
};
struct KeyHandler {
std::map<SDL_Scancode, bool> keysDown;
bool getIfKeyDown(SDL_Scancode scan) {
return keysDown[scan];
}
/** state is either down (true) or up (false) */
void setKeyState(SDL_Scancode scan, bool state=true) {
keysDown[scan] = state;
}
};
struct Vol_LOD_Set {
int sLowR, lowR, medR, highR;
VolumeStore<Voxel> *sLow, *low, *med, *high;
VolumeStore<Voxel> *arr[4]; // different way to reference the same thing
Vol_LOD_Set(std::string filename, int coloringMode = 0, int sLowR=16, int lowR=32, int medR=128, int highR=256);
~Vol_LOD_Set() {
delete sLow;
delete low;
delete med;
delete high;
}
};
struct State {
Window_SDL *window;
Texture_SDL *screenTex;
std::vector<Vol_LOD_Set*> volumes;
int curVolume = 0, curLoD = 0;
int frame = 0;
glm::vec3 camPos = glm::vec3(0);
glm::vec3 camDir = glm::vec3(0);
glm::vec3 camUp = glm::vec3(0,0,-1);
glm::mat4 view;
KeyHandler keys;
int mouseX, mouseY, mouseDX, mouseDY;
int ms = 0;
int ms_prev = 0;
int ms_start = 0;
int winSizeX = 1152, winSizeY = 864;
int renderTargetSizeX = 400, renderTargetSizeY = 300;
void raycastOntoScreen();
void initAllVolumes();
void resolveUserInput();
void vollyMainLoop();
VolumeStore<Voxel>* getCurVol() { return volumes[curVolume]->arr[curLoD]; }
VolumeStore<Voxel>* getCurVol_LowLOD() { return volumes[curVolume]->arr[1]; }
VolumeStore<Voxel>* getCurVol_SLowLOD() { return volumes[curVolume]->arr[0]; }
};
}
#endif // MAIN_H