mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-18 10:59:18 -06:00
Clean up and fix comments.
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include <modules/globebrowsing/rendering/chunkrenderer.h>
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -80,7 +79,7 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
void ChunkRenderer::renderChunk(const Chunk& chunk, const RenderData& data) {
|
||||
// A little arbitrary but it works
|
||||
// A little arbitrary with 10 but it works
|
||||
if (chunk.tileIndex().level < 10) {
|
||||
renderChunkGlobally(chunk, data);
|
||||
}
|
||||
@@ -94,8 +93,8 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
ProgramObject* ChunkRenderer::getActivatedProgramWithTileData(
|
||||
LayerShaderManager* layeredTextureShaderProvider,
|
||||
GPULayerManager * gpuLayerManager,
|
||||
std::shared_ptr<LayerShaderManager> layeredShaderManager,
|
||||
std::shared_ptr<GPULayerManager> gpuLayerManager,
|
||||
const Chunk& chunk)
|
||||
{
|
||||
const TileIndex& tileIndex = chunk.tileIndex();
|
||||
@@ -115,22 +114,27 @@ namespace globebrowsing {
|
||||
const auto& debugProps = chunk.owner().debugProperties();
|
||||
auto& pairs = layeredTexturePreprocessingData.keyValuePairs;
|
||||
|
||||
pairs.push_back(std::make_pair("useAtmosphere", std::to_string(generalProps.atmosphereEnabled)));
|
||||
pairs.push_back(std::make_pair("performShading", std::to_string(generalProps.performShading)));
|
||||
pairs.push_back(std::make_pair("showChunkEdges", std::to_string(debugProps.showChunkEdges)));
|
||||
pairs.push_back(std::make_pair("showHeightResolution", std::to_string(debugProps.showHeightResolution)));
|
||||
pairs.push_back(std::make_pair("showHeightIntensities", std::to_string(debugProps.showHeightIntensities)));
|
||||
pairs.push_back(std::make_pair("defaultHeight", std::to_string(Chunk::DEFAULT_HEIGHT)));
|
||||
pairs.push_back(std::make_pair("useAtmosphere",
|
||||
std::to_string(generalProps.atmosphereEnabled)));
|
||||
pairs.push_back(std::make_pair("performShading",
|
||||
std::to_string(generalProps.performShading)));
|
||||
pairs.push_back(std::make_pair("showChunkEdges",
|
||||
std::to_string(debugProps.showChunkEdges)));
|
||||
pairs.push_back(std::make_pair("showHeightResolution",
|
||||
std::to_string(debugProps.showHeightResolution)));
|
||||
pairs.push_back(std::make_pair("showHeightIntensities",
|
||||
std::to_string(debugProps.showHeightIntensities)));
|
||||
pairs.push_back(std::make_pair("defaultHeight",
|
||||
std::to_string(Chunk::DEFAULT_HEIGHT)));
|
||||
|
||||
// Now the shader program can be accessed
|
||||
ProgramObject* programObject =
|
||||
layeredTextureShaderProvider->programObject(
|
||||
layeredShaderManager->programObject(
|
||||
layeredTexturePreprocessingData);
|
||||
|
||||
if (layeredTextureShaderProvider->updatedOnLastCall()) {
|
||||
if (layeredShaderManager->updatedOnLastCall()) {
|
||||
gpuLayerManager->updateUniformLocations(programObject, *_layerManager);
|
||||
}
|
||||
|
||||
|
||||
// Activate the shader program
|
||||
programObject->activate();
|
||||
@@ -138,11 +142,16 @@ namespace globebrowsing {
|
||||
gpuLayerManager->setValue(programObject, *_layerManager, tileIndex);
|
||||
|
||||
// The length of the skirts is proportional to its size
|
||||
programObject->setUniform("skirtLength", min(static_cast<float>(chunk.surfacePatch().halfSize().lat * 1000000), 8700.0f));
|
||||
// TODO: Skirt length should probably be proportional to the size reffered to by
|
||||
// the chunk's most high resolution height map.
|
||||
programObject->setUniform("skirtLength",
|
||||
min(static_cast<float>(chunk.surfacePatch().halfSize().lat * 1000000),
|
||||
8700.0f));
|
||||
programObject->setUniform("xSegments", _grid->xSegments());
|
||||
|
||||
if (chunk.owner().debugProperties().showHeightResolution) {
|
||||
programObject->setUniform("vertexResolution", glm::vec2(_grid->xSegments(), _grid->ySegments()));
|
||||
programObject->setUniform("vertexResolution",
|
||||
glm::vec2(_grid->xSegments(), _grid->ySegments()));
|
||||
}
|
||||
|
||||
return programObject;
|
||||
@@ -151,8 +160,8 @@ namespace globebrowsing {
|
||||
void ChunkRenderer::renderChunkGlobally(const Chunk& chunk, const RenderData& data){
|
||||
|
||||
ProgramObject* programObject = getActivatedProgramWithTileData(
|
||||
_globalLayerShaderManager.get(),
|
||||
_globalGpuLayerManager.get(),
|
||||
_globalLayerShaderManager,
|
||||
_globalGpuLayerManager,
|
||||
chunk);
|
||||
if (programObject == nullptr) {
|
||||
return;
|
||||
@@ -161,12 +170,13 @@ namespace globebrowsing {
|
||||
const Ellipsoid& ellipsoid = chunk.owner().ellipsoid();
|
||||
|
||||
if (_layerManager->hasAnyBlendingLayersEnabled()) {
|
||||
// Calculations are done in the reference frame of the globe. Hence, the camera
|
||||
// position needs to be transformed with the inverse model matrix
|
||||
// Calculations are done in the reference frame of the globe. Hence, the
|
||||
// camera position needs to be transformed with the inverse model matrix
|
||||
glm::dmat4 inverseModelTransform = chunk.owner().inverseModelTransform();
|
||||
glm::dvec3 cameraPosition =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
|
||||
float distanceScaleFactor = chunk.owner().generalProperties().lodScaleFactor * ellipsoid.minimumRadius();
|
||||
glm::dvec3 cameraPosition = glm::dvec3(
|
||||
inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
|
||||
float distanceScaleFactor = chunk.owner().generalProperties().lodScaleFactor *
|
||||
ellipsoid.minimumRadius();
|
||||
programObject->setUniform("cameraPosition", vec3(cameraPosition));
|
||||
programObject->setUniform("distanceScaleFactor", distanceScaleFactor);
|
||||
programObject->setUniform("chunkLevel", chunk.tileIndex().level);
|
||||
@@ -179,32 +189,37 @@ namespace globebrowsing {
|
||||
dmat4 modelTransform = chunk.owner().modelTransform();
|
||||
dmat4 viewTransform = data.camera.combinedViewMatrix();
|
||||
mat4 modelViewTransform = mat4(viewTransform * modelTransform);
|
||||
mat4 modelViewProjectionTransform = data.camera.projectionMatrix() * modelViewTransform;
|
||||
mat4 modelViewProjectionTransform = data.camera.projectionMatrix() *
|
||||
modelViewTransform;
|
||||
|
||||
// Upload the uniform variables
|
||||
programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);
|
||||
programObject->setUniform(
|
||||
"modelViewProjectionTransform", modelViewProjectionTransform);
|
||||
programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2()));
|
||||
programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
|
||||
programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));
|
||||
|
||||
if (_layerManager->layerGroup(LayerManager::NightLayers).activeLayers().size() > 0 ||
|
||||
_layerManager->layerGroup(LayerManager::WaterMasks).activeLayers().size() > 0 ||
|
||||
if (_layerManager->layerGroup(
|
||||
LayerManager::NightLayers).activeLayers().size() > 0 ||
|
||||
_layerManager->layerGroup(
|
||||
LayerManager::WaterMasks).activeLayers().size() > 0 ||
|
||||
chunk.owner().generalProperties().atmosphereEnabled ||
|
||||
chunk.owner().generalProperties().performShading) {
|
||||
// This code temporary until real light sources can be implemented.
|
||||
glm::vec3 directionToSunWorldSpace =
|
||||
glm::normalize(-data.modelTransform.translation);
|
||||
glm::vec3 directionToSunCameraSpace =
|
||||
(viewTransform * glm::dvec4(directionToSunWorldSpace, 0));
|
||||
data.modelTransform.translation;
|
||||
programObject->setUniform("modelViewTransform", modelViewTransform);
|
||||
programObject->setUniform("lightDirectionCameraSpace", -directionToSunCameraSpace);
|
||||
programObject->setUniform(
|
||||
"lightDirectionCameraSpace", -directionToSunCameraSpace);
|
||||
}
|
||||
|
||||
// OpenGL rendering settings
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
|
||||
// render
|
||||
_grid->geometry().drawUsingActiveProgram();
|
||||
@@ -216,13 +231,11 @@ namespace globebrowsing {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChunkRenderer::renderChunkLocally(const Chunk& chunk, const RenderData& data) {
|
||||
|
||||
ProgramObject* programObject = getActivatedProgramWithTileData(
|
||||
_localLayerShaderManager.get(),
|
||||
_localGpuLayerManager.get(),
|
||||
_localLayerShaderManager,
|
||||
_localGpuLayerManager,
|
||||
chunk);
|
||||
if (programObject == nullptr) {
|
||||
return;
|
||||
@@ -234,7 +247,8 @@ namespace globebrowsing {
|
||||
|
||||
|
||||
if (_layerManager->hasAnyBlendingLayersEnabled()) {
|
||||
float distanceScaleFactor = chunk.owner().generalProperties().lodScaleFactor * chunk.owner().ellipsoid().minimumRadius();
|
||||
float distanceScaleFactor = chunk.owner().generalProperties().lodScaleFactor *
|
||||
chunk.owner().ellipsoid().minimumRadius();
|
||||
programObject->setUniform("distanceScaleFactor", distanceScaleFactor);
|
||||
programObject->setUniform("chunkLevel", chunk.tileIndex().level);
|
||||
}
|
||||
@@ -250,20 +264,27 @@ namespace globebrowsing {
|
||||
Quad q = (Quad)i;
|
||||
Geodetic2 corner = chunk.surfacePatch().getCorner(q);
|
||||
Vec3 cornerModelSpace = ellipsoid.cartesianSurfacePosition(corner);
|
||||
Vec3 cornerCameraSpace = Vec3(dmat4(modelViewTransform) * glm::dvec4(cornerModelSpace, 1));
|
||||
Vec3 cornerCameraSpace =
|
||||
Vec3(dmat4(modelViewTransform) * glm::dvec4(cornerModelSpace, 1));
|
||||
cornersCameraSpace[i] = cornerCameraSpace;
|
||||
programObject->setUniform(cornerNames[i], vec3(cornerCameraSpace));
|
||||
}
|
||||
|
||||
// TODO: Patch normal can be calculated for all corners and then linearly
|
||||
// interpolated on the GPU to avoid cracks for high altitudes.
|
||||
vec3 patchNormalCameraSpace = normalize(
|
||||
cross(cornersCameraSpace[Quad::SOUTH_EAST] - cornersCameraSpace[Quad::SOUTH_WEST],
|
||||
cornersCameraSpace[Quad::NORTH_EAST] - cornersCameraSpace[Quad::SOUTH_WEST]));
|
||||
cross(cornersCameraSpace[Quad::SOUTH_EAST] -
|
||||
cornersCameraSpace[Quad::SOUTH_WEST],
|
||||
cornersCameraSpace[Quad::NORTH_EAST] -
|
||||
cornersCameraSpace[Quad::SOUTH_WEST]));
|
||||
|
||||
programObject->setUniform("patchNormalCameraSpace", patchNormalCameraSpace);
|
||||
programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
|
||||
|
||||
if (_layerManager->layerGroup(LayerManager::NightLayers).activeLayers().size() > 0 ||
|
||||
_layerManager->layerGroup(LayerManager::WaterMasks).activeLayers().size() > 0 ||
|
||||
if (_layerManager->layerGroup(
|
||||
LayerManager::NightLayers).activeLayers().size() > 0 ||
|
||||
_layerManager->layerGroup(
|
||||
LayerManager::WaterMasks).activeLayers().size() > 0 ||
|
||||
chunk.owner().generalProperties().atmosphereEnabled ||
|
||||
chunk.owner().generalProperties().performShading)
|
||||
{
|
||||
@@ -272,10 +293,10 @@ namespace globebrowsing {
|
||||
glm::vec3 directionToSunCameraSpace =
|
||||
(viewTransform * glm::dvec4(directionToSunWorldSpace, 0));
|
||||
data.modelTransform.translation;
|
||||
programObject->setUniform("lightDirectionCameraSpace", -directionToSunCameraSpace);
|
||||
programObject->setUniform(
|
||||
"lightDirectionCameraSpace", -directionToSunCameraSpace);
|
||||
}
|
||||
|
||||
|
||||
// OpenGL rendering settings
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
@@ -288,8 +309,6 @@ namespace globebrowsing {
|
||||
|
||||
// disable shader
|
||||
programObject->deactivate();
|
||||
|
||||
|
||||
}
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
@@ -87,8 +86,8 @@ namespace globebrowsing {
|
||||
|
||||
|
||||
ProgramObject* getActivatedProgramWithTileData(
|
||||
LayerShaderManager* layeredTextureShaderProvider,
|
||||
GPULayerManager * gpuLayerManager,
|
||||
std::shared_ptr<LayerShaderManager> layeredShaderManager,
|
||||
std::shared_ptr<GPULayerManager> gpuLayerManager,
|
||||
const Chunk& chunk);
|
||||
|
||||
// shared pointer to a grid which can be the same for all rendered chunks.
|
||||
|
||||
@@ -48,61 +48,78 @@ namespace globebrowsing {
|
||||
|
||||
// TileUvTransform
|
||||
|
||||
void GPUTileUvTransform::setValue(ProgramObject* programObject, const TileUvTransform& tileUvTransform){
|
||||
void GPUTileUvTransform::setValue(
|
||||
ProgramObject* programObject,
|
||||
const TileUvTransform& tileUvTransform) {
|
||||
gpuUvOffset.setValue(programObject, tileUvTransform.uvOffset);
|
||||
gpuUvScale.setValue(programObject, tileUvTransform.uvScale);
|
||||
}
|
||||
|
||||
void GPUTileUvTransform::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase){
|
||||
void GPUTileUvTransform::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase) {
|
||||
gpuUvOffset.updateUniformLocations(programObject, nameBase + "uvOffset");
|
||||
gpuUvScale.updateUniformLocations(programObject, nameBase + "uvScale");
|
||||
}
|
||||
|
||||
|
||||
// TileDepthTransform
|
||||
|
||||
void GPUTileDepthTransform::setValue(ProgramObject* programObject, const TileDepthTransform& depthTransform){
|
||||
void GPUTileDepthTransform::setValue(
|
||||
ProgramObject* programObject,
|
||||
const TileDepthTransform& depthTransform) {
|
||||
gpuDepthOffset.setValue(programObject, depthTransform.depthOffset);
|
||||
gpuDepthScale.setValue(programObject, depthTransform.depthScale);
|
||||
}
|
||||
|
||||
void GPUTileDepthTransform::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase){
|
||||
void GPUTileDepthTransform::updateUniformLocations(
|
||||
ProgramObject* programObject, const std::string& nameBase) {
|
||||
gpuDepthOffset.updateUniformLocations(programObject, nameBase + "depthOffset");
|
||||
gpuDepthScale.updateUniformLocations(programObject, nameBase + "depthScale");
|
||||
}
|
||||
|
||||
|
||||
// ChunkTile
|
||||
|
||||
void GPUChunkTile::setValue(ProgramObject* programObject, const ChunkTile& chunkTile){
|
||||
void GPUChunkTile::setValue(
|
||||
ProgramObject* programObject,
|
||||
const ChunkTile& chunkTile) {
|
||||
gpuTexture.setValue(programObject, chunkTile.tile.texture);
|
||||
gpuTileUvTransform.setValue(programObject, chunkTile.uvTransform);
|
||||
}
|
||||
|
||||
void GPUChunkTile::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase){
|
||||
void GPUChunkTile::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase) {
|
||||
gpuTexture.updateUniformLocations(programObject, nameBase + "textureSampler");
|
||||
gpuTileUvTransform.updateUniformLocations(programObject, nameBase + "uvTransform.");
|
||||
gpuTileUvTransform.updateUniformLocations(
|
||||
programObject, nameBase + "uvTransform.");
|
||||
}
|
||||
|
||||
void GPUChunkTile::deactivate(){
|
||||
gpuTexture.deactivate();
|
||||
}
|
||||
|
||||
|
||||
// ChunkTilePile
|
||||
|
||||
void GPUChunkTilePile::setValue(ProgramObject* programObject, const ChunkTilePile& chunkTilePile){
|
||||
ghoul_assert(gpuChunkTiles.size() == chunkTilePile.chunkTiles.size(), "GPU and CPU ChunkTilePile must have same size!");
|
||||
void GPUChunkTilePile::setValue(
|
||||
ProgramObject* programObject,
|
||||
const ChunkTilePile& chunkTilePile) {
|
||||
ghoul_assert(
|
||||
gpuChunkTiles.size() == chunkTilePile.chunkTiles.size(),
|
||||
"GPU and CPU ChunkTilePile must have same size!");
|
||||
for (size_t i = 0; i < gpuChunkTiles.size(); ++i){
|
||||
gpuChunkTiles[i].setValue(programObject, chunkTilePile.chunkTiles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUChunkTilePile::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize){
|
||||
void GPUChunkTilePile::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase,
|
||||
int pileSize) {
|
||||
gpuChunkTiles.resize(pileSize);
|
||||
for (size_t i = 0; i < gpuChunkTiles.size(); ++i){
|
||||
std::string nameExtension = "chunkTile" + std::to_string(i) + ".";
|
||||
gpuChunkTiles[i].updateUniformLocations(programObject, nameBase + nameExtension);
|
||||
gpuChunkTiles[i].updateUniformLocations(
|
||||
programObject, nameBase + nameExtension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,64 +129,91 @@ namespace globebrowsing {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GPULayerRenderSettings::setValue(ProgramObject* programObject, const LayerRenderSettings& layerSettings){
|
||||
void GPULayerRenderSettings::setValue(
|
||||
ProgramObject* programObject,
|
||||
const LayerRenderSettings& layerSettings) {
|
||||
gpuOpacity.setValue(programObject, layerSettings.opacity.value());
|
||||
gpuGamma.setValue(programObject, layerSettings.gamma.value());
|
||||
gpuMultiplier.setValue(programObject, layerSettings.multiplier.value());
|
||||
}
|
||||
|
||||
void GPULayerRenderSettings::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase){
|
||||
void GPULayerRenderSettings::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase) {
|
||||
gpuOpacity.updateUniformLocations(programObject, nameBase + "opacity");
|
||||
gpuGamma.updateUniformLocations(programObject, nameBase + "gamma");
|
||||
gpuMultiplier.updateUniformLocations(programObject, nameBase + "multiplier");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Layer
|
||||
|
||||
void GPULayer::setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize){
|
||||
void GPULayer::setValue(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const TileIndex& tileIndex,
|
||||
int pileSize) {
|
||||
ChunkTilePile chunkTilePile = layer.getChunkTilePile(tileIndex, pileSize);
|
||||
gpuChunkTilePile.setValue(programObject, chunkTilePile);
|
||||
gpuRenderSettings.setValue(programObject, layer.renderSettings());
|
||||
}
|
||||
|
||||
void GPULayer::updateUniformLocations(ProgramObject* programObject, const Layer& layer, const std::string& nameBase, int pileSize){
|
||||
gpuChunkTilePile.updateUniformLocations(programObject, nameBase + "pile.", pileSize);
|
||||
gpuRenderSettings.updateUniformLocations(programObject, nameBase + "settings.");
|
||||
void GPULayer::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const std::string& nameBase,
|
||||
int pileSize) {
|
||||
gpuChunkTilePile.updateUniformLocations(
|
||||
programObject, nameBase + "pile.", pileSize);
|
||||
gpuRenderSettings.updateUniformLocations(
|
||||
programObject, nameBase + "settings.");
|
||||
}
|
||||
|
||||
void GPULayer::deactivate(){
|
||||
gpuChunkTilePile.deactivate();
|
||||
}
|
||||
|
||||
|
||||
// Override behavior for HeightLayer
|
||||
|
||||
void GPUHeightLayer::setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize){
|
||||
void GPUHeightLayer::setValue(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const TileIndex& tileIndex,
|
||||
int pileSize) {
|
||||
GPULayer::setValue(programObject, layer, tileIndex, pileSize);
|
||||
gpuDepthTransform.setValue(programObject, layer.tileProvider()->depthTransform());
|
||||
}
|
||||
|
||||
void GPUHeightLayer::updateUniformLocations(ProgramObject* programObject, const Layer& layer, const std::string& nameBase, int pileSize){
|
||||
void GPUHeightLayer::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const std::string& nameBase,
|
||||
int pileSize) {
|
||||
GPULayer::updateUniformLocations(programObject, layer, nameBase, pileSize);
|
||||
gpuDepthTransform.updateUniformLocations(programObject, nameBase + "depthTransform.");
|
||||
gpuDepthTransform.updateUniformLocations(
|
||||
programObject, nameBase + "depthTransform.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// LayerGroup
|
||||
|
||||
void GPULayerGroup::setValue(ProgramObject* programObject, const LayerGroup& layerGroup, const TileIndex& tileIndex){
|
||||
void GPULayerGroup::setValue(
|
||||
ProgramObject* programObject,
|
||||
const LayerGroup& layerGroup,
|
||||
const TileIndex& tileIndex) {
|
||||
auto& activeLayers = layerGroup.activeLayers();
|
||||
ghoul_assert(activeLayers.size() == gpuActiveLayers.size(), "GPU and CPU active layers must have same size!");
|
||||
ghoul_assert(
|
||||
activeLayers.size() == gpuActiveLayers.size(),
|
||||
"GPU and CPU active layers must have same size!");
|
||||
for (int i = 0; i < activeLayers.size(); ++i){
|
||||
gpuActiveLayers[i]->setValue(programObject, *activeLayers[i], tileIndex, layerGroup.pileSize());
|
||||
gpuActiveLayers[i]->setValue(
|
||||
programObject, *activeLayers[i], tileIndex, layerGroup.pileSize());
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::updateUniformLocations(ProgramObject* programObject, const LayerGroup& layerGroup, const std::string& nameBase, int category){
|
||||
void GPULayerGroup::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const LayerGroup& layerGroup,
|
||||
const std::string& nameBase,
|
||||
int category) {
|
||||
auto activeLayers = layerGroup.activeLayers();
|
||||
gpuActiveLayers.resize(activeLayers.size());
|
||||
int pileSize = layerGroup.pileSize();
|
||||
@@ -179,27 +223,32 @@ namespace globebrowsing {
|
||||
std::make_unique<GPUHeightLayer>() :
|
||||
std::make_unique<GPULayer>();
|
||||
std::string nameExtension = "[" + std::to_string(i) + "].";
|
||||
gpuActiveLayers[i]->updateUniformLocations(programObject, *activeLayers[i], nameBase + nameExtension, pileSize);
|
||||
gpuActiveLayers[i]->updateUniformLocations(
|
||||
programObject, *activeLayers[i], nameBase + nameExtension, pileSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::deactivate(){
|
||||
void GPULayerGroup::deactivate() {
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i){
|
||||
gpuActiveLayers[i]->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// LayerManager
|
||||
|
||||
void GPULayerManager::setValue(ProgramObject* programObject, const LayerManager& layerManager, const TileIndex& tileIndex){
|
||||
void GPULayerManager::setValue(
|
||||
ProgramObject* programObject,
|
||||
const LayerManager& layerManager,
|
||||
const TileIndex& tileIndex) {
|
||||
auto layerGroups = layerManager.layerGroups();
|
||||
for (size_t i = 0; i < layerGroups.size(); ++i){
|
||||
gpuLayerGroups[i]->setValue(programObject, *layerGroups[i], tileIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerManager::updateUniformLocations(ProgramObject* programObject, const LayerManager& layerManager){
|
||||
void GPULayerManager::updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const LayerManager& layerManager) {
|
||||
auto layerGroups = layerManager.layerGroups();
|
||||
if(gpuLayerGroups.size() != layerGroups.size()){
|
||||
gpuLayerGroups.resize(layerGroups.size());
|
||||
@@ -210,7 +259,8 @@ namespace globebrowsing {
|
||||
|
||||
for (size_t i = 0; i < layerGroups.size(); ++i){
|
||||
std::string nameBase = LayerManager::LAYER_GROUP_NAMES[i];
|
||||
gpuLayerGroups[i]->updateUniformLocations(programObject, *layerGroups[i], nameBase, i);
|
||||
gpuLayerGroups[i]->updateUniformLocations(
|
||||
programObject, *layerGroups[i], nameBase, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,8 +270,5 @@ namespace globebrowsing {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -35,50 +35,47 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace ghoul{
|
||||
namespace opengl{
|
||||
class ProgramObject;
|
||||
}//namespace opengl
|
||||
}//namespace ghoul
|
||||
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
|
||||
class GPUTileUvTransform {
|
||||
public:
|
||||
|
||||
void setValue(ProgramObject* programObject, const TileUvTransform& uvTransform);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase);
|
||||
void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<glm::vec2> gpuUvOffset;
|
||||
GPUData<glm::vec2> gpuUvScale;
|
||||
};
|
||||
|
||||
|
||||
class GPUTileDepthTransform {
|
||||
public:
|
||||
|
||||
void setValue(ProgramObject* programObject, const TileDepthTransform& depthTransform);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase);
|
||||
void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<float> gpuDepthOffset;
|
||||
GPUData<float> gpuDepthScale;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class GPUChunkTile {
|
||||
public:
|
||||
|
||||
void setValue(ProgramObject* programObject, const ChunkTile& chunkTile);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase);
|
||||
void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase);
|
||||
void deactivate();
|
||||
|
||||
private:
|
||||
@@ -86,27 +83,26 @@ private:
|
||||
GPUTileUvTransform gpuTileUvTransform;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class GPUChunkTilePile{
|
||||
public:
|
||||
|
||||
public:
|
||||
void setValue(ProgramObject* programObject, const ChunkTilePile& chunkTilePile);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize);
|
||||
void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase,
|
||||
int pileSize);
|
||||
void deactivate();
|
||||
|
||||
private:
|
||||
|
||||
std::vector<GPUChunkTile> gpuChunkTiles;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LayerRenderSettings;
|
||||
class GPULayerRenderSettings{
|
||||
public:
|
||||
void setValue(ProgramObject* programObject, const LayerRenderSettings& layerSettings);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase);
|
||||
void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<float> gpuOpacity;
|
||||
@@ -114,12 +110,19 @@ private:
|
||||
GPUData<float> gpuMultiplier;
|
||||
};
|
||||
|
||||
|
||||
class Layer;
|
||||
class GPULayer {
|
||||
public:
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const Layer& layer, const std::string& nameBase, int pileSize);
|
||||
virtual void setValue(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const TileIndex& tileIndex,
|
||||
int pileSize);
|
||||
virtual void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const std::string& nameBase,
|
||||
int pileSize);
|
||||
virtual void deactivate();
|
||||
private:
|
||||
GPUChunkTilePile gpuChunkTilePile;
|
||||
@@ -128,38 +131,52 @@ private:
|
||||
|
||||
class GPUHeightLayer : public GPULayer{
|
||||
public:
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const Layer& layer, const std::string& nameBase, int pileSize);
|
||||
virtual void setValue(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const TileIndex& tileIndex,
|
||||
int pileSize);
|
||||
virtual void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const Layer& layer,
|
||||
const std::string& nameBase,
|
||||
int pileSize);
|
||||
private:
|
||||
GPUTileDepthTransform gpuDepthTransform;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LayerGroup;
|
||||
class GPULayerGroup{
|
||||
public:
|
||||
|
||||
virtual void setValue(ProgramObject* programObject, const LayerGroup& layerGroup, const TileIndex& tileIndex);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const LayerGroup& layerGroup, const std::string& nameBase, int category);
|
||||
virtual void setValue(
|
||||
ProgramObject* programObject,
|
||||
const LayerGroup& layerGroup,
|
||||
const TileIndex& tileIndex);
|
||||
virtual void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const LayerGroup& layerGroup,
|
||||
const std::string& nameBase,
|
||||
int category);
|
||||
virtual void deactivate();
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayer>> gpuActiveLayers;
|
||||
};
|
||||
|
||||
|
||||
class LayerManager;
|
||||
class GPULayerManager{
|
||||
public:
|
||||
|
||||
virtual void setValue(ProgramObject* programObject, const LayerManager& layerManager, const TileIndex& tileIndex);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const LayerManager& layerManager);
|
||||
public:
|
||||
virtual void setValue(
|
||||
ProgramObject* programObject,
|
||||
const LayerManager& layerManager,
|
||||
const TileIndex& tileIndex);
|
||||
virtual void updateUniformLocations(
|
||||
ProgramObject* programObject,
|
||||
const LayerManager& layerManager);
|
||||
virtual void deactivate();
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayerGroup>> gpuLayerGroups;
|
||||
};
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
#endif // __GPU_LAYER_MANAGER_H__
|
||||
#endif // __GPU_LAYER_MANAGER_H__
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __LAYER_MANAGER_H__
|
||||
#define __LAYER_MANAGER_H__
|
||||
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
#include <modules/globebrowsing/tile/tileselector.h>
|
||||
|
||||
@@ -39,15 +39,14 @@ namespace {
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
bool LayerGroupPreprocessingData::operator==(const LayerGroupPreprocessingData& other) const {
|
||||
bool LayerGroupPreprocessingData::operator==(
|
||||
const LayerGroupPreprocessingData& other) const {
|
||||
return lastLayerIdx == other.lastLayerIdx &&
|
||||
layerBlendingEnabled == other.layerBlendingEnabled;
|
||||
}
|
||||
|
||||
bool LayerShaderPreprocessingData::operator==(
|
||||
const LayerShaderPreprocessingData& other) const
|
||||
{
|
||||
|
||||
const LayerShaderPreprocessingData& other) const {
|
||||
if (layeredTextureInfo.size() != other.layeredTextureInfo.size() ||
|
||||
keyValuePairs.size() != other.keyValuePairs.size()) {
|
||||
return false;
|
||||
@@ -71,10 +70,7 @@ namespace globebrowsing {
|
||||
: _shaderName(shaderName)
|
||||
, _vsPath(vsPath)
|
||||
, _fsPath(fsPath)
|
||||
, _updatedOnLastCall(false)
|
||||
{
|
||||
|
||||
}
|
||||
, _updatedOnLastCall(false) { }
|
||||
|
||||
LayerShaderManager::~LayerShaderManager() {
|
||||
if (_programObject) {
|
||||
@@ -85,8 +81,7 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
ProgramObject* LayerShaderManager::programObject(
|
||||
LayerShaderPreprocessingData preprocessingData)
|
||||
{
|
||||
LayerShaderPreprocessingData preprocessingData) {
|
||||
_updatedOnLastCall = false;
|
||||
if (!(preprocessingData == _preprocessingData) || _programObject == nullptr) {
|
||||
recompileShaderProgram(preprocessingData);
|
||||
@@ -96,22 +91,23 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
void LayerShaderManager::recompileShaderProgram(
|
||||
LayerShaderPreprocessingData preprocessingData)
|
||||
{
|
||||
LayerShaderPreprocessingData preprocessingData) {
|
||||
_preprocessingData = preprocessingData;
|
||||
ghoul::Dictionary shaderDictionary;
|
||||
|
||||
|
||||
// Different texture types can be height maps or color texture for example.
|
||||
// Different layer types can be height layers or color layers for example.
|
||||
// These are used differently within the shaders.
|
||||
auto textureTypes = _preprocessingData.layeredTextureInfo;
|
||||
for (size_t i = 0; i < textureTypes.size(); i++) {
|
||||
// lastLayerIndex must be at least 0 for the shader to compile,
|
||||
// the layer type is inactivated by setting use to false
|
||||
std::string groupName = LayerManager::LAYER_GROUP_NAMES[i];
|
||||
shaderDictionary.setValue("lastLayerIndex" + groupName, glm::max(textureTypes[i].lastLayerIdx, 0));
|
||||
shaderDictionary.setValue("use" + groupName, textureTypes[i].lastLayerIdx >= 0);
|
||||
shaderDictionary.setValue("blend" + groupName, textureTypes[i].layerBlendingEnabled);
|
||||
shaderDictionary.setValue(
|
||||
"lastLayerIndex" + groupName, glm::max(textureTypes[i].lastLayerIdx, 0));
|
||||
shaderDictionary.setValue(
|
||||
"use" + groupName, textureTypes[i].lastLayerIdx >= 0);
|
||||
shaderDictionary.setValue(
|
||||
"blend" + groupName, textureTypes[i].layerBlendingEnabled);
|
||||
}
|
||||
|
||||
// Other settings such as "useAtmosphere"
|
||||
@@ -139,4 +135,4 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
@@ -42,7 +42,7 @@ namespace globebrowsing {
|
||||
class LayerManager;
|
||||
|
||||
/**
|
||||
* Settings per texture category that contains shader preprocessing information.
|
||||
* Settings per texture group that contains shader preprocessing information.
|
||||
*/
|
||||
struct LayerGroupPreprocessingData {
|
||||
int lastLayerIdx;
|
||||
@@ -56,12 +56,13 @@ namespace globebrowsing {
|
||||
*
|
||||
* If a <code>LayerShaderPreprocessingData</code> is compared with another it can
|
||||
* be determined wheter or not a <code>LayerShaderManager</code> needs to
|
||||
* recompile its shader program. For each <code>TextureCategory</code> there is
|
||||
* recompile its shader program. For each <code>TextureGroup</code> there is
|
||||
* information about how many layers it has and whether or not to blend the texture
|
||||
* levels.
|
||||
*/
|
||||
struct LayerShaderPreprocessingData {
|
||||
std::array<LayerGroupPreprocessingData, LayerManager::NUM_LAYER_GROUPS> layeredTextureInfo;
|
||||
std::array<LayerGroupPreprocessingData, LayerManager::NUM_LAYER_GROUPS>
|
||||
layeredTextureInfo;
|
||||
std::vector<std::pair<std::string, std::string> > keyValuePairs;
|
||||
bool operator==(const LayerShaderPreprocessingData& other) const;
|
||||
};
|
||||
@@ -103,8 +104,7 @@ namespace globebrowsing {
|
||||
bool _updatedOnLastCall;
|
||||
};
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __LAYER_SHADER_MANAGER_H__
|
||||
#endif // __LAYER_SHADER_MANAGER_H__
|
||||
Reference in New Issue
Block a user