From 4a39eda2dc18efc58f7b1fec0f0aae474647ea1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 10 Nov 2013 17:04:38 +0100 Subject: [PATCH] WIP on fluid medium traversal --- src/editing/editing.pro | 6 + src/editing/editing_global.h | 2 + src/editing/formrender.cpp | 5 +- src/render/software/FluidMediumTraversal.cpp | 20 +++ src/render/software/SoftwareRenderer.cpp | 20 ++- src/render/software/SoftwareRenderer.h | 4 +- src/rendering/Scenery.cpp | 5 + src/rendering/Scenery.h | 2 + src/rendering/renderer.cpp | 126 +++++++++++-------- src/rendering/renderer.h | 8 +- src/rendering/terrain/ter_render.cpp | 2 +- src/rendering/water/wat_render.cpp | 2 +- 12 files changed, 140 insertions(+), 62 deletions(-) diff --git a/src/editing/editing.pro b/src/editing/editing.pro index a8b4ce0..de3ef27 100644 --- a/src/editing/editing.pro +++ b/src/editing/editing.pro @@ -161,6 +161,12 @@ else:unix: LIBS += -L$$OUT_PWD/../definition/ -lpaysages_definition INCLUDEPATH += $$PWD/../definition DEPENDPATH += $$PWD/../definition +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../render/software/release/ -lpaysages_render_software +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../render/software/debug/ -lpaysages_render_software +else:unix: LIBS += -L$$OUT_PWD/../render/software/ -lpaysages_render_software +INCLUDEPATH += $$PWD/../render/software +DEPENDPATH += $$PWD/../render/software + win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../render/opengl/release/ -lpaysages_render_opengl else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../render/opengl/debug/ -lpaysages_render_opengl else:unix: LIBS += -L$$OUT_PWD/../render/opengl/ -lpaysages_render_opengl diff --git a/src/editing/editing_global.h b/src/editing/editing_global.h index c2a39ad..09e2e46 100644 --- a/src/editing/editing_global.h +++ b/src/editing/editing_global.h @@ -6,11 +6,13 @@ namespace paysages namespace system {} namespace basics {} namespace definition {} + namespace software {} namespace opengl {} } using namespace paysages::system; using namespace paysages::basics; using namespace paysages::definition; +using namespace paysages::software; using namespace paysages::opengl; #endif // EDITING_GLOBAL_H diff --git a/src/editing/formrender.cpp b/src/editing/formrender.cpp index 5a79478..3f00179 100644 --- a/src/editing/formrender.cpp +++ b/src/editing/formrender.cpp @@ -12,6 +12,7 @@ #include "rendering/water/public.h" #include "Scenery.h" #include "PackStream.h" +#include "SoftwareRenderer.h" /**************** Previews ****************/ class PreviewRenderLandscape : public BasePreview @@ -182,7 +183,7 @@ void FormRender::startQuickRender() { rendererDelete(_renderer); } - _renderer = sceneryCreateStandardRenderer(); + _renderer = new SoftwareRenderer(); _renderer_inited = true; DialogRender* dialog = new DialogRender(this, _renderer); @@ -198,7 +199,7 @@ void FormRender::startRender() { rendererDelete(_renderer); } - _renderer = sceneryCreateStandardRenderer(); + _renderer = new SoftwareRenderer(); _renderer_inited = true; DialogRender* dialog = new DialogRender(this, _renderer); diff --git a/src/render/software/FluidMediumTraversal.cpp b/src/render/software/FluidMediumTraversal.cpp index 7c8bb30..9250dc1 100644 --- a/src/render/software/FluidMediumTraversal.cpp +++ b/src/render/software/FluidMediumTraversal.cpp @@ -4,3 +4,23 @@ FluidMediumTraversal::FluidMediumTraversal(SoftwareRenderer* renderer): renderer(renderer) { } + +FluidMediumTraversal::~FluidMediumTraversal() +{ +} + +void FluidMediumTraversal::setCollector(FluidMediumCollector *collector) +{ +} + +void FluidMediumTraversal::getTraversedMedia(std::vector &media, const SpaceCoordinates &start, const SpaceCoordinates &end) +{ +} + +void FluidMediumTraversal::collectHalfLine(const SpaceCoordinates &start, const Vector3 &direction) +{ +} + +void FluidMediumTraversal::collectSegment(const SpaceCoordinates &start, const SpaceCoordinates &end) +{ +} diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index 991240a..3463931 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -1,14 +1,30 @@ #include "SoftwareRenderer.h" +#include "Scenery.h" #include "FluidMediumTraversal.h" -SoftwareRenderer::SoftwareRenderer(Scenery* scenery): - scenery(scenery) +SoftwareRenderer::SoftwareRenderer(Scenery* scenery) { fluid_medium = new FluidMediumTraversal(this); + + if (scenery) + { + this->scenery = scenery; + } + else + { + this->scenery = Scenery::getCurrent(); + } + this->scenery->bindToRenderer(this); } SoftwareRenderer::~SoftwareRenderer() { delete fluid_medium; } + +Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color) +{ + // TODO + return color; +} diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index fa204ec..0f19a70 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -19,11 +19,13 @@ class SOFTWARESHARED_EXPORT SoftwareRenderer: public Renderer { public: - SoftwareRenderer(Scenery* scenery); + SoftwareRenderer(Scenery* scenery=0); virtual ~SoftwareRenderer(); inline Scenery* getScenery() const {return scenery;} + virtual Color applyMediumTraversal(Vector3 location, Color color); + private: Scenery* scenery; FluidMediumTraversal* fluid_medium; diff --git a/src/rendering/Scenery.cpp b/src/rendering/Scenery.cpp index c8fde98..e0a71f0 100644 --- a/src/rendering/Scenery.cpp +++ b/src/rendering/Scenery.cpp @@ -39,6 +39,11 @@ Scenery::~Scenery() WaterDefinitionClass.destroy(water); } +Scenery* Scenery::getCurrent() +{ + return _main_scenery; +} + void Scenery::save(PackStream* stream) { BaseDefinition::save(stream); diff --git a/src/rendering/Scenery.h b/src/rendering/Scenery.h index 64a63c1..5cdad94 100644 --- a/src/rendering/Scenery.h +++ b/src/rendering/Scenery.h @@ -30,6 +30,8 @@ public: Scenery(); virtual ~Scenery(); + static Scenery* getCurrent(); + virtual void save(PackStream* stream); virtual void load(PackStream* stream); diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 3c8e1a6..784f3fb 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -117,69 +117,89 @@ static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vecto return result; } -static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color) + + + + + +Renderer::Renderer() { - color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final; - color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location); + RenderParams params = {1, 1, 1, 5}; + + render_quality = 5; + render_width = 1; + render_height = 1; + render_interrupt = 0; + render_progress = 0.0; + is_rendering = 0; + render_camera = cameraCreateDefinition(); + render_area = renderCreateArea(this); + + renderSetParams(render_area, params); + + addRenderProgress = _addRenderProgress; + getCameraLocation = _getCameraLocation; + getCameraDirection = _getCameraDirection; + getPrecision = _getPrecision; + projectPoint = _projectPoint; + unprojectPoint = _unprojectPoint; + pushTriangle = _pushTriangle; + pushQuad = _pushQuad; + pushDisplacedTriangle = _pushDisplacedTriangle; + pushDisplacedQuad = _pushDisplacedQuad; + + rayWalking = _rayWalking; + + applyLightingToSurface = _applyLightingToSurface; + + lighting = lightingManagerCreate(); + + atmosphere = (AtmosphereRenderer*)AtmosphereRendererClass.create(); + clouds = (CloudsRenderer*)CloudsRendererClass.create(); + terrain = (TerrainRenderer*)TerrainRendererClass.create(); + textures = (TexturesRenderer*)TexturesRendererClass.create(); + water = (WaterRenderer*)WaterRendererClass.create(); +} + +Renderer::~Renderer() +{ + cameraDeleteDefinition(render_camera); + lightingManagerDelete(lighting); + + AtmosphereRendererClass.destroy(atmosphere); + CloudsRendererClass.destroy(clouds); + TerrainRendererClass.destroy(terrain); + TexturesRendererClass.destroy(textures); + WaterRendererClass.destroy(water); + + renderDeleteArea(render_area); +} + +Color Renderer::applyMediumTraversal(Vector3 location, Color color) +{ + color = atmosphere->applyAerialPerspective(this, location, color).final; + color = clouds->getColor(this, color, getCameraLocation(this, location), location); return color; } + + + + + + + + + +// Old API compat + Renderer* rendererCreate() { - Renderer* result = new Renderer; - RenderParams params = {1, 1, 1, 5}; - - result->render_quality = 5; - result->render_width = 1; - result->render_height = 1; - result->render_interrupt = 0; - result->render_progress = 0.0; - result->is_rendering = 0; - result->render_camera = cameraCreateDefinition(); - result->render_area = renderCreateArea(result); - - renderSetParams(result->render_area, params); - - result->addRenderProgress = _addRenderProgress; - result->getCameraLocation = _getCameraLocation; - result->getCameraDirection = _getCameraDirection; - result->getPrecision = _getPrecision; - result->projectPoint = _projectPoint; - result->unprojectPoint = _unprojectPoint; - result->pushTriangle = _pushTriangle; - result->pushQuad = _pushQuad; - result->pushDisplacedTriangle = _pushDisplacedTriangle; - result->pushDisplacedQuad = _pushDisplacedQuad; - - result->rayWalking = _rayWalking; - - result->applyLightingToSurface = _applyLightingToSurface; - result->applyMediumTraversal = _applyMediumTraversal; - - result->lighting = lightingManagerCreate(); - - result->atmosphere = (AtmosphereRenderer*)AtmosphereRendererClass.create(); - result->clouds = (CloudsRenderer*)CloudsRendererClass.create(); - result->terrain = (TerrainRenderer*)TerrainRendererClass.create(); - result->textures = (TexturesRenderer*)TexturesRendererClass.create(); - result->water = (WaterRenderer*)WaterRendererClass.create(); - - return result; + return new Renderer(); } void rendererDelete(Renderer* renderer) { - cameraDeleteDefinition(renderer->render_camera); - lightingManagerDelete(renderer->lighting); - - AtmosphereRendererClass.destroy(renderer->atmosphere); - CloudsRendererClass.destroy(renderer->clouds); - TerrainRendererClass.destroy(renderer->terrain); - TexturesRendererClass.destroy(renderer->textures); - WaterRendererClass.destroy(renderer->water); - - renderDeleteArea(renderer->render_area); - delete renderer; } diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h index 71e4df3..512e6a9 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -14,8 +14,12 @@ class TexturesRenderer; class CloudsRenderer; class WaterRenderer; -struct Renderer +class Renderer { +public: + Renderer(); + virtual ~Renderer(); + /* Render base configuration */ int render_quality; int render_width; @@ -40,7 +44,7 @@ struct Renderer /* Shortcuts */ Color(*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material); - Color(*applyMediumTraversal)(Renderer* renderer, Vector3 location, Color color); + virtual Color applyMediumTraversal(Vector3 location, Color color); /* Scenery related */ RayCastingResult(*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds); diff --git a/src/rendering/terrain/ter_render.cpp b/src/rendering/terrain/ter_render.cpp index c8b036b..e5a59d3 100644 --- a/src/rendering/terrain/ter_render.cpp +++ b/src/rendering/terrain/ter_render.cpp @@ -148,7 +148,7 @@ static Color _realGetFinalColor(Renderer* renderer, Vector3 location, double pre { /* TODO Restore precision control */ TexturesResult textures = renderer->textures->applyToTerrain(renderer, location.x, location.z); - return renderer->applyMediumTraversal(renderer, textures.final_location, textures.final_color); + return renderer->applyMediumTraversal(textures.final_location, textures.final_color); } static RayCastingResult _fakeCastRay(Renderer* renderer, Vector3 start, Vector3 direction) diff --git a/src/rendering/water/wat_render.cpp b/src/rendering/water/wat_render.cpp index 034d5b7..be0af3c 100644 --- a/src/rendering/water/wat_render.cpp +++ b/src/rendering/water/wat_render.cpp @@ -290,7 +290,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z) colorMask(&color, &foam); /* Bring color to the camera */ - color = renderer->applyMediumTraversal(renderer, location, color); + color = renderer->applyMediumTraversal(location, color); result.base = definition->material._rgb; result.final = color;