From 11249419c72b6ee2a3f7880f0751b37b38f597fc Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sat, 24 Feb 2024 18:43:29 +1100 Subject: [PATCH] performace optimisations; remove debug print statements --- src/graphics/mesh/model.cpp | 8 ++++---- src/graphics/mesh/texture.cpp | 2 +- src/graphics/ui.cpp | 31 +++++++++++++++++++++++++------ src/graphics/ui.hpp | 1 + src/graphics/widget/clock.cpp | 14 +++++++------- src/graphics/widget/clock.hpp | 3 ++- src/graphics/window.cpp | 11 +++-------- 7 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/graphics/mesh/model.cpp b/src/graphics/mesh/model.cpp index 756b1a7..66ee752 100644 --- a/src/graphics/mesh/model.cpp +++ b/src/graphics/mesh/model.cpp @@ -62,7 +62,7 @@ static void proc_mesh(ProcState& state, glm::mat4 mat, aiMesh* mesh, const aiSce aiString name; material->Get(AI_MATKEY_NAME, name); - +/* std::cout << "Material " << name.C_Str() << " has " << material->mNumProperties << " properties\n"; for(int i = 0; i < material->mNumProperties; i++) @@ -97,7 +97,7 @@ static void proc_mesh(ProcState& state, glm::mat4 mat, aiMesh* mesh, const aiSce } std::cout << "\n"; - } + }*/ glm::vec3 matv(0); aiColor4D ai_cb; @@ -117,8 +117,6 @@ static void proc_mesh(ProcState& state, glm::mat4 mat, aiMesh* mesh, const aiSce cb = em; } - std::cout << "Material: " << matv << "\n"; - unsigned int handle = proc_texture(state, material, scene, aiTextureType_BASE_COLOR, 0); unsigned int offset = state.offset; glm::mat3 mat3(mat); @@ -238,6 +236,8 @@ void Mesh::load_model(std::string base, std::string filename) Assimp::Importer importer; const aiScene *scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs); + + std::cout << "Loaded model: " << path << "\n"; if(scene == nullptr) { diff --git a/src/graphics/mesh/texture.cpp b/src/graphics/mesh/texture.cpp index 7ea9392..7871b68 100644 --- a/src/graphics/mesh/texture.cpp +++ b/src/graphics/mesh/texture.cpp @@ -92,7 +92,7 @@ unsigned int Texture::load(std::string path) throw std::runtime_error("Failed to load path: " + path); } - std::cout << "Loaded Image: " << path << "\n"; + std::cout << "Loaded image: " << path << "\n"; loaded[path] = handle; return handle; diff --git a/src/graphics/ui.cpp b/src/graphics/ui.cpp index 22885e1..57fce98 100644 --- a/src/graphics/ui.cpp +++ b/src/graphics/ui.cpp @@ -18,9 +18,13 @@ using namespace Sim::Graphics; -static GLMesh s_mesh; +static GLMesh gm_ui; +static GLMesh gm_dynamic_slow[2]; + static Widget::Clock w_clock; +static int gm_dynamic_slow_at = 0; + void UI::init() { Mesh m; @@ -37,8 +41,8 @@ void UI::init() m.set_indices(indices, 6); m.set_vertices(vertices, 4); - s_mesh.bind(); - s_mesh.set(m, GL_STATIC_DRAW); + gm_ui.bind(); + gm_ui.set(m, GL_STATIC_DRAW); } void UI::update(double dt) @@ -46,6 +50,17 @@ void UI::update(double dt) w_clock.update(dt); } +void UI::update_slow() +{ + Mesh mesh; + + w_clock.remesh_slow(mesh); + + gm_dynamic_slow[gm_dynamic_slow_at].bind(); + gm_dynamic_slow[gm_dynamic_slow_at].set(mesh, GL_DYNAMIC_DRAW); + gm_dynamic_slow_at = (gm_dynamic_slow_at + 1) % 2; +} + void UI::render() { glClear(GL_DEPTH_BUFFER_BIT); @@ -57,9 +72,13 @@ void UI::render() glUniformMatrix4fv(Shader::MAIN["projection"], 1, false, &mat_projection[0][0]); glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]); - s_mesh.bind(); - s_mesh.uniform(); - s_mesh.render(); + gm_ui.bind(); + gm_ui.uniform(); + gm_ui.render(); + + gm_dynamic_slow[gm_dynamic_slow_at].bind(); + gm_dynamic_slow[gm_dynamic_slow_at].uniform(); + gm_dynamic_slow[gm_dynamic_slow_at].render(); w_clock.render(); } diff --git a/src/graphics/ui.hpp b/src/graphics/ui.hpp index f3fa585..07f701a 100644 --- a/src/graphics/ui.hpp +++ b/src/graphics/ui.hpp @@ -6,6 +6,7 @@ namespace Sim::Graphics::UI void init(); void update(double dt); +void update_slow(); void render(); }; diff --git a/src/graphics/widget/clock.cpp b/src/graphics/widget/clock.cpp index 91ed13e..3a512fc 100644 --- a/src/graphics/widget/clock.cpp +++ b/src/graphics/widget/clock.cpp @@ -19,6 +19,11 @@ using namespace Sim::Graphics::Widget; void Clock::update(double dt) +{ + this->dt = dt; +} + +void Clock::remesh_slow(Mesh& rmesh) { Mesh m; double at = System::active->clock; @@ -29,22 +34,17 @@ void Clock::update(double dt) int t_m = std::fmod(at / 60, 60); int t_h = std::fmod(at / 3600, 24); +// ss << "FPS: " << (1.0 / dt) << "\n"; ss << "Time: " << std::setfill('0') << std::setw(2) << t_h << ":"; ss << std::setfill('0') << std::setw(2) << t_m << ":"; ss << std::setfill('0') << std::setw(2) << t_s << "\n"; ss << "Day: " << std::floor(at / (3600 * 24)) << "\n"; m.load_text(ss.str().c_str(), 20); - - data.bind(); - data.model_matrix = glm::translate(glm::mat4(1), glm::vec3(-wsize + glm::vec2(2, 2), 0)); - data.set(m, GL_DYNAMIC_DRAW); + rmesh.add(m, glm::translate(glm::mat4(1), glm::vec3(-wsize + glm::vec2(2, 2), 0))); } void Clock::render() { - data.bind(); - data.uniform(); - data.render(); } diff --git a/src/graphics/widget/clock.hpp b/src/graphics/widget/clock.hpp index f96be43..8e4f57a 100644 --- a/src/graphics/widget/clock.hpp +++ b/src/graphics/widget/clock.hpp @@ -8,9 +8,10 @@ namespace Sim::Graphics::Widget struct Clock { - GLMesh data; + double dt; void update(double dt); + void remesh_slow(Mesh& rmesh); void render(); }; diff --git a/src/graphics/window.cpp b/src/graphics/window.cpp index 513f718..b6b5912 100644 --- a/src/graphics/window.cpp +++ b/src/graphics/window.cpp @@ -142,13 +142,6 @@ void Window::create() } } - for(Light& light : m.lights) - { - std::cout << "Sent light: " << light.pos << " with " << light.colour << "\n"; - } - - std::cout << "Light struct is " << sizeof(m.lights[0]) << " bytes\n"; - // send all the light data glGenBuffers(1, &ssbo_lights); glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_lights); @@ -184,6 +177,8 @@ void update_slow() gm_dynamic_slow[gm_dynamic_slow_at].bind(); gm_dynamic_slow[gm_dynamic_slow_at].set(mesh, GL_DYNAMIC_DRAW); gm_dynamic_slow_at = (gm_dynamic_slow_at + 1) % 2; + + UI::update_slow(); } void Window::update(double dt) @@ -210,7 +205,7 @@ void Window::update(double dt) { gm_dynamic_fast.bind(); gm_dynamic_fast.set(mesh, GL_DYNAMIC_DRAW); - m_dynamic_fast = mesh; + m_dynamic_fast = std::move(mesh); } secs_wait_now += dt;