Skip to content

Commit

Permalink
Revert "improve"
Browse files Browse the repository at this point in the history
This reverts commit ccd2beb.
  • Loading branch information
mehah committed Nov 25, 2023
1 parent ccd2beb commit a7866a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/framework/graphics/drawpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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&>(color)), texture, m_state.depthLevel, m_state.hash
std::move(m_state.action), std::move(const_cast<Color&>(color)), texture, m_state.hash
};
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -366,7 +368,7 @@ void DrawPool::removeFramebuffer() {
void DrawPool::addAction(const std::function<void()>& 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)
Expand Down
19 changes: 12 additions & 7 deletions src/framework/graphics/drawpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "../stdext/storage.h"

#define MAX_DRAW_DEPTH 15

enum class DrawPoolType : uint8_t
{
MAP,
Expand Down Expand Up @@ -131,10 +133,9 @@ class DrawPool
std::function<void()> 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;
};

Expand Down Expand Up @@ -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() {
Expand All @@ -231,9 +233,11 @@ class DrawPool
return false;

m_objectsDraw.clear();
for (int_fast8_t order = 0; order < static_cast<uint8_t>(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<uint8_t>(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;
Expand All @@ -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 };
Expand All @@ -267,7 +272,7 @@ class DrawPool
std::vector<Matrix3> m_transformMatrixStack;
std::vector<FrameBufferPtr> m_temporaryFramebuffers;

std::vector<DrawObject> m_objects[static_cast<uint8_t>(DrawOrder::LAST)];
std::vector<DrawObject> m_objects[MAX_DRAW_DEPTH + 1][static_cast<uint8_t>(DrawOrder::LAST)];
std::vector<DrawObject> m_objectsDraw;

stdext::map<size_t, CoordsBuffer*> m_coords;
Expand Down

0 comments on commit a7866a4

Please sign in to comment.