Add ability to disable vegetation rendering

It is disabled in opengl rendering for now
This commit is contained in:
Michaël Lemaire 2015-10-18 17:35:42 +02:00
parent b430f6037e
commit cd7f30ecae
4 changed files with 48 additions and 14 deletions

View file

@ -7,6 +7,7 @@
#include "OpenGLWater.h"
#include "OpenGLTerrain.h"
#include "CloudsRenderer.h"
#include "VegetationRenderer.h"
#include "Color.h"
#include "Scenery.h"
#include "LightingManager.h"
@ -61,6 +62,16 @@ OpenGLRenderer::~OpenGLRenderer()
delete shared_state;
}
void OpenGLRenderer::prepare()
{
SoftwareRenderer::prepare();
getCloudsRenderer()->setEnabled(false);
getLightingManager()->setSpecularity(false);
getGodRaysSampler()->setEnabled(false);
getVegetationRenderer()->setEnabled(false);
}
void OpenGLRenderer::initialize()
{
ready = functions->initializeOpenGLFunctions();
@ -71,10 +82,6 @@ void OpenGLRenderer::initialize()
prepare();
getCloudsRenderer()->setEnabled(false);
getLightingManager()->setSpecularity(false);
getGodRaysSampler()->setEnabled(false);
skybox->initialize();
skybox->updateScenery();

View file

@ -24,6 +24,8 @@ public:
inline OpenGLTerrain *getTerrain() const {return terrain;}
inline bool isDisplayed() const {return displayed;}
virtual void prepare() override;
void initialize();
void prepareOpenGLState();
void resize(int width, int height);

View file

@ -47,6 +47,11 @@ VegetationRenderer::VegetationRenderer(SoftwareRenderer *parent):
{
}
void VegetationRenderer::setEnabled(bool enabled)
{
this->enabled = enabled;
}
RayCastingResult VegetationRenderer::renderInstance(const SpaceSegment &segment, const VegetationInstance &instance, bool only_hit)
{
RayCastingResult final;
@ -71,6 +76,8 @@ RayCastingResult VegetationRenderer::renderInstance(const SpaceSegment &segment,
RayCastingResult VegetationRenderer::getResult(const SpaceSegment &segment, bool only_hit)
{
if (enabled)
{
// Find instances potentially crossing the segment
// TODO Collect the nearest hit, don't stop at the first one
VegetationGridIterator it(segment, this, parent->getScenery()->getVegetation()->debug_model, only_hit);
@ -82,10 +89,17 @@ RayCastingResult VegetationRenderer::getResult(const SpaceSegment &segment, bool
{
return RayCastingResult();
}
}
else
{
return RayCastingResult();
}
}
bool VegetationRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
{
if (enabled)
{
// Get segment to iterate
SpaceSegment segment(at, at.add(light.direction.scale(-1.0 * parent->render_quality)));
if (getResult(segment, true).hit)
@ -97,4 +111,9 @@ bool VegetationRenderer::applyLightFilter(LightComponent &light, const Vector3 &
{
return true;
}
}
else
{
return true;
}
}

View file

@ -13,6 +13,11 @@ class SOFTWARESHARED_EXPORT VegetationRenderer: public LightFilter
public:
VegetationRenderer(SoftwareRenderer *parent);
/**
* Totally enable or disable the vegetation layers rendering.
*/
void setEnabled(bool enabled);
inline SoftwareRenderer *getParent() const {return parent;}
/**
@ -29,6 +34,7 @@ public:
private:
SoftwareRenderer *parent;
bool enabled;
};
}