Skip to content

Commit

Permalink
#5893: Add IRenderEntity::foreachSurfaceTouchingBounds to enumerate t…
Browse files Browse the repository at this point in the history
…he ones intersecting with a given light.
  • Loading branch information
codereader committed Jan 27, 2022
1 parent da0a46f commit 8f56350
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/irender.h
Expand Up @@ -180,6 +180,13 @@ class IRenderEntity
* Removes the surface from this entity.
*/
virtual void removeSurface(const render::IRenderableSurface::Ptr& surface) = 0;

/**
* Enumerate all entity surfaces (partially) intersecting with the given bounds.
* The bounds are specified in world coordinates.
*/
virtual void foreachSurfaceTouchingBounds(const AABB& bounds,
const std::function<void(const render::IRenderableSurface::Ptr&)>& functor) = 0;
};
typedef std::shared_ptr<IRenderEntity> IRenderEntityPtr;
typedef std::weak_ptr<IRenderEntity> IRenderEntityWeakPtr;
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -210,6 +210,12 @@ void EntityNode::removeSurface(const render::IRenderableSurface::Ptr& surface)
// TODO
}

void EntityNode::foreachSurfaceTouchingBounds(const AABB& bounds,
const std::function<void(const render::IRenderableSurface::Ptr&)>& functor)
{
// TODO
}

std::string EntityNode::getFingerprint()
{
std::map<std::string, std::string> sortedKeyValues;
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/EntityNode.h
Expand Up @@ -126,6 +126,8 @@ class EntityNode :

virtual void addSurface(const render::IRenderableSurface::Ptr& surface) override;
virtual void removeSurface(const render::IRenderableSurface::Ptr& surface) override;
virtual void foreachSurfaceTouchingBounds(const AABB& bounds,
const std::function<void(const render::IRenderableSurface::Ptr&)>& functor) override;

// IMatrixTransform implementation
Matrix4 localToParent() const override { return _localToParent; }
Expand Down
5 changes: 4 additions & 1 deletion radiantcore/rendersystem/LightingModeRenderResult.h
Expand Up @@ -13,9 +13,12 @@ class LightingModeRenderResult :
std::size_t visibleLights = 0;
std::size_t skippedLights = 0;

std::size_t entities = 0;
std::size_t surfaces = 0;

std::string toString() override
{
return fmt::format("Lights: {0} of {1}", visibleLights, skippedLights);
return fmt::format("Lights: {0} of {1} | Entities: {2} | Surfaces: {3}", visibleLights, skippedLights, entities, surfaces);
}
};

Expand Down
18 changes: 17 additions & 1 deletion radiantcore/rendersystem/OpenGLRenderSystem.cpp
Expand Up @@ -310,7 +310,23 @@ IRenderResult::Ptr OpenGLRenderSystem::renderLitScene(RenderStateFlags globalFla

result->visibleLights++;

// TODO: Insert rendering code here
// Now check all the entities intersecting with this light
for (const auto& entity : _entities)
{
auto entitySurfaceCount = 0;

entity->foreachSurfaceTouchingBounds(light->lightAABB(),
[&](const render::IRenderableSurface::Ptr& surface)
{
entitySurfaceCount++;
});

if (entitySurfaceCount > 0)
{
result->surfaces += entitySurfaceCount;
result->entities++;
}
}
}

finishRendering();
Expand Down

0 comments on commit 8f56350

Please sign in to comment.