Some memory management
This commit is contained in:
parent
4c3a2729c7
commit
fdebcf9499
|
@ -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;
|
||||
}
|
|
@ -85,6 +85,12 @@ namespace simpleengine::gfx {
|
|||
*/
|
||||
void delete_shader();
|
||||
|
||||
/**
|
||||
* @brief Delete the shader program.
|
||||
*
|
||||
*/
|
||||
void delete_program();
|
||||
|
||||
/**
|
||||
* @brief Use the shader program.
|
||||
*
|
||||
|
|
|
@ -28,5 +28,7 @@ namespace simpleengine {
|
|||
ecs::Entity create_entity();
|
||||
|
||||
virtual void update(const float& delta_time) override;
|
||||
|
||||
virtual void destroy() override;
|
||||
};
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
} */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue