From ec71b09f2eed9e749ce065dae834eda8077e1a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 2 Jan 2014 17:36:19 +0100 Subject: [PATCH] [WIP] Texture form previews --- src/interface/desktop/desktop.pro | 4 -- .../desktop/textures/PreviewLayerCoverage.cpp | 43 -------------- .../desktop/textures/PreviewLayerLook.cpp | 43 -------------- .../desktop/textures/PreviewLayerLook.h | 27 --------- .../desktop/textures/maintexturesform.cpp | 11 ++-- .../desktop/textures/maintexturesform.h | 4 +- .../TextureLayerAspectPreviewRenderer.cpp | 51 ++++++++++++++++ .../TextureLayerAspectPreviewRenderer.h} | 19 +++--- .../TextureLayerCoveragePreviewRenderer.cpp | 59 +++++++++++++++++++ .../TextureLayerCoveragePreviewRenderer.h | 33 +++++++++++ .../preview/TexturesMixPreviewRenderer.h | 6 +- src/render/preview/preview.pro | 8 ++- src/render/preview/preview_global.h | 2 + 13 files changed, 174 insertions(+), 136 deletions(-) delete mode 100644 src/interface/desktop/textures/PreviewLayerCoverage.cpp delete mode 100644 src/interface/desktop/textures/PreviewLayerLook.cpp delete mode 100644 src/interface/desktop/textures/PreviewLayerLook.h create mode 100644 src/render/preview/TextureLayerAspectPreviewRenderer.cpp rename src/{interface/desktop/textures/PreviewLayerCoverage.h => render/preview/TextureLayerAspectPreviewRenderer.h} (50%) create mode 100644 src/render/preview/TextureLayerCoveragePreviewRenderer.cpp create mode 100644 src/render/preview/TextureLayerCoveragePreviewRenderer.h diff --git a/src/interface/desktop/desktop.pro b/src/interface/desktop/desktop.pro index 4754e1b..cb703cd 100644 --- a/src/interface/desktop/desktop.pro +++ b/src/interface/desktop/desktop.pro @@ -50,8 +50,6 @@ HEADERS += \ lighting/DialogMaterialEditor.h \ lighting/SmallPreviewColor.h \ lighting/SmallPreviewHues.h \ - textures/PreviewLayerCoverage.h \ - textures/PreviewLayerLook.h \ textures/DialogTexturesLayer.h \ desktop_global.h \ DesktopScenery.h @@ -97,8 +95,6 @@ SOURCES += \ lighting/DialogMaterialEditor.cpp \ lighting/SmallPreviewColor.cpp \ lighting/SmallPreviewHues.cpp \ - textures/PreviewLayerCoverage.cpp \ - textures/PreviewLayerLook.cpp \ textures/DialogTexturesLayer.cpp \ DesktopScenery.cpp diff --git a/src/interface/desktop/textures/PreviewLayerCoverage.cpp b/src/interface/desktop/textures/PreviewLayerCoverage.cpp deleted file mode 100644 index 53dbef1..0000000 --- a/src/interface/desktop/textures/PreviewLayerCoverage.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "PreviewLayerCoverage.h" - -#include "SoftwareRenderer.h" -#include "BasePreview.h" - -void PreviewLayerCoverage::setTextures(TexturesDefinition* textures) -{ - this->textures = textures; -} - -void PreviewLayerCoverage::setLayer(int layer) -{ - this->layer = layer; -} - -void PreviewLayerCoverage::bindEvent(BasePreview* preview) -{ - preview->addOsd(QString("geolocation")); - - 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 PreviewLayerCoverage::updateEvent() -{ - if (textures) - { - //TexturesPreviewLayerCoverage_bind(this, textures); - } -} - -Color PreviewLayerCoverage::getColor2D(double x, double y, double scaling) -{ - if (textures) - { - return COLOR_BLACK; - //return TexturesPreviewLayerCoverage_getColor(this, x, y, scaling, layer); - } - else - { - return COLOR_BLACK; - } -} diff --git a/src/interface/desktop/textures/PreviewLayerLook.cpp b/src/interface/desktop/textures/PreviewLayerLook.cpp deleted file mode 100644 index 423757a..0000000 --- a/src/interface/desktop/textures/PreviewLayerLook.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "PreviewLayerLook.h" - -#include "SoftwareRenderer.h" -#include "BasePreview.h" - -void PreviewLayerLook::setTextures(TexturesDefinition* textures) -{ - this->textures = textures; -} - -void PreviewLayerLook::setLayer(int layer) -{ - this->layer = layer; -} - -void PreviewLayerLook::bindEvent(BasePreview* preview) -{ - //preview->configHdrToneMapping(true); - - preview->configScaling(0.01, 1.0, 0.01, 0.1); -} - -void PreviewLayerLook::updateEvent() -{ - if (textures) - { - //TexturesPreviewLayerLook_bind(this, textures); - } -} - -Color PreviewLayerLook::getColor2D(double x, double y, double scaling) -{ - if (textures) - { - return COLOR_BLACK; - //return TexturesPreviewLayerLook_getColor(this, x, y, scaling, layer); - } - else - { - return COLOR_BLACK; - } -} - diff --git a/src/interface/desktop/textures/PreviewLayerLook.h b/src/interface/desktop/textures/PreviewLayerLook.h deleted file mode 100644 index 0ba0ad3..0000000 --- a/src/interface/desktop/textures/PreviewLayerLook.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef EDITING_TEXTURES_PREVIEWLAYERLOOK_H -#define EDITING_TEXTURES_PREVIEWLAYERLOOK_H - -#include "desktop_global.h" - -#include "Base2dPreviewRenderer.h" - -class PreviewLayerLook : public Base2dPreviewRenderer -{ -public: - explicit PreviewLayerLook(): - Base2dPreviewRenderer(),textures(0){} - - void setTextures(TexturesDefinition* textures); - void setLayer(int layer); - -protected: - virtual void bindEvent(BasePreview* preview); - virtual void updateEvent(); - virtual Color getColor2D(double x, double y, double scaling); - -private: - TexturesDefinition* textures; - int layer; -}; - -#endif diff --git a/src/interface/desktop/textures/maintexturesform.cpp b/src/interface/desktop/textures/maintexturesform.cpp index 98ab5ab..99e02b6 100644 --- a/src/interface/desktop/textures/maintexturesform.cpp +++ b/src/interface/desktop/textures/maintexturesform.cpp @@ -7,10 +7,10 @@ #include "TexturesDefinition.h" #include "TextureLayerDefinition.h" #include "previewmaterial.h" -#include "textures/PreviewLayerCoverage.h" -#include "textures/PreviewLayerLook.h" -#include "TexturesMixPreviewRenderer.h" #include "textures/DialogTexturesLayer.h" +#include "TexturesMixPreviewRenderer.h" +#include "TextureLayerCoveragePreviewRenderer.h" +#include "TextureLayerAspectPreviewRenderer.h" MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm) { @@ -35,11 +35,11 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui form_helper->setExploreButton(ui->button_explore); form_helper->setRenderButton(ui->button_render); - preview_layer_coverage = new PreviewLayerCoverage(); + preview_layer_coverage = new TextureLayerCoveragePreviewRenderer(); preview_layer_coverage->setTextures(textures); form_helper->addPreview(ui->preview_coverage, preview_layer_coverage); - preview_layer_look = new PreviewLayerLook(); + preview_layer_look = new TextureLayerAspectPreviewRenderer(); preview_layer_look->setTextures(textures); form_helper->addPreview(ui->preview_texture, preview_layer_look); @@ -135,6 +135,7 @@ void MainTexturesForm::updateLocalDataFromScenery() { DesktopScenery::getCurrent()->getTextures(textures); + preview_layer_coverage->setTerrain(DesktopScenery::getCurrent()->getTerrain()); preview_cumul->setTerrain(DesktopScenery::getCurrent()->getTerrain()); } diff --git a/src/interface/desktop/textures/maintexturesform.h b/src/interface/desktop/textures/maintexturesform.h index db5ea85..917a189 100644 --- a/src/interface/desktop/textures/maintexturesform.h +++ b/src/interface/desktop/textures/maintexturesform.h @@ -40,8 +40,8 @@ private: TexturesDefinition* textures; FreeFormHelper* form_helper; FreeLayerHelper* layer_helper; - PreviewLayerCoverage* preview_layer_coverage; - PreviewLayerLook* preview_layer_look; + TextureLayerCoveragePreviewRenderer* preview_layer_coverage; + TextureLayerAspectPreviewRenderer* preview_layer_look; TexturesMixPreviewRenderer* preview_cumul; }; diff --git a/src/render/preview/TextureLayerAspectPreviewRenderer.cpp b/src/render/preview/TextureLayerAspectPreviewRenderer.cpp new file mode 100644 index 0000000..b99329f --- /dev/null +++ b/src/render/preview/TextureLayerAspectPreviewRenderer.cpp @@ -0,0 +1,51 @@ +#include "TextureLayerAspectPreviewRenderer.h" + +#include "Scenery.h" +#include "BasePreview.h" +#include "TexturesRenderer.h" + +TextureLayerAspectPreviewRenderer::TextureLayerAspectPreviewRenderer(): + Base2dPreviewRenderer() +{ + textures = NULL; + + render_quality = 3; +} + +void TextureLayerAspectPreviewRenderer::setTextures(TexturesDefinition* textures) +{ + this->textures = textures; +} + +void TextureLayerAspectPreviewRenderer::setLayer(int layer) +{ + this->layer = layer; +} + +void TextureLayerAspectPreviewRenderer::bindEvent(BasePreview* preview) +{ + preview->addOsd(QString("geolocation")); + + 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 TextureLayerAspectPreviewRenderer::updateEvent() +{ + Base2dPreviewRenderer::updateEvent(); + + if (textures) + { + getScenery()->setTextures(textures); + } + + disableAtmosphere(); + disableClouds(); +} + +Color TextureLayerAspectPreviewRenderer::getColor2D(double x, double y, double) +{ + TexturesRenderer* textures_renderer = getTexturesRenderer(); + + return textures_renderer->applyToTerrain(x, y).final_color; +} diff --git a/src/interface/desktop/textures/PreviewLayerCoverage.h b/src/render/preview/TextureLayerAspectPreviewRenderer.h similarity index 50% rename from src/interface/desktop/textures/PreviewLayerCoverage.h rename to src/render/preview/TextureLayerAspectPreviewRenderer.h index 2e983d1..9e7ac59 100644 --- a/src/interface/desktop/textures/PreviewLayerCoverage.h +++ b/src/render/preview/TextureLayerAspectPreviewRenderer.h @@ -1,15 +1,17 @@ -#ifndef EDITING_TEXTURES_PREVIEWLAYERCOVERAGE_H -#define EDITING_TEXTURES_PREVIEWLAYERCOVERAGE_H +#ifndef TEXTURELAYERASPECTPREVIEWRENDERER_H +#define TEXTURELAYERASPECTPREVIEWRENDERER_H -#include "desktop_global.h" +#include "preview_global.h" #include "Base2dPreviewRenderer.h" -class PreviewLayerCoverage : public Base2dPreviewRenderer +namespace paysages { +namespace preview { + +class PREVIEWSHARED_EXPORT TextureLayerAspectPreviewRenderer: public Base2dPreviewRenderer { public: - explicit PreviewLayerCoverage(): - Base2dPreviewRenderer(),textures(0){} + TextureLayerAspectPreviewRenderer(); void setTextures(TexturesDefinition* textures); void setLayer(int layer); @@ -24,4 +26,7 @@ private: int layer; }; -#endif +} +} + +#endif // TEXTURELAYERASPECTPREVIEWRENDERER_H diff --git a/src/render/preview/TextureLayerCoveragePreviewRenderer.cpp b/src/render/preview/TextureLayerCoveragePreviewRenderer.cpp new file mode 100644 index 0000000..305a422 --- /dev/null +++ b/src/render/preview/TextureLayerCoveragePreviewRenderer.cpp @@ -0,0 +1,59 @@ +#include "TextureLayerCoveragePreviewRenderer.h" + +#include "Scenery.h" +#include "BasePreview.h" +#include "TexturesRenderer.h" + +TextureLayerCoveragePreviewRenderer::TextureLayerCoveragePreviewRenderer(): + Base2dPreviewRenderer() +{ + textures = NULL; + + render_quality = 3; +} + +void TextureLayerCoveragePreviewRenderer::setTextures(TexturesDefinition* textures) +{ + this->textures = textures; +} + +void TextureLayerCoveragePreviewRenderer::setTerrain(TerrainDefinition *terrain) +{ + getScenery()->setTerrain(terrain); +} + +void TextureLayerCoveragePreviewRenderer::setLayer(int layer) +{ + this->layer = layer; +} + +void TextureLayerCoveragePreviewRenderer::bindEvent(BasePreview* preview) +{ + preview->addOsd(QString("geolocation")); + + 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 TextureLayerCoveragePreviewRenderer::updateEvent() +{ + Base2dPreviewRenderer::updateEvent(); + + if (textures) + { + getScenery()->setTextures(textures); + } + + disableAtmosphere(); + disableClouds(); +} + +Color TextureLayerCoveragePreviewRenderer::getColor2D(double x, double y, double) +{ + TexturesRenderer* textures_renderer = getTexturesRenderer(); + TerrainRenderer* terrain_renderer = getTerrainRenderer(); + + double presence = textures_renderer->getBasePresence(layer, terrain_renderer->getResult(x, y, 1, 0)); + + return Color(presence, presence, presence); +} diff --git a/src/render/preview/TextureLayerCoveragePreviewRenderer.h b/src/render/preview/TextureLayerCoveragePreviewRenderer.h new file mode 100644 index 0000000..7382c18 --- /dev/null +++ b/src/render/preview/TextureLayerCoveragePreviewRenderer.h @@ -0,0 +1,33 @@ +#ifndef TEXTURELAYERCOVERAGEPREVIEWRENDERER_H +#define TEXTURELAYERCOVERAGEPREVIEWRENDERER_H + +#include "preview_global.h" + +#include "Base2dPreviewRenderer.h" + +namespace paysages { +namespace preview { + +class PREVIEWSHARED_EXPORT TextureLayerCoveragePreviewRenderer: public Base2dPreviewRenderer +{ +public: + TextureLayerCoveragePreviewRenderer(); + + void setTextures(TexturesDefinition* textures); + void setTerrain(TerrainDefinition* terrain); + void setLayer(int layer); + +protected: + virtual void bindEvent(BasePreview* preview); + virtual void updateEvent(); + virtual Color getColor2D(double x, double y, double scaling); + +private: + TexturesDefinition* textures; + int layer; +}; + +} +} + +#endif // TEXTURELAYERCOVERAGEPREVIEWRENDERER_H diff --git a/src/render/preview/TexturesMixPreviewRenderer.h b/src/render/preview/TexturesMixPreviewRenderer.h index 837cac9..3fafbb8 100644 --- a/src/render/preview/TexturesMixPreviewRenderer.h +++ b/src/render/preview/TexturesMixPreviewRenderer.h @@ -18,9 +18,9 @@ public: void setLayer(int layer); protected: - virtual void bindEvent(BasePreview* preview); - virtual void updateEvent(); - virtual Color getColor2D(double x, double y, double scaling); + virtual void bindEvent(BasePreview* preview) override; + virtual void updateEvent() override; + virtual Color getColor2D(double x, double y, double scaling) override; private: int layer; diff --git a/src/render/preview/preview.pro b/src/render/preview/preview.pro index b7710de..f06940d 100644 --- a/src/render/preview/preview.pro +++ b/src/render/preview/preview.pro @@ -24,7 +24,9 @@ SOURCES += Base2dPreviewRenderer.cpp \ WaterAspectPreviewRenderer.cpp \ TerrainShapePreviewRenderer.cpp \ SceneryTopDownPreviewRenderer.cpp \ - TexturesMixPreviewRenderer.cpp + TexturesMixPreviewRenderer.cpp \ + TextureLayerCoveragePreviewRenderer.cpp \ + TextureLayerAspectPreviewRenderer.cpp HEADERS += Base2dPreviewRenderer.h\ preview_global.h \ @@ -39,7 +41,9 @@ HEADERS += Base2dPreviewRenderer.h\ WaterAspectPreviewRenderer.h \ TerrainShapePreviewRenderer.h \ SceneryTopDownPreviewRenderer.h \ - TexturesMixPreviewRenderer.h + TexturesMixPreviewRenderer.h \ + TextureLayerCoveragePreviewRenderer.h \ + TextureLayerAspectPreviewRenderer.h unix:!symbian { maemo5 { diff --git a/src/render/preview/preview_global.h b/src/render/preview/preview_global.h index 483026b..cc589b5 100644 --- a/src/render/preview/preview_global.h +++ b/src/render/preview/preview_global.h @@ -24,6 +24,8 @@ namespace preview { class WaterAspectPreviewRenderer; class TerrainShapePreviewRenderer; class TexturesMixPreviewRenderer; + class TextureLayerCoveragePreviewRenderer; + class TextureLayerAspectPreviewRenderer; } } using namespace paysages::preview;