From 30ca5343a66a978d3b86c0796912a92cca25bf08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr>
Date: Mon, 28 Oct 2024 04:00:04 +0100
Subject: [PATCH] Remove useless clear and if for optimisation

---
 .../engine/graphics/front/engine/Engine.cpp   |  1 -
 source/engine/graphics/front/engine/Layer.cpp | 10 +++------
 .../graphics/front/group/FrameBufferGroup.cpp | 22 +++++++++----------
 .../graphics/front/group/ImageGroup.cpp       |  2 --
 4 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/source/engine/graphics/front/engine/Engine.cpp b/source/engine/graphics/front/engine/Engine.cpp
index 6c78b0c..f4f093e 100644
--- a/source/engine/graphics/front/engine/Engine.cpp
+++ b/source/engine/graphics/front/engine/Engine.cpp
@@ -27,7 +27,6 @@ namespace megu {
 
             // Merge Textures
             FrameBuffer::BindDefaultFrameBuffer();
-            this->_renderer.clear();
             this->_renderer.render(this->_window, this->_group, textures);
             this->_window.swapBuffers();
         }
diff --git a/source/engine/graphics/front/engine/Layer.cpp b/source/engine/graphics/front/engine/Layer.cpp
index 762f10a..63a0e4d 100644
--- a/source/engine/graphics/front/engine/Layer.cpp
+++ b/source/engine/graphics/front/engine/Layer.cpp
@@ -12,14 +12,10 @@ namespace megu {
     }
 
     const Texture & Layer::draw(const Window & window, const TextureArray & textures) const {
-        if(this->_frameBuffer.usable()) {
-            this->_renderer.setClearColor(0.f, 0.f, 0.f, 0.f);
-            this->_renderer.clear();
-            this->_frameBuffer.bind();
+        this->_frameBuffer.bind();
 
-            for(auto &[priority, group] : this->_objects) {
-                this->_renderer.render(window, *group, textures);
-            }
+        for(auto &[priority, group] : this->_objects) {
+            this->_renderer.render(window, *group, textures);
         }
         
         return this->_frameBuffer.texture();
diff --git a/source/engine/graphics/front/group/FrameBufferGroup.cpp b/source/engine/graphics/front/group/FrameBufferGroup.cpp
index 730ab99..cae296d 100644
--- a/source/engine/graphics/front/group/FrameBufferGroup.cpp
+++ b/source/engine/graphics/front/group/FrameBufferGroup.cpp
@@ -21,17 +21,15 @@ namespace megu {
     }
 
     void FrameBufferGroup::draw(const Window & window, const Camera & camera, const TextureArray & textures) const {
-        if(window.isOpen()) {
-            this->_program.use();
-            this->_vao.bind();
-
-            for(GLuint i = 0; i < static_cast<GLuint>(textures.size()); ++i) {
-                textures[i].get().bind(static_cast<GLuint>(i));
-            }   
-
-            this->_program.setUniform("uSampler", std::vector<GLint>{0, 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10});
-            this->_program.setUniform("uTexturesCount", static_cast<GLuint>(textures.size()));
-            glDrawArrays(Plane::Primitive(), 0, static_cast<GLsizei>(Plane::Vertices().size()));
-        }
+        this->_program.use();
+        this->_vao.bind();
+
+        for(GLuint i = 0; i < static_cast<GLuint>(textures.size()); ++i) {
+            textures[i].get().bind(static_cast<GLuint>(i));
+        }   
+
+        this->_program.setUniform("uSampler", std::vector<GLint>{0, 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10});
+        this->_program.setUniform("uTexturesCount", static_cast<GLuint>(textures.size()));
+        glDrawArrays(Plane::Primitive(), 0, static_cast<GLsizei>(Plane::Vertices().size()));
     }
 }
\ No newline at end of file
diff --git a/source/engine/graphics/front/group/ImageGroup.cpp b/source/engine/graphics/front/group/ImageGroup.cpp
index c1c8cf6..f5ce936 100644
--- a/source/engine/graphics/front/group/ImageGroup.cpp
+++ b/source/engine/graphics/front/group/ImageGroup.cpp
@@ -70,8 +70,6 @@ namespace megu {
             }
         }
 
-        //std::cout << "---------------" << std::endl;
-
         if(!textures.empty()) {
             this->_program.setUniform("uProj", camera.projection());
             this->_program.setUniform("uView", camera.view());
-- 
GitLab