Add option to purge texture from RAM after gpu upload

This commit is contained in:
Emma Broman
2021-01-18 13:34:50 +01:00
parent 6380e5b307
commit 2ae5a16697
2 changed files with 24 additions and 6 deletions

View File

@@ -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

View File

@@ -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<ghoul::filesystem::File>(path);