Optimized terrain rendering

Painted height map is not queried anymore when empty
This commit is contained in:
Michaël Lemaire 2015-09-21 01:36:03 +02:00
parent aacb4addd5
commit 7658bf256f
6 changed files with 20 additions and 3 deletions

View file

@ -119,6 +119,11 @@ double PaintedGrid::getFinalValue(double x, double y) const
} }
} }
bool PaintedGrid::hasPainting() const
{
return merged_data->hasData() || brush_data->hasData();
}
bool PaintedGrid::isPainted(int x, int y) const bool PaintedGrid::isPainted(int x, int y) const
{ {
return getDataPointer(brush_data, x, y, NULL, false) || getDataPointer(merged_data, x, y, NULL, false); return getDataPointer(brush_data, x, y, NULL, false) || getDataPointer(merged_data, x, y, NULL, false);

View file

@ -44,6 +44,11 @@ public:
*/ */
double getFinalValue(double x, double y) const; double getFinalValue(double x, double y) const;
/**
* Returns true if the grid has any painting.
*/
bool hasPainting() const;
/** /**
* Returns true if a grid point is user-specified, false if it's the initial value. * Returns true if a grid point is user-specified, false if it's the initial value.
*/ */

View file

@ -26,6 +26,8 @@ public:
*/ */
void clear(); void clear();
inline bool hasData() const {return rows_count > 0;}
private: private:
typedef struct typedef struct
{ {

View file

@ -12,6 +12,7 @@ TerrainDefinition::TerrainDefinition(DefinitionNode* parent):
shadow_smoothing = 0.0; shadow_smoothing = 0.0;
height_map = new TerrainHeightMap(this); height_map = new TerrainHeightMap(this);
has_painting = false;
addChild(height_map); addChild(height_map);
water_height = new FloatNode(this, "water_height"); water_height = new FloatNode(this, "water_height");
@ -38,7 +39,8 @@ void TerrainDefinition::validate()
_min_height *= height; _min_height *= height;
_max_height *= height; _max_height *= height;
/* TODO Alter with heightmap min/max */ /* TODO Alter limits with heightmap min/max */
has_painting = height_map->hasPainting();
} }
void TerrainDefinition::copy(DefinitionNode* _destination) const void TerrainDefinition::copy(DefinitionNode* _destination) const
@ -79,7 +81,7 @@ double TerrainDefinition::getGridHeight(int x, int z, bool with_painting)
{ {
double h; double h;
if (!with_painting || !height_map->getGridValue(x, z, &h)) if (!with_painting || !has_painting || !height_map->getGridValue(x, z, &h))
{ {
h = _height_noise->get2DTotal((double)x, (double)z); h = _height_noise->get2DTotal((double)x, (double)z);
} }
@ -91,7 +93,7 @@ double TerrainDefinition::getInterpolatedHeight(double x, double z, bool scaled,
{ {
double h; double h;
if (!with_painting || !height_map->getInterpolatedValue(x, z, &h)) if (!with_painting || !has_painting || !height_map->getInterpolatedValue(x, z, &h))
{ {
h = _height_noise->get2DTotal(x, z); h = _height_noise->get2DTotal(x, z);
} }

View file

@ -47,6 +47,7 @@ public:
double shadow_smoothing; double shadow_smoothing;
TerrainHeightMap* height_map; TerrainHeightMap* height_map;
bool has_painting;
double _detail; double _detail;
NoiseGenerator* _height_noise; NoiseGenerator* _height_noise;

View file

@ -63,6 +63,8 @@ SoftwareRenderer::~SoftwareRenderer()
void SoftwareRenderer::prepare() void SoftwareRenderer::prepare()
{ {
scenery->validate();
// Prepare sub renderers // Prepare sub renderers
// TODO Don't recreate the renderer each time // TODO Don't recreate the renderer each time
delete atmosphere_renderer; delete atmosphere_renderer;