From 67105775b6eee8d3de9b9a3c222078a65f921d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 13 Nov 2013 23:36:52 +0100 Subject: [PATCH] The default scenery for a SoftwareRenderer is now a default scenery (not the global one) --- src/editing/common/freeformhelper.cpp | 6 ++-- src/editing/formatmosphere.cpp | 33 ++++++++++--------- src/editing/formatmosphere.h | 3 ++ src/editing/formrender.cpp | 4 +-- src/render/opengl/WidgetExplorer.cpp | 2 +- .../AtmosphereColorPreviewRenderer.cpp | 6 ++-- .../preview/AtmosphereColorPreviewRenderer.h | 2 +- src/render/preview/Base2dPreviewRenderer.cpp | 2 -- src/render/preview/Base2dPreviewRenderer.h | 3 -- src/render/preview/BasePreview.cpp | 5 +-- src/render/software/SoftwareRenderer.cpp | 10 +++++- src/render/software/SoftwareRenderer.h | 1 + src/tests/FluidMediumManager_Test.cpp | 5 +-- 13 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/editing/common/freeformhelper.cpp b/src/editing/common/freeformhelper.cpp index ef39e03..b550561 100644 --- a/src/editing/common/freeformhelper.cpp +++ b/src/editing/common/freeformhelper.cpp @@ -232,9 +232,8 @@ void FreeFormHelper::processApplyClicked() void FreeFormHelper::processExploreClicked() { - SoftwareRenderer renderer; + SoftwareRenderer renderer(Scenery::getCurrent()); - Scenery::getCurrent()->bindToRenderer(&renderer); emit needAlterRenderer(&renderer); CameraDefinition* camera = cameraCreateDefinition(); @@ -249,9 +248,8 @@ void FreeFormHelper::processExploreClicked() void FreeFormHelper::processRenderClicked() { - SoftwareRenderer renderer; + SoftwareRenderer renderer(Scenery::getCurrent()); - Scenery::getCurrent()->bindToRenderer(&renderer); emit needAlterRenderer(&renderer); DialogRender* dialog = new DialogRender(_form_widget, &renderer); diff --git a/src/editing/formatmosphere.cpp b/src/editing/formatmosphere.cpp index 9ca3858..566aa01 100644 --- a/src/editing/formatmosphere.cpp +++ b/src/editing/formatmosphere.cpp @@ -15,24 +15,14 @@ static AtmosphereDefinition* _definition; /**************** Previews ****************/ -class PreviewSkyEast:public AtmosphereColorPreviewRenderer +class PreviewSkyRenderer:public AtmosphereColorPreviewRenderer { public: - void bindEvent(BasePreview* preview) override + PreviewSkyRenderer(double heading): + AtmosphereColorPreviewRenderer(heading) { - preview->configHdrToneMapping(true); - preview->configScaling(0.5, 5.0, 0.5, 2.5); } - void updateEvent() override - { - /*AtmosphereRendererClass.bind(renderer, _definition); - renderer->prepare();*/ - } -}; -class PreviewSkyWest:public AtmosphereColorPreviewRenderer -{ -public: void bindEvent(BasePreview* preview) override { preview->configHdrToneMapping(true); @@ -40,8 +30,8 @@ public: } void updateEvent() override { - /*AtmosphereRendererClass.bind(renderer, _definition); - renderer->prepare();*/ + getScenery()->setAtmosphere(_definition); + prepare(); } }; @@ -58,8 +48,13 @@ FormAtmosphere::FormAtmosphere(QWidget *parent): _definition = (AtmosphereDefinition*)AtmosphereDefinitionClass.create(); previewWest = new BasePreview(this); + previewWestRenderer = new PreviewSkyRenderer(M_PI / 2.0); + previewWest->setRenderer(previewWestRenderer); addPreview(previewWest, QString(tr("West preview"))); + previewEast = new BasePreview(this); + previewEastRenderer = new PreviewSkyRenderer(-M_PI / 2.0); + previewEast->setRenderer(previewEastRenderer); addPreview(previewEast, QString(tr("East preview"))); //addInputEnum(tr("Color model"), (int*)&_definition->model, QStringList(tr("Simplified model (with weather)")) << tr("Complex model")); @@ -73,6 +68,14 @@ FormAtmosphere::FormAtmosphere(QWidget *parent): revertConfig(); } +FormAtmosphere::~FormAtmosphere() +{ + delete previewWest; + delete previewWestRenderer; + delete previewEast; + delete previewEastRenderer; +} + void FormAtmosphere::revertConfig() { Scenery::getCurrent()->getAtmosphere(_definition); diff --git a/src/editing/formatmosphere.h b/src/editing/formatmosphere.h index 202564d..203543b 100644 --- a/src/editing/formatmosphere.h +++ b/src/editing/formatmosphere.h @@ -12,6 +12,7 @@ class FormAtmosphere : public BaseForm public: explicit FormAtmosphere(QWidget *parent = 0); + virtual ~FormAtmosphere(); public slots: virtual void revertConfig(); @@ -23,7 +24,9 @@ protected slots: private: BasePreview* previewEast; + Base2dPreviewRenderer* previewEastRenderer; BasePreview* previewWest; + Base2dPreviewRenderer* previewWestRenderer; }; #endif diff --git a/src/editing/formrender.cpp b/src/editing/formrender.cpp index 0935ff1..d88d82b 100644 --- a/src/editing/formrender.cpp +++ b/src/editing/formrender.cpp @@ -192,7 +192,7 @@ void FormRender::startQuickRender() { rendererDelete(_renderer); } - _renderer = new SoftwareRenderer(); + _renderer = new SoftwareRenderer(Scenery::getCurrent()); _renderer_inited = true; DialogRender* dialog = new DialogRender(this, _renderer); @@ -208,7 +208,7 @@ void FormRender::startRender() { rendererDelete(_renderer); } - _renderer = new SoftwareRenderer(); + _renderer = new SoftwareRenderer(Scenery::getCurrent()); _renderer_inited = true; DialogRender* dialog = new DialogRender(this, _renderer); diff --git a/src/render/opengl/WidgetExplorer.cpp b/src/render/opengl/WidgetExplorer.cpp index a84c5fe..a0cae0b 100644 --- a/src/render/opengl/WidgetExplorer.cpp +++ b/src/render/opengl/WidgetExplorer.cpp @@ -90,7 +90,7 @@ QGLWidget(parent) } else { - _renderer = new SoftwareRenderer(); + _renderer = new SoftwareRenderer(Scenery::getCurrent()); _renderer_created = true; } _opengl_renderer = new OpenGLRenderer(NULL); diff --git a/src/render/preview/AtmosphereColorPreviewRenderer.cpp b/src/render/preview/AtmosphereColorPreviewRenderer.cpp index a71ee75..99df668 100644 --- a/src/render/preview/AtmosphereColorPreviewRenderer.cpp +++ b/src/render/preview/AtmosphereColorPreviewRenderer.cpp @@ -145,8 +145,8 @@ static inline int _checkHit(Vector3 eye, Vector3 direction, Vector3* hit, Vector return _checkHitGround(eye, direction, hit); } -AtmosphereColorPreviewRenderer::AtmosphereColorPreviewRenderer(): - heading(0.0) +AtmosphereColorPreviewRenderer::AtmosphereColorPreviewRenderer(double heading): + heading(heading) { cameraSetLocation(render_camera, Vector3(0.0, 7.0, 0.0)); } @@ -154,7 +154,7 @@ AtmosphereColorPreviewRenderer::AtmosphereColorPreviewRenderer(): Color AtmosphereColorPreviewRenderer::getColor2D(double x, double y, double) { Vector3 eye = {0.0, 7.0, 0.0}; - Vector3 direction = {x, y, -1.0}; + Vector3 direction = {x, -y, -1.0}; Vector3 hit, normal; Matrix4 rotation; diff --git a/src/render/preview/AtmosphereColorPreviewRenderer.h b/src/render/preview/AtmosphereColorPreviewRenderer.h index abbe762..b3fe1b5 100644 --- a/src/render/preview/AtmosphereColorPreviewRenderer.h +++ b/src/render/preview/AtmosphereColorPreviewRenderer.h @@ -9,7 +9,7 @@ namespace preview { class AtmosphereColorPreviewRenderer:public Base2dPreviewRenderer { public: - AtmosphereColorPreviewRenderer(); + AtmosphereColorPreviewRenderer(double heading); virtual Color getColor2D(double x, double y, double scaling) override; diff --git a/src/render/preview/Base2dPreviewRenderer.cpp b/src/render/preview/Base2dPreviewRenderer.cpp index 91a355e..5e67e99 100644 --- a/src/render/preview/Base2dPreviewRenderer.cpp +++ b/src/render/preview/Base2dPreviewRenderer.cpp @@ -6,12 +6,10 @@ Base2dPreviewRenderer::Base2dPreviewRenderer(): SoftwareRenderer() { - scenery = new Scenery(); } Base2dPreviewRenderer::~Base2dPreviewRenderer() { - delete scenery; } void Base2dPreviewRenderer::bindEvent(BasePreview*) diff --git a/src/render/preview/Base2dPreviewRenderer.h b/src/render/preview/Base2dPreviewRenderer.h index 20d110d..8e685e0 100644 --- a/src/render/preview/Base2dPreviewRenderer.h +++ b/src/render/preview/Base2dPreviewRenderer.h @@ -22,9 +22,6 @@ public: virtual void updateEvent(); virtual Color getColor2D(double x, double y, double scaling); - -protected: - Scenery* scenery; }; } diff --git a/src/render/preview/BasePreview.cpp b/src/render/preview/BasePreview.cpp index a798485..8297e6c 100644 --- a/src/render/preview/BasePreview.cpp +++ b/src/render/preview/BasePreview.cpp @@ -646,10 +646,7 @@ QColor BasePreview::getPixelColor(int x, int y) { col = colorProfileApply(_hdr_profile, col); } - else - { - colorNormalize(&col); - } + col.normalize(); return QColor::fromRgbF(col.r, col.g, col.b, col.a); } diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index b4afd38..3a4365e 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -34,10 +34,12 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery) if (scenery) { this->scenery = scenery; + own_scenery = false; } else { - this->scenery = Scenery::getCurrent(); + this->scenery = new Scenery; + own_scenery = true; } this->scenery->bindToRenderer(this); } @@ -47,6 +49,11 @@ SoftwareRenderer::~SoftwareRenderer() delete atmosphere_renderer; delete fluid_medium; + + if (own_scenery) + { + delete scenery; + } } void SoftwareRenderer::prepare() @@ -56,6 +63,7 @@ void SoftwareRenderer::prepare() atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this); // Setup transitional renderers (for C-legacy subsystems) + AtmosphereDefinitionClass.copy(scenery->getAtmosphere(), atmosphere->definition); atmosphere->applyAerialPerspective = _legacyApplyAerialPerspective; atmosphere->getSkyColor = _legacyGetSkyColor; atmosphere->getLightingStatus = _legacyGetLightingStatus; diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index e54a6c1..53ba7b2 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -36,6 +36,7 @@ public: private: Scenery* scenery; + bool own_scenery; FluidMediumManager* fluid_medium; BaseAtmosphereRenderer* atmosphere_renderer; }; diff --git a/src/tests/FluidMediumManager_Test.cpp b/src/tests/FluidMediumManager_Test.cpp index 53ba9d6..3bae97f 100644 --- a/src/tests/FluidMediumManager_Test.cpp +++ b/src/tests/FluidMediumManager_Test.cpp @@ -11,17 +11,14 @@ class FluidMediumManager_Test:public BaseTestCase protected: virtual void setUp() { - scenery = new Scenery(); - renderer = new SoftwareRenderer(scenery); + renderer = new SoftwareRenderer(); } virtual void tearDown() { delete renderer; - delete scenery; } - Scenery* scenery; SoftwareRenderer* renderer; };