Fixed clouds layers being deleted in scenery by opengl renderer

This commit is contained in:
Michaël Lemaire 2015-08-19 19:28:36 +02:00
parent 0058a0a8e3
commit 3599c3aecf
5 changed files with 18 additions and 14 deletions

View file

@ -6,6 +6,7 @@
#include "OpenGLSkybox.h" #include "OpenGLSkybox.h"
#include "OpenGLWater.h" #include "OpenGLWater.h"
#include "OpenGLTerrain.h" #include "OpenGLTerrain.h"
#include "CloudsRenderer.h"
#include "Scenery.h" #include "Scenery.h"
#include "LightingManager.h" #include "LightingManager.h"
#include "Logs.h" #include "Logs.h"
@ -57,7 +58,7 @@ void OpenGLRenderer::initialize()
prepare(); prepare();
disableClouds(); getCloudsRenderer()->setEnabled(false);
getLightingManager()->setSpecularity(false); getLightingManager()->setSpecularity(false);
skybox->initialize(); skybox->initialize();

View file

@ -17,6 +17,7 @@
CloudsRenderer::CloudsRenderer(SoftwareRenderer* parent): CloudsRenderer::CloudsRenderer(SoftwareRenderer* parent):
parent(parent) parent(parent)
{ {
enabled = true;
fake_renderer = new BaseCloudLayerRenderer(parent); fake_renderer = new BaseCloudLayerRenderer(parent);
CloudLayerDefinition* fake_layer = new CloudLayerDefinition(NULL); CloudLayerDefinition* fake_layer = new CloudLayerDefinition(NULL);
@ -39,6 +40,11 @@ CloudsRenderer::~CloudsRenderer()
delete fake_model; delete fake_model;
} }
void CloudsRenderer::setEnabled(bool enabled)
{
this->enabled = enabled;
}
void CloudsRenderer::update() void CloudsRenderer::update()
{ {
for (auto renderer : layer_renderers) for (auto renderer : layer_renderers)
@ -138,7 +144,7 @@ Color CloudsRenderer::getColor(const Vector3 &eye, const Vector3 &location, cons
CloudsDefinition* definition = parent->getScenery()->getClouds(); CloudsDefinition* definition = parent->getScenery()->getClouds();
int n = definition->count(); int n = definition->count();
if (n < 1) if (not enabled or n < 1)
{ {
return base; return base;
} }
@ -164,7 +170,7 @@ bool CloudsRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
CloudsDefinition* definition = parent->getScenery()->getClouds(); CloudsDefinition* definition = parent->getScenery()->getClouds();
int n = definition->count(); int n = definition->count();
if (n < 1) if (not enabled or n < 1)
{ {
return true; return true;
} }

View file

@ -17,6 +17,11 @@ public:
CloudsRenderer(SoftwareRenderer* parent); CloudsRenderer(SoftwareRenderer* parent);
virtual ~CloudsRenderer(); virtual ~CloudsRenderer();
/**
* Enable or disable the whole cloud rendering.
*/
void setEnabled(bool enabled);
/*! /*!
* \brief Update the renderer with the bound scenery. * \brief Update the renderer with the bound scenery.
* *
@ -58,6 +63,7 @@ public:
*/ */
virtual bool applyLightFilter(LightComponent &light, const Vector3 &at) override; virtual bool applyLightFilter(LightComponent &light, const Vector3 &at) override;
private: private:
bool enabled;
SoftwareRenderer* parent; SoftwareRenderer* parent;
std::vector<BaseCloudLayerRenderer*> layer_renderers; std::vector<BaseCloudLayerRenderer*> layer_renderers;

View file

@ -86,11 +86,6 @@ void SoftwareRenderer::prepare()
//fluid_medium->registerMedium(water_renderer); //fluid_medium->registerMedium(water_renderer);
} }
void SoftwareRenderer::disableClouds()
{
scenery->getClouds()->clear();
}
void SoftwareRenderer::disableAtmosphere() void SoftwareRenderer::disableAtmosphere()
{ {
LightComponent light; LightComponent light;

View file

@ -38,16 +38,12 @@ public:
*/ */
virtual void prepare(); virtual void prepare();
/*!
* \brief Disable the clouds feature.
*
* This toggle is permanent, provided the clouds part of the sceney is not changed.
*/
void disableClouds();
/*! /*!
* \brief Disable atmosphere and sky lighting, replacing it by static lights. * \brief Disable atmosphere and sky lighting, replacing it by static lights.
* *
* This function needs to be called after each prepare(). * This function needs to be called after each prepare().
*
* WARNING : This method changes the scenery attached to the renderer !
*/ */
void disableAtmosphere(); void disableAtmosphere();
void disableAtmosphere(const std::vector<LightComponent> &lights); void disableAtmosphere(const std::vector<LightComponent> &lights);