performace optimisations; remove debug print statements

This commit is contained in:
Jay Robson 2024-02-24 18:43:29 +11:00
parent 10b2d24f8b
commit 11249419c7
7 changed files with 43 additions and 27 deletions

View File

@ -62,7 +62,7 @@ static void proc_mesh(ProcState& state, glm::mat4 mat, aiMesh* mesh, const aiSce
aiString name; aiString name;
material->Get(AI_MATKEY_NAME, name); material->Get(AI_MATKEY_NAME, name);
/*
std::cout << "Material " << name.C_Str() << " has " << material->mNumProperties << " properties\n"; std::cout << "Material " << name.C_Str() << " has " << material->mNumProperties << " properties\n";
for(int i = 0; i < material->mNumProperties; i++) 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"; std::cout << "\n";
} }*/
glm::vec3 matv(0); glm::vec3 matv(0);
aiColor4D ai_cb; aiColor4D ai_cb;
@ -117,8 +117,6 @@ static void proc_mesh(ProcState& state, glm::mat4 mat, aiMesh* mesh, const aiSce
cb = em; cb = em;
} }
std::cout << "Material: " << matv << "\n";
unsigned int handle = proc_texture(state, material, scene, aiTextureType_BASE_COLOR, 0); unsigned int handle = proc_texture(state, material, scene, aiTextureType_BASE_COLOR, 0);
unsigned int offset = state.offset; unsigned int offset = state.offset;
glm::mat3 mat3(mat); glm::mat3 mat3(mat);
@ -239,6 +237,8 @@ void Mesh::load_model(std::string base, std::string filename)
const aiScene *scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs); const aiScene *scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs);
std::cout << "Loaded model: " << path << "\n";
if(scene == nullptr) if(scene == nullptr)
{ {
std::cerr << "AssImp: Error loading model\n"; std::cerr << "AssImp: Error loading model\n";

View File

@ -92,7 +92,7 @@ unsigned int Texture::load(std::string path)
throw std::runtime_error("Failed to load path: " + 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; loaded[path] = handle;
return handle; return handle;

View File

@ -18,9 +18,13 @@
using namespace Sim::Graphics; using namespace Sim::Graphics;
static GLMesh s_mesh; static GLMesh gm_ui;
static GLMesh gm_dynamic_slow[2];
static Widget::Clock w_clock; static Widget::Clock w_clock;
static int gm_dynamic_slow_at = 0;
void UI::init() void UI::init()
{ {
Mesh m; Mesh m;
@ -37,8 +41,8 @@ void UI::init()
m.set_indices(indices, 6); m.set_indices(indices, 6);
m.set_vertices(vertices, 4); m.set_vertices(vertices, 4);
s_mesh.bind(); gm_ui.bind();
s_mesh.set(m, GL_STATIC_DRAW); gm_ui.set(m, GL_STATIC_DRAW);
} }
void UI::update(double dt) void UI::update(double dt)
@ -46,6 +50,17 @@ void UI::update(double dt)
w_clock.update(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() void UI::render()
{ {
glClear(GL_DEPTH_BUFFER_BIT); 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["projection"], 1, false, &mat_projection[0][0]);
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]); glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
s_mesh.bind(); gm_ui.bind();
s_mesh.uniform(); gm_ui.uniform();
s_mesh.render(); 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(); w_clock.render();
} }

View File

@ -6,6 +6,7 @@ namespace Sim::Graphics::UI
void init(); void init();
void update(double dt); void update(double dt);
void update_slow();
void render(); void render();
}; };

View File

@ -19,6 +19,11 @@
using namespace Sim::Graphics::Widget; using namespace Sim::Graphics::Widget;
void Clock::update(double dt) void Clock::update(double dt)
{
this->dt = dt;
}
void Clock::remesh_slow(Mesh& rmesh)
{ {
Mesh m; Mesh m;
double at = System::active->clock; double at = System::active->clock;
@ -29,22 +34,17 @@ void Clock::update(double dt)
int t_m = std::fmod(at / 60, 60); int t_m = std::fmod(at / 60, 60);
int t_h = std::fmod(at / 3600, 24); 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 << "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_m << ":";
ss << std::setfill('0') << std::setw(2) << t_s << "\n"; ss << std::setfill('0') << std::setw(2) << t_s << "\n";
ss << "Day: " << std::floor(at / (3600 * 24)) << "\n"; ss << "Day: " << std::floor(at / (3600 * 24)) << "\n";
m.load_text(ss.str().c_str(), 20); m.load_text(ss.str().c_str(), 20);
rmesh.add(m, glm::translate(glm::mat4(1), glm::vec3(-wsize + glm::vec2(2, 2), 0)));
data.bind();
data.model_matrix = glm::translate(glm::mat4(1), glm::vec3(-wsize + glm::vec2(2, 2), 0));
data.set(m, GL_DYNAMIC_DRAW);
} }
void Clock::render() void Clock::render()
{ {
data.bind();
data.uniform();
data.render();
} }

View File

@ -8,9 +8,10 @@ namespace Sim::Graphics::Widget
struct Clock struct Clock
{ {
GLMesh data; double dt;
void update(double dt); void update(double dt);
void remesh_slow(Mesh& rmesh);
void render(); void render();
}; };

View File

@ -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 // send all the light data
glGenBuffers(1, &ssbo_lights); glGenBuffers(1, &ssbo_lights);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 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].bind();
gm_dynamic_slow[gm_dynamic_slow_at].set(mesh, GL_DYNAMIC_DRAW); gm_dynamic_slow[gm_dynamic_slow_at].set(mesh, GL_DYNAMIC_DRAW);
gm_dynamic_slow_at = (gm_dynamic_slow_at + 1) % 2; gm_dynamic_slow_at = (gm_dynamic_slow_at + 1) % 2;
UI::update_slow();
} }
void Window::update(double dt) void Window::update(double dt)
@ -210,7 +205,7 @@ void Window::update(double dt)
{ {
gm_dynamic_fast.bind(); gm_dynamic_fast.bind();
gm_dynamic_fast.set(mesh, GL_DYNAMIC_DRAW); gm_dynamic_fast.set(mesh, GL_DYNAMIC_DRAW);
m_dynamic_fast = mesh; m_dynamic_fast = std::move(mesh);
} }
secs_wait_now += dt; secs_wait_now += dt;