diff --git a/src/graphics/cpu_particle_manager.cpp b/src/graphics/cpu_particle_manager.cpp index 8f9847959..e148d475a 100644 --- a/src/graphics/cpu_particle_manager.cpp +++ b/src/graphics/cpu_particle_manager.cpp @@ -99,6 +99,10 @@ void CPUParticleManager::addParticleNode(STKParticle* node) { return; } + if (node->getFlips()) + { + m_flips_material.insert(tex_name); + } m_particles_queue[tex_name].push_back(node); } // addParticleNode @@ -111,19 +115,15 @@ void CPUParticleManager::generateAll() { continue; } - bool flips = false; for (auto& q : p.second) { - if (q->getFlips() && !flips) - { - flips = q->getFlips(); - } q->generate(&m_particles_generated[p.first]); } - if (flips) + if (isFlipsMaterial(p.first)) { - STKParticle::updateFlips(m_particles_queue[p.first].size() * - m_particles_queue[p.first][0]->getMaxCount()); + STKParticle::updateFlips(unsigned + (m_particles_queue.at(p.first).size() * + m_particles_queue.at(p.first)[0]->getMaxCount())); } } } // generateAll @@ -172,16 +172,7 @@ void CPUParticleManager::uploadAll() glVertexAttribPointer(2, 2, GL_HALF_FLOAT, GL_FALSE, 20, (void*)16); glVertexAttribDivisorARB(2, 1); - bool flips = false; - for (unsigned i = 0; i < m_particles_queue[p.first].size(); i++) - { - if (m_particles_queue[p.first][i]->getFlips()) - { - flips = true; - break; - } - } - if (flips) + if (isFlipsMaterial(p.first)) { glBindBuffer(GL_ARRAY_BUFFER, STKParticle::getFlipsBuffer()); glEnableVertexAttribArray(6); @@ -221,22 +212,14 @@ void CPUParticleManager::drawAll() std::sort(particle_drawn.begin(), particle_drawn.end(), [](const std::pair& a, const std::pair& b)->bool - { + { return a.first->getShaderType() > b.first->getShaderType(); }); Material::ShaderType st = Material::SHADERTYPE_COUNT; for (auto& p : particle_drawn) { - bool flips = false; - for (unsigned i = 0; i < m_particles_queue[p.second].size(); i++) - { - if (m_particles_queue[p.second][i]->getFlips()) - { - flips = true; - break; - } - } + const bool flips = isFlipsMaterial(p.second); Material* cur_mat = p.first; if (cur_mat->getShaderType() != st) { diff --git a/src/graphics/cpu_particle_manager.hpp b/src/graphics/cpu_particle_manager.hpp index 2531c4874..d027afaba 100644 --- a/src/graphics/cpu_particle_manager.hpp +++ b/src/graphics/cpu_particle_manager.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include using namespace irr; @@ -75,6 +76,12 @@ private: std::unordered_map m_material_map; + std::unordered_set m_flips_material; + + // ------------------------------------------------------------------------ + bool isFlipsMaterial(const std::string& name) + { return m_flips_material.find(name) != m_flips_material.end(); } + public: // ------------------------------------------------------------------------ CPUParticleManager() {} @@ -104,6 +111,7 @@ public: void cleanMaterialMap() { m_material_map.clear(); + m_flips_material.clear(); } };