1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

Build a kdtree for terrain geometry

Improves intersection testing performance, shaving off ~2ms of frame time in exteriors.

Also increases terrain loading time by ~1ms per cell, so will have to look into background loading soon.
This commit is contained in:
scrawl 2015-06-09 02:29:56 +02:00
parent 93ee11c5e7
commit 5921e70625
2 changed files with 12 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include <osg/PositionAttitudeTransform>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/KdTree>
#include <osgFX/Effect>
@ -66,6 +67,7 @@ namespace Terrain
TerrainGrid::TerrainGrid(osg::Group* parent, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico,
Storage* storage, int nodeMask)
: Terrain::World(parent, resourceSystem, ico, storage, nodeMask)
, mKdTreeBuilder(new osg::KdTreeBuilder)
{
}
@ -133,6 +135,9 @@ void TerrainGrid::loadCell(int x, int y)
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
geode->addDrawable(geometry);
// build a kdtree to speed up intersection tests with the terrain
geode->accept(*mKdTreeBuilder);
std::vector<LayerInfo> layerList;
std::vector<osg::ref_ptr<osg::Image> > blendmaps;
mStorage->getBlendmaps(1.f, center, false, blendmaps, layerList);

View File

@ -25,6 +25,11 @@
#include "world.hpp"
#include "material.hpp"
namespace osg
{
class KdTreeBuilder;
}
namespace Terrain
{
@ -44,6 +49,8 @@ namespace Terrain
private:
typedef std::map<std::pair<int, int>, GridElement*> Grid;
Grid mGrid;
osg::ref_ptr<osg::KdTreeBuilder> mKdTreeBuilder;
};
}