mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 17:09:05 -05:00
Intermediate commit: Pre gpu layer refactorization
This commit is contained in:
@@ -218,12 +218,13 @@ namespace globebrowsing {
|
||||
// Go through all the categories
|
||||
for (size_t category = 0; category < LayeredTextures::NUM_TEXTURE_CATEGORIES; category++) {
|
||||
LayerGroup& layerGroup = _layerManager->layerGroup(category);
|
||||
GPULayerGroup& gpuLayerGroup = programUniformHandler->_gpuLayerGroups[category];
|
||||
GPULayerGroup* gpuLayerGroup = programUniformHandler->gpuLayerGroup(category);
|
||||
|
||||
int pileSize = layerGroup.levelBlendingEnabled ? 3 : 1;
|
||||
gpuLayerGroup->setValue(programObject, layerGroup, tileIndex, pileSize);
|
||||
|
||||
int i = 0;
|
||||
for (const Layer& layer : layerGroup.activeLayers()) {
|
||||
int pileSize = layerGroup.levelBlendingEnabled ? 3 : 1;
|
||||
gpuLayerGroup.setValue(programObject, layerGroup, tileIndex, pileSize);
|
||||
|
||||
setLayerSettingsUniforms(
|
||||
programObject,
|
||||
programUniformHandler,
|
||||
@@ -357,8 +358,8 @@ namespace globebrowsing {
|
||||
// render
|
||||
_grid->geometry().drawUsingActiveProgram();
|
||||
|
||||
for (auto& layerGroup : _globalProgramUniformHandler->_gpuLayerGroups) {
|
||||
layerGroup.deactivate();
|
||||
for (int i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; ++i) {
|
||||
_globalProgramUniformHandler->gpuLayerGroup(i)->deactivate();
|
||||
}
|
||||
|
||||
// disable shader
|
||||
@@ -443,6 +444,10 @@ namespace globebrowsing {
|
||||
|
||||
// render
|
||||
_grid->geometry().drawUsingActiveProgram();
|
||||
|
||||
for (int i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; ++i) {
|
||||
_localProgramUniformHandler->gpuLayerGroup(i)->deactivate();
|
||||
}
|
||||
|
||||
// disable shader
|
||||
programObject->deactivate();
|
||||
|
||||
@@ -154,11 +154,19 @@ namespace globebrowsing {
|
||||
return _updatedOnLastCall;
|
||||
}
|
||||
|
||||
LayeredTextureShaderUniformIdHandler::LayeredTextureShaderUniformIdHandler()
|
||||
{}
|
||||
LayeredTextureShaderUniformIdHandler::LayeredTextureShaderUniformIdHandler(){
|
||||
for (size_t i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; i++) {
|
||||
_gpuLayerGroups[i] = std::make_unique<GPULayerGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
LayeredTextureShaderUniformIdHandler::~LayeredTextureShaderUniformIdHandler()
|
||||
{}
|
||||
|
||||
GPULayerGroup* LayeredTextureShaderUniformIdHandler::gpuLayerGroup(int i) const{
|
||||
return _gpuLayerGroups[i].get();
|
||||
}
|
||||
|
||||
|
||||
void LayeredTextureShaderUniformIdHandler::updateIdsIfNecessary(
|
||||
LayeredTextureShaderProvider* shaderProvider, LayerManager* layerManager) {
|
||||
@@ -174,7 +182,7 @@ namespace globebrowsing {
|
||||
std::string nameBase = LayeredTextures::TEXTURE_CATEGORY_NAMES[category];
|
||||
int pileSize = layerGroup.levelBlendingEnabled ? 3 : 1;
|
||||
int numActiveLayers = layerGroup.activeLayers().size();
|
||||
_gpuLayerGroups[category].updateUniformLocations(programObject, nameBase, pileSize, numActiveLayers);
|
||||
_gpuLayerGroups[category]->updateUniformLocations(programObject, nameBase, pileSize, numActiveLayers);
|
||||
}
|
||||
|
||||
// Ignore errors since this loops through even uniforms that does not exist.
|
||||
|
||||
@@ -131,9 +131,11 @@ namespace globebrowsing {
|
||||
size_t layerIndex,
|
||||
LayeredTextures::LayerSettingsIds layerSettingsId);
|
||||
ProgramObject& programObject();
|
||||
|
||||
std::array<GPULayerGroup, LayeredTextures::NUM_TEXTURE_CATEGORIES> _gpuLayerGroups;
|
||||
|
||||
GPULayerGroup* gpuLayerGroup(int i) const;
|
||||
|
||||
private:
|
||||
std::array<std::unique_ptr<GPULayerGroup>, LayeredTextures::NUM_TEXTURE_CATEGORIES> _gpuLayerGroups;
|
||||
|
||||
std::array<
|
||||
std::array<
|
||||
|
||||
@@ -114,8 +114,6 @@ struct Layer {
|
||||
LayerSettings settings;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct LevelWeights {
|
||||
float w1;
|
||||
float w2;
|
||||
|
||||
@@ -79,13 +79,11 @@ namespace globebrowsing {
|
||||
void GPUChunkTile::setValue(ProgramObject* programObject, const ChunkTile& chunkTile){
|
||||
gpuTexture.setValue(programObject, chunkTile.tile.texture);
|
||||
gpuTileUvTransform.setValue(programObject, chunkTile.uvTransform);
|
||||
gpuTileDepthTransform.setValue(programObject, chunkTile.depthTransform);
|
||||
}
|
||||
|
||||
void GPUChunkTile::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase){
|
||||
gpuTexture.updateUniformLocations(programObject, nameBase + "textureSampler");
|
||||
gpuTileUvTransform.updateUniformLocations(programObject, nameBase + "uvTransform.");
|
||||
gpuTileDepthTransform.updateUniformLocations(programObject, nameBase + "depthTransform.");
|
||||
}
|
||||
|
||||
void GPUChunkTile::deactivate(){
|
||||
@@ -135,6 +133,19 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
|
||||
// Override behavior for HeightLayer
|
||||
|
||||
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 std::string& nameBase, int pileSize){
|
||||
GPULayer::updateUniformLocations(programObject, nameBase, pileSize);
|
||||
gpuDepthTransform.updateUniformLocations(programObject, nameBase);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// LayerGroup
|
||||
|
||||
@@ -142,25 +153,31 @@ namespace globebrowsing {
|
||||
auto& activeLayers = layerGroup.activeLayers();
|
||||
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, pileSize);
|
||||
gpuActiveLayers[i]->setValue(programObject, activeLayers[i], tileIndex, pileSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize, int numActiveLayers){
|
||||
gpuActiveLayers.resize(numActiveLayers);
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i){
|
||||
gpuActiveLayers[i] = std::make_unique<GPULayer>();
|
||||
std::string nameExtension = "[" + std::to_string(i) + "].";
|
||||
gpuActiveLayers[i].updateUniformLocations(programObject, nameBase + nameExtension, pileSize);
|
||||
gpuActiveLayers[i]->updateUniformLocations(programObject, nameBase + nameExtension, pileSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::deactivate(){
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i){
|
||||
gpuActiveLayers[i].deactivate();
|
||||
gpuActiveLayers[i]->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
|
||||
@@ -82,7 +82,6 @@ public:
|
||||
private:
|
||||
GPUTexture gpuTexture;
|
||||
GPUTileUvTransform gpuTileUvTransform;
|
||||
GPUTileDepthTransform gpuTileDepthTransform;
|
||||
};
|
||||
|
||||
|
||||
@@ -117,29 +116,37 @@ private:
|
||||
class Layer;
|
||||
class GPULayer {
|
||||
public:
|
||||
void setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize);
|
||||
void deactivate();
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize);
|
||||
virtual void deactivate();
|
||||
private:
|
||||
GPUChunkTilePile gpuChunkTilePile;
|
||||
GPULayerSettings gpuLayerSettings;
|
||||
};
|
||||
|
||||
class GPUHeightLayer : public GPULayer{
|
||||
public:
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer, const TileIndex& tileIndex, int pileSize);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize);
|
||||
private:
|
||||
GPUTileDepthTransform gpuDepthTransform;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LayerGroup;
|
||||
class GPULayerGroup{
|
||||
public:
|
||||
|
||||
void setValue(ProgramObject* programObject, const LayerGroup& layerGroup, const TileIndex& tileIndex, int pileSize);
|
||||
void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize, int numActiveLayers);
|
||||
void deactivate();
|
||||
|
||||
std::vector<GPULayer> gpuActiveLayers;
|
||||
|
||||
|
||||
virtual void setValue(ProgramObject* programObject, const LayerGroup& layerGroup, const TileIndex& tileIndex, int pileSize);
|
||||
virtual void updateUniformLocations(ProgramObject* programObject, const std::string& nameBase, int pileSize, int numActiveLayers);
|
||||
virtual void deactivate();
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayer>> gpuActiveLayers;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
#endif // GPU_STRUCTS_H
|
||||
|
||||
Reference in New Issue
Block a user