Skip to content

Commit

Permalink
Test rendered light entity has correct world origin
Browse files Browse the repository at this point in the history
TestRenderableCollector now stores a list of RendererLight pointers rather than
just counting the lights submitted, and this list is used to confirm that the
"origin" key set on the test light entity appears correctly as the result of
worldOrigin().
  • Loading branch information
Matthew Mott committed Jan 31, 2021
1 parent 65a2ef3 commit df60c5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 3 additions & 5 deletions include/irender.h
Expand Up @@ -149,8 +149,7 @@ typedef std::shared_ptr<IRenderEntity> IRenderEntityPtr;
typedef std::weak_ptr<IRenderEntity> IRenderEntityWeakPtr;

/**
* \brief
* Interface for a light source in the renderer.
* \brief Interface for a light source in the renderer.
*/
class RendererLight
{
Expand All @@ -171,8 +170,7 @@ class RendererLight
virtual const ShaderPtr& getShader() const = 0;

/**
* \brief
* Return the origin of the light volume in world space.
* \brief Return the origin of the light volume in world space.
*
* This corresponds to the "origin" key of the light object, i.e. the center
* of the bounding box for an omni light and the tip of the pyramid for a
Expand Down Expand Up @@ -573,7 +571,7 @@ class RenderSystem
// Returns true if openGL supports ARB or GLSL lighting
virtual bool shaderProgramsAvailable() const = 0;

// Sets the flag whether shader programs are available.
// Sets the flag whether shader programs are available.
virtual void setShaderProgramsAvailable(bool available) = 0;

// Subscription to get notified as soon as the openGL extensions have been initialised
Expand Down
22 changes: 19 additions & 3 deletions test/Entity.cpp
Expand Up @@ -7,6 +7,7 @@
#include "iselection.h"

#include "render/NopVolumeTest.h"
#include "string/convert.h"

namespace test
{
Expand Down Expand Up @@ -277,13 +278,16 @@ TEST_F(EntityTest, DestroySelectedEntity)

namespace
{
// A simple RenderableCollector which just logs the number of renderables
// and lights submitted
// A simple RenderableCollector which just logs/stores whatever is submitted
struct TestRenderableCollector: public RenderableCollector
{
// Count of submitted renderables and lights
int renderables = 0;
int lights = 0;

// List of actual RendererLight objects
std::list<const RendererLight*> lightPtrs;

void addRenderable(Shader& shader, const OpenGLRenderable& renderable,
const Matrix4& localToWorld,
const LitObject* litObject = nullptr,
Expand All @@ -295,6 +299,7 @@ namespace
void addLight(const RendererLight& light)
{
++lights;
lightPtrs.push_back(&light);
}

bool supportsFullMaterials() const override { return true; }
Expand Down Expand Up @@ -346,15 +351,26 @@ TEST_F(EntityTest, RenderSelectedLightEntity)
TEST_F(EntityTest, RenderLightAsLightSource)
{
auto light = createByClassName("light");
RenderFixture renderF;
auto& spawnArgs = light->getEntity();

// Set a non-default origin for the light
static const Vector3 ORIGIN(-64, 128, 963);
spawnArgs.setKeyValue("origin", string::to_string(ORIGIN));

// Render the light in full materials mode
RenderFixture renderF;
light->setRenderSystem(renderF.backend);
light->renderSolid(renderF.collector, renderF.volumeTest);

// We should get one renderable for the origin diamond, and one light source
EXPECT_EQ(renderF.collector.renderables, 1);
EXPECT_EQ(renderF.collector.lights, 1);

// Confirm properties of the submitted RendererLight
ASSERT_EQ(renderF.collector.lightPtrs.size(), 1);
const RendererLight* rLight = renderF.collector.lightPtrs.front();
ASSERT_TRUE(rLight);
EXPECT_EQ(rLight->worldOrigin(), ORIGIN);
}

TEST_F(EntityTest, CreateAttachedLightEntity)
Expand Down

0 comments on commit df60c5f

Please sign in to comment.