mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 13:08:49 -05:00
Add display showing the number of active layers
Automatically disable last layer if number of texture units is exhausted Closes #427
This commit is contained in:
+1
-1
Submodule ext/ghoul updated: 30a5be7593...e2e53560b6
@@ -185,7 +185,7 @@ Layer::Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict,
|
||||
// On change callbacks definitions
|
||||
_enabled.onChange([&]() {
|
||||
if (_onChangeCallback) {
|
||||
_onChangeCallback();
|
||||
_onChangeCallback(this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -232,19 +232,19 @@ Layer::Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict,
|
||||
initializeBasedOnType(type(), {});
|
||||
addVisibleProperties();
|
||||
if (_onChangeCallback) {
|
||||
_onChangeCallback();
|
||||
_onChangeCallback(this);
|
||||
}
|
||||
});
|
||||
|
||||
_blendModeOption.onChange([&]() {
|
||||
if (_onChangeCallback) {
|
||||
_onChangeCallback();
|
||||
_onChangeCallback(this);
|
||||
}
|
||||
});
|
||||
|
||||
_layerAdjustment.onChange([&]() {
|
||||
if (_onChangeCallback) {
|
||||
_onChangeCallback();
|
||||
_onChangeCallback(this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -313,6 +313,10 @@ TileDepthTransform Layer::depthTransform() const {
|
||||
TileDepthTransform{ 1.f, 0.f };
|
||||
}
|
||||
|
||||
void Layer::setEnabled(bool enabled) {
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
bool Layer::enabled() const {
|
||||
return _enabled;
|
||||
}
|
||||
@@ -333,7 +337,7 @@ const LayerAdjustment& Layer::layerAdjustment() const {
|
||||
return _layerAdjustment;
|
||||
}
|
||||
|
||||
void Layer::onChange(std::function<void(void)> callback) {
|
||||
void Layer::onChange(std::function<void(Layer*)> callback) {
|
||||
_onChangeCallback = std::move(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,13 +55,14 @@ public:
|
||||
layergroupid::TypeID type() const;
|
||||
layergroupid::BlendModeID blendMode() const;
|
||||
TileDepthTransform depthTransform() const;
|
||||
void setEnabled(bool enabled);
|
||||
bool enabled() const;
|
||||
tileprovider::TileProvider* tileProvider() const;
|
||||
glm::vec3 solidColor() const;
|
||||
const LayerRenderSettings& renderSettings() const;
|
||||
const LayerAdjustment& layerAdjustment() const;
|
||||
|
||||
void onChange(std::function<void(void)> callback);
|
||||
void onChange(std::function<void(Layer*)> callback);
|
||||
|
||||
void update();
|
||||
|
||||
@@ -93,7 +94,7 @@ private:
|
||||
|
||||
const layergroupid::GroupID _layerGroupId;
|
||||
|
||||
std::function<void(void)> _onChangeCallback;
|
||||
std::function<void(Layer*)> _onChangeCallback;
|
||||
};
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
@@ -120,7 +120,7 @@ Layer* LayerGroup::addLayer(const ghoul::Dictionary& layerDict) {
|
||||
_layers.push_back(std::move(layer));
|
||||
update();
|
||||
if (_onChangeCallback) {
|
||||
_onChangeCallback();
|
||||
_onChangeCallback(ptr);
|
||||
}
|
||||
addPropertySubOwner(ptr);
|
||||
_levelBlendingEnabled.setVisibility(properties::Property::Visibility::User);
|
||||
@@ -138,7 +138,7 @@ void LayerGroup::deleteLayer(const std::string& layerName) {
|
||||
_layers.erase(it);
|
||||
update();
|
||||
if (_onChangeCallback) {
|
||||
_onChangeCallback();
|
||||
_onChangeCallback(nullptr);
|
||||
}
|
||||
LINFO("Deleted layer " + layerName);
|
||||
|
||||
@@ -174,9 +174,9 @@ bool LayerGroup::layerBlendingEnabled() const {
|
||||
return _levelBlendingEnabled;
|
||||
}
|
||||
|
||||
void LayerGroup::onChange(std::function<void(void)> callback) {
|
||||
void LayerGroup::onChange(std::function<void(Layer*)> callback) {
|
||||
_onChangeCallback = std::move(callback);
|
||||
_levelBlendingEnabled.onChange(_onChangeCallback);
|
||||
_levelBlendingEnabled.onChange([this]() {_onChangeCallback(nullptr); });
|
||||
for (const std::unique_ptr<Layer>& layer : _layers) {
|
||||
layer->onChange(_onChangeCallback);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ struct LayerGroup : public properties::PropertyOwner {
|
||||
|
||||
bool layerBlendingEnabled() const;
|
||||
|
||||
void onChange(std::function<void(void)> callback);
|
||||
void onChange(std::function<void(Layer*)> callback);
|
||||
|
||||
private:
|
||||
const layergroupid::GroupID _groupId;
|
||||
@@ -72,7 +72,7 @@ private:
|
||||
std::vector<Layer*> _activeLayers;
|
||||
|
||||
properties::BoolProperty _levelBlendingEnabled;
|
||||
std::function<void(void)> _onChangeCallback;
|
||||
std::function<void(Layer*)> _onChangeCallback;
|
||||
};
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
@@ -127,7 +127,7 @@ void LayerManager::reset(bool includeDisabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void LayerManager::onChange(std::function<void(void)> callback) {
|
||||
void LayerManager::onChange(std::function<void(Layer*)> callback) {
|
||||
for (std::unique_ptr<LayerGroup>& layerGroup : _layerGroups) {
|
||||
layerGroup->onChange(callback);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
void update();
|
||||
void reset(bool includeDisabled = false);
|
||||
|
||||
void onChange(std::function<void(void)> callback);
|
||||
void onChange(std::function<void(Layer* l)> callback);
|
||||
|
||||
private:
|
||||
std::array<std::unique_ptr<LayerGroup>, NumLayerGroups> _layerGroups;
|
||||
|
||||
@@ -41,7 +41,10 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
|
||||
#include <numeric>
|
||||
#include <queue>
|
||||
|
||||
namespace {
|
||||
@@ -180,6 +183,13 @@ namespace {
|
||||
"orenNayarRoughness",
|
||||
"" // @TODO Missing documentation
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo NActiveLayersInfo = {
|
||||
"NActiveLayers",
|
||||
"Number of active layers",
|
||||
"This is the number of currently active layers, if this value reaches the "
|
||||
"maximum, bad things will happen."
|
||||
};
|
||||
} // namespace
|
||||
|
||||
using namespace openspace::properties;
|
||||
@@ -396,7 +406,8 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
BoolProperty(EclipseHardShadowsInfo, false),
|
||||
FloatProperty(LodScaleFactorInfo, 15.f, 1.f, 50.f),
|
||||
FloatProperty(CameraMinHeightInfo, 100.f, 0.f, 1000.f),
|
||||
FloatProperty(OrenNayarRoughnessInfo, 0.f, 0.f, 1.f)
|
||||
FloatProperty(OrenNayarRoughnessInfo, 0.f, 0.f, 1.f),
|
||||
IntProperty(NActiveLayersInfo, 0, 0, OpenGLCap.maxTextureUnits() / 3)
|
||||
})
|
||||
, _debugPropertyOwner({ "Debug" })
|
||||
, _grid(DefaultSkirtedGridSegments, DefaultSkirtedGridSegments)
|
||||
@@ -434,6 +445,8 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_generalProperties.lodScaleFactor);
|
||||
addProperty(_generalProperties.cameraMinHeight);
|
||||
addProperty(_generalProperties.orenNayarRoughness);
|
||||
_generalProperties.nActiveLayers.setReadOnly(true);
|
||||
addProperty(_generalProperties.nActiveLayers);
|
||||
|
||||
_debugPropertyOwner.addProperty(_debugProperties.showChunkEdges);
|
||||
_debugPropertyOwner.addProperty(_debugProperties.showChunkBounds);
|
||||
@@ -457,9 +470,11 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
_debugProperties.showHeightResolution.onChange(notifyShaderRecompilation);
|
||||
_debugProperties.showHeightIntensities.onChange(notifyShaderRecompilation);
|
||||
|
||||
_layerManager.onChange([&]() {
|
||||
_layerManager.onChange([&](Layer* l) {
|
||||
_shadersNeedRecompilation = true;
|
||||
_chunkCornersDirty = true;
|
||||
_nLayersIsDirty = true;
|
||||
_lastChangedLayer = l;
|
||||
});
|
||||
|
||||
addPropertySubOwner(_debugPropertyOwner);
|
||||
@@ -585,8 +600,38 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& rendererTask
|
||||
const double distance = res * boundingSphere() / tfov;
|
||||
|
||||
if (distanceToCamera < distance) {
|
||||
renderChunks(data, rendererTask);
|
||||
try {
|
||||
renderChunks(data, rendererTask);
|
||||
}
|
||||
catch (const ghoul::opengl::TextureUnit::TextureUnitError&) {
|
||||
std::string layer = _lastChangedLayer ?
|
||||
_lastChangedLayer->guiName() :
|
||||
"";
|
||||
|
||||
LWARNINGC(
|
||||
guiName(),
|
||||
layer.empty() ?
|
||||
"Too many layers enabled" :
|
||||
"Too many layers enabled, disabling layer: " + layer
|
||||
);
|
||||
|
||||
// We bailed out in the middle of the rendering, so some TextureUnits are
|
||||
// still bound and we would fail in some next render function for sure
|
||||
for (GPULayerGroup& l : _globalRenderer.gpuLayerGroups) {
|
||||
l.deactivate();
|
||||
}
|
||||
|
||||
for (GPULayerGroup& l : _localRenderer.gpuLayerGroups) {
|
||||
l.deactivate();
|
||||
}
|
||||
|
||||
if (_lastChangedLayer) {
|
||||
_lastChangedLayer->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_lastChangedLayer = nullptr;
|
||||
}
|
||||
|
||||
void RenderableGlobe::update(const UpdateData& data) {
|
||||
@@ -609,6 +654,20 @@ void RenderableGlobe::update(const UpdateData& data) {
|
||||
_debugProperties.resetTileProviders = false;
|
||||
}
|
||||
_layerManager.update();
|
||||
|
||||
if (_nLayersIsDirty) {
|
||||
std::array<LayerGroup*, LayerManager::NumLayerGroups> lgs =
|
||||
_layerManager.layerGroups();
|
||||
_generalProperties.nActiveLayers = std::accumulate(
|
||||
lgs.begin(),
|
||||
lgs.end(),
|
||||
0,
|
||||
[](int lhs, LayerGroup* lg) {
|
||||
return lhs + static_cast<int>(lg->activeLayers().size());
|
||||
}
|
||||
);
|
||||
_nLayersIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
const LayerManager& RenderableGlobe::layerManager() const {
|
||||
|
||||
@@ -116,6 +116,7 @@ private:
|
||||
properties::FloatProperty lodScaleFactor;
|
||||
properties::FloatProperty cameraMinHeight;
|
||||
properties::FloatProperty orenNayarRoughness;
|
||||
properties::IntProperty nActiveLayers;
|
||||
} _generalProperties;
|
||||
|
||||
properties::PropertyOwner _debugPropertyOwner;
|
||||
@@ -239,6 +240,8 @@ private:
|
||||
bool _shadersNeedRecompilation = true;
|
||||
bool _lodScaleFactorDirty = true;
|
||||
bool _chunkCornersDirty = true;
|
||||
bool _nLayersIsDirty = true;
|
||||
Layer* _lastChangedLayer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
Reference in New Issue
Block a user