Some memory management

This commit is contained in:
SeanOMik 2022-10-12 23:18:47 -04:00
parent 4c3a2729c7
commit fdebcf9499
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
7 changed files with 31 additions and 0 deletions

View File

@ -105,8 +105,10 @@ int main(int argc, char *argv[]) {
game.set_enable_vsync(true);
// game.set_fps_limit(120);
int res = game.run();
std::cout << "Engine result: " << res << std::endl;
renderer->destroy();
scene->destroy();
return res;
}

View File

@ -85,6 +85,12 @@ namespace simpleengine::gfx {
*/
void delete_shader();
/**
* @brief Delete the shader program.
*
*/
void delete_program();
/**
* @brief Use the shader program.
*

View File

@ -28,5 +28,7 @@ namespace simpleengine {
ecs::Entity create_entity();
virtual void update(const float& delta_time) override;
virtual void destroy() override;
};
}

View File

@ -44,6 +44,7 @@ namespace simpleengine::gfx {
this->ebo.destroy();
this->vbo.destroy();
this->vao.destroy();
this->tangent_vbo.destroy();
}
void Mesh::update(const float& delta_time) {

View File

@ -128,6 +128,8 @@ namespace simpleengine::gfx {
void Renderer::destroy() {
std::cout << "Destroying renderer..." << std::endl;
shader.delete_program();
/* for (auto& [handle, rendering] : rendering_models) {
rendering.destroy_buffers();
} */

View File

@ -100,6 +100,11 @@ namespace simpleengine::gfx {
glDeleteShader(shader);
}
void Shader::delete_program() {
unuse();
glDeleteProgram(program);
}
void Shader::use() const {
if (Shader::inuse_program != program) {
glUseProgram(program);

View File

@ -41,4 +41,17 @@ namespace simpleengine {
transform.rotate(rotating.rate * delta_time, rotating.rotation_axis);
});
}
void Scene::destroy() {
std::cout << "Destroying Scene..." << std::endl;
registry.view<ModelComponent>().each([this](ModelComponent& model_component) {
for (auto& mesh : model_component.model.meshes) {
mesh.destroy();
}
});
registry.view<MeshComponent>().each([this](MeshComponent& mesh_component) {
mesh_component.mesh.destroy();
});
}
}