Skip to content

Commit f982322

Browse files
committed
gui: added GUI debug statistics, fps graph and gl memory information
1 parent a5239a5 commit f982322

File tree

14 files changed

+232
-37
lines changed

14 files changed

+232
-37
lines changed

examples/demo/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int main()
135135
World::run_system<ParticleEmitterSystem>();
136136

137137
Window::framebuffer->bind();
138-
Gui::debug_performance();
138+
Gui::debug_stats();
139139
Gui::render();
140140
Window::framebuffer->unbind();
141141

examples/performance_monitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ int main()
9090
void setup_gui(FrameBuffer &fb)
9191
{
9292
Gui::new_frame(fb, "Game");
93-
Gui::debug_performance();
93+
Gui::debug_stats();
9494
}

include/brenta/asset.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
namespace brenta
2020
{
2121

22+
class Gui;
23+
2224
//
2325
// The central Asset Manager
2426
// -------------------------
@@ -54,6 +56,8 @@ class AssetManager
5456
struct AssetOwned;
5557
struct HotReloadItem;
5658

59+
friend class Gui;
60+
5761
enum class AssetType
5862
{
5963
Model,
@@ -96,12 +100,12 @@ class AssetManager
96100

97101
private:
98102

99-
static std::unordered_map<AssetId, Asset<Model>> models;
100-
static std::unordered_map<AssetId, Asset<Texture>> textures;
101-
static std::unordered_map<AssetId, Asset<Material>> materials;
102-
static std::unordered_map<AssetId, Asset<Shader>> shaders;
103-
static std::unordered_map<AssetId, Asset<Font>> fonts;
104-
static std::unordered_map<AssetId, AssetOwned<Scene>> scenes;
103+
static std::unordered_map<AssetId, Asset<Model>> models;
104+
static std::unordered_map<AssetId, Asset<Texture>> textures;
105+
static std::unordered_map<AssetId, Asset<Material>> materials;
106+
static std::unordered_map<AssetId, Asset<Shader>> shaders;
107+
static std::unordered_map<AssetId, Asset<Font>> fonts;
108+
static std::unordered_map<AssetId, AssetOwned<Scene>> scenes;
105109
static std::unordered_map<AssetId, AssetOwned<SoundAsset>> sound_assets;
106110

107111

include/brenta/gui.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Gui : public Subsystem
5353
float size = 25.0f);
5454
static void push_font(ImFont* f = font);
5555
static void pop_font();
56-
static void debug_performance();
56+
static void debug_stats();
5757

5858
private:
5959

include/brenta/renderer/opengl/buffer.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class Buffer
5050
DynamicRead = GL_DYNAMIC_READ,
5151
DynamicCopy = GL_DYNAMIC_COPY,
5252
};
53+
54+
// Used for profiling
55+
int memory = 0;
56+
static int tot_memory;
5357

5458
Buffer() = default;
5559
Buffer(Target target);
@@ -61,13 +65,19 @@ class Buffer
6165
{
6266
this->id = other.id;
6367
this->target = other.target;
68+
this->memory = other.memory;
69+
6470
other.id = 0;
71+
other.memory = 0;
6572
}
6673
constexpr Buffer& operator=(Buffer&& other) noexcept
6774
{
6875
this->id = other.id;
6976
this->target = other.target;
77+
this->memory = other.memory;
78+
7079
other.id = 0;
80+
other.memory = 0;
7181
return *this;
7282
}
7383

include/brenta/renderer/opengl/cubemap.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class Cubemap : public Texture
4343
0, GL_RGB, width, height, 0, GL_RGB,
4444
GL_UNSIGNED_BYTE, data);
4545
stbi_image_free(data);
46+
47+
this->memory += 3 * width * height;
48+
Texture::memory += this->memory;
49+
4650
}
4751
}
4852

include/brenta/renderer/opengl/framebuffer.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ class FrameBuffer : public Buffer
3333
GLuint texture_id;
3434
GLuint render_buffer_id;
3535
GLenum color_format;
36+
GLenum channel_type = GL_UNSIGNED_BYTE;
3637
int width;
3738
int height;
3839

40+
// Used for profiling
41+
int memory = 0;
42+
static int tot_memory;
43+
3944
FrameBuffer() = default;
4045
FrameBuffer(int width, int height, GLenum format = GL_RGBA);
4146

@@ -48,8 +53,10 @@ class FrameBuffer : public Buffer
4853
this->height = other.height;
4954
this->target = other.target;
5055
this->id = other.id;
56+
this->memory = other.memory;
5157

52-
other.id = 0;
58+
other.id = 0;
59+
other.memory = 0;
5360
}
5461
FrameBuffer &operator=(FrameBuffer&& other)
5562
{
@@ -60,7 +67,10 @@ class FrameBuffer : public Buffer
6067
this->height = other.height;
6168
this->target = other.target;
6269
this->id = other.id;
63-
other.id = 0;
70+
this->memory = other.memory;
71+
72+
other.id = 0;
73+
other.memory = 0;
6474

6575
return *this;
6676
}
@@ -74,7 +84,7 @@ class FrameBuffer : public Buffer
7484

7585
void rescale(int width, int height);
7686
void set_color_format(GLenum color_format);
77-
87+
7888
};
7989

8090
} // namespace brenta

include/brenta/renderer/opengl/gl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class Gl : public Subsystem
5858
// Member functions
5959

6060
static Gl &instance();
61-
61+
62+
static int get_num_channels(GLenum color_format);
63+
static int get_bytes_per_channel(GLenum type);
6264
static void set_poligon_mode(GLboolean enable);
6365
static void set_viewport(int x, int y, int width, int height);
6466
static void set_color(const Color &color);

include/brenta/renderer/opengl/texture.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,21 @@ class Texture
132132

133133
// This tells the shader where to find the texture
134134
static void active_texture(int texture);
135-
static Texture::Id load(const std::filesystem::path &path, bool flip = true);
135+
// Loads texture from path, sets [loaded_memory] with the number
136+
// of bytes loaded and returns the id of the loaded texture
137+
static Texture::Id load(const std::filesystem::path &path,
138+
int &loaded_memory, bool flip = true);
136139
static Texture::Id load_solid_color(Color color);
137140
static void bind_id(Texture::Target target, Texture::Id id);
138141
static void bind_id(Texture::Target target, Texture::Id id,
139142
const Texture::Properties &properties);
140143

141144
// Non static
142145

146+
// Used for profiling
147+
int memory = 0;
148+
static int tot_memory;
149+
143150
Texture() {}
144151
Texture(const Config &conf);
145152

@@ -153,7 +160,10 @@ class Texture
153160
this->type = other.type;
154161
this->target = other.target;
155162
this->properties = other.properties;
156-
other.id = 0;
163+
this->memory = other.memory;
164+
165+
other.id = 0;
166+
other.memory = 0;
157167
}
158168

159169
Texture& operator=(Texture&& other) noexcept
@@ -163,7 +173,10 @@ class Texture
163173
this->path = other.path;
164174
this->target = other.target;
165175
this->properties = other.properties;
166-
other.id = 0;
176+
this->memory = other.memory;
177+
178+
other.id = 0;
179+
other.memory = 0;
167180
return *this;
168181
}
169182

@@ -184,8 +197,9 @@ class Texture
184197
Texture::Target target;
185198
std::filesystem::path path;
186199
Texture::Properties properties;
187-
188-
static void read_image(const std::filesystem::path &path, bool flip);
200+
201+
// Returns the number of bytes loaded
202+
static int read_image(const std::filesystem::path &path, bool flip);
189203

190204
};
191205

src/gui.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// Github: @San7o
55

66
#include <brenta/renderer/opengl/gl.hpp>
7+
#include <brenta/renderer/opengl/texture.hpp>
78
#include <brenta/gui.hpp>
89
#include <brenta/window.hpp>
910
#include <brenta/logger.hpp>
11+
#include <brenta/asset.hpp>
1012

1113
#include <cmath>
1214

@@ -285,10 +287,14 @@ void Gui::render()
285287

286288
static float gui_debug_last_time = 0;
287289

288-
void Gui::debug_performance()
290+
void Gui::debug_stats()
289291
{
290-
ImGui::Begin("Performance");
292+
ImGui::Begin("Stats");
291293

294+
//
295+
// FPS information
296+
//
297+
292298
static TimePlotBuffer fps_data;
293299

294300
auto time = Window::get_time();
@@ -325,6 +331,35 @@ void Gui::debug_performance()
325331
ImPlot::EndPlot();
326332
}
327333

334+
ImGui::Separator();
335+
336+
//
337+
// Memory information
338+
//
339+
340+
ImGui::Text("Tot GlBuffer Memory: %f MB",
341+
Buffer::tot_memory / 1024.0 / 1024.0);
342+
ImGui::Text("Tot GlFrameByffer Memory: %f MB",
343+
FrameBuffer::tot_memory / 1024.0 / 1024.0);
344+
ImGui::Text("Tot GlTexture Memory: %f MB",
345+
Texture::tot_memory / 1024.0 / 1024.0);
346+
347+
ImGui::Separator();
348+
349+
//
350+
// Asset manager information
351+
//
352+
353+
ImGui::Text("Number of assets loaded with AssetManager");
354+
355+
ImGui::BulletText("Models: %ld", AssetManager::models.size());
356+
ImGui::BulletText("Textures: %ld", AssetManager::textures.size());
357+
ImGui::BulletText("Materials: %ld", AssetManager::materials.size());
358+
ImGui::BulletText("Shaders: %ld", AssetManager::shaders.size());
359+
ImGui::BulletText("Fonts: %ld", AssetManager::fonts.size());
360+
ImGui::BulletText("Scenes: %ld", AssetManager::scenes.size());
361+
ImGui::BulletText("Sound Assets: %ld", AssetManager::sound_assets.size());
362+
328363
ImGui::End();
329364
}
330365

0 commit comments

Comments
 (0)