mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Merge branch 'master' of github.com:OpenSpace/OpenSpace
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -74,7 +74,13 @@ Layer* LayerManager::addLayer(layergroupid::GroupID groupId,
|
||||
const ghoul::Dictionary& layerDict)
|
||||
{
|
||||
ghoul_assert(groupId != layergroupid::Unknown, "Layer group ID must be known");
|
||||
return _layerGroups[groupId]->addLayer(layerDict);
|
||||
try {
|
||||
return _layerGroups[groupId]->addLayer(layerDict);
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerManager::deleteLayer(layergroupid::GroupID id, const std::string& layerName) {
|
||||
@@ -121,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;
|
||||
|
||||
@@ -57,6 +57,63 @@ namespace openspace::globebrowsing {
|
||||
|
||||
namespace {
|
||||
|
||||
// These are some locations in memory taken from ESRI's No Data Available tile so that we
|
||||
// can spotcheck these tiles and not present them
|
||||
// The pair is <byte index, expected value>
|
||||
struct MemoryLocation {
|
||||
int offset;
|
||||
std::byte value;
|
||||
};
|
||||
|
||||
// The memory locations are grouped to be mostly cache-aligned
|
||||
constexpr std::array<MemoryLocation, 42> NoDataAvailableData = {
|
||||
MemoryLocation{ 296380, std::byte(205) },
|
||||
MemoryLocation{ 296381, std::byte(205) },
|
||||
MemoryLocation{ 296382, std::byte(205) },
|
||||
MemoryLocation{ 296383, std::byte(255) },
|
||||
MemoryLocation{ 296384, std::byte(224) },
|
||||
MemoryLocation{ 296385, std::byte(224) },
|
||||
MemoryLocation{ 296386, std::byte(224) },
|
||||
MemoryLocation{ 296387, std::byte(255) },
|
||||
MemoryLocation{ 296388, std::byte(244) },
|
||||
MemoryLocation{ 296389, std::byte(244) },
|
||||
MemoryLocation{ 296390, std::byte(244) },
|
||||
MemoryLocation{ 296391, std::byte(255) },
|
||||
|
||||
MemoryLocation{ 269840, std::byte(209) },
|
||||
MemoryLocation{ 269841, std::byte(209) },
|
||||
MemoryLocation{ 269842, std::byte(209) },
|
||||
MemoryLocation{ 269844, std::byte(203) },
|
||||
MemoryLocation{ 269845, std::byte(203) },
|
||||
MemoryLocation{ 269846, std::byte(203) },
|
||||
MemoryLocation{ 269852, std::byte(221) },
|
||||
MemoryLocation{ 269853, std::byte(221) },
|
||||
MemoryLocation{ 269854, std::byte(221) },
|
||||
MemoryLocation{ 269856, std::byte(225) },
|
||||
MemoryLocation{ 269857, std::byte(225) },
|
||||
MemoryLocation{ 269858, std::byte(225) },
|
||||
MemoryLocation{ 269860, std::byte(218) },
|
||||
MemoryLocation{ 269861, std::byte(218) },
|
||||
|
||||
MemoryLocation{ 240349, std::byte(203) },
|
||||
MemoryLocation{ 240350, std::byte(203) },
|
||||
MemoryLocation{ 240352, std::byte(205) },
|
||||
MemoryLocation{ 240353, std::byte(204) },
|
||||
MemoryLocation{ 240354, std::byte(205) },
|
||||
|
||||
MemoryLocation{ 0, std::byte(204) },
|
||||
MemoryLocation{ 7, std::byte(255) },
|
||||
MemoryLocation{ 520, std::byte(204) },
|
||||
MemoryLocation{ 880, std::byte(204) },
|
||||
MemoryLocation{ 883, std::byte(255) },
|
||||
MemoryLocation{ 91686, std::byte(204) },
|
||||
MemoryLocation{ 372486, std::byte(204) },
|
||||
MemoryLocation{ 670483, std::byte(255) },
|
||||
MemoryLocation{ 231684, std::byte(202) },
|
||||
MemoryLocation{ 232092, std::byte(202) },
|
||||
MemoryLocation{ 235921, std::byte(203) },
|
||||
};
|
||||
|
||||
enum class Side {
|
||||
Left = 0,
|
||||
Top,
|
||||
@@ -579,6 +636,17 @@ RawTile RawTileDataReader::readTileData(TileIndex tileIndex) const {
|
||||
RawTile::ReadError worstError = RawTile::ReadError::None;
|
||||
readImageData(io, worstError, reinterpret_cast<char*>(rawTile.imageData.get()));
|
||||
|
||||
for (const MemoryLocation& ml : NoDataAvailableData) {
|
||||
std::byte* ptr = rawTile.imageData.get();
|
||||
if (ml.offset >= numBytes || ptr[ml.offset] != ml.value) {
|
||||
// Bail out as early as possible
|
||||
break;
|
||||
}
|
||||
|
||||
// If we got here, we have (most likely) a No data yet available tile
|
||||
worstError = RawTile::ReadError::Failure;
|
||||
}
|
||||
|
||||
rawTile.error = worstError;
|
||||
rawTile.tileIndex = std::move(tileIndex);
|
||||
rawTile.textureInitData = _initData;
|
||||
|
||||
@@ -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