Skip to content

Commit

Permalink
Add a simple test for rendering a light entity
Browse files Browse the repository at this point in the history
Render the light entity in wireframe mode and confirm we receive the expected
number of renderables (origin diamond, radius and light_center depending on
selection status).
  • Loading branch information
Matthew Mott committed Jan 31, 2021
1 parent 6ed581f commit a4a3ace
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
14 changes: 5 additions & 9 deletions include/irenderable.h
Expand Up @@ -16,8 +16,7 @@ class RendererLight;
class LitObject;

/**
* \brief
* Class which accepts OpenGLRenderable objects during the first pass of
* \brief Class which accepts OpenGLRenderable objects during the first pass of
* rendering.
*
* Each Renderable in the scenegraph is passed a reference to a
Expand All @@ -33,8 +32,7 @@ class RenderableCollector
virtual ~RenderableCollector() {}

/**
* \brief
* Submit a renderable object
* \brief Submit a renderable object.
*
* This method allows renderable geometry to be submitted under the control
* of a LitObject which will determine whether and how the renderable is
Expand Down Expand Up @@ -74,8 +72,7 @@ class RenderableCollector
const IRenderEntity* entity = nullptr) = 0;

/**
* \brief
* Submit a light source for the render operation.
* \brief Submit a light source for the render operation.
*
* This is the entry point for lights into the render front-end. Each light
* in the scene graph must be submitted through this method in order to
Expand All @@ -85,9 +82,8 @@ class RenderableCollector
virtual void addLight(const RendererLight& light) = 0;

/**
* \brief
* Determine if this RenderableCollector can accept renderables for full
* materials rendering, or just wireframe rendering.
* \brief Determine if this RenderableCollector can accept renderables for
* full materials rendering, or just wireframe rendering.
*
* \return
* true if full materials are supported, false if only wireframe rendering
Expand Down
62 changes: 62 additions & 0 deletions test/Entity.cpp
Expand Up @@ -2,6 +2,10 @@

#include "ieclass.h"
#include "ientity.h"
#include "irendersystemfactory.h"
#include "iselectable.h"

#include "render/NopVolumeTest.h"

namespace test
{
Expand Down Expand Up @@ -244,6 +248,64 @@ TEST_F(EntityTest, CopySpawnargs)
EXPECT_EQ(overlap.size(), 0);
}

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

void addRenderable(Shader& shader, const OpenGLRenderable& renderable,
const Matrix4& localToWorld,
const LitObject* litObject = nullptr,
const IRenderEntity* entity = nullptr) override
{
++renderables;
}

void addLight(const RendererLight& light)
{
++lights;
}

bool supportsFullMaterials() const override { return true; }
void setHighlightFlag(Highlight::Flags flags, bool enabled) override
{}
};
}

TEST_F(EntityTest, RenderLightEntity)
{
auto light = createByClassName("light");
auto& spawnArgs = light->getEntity();

// Rendering requires a backend and a volume test
auto backend = GlobalRenderSystemFactory().createRenderSystem();
render::NopVolumeTest volumeTest;

// Render the light in wireframe mode. This should render just the origin
// diamond.
{
TestRenderableCollector wireframeRenderer;
light->setRenderSystem(backend);
light->renderWireframe(wireframeRenderer, volumeTest);
EXPECT_EQ(wireframeRenderer.renderables, 1);
}

// With the light selected, we should get the origin diamond, the radius and
// the center vertex.
{
TestRenderableCollector wireframeRenderer;
Node_getSelectable(light)->setSelected(true);
light->setRenderSystem(backend);
light->renderWireframe(wireframeRenderer, volumeTest);
EXPECT_EQ(wireframeRenderer.renderables, 3);
Node_getSelectable(light)->setSelected(false);
}
}

TEST_F(EntityTest, CreateAttachedLightEntity)
{
// Create the torch entity which has an attached light
Expand Down

0 comments on commit a4a3ace

Please sign in to comment.