-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sin.hpp
280 lines (175 loc) · 3.69 KB
/
Sin.hpp
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#ifndef __SIN_H__
#define __SIN_H__
// --- * --- * ---
// deps
#include "bitter/kvrnel/GLM.hpp"
#include "ui/Frame.hpp"
#include "ui/Debug_Draw.hpp"
#include "shader/Frame.hpp"
#include "mesh/Frame.hpp"
// --- * --- * ---
// info
class SIN {
public:
VERSION "v0.01.3b";
AUTHOR "IBN-3DILA";
// indices into shader array
enum {
DEBUG,TEXT,
IMAGE,MESH,
MATBAKE,
NUM_SHMODES
};
// indices into color array
enum {
BLACK,RED,GREEN,YELLOW,
BLUE,PURPLE,CYAN,WHITE,
BRIGHT = 0x08,
OPAQUE = 0xF0,
XPARENT = 0x80
};
cx32 LINE_VAO_SZ = 0x100 * 2;
// --- * --- * ---
// helpers
typedef std::vector<Meshes> Batches;
typedef std::vector<Sprite> Sprites;
// --- * --- * ---
// attrs
public:
Batches meshes;
Programs programs;
Program* program;
Meshes* batch;
uint32_t batch_id=-1;
Sprites sprites;
// --- * --- * ---
// guts
private:
typedef Debug_Draw DD;
typedef std::vector <
Meshes::Draw_Queue
> Draw_Queues;
struct Queue {
Draw_Queues draw_data;
uint32_t top = 0;
uint32_t i = 0;
};
typedef std::vector<Queue> Queues;
Queues m_queues;
// for gl buffers
enum {
MATRIX_SSBO,
NUM_BUFFS
};
GBuff m_gbuff[NUM_BUFFS];
DD m_dd_lines;
DD m_dd_points;
UI m_ui;
// ^makes
void nit_buffs(void);
// updates ssbo with matrix block
void upload_mats(
Meshes::Draw_Queue_Mats& mats
);
uint32_t m_shaders[NUM_SHMODES];
// --- * --- * ---
// sub-steps of draw_enqueued
void draw_nodes(void);
void draw_dd(void);
void draw_ui(void);
// --- * --- * ---
// iface
public:
// ctrash
SIN(void);
~SIN(void);
SINGLETON(SIN);
// create new mesh batch
uint32_t new_batch(
uint32_t pidex=MESH,
uint32_t texsz=256
);
// use/dont use
void bind_batch(uint32_t idex);
void unbind_batch(void);
// instantiate an array of
// shader params
void nit_programs(
shader::List& list
);
// put draw commands "on hold"
void enqueue(
uint32_t batid,
uint32_t meshid,
mat4& model,
mat3& nmat
);
// ^exec
void draw_enqueued(void);
// world space coords
void draw_line(
vec3 a,
vec3 b,
uint8_t color=OPAQUE|RED,
float width=1.0f
);
// ^screen space
void draw_line(
vec2 a,
vec2 b,
uint8_t color=OPAQUE|RED,
float width=1.0f
);
// world space coords
void draw_point(
vec3 a,
uint8_t color=OPAQUE|YELLOW,
float width=1.0f
);
// ^screen space
void draw_point(
vec2 a,
uint8_t color=OPAQUE|YELLOW,
float width=1.0f
);
// makes ui element
// gives idex to it
uint32_t draw_ui_text(
std::string ct,
vec3 pos = {0,0,0},
vec3 dim = {9,16,8},
uint16_t color = OPAQUE|WHITE,
bool show_ctl = false
);
// ^same system, plain quad
uint32_t draw_ui_rect(
vec3 pos,
vec2 dim,
uint16_t color=(OPAQUE|BRIGHT|BLACK) << 8
);
// ^retrieve
inline UI::Elem& ui_elem(uint32_t idex) {
return m_ui.get_elem(idex);
};
// ui draw cursor ctl
inline vec2& get_ui_cursor(void) {
return m_ui.get_cursor();
};
inline void reset_ui_cursor(void) {
m_ui.reset_cursor();
};
inline float get_line_layer(void) {
return m_dd_lines.get_layer();
};
inline void set_line_layer(float z) {
m_dd_lines.set_layer(z);
};
inline float get_point_layer(void) {
return m_dd_points.get_layer();
};
inline void set_point_layer(float z) {
m_dd_points.set_layer(z);
};
};
// --- * --- * ---
#endif // __SIN_H__