diff --git a/examples/dev_testing/src/main.cpp b/examples/dev_testing/src/main.cpp index ed161eb..5093a98 100644 --- a/examples/dev_testing/src/main.cpp +++ b/examples/dev_testing/src/main.cpp @@ -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; } \ No newline at end of file diff --git a/include/simpleengine/gfx/shader.h b/include/simpleengine/gfx/shader.h index c1179a3..65b6f0e 100644 --- a/include/simpleengine/gfx/shader.h +++ b/include/simpleengine/gfx/shader.h @@ -85,6 +85,12 @@ namespace simpleengine::gfx { */ void delete_shader(); + /** + * @brief Delete the shader program. + * + */ + void delete_program(); + /** * @brief Use the shader program. * diff --git a/include/simpleengine/scene.h b/include/simpleengine/scene.h index 87f8318..ec086fa 100644 --- a/include/simpleengine/scene.h +++ b/include/simpleengine/scene.h @@ -28,5 +28,7 @@ namespace simpleengine { ecs::Entity create_entity(); virtual void update(const float& delta_time) override; + + virtual void destroy() override; }; } \ No newline at end of file diff --git a/src/gfx/mesh.cpp b/src/gfx/mesh.cpp index 4c47090..1814b6d 100644 --- a/src/gfx/mesh.cpp +++ b/src/gfx/mesh.cpp @@ -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) { diff --git a/src/gfx/renderer.cpp b/src/gfx/renderer.cpp index dfcd21e..47d099d 100644 --- a/src/gfx/renderer.cpp +++ b/src/gfx/renderer.cpp @@ -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(); } */ diff --git a/src/gfx/shader.cpp b/src/gfx/shader.cpp index 6716601..b4e5b7d 100644 --- a/src/gfx/shader.cpp +++ b/src/gfx/shader.cpp @@ -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); diff --git a/src/scene.cpp b/src/scene.cpp index 8a5e735..d5e5540 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -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().each([this](ModelComponent& model_component) { + for (auto& mesh : model_component.model.meshes) { + mesh.destroy(); + } + }); + + registry.view().each([this](MeshComponent& mesh_component) { + mesh_component.mesh.destroy(); + }); + } } \ No newline at end of file