From f0ed8d4b4a71fe1b2204782049634a7c1984af66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 2 Jan 2014 15:19:20 +0100 Subject: [PATCH] Added textures mix preview --- src/interface/desktop/desktop.pro | 2 - .../desktop/textures/PreviewCumul.cpp | 45 -------------- .../desktop/textures/maintexturesform.cpp | 9 ++- .../desktop/textures/maintexturesform.h | 2 +- src/render/preview/Base2dPreviewRenderer.cpp | 1 + .../preview/TexturesMixPreviewRenderer.cpp | 58 +++++++++++++++++++ .../preview/TexturesMixPreviewRenderer.h} | 22 ++++--- src/render/preview/preview.pro | 6 +- src/render/preview/preview_global.h | 1 + 9 files changed, 85 insertions(+), 61 deletions(-) delete mode 100644 src/interface/desktop/textures/PreviewCumul.cpp create mode 100644 src/render/preview/TexturesMixPreviewRenderer.cpp rename src/{interface/desktop/textures/PreviewCumul.h => render/preview/TexturesMixPreviewRenderer.h} (50%) diff --git a/src/interface/desktop/desktop.pro b/src/interface/desktop/desktop.pro index b0a4422..4754e1b 100644 --- a/src/interface/desktop/desktop.pro +++ b/src/interface/desktop/desktop.pro @@ -52,7 +52,6 @@ HEADERS += \ lighting/SmallPreviewHues.h \ textures/PreviewLayerCoverage.h \ textures/PreviewLayerLook.h \ - textures/PreviewCumul.h \ textures/DialogTexturesLayer.h \ desktop_global.h \ DesktopScenery.h @@ -100,7 +99,6 @@ SOURCES += \ lighting/SmallPreviewHues.cpp \ textures/PreviewLayerCoverage.cpp \ textures/PreviewLayerLook.cpp \ - textures/PreviewCumul.cpp \ textures/DialogTexturesLayer.cpp \ DesktopScenery.cpp diff --git a/src/interface/desktop/textures/PreviewCumul.cpp b/src/interface/desktop/textures/PreviewCumul.cpp deleted file mode 100644 index 22c549f..0000000 --- a/src/interface/desktop/textures/PreviewCumul.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "PreviewCumul.h" - -#include "SoftwareRenderer.h" -#include "BasePreview.h" - -void PreviewCumul::setTextures(TexturesDefinition* textures) -{ - this->textures = textures; -} - -void PreviewCumul::setLayer(int layer) -{ - this->layer = layer; -} - -void PreviewCumul::bindEvent(BasePreview* preview) -{ - preview->addOsd(QString("geolocation")); - - //preview->configHdrToneMapping(true); - - preview->configScaling(20.0, 1000.0, 20.0, 200.0); - preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); -} - -void PreviewCumul::updateEvent() -{ - if (textures) - { - //TexturesPreviewCumul_bind(this, textures); - } -} - -Color PreviewCumul::getColor2D(double x, double y, double scaling) -{ - if (textures) - { - return COLOR_BLACK; - //return TexturesPreviewCumul_getColor(this, x, y, scaling, layer); - } - else - { - return COLOR_BLACK; - } -} diff --git a/src/interface/desktop/textures/maintexturesform.cpp b/src/interface/desktop/textures/maintexturesform.cpp index 2fdec28..98ab5ab 100644 --- a/src/interface/desktop/textures/maintexturesform.cpp +++ b/src/interface/desktop/textures/maintexturesform.cpp @@ -9,7 +9,7 @@ #include "previewmaterial.h" #include "textures/PreviewLayerCoverage.h" #include "textures/PreviewLayerLook.h" -#include "textures/PreviewCumul.h" +#include "TexturesMixPreviewRenderer.h" #include "textures/DialogTexturesLayer.h" MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm) @@ -34,7 +34,6 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui form_helper->setRevertButton(ui->button_revert); form_helper->setExploreButton(ui->button_explore); form_helper->setRenderButton(ui->button_render); - form_helper->startManaging(); preview_layer_coverage = new PreviewLayerCoverage(); preview_layer_coverage->setTextures(textures); @@ -44,7 +43,7 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui preview_layer_look->setTextures(textures); form_helper->addPreview(ui->preview_texture, preview_layer_look); - preview_cumul = new PreviewCumul(); + preview_cumul = new TexturesMixPreviewRenderer(); preview_cumul->setTextures(textures); form_helper->addPreview(ui->preview_cumul, preview_cumul); @@ -56,6 +55,8 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui connect(form_helper, SIGNAL(presetSelected(int)), this, SLOT(selectPreset(int))); connect(layer_helper, SIGNAL(layersChanged()), form_helper, SLOT(processDataChange())); + + form_helper->startManaging(); } MainTexturesForm::~MainTexturesForm() @@ -133,6 +134,8 @@ void MainTexturesForm::selectPreset(int preset) void MainTexturesForm::updateLocalDataFromScenery() { DesktopScenery::getCurrent()->getTextures(textures); + + preview_cumul->setTerrain(DesktopScenery::getCurrent()->getTerrain()); } void MainTexturesForm::commitLocalDataToScenery() diff --git a/src/interface/desktop/textures/maintexturesform.h b/src/interface/desktop/textures/maintexturesform.h index ef794ea..db5ea85 100644 --- a/src/interface/desktop/textures/maintexturesform.h +++ b/src/interface/desktop/textures/maintexturesform.h @@ -42,7 +42,7 @@ private: FreeLayerHelper* layer_helper; PreviewLayerCoverage* preview_layer_coverage; PreviewLayerLook* preview_layer_look; - PreviewCumul* preview_cumul; + TexturesMixPreviewRenderer* preview_cumul; }; #endif // MAINTEXTURESFORM_H diff --git a/src/render/preview/Base2dPreviewRenderer.cpp b/src/render/preview/Base2dPreviewRenderer.cpp index 579b11a..0ae5adc 100644 --- a/src/render/preview/Base2dPreviewRenderer.cpp +++ b/src/render/preview/Base2dPreviewRenderer.cpp @@ -26,6 +26,7 @@ void Base2dPreviewRenderer::choiceChangeEvent(const std::string &, int) void Base2dPreviewRenderer::updateEvent() { + prepare(); } void Base2dPreviewRenderer::cameraEvent(double, double, double) diff --git a/src/render/preview/TexturesMixPreviewRenderer.cpp b/src/render/preview/TexturesMixPreviewRenderer.cpp new file mode 100644 index 0000000..a030da8 --- /dev/null +++ b/src/render/preview/TexturesMixPreviewRenderer.cpp @@ -0,0 +1,58 @@ +#include "TexturesMixPreviewRenderer.h" + +#include "Scenery.h" +#include "BasePreview.h" +#include "TerrainRenderer.h" + +TexturesMixPreviewRenderer::TexturesMixPreviewRenderer(): + Base2dPreviewRenderer() +{ + textures = NULL; + + render_quality = 3; +} + +void TexturesMixPreviewRenderer::setTextures(TexturesDefinition* textures) +{ + this->textures = textures; +} + +void TexturesMixPreviewRenderer::setTerrain(TerrainDefinition *terrain) +{ + getScenery()->setTerrain(terrain); +} + +void TexturesMixPreviewRenderer::setLayer(int layer) +{ + this->layer = layer; +} + +void TexturesMixPreviewRenderer::bindEvent(BasePreview* preview) +{ + preview->addOsd(QString("geolocation")); + + preview->configHdrToneMapping(true); + + preview->configScaling(20.0, 1000.0, 20.0, 200.0); + preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); +} + +void TexturesMixPreviewRenderer::updateEvent() +{ + Base2dPreviewRenderer::updateEvent(); + + if (textures) + { + getScenery()->setTextures(textures); + } + + disableAtmosphere(); + disableClouds(); +} + +Color TexturesMixPreviewRenderer::getColor2D(double x, double y, double scaling) +{ + TerrainRenderer* terrain_renderer = getTerrainRenderer(); + Vector3 location(x, terrain_renderer->getHeight(x, y, 1), y); + return terrain_renderer->getFinalColor(location, scaling); +} diff --git a/src/interface/desktop/textures/PreviewCumul.h b/src/render/preview/TexturesMixPreviewRenderer.h similarity index 50% rename from src/interface/desktop/textures/PreviewCumul.h rename to src/render/preview/TexturesMixPreviewRenderer.h index f0ea18d..837cac9 100644 --- a/src/interface/desktop/textures/PreviewCumul.h +++ b/src/render/preview/TexturesMixPreviewRenderer.h @@ -1,17 +1,20 @@ -#ifndef EDITING_TEXTURES_PREVIEWCUMUL_H -#define EDITING_TEXTURES_PREVIEWCUMUL_H +#ifndef TEXTURESMIXPREVIEWRENDERER_H +#define TEXTURESMIXPREVIEWRENDERER_H -#include "desktop_global.h" +#include "preview_global.h" #include "Base2dPreviewRenderer.h" -class PreviewCumul : public Base2dPreviewRenderer +namespace paysages { +namespace preview { + +class PREVIEWSHARED_EXPORT TexturesMixPreviewRenderer:public Base2dPreviewRenderer { public: - explicit PreviewCumul(): - Base2dPreviewRenderer(),textures(0){} + TexturesMixPreviewRenderer(); void setTextures(TexturesDefinition* textures); + void setTerrain(TerrainDefinition* terrain); void setLayer(int layer); protected: @@ -20,8 +23,11 @@ protected: virtual Color getColor2D(double x, double y, double scaling); private: - TexturesDefinition* textures; int layer; + TexturesDefinition* textures; }; -#endif +} +} + +#endif // TEXTURESMIXPREVIEWRENDERER_H diff --git a/src/render/preview/preview.pro b/src/render/preview/preview.pro index 9e04425..b7710de 100644 --- a/src/render/preview/preview.pro +++ b/src/render/preview/preview.pro @@ -23,7 +23,8 @@ SOURCES += Base2dPreviewRenderer.cpp \ WaterCoveragePreviewRenderer.cpp \ WaterAspectPreviewRenderer.cpp \ TerrainShapePreviewRenderer.cpp \ - SceneryTopDownPreviewRenderer.cpp + SceneryTopDownPreviewRenderer.cpp \ + TexturesMixPreviewRenderer.cpp HEADERS += Base2dPreviewRenderer.h\ preview_global.h \ @@ -37,7 +38,8 @@ HEADERS += Base2dPreviewRenderer.h\ WaterCoveragePreviewRenderer.h \ WaterAspectPreviewRenderer.h \ TerrainShapePreviewRenderer.h \ - SceneryTopDownPreviewRenderer.h + SceneryTopDownPreviewRenderer.h \ + TexturesMixPreviewRenderer.h unix:!symbian { maemo5 { diff --git a/src/render/preview/preview_global.h b/src/render/preview/preview_global.h index 4574bf6..483026b 100644 --- a/src/render/preview/preview_global.h +++ b/src/render/preview/preview_global.h @@ -23,6 +23,7 @@ namespace preview { class WaterCoveragePreviewRenderer; class WaterAspectPreviewRenderer; class TerrainShapePreviewRenderer; + class TexturesMixPreviewRenderer; } } using namespace paysages::preview;