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
|
#pragma once
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
#include "../core.h"
#include "../math.h"
#include "../array/array.h"
#define BATCH_SIZE 2000
struct TextChar {
s64 lsb;
s64 advance;
Vec2 bbox0;
Vec2 bbox1;
Vec2 size;
};
struct TextState {
r32 scale;
u32 pixel_size;
s32 ascent;
s32 descent;
s32 linegap;
u32 texture_atlas_id;
u32 sp;
u32 vao;
u32 vbo;
u32 chunk_size;
IVec2 bbox0;
IVec2 bbox1;
stbtt_fontinfo font;
s32* char_indexes;
Mat4* transforms;
TextChar* char_map;
};
struct GlQuad {
u32 sp;
u32 vao;
};
struct CameraOrtho {
b8 update;
Vec3 up;
Vec3 pos;
Vec3 look;
Mat4 view;
Mat4 proj;
};
struct GLRenderer {
b8 cq_init;
GlQuad quad;
// ui camera
CameraOrtho ui_cam;
// camera
Vec3 preset_up_dir;
Mat4 cam_proj;
//b8 ui_cam_update;
//Vec3 ui_cam_pos;
//Vec3 ui_cam_look;
//Mat4 ui_cam_view;
// game camera
CameraOrtho game_cam;
b8 cam_update;
Vec3 cam_pos;
Vec3 cam_look;
Mat4 cam_view;
// Batched cq
// batching buffer
u32 cq_batch_sp;
u32 cq_batch_vao;
u32 cq_batch_vbo;
u32 cq_batch_count;
r32_array cq_pos_batch;
r32_array cq_color_batch;
// Batched line
u32 line_sp;
u32 line_vao;
u32 line_vbo;
u32 line_batch_count;
r32_array line_pos_batch;
r32_array line_color_batch;
// ui text
TextState ui_text;
};
u32 gl_shader_program(char *vs, char *fs);
u32 gl_shader_program_from_path(const char *vspath, const char *fspath);
// ==================== QUADS ====================
u32 gl_setup_quad(u32 sp);
void gl_draw_quad(GlQuad quad,
CameraOrtho *camera,
Vec3 position,
Vec2 size,
Vec3 color);
// batched renderer
void gl_setup_colored_quad_optimized(
GLRenderer* renderer,
u32 sp);
void gl_draw_colored_quad_optimized(
GLRenderer* renderer,
Vec3 position,
Vec2 size,
Vec3 color);
void gl_cq_flush(GLRenderer *renderer);
// ==================== LINE ====================
void gl_setup_line_batch(GLRenderer *renderer, u32 sp);
void gl_draw_line_batch(
GLRenderer *renderer,
Vec3 start,
Vec3 end,
Vec3 color
);
void gl_flush_line_batch(GLRenderer *renderer);
// ==================== FONT RENDERING ====================
void gl_setup_text(TextState *uistate);
void gl_render_text(GLRenderer *renderer,
char *text,
Vec3 position,
Vec3 color,
r32 font_size);
void gl_text_flush(GLRenderer *renderer, u32 render_count);
|