Merge branch 'feature/globebrowsing' of github.com:OpenSpace/OpenSpace into feature/globebrowsing

This commit is contained in:
Erik Broberg
2016-10-18 13:43:31 +02:00
5 changed files with 71 additions and 23 deletions

View File

@@ -46,7 +46,7 @@
#include <math.h>
namespace {
const std::string _loggerCat = "PatchRenderer";
const std::string _loggerCat = "ChunkRenderer";
const std::string keyFrame = "Frame";
const std::string keyGeometry = "Geometry";
@@ -57,7 +57,6 @@ namespace {
namespace openspace {
ChunkRenderer::ChunkRenderer(
std::shared_ptr<Grid> grid,
std::shared_ptr<TileProviderManager> tileProviderManager)
@@ -74,12 +73,15 @@ namespace openspace {
"${MODULE_GLOBEBROWSING}/shaders/localchunkedlodpatch_vs.glsl",
"${MODULE_GLOBEBROWSING}/shaders/localchunkedlodpatch_fs.glsl");
_globalProgramUniformHandler = std::make_shared<LayeredTextureShaderUniformIdHandler>();
_localProgramUniformHandler = std::make_shared<LayeredTextureShaderUniformIdHandler>();
_globalProgramUniformHandler =
std::make_shared<LayeredTextureShaderUniformIdHandler>();
_localProgramUniformHandler =
std::make_shared<LayeredTextureShaderUniformIdHandler>();
}
void ChunkRenderer::renderChunk(const Chunk& chunk, const RenderData& data) {
// A little arbitrary but it works
if (chunk.tileIndex().level < 10) {
renderChunkGlobally(chunk, data);
}
@@ -89,7 +91,7 @@ namespace openspace {
}
void ChunkRenderer::update() {
// unued atm. Could be used for caching or precalculating
// unused atm. Could be used for caching or precalculating
}
void ChunkRenderer::setDepthTransformUniforms(
@@ -125,7 +127,6 @@ namespace openspace {
ghoul::opengl::TextureUnit& texUnit,
const TileAndTransform& tileAndTransform)
{
// Blend tile with two parents
// The texture needs a unit to sample from
texUnit.activate();
@@ -181,14 +182,19 @@ namespace openspace {
LayeredTextures::NUM_TEXTURE_CATEGORIES> tileProviders;
LayeredTexturePreprocessingData layeredTexturePreprocessingData;
for (size_t category = 0; category < LayeredTextures::NUM_TEXTURE_CATEGORIES; category++) {
tileProviders[category] = _tileProviderManager->getTileProviderGroup(category).getActiveTileProviders();
for (size_t category = 0;
category < LayeredTextures::NUM_TEXTURE_CATEGORIES;
category++) {
tileProviders[category] = _tileProviderManager->getTileProviderGroup(
category).getActiveTileProviders();
LayeredTextureInfo layeredTextureInfo;
layeredTextureInfo.lastLayerIdx = tileProviders[category].size() - 1;
layeredTextureInfo.layerBlendingEnabled = _tileProviderManager->getTileProviderGroup(category).levelBlendingEnabled;
layeredTextureInfo.layerBlendingEnabled =
_tileProviderManager->getTileProviderGroup(category).levelBlendingEnabled;
layeredTexturePreprocessingData.layeredTextureInfo[category] = layeredTextureInfo;
layeredTexturePreprocessingData.layeredTextureInfo[category] =
layeredTextureInfo;
}
layeredTexturePreprocessingData.keyValuePairs.push_back(
@@ -220,9 +226,6 @@ namespace openspace {
std::pair<std::string, std::string>(
"defaultHeight",
std::to_string(Chunk::DEFAULT_HEIGHT)));
// Now the shader program can be accessed
ProgramObject* programObject =

View File

@@ -57,12 +57,35 @@ namespace openspace {
ChunkRenderer(std::shared_ptr<Grid> grid,
std::shared_ptr<TileProviderManager> tileProviderManager);
/**
Chooses to render a chunk either locally or globally depending on the chunklevel
of the <code>Chunk</code>.
*/
void renderChunk(const Chunk& chunk, const RenderData& data);
void update();
private:
/**
Chunks can be rendered either globally or locally. Global rendering is performed
in the model space of the globe. With global rendering, the vertex positions
of a chunk are calculated in the vertex shader by transforming the geodetic
coordinates of the chunk to model space coordinates. We can only achieve floating
point precision by doing this which means that the camera too close to a global
tile will lead to jagging. We only render global chunks for lower chunk levels.
*/
void renderChunkGlobally(const Chunk& chunk, const RenderData& data);
/**
Local rendering of chunks are done using linear interpolation in camera space.
All four corner points of the chunk are calculated in double precision on the
CPU and transformed to camera space with double precision matrix transforms.
These positions can then be cast to floats and uploaded to the vertex shader.
The vertex shader rendering performs linear interpolation between the four
corner points to get the resulting chunk. This means that there will be an error
due to the curvature of the globe. The smaller the patch is (with higher chunk
levels) the better the approximation becomes. This is why we only render local
chunks for higher chunk levels.
*/
void renderChunkLocally(const Chunk& chunk, const RenderData& data);
void setDepthTransformUniforms(
@@ -91,19 +114,17 @@ namespace openspace {
std::shared_ptr<LayeredTextureShaderUniformIdHandler> programUniformHandler,
const Chunk& chunk);
//////////////////////////////////////////////////////////////////////////////////
// Member variables //
//////////////////////////////////////////////////////////////////////////////////
// shared pointer to a grid which can be the same for all rendered chunks.
std::shared_ptr<Grid> _grid;
std::shared_ptr<TileProviderManager> _tileProviderManager;
// Two different shader programs. One for global and one for local rendering.
std::shared_ptr<LayeredTextureShaderProvider> _globalRenderingShaderProvider;
std::shared_ptr<LayeredTextureShaderProvider> _localRenderingShaderProvider;
// Layered texture uniforms are chached in the uniform ID handles.
std::shared_ptr<LayeredTextureShaderUniformIdHandler> _globalProgramUniformHandler;
std::shared_ptr<LayeredTextureShaderUniformIdHandler> _localProgramUniformHandler;
};
} // namespace openspace

View File

@@ -49,15 +49,26 @@ namespace openspace {
class ChunkedLodGlobe;
class TileProviderManager;
/**
Property owner that owns all property of a single texture layer.
These properties include all the per layer settings defined for each texture layer.
*/
class SingleTexturePropertyOwner : public properties::PropertyOwner
{
public:
SingleTexturePropertyOwner(std::string name);
~SingleTexturePropertyOwner();
// This property is not part of the per layer settings since it should not be used
// as a uniform in the shaders. It is instead passed as a pre processor macro
// so that the glsl code can be optimised to not use the texture id if is not enabled.
properties::BoolProperty isEnabled;
};
/**
Property owner defined to carry properties for each layer category.
Layer categories are defined in <code>LayeredTextures</code>.
*/
class LayeredCategoryPropertyOwner : public properties::PropertyOwner
{
public:
@@ -72,8 +83,16 @@ private:
properties::BoolProperty _levelBlendingEnabled;
};
/**
A <code>RenderableGlobe</code> is a globe modeled as an ellipsoid using a chunked LOD
algorithm for rendering.
*/
class RenderableGlobe : public Renderable {
public:
/**
These properties are specific for <code>ChunkedLodGlobe</code> and separated from
the general properties of <code>RenderableGlobe</code>.
*/
struct DebugProperties {
properties::BoolProperty saveOrThrowCamera;
properties::BoolProperty showChunkEdges;
@@ -118,12 +137,15 @@ public:
const DebugProperties& debugProperties() const;
const GeneralProperties& generalProperties() const;
const std::shared_ptr<const Camera> savedCamera() const;
double interactionDepthBelowEllipsoid();
// Setters
void setSaveCamera(std::shared_ptr<Camera> camera);
private:
// Globes. These are renderables inserted in a distance switch so that the heavier
// <code>ChunkedLodGlobe</code> does not have to be rendered qt far distances.
// Currently we only have the <code>ChunkedLodGlobe</code> and a simple globe rendered
// as a point.
std::shared_ptr<ChunkedLodGlobe> _chunkedLodGlobe;
std::shared_ptr<PointGlobe> _pointGlobe;
@@ -142,10 +164,8 @@ private:
// Properties
DebugProperties _debugProperties;
GeneralProperties _generalProperties;
properties::PropertyOwner _debugPropertyOwner;
properties::PropertyOwner _texturePropertyOwner;
std::vector<std::unique_ptr<LayeredCategoryPropertyOwner> > _textureProperties;
};

View File

@@ -58,9 +58,13 @@ namespace openspace {
for (size_t i = 0; i < layeredTextureInfo.size(); i++) {
equal = equal && (layeredTextureInfo[i] == other.layeredTextureInfo[i]);
}
// Commented this for-loop. Not necessary since the keyValuePairs
// are always supposed to be equal. Comparing strings takes time.
/*
for (size_t i = 0; i < keyValuePairs.size(); i++) {
equal = equal && (keyValuePairs[i] == other.keyValuePairs[i]);
}
*/
return equal;
}
}

View File

@@ -739,7 +739,6 @@ namespace openspace {
float noDataValue = _dataset->GetRasterBand(1)->GetNoDataValue();
for (size_t y = 0; y < region.numPixels.y; y++) {
size_t yi = (region.numPixels.y - 1 - y) * bytesPerLine;
@@ -747,6 +746,7 @@ namespace openspace {
for (size_t x = 0; x < region.numPixels.x; x++) {
for (size_t c = 0; c < _dataLayout.numRasters; c++) {
float noDataValue = _dataset->GetRasterBand(c + 1)->GetNoDataValue();
float val = TileDataType::interpretFloat(_dataLayout.gdalType, &(result->imageData[yi + i]));
if (val != noDataValue) {
preprocessData->maxValues[c] = std::max(val, preprocessData->maxValues[c]);