Check flips using unordered_set

This commit is contained in:
Benau 2017-10-15 15:05:49 +08:00
parent 058f9163db
commit a7debc286a
2 changed files with 19 additions and 28 deletions

View File

@ -99,6 +99,10 @@ void CPUParticleManager::addParticleNode(STKParticle* node)
{ {
return; return;
} }
if (node->getFlips())
{
m_flips_material.insert(tex_name);
}
m_particles_queue[tex_name].push_back(node); m_particles_queue[tex_name].push_back(node);
} // addParticleNode } // addParticleNode
@ -111,19 +115,15 @@ void CPUParticleManager::generateAll()
{ {
continue; continue;
} }
bool flips = false;
for (auto& q : p.second) for (auto& q : p.second)
{ {
if (q->getFlips() && !flips)
{
flips = q->getFlips();
}
q->generate(&m_particles_generated[p.first]); q->generate(&m_particles_generated[p.first]);
} }
if (flips) if (isFlipsMaterial(p.first))
{ {
STKParticle::updateFlips(m_particles_queue[p.first].size() * STKParticle::updateFlips(unsigned
m_particles_queue[p.first][0]->getMaxCount()); (m_particles_queue.at(p.first).size() *
m_particles_queue.at(p.first)[0]->getMaxCount()));
} }
} }
} // generateAll } // generateAll
@ -172,16 +172,7 @@ void CPUParticleManager::uploadAll()
glVertexAttribPointer(2, 2, GL_HALF_FLOAT, GL_FALSE, 20, glVertexAttribPointer(2, 2, GL_HALF_FLOAT, GL_FALSE, 20,
(void*)16); (void*)16);
glVertexAttribDivisorARB(2, 1); glVertexAttribDivisorARB(2, 1);
bool flips = false; if (isFlipsMaterial(p.first))
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)
{ {
glBindBuffer(GL_ARRAY_BUFFER, STKParticle::getFlipsBuffer()); glBindBuffer(GL_ARRAY_BUFFER, STKParticle::getFlipsBuffer());
glEnableVertexAttribArray(6); glEnableVertexAttribArray(6);
@ -228,15 +219,7 @@ void CPUParticleManager::drawAll()
Material::ShaderType st = Material::SHADERTYPE_COUNT; Material::ShaderType st = Material::SHADERTYPE_COUNT;
for (auto& p : particle_drawn) for (auto& p : particle_drawn)
{ {
bool flips = false; const bool flips = isFlipsMaterial(p.second);
for (unsigned i = 0; i < m_particles_queue[p.second].size(); i++)
{
if (m_particles_queue[p.second][i]->getFlips())
{
flips = true;
break;
}
}
Material* cur_mat = p.first; Material* cur_mat = p.first;
if (cur_mat->getShaderType() != st) if (cur_mat->getShaderType() != st)
{ {

View File

@ -33,6 +33,7 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
#include <vector> #include <vector>
using namespace irr; using namespace irr;
@ -75,6 +76,12 @@ private:
std::unordered_map<std::string, Material*> m_material_map; std::unordered_map<std::string, Material*> m_material_map;
std::unordered_set<std::string> m_flips_material;
// ------------------------------------------------------------------------
bool isFlipsMaterial(const std::string& name)
{ return m_flips_material.find(name) != m_flips_material.end(); }
public: public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
CPUParticleManager() {} CPUParticleManager() {}
@ -104,6 +111,7 @@ public:
void cleanMaterialMap() void cleanMaterialMap()
{ {
m_material_map.clear(); m_material_map.clear();
m_flips_material.clear();
} }
}; };