From d2bba1beb38592249e06aa6ebdc439f7bf56e5a9 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:13:38 +0100 Subject: [PATCH] Avoid binding of fbo for empty layers --- .../engine/graphics/front/engine/Engine.cpp | 4 +- source/engine/graphics/front/engine/Layer.hpp | 2 + source/main.cpp | 51 ++++++++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/source/engine/graphics/front/engine/Engine.cpp b/source/engine/graphics/front/engine/Engine.cpp index f4f093e..7908f9c 100644 --- a/source/engine/graphics/front/engine/Engine.cpp +++ b/source/engine/graphics/front/engine/Engine.cpp @@ -22,7 +22,9 @@ namespace megu { // Draw Layers TextureArray textures; for(auto & [priority, layer] : this->_layers) { - textures.push_back(layer->draw(this->_window, textures)); + if(!layer.get()->empty()) { + textures.push_back(layer->draw(this->_window, textures)); + } } // Merge Textures diff --git a/source/engine/graphics/front/engine/Layer.hpp b/source/engine/graphics/front/engine/Layer.hpp index 8c9eb22..5ba2a66 100644 --- a/source/engine/graphics/front/engine/Layer.hpp +++ b/source/engine/graphics/front/engine/Layer.hpp @@ -16,6 +16,8 @@ namespace megu { void push(Priority, const DrawGroup &); + inline bool empty() const {return this->_objects.empty();} + virtual const Texture & draw(const Window &, const TextureArray &) const; private: diff --git a/source/main.cpp b/source/main.cpp index 584217f..727695f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -42,6 +42,7 @@ int main(int argc, const char * argv[]) { //? Group megu::ImageGroup group; megu::ImageGroup group_2; + megu::ImageGroup group_3; std::cout << "Group Inited" << std::endl; @@ -94,7 +95,7 @@ int main(int argc, const char * argv[]) { std::cout << "Image Inited 1" << std::endl; - //? Image 1 + //? Image 2 std::vector<int> map_2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -138,6 +139,52 @@ int main(int argc, const char * argv[]) { i.get()->setSize({32.f, 32.f}); } + std::cout << "Image Inited 3" << std::endl; + + //? Image 2 + std::vector<int> map_3 = { + 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, + }; + + size_t x_3 = 0; + size_t y_3 = 0; + + std::vector<std::unique_ptr<megu::Image>> images_3; + + megu::Texture texture_4; + texture_4.store(megu::TextureBuffer("assets/textures/Cube_Green.png")); + + for(auto id : map_3) { + if(x_3 == 10) { + x_3 = 0; + ++y_3; + } + + + if(id != 0) { + images_3.push_back(std::make_unique<megu::Image>(texture_4)); + glm::vec2 pos = to_screen_coordinate({x_3, y_3}, 32.f, 32.f, 2.f); + + images_3.back()->setPosition({pos.x + 25, pos.y}); + } + + ++x_3; + } + + for(auto & i : images_3) { + group_3.add(*i); + i.get()->setSize({32.f, 32.f}); + } + std::cout << "Image Inited 2" << std::endl; //? ImGui @@ -151,7 +198,9 @@ int main(int argc, const char * argv[]) { engine.push(0, basic_renderer); engine.push(1, basic_renderer); + engine.push(2, basic_renderer); + engine.push(1, 1, group_3); engine.push(1, 0, group); engine.push(0, 0, group_2); -- GitLab