mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-26 05:58:58 -06:00
ChunkNodes store their own ChunkIndex
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
|
||||
@@ -47,13 +47,16 @@ namespace openspace {
|
||||
const GeodeticPatch ChunkLodGlobe::LEFT_HEMISPHERE = GeodeticPatch(0, -M_PI/2, M_PI/2, M_PI/2);
|
||||
const GeodeticPatch ChunkLodGlobe::RIGHT_HEMISPHERE = GeodeticPatch(0, M_PI/2, M_PI/2, M_PI/2);
|
||||
|
||||
const ChunkIndex ChunkLodGlobe::LEFT_HEMISPHERE_INDEX = ChunkIndex(0, 0, 1);
|
||||
const ChunkIndex ChunkLodGlobe::RIGHT_HEMISPHERE_INDEX = ChunkIndex(1, 0, 1);
|
||||
|
||||
|
||||
ChunkLodGlobe::ChunkLodGlobe(
|
||||
const Ellipsoid& ellipsoid,
|
||||
std::shared_ptr<TileProviderManager> tileProviderManager)
|
||||
: _ellipsoid(ellipsoid)
|
||||
, _leftRoot(new ChunkNode(*this, LEFT_HEMISPHERE))
|
||||
, _rightRoot(new ChunkNode(*this, RIGHT_HEMISPHERE))
|
||||
, _leftRoot(new ChunkNode(*this, LEFT_HEMISPHERE_INDEX))
|
||||
, _rightRoot(new ChunkNode(*this, RIGHT_HEMISPHERE_INDEX))
|
||||
, minSplitDepth(2)
|
||||
, maxSplitDepth(22)
|
||||
{
|
||||
@@ -93,11 +96,9 @@ namespace openspace {
|
||||
ChunkNode::renderedPatches = 0;
|
||||
|
||||
|
||||
ChunkIndex leftRootChunkIndex = { 0, 0, 1 };
|
||||
_leftRoot->render(data, leftRootChunkIndex);
|
||||
|
||||
ChunkIndex rightRootChunkIndex = { 1, 0, 1 };
|
||||
_rightRoot->render(data, rightRootChunkIndex);
|
||||
_leftRoot->render(data);
|
||||
_rightRoot->render(data);
|
||||
|
||||
//LDEBUG("min distnace to camera: " << minDistToCamera);
|
||||
|
||||
|
||||
@@ -90,6 +90,9 @@ namespace openspace {
|
||||
static const GeodeticPatch LEFT_HEMISPHERE;
|
||||
static const GeodeticPatch RIGHT_HEMISPHERE;
|
||||
|
||||
static const ChunkIndex LEFT_HEMISPHERE_INDEX;
|
||||
static const ChunkIndex RIGHT_HEMISPHERE_INDEX;
|
||||
|
||||
const Ellipsoid& _ellipsoid;
|
||||
};
|
||||
|
||||
|
||||
@@ -42,9 +42,10 @@ namespace openspace {
|
||||
int ChunkNode::instanceCount = 0;
|
||||
int ChunkNode::renderedPatches = 0;
|
||||
|
||||
ChunkNode::ChunkNode(ChunkLodGlobe& owner, const GeodeticPatch& patch, ChunkNode* parent)
|
||||
ChunkNode::ChunkNode(ChunkLodGlobe& owner, const ChunkIndex& index, ChunkNode* parent)
|
||||
: _owner(owner)
|
||||
, _patch(patch)
|
||||
, _index(index)
|
||||
, _patch(index)
|
||||
, _parent(parent)
|
||||
, _isVisible(true)
|
||||
{
|
||||
@@ -68,16 +69,16 @@ bool ChunkNode::isLeaf() const {
|
||||
}
|
||||
|
||||
|
||||
void ChunkNode::render(const RenderData& data, ChunkIndex traverseData) {
|
||||
void ChunkNode::render(const RenderData& data) {
|
||||
ghoul_assert(isRoot(), "this method should only be invoked on root");
|
||||
//LDEBUG("-------------");
|
||||
internalUpdateChunkTree(data, traverseData);
|
||||
internalRender(data, traverseData);
|
||||
internalUpdateChunkTree(data);
|
||||
internalRender(data);
|
||||
}
|
||||
|
||||
|
||||
// Returns true or false wether this node can be merge or not
|
||||
bool ChunkNode::internalUpdateChunkTree(const RenderData& data, ChunkIndex& traverseData) {
|
||||
bool ChunkNode::internalUpdateChunkTree(const RenderData& data) {
|
||||
using namespace glm;
|
||||
Geodetic2 center = _patch.center();
|
||||
|
||||
@@ -85,12 +86,12 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data, ChunkIndex& trav
|
||||
|
||||
if (isLeaf()) {
|
||||
|
||||
int desiredLevel = calculateDesiredLevelAndUpdateIsVisible(data, traverseData);
|
||||
int desiredLevel = calculateDesiredLevelAndUpdateIsVisible(data, _index);
|
||||
desiredLevel = glm::clamp(desiredLevel, _owner.minSplitDepth, _owner.maxSplitDepth);
|
||||
if (desiredLevel > traverseData.level) {
|
||||
if (desiredLevel > _index.level) {
|
||||
split();
|
||||
}
|
||||
else if(desiredLevel < traverseData.level){
|
||||
else if(desiredLevel < _index.level){
|
||||
return true; // request a merge from parent
|
||||
}
|
||||
return false;
|
||||
@@ -98,9 +99,8 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data, ChunkIndex& trav
|
||||
else {
|
||||
|
||||
int requestedMergeMask = 0;
|
||||
std::vector<ChunkIndex> childIndices = traverseData.childIndices();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (_children[i]->internalUpdateChunkTree(data, childIndices[i])) {
|
||||
if (_children[i]->internalUpdateChunkTree(data)) {
|
||||
requestedMergeMask |= (1 << i);
|
||||
}
|
||||
}
|
||||
@@ -110,27 +110,25 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data, ChunkIndex& trav
|
||||
merge();
|
||||
|
||||
// re-run this method on this, now that this is a leaf node
|
||||
return internalUpdateChunkTree(data, traverseData);
|
||||
return internalUpdateChunkTree(data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChunkNode::internalRender(const RenderData& data, ChunkIndex& traverseData) {
|
||||
void ChunkNode::internalRender(const RenderData& data) {
|
||||
if (isLeaf()) {
|
||||
if (_isVisible) {
|
||||
|
||||
LatLonPatchRenderer& patchRenderer = _owner.getPatchRenderer();
|
||||
|
||||
patchRenderer.renderPatch(_patch, data, _owner.ellipsoid(), traverseData);
|
||||
patchRenderer.renderPatch(_patch, data, _owner.ellipsoid(), _index);
|
||||
ChunkNode::renderedPatches++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::vector<ChunkIndex> childIndices = traverseData.childIndices();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_children[i]->internalRender(data, childIndices[i]);
|
||||
_children[i]->internalRender(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,25 +213,11 @@ int ChunkNode::calculateDesiredLevelAndUpdateIsVisible(
|
||||
|
||||
void ChunkNode::split(int depth) {
|
||||
if (depth > 0 && isLeaf()) {
|
||||
|
||||
// Defining short handles for center, halfSize and quarterSize
|
||||
const Geodetic2& c = _patch.center();
|
||||
const Geodetic2& hs = _patch.halfSize();
|
||||
Geodetic2 qs = Geodetic2(0.5 * hs.lat, 0.5 * hs.lon);
|
||||
|
||||
// Subdivide bounds
|
||||
|
||||
GeodeticPatch nwBounds = GeodeticPatch(Geodetic2(c.lat + qs.lat, c.lon - qs.lon), qs);
|
||||
GeodeticPatch neBounds = GeodeticPatch(Geodetic2(c.lat + qs.lat, c.lon + qs.lon), qs);
|
||||
GeodeticPatch swBounds = GeodeticPatch(Geodetic2(c.lat - qs.lat, c.lon - qs.lon), qs);
|
||||
GeodeticPatch seBounds = GeodeticPatch(Geodetic2(c.lat - qs.lat, c.lon + qs.lon), qs);
|
||||
|
||||
// Create new chunk nodes
|
||||
|
||||
_children[Quad::NORTH_WEST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, nwBounds, this));
|
||||
_children[Quad::SOUTH_WEST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, swBounds, this));
|
||||
_children[Quad::NORTH_EAST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, neBounds, this));
|
||||
_children[Quad::SOUTH_EAST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, seBounds, this));
|
||||
auto childIndices = _index.childIndices();
|
||||
for (size_t i = 0; i < childIndices.size(); i++) {
|
||||
_children[i] = std::unique_ptr<ChunkNode>(
|
||||
new ChunkNode(_owner, childIndices[i], this));
|
||||
}
|
||||
}
|
||||
|
||||
if (depth - 1 > 0) {
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace openspace {
|
||||
|
||||
class ChunkNode {
|
||||
public:
|
||||
ChunkNode(ChunkLodGlobe&, const GeodeticPatch&, ChunkNode* parent = nullptr);
|
||||
ChunkNode(ChunkLodGlobe&, const ChunkIndex&, ChunkNode* parent = nullptr);
|
||||
~ChunkNode();
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
|
||||
const ChunkNode& getChild(Quad quad) const;
|
||||
|
||||
void render(const RenderData& data, ChunkIndex);
|
||||
void render(const RenderData& data);
|
||||
|
||||
static int instanceCount;
|
||||
static int renderedPatches;
|
||||
@@ -69,8 +69,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void internalRender(const RenderData& data, ChunkIndex&);
|
||||
bool internalUpdateChunkTree(const RenderData& data, ChunkIndex& traverseData);
|
||||
void internalRender(const RenderData& data);
|
||||
bool internalUpdateChunkTree(const RenderData& data);
|
||||
|
||||
/**
|
||||
Uses horizon culling, frustum culling and distance to camera to determine a
|
||||
@@ -90,6 +90,7 @@ private:
|
||||
std::unique_ptr<ChunkNode> _children[4];
|
||||
ChunkLodGlobe& _owner;
|
||||
GeodeticPatch _patch;
|
||||
ChunkIndex _index;
|
||||
bool _isVisible;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user