diff --git a/modules/base/rendering/renderablesphereimagelocal.cpp b/modules/base/rendering/renderablesphereimagelocal.cpp index 383cd356c1..126e5f6912 100644 --- a/modules/base/rendering/renderablesphereimagelocal.cpp +++ b/modules/base/rendering/renderablesphereimagelocal.cpp @@ -44,11 +44,6 @@ namespace { struct [[codegen::Dictionary(RenderableSphereImageLocal)]] Parameters { // [[codegen::verbatim(TextureInfo.description)]] std::filesystem::path texture; - - // If true, the image for this sphere will not be loaded at startup but rather - // when the image is shown for the first time. Additionally, if the sphere is - // disabled, the image will automatically be unloaded. - std::optional lazyLoading; }; #include "renderablesphereimagelocal_codegen.cpp" } // namespace @@ -70,24 +65,24 @@ RenderableSphereImageLocal::RenderableSphereImageLocal( const Parameters p = codegen::bake(dictionary); _texturePath = p.texture.string(); - _textureFile = std::make_unique(_texturePath.value()); - _texturePath.onChange([this]() { - loadTexture(); - }); + _texturePath.onChange([this]() { _texture->loadFromFile(_texturePath.value()); }); addProperty(_texturePath); - _textureFile->setCallback([this]() { _textureIsDirty = true; }); } bool RenderableSphereImageLocal::isReady() const { return RenderableSphere::isReady() && _texture; } +void RenderableSphereImageLocal::initialize() { + _texture = std::make_unique(2); + _texture->setFilterMode(ghoul::opengl::Texture::FilterMode::LinearMipMap); + _texture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToEdge); +} + void RenderableSphereImageLocal::initializeGL() { RenderableSphere::initializeGL(); - - if (!_isLoadingLazily) { - loadTexture(); - } + _texture->loadFromFile(_texturePath.value()); + _texture->uploadToGpu(); } void RenderableSphereImageLocal::deinitializeGL() { @@ -98,41 +93,11 @@ void RenderableSphereImageLocal::deinitializeGL() { void RenderableSphereImageLocal::update(const UpdateData& data) { RenderableSphere::update(data); - - if (_textureIsDirty) { - loadTexture(); - _textureIsDirty = false; - } + _texture->update(); } void RenderableSphereImageLocal::bindTexture() { _texture->bind(); } -void RenderableSphereImageLocal::loadTexture() { - if (_texturePath.value().empty()) { - return; - } - - std::unique_ptr texture = - ghoul::io::TextureReader::ref().loadTexture(_texturePath.value(), 2); - - if (!texture) { - LWARNINGC( - "RenderableSphereImageLocal", - std::format("Could not load texture from '{}'", absPath(_texturePath)) - ); - return; - } - - LDEBUGC( - "RenderableSphereImageLocal", - std::format("Loaded texture from '{}'", absPath(_texturePath)) - ); - texture->uploadTexture(); - texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - texture->purgeFromRAM(); - _texture = std::move(texture); -} - } // namespace openspace diff --git a/modules/base/rendering/renderablesphereimagelocal.h b/modules/base/rendering/renderablesphereimagelocal.h index 2a2abf092d..b77ff0e159 100644 --- a/modules/base/rendering/renderablesphereimagelocal.h +++ b/modules/base/rendering/renderablesphereimagelocal.h @@ -27,6 +27,8 @@ #include +#include + namespace ghoul::opengl { class Texture; } namespace openspace { @@ -40,6 +42,7 @@ class RenderableSphereImageLocal : public RenderableSphere { public: RenderableSphereImageLocal(const ghoul::Dictionary& dictionary); + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -53,14 +56,10 @@ protected: void bindTexture() override; private: - void loadTexture(); properties::StringProperty _texturePath; - std::unique_ptr _textureFile; - std::unique_ptr _texture; - bool _isLoadingLazily = false; - bool _textureIsDirty = false; + std::unique_ptr _texture; }; } // namespace openspace diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index dadaa3623a..42eb12173a 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -25,11 +25,12 @@ #ifndef __OPENSPACE_MODULE_EXOPLANETS___RENDERABLEORBITDISC___H__ #define __OPENSPACE_MODULE_EXOPLANETS___RENDERABLEORBITDISC___H__ +#include + #include #include #include #include -#include #include #include #include