mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 10:40:09 -06:00
Add option to purge texture from RAM after gpu upload
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user