diff --git a/include/openspace/rendering/texturecomponent.h b/include/openspace/rendering/texturecomponent.h index 0046ea1cc0..2a7d94e681 100644 --- a/include/openspace/rendering/texturecomponent.h +++ b/include/openspace/rendering/texturecomponent.h @@ -39,11 +39,15 @@ class TextureComponent { public: TextureComponent() = default; - TextureComponent(const Texture::FilterMode filterMode, bool watchFile = true); + TextureComponent(const Texture::FilterMode filterMode, bool watchFile = true, + bool shouldPurge = true); ~TextureComponent() = default; Texture* texture() const; + void setShouldWatchFileForChanges(bool value); + void setShouldPurgeFromRAM(bool value); + void bind(); void uploadToGpu(); @@ -60,9 +64,10 @@ private: Texture::FilterMode _filterMode = Texture::FilterMode::LinearMipMap; bool _shouldWatchFile = true; + bool _shouldPurgeFromRAM = true; - bool _fileIsDirty = false; - bool _textureIsDirty = false; + bool _fileIsDirty; + bool _textureIsDirty; }; } // namespace openspace diff --git a/src/rendering/texturecomponent.cpp b/src/rendering/texturecomponent.cpp index 62e9aabf5a..c334ac851b 100644 --- a/src/rendering/texturecomponent.cpp +++ b/src/rendering/texturecomponent.cpp @@ -35,14 +35,25 @@ namespace { namespace openspace { -TextureComponent::TextureComponent(const Texture::FilterMode filterMode, bool watchFile) - : _filterMode(filterMode), _shouldWatchFile(watchFile) +TextureComponent::TextureComponent(const Texture::FilterMode filterMode, + bool watchFile, bool shouldPurge) + : _filterMode(filterMode) + , _shouldWatchFile(watchFile) + , _shouldPurgeFromRAM(shouldPurge) {} ghoul::opengl::Texture* TextureComponent::texture() const { return _texture.get(); } +void TextureComponent::setShouldWatchFileForChanges(bool value) { + _shouldWatchFile = value; +} + +void TextureComponent::setShouldPurgeFromRAM(bool value) { + _shouldPurgeFromRAM = value; +} + void TextureComponent::bind() { ghoul_assert(_texture, "Texture must be loaded before binding"); _texture->bind(); @@ -55,6 +66,9 @@ void TextureComponent::uploadToGpu() { } _texture->uploadTexture(); _texture->setFilter(_filterMode); + if (_shouldPurgeFromRAM) { + _texture->purgeFromRAM(); + } } void TextureComponent::loadFromFile(const std::string& path) { @@ -67,7 +81,6 @@ void TextureComponent::loadFromFile(const std::string& path) { if (texture) { LDEBUG(fmt::format("Loaded texture from '{}'", absPath(path))); - _texture = nullptr; _texture = std::move(texture); _textureFile = std::make_unique(path);