Skip to content

Commit

Permalink
#5584: Start migrating particle render methods. Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 16, 2021
1 parent 3957655 commit 706201f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
12 changes: 12 additions & 0 deletions radiantcore/particles/ParticleNode.cpp
Expand Up @@ -64,15 +64,25 @@ bool ParticleNode::isOriented() const
return true;
}

void ParticleNode::onPreRender(const VolumeTest& volume)
{
if (!_renderableParticle) return;

// Update the particle system before rendering
update(volume);
}

void ParticleNode::renderSolid(IRenderableCollector& collector,
const VolumeTest& volume) const
{
#if 0
if (!_renderableParticle) return;

// Update the particle system before rendering
update(volume);

_renderableParticle->renderSolid(collector, volume, localToWorld(), _renderEntity);
#endif
}

void ParticleNode::renderWireframe(IRenderableCollector& collector,
Expand All @@ -91,9 +101,11 @@ void ParticleNode::renderWireframe(IRenderableCollector& collector,

void ParticleNode::renderHighlights(IRenderableCollector& collector, const VolumeTest& volume)
{
#if 0
if (!collector.supportsFullMaterials()) return;

renderSolid(collector, volume);
#endif
}

void ParticleNode::setRenderSystem(const RenderSystemPtr& renderSystem)
Expand Down
1 change: 1 addition & 0 deletions radiantcore/particles/ParticleNode.h
Expand Up @@ -36,6 +36,7 @@ class ParticleNode :
std::size_t getHighlightFlags() override;

bool isOriented() const override;
void onPreRender(const VolumeTest& volume) override;
void renderSolid(IRenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(IRenderableCollector& collector, const VolumeTest& volume) const override;
void renderHighlights(IRenderableCollector& collector, const VolumeTest& volume) override;
Expand Down
43 changes: 20 additions & 23 deletions radiantcore/particles/RenderableParticle.cpp
Expand Up @@ -16,17 +16,17 @@ RenderableParticle::RenderableParticle(const IParticleDefPtr& particleDef) :
RenderableParticle::~RenderableParticle()
{
// Clear the particle def reference (remove this class as observer)
setParticleDef(IParticleDefPtr());
setParticleDef({});
}

// Time is in msecs
void RenderableParticle::update(const Matrix4& viewRotation)
{
RenderSystemPtr renderSystem = _renderSystem.lock();
auto renderSystem = _renderSystem.lock();

if (!renderSystem) return; // no rendersystem there yet

std::size_t time = renderSystem->getTime();
auto time = renderSystem->getTime();

// Invalidate our bounds information
_bounds = AABB();
Expand All @@ -36,15 +36,14 @@ void RenderableParticle::update(const Matrix4& viewRotation)

// greebo: Use the inverse matrix of the incoming matrix, this is enough to compensate
// the camera rotation.
Matrix4 invViewRotation = viewRotation.getInverse();
auto invViewRotation = viewRotation.getInverse();

// Traverse the stages and call update
for (ShaderMap::const_iterator i = _shaderMap.begin(); i != _shaderMap.end(); ++i)
for (const auto& pair : _shaderMap)
{
for (RenderableParticleStageList::const_iterator stage = i->second.stages.begin();
stage != i->second.stages.end(); ++stage)
for (const auto& stage : pair.second.stages)
{
(*stage)->update(time, invViewRotation);
stage->update(time, invViewRotation);
}
}
}
Expand Down Expand Up @@ -137,7 +136,7 @@ void RenderableParticle::setEntityColour(const Vector3& colour)
{
_entityColour = colour;

// The particle stages hold a const-reference to _direction
// The particle stages hold a const-reference to _entityColour
// so no further update is needed
}

Expand All @@ -154,12 +153,11 @@ const AABB& RenderableParticle::getBounds()

void RenderableParticle::calculateBounds()
{
for (ShaderMap::const_iterator i = _shaderMap.begin(); i != _shaderMap.end(); ++i)
for (const auto& pair : _shaderMap)
{
for (RenderableParticleStageList::const_iterator stage = i->second.stages.begin();
stage != i->second.stages.end(); ++stage)
for (const auto& stage : pair.second.stages)
{
_bounds.includeAABB((*stage)->getBounds());
_bounds.includeAABB(stage->getBounds());
}
}
}
Expand All @@ -169,33 +167,32 @@ void RenderableParticle::setupStages()
{
_shaderMap.clear();

if (_particleDef == NULL) return; // nothing to do.
if (!_particleDef) return; // nothing to do.

for (std::size_t i = 0; i < _particleDef->getNumStages(); ++i)
{
const IStageDef& stage = _particleDef->getStage(i);

const std::string& materialName = stage.getMaterialName();
const auto& stage = _particleDef->getStage(i);
const auto& materialName = stage.getMaterialName();

if (_shaderMap.find(materialName) == _shaderMap.end())
{
_shaderMap.insert(ShaderMap::value_type(materialName, ParticleStageGroup()));
_shaderMap.emplace(materialName, ParticleStageGroup());
}

// Create a new renderable stage and add it to the shader
RenderableParticleStagePtr renderableStage(new RenderableParticleStage(stage, _random, _direction, _entityColour));
_shaderMap[materialName].stages.push_back(renderableStage);
auto renderableStage = std::make_shared<RenderableParticleStage>(stage, _random, _direction, _entityColour);
_shaderMap[materialName].stages.emplace_back(std::move(renderableStage));
}
}

// Capture all shaders, if necessary
void RenderableParticle::ensureShaders(RenderSystem& renderSystem)
{
for (ShaderMap::iterator i = _shaderMap.begin(); i != _shaderMap.end(); ++i)
for (auto& pair : _shaderMap)
{
if (i->second.shader == NULL)
if (!pair.second.shader)
{
i->second.shader = renderSystem.capture(i->first);
pair.second.shader = renderSystem.capture(pair.first);
}
}
}
Expand Down

0 comments on commit 706201f

Please sign in to comment.