diff --git a/src/basics/basics.pro b/src/basics/basics.pro new file mode 100644 index 0000000..9574c78 --- /dev/null +++ b/src/basics/basics.pro @@ -0,0 +1,26 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-10-29T17:15:02 +# +#------------------------------------------------- + +QT -= gui + +TARGET = basics +TEMPLATE = lib + +DEFINES += BASICS_LIBRARY + +SOURCES += + +HEADERS +=\ + basics_global.h + +unix:!symbian { + maemo5 { + target.path = /opt/usr/lib + } else { + target.path = /usr/lib + } + INSTALLS += target +} diff --git a/src/basics/basics_global.h b/src/basics/basics_global.h new file mode 100644 index 0000000..53250b6 --- /dev/null +++ b/src/basics/basics_global.h @@ -0,0 +1,33 @@ +#ifndef BASICS_GLOBAL_H +#define BASICS_GLOBAL_H + +/* Shared object helpers */ +#ifdef __cplusplus +# include +#else +# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) +# define Q_DECL_EXPORT __declspec(dllexport) +# define Q_DECL_IMPORT __declspec(dllimport) +# else +# define Q_DECL_EXPORT +# define Q_DECL_IMPORT +# endif +#endif +#if defined(DEFINITION_LIBRARY) +# define BASICSSHARED_EXPORT Q_DECL_EXPORT +#else +# define BASICSSHARED_EXPORT Q_DECL_IMPORT +#endif + +/* Namespace using */ +#ifdef __cplusplus +namespace paysages +{ + namespace basics {} +} +using namespace paysages::system; +#endif + +/* Global imports */ + +#endif // BASICS_GLOBAL_H diff --git a/src/controlling/main.c b/src/controlling/main.c index 8e8d87f..92f5786 100644 --- a/src/controlling/main.c +++ b/src/controlling/main.c @@ -5,7 +5,7 @@ #include "rendering/main.h" #include "rendering/render.h" -#include "rendering/scenery.h" +#include "rendering/Scenery.h" void startRender(Renderer* renderer, char* outputpath, RenderParams params) { diff --git a/src/definition/definition.pro b/src/definition/definition.pro new file mode 100644 index 0000000..624b6bd --- /dev/null +++ b/src/definition/definition.pro @@ -0,0 +1,38 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-10-29T14:38:43 +# +#------------------------------------------------- + +QT -= gui + +TARGET = paysages_definition +TEMPLATE = lib + +DEFINES += DEFINITION_LIBRARY + +SOURCES += + +HEADERS +=\ + definition_global.h + +unix:!symbian { + maemo5 { + target.path = /opt/usr/lib + } else { + target.path = /usr/lib + } + INSTALLS += target +} + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ -lpaysages_rendering +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering +else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering +INCLUDEPATH += $$PWD/../rendering +DEPENDPATH += $$PWD/../rendering + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system +else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system +INCLUDEPATH += $$PWD/../system +DEPENDPATH += $$PWD/../system diff --git a/src/definition/definition_global.h b/src/definition/definition_global.h new file mode 100644 index 0000000..a716918 --- /dev/null +++ b/src/definition/definition_global.h @@ -0,0 +1,33 @@ +#ifndef DEFINITION_GLOBAL_H +#define DEFINITION_GLOBAL_H + +/* Shared object helpers */ +#ifdef __cplusplus +# include +#else +# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) +# define Q_DECL_EXPORT __declspec(dllexport) +# define Q_DECL_IMPORT __declspec(dllimport) +# else +# define Q_DECL_EXPORT +# define Q_DECL_IMPORT +# endif +#endif +#if defined(DEFINITION_LIBRARY) +# define DEFINITIONSHARED_EXPORT Q_DECL_EXPORT +#else +# define DEFINITIONSHARED_EXPORT Q_DECL_IMPORT +#endif + +/* Namespace using */ +#ifdef __cplusplus +namespace paysages +{ + namespace definition {} +} +using namespace paysages::system; +#endif + +/* Global imports */ + +#endif // DEFINITION_GLOBAL_H diff --git a/src/editing/common/freeformhelper.cpp b/src/editing/common/freeformhelper.cpp index 6fefe2f..14a9733 100644 --- a/src/editing/common/freeformhelper.cpp +++ b/src/editing/common/freeformhelper.cpp @@ -11,7 +11,7 @@ #include "mainwindow.h" #include "dialogrender.h" #include "dialogexplorer.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "rendering/renderer.h" #include "tools.h" diff --git a/src/editing/common/mainwindow.cpp b/src/editing/common/mainwindow.cpp index dcae771..edd9962 100644 --- a/src/editing/common/mainwindow.cpp +++ b/src/editing/common/mainwindow.cpp @@ -24,7 +24,7 @@ #include "dialogexplorer.h" #include "rendering/main.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "tools.h" MainWindow* MainWindow::_instance = NULL; diff --git a/src/editing/dialogrender.cpp b/src/editing/dialogrender.cpp index 9e6c17e..39211b4 100644 --- a/src/editing/dialogrender.cpp +++ b/src/editing/dialogrender.cpp @@ -12,7 +12,7 @@ #include #include "tools.h" -#include "rendering/scenery.h" +#include "Scenery.h" static DialogRender* _current_dialog; diff --git a/src/editing/formatmosphere.cpp b/src/editing/formatmosphere.cpp index 52e705a..f62df52 100644 --- a/src/editing/formatmosphere.cpp +++ b/src/editing/formatmosphere.cpp @@ -7,7 +7,7 @@ #include #include "rendering/atmosphere/public.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "rendering/renderer.h" static AtmosphereDefinition* _definition; diff --git a/src/editing/formclouds.cpp b/src/editing/formclouds.cpp index 4a47163..bcc243b 100644 --- a/src/editing/formclouds.cpp +++ b/src/editing/formclouds.cpp @@ -3,7 +3,7 @@ #include "rendering/clouds/clo_preview.h" #include "rendering/tools/color.h" #include "rendering/tools/euclid.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "tools.h" diff --git a/src/editing/formrender.cpp b/src/editing/formrender.cpp index 7ae0f3b..7c45976 100644 --- a/src/editing/formrender.cpp +++ b/src/editing/formrender.cpp @@ -6,7 +6,7 @@ #include "inputcamera.h" #include "tools.h" #include "rendering/render.h" -#include "rendering/scenery.h" +#include "Scenery.h" /**************** Previews ****************/ class PreviewRenderLandscape : public BasePreview diff --git a/src/editing/formtextures.cpp b/src/editing/formtextures.cpp index eb2cf33..075e0cb 100644 --- a/src/editing/formtextures.cpp +++ b/src/editing/formtextures.cpp @@ -1,6 +1,6 @@ #include "formtextures.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "tools.h" /**************** Previews ****************/ diff --git a/src/editing/formwater.cpp b/src/editing/formwater.cpp index 330f7d3..2a8238d 100644 --- a/src/editing/formwater.cpp +++ b/src/editing/formwater.cpp @@ -8,7 +8,7 @@ #include "rendering/tools/euclid.h" #include "rendering/tools/lighting.h" #include "rendering/renderer.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "rendering/water/public.h" #include "tools.h" diff --git a/src/editing/terrain/mainterrainform.cpp b/src/editing/terrain/mainterrainform.cpp index 6df0940..49055a5 100644 --- a/src/editing/terrain/mainterrainform.cpp +++ b/src/editing/terrain/mainterrainform.cpp @@ -6,7 +6,7 @@ #include "dialogterrainpainting.h" #include "previewterrainshape.h" #include "tools.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "rendering/textures/public.h" MainTerrainForm::MainTerrainForm(QWidget *parent) : diff --git a/src/editing/terrain/widgetheightmap.cpp b/src/editing/terrain/widgetheightmap.cpp index b54418e..b8fcb58 100644 --- a/src/editing/terrain/widgetheightmap.cpp +++ b/src/editing/terrain/widgetheightmap.cpp @@ -6,7 +6,7 @@ #include #include #include "tools.h" -#include "rendering/scenery.h" +#include "Scenery.h" #define HEIGHTMAP_RESOLUTION 256 diff --git a/src/editing/textures/maintexturesform.cpp b/src/editing/textures/maintexturesform.cpp index 5b81ed2..1c0ebcb 100644 --- a/src/editing/textures/maintexturesform.cpp +++ b/src/editing/textures/maintexturesform.cpp @@ -3,7 +3,7 @@ #include "../common/freeformhelper.h" #include "../common/freelayerhelper.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "previewmaterial.h" #include "editing/textures/PreviewLayerCoverage.h" #include "editing/textures/PreviewLayerLook.h" diff --git a/src/editing/widgetexplorer.cpp b/src/editing/widgetexplorer.cpp index 22a3fd1..6c8f8ce 100644 --- a/src/editing/widgetexplorer.cpp +++ b/src/editing/widgetexplorer.cpp @@ -3,10 +3,10 @@ #include #include #include -#include +#include #include #include -#include "rendering/scenery.h" +#include "Scenery.h" #include "rendering/tools/euclid.h" #include "../exploring/main.h" #include "explorerchunkterrain.h" diff --git a/src/paysages.pro b/src/paysages.pro index 8a35e55..96feac6 100644 --- a/src/paysages.pro +++ b/src/paysages.pro @@ -6,12 +6,15 @@ SUBDIRS = \ rendering \ exploring \ editing \ - controlling + controlling \ + definition \ + basics unix:SUBDIRS += testing rendering.depends = system exploring.depends = rendering +definition.depends = rendering system editing.depends = exploring rendering controlling.depends = rendering unix:testing.depends = rendering diff --git a/src/rendering/Scenery.cpp b/src/rendering/Scenery.cpp new file mode 100644 index 0000000..e6eb76a --- /dev/null +++ b/src/rendering/Scenery.cpp @@ -0,0 +1,312 @@ +#include "Scenery.h" + +#include + +#include "rendering/noise.h" +#include "rendering/terrain/ter_raster.h" + +static Scenery* _main_scenery; +static SceneryCustomDataCallback _custom_save = NULL; +static SceneryCustomDataCallback _custom_load = NULL; +static void* _custom_data = NULL; + +Scenery::Scenery() +{ + atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create(); + camera = cameraCreateDefinition(); + clouds = (CloudsDefinition*)CloudsDefinitionClass.create(); + terrain = (TerrainDefinition*)TerrainDefinitionClass.create(); + textures = (TexturesDefinition*)TexturesDefinitionClass.create(); + water = (WaterDefinition*)WaterDefinitionClass.create(); +} + +Scenery::~Scenery() +{ + AtmosphereDefinitionClass.destroy(atmosphere); + cameraDeleteDefinition(camera); + CloudsDefinitionClass.destroy(clouds); + TerrainDefinitionClass.destroy(terrain); + TexturesDefinitionClass.destroy(textures); + WaterDefinitionClass.destroy(water); +} + +void Scenery::save(PackStream* stream) +{ + AtmosphereDefinitionClass.save(stream, atmosphere); + cameraSave(stream, camera); + CloudsDefinitionClass.save(stream, clouds); + TerrainDefinitionClass.save(stream, terrain); + TexturesDefinitionClass.save(stream, textures); + WaterDefinitionClass.save(stream, water); +} + +void Scenery::load(PackStream* stream) +{ + AtmosphereDefinitionClass.load(stream, atmosphere); + cameraLoad(stream, camera); + CloudsDefinitionClass.load(stream, clouds); + TerrainDefinitionClass.load(stream, terrain); + TexturesDefinitionClass.load(stream, textures); + WaterDefinitionClass.load(stream, water); +} + +void Scenery::autoPreset(int seed) +{ + if (!seed) + { + seed = time(NULL); + } + srand(seed); + + terrainAutoPreset(terrain, TERRAIN_PRESET_STANDARD); + texturesAutoPreset(textures, TEXTURES_PRESET_FULL); + atmosphereAutoPreset(atmosphere, ATMOSPHERE_PRESET_CLEAR_DAY); + waterAutoPreset(water, WATER_PRESET_LAKE); + cloudsAutoPreset(clouds, CLOUDS_PRESET_PARTLY_CLOUDY); + + cameraSetLocation(camera, VECTOR_ZERO); + cameraSetTarget(camera, VECTOR_NORTH); + cameraValidateDefinition(camera, 1); +} + +void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere) +{ + AtmosphereDefinitionClass.copy(atmosphere, this->atmosphere); +} + +void Scenery::getAtmosphere(AtmosphereDefinition* atmosphere) +{ + AtmosphereDefinitionClass.copy(this->atmosphere, atmosphere); +} + +void Scenery::setCamera(CameraDefinition* camera) +{ + cameraCopyDefinition(camera, this->camera); +} + +void Scenery::getCamera(CameraDefinition* camera) +{ + cameraCopyDefinition(this->camera, camera); +} + +void Scenery::setClouds(CloudsDefinition* clouds) +{ + CloudsDefinitionClass.copy(clouds, this->clouds); +} + +void Scenery::getClouds(CloudsDefinition* clouds) +{ + CloudsDefinitionClass.copy(this->clouds, clouds); +} + +void Scenery::setTerrain(TerrainDefinition* terrain) +{ + TerrainDefinitionClass.copy(terrain, this->terrain); +} + +void Scenery::getTerrain(TerrainDefinition* terrain) +{ + TerrainDefinitionClass.copy(this->terrain, terrain); +} + +void Scenery::setTextures(TexturesDefinition* textures) +{ + TexturesDefinitionClass.copy(textures, this->textures); +} + +void Scenery::getTextures(TexturesDefinition* textures) +{ + TexturesDefinitionClass.copy(this->textures, textures); +} + +void Scenery::setWater(WaterDefinition* water) +{ + WaterDefinitionClass.copy(water, this->water); +} + +void Scenery::getWater(WaterDefinition* water) +{ + WaterDefinitionClass.copy(this->water, water); +} + +void Scenery::bindToRenderer(Renderer* renderer) +{ + cameraCopyDefinition(camera, renderer->render_camera); + AtmosphereRendererClass.bind(renderer, atmosphere); + TerrainRendererClass.bind(renderer, terrain); + TexturesRendererClass.bind(renderer, textures); + CloudsRendererClass.bind(renderer, clouds); + WaterRendererClass.bind(renderer, water); +} + +// Transitional C-API + +void sceneryInit() +{ + noiseInit(); + _main_scenery = new Scenery(); +} + +void sceneryQuit() +{ + delete _main_scenery; + noiseQuit(); +} + +void sceneryAutoPreset(int seed) +{ + _main_scenery->autoPreset(seed); +} + +void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data) +{ + _custom_save = callback_save; + _custom_load = callback_load; + _custom_data = data; +} + +void scenerySave(PackStream* stream) +{ + noiseSave(stream); + + _main_scenery->save(stream); + + if (_custom_save) + { + _custom_save(stream, _custom_data); + } +} + +void sceneryLoad(PackStream* stream) +{ + /* TODO Use intermediary definitions ? */ + + noiseLoad(stream); + + _main_scenery->load(stream); + + if (_custom_load) + { + _custom_load(stream, _custom_data); + } +} + +void scenerySetAtmosphere(AtmosphereDefinition* atmosphere) +{ + _main_scenery->setAtmosphere(atmosphere); +} + +void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere) +{ + _main_scenery->getAtmosphere(atmosphere); +} + +void scenerySetCamera(CameraDefinition* camera) +{ + _main_scenery->setCamera(camera); +} + +void sceneryGetCamera(CameraDefinition* camera) +{ + _main_scenery->getCamera(camera); +} + +void scenerySetClouds(CloudsDefinition* clouds) +{ + _main_scenery->setClouds(clouds); +} + +void sceneryGetClouds(CloudsDefinition* clouds) +{ + _main_scenery->getClouds(clouds); +} + +void scenerySetTerrain(TerrainDefinition* terrain) +{ + _main_scenery->setTerrain(terrain); +} + +void sceneryGetTerrain(TerrainDefinition* terrain) +{ + _main_scenery->getTerrain(terrain); +} + +TerrainDefinition* sceneryGetTerrainDirect() +{ + return _main_scenery->getTerrain(); +} + +void scenerySetTextures(TexturesDefinition* textures) +{ + _main_scenery->setTextures(textures); +} + +void sceneryGetTextures(TexturesDefinition* textures) +{ + _main_scenery->getTextures(textures); +} + +void scenerySetWater(WaterDefinition* water) +{ + _main_scenery->setWater(water); +} + +void sceneryGetWater(WaterDefinition* water) +{ + _main_scenery->getWater(water); +} + +static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int) +{ + RayCastingResult result; + Color sky_color; + + result = renderer->terrain->castRay(renderer, location, direction); + if (!result.hit) + { + sky_color = renderer->atmosphere->getSkyColor(renderer, direction).final; + + result.hit = 1; + result.hit_location = v3Add(location, v3Scale(direction, 1000.0)); + result.hit_color = renderer->clouds->getColor(renderer, sky_color, location, result.hit_location); + } + + return result; +} + +static double _getPrecision(Renderer* renderer, Vector3 location) +{ + Vector3 projected; + + projected = cameraProject(renderer->render_camera, location); + projected.x += 1.0; + //projected.y += 1.0; + + return v3Norm(v3Sub(cameraUnproject(renderer->render_camera, projected), location)); // / (double)render_quality; +} + +Renderer* sceneryCreateStandardRenderer() +{ + Renderer* result; + + result = rendererCreate(); + + result->rayWalking = _rayWalking; + result->getPrecision = _getPrecision; + + sceneryBindRenderer(result); + + return result; +} + +void sceneryBindRenderer(Renderer* renderer) +{ + _main_scenery->bindToRenderer(renderer); +} + +void sceneryRenderFirstPass(Renderer* renderer) +{ + terrainRenderSurface(renderer); + waterRenderSurface(renderer); + atmosphereRenderSkydome(renderer); +} diff --git a/src/rendering/Scenery.h b/src/rendering/Scenery.h new file mode 100644 index 0000000..bb8a877 --- /dev/null +++ b/src/rendering/Scenery.h @@ -0,0 +1,125 @@ +#ifndef SCENERY_H +#define SCENERY_H + +#include "rendering_global.h" + +#include "rendering/atmosphere/public.h" +#include "rendering/camera.h" +#include "rendering/clouds/public.h" +#include "rendering/terrain/public.h" +#include "rendering/textures/public.h" +#include "rendering/water/public.h" +#include "rendering/tools/pack.h" +#include "rendering/renderer.h" + +#ifdef __cplusplus + +//class AtmosphereDefinition; +//class CameraDefinition; +//class CloudsDefinition; +//class TerrainDefinition; +//class TexturesDefinition; +//class WaterDefinition; +//class PackStream; +//class Renderer; + +namespace paysages { +namespace rendering { + +/** + * @brief Global scenery management + * + * This class contains the whole scenery definition. + */ +class RENDERINGSHARED_EXPORT Scenery +{ +public: + Scenery(); + ~Scenery(); + + void autoPreset(int seed); + + void save(PackStream* stream); + void load(PackStream* stream); + + void setAtmosphere(AtmosphereDefinition* atmosphere); + inline AtmosphereDefinition* getAtmosphere() {return atmosphere;} + void getAtmosphere(AtmosphereDefinition* atmosphere); + + void setCamera(CameraDefinition* camera); + inline CameraDefinition* getCamera() {return camera;} + void getCamera(CameraDefinition* camera); + + void setClouds(CloudsDefinition* clouds); + inline CloudsDefinition* getClouds() {return clouds;} + void getClouds(CloudsDefinition* clouds); + + void setTerrain(TerrainDefinition* terrain); + inline TerrainDefinition* getTerrain() {return terrain;} + void getTerrain(TerrainDefinition* terrain); + + void setTextures(TexturesDefinition* textures); + inline TexturesDefinition* getTextures() {return textures;} + void getTextures(TexturesDefinition* textures); + + void setWater(WaterDefinition* water); + inline WaterDefinition* getWater() {return water;} + void getWater(WaterDefinition* water); + + void bindToRenderer(Renderer* renderer); + +private: + AtmosphereDefinition* atmosphere; + CameraDefinition* camera; + CloudsDefinition* clouds; + TerrainDefinition* terrain; + TexturesDefinition* textures; + WaterDefinition* water; +}; + +} +} + +extern "C" { +#endif + +// Transitional C-API +RENDERINGSHARED_EXPORT void sceneryInit(); +RENDERINGSHARED_EXPORT void sceneryQuit(); + +RENDERINGSHARED_EXPORT void sceneryAutoPreset(int seed); + +typedef void (*SceneryCustomDataCallback)(PackStream* stream, void* data); +RENDERINGSHARED_EXPORT void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data); + +RENDERINGSHARED_EXPORT void scenerySave(PackStream* stream); +RENDERINGSHARED_EXPORT void sceneryLoad(PackStream* stream); + +RENDERINGSHARED_EXPORT void scenerySetAtmosphere(AtmosphereDefinition* atmosphere); +RENDERINGSHARED_EXPORT void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere); + +RENDERINGSHARED_EXPORT void scenerySetCamera(CameraDefinition* camera); +RENDERINGSHARED_EXPORT void sceneryGetCamera(CameraDefinition* camera); + +RENDERINGSHARED_EXPORT void scenerySetClouds(CloudsDefinition* clouds); +RENDERINGSHARED_EXPORT void sceneryGetClouds(CloudsDefinition* clouds); + +RENDERINGSHARED_EXPORT void scenerySetTerrain(TerrainDefinition* terrain); +RENDERINGSHARED_EXPORT void sceneryGetTerrain(TerrainDefinition* terrain); +RENDERINGSHARED_EXPORT TerrainDefinition* sceneryGetTerrainDirect(); + +RENDERINGSHARED_EXPORT void scenerySetTextures(TexturesDefinition* textures); +RENDERINGSHARED_EXPORT void sceneryGetTextures(TexturesDefinition* textures); + +RENDERINGSHARED_EXPORT void scenerySetWater(WaterDefinition* water); +RENDERINGSHARED_EXPORT void sceneryGetWater(WaterDefinition* water); + +RENDERINGSHARED_EXPORT Renderer* sceneryCreateStandardRenderer(); +RENDERINGSHARED_EXPORT void sceneryBindRenderer(Renderer* renderer); +RENDERINGSHARED_EXPORT void sceneryRenderFirstPass(Renderer* renderer); + +#ifdef __cplusplus +} +#endif + +#endif // SCENERY_H diff --git a/src/rendering/camera.c b/src/rendering/camera.c index 2d085a8..b018bf7 100644 --- a/src/rendering/camera.c +++ b/src/rendering/camera.c @@ -3,7 +3,7 @@ #include #include #include "render.h" -#include "scenery.h" +#include "Scenery.h" #include "tools.h" #include "tools/boundingbox.h" @@ -95,6 +95,7 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above) if (check_above) { + /* TODO Don't create a renderer for this ! */ renderer = sceneryCreateStandardRenderer(); terrain_height = renderer->terrain->getHeight(renderer, definition->location.x, definition->location.z, 1) + 0.5; water_height = renderer->water->getHeightInfo(renderer).max_height + 0.5; diff --git a/src/rendering/main.c b/src/rendering/main.c index 9a84d1a..5ef099f 100644 --- a/src/rendering/main.c +++ b/src/rendering/main.c @@ -2,7 +2,7 @@ #include #include "tools/data.h" -#include "scenery.h" +#include "Scenery.h" #include "render.h" #include "main.h" #include "opencl.h" diff --git a/src/rendering/renderer.c b/src/rendering/renderer.c index 56ff890..fccf16b 100644 --- a/src/rendering/renderer.c +++ b/src/rendering/renderer.c @@ -4,7 +4,7 @@ #include "System.h" #include "Thread.h" #include "render.h" -#include "scenery.h" +#include "Scenery.h" #include "tools.h" static RayCastingResult _RAYCASTING_NULL = {0}; diff --git a/src/rendering/rendering.pro b/src/rendering/rendering.pro index e347660..e6d3055 100644 --- a/src/rendering/rendering.pro +++ b/src/rendering/rendering.pro @@ -1,6 +1,5 @@ CONFIG += console CONFIG -= app_bundle -CONFIG -= qt TEMPLATE = lib TARGET = paysages_rendering @@ -12,7 +11,6 @@ INCLUDEPATH += $$PWD/.. SOURCES += main.c \ tools.c \ - scenery.c \ renderer.c \ render.c \ opencl.c \ @@ -64,11 +62,11 @@ SOURCES += main.c \ water/wat_raster.c \ water/wat_preview.c \ water/wat_presets.c \ - water/wat_definition.c + water/wat_definition.c \ + Scenery.cpp HEADERS += \ tools.h \ - scenery.h \ renderer.h \ render.h \ opencl.h \ @@ -110,7 +108,8 @@ HEADERS += \ tools/array.h \ water/public.h \ water/private.h \ - rendering_global.h + rendering_global.h \ + Scenery.h win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system diff --git a/src/rendering/rendering_global.h b/src/rendering/rendering_global.h index 4bc9885..a82fb9c 100644 --- a/src/rendering/rendering_global.h +++ b/src/rendering/rendering_global.h @@ -20,6 +20,15 @@ #endif /* Namespace using */ +#ifdef __cplusplus +namespace paysages +{ + namespace system {} + namespace rendering {} +} +using namespace paysages::system; +using namespace paysages::rendering; +#endif /* Global import */ diff --git a/src/rendering/scenery.c b/src/rendering/scenery.c deleted file mode 100644 index 507a769..0000000 --- a/src/rendering/scenery.c +++ /dev/null @@ -1,246 +0,0 @@ -#include "scenery.h" - -#include -#include "rendering/terrain/ter_raster.h" -#include "rendering/tools.h" -#include "rendering/tools/color.h" -#include "rendering/tools/euclid.h" -#include "rendering/render.h" - -static AtmosphereDefinition* _atmosphere; -static CameraDefinition* _camera; -static CloudsDefinition* _clouds; -static TerrainDefinition* _terrain; -static TexturesDefinition* _textures; -static WaterDefinition* _water; - -static SceneryCustomDataCallback _custom_save = NULL; -static SceneryCustomDataCallback _custom_load = NULL; -static void* _custom_data = NULL; - -void sceneryInit() -{ - noiseInit(); - - _atmosphere = AtmosphereDefinitionClass.create(); - _camera = cameraCreateDefinition(); - _clouds = CloudsDefinitionClass.create(); - _terrain = TerrainDefinitionClass.create(); - _textures = TexturesDefinitionClass.create(); - _water = WaterDefinitionClass.create(); - - _custom_save = NULL; - _custom_load = NULL; - - sceneryAutoPreset(0); -} - -void sceneryQuit() -{ - AtmosphereDefinitionClass.destroy(_atmosphere); - cameraDeleteDefinition(_camera); - CloudsDefinitionClass.destroy(_clouds); - TerrainDefinitionClass.destroy(_terrain); - TexturesDefinitionClass.destroy(_textures); - AtmosphereDefinitionClass.destroy(_water); - - noiseQuit(); -} - -void sceneryAutoPreset(int seed) -{ - if (!seed) - { - seed = time(NULL); - } - srand(seed); - - terrainAutoPreset(_terrain, TERRAIN_PRESET_STANDARD); - texturesAutoPreset(_textures, TEXTURES_PRESET_FULL); - atmosphereAutoPreset(_atmosphere, ATMOSPHERE_PRESET_CLEAR_DAY); - waterAutoPreset(_water, WATER_PRESET_LAKE); - cloudsAutoPreset(_clouds, CLOUDS_PRESET_PARTLY_CLOUDY); - - cameraSetLocation(_camera, VECTOR_ZERO); - cameraSetTarget(_camera, VECTOR_NORTH); - cameraValidateDefinition(_camera, 1); -} - -void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data) -{ - _custom_save = callback_save; - _custom_load = callback_load; - _custom_data = data; -} - -void scenerySave(PackStream* stream) -{ - noiseSave(stream); - AtmosphereDefinitionClass.save(stream, _atmosphere); - cameraSave(stream, _camera); - CloudsDefinitionClass.save(stream, _clouds); - TerrainDefinitionClass.save(stream, _terrain); - TexturesDefinitionClass.save(stream, _textures); - WaterDefinitionClass.save(stream, _water); - - if (_custom_save) - { - _custom_save(stream, _custom_data); - } -} - -void sceneryLoad(PackStream* stream) -{ - /* TODO Use intermediary definitions ? */ - - noiseLoad(stream); - AtmosphereDefinitionClass.load(stream, _atmosphere); - cameraLoad(stream, _camera); - CloudsDefinitionClass.load(stream, _clouds); - TerrainDefinitionClass.load(stream, _terrain); - TexturesDefinitionClass.load(stream, _textures); - WaterDefinitionClass.load(stream, _water); - - if (_custom_load) - { - _custom_load(stream, _custom_data); - } -} - -void scenerySetAtmosphere(AtmosphereDefinition* atmosphere) -{ - AtmosphereDefinitionClass.copy(atmosphere, _atmosphere); -} - -void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere) -{ - AtmosphereDefinitionClass.copy(_atmosphere, atmosphere); -} - -void scenerySetCamera(CameraDefinition* camera) -{ - cameraCopyDefinition(camera, _camera); - cameraValidateDefinition(_camera, 1); -} - -void sceneryGetCamera(CameraDefinition* camera) -{ - cameraCopyDefinition(_camera, camera); -} - -void scenerySetClouds(CloudsDefinition* clouds) -{ - CloudsDefinitionClass.copy(clouds, _clouds); -} - -void sceneryGetClouds(CloudsDefinition* clouds) -{ - CloudsDefinitionClass.copy(_clouds, clouds); -} - -void scenerySetTerrain(TerrainDefinition* terrain) -{ - TerrainDefinitionClass.copy(terrain, _terrain); - - cameraValidateDefinition(_camera, 1); -} - -void sceneryGetTerrain(TerrainDefinition* terrain) -{ - TerrainDefinitionClass.copy(_terrain, terrain); -} - -TerrainDefinition* sceneryGetTerrainDirect() -{ - return _terrain; -} - -void scenerySetTextures(TexturesDefinition* textures) -{ - TexturesDefinitionClass.copy(textures, _textures); - - cameraValidateDefinition(_camera, 1); -} - -void sceneryGetTextures(TexturesDefinition* textures) -{ - TexturesDefinitionClass.copy(_textures, textures); -} - -void scenerySetWater(WaterDefinition* water) -{ - WaterDefinitionClass.copy(water, _water); - - cameraValidateDefinition(_camera, 1); -} - -void sceneryGetWater(WaterDefinition* water) -{ - WaterDefinitionClass.copy(_water, water); -} - -void sceneryRenderFirstPass(Renderer* renderer) -{ - terrainRenderSurface(renderer); - waterRenderSurface(renderer); - atmosphereRenderSkydome(renderer); -} - -/******* Standard renderer *********/ -static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds) -{ - RayCastingResult result; - Color sky_color; - - UNUSED(terrain); - UNUSED(water); - UNUSED(sky); - UNUSED(clouds); - - result = renderer->terrain->castRay(renderer, location, direction); - if (!result.hit) - { - sky_color = renderer->atmosphere->getSkyColor(renderer, direction).final; - - result.hit = 1; - result.hit_location = v3Add(location, v3Scale(direction, 1000.0)); - result.hit_color = renderer->clouds->getColor(renderer, sky_color, location, result.hit_location); - } - - return result; -} - -static double _getPrecision(Renderer* renderer, Vector3 location) -{ - Vector3 projected; - - projected = cameraProject(renderer->render_camera, location); - projected.x += 1.0; - //projected.y += 1.0; - - return v3Norm(v3Sub(cameraUnproject(renderer->render_camera, projected), location)); // / (double)render_quality; -} - -Renderer* sceneryCreateStandardRenderer() -{ - Renderer* result; - - result = rendererCreate(); - - result->rayWalking = _rayWalking; - result->getPrecision = _getPrecision; - - sceneryBindRenderer(result); - - return result; -} - -void sceneryBindRenderer(Renderer* renderer) -{ - cameraCopyDefinition(_camera, renderer->render_camera); - AtmosphereRendererClass.bind(renderer, _atmosphere); - TerrainRendererClass.bind(renderer, _terrain); - TexturesRendererClass.bind(renderer, _textures); - CloudsRendererClass.bind(renderer, _clouds); - WaterRendererClass.bind(renderer, _water); -} diff --git a/src/rendering/scenery.h b/src/rendering/scenery.h deleted file mode 100644 index 7d80198..0000000 --- a/src/rendering/scenery.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _PAYSAGES_SCENERY_H_ -#define _PAYSAGES_SCENERY_H_ - -/* - * Scenery management. - * - * This module handles all scenery components (terrain, water...) definitions and maintains - * a standard renderer. - */ - -#include "rendering_global.h" -#include "tools/pack.h" -#include "atmosphere/public.h" -#include "clouds/public.h" -#include "terrain/public.h" -#include "textures/public.h" -#include "water/public.h" -#include "camera.h" -#include "renderer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*SceneryCustomDataCallback)(PackStream* stream, void* data); - -RENDERINGSHARED_EXPORT void sceneryInit(); -RENDERINGSHARED_EXPORT void sceneryQuit(); - -RENDERINGSHARED_EXPORT void sceneryAutoPreset(int seed); - -RENDERINGSHARED_EXPORT void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data); - -RENDERINGSHARED_EXPORT void scenerySave(PackStream* stream); -RENDERINGSHARED_EXPORT void sceneryLoad(PackStream* stream); - -RENDERINGSHARED_EXPORT void scenerySetAtmosphere(AtmosphereDefinition* atmosphere); -RENDERINGSHARED_EXPORT void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere); - -RENDERINGSHARED_EXPORT void scenerySetCamera(CameraDefinition* camera); -RENDERINGSHARED_EXPORT void sceneryGetCamera(CameraDefinition* camera); - -RENDERINGSHARED_EXPORT void scenerySetClouds(CloudsDefinition* clouds); -RENDERINGSHARED_EXPORT void sceneryGetClouds(CloudsDefinition* clouds); - -RENDERINGSHARED_EXPORT void scenerySetTerrain(TerrainDefinition* terrain); -RENDERINGSHARED_EXPORT void sceneryGetTerrain(TerrainDefinition* terrain); -RENDERINGSHARED_EXPORT TerrainDefinition* sceneryGetTerrainDirect(); - -RENDERINGSHARED_EXPORT void scenerySetTextures(TexturesDefinition* textures); -RENDERINGSHARED_EXPORT void sceneryGetTextures(TexturesDefinition* textures); - -RENDERINGSHARED_EXPORT void scenerySetWater(WaterDefinition* water); -RENDERINGSHARED_EXPORT void sceneryGetWater(WaterDefinition* water); - -RENDERINGSHARED_EXPORT Renderer* sceneryCreateStandardRenderer(); -RENDERINGSHARED_EXPORT void sceneryBindRenderer(Renderer* renderer); -RENDERINGSHARED_EXPORT void sceneryRenderFirstPass(Renderer* renderer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/rendering/textures/tex_definition.c b/src/rendering/textures/tex_definition.c index 945c8ea..faf4e8f 100644 --- a/src/rendering/textures/tex_definition.c +++ b/src/rendering/textures/tex_definition.c @@ -1,5 +1,5 @@ #include "private.h" -#include "scenery.h" +#include "Scenery.h" #include diff --git a/src/rendering/textures/tex_preview.c b/src/rendering/textures/tex_preview.c index 5d80559..1cedd2e 100644 --- a/src/rendering/textures/tex_preview.c +++ b/src/rendering/textures/tex_preview.c @@ -1,7 +1,7 @@ #include "tex_preview.h" #include "private.h" -#include "rendering/scenery.h" +#include "Scenery.h" #include "rendering/tools.h" void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition) diff --git a/src/system/system_global.h b/src/system/system_global.h index a8db430..ef0e386 100644 --- a/src/system/system_global.h +++ b/src/system/system_global.h @@ -28,6 +28,6 @@ namespace paysages using namespace paysages::system; #endif -/* Global import */ +/* Global imports */ #endif // SYSTEM_GLOBAL_H diff --git a/src/testing/test_bruneton.c b/src/testing/test_bruneton.c index 804153d..6055520 100644 --- a/src/testing/test_bruneton.c +++ b/src/testing/test_bruneton.c @@ -1,6 +1,6 @@ #include "testing/common.h" #include "System.h" -#include "rendering/scenery.h" +#include "rendering/Scenery.h" #define OUTPUT_WIDTH 400 #define OUTPUT_HEIGHT 300