Removed Scenery C-API and fixed some problems

This commit is contained in:
Michaël Lemaire 2013-11-13 23:03:02 +01:00
parent 5be3231ab9
commit cdd9ef26a2
32 changed files with 253 additions and 493 deletions

View file

@ -1,5 +1,10 @@
#define COLOR_INLINE_CPP
#ifndef NDEBUG
#include <cmath>
#include <cassert>
#endif
#ifdef COLOR_H
# define METHSPEC inline
#else
@ -99,21 +104,21 @@ METHSPEC void Color::mask(const Color& mask)
METHSPEC double Color::normalize()
{
#ifndef NDEBUG
assert(col->r >= 0.0);
assert(col->g >= 0.0);
assert(col->b >= 0.0);
assert(col->a >= 0.0);
assert(r >= 0.0);
assert(g >= 0.0);
assert(b >= 0.0);
assert(a >= 0.0);
#ifdef isnan
assert(!isnan(col->r));
assert(!isnan(col->g));
assert(!isnan(col->b));
assert(!isnan(col->a));
assert(!isnan(r));
assert(!isnan(g));
assert(!isnan(b));
assert(!isnan(a));
#endif
#ifdef isfinite
assert(isfinite(col->r));
assert(isfinite(col->g));
assert(isfinite(col->b));
assert(isfinite(col->a));
assert(isfinite(r));
assert(isfinite(g));
assert(isfinite(b));
assert(isfinite(a));
#endif
#endif

View file

@ -6,10 +6,18 @@
#include "PackStream.h"
#include "RandomGenerator.h"
#include <cmath>
#include <cstdlib>
#define MAX_LEVEL_COUNT 30
void noiseInit()
/* Global noise state */
void noiseQuit()
{
noiseNaiveQuit();
}
int noiseInit()
{
noiseSimplexInit();
noisePerlinInit();
@ -34,12 +42,13 @@ void noiseInit()
}
printf("%f %f\n", min, max);
noiseDeleteGenerator(noise);*/
atexit(noiseQuit);
return 1;
}
void noiseQuit()
{
noiseNaiveQuit();
}
static int inited = noiseInit();
void noiseSave(PackStream* stream)
{
@ -51,6 +60,8 @@ void noiseLoad(PackStream* stream)
noiseNaiveLoad(stream);
}
/* NoiseGenerator class */
NoiseGenerator::NoiseGenerator()
{
function.algorithm = NOISE_FUNCTION_SIMPLEX;

View file

@ -92,8 +92,6 @@ private:
}
}
BASICSSHARED_EXPORT void noiseInit();
BASICSSHARED_EXPORT void noiseQuit();
BASICSSHARED_EXPORT void noiseSave(PackStream* stream);
BASICSSHARED_EXPORT void noiseLoad(PackStream* stream);

View file

@ -34,3 +34,9 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../definition/debug
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

View file

@ -8,6 +8,7 @@
#include "rendering/renderer.h"
#include "rendering/atmosphere/public.h"
#include "rendering/camera.h"
#include "SoftwareRenderer.h"
#include "Scenery.h"
void startRender(Renderer* renderer, char* outputpath, RenderParams params)
@ -45,7 +46,7 @@ void _previewUpdate(double progress)
int main(int argc, char** argv)
{
Renderer* renderer;
SoftwareRenderer* renderer;
char* conf_file_path = NULL;
RenderParams conf_render_params = {800, 600, 1, 5};
int conf_first_picture = 0;
@ -166,24 +167,16 @@ int main(int argc, char** argv)
for (outputcount = 0; outputcount < conf_first_picture + conf_nb_pictures; outputcount++)
{
AtmosphereDefinition* atmo;
atmo = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
sceneryGetAtmosphere(atmo);
AtmosphereDefinition* atmo = Scenery::getCurrent()->getAtmosphere();
atmo->hour = (int)floor(conf_daytime_start * 24.0);
atmo->minute = (int)floor(fmod(conf_daytime_start, 1.0 / 24.0) * 24.0 * 60.0);
AtmosphereDefinitionClass.validate(atmo);
scenerySetAtmosphere(atmo);
AtmosphereDefinitionClass.destroy(atmo);
CameraDefinition* camera;
CameraDefinition* camera = Scenery::getCurrent()->getCamera();
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};
camera = cameraCreateDefinition();
sceneryGetCamera(camera);
cameraSetLocation(camera, v3Add(cameraGetLocation(camera), step));
scenerySetCamera(camera);
cameraDeleteDefinition(camera);
renderer = sceneryCreateStandardRenderer();
renderer = new SoftwareRenderer(Scenery::getCurrent());
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);
if (outputcount >= conf_first_picture)
@ -192,7 +185,7 @@ int main(int argc, char** argv)
startRender(renderer, outputpath, conf_render_params);
}
rendererDelete(renderer);
delete renderer;
conf_daytime_start += conf_daytime_step;
}

View file

@ -13,7 +13,15 @@ WaterDefinition::WaterDefinition(BaseDefinition* parent):
foam_material = new SurfaceMaterial;
_waves_noise = new NoiseGenerator;
//waterAutoPreset(this, WATER_PRESET_LAKE);
transparency_depth = 0.0;
transparency = 0.0;
reflection = 0.0;
lighting_depth = 0.0;
scaling = 1.0;
waves_height = 0.0;
detail_height = 0.0;
turbulence = 0.0;
foam_coverage = 0.0;
}
WaterDefinition::~WaterDefinition()
@ -111,3 +119,51 @@ void WaterDefinition::validate()
materialValidate(material);
materialValidate(foam_material);
}
void WaterDefinition::applyPreset(WaterPreset preset)
{
_waves_noise->randomizeOffsets();
if (preset == WATER_PRESET_LAKE)
{
transparency = 0.5;
reflection = 0.4;
transparency_depth = 4.0;
material->base = colorToHSL(colorFromValues(0.08, 0.15, 0.2, 1.0));
depth_color->r = 0.0;
depth_color->g = 0.1;
depth_color->b = 0.1;
lighting_depth = 6.0;
scaling = 1.0;
waves_height = 0.8;
detail_height = 0.05;
turbulence = 0.1;
foam_coverage = 0.15;
}
else if (preset == WATER_PRESET_SEA)
{
transparency = 0.4;
reflection = 0.35;
transparency_depth = 3.0;
material->base = colorToHSL(colorFromValues(0.05, 0.18, 0.2, 1.0));
depth_color->r = 0.0;
depth_color->g = 0.18;
depth_color->b = 0.15;
lighting_depth = 4.0;
scaling = 1.5;
waves_height = 1.0;
detail_height = 0.06;
turbulence = 0.3;
foam_coverage = 0.4;
}
depth_color->a = 1.0;
material->base.a = 1.0;
material->reflection = 1.0;
material->shininess = 16.0;
foam_material->base = colorToHSL(colorFromValues(0.8, 0.8, 0.8, 1.0));
foam_material->reflection = 0.1;
foam_material->shininess = 1.5;
validate();
}

View file

@ -8,6 +8,12 @@
namespace paysages {
namespace definition {
typedef enum
{
WATER_PRESET_LAKE,
WATER_PRESET_SEA
} WaterPreset;
class WaterDefinition: public BaseDefinition
{
public:
@ -20,6 +26,8 @@ public:
virtual void copy(BaseDefinition* destination) const override;
virtual void validate() override;
void applyPreset(WaterPreset preset);
public:
double transparency;
double reflection;

View file

@ -14,7 +14,7 @@
#include "dialogexplorer.h"
#include "Scenery.h"
#include "BasePreview.h"
#include "renderer.h"
#include "SoftwareRenderer.h"
#include "camera.h"
#include "tools.h"
@ -232,38 +232,33 @@ void FreeFormHelper::processApplyClicked()
void FreeFormHelper::processExploreClicked()
{
Renderer* renderer;
SoftwareRenderer renderer;
renderer = sceneryCreateStandardRenderer();
emit needAlterRenderer(renderer);
Scenery::getCurrent()->bindToRenderer(&renderer);
emit needAlterRenderer(&renderer);
CameraDefinition* camera = cameraCreateDefinition();
sceneryGetCamera(camera);
Scenery::getCurrent()->getCamera(camera);
DialogExplorer* dialog = new DialogExplorer(_form_widget, camera, false, renderer);
DialogExplorer* dialog = new DialogExplorer(_form_widget, camera, false, &renderer);
dialog->exec();
delete dialog;
rendererDelete(renderer);
cameraDeleteDefinition(camera);
}
void FreeFormHelper::processRenderClicked()
{
Renderer* renderer;
SoftwareRenderer renderer;
renderer = sceneryCreateStandardRenderer();
Scenery::getCurrent()->bindToRenderer(&renderer);
emit needAlterRenderer(&renderer);
emit needAlterRenderer(renderer);
DialogRender* dialog = new DialogRender(_form_widget, renderer);
DialogRender* dialog = new DialogRender(_form_widget, &renderer);
RenderParams params = {400, 300, 1, 3};
dialog->startRender(params);
delete dialog;
rendererDelete(renderer);
}
void FreeFormHelper::processDecimalChange(double value)

View file

@ -126,11 +126,11 @@ MainWindow::MainWindow() :
ui->tool_panel->hide();
//ui->menuBar->hide();
scenerySetCustomDataCallback(MainWindow::guiSaveCallback, MainWindow::guiLoadCallback, this);
Scenery::getCurrent()->setCustomSaveCallbacks(MainWindow::guiSaveCallback, MainWindow::guiLoadCallback, this);
// FIXME AutoPreset has already been called by paysagesInit but we need to redo it here because
// the auto apply on FormRender overwrites the camera. Delete this when the render form is no longer a BaseForm.
sceneryAutoPreset(0);
Scenery::getCurrent()->autoPreset(0);
refreshAll();
}
@ -160,14 +160,11 @@ void MainWindow::refreshAll()
}
// Refresh preview OSD
CameraDefinition* camera = cameraCreateDefinition();
PreviewOsd* osd = PreviewOsd::getInstance(QString("geolocation"));
osd->clearItems();
sceneryGetCamera(camera);
PreviewOsdItem* item = osd->newItem(50, 50);
item->drawCamera(camera);
item->drawCamera(Scenery::getCurrent()->getCamera());
item->setToolTip(QString(tr("Camera")));
cameraDeleteDefinition(camera);
emit refreshed();
}
@ -181,7 +178,7 @@ void MainWindow::fileNew()
{
if (QMessageBox::question(this, tr("Paysages 3D - New scenery"), tr("Do you want to start a new scenery ? Any unsaved changes will be lost."), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
{
sceneryAutoPreset(0);
Scenery::getCurrent()->autoPreset(0);
refreshAll();
}
}
@ -265,7 +262,7 @@ void MainWindow::explore3D()
int result;
camera = cameraCreateDefinition();
sceneryGetCamera(camera);
Scenery::getCurrent()->getCamera(camera);
DialogExplorer* dialog = new DialogExplorer(this, camera, true);
result = dialog->exec();
@ -274,7 +271,7 @@ void MainWindow::explore3D()
if (result == QDialog::Accepted)
{
scenerySetCamera(camera);
Scenery::getCurrent()->setCamera(camera);
refreshAll();
}

View file

@ -75,13 +75,13 @@ FormAtmosphere::FormAtmosphere(QWidget *parent):
void FormAtmosphere::revertConfig()
{
sceneryGetAtmosphere(_definition);
Scenery::getCurrent()->getAtmosphere(_definition);
BaseForm::revertConfig();
}
void FormAtmosphere::applyConfig()
{
scenerySetAtmosphere(_definition);
Scenery::getCurrent()->setAtmosphere(_definition);
BaseForm::applyConfig();
}

View file

@ -125,14 +125,14 @@ FormClouds::~FormClouds()
void FormClouds::revertConfig()
{
sceneryGetClouds(_definition);
Scenery::getCurrent()->getClouds(_definition);
BaseFormLayer::revertConfig();
}
void FormClouds::applyConfig()
{
BaseFormLayer::applyConfig();
scenerySetClouds(_definition);
Scenery::getCurrent()->setClouds(_definition);
}
void FormClouds::layerReadCurrentFrom(void* layer_definition)

View file

@ -64,7 +64,7 @@ protected:
void updateData()
{
sceneryBindRenderer(_renderer);
Scenery::getCurrent()->bindToRenderer(_renderer);
if (!_clouds_enabled)
{
CloudsRendererClass.bind(_renderer, _no_clouds);
@ -170,13 +170,13 @@ void FormRender::loadPack(PackStream* stream)
void FormRender::revertConfig()
{
sceneryGetCamera(_camera);
Scenery::getCurrent()->getCamera(_camera);
BaseForm::revertConfig();
}
void FormRender::applyConfig()
{
scenerySetCamera(_camera);
Scenery::getCurrent()->setCamera(_camera);
BaseForm::applyConfig();
}

View file

@ -13,8 +13,6 @@ public:
PreviewTexturesCoverage(QWidget* parent, TexturesLayerDefinition* layer) : BasePreview(parent)
{
_terrain = (TerrainDefinition*) TerrainDefinitionClass.create();
_renderer = rendererCreate();
_renderer->render_quality = 3;
@ -46,8 +44,7 @@ protected:
void updateData()
{
sceneryGetTerrain(_terrain);
TerrainRendererClass.bind(_renderer, _terrain);
TerrainRendererClass.bind(_renderer, Scenery::getCurrent()->getTerrain());
//TexturesDefinitionClass.copy(_original_layer, _preview_layer);
}
@ -56,7 +53,6 @@ private:
Renderer* _renderer;
TexturesLayerDefinition* _original_layer;
TexturesDefinition* _preview_definition;
TerrainDefinition* _terrain;
};
class PreviewTexturesColor : public BasePreview
@ -142,14 +138,14 @@ FormTextures::~FormTextures()
void FormTextures::revertConfig()
{
sceneryGetTextures(_definition);
Scenery::getCurrent()->getTextures(_definition);
BaseFormLayer::revertConfig();
}
void FormTextures::applyConfig()
{
BaseFormLayer::applyConfig();
scenerySetTextures(_definition);
Scenery::getCurrent()->setTextures(_definition);
}
void FormTextures::layerReadCurrentFrom(void* layer_definition)

View file

@ -45,12 +45,7 @@ protected:
void updateData()
{
WaterRendererClass.bind(_renderer, _definition);
// TODO Do this only on full refresh
TerrainDefinition* terrain = (TerrainDefinition*) TerrainDefinitionClass.create();
sceneryGetTerrain(terrain);
TerrainRendererClass.bind(_renderer, terrain);
TerrainDefinitionClass.destroy(terrain);
TerrainRendererClass.bind(_renderer, Scenery::getCurrent()->getTerrain());
}
void toggleChangeEvent(QString key, bool value)
@ -263,13 +258,13 @@ BaseForm(parent)
void FormWater::revertConfig()
{
sceneryGetWater(_definition);
Scenery::getCurrent()->getWater(_definition);
BaseForm::revertConfig();
}
void FormWater::applyConfig()
{
scenerySetWater(_definition);
Scenery::getCurrent()->setWater(_definition);
BaseForm::applyConfig();
}
@ -281,7 +276,7 @@ void FormWater::configChangeEvent()
void FormWater::autoPresetSelected(int preset)
{
waterAutoPreset(_definition, (WaterPreset) preset);
_definition->applyPreset((WaterPreset)preset);
BaseForm::autoPresetSelected(preset);
}

View file

@ -69,10 +69,7 @@ void MainTerrainForm::refreshFromLocalData()
void MainTerrainForm::refreshFromFellowData()
{
TexturesDefinition* textures = (TexturesDefinition*)TexturesDefinitionClass.create();
sceneryGetTextures(textures);
double disp = texturesGetMaximalDisplacement(textures);
TexturesDefinitionClass.destroy(textures);
double disp = texturesGetMaximalDisplacement(Scenery::getCurrent()->getTextures());
if (disp == 0.0)
{
@ -86,12 +83,12 @@ void MainTerrainForm::refreshFromFellowData()
void MainTerrainForm::updateLocalDataFromScenery()
{
sceneryGetTerrain(_terrain);
Scenery::getCurrent()->getTerrain(_terrain);
}
void MainTerrainForm::commitLocalDataToScenery()
{
scenerySetTerrain(_terrain);
Scenery::getCurrent()->setTerrain(_terrain);
}
void MainTerrainForm::alterRenderer(Renderer* renderer)

View file

@ -130,12 +130,12 @@ void MainTexturesForm::selectPreset(int preset)
void MainTexturesForm::updateLocalDataFromScenery()
{
sceneryGetTextures(textures);
Scenery::getCurrent()->getTextures(textures);
}
void MainTexturesForm::commitLocalDataToScenery()
{
scenerySetTextures(textures);
Scenery::getCurrent()->setTextures(textures);
}
void MainTexturesForm::refreshFromLocalData()

View file

@ -14,10 +14,7 @@
#include "terrain/ter_raster.h"
#include "WaterDefinition.h"
static Scenery* _main_scenery;
static SceneryCustomDataCallback _custom_save = NULL;
static SceneryCustomDataCallback _custom_load = NULL;
static void* _custom_data = NULL;
static Scenery _main_scenery;
Scenery::Scenery():
BaseDefinition(NULL)
@ -30,6 +27,10 @@ Scenery::Scenery():
water = new WaterDefinition(this);
addChild(water);
_custom_load = NULL;
_custom_save = NULL;
_custom_data = NULL;
}
Scenery::~Scenery()
@ -46,29 +47,50 @@ Scenery::~Scenery()
Scenery* Scenery::getCurrent()
{
return _main_scenery;
return &_main_scenery;
}
void Scenery::setCustomSaveCallbacks(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data)
{
_custom_save = callback_save;
_custom_load = callback_load;
_custom_data = data;
}
void Scenery::save(PackStream* stream) const
{
BaseDefinition::save(stream);
noiseSave(stream);
AtmosphereDefinitionClass.save(stream, atmosphere);
cameraSave(stream, camera);
CloudsDefinitionClass.save(stream, clouds);
TerrainDefinitionClass.save(stream, terrain);
TexturesDefinitionClass.save(stream, textures);
if (_custom_save)
{
_custom_save(stream, _custom_data);
}
}
void Scenery::load(PackStream* stream)
{
BaseDefinition::load(stream);
noiseLoad(stream);
AtmosphereDefinitionClass.load(stream, atmosphere);
cameraLoad(stream, camera);
CloudsDefinitionClass.load(stream, clouds);
TerrainDefinitionClass.load(stream, terrain);
TexturesDefinitionClass.load(stream, textures);
if (_custom_load)
{
_custom_load(stream, _custom_data);
}
}
void Scenery::autoPreset(int seed)
@ -82,7 +104,7 @@ void Scenery::autoPreset(int seed)
terrainAutoPreset(terrain, TERRAIN_PRESET_STANDARD);
texturesAutoPreset(textures, TEXTURES_PRESET_FULL);
atmosphereAutoPreset(atmosphere, ATMOSPHERE_PRESET_CLEAR_DAY);
waterAutoPreset(water, WATER_PRESET_LAKE);
water->applyPreset(WATER_PRESET_LAKE);
cloudsAutoPreset(clouds, CLOUDS_PRESET_PARTLY_CLOUDY);
cameraSetLocation(camera, VECTOR_ZERO);
@ -150,140 +172,6 @@ void Scenery::getWater(WaterDefinition* water)
this->water->copy(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()
{
if (_main_scenery)
{
return _main_scenery->getTerrain();
}
else
{
return NULL;
}
}
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;
@ -313,24 +201,21 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
return v3Norm(v3Sub(cameraUnproject(renderer->render_camera, projected), location)); // / (double)render_quality;
}
Renderer* sceneryCreateStandardRenderer()
void Scenery::bindToRenderer(Renderer* renderer)
{
Renderer* result;
// TODO Get rid of this !
renderer->rayWalking = _rayWalking;
renderer->getPrecision = _getPrecision;
result = rendererCreate();
result->rayWalking = _rayWalking;
result->getPrecision = _getPrecision;
sceneryBindRenderer(result);
return result;
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);
}
void sceneryBindRenderer(Renderer* renderer)
{
_main_scenery->bindToRenderer(renderer);
}
// Transitional C-API
void sceneryRenderFirstPass(Renderer* renderer)
{

View file

@ -12,11 +12,7 @@ class TerrainDefinition;
class TexturesDefinition;
class Renderer;
namespace paysages {
namespace system {
class PackStream;
}
}
typedef void (*SceneryCustomDataCallback)(PackStream* stream, void* data);
/**
* @brief Global scenery management
@ -31,6 +27,8 @@ public:
static Scenery* getCurrent();
void setCustomSaveCallbacks(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data);
virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) override;
@ -69,41 +67,14 @@ private:
TerrainDefinition* terrain;
TexturesDefinition* textures;
WaterDefinition* water;
SceneryCustomDataCallback _custom_save;
SceneryCustomDataCallback _custom_load;
void* _custom_data;
};
// 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);
#endif // SCENERY_H

View file

@ -93,18 +93,15 @@ void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destinatio
void cameraValidateDefinition(CameraDefinition* definition, int check_above)
{
Renderer* renderer;
double water_height, terrain_height, diff;
Vector3 move;
Matrix4 rotation;
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;
rendererDelete(renderer);
TerrainDefinition* terrain = Scenery::getCurrent()->getTerrain();
terrain_height = terrainGetInterpolatedHeight(terrain, definition->location.x, definition->location.z, 1, 1) + 0.5;
water_height = terrainGetWaterHeight(terrain) + 0.5;
if (definition->location.y < water_height || definition->location.y < terrain_height)
{

View file

@ -20,13 +20,11 @@ void paysagesInit()
}
openclInit();
sceneryInit();
renderInit();
}
void paysagesQuit()
{
sceneryQuit();
renderQuit();
openclQuit();
@ -47,7 +45,7 @@ FileOperationResult paysagesSave(char* filepath)
version_header = (double)PAYSAGES_CURRENT_DATA_VERSION;
stream.write(&version_header);
scenerySave(&stream);
Scenery::getCurrent()->save(&stream);
return FILE_OPERATION_OK;
}
@ -74,7 +72,7 @@ FileOperationResult paysagesLoad(char* filepath)
return FILE_OPERATION_VERSION_MISMATCH;
}
sceneryLoad(&stream);
Scenery::getCurrent()->load(&stream);
return FILE_OPERATION_OK;
}

View file

@ -759,9 +759,16 @@ void renderPostProcess(RenderArea* area, int nbchunks)
area->callback_update(1.0);
}
static unsigned int _getPicturePixel(void* data, int x, int y)
{
Color result = _getFinalPixel((RenderArea*)data, x, y);
result.normalize();
return result.to32BitBGRA();
}
int renderSaveToFile(RenderArea* area, const char* path)
{
return systemSavePictureFile(path, (PictureCallbackSavePixel)_getFinalPixel, area, area->params.width, area->params.height);
return systemSavePictureFile(path, _getPicturePixel, area, area->params.width, area->params.height);
}
void renderSetPreviewCallbacks(RenderArea* area, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)

View file

@ -26,7 +26,6 @@ SOURCES += main.cpp \
clouds/clo_presets.cpp \
clouds/clo_density.cpp \
clouds/clo_definition.cpp \
shared/preview.cpp \
terrain/ter_render.cpp \
terrain/ter_raster.cpp \
terrain/ter_preview.cpp \
@ -53,7 +52,6 @@ SOURCES += main.cpp \
water/wat_render.cpp \
water/wat_raster.cpp \
water/wat_preview.cpp \
water/wat_presets.cpp \
water/wat_definition.cpp \
Scenery.cpp
@ -73,7 +71,6 @@ HEADERS += \
clouds/clo_preview.h \
clouds/clo_density.h \
shared/types.h \
shared/preview.h \
terrain/ter_raster.h \
terrain/public.h \
terrain/private.h \

View file

@ -1,48 +0,0 @@
#include "preview.h"
#include <stdlib.h>
#include "../renderer.h"
#include "../camera.h"
struct PreviewRenderer
{
Renderer* renderer;
};
static PreviewRenderer* _createRenderer()
{
PreviewRenderer* renderer;
renderer = (PreviewRenderer*)malloc(sizeof (PreviewRenderer));
renderer->renderer = rendererCreate();
return renderer;
}
static void _deleteRenderer(PreviewRenderer* renderer)
{
rendererDelete(renderer->renderer);
free(renderer);
}
static void _setCamera(PreviewRenderer* renderer, Vector3 location, Vector3 target)
{
cameraSetLocation(renderer->renderer->render_camera, location);
cameraSetTarget(renderer->renderer->render_camera, target);
}
PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor)
{
PreviewClass result;
result.createRenderer = _createRenderer;
result.deleteRenderer = _deleteRenderer;
result.setCamera = _setCamera;
result.customizeRenderer = customizeRenderer;
result.bindDefinition = bindDefinition;
result.getPixelColor = getPixelColor;
return result;
}

View file

@ -1,30 +0,0 @@
#ifndef _PAYSAGES_SHARED_PREVIEW_H_
#define _PAYSAGES_SHARED_PREVIEW_H_
/*
* Preview management.
*/
#include "../rendering_global.h"
#include "types.h"
typedef struct PreviewRenderer PreviewRenderer;
typedef void (*FuncPreviewCustomizeRenderer)(PreviewRenderer* preview_renderer, Renderer* renderer);
typedef void (*FuncPreviewBindDefinition)(PreviewRenderer* renderer, void* definition);
typedef Color (*FuncPreviewGetPixelColor)(PreviewRenderer* renderer, double x, double y, double scaling);
typedef struct {
PreviewRenderer* (*createRenderer)();
void (*deleteRenderer)(PreviewRenderer* renderer);
void (*setCamera)(PreviewRenderer* renderer, Vector3 location, Vector3 target);
FuncPreviewCustomizeRenderer customizeRenderer;
FuncPreviewBindDefinition bindDefinition;
FuncPreviewGetPixelColor getPixelColor;
} PreviewClass;
RENDERINGSHARED_EXPORT PreviewClass previewCreateClass(FuncPreviewCustomizeRenderer customizeRenderer, FuncPreviewBindDefinition bindDefinition, FuncPreviewGetPixelColor getPixelColor);
#endif

View file

@ -74,6 +74,7 @@ RENDERINGSHARED_EXPORT void terrainAlterPreviewRenderer(Renderer* renderer);
RENDERINGSHARED_EXPORT Color terrainGetPreviewColor(Renderer* renderer, double x, double z, double detail);
RENDERINGSHARED_EXPORT HeightInfo terrainGetHeightInfo(TerrainDefinition* definition);
RENDERINGSHARED_EXPORT double terrainGetWaterHeight(TerrainDefinition* definition);
typedef struct
{

View file

@ -140,3 +140,8 @@ HeightInfo terrainGetHeightInfo(TerrainDefinition* definition)
return result;
}
double terrainGetWaterHeight(TerrainDefinition* definition)
{
return definition->water_height * definition->height * definition->scaling;
}

View file

@ -71,7 +71,7 @@ static void _layerValidateDefinition(TexturesLayerDefinition* definition)
materialValidate(&definition->material);
/* Update zone height range */
TerrainDefinition* terrain = sceneryGetTerrainDirect();
TerrainDefinition* terrain = Scenery::getCurrent()->getTerrain();
if (terrain)
{
HeightInfo height_info = terrainGetHeightInfo(terrain);

View file

@ -6,11 +6,7 @@
void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition)
{
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
sceneryGetTerrain(terrain);
TerrainRendererClass.bind(renderer, terrain);
TerrainDefinitionClass.destroy(terrain);
TerrainRendererClass.bind(renderer, Scenery::getCurrent()->getTerrain());
TexturesRendererClass.bind(renderer, definition);
}
@ -74,11 +70,7 @@ Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y,
void TexturesPreviewCumul_bind(Renderer* renderer, TexturesDefinition* definition)
{
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
sceneryGetTerrain(terrain);
TerrainRendererClass.bind(renderer, terrain);
TerrainDefinitionClass.destroy(terrain);
TerrainRendererClass.bind(renderer, Scenery::getCurrent()->getTerrain());
TexturesRendererClass.bind(renderer, definition);
}

View file

@ -7,18 +7,6 @@
#include "../tools/curve.h"
#include "../tools/euclid.h"
namespace paysages {
namespace basics {
class NoiseGenerator;
}
}
typedef enum
{
WATER_PRESET_LAKE,
WATER_PRESET_SEA
} WaterPreset;
typedef struct
{
Vector3 location;
@ -47,7 +35,6 @@ public:
RENDERINGSHARED_EXPORT extern StandardRenderer WaterRendererClass;
RENDERINGSHARED_EXPORT void waterRenderSurface(Renderer* renderer);
RENDERINGSHARED_EXPORT void waterAutoPreset(WaterDefinition* definition, WaterPreset preset);
RENDERINGSHARED_EXPORT void waterAlterPreviewCoverageRenderer(Renderer* renderer);
RENDERINGSHARED_EXPORT Color waterGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int highlight_enabled);

View file

@ -1,53 +0,0 @@
#include "private.h"
#include "WaterDefinition.h"
#include "SurfaceMaterial.h"
#include "NoiseGenerator.h"
void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
{
definition->_waves_noise->randomizeOffsets();
if (preset == WATER_PRESET_LAKE)
{
definition->transparency = 0.5;
definition->reflection = 0.4;
definition->transparency_depth = 4.0;
definition->material->base = colorToHSL(colorFromValues(0.08, 0.15, 0.2, 1.0));
definition->depth_color->r = 0.0;
definition->depth_color->g = 0.1;
definition->depth_color->b = 0.1;
definition->lighting_depth = 6.0;
definition->scaling = 1.0;
definition->waves_height = 0.8;
definition->detail_height = 0.05;
definition->turbulence = 0.1;
definition->foam_coverage = 0.15;
}
else if (preset == WATER_PRESET_SEA)
{
definition->transparency = 0.4;
definition->reflection = 0.35;
definition->transparency_depth = 3.0;
definition->material->base = colorToHSL(colorFromValues(0.05, 0.18, 0.2, 1.0));
definition->depth_color->r = 0.0;
definition->depth_color->g = 0.18;
definition->depth_color->b = 0.15;
definition->lighting_depth = 4.0;
definition->scaling = 1.5;
definition->waves_height = 1.0;
definition->detail_height = 0.06;
definition->turbulence = 0.3;
definition->foam_coverage = 0.4;
}
definition->depth_color->a = 1.0;
definition->material->base.a = 1.0;
definition->material->reflection = 1.0;
definition->material->shininess = 16.0;
definition->foam_material->base = colorToHSL(colorFromValues(0.8, 0.8, 0.8, 1.0));
definition->foam_material->reflection = 0.1;
definition->foam_material->shininess = 1.5;
definition->validate();
}

View file

@ -19,7 +19,7 @@ public:
// Transitional C-API
// Les pixels doivent être fournis en RGBA
// Les pixels doivent être fournis en BGRA
typedef unsigned int (*PictureCallbackSavePixel)(void* data, int x, int y);
SYSTEMSHARED_EXPORT int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height);

View file

@ -2,7 +2,7 @@
#include "tools/color.h"
#include "camera.h"
#include "renderer.h"
#include "SoftwareRenderer.h"
#include "atmosphere/public.h"
#include "Scenery.h"
#include "System.h"
@ -17,63 +17,57 @@ static Color _postProcessFragment(Renderer* renderer, Vector3 location, void*)
TEST(Bruneton, AerialPerspective1)
{
Renderer* renderer = sceneryCreateStandardRenderer();
renderer->render_width = 800;
renderer->render_height = 600;
renderer->render_quality = 1;
SoftwareRenderer renderer;
renderer.render_width = 800;
renderer.render_height = 600;
renderer.render_quality = 1;
cameraSetLocation(renderer->render_camera, VECTOR_ZERO);
cameraSetTarget(renderer->render_camera, VECTOR_EAST);
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
cameraSetLocation(renderer.render_camera, VECTOR_ZERO);
cameraSetTarget(renderer.render_camera, VECTOR_EAST);
cameraSetRenderSize(renderer.render_camera, renderer.render_width, renderer.render_height);
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
renderSetParams(renderer->render_area, params);
renderSetBackgroundColor(renderer->render_area, COLOR_BLACK);
renderClear(renderer->render_area);
RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
renderSetParams(renderer.render_area, params);
renderSetBackgroundColor(renderer.render_area, COLOR_BLACK);
renderClear(renderer.render_area);
renderer->pushQuad(renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(10.0, -10.0, -10.0), v3(10.0, -10.0, -5.0), v3(10.0, 50.0, -5.0), v3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(15.0, -10.0, -5.0), v3(15.0, -10.0, 0.0), v3(15.0, 50.0, 0.0), v3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(20.0, -10.0, 5.0), v3(20.0, -10.0, 10.0), v3(20.0, 50.0, 10.0), v3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(30.0, -10.0, 25.0), v3(30.0, -10.0, 30.0), v3(30.0, 50.0, 30.0), v3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderPostProcess(renderer->render_area, System::getCoreCount());
renderer.pushQuad(&renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(10.0, -10.0, -10.0), v3(10.0, -10.0, -5.0), v3(10.0, 50.0, -5.0), v3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(15.0, -10.0, -5.0), v3(15.0, -10.0, 0.0), v3(15.0, 50.0, 0.0), v3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(20.0, -10.0, 5.0), v3(20.0, -10.0, 10.0), v3(20.0, 50.0, 10.0), v3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(30.0, -10.0, 25.0), v3(30.0, -10.0, 30.0), v3(30.0, 50.0, 30.0), v3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderPostProcess(renderer.render_area, System::getCoreCount());
renderSaveToFile(renderer->render_area, "./output/test_bruneton_perspective.png");
rendererDelete(renderer);
renderSaveToFile(renderer.render_area, "./output/test_bruneton_perspective.png");
}
TEST(Bruneton, AerialPerspective2)
{
AtmosphereDefinition* atmo = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
sceneryGetAtmosphere(atmo);
AtmosphereDefinition* atmo = Scenery::getCurrent()->getAtmosphere();
atmo->hour = 6;
atmo->minute = 30;
scenerySetAtmosphere(atmo);
AtmosphereDefinitionClass.destroy(atmo);
AtmosphereDefinitionClass.validate(atmo);
Renderer* renderer = sceneryCreateStandardRenderer();
renderer->render_width = 800;
renderer->render_height = 600;
renderer->render_quality = 1;
Renderer renderer;
renderer.render_width = 800;
renderer.render_height = 600;
renderer.render_quality = 1;
cameraSetLocation(renderer->render_camera, VECTOR_ZERO);
cameraSetTarget(renderer->render_camera, VECTOR_EAST);
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
cameraSetLocation(renderer.render_camera, VECTOR_ZERO);
cameraSetTarget(renderer.render_camera, VECTOR_EAST);
cameraSetRenderSize(renderer.render_camera, renderer.render_width, renderer.render_height);
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
renderSetParams(renderer->render_area, params);
renderSetBackgroundColor(renderer->render_area, COLOR_BLACK);
renderClear(renderer->render_area);
RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
renderSetParams(renderer.render_area, params);
renderSetBackgroundColor(renderer.render_area, COLOR_BLACK);
renderClear(renderer.render_area);
renderer->pushQuad(renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(10.0, -10.0, -10.0), v3(10.0, -10.0, -5.0), v3(10.0, 50.0, -5.0), v3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(15.0, -10.0, -5.0), v3(15.0, -10.0, 0.0), v3(15.0, 50.0, 0.0), v3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(20.0, -10.0, 5.0), v3(20.0, -10.0, 10.0), v3(20.0, 50.0, 10.0), v3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer->pushQuad(renderer, v3(30.0, -10.0, 25.0), v3(30.0, -10.0, 30.0), v3(30.0, 50.0, 30.0), v3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderPostProcess(renderer->render_area, System::getCoreCount());
renderer.pushQuad(&renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(10.0, -10.0, -10.0), v3(10.0, -10.0, -5.0), v3(10.0, 50.0, -5.0), v3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(15.0, -10.0, -5.0), v3(15.0, -10.0, 0.0), v3(15.0, 50.0, 0.0), v3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(20.0, -10.0, 5.0), v3(20.0, -10.0, 10.0), v3(20.0, 50.0, 10.0), v3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer.pushQuad(&renderer, v3(30.0, -10.0, 25.0), v3(30.0, -10.0, 30.0), v3(30.0, 50.0, 30.0), v3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderPostProcess(renderer.render_area, System::getCoreCount());
renderSaveToFile(renderer->render_area, "./output/test_bruneton_perspective1.png");
rendererDelete(renderer);
renderSaveToFile(renderer.render_area, "./output/test_bruneton_perspective1.png");
}