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
|
#include <renderer/Renderer.hpp>
#include <renderer/RSoftwareBackend.hpp>
#include <GL/glew.h>
#include <imgui.h>
#include <memory>
Renderer g_renderer;
void
Renderer::Init(SDL_Window* window)
{
m_window = window;
m_render_entities.reserve(1024);
m_sort_entries.reserve(1024);
m_backend = std::make_unique<RSoftwareBackend>(*this);
}
void
Renderer::Reset()
{
m_render_entities.clear();
m_sort_entries.clear();
SetCameraSize(0.0f, 0.0f);
}
void
Renderer::Draw()
{
m_backend->Draw();
}
void
Renderer::SetScreenSize(int32_t w, int32_t h)
{
m_screen_w = w;
m_screen_h = h;
}
void
Renderer::SetCameraSize(float w, float h)
{
m_camera_w = w;
m_camera_h = h;
}
int32_t
Renderer::WorldXToScreenX(float world_x)
{
float screen_x = (world_x / m_camera_w) * (float)m_screen_w;
return (int32_t)screen_x;
}
int32_t
Renderer::WorldYToScreenY(float world_y)
{
float screen_y = (world_y / m_camera_h) * (float)m_screen_h;
return (int32_t)screen_y;
}
void
Renderer::SetClearColor(Color color)
{
m_clear_color = color;
}
void
Renderer::PushAlphaBitmap(AlphaBitmap& bitmap, V2F32 pos, Color color, uint32_t z)
{
m_render_entities.emplace_back(REntity{.bitmap{
REntityType_AlphaBitmap,
bitmap,
pos,
color
}});
m_sort_entries.emplace_back(z, m_render_entities.size()-1);
}
void
Renderer::PushRectangle(Rectangle rect, Color color, uint32_t z)
{
m_render_entities.emplace_back(REntity{.rect{
REntityType_Rectangle,
rect,
color
}});
m_sort_entries.emplace_back(z, m_render_entities.size()-1);
}
void
Renderer::PushCircle(Circle circle, Color color, uint32_t z)
{
m_render_entities.emplace_back(REntity{.circle{
REntityType_Circle,
circle,
color
}});
m_sort_entries.emplace_back(z, m_render_entities.size()-1);
}
void
Renderer::PushString32(String32Id id, Font& font, V2F32 pos, Color color, uint32_t z)
{
m_render_entities.emplace_back(REntity{.string32{
REntityType_Text,
id,
font,
pos,
color
}});
m_sort_entries.emplace_back(z, m_render_entities.size()-1);
}
|