Enable rendering smallest (i.e. closest) chunk nodes first. Toggleable from GUI

This commit is contained in:
Erik Broberg
2016-05-16 14:33:28 -04:00
parent 8639190b9e
commit 33d1d1a31d
6 changed files with 77 additions and 39 deletions
@@ -95,20 +95,30 @@ namespace openspace {
void ChunkedLodGlobe::render(const RenderData& data){
minDistToCamera = INFINITY;
ChunkNode::renderedPatches = 0;
ChunkNode::renderedChunks = 0;
_leftRoot->render(data);
_rightRoot->render(data);
renderChunkTree(_leftRoot.get(), data);
renderChunkTree(_rightRoot.get(), data);
//LDEBUG("min distnace to camera: " << minDistToCamera);
Vec3 cameraPos = data.camera.position().dvec3();
//LDEBUG("cam pos x: " << cameraPos.x << " y: " << cameraPos.y << " z: " << cameraPos.z);
//LDEBUG("ChunkNode count: " << ChunkNode::instanceCount);
//LDEBUG("RenderedPatches count: " << ChunkNode::renderedPatches);
//LDEBUG(ChunkNode::renderedPatches << " / " << ChunkNode::instanceCount << " chunks rendered");
//LDEBUG("ChunkNode count: " << ChunkNode::chunkNodeCount);
//LDEBUG("RenderedPatches count: " << ChunkNode::renderedChunks);
//LDEBUG(ChunkNode::renderedChunks << " / " << ChunkNode::chunkNodeCount << " chunks rendered");
}
void ChunkedLodGlobe::renderChunkTree(ChunkNode* node, const RenderData& data) const {
node->updateChunkTree(data);
if (renderSmallChunksFirst) {
node->renderReversedBreadthFirst(data);
}
else {
node->renderDepthFirst(data);
}
}
void ChunkedLodGlobe::update(const UpdateData& data) {
@@ -90,10 +90,13 @@ namespace openspace {
bool mergeInvisible;
float lodScaleFactor;
bool initChunkVisible;
bool renderSmallChunksFirst = true;
private:
void renderChunkTree(ChunkNode* node, const RenderData& data) const;
// Covers all negative longitudes
std::unique_ptr<ChunkNode> _leftRoot;
+43 -22
View File
@@ -22,13 +22,14 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/globebrowsing/globes/chunknode.h>
#include <queue>
#include <ghoul/misc/assert.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/engine/openspaceengine.h>
#include <modules/globebrowsing/globes/chunknode.h>
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
#include <modules/globebrowsing/rendering/culling.h>
@@ -39,8 +40,8 @@ namespace {
namespace openspace {
int ChunkNode::instanceCount = 0;
int ChunkNode::renderedPatches = 0;
int ChunkNode::chunkNodeCount = 0;
int ChunkNode::renderedChunks = 0;
ChunkNode::ChunkNode(const Chunk& chunk, ChunkNode* parent)
: _chunk(chunk)
@@ -50,11 +51,11 @@ ChunkNode::ChunkNode(const Chunk& chunk, ChunkNode* parent)
_children[1] = nullptr;
_children[2] = nullptr;
_children[3] = nullptr;
instanceCount++;
chunkNodeCount++;
}
ChunkNode::~ChunkNode() {
instanceCount--;
chunkNodeCount--;
}
bool ChunkNode::isRoot() const {
@@ -66,16 +67,8 @@ bool ChunkNode::isLeaf() const {
}
void ChunkNode::render(const RenderData& data) {
ghoul_assert(isRoot(), "this method should only be invoked on root");
//LDEBUG("-------------");
internalUpdateChunkTree(data);
internalRender(data);
}
// Returns true or false wether this node can be merge or not
bool ChunkNode::internalUpdateChunkTree(const RenderData& data) {
bool ChunkNode::updateChunkTree(const RenderData& data) {
//Geodetic2 center = _chunk.surfacePatch.center();
//LDEBUG("x: " << patch.x << " y: " << patch.y << " level: " << patch.level << " lat: " << center.lat << " lon: " << center.lon);
@@ -90,7 +83,7 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data) {
char requestedMergeMask = 0;
for (int i = 0; i < 4; ++i) {
if (_children[i]->internalUpdateChunkTree(data)) {
if (_children[i]->updateChunkTree(data)) {
requestedMergeMask |= (1 << i);
}
}
@@ -99,26 +92,54 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data) {
if (requestedMergeMask == 0xf && _chunk.update(data)) {
merge();
// re-run internalUpdateChunkTree on this, now that this is a leaf node
// re-run updateChunkTree on this, now that this is a leaf node
// OBS, this may currently cause a split() again ...
return internalUpdateChunkTree(data);
return updateChunkTree(data);
}
return false;
}
}
void ChunkNode::internalRender(const RenderData& data) {
void ChunkNode::renderReversedBreadthFirst(const RenderData& data) {
std::stack<ChunkNode*> S;
std::queue<ChunkNode*> Q;
Q.push(this);
while (Q.size() > 0) {
ChunkNode* node = Q.front();
Q.pop();
if (node->isLeaf()) {
if (node->_chunk.isVisible()) {
S.push(node);
}
}
else {
for (int i = 0; i < 4; ++i) {
Q.push(node->_children[i].get());
}
}
}
while (S.size() > 0) {
S.top()->renderThisChunk(data);
S.pop();
}
}
void ChunkNode::renderThisChunk(const RenderData& data) {
ChunkRenderer& patchRenderer = _chunk.owner()->getPatchRenderer();
patchRenderer.renderChunk(_chunk, data);
ChunkNode::renderedChunks++;
}
void ChunkNode::renderDepthFirst(const RenderData& data) {
if (isLeaf()) {
if (_chunk.isVisible()) {
ChunkRenderer& patchRenderer = _chunk.owner()->getPatchRenderer();
patchRenderer.renderChunk(_chunk, data);
ChunkNode::renderedPatches++;
renderThisChunk(data);
}
}
else {
for (int i = 0; i < 4; ++i) {
_children[i]->internalRender(data);
_children[i]->renderDepthFirst(data);
}
}
}
+8 -9
View File
@@ -27,6 +27,7 @@
#include <glm/glm.hpp>
#include <vector>
#include <stack>
#include <memory>
#include <ostream>
@@ -64,19 +65,17 @@ public:
const ChunkNode& getChild(Quad quad) const;
void render(const RenderData& data);
void renderDepthFirst(const RenderData& data);
static int instanceCount;
static int renderedPatches;
void renderReversedBreadthFirst(const RenderData& data);
void renderThisChunk(const RenderData& data);
bool updateChunkTree(const RenderData& data);
static int chunkNodeCount;
static int renderedChunks;
private:
void internalRender(const RenderData& data);
bool internalUpdateChunkTree(const RenderData& data);
ChunkNode* _parent;
std::unique_ptr<ChunkNode> _children[4];
@@ -59,7 +59,7 @@ namespace openspace {
, mergeInvisible(properties::BoolProperty("mergeInvisible", "mergeInvisible", true))
, lodScaleFactor(properties::FloatProperty("lodScaleFactor", "lodScaleFactor", 10.0f, 0.0f, 100.0f))
, initChunkVisible(properties::BoolProperty("initChunkVisible", "initChunkVisible", true))
, renderSmallChunksFirst(properties::BoolProperty("renderSmallChunksFirst", "renderSmallChunksFirst", true))
{
setName("RenderableGlobe");
@@ -70,9 +70,13 @@ namespace openspace {
addProperty(mergeInvisible);
addProperty(lodScaleFactor);
addProperty(initChunkVisible);
addProperty(renderSmallChunksFirst);
doFrustumCulling.setValue(true);
doHorizonCulling.setValue(true);
renderSmallChunksFirst.setValue(true);
// Read the radii in to its own dictionary
Vec3 radii;
@@ -68,6 +68,7 @@ public:
properties::BoolProperty mergeInvisible;
properties::FloatProperty lodScaleFactor;
properties::BoolProperty initChunkVisible;
properties::BoolProperty renderSmallChunksFirst;
private:
double _time;