Skip to content

Commit

Permalink
#219: Fix crash when opening render previews
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 26, 2022
1 parent 16bc9c1 commit 02f23ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
21 changes: 18 additions & 3 deletions radiantcore/rendersystem/backend/LightInteractions.cpp
Expand Up @@ -8,6 +8,20 @@
namespace render
{

LightInteractions::LightInteractions(RendererLight& light, IGeometryStore& store) :
_light(light),
_store(store),
_lightBounds(light.lightAABB()),
_interactionDrawCalls(0),
_depthDrawCalls(0),
_objectCount(0),
_shadowMapDrawCalls(0),
_shadowLightIndex(-1)
{
// Consider the "noshadows" flag and the setting of the light material
_isShadowCasting = _light.isShadowCasting() && _light.getShader() && _light.getShader()->getMaterial()->lightCastsShadows();
}

void LightInteractions::addObject(IRenderableObject& object, IRenderEntity& entity, OpenGLShader* shader)
{
auto& objectsByMaterial = _objectsByEntity.emplace(
Expand All @@ -26,9 +40,9 @@ bool LightInteractions::isInView(const IRenderView& view)
return view.TestAABB(_lightBounds) != VOLUME_OUTSIDE;
}

bool LightInteractions::isShadowCasting()
bool LightInteractions::isShadowCasting() const
{
return _light.isShadowCasting();
return _isShadowCasting;
}

void LightInteractions::collectSurfaces(const IRenderView& view, const std::set<IRenderEntityPtr>& entities)
Expand Down Expand Up @@ -156,7 +170,8 @@ void LightInteractions::drawShadowMap(OpenGLState& state, const Rectangle& recta
{
auto depthFillPass = shader->getDepthFillPass();

if (!depthFillPass) continue;
// Skip shaders not affecting scene depth, and materials not casting any shadow
if (!depthFillPass || !shader->getMaterial()->surfaceCastsShadow()) continue;

setupAlphaTest(state, shader, depthFillPass, program, renderTime, entity);

Expand Down
15 changes: 3 additions & 12 deletions radiantcore/rendersystem/backend/LightInteractions.h
Expand Up @@ -4,7 +4,6 @@
#include <vector>
#include <set>
#include "irender.h"
#include "isurfacerenderer.h"
#include "irenderableobject.h"
#include "irenderview.h"
#include "render/Rectangle.h"
Expand Down Expand Up @@ -48,18 +47,10 @@ class LightInteractions
std::size_t _shadowMapDrawCalls;

int _shadowLightIndex;
bool _isShadowCasting;

public:
LightInteractions(RendererLight& light, IGeometryStore& store) :
_light(light),
_store(store),
_lightBounds(light.lightAABB()),
_interactionDrawCalls(0),
_depthDrawCalls(0),
_objectCount(0),
_shadowMapDrawCalls(0),
_shadowLightIndex(-1)
{}
LightInteractions(RendererLight& light, IGeometryStore& store);

const Vector3& getBoundsCenter() const
{
Expand Down Expand Up @@ -110,7 +101,7 @@ class LightInteractions

bool isInView(const IRenderView& view);

bool isShadowCasting();
bool isShadowCasting() const;

void collectSurfaces(const IRenderView& view, const std::set<IRenderEntityPtr>& entities);

Expand Down

0 comments on commit 02f23ea

Please sign in to comment.