From a7866a48b29b58d5389a001064cdb246fca50947 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 24 Nov 2023 21:57:59 -0300 Subject: [PATCH] Revert "improve" This reverts commit ccd2bebfeece0b3a78c7ed5fa238f1ac1a87223b. --- src/framework/graphics/drawpool.cpp | 12 +++++++----- src/framework/graphics/drawpool.h | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/framework/graphics/drawpool.cpp b/src/framework/graphics/drawpool.cpp index f936584237..76ce17ec85 100644 --- a/src/framework/graphics/drawpool.cpp +++ b/src/framework/graphics/drawpool.cpp @@ -65,7 +65,7 @@ void DrawPool::add(const Color& color, const TexturePtr& texture, DrawPool::Draw auto& coords = m_coords.try_emplace(m_state.hash, nullptr).first->second; if (!coords) { auto state = getState(texture, color); - coords = m_objects[order].emplace_back(std::move(state)).coords.get(); + coords = m_objects[m_depthLevel][order].emplace_back(std::move(state)).coords.get(); } if (coordsBuffer) @@ -75,7 +75,7 @@ void DrawPool::add(const Color& color, const TexturePtr& texture, DrawPool::Draw } else { bool addNewObj = true; - auto& list = m_objects[order]; + auto& list = m_objects[m_depthLevel][order]; if (!list.empty()) { auto& prevObj = list.back(); if (prevObj.state == m_state) { @@ -195,7 +195,7 @@ DrawPool::PoolState DrawPool::getState(const TexturePtr& texture, const Color& c std::move(m_state.transformMatrix), m_state.opacity, m_state.compositionMode, m_state.blendEquation, std::move(m_state.clipRect), m_state.shaderProgram, - std::move(m_state.action), std::move(const_cast(color)), texture, m_state.depthLevel, m_state.hash + std::move(m_state.action), std::move(const_cast(color)), texture, m_state.hash }; } @@ -245,11 +245,13 @@ void DrawPool::setShaderProgram(const PainterShaderProgramPtr& shaderProgram, bo void DrawPool::resetState() { for (auto& objs : m_objects) { - objs.clear(); + for (auto& order : objs) + order.clear(); } m_coords.clear(); m_state = {}; + m_depthLevel = 0; m_status.second = 0; m_lastFramebufferId = 0; m_shaderRefreshDelay = 0; @@ -366,7 +368,7 @@ void DrawPool::removeFramebuffer() { void DrawPool::addAction(const std::function& action) { const uint8_t order = m_type == DrawPoolType::MAP ? DrawOrder::THIRD : DrawOrder::FIRST; - m_objects[order].emplace_back(action); + m_objects[m_depthLevel][order].emplace_back(action); } void DrawPool::bindFrameBuffer(const Size& size) diff --git a/src/framework/graphics/drawpool.h b/src/framework/graphics/drawpool.h index 5aa6d532dd..8efa785e79 100644 --- a/src/framework/graphics/drawpool.h +++ b/src/framework/graphics/drawpool.h @@ -33,6 +33,8 @@ #include "../stdext/storage.h" +#define MAX_DRAW_DEPTH 15 + enum class DrawPoolType : uint8_t { MAP, @@ -131,10 +133,9 @@ class DrawPool std::function action{ nullptr }; Color color{ Color::white }; TexturePtr texture; - size_t depthLevel{ 0 }; size_t hash{ 0 }; - bool operator==(const PoolState& s2) const { return depthLevel == s2.depthLevel && hash == s2.hash; } + bool operator==(const PoolState& s2) const { return hash == s2.hash; } void execute() const; }; @@ -221,7 +222,8 @@ class DrawPool void flush() { m_coords.clear(); - ++m_state.depthLevel; + if (m_depthLevel < MAX_DRAW_DEPTH) + ++m_depthLevel; } inline bool swapObjects() { @@ -231,9 +233,11 @@ class DrawPool return false; m_objectsDraw.clear(); - for (int_fast8_t order = 0; order < static_cast(DrawOrder::LAST); ++order) { - auto& objs = m_objects[order]; - m_objectsDraw.insert(m_objectsDraw.end(), make_move_iterator(objs.begin()), make_move_iterator(objs.end())); + for (int_fast8_t depth = 0; depth <= MAX_DRAW_DEPTH; ++depth) { + for (int_fast8_t order = 0; order < static_cast(DrawOrder::LAST); ++order) { + auto& objs = m_objects[depth][order]; + m_objectsDraw.insert(m_objectsDraw.end(), make_move_iterator(objs.begin()), make_move_iterator(objs.end())); + } } return true; @@ -251,6 +255,7 @@ class DrawPool bool m_alwaysGroupDrawings{ false }; int_fast8_t m_bindedFramebuffers{ -1 }; + uint8_t m_depthLevel{ 0 }; uint16_t m_refreshDelay{ 0 }, m_shaderRefreshDelay{ 0 }; uint32_t m_onlyOnceStateFlag{ 0 }; @@ -267,7 +272,7 @@ class DrawPool std::vector m_transformMatrixStack; std::vector m_temporaryFramebuffers; - std::vector m_objects[static_cast(DrawOrder::LAST)]; + std::vector m_objects[MAX_DRAW_DEPTH + 1][static_cast(DrawOrder::LAST)]; std::vector m_objectsDraw; stdext::map m_coords;