diff --git a/modules/space/rendering/renderablestars.cpp b/modules/space/rendering/renderablestars.cpp index e51bfefd51..e3a5987a08 100644 --- a/modules/space/rendering/renderablestars.cpp +++ b/modules/space/rendering/renderablestars.cpp @@ -789,7 +789,7 @@ void RenderableStars::initializeGL() { ); //loadShapeTexture(); - + loadPSFTexture(); renderPSFToTexture(); } @@ -808,6 +808,39 @@ void RenderableStars::deinitializeGL() { } } +void RenderableStars::loadPSFTexture() { + _pointSpreadFunctionTexture = nullptr; + if (!_pointSpreadFunctionTexturePath.value().empty() && + std::filesystem::exists(_pointSpreadFunctionTexturePath.value())) + { + _pointSpreadFunctionTexture = ghoul::io::TextureReader::ref().loadTexture( + absPath(_pointSpreadFunctionTexturePath) + ); + + if (_pointSpreadFunctionTexture) { + LDEBUG(fmt::format( + "Loaded texture from '{}'", + absPath(_pointSpreadFunctionTexturePath) + )); + _pointSpreadFunctionTexture->uploadTexture(); + } + _pointSpreadFunctionTexture->setFilter( + ghoul::opengl::Texture::FilterMode::AnisotropicMipMap + ); + + _pointSpreadFunctionFile = std::make_unique( + _pointSpreadFunctionTexturePath + ); + _pointSpreadFunctionFile->setCallback( + [&](const ghoul::filesystem::File&) { + _pointSpreadFunctionTextureIsDirty = true; + } + ); + } + _pointSpreadFunctionTextureIsDirty = false; + +} + void RenderableStars::renderPSFToTexture() { // Saves current FBO first GLint defaultFBO; @@ -1214,35 +1247,7 @@ void RenderableStars::update(const UpdateData&) { if (_pointSpreadFunctionTextureIsDirty) { LDEBUG("Reloading Point Spread Function texture"); - _pointSpreadFunctionTexture = nullptr; - if (!_pointSpreadFunctionTexturePath.value().empty() && - std::filesystem::exists(_pointSpreadFunctionTexturePath.value())) - { - _pointSpreadFunctionTexture = ghoul::io::TextureReader::ref().loadTexture( - absPath(_pointSpreadFunctionTexturePath) - ); - - if (_pointSpreadFunctionTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'", - absPath(_pointSpreadFunctionTexturePath) - )); - _pointSpreadFunctionTexture->uploadTexture(); - } - _pointSpreadFunctionTexture->setFilter( - ghoul::opengl::Texture::FilterMode::AnisotropicMipMap - ); - - _pointSpreadFunctionFile = std::make_unique( - _pointSpreadFunctionTexturePath - ); - _pointSpreadFunctionFile->setCallback( - [&](const ghoul::filesystem::File&) { - _pointSpreadFunctionTextureIsDirty = true; - } - ); - } - _pointSpreadFunctionTextureIsDirty = false; + loadPSFTexture(); } if (_colorTextureIsDirty) { diff --git a/modules/space/rendering/renderablestars.h b/modules/space/rendering/renderablestars.h index 946f9b917b..0ab79f66cc 100644 --- a/modules/space/rendering/renderablestars.h +++ b/modules/space/rendering/renderablestars.h @@ -58,6 +58,7 @@ public: bool isReady() const override; + void loadPSFTexture(); void renderPSFToTexture(); void render(const RenderData& data, RendererTasks& rendererTask) override; void update(const UpdateData& data) override;