diff options
Diffstat (limited to 'Source/Core/VideoCommon/Resources/TexturePool.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/Resources/TexturePool.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/Resources/TexturePool.cpp b/Source/Core/VideoCommon/Resources/TexturePool.cpp new file mode 100644 index 0000000000..ce76dc5b24 --- /dev/null +++ b/Source/Core/VideoCommon/Resources/TexturePool.cpp @@ -0,0 +1,43 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/Resources/TexturePool.h" + +#include "Common/Logging/Log.h" + +#include "VideoCommon/AbstractGfx.h" +#include "VideoCommon/AbstractTexture.h" + +namespace VideoCommon +{ +void TexturePool::Reset() +{ + m_cache.clear(); +} + +std::unique_ptr<AbstractTexture> TexturePool::AllocateTexture(const TextureConfig& config) +{ + const auto iter = m_cache.find(config); + if (iter != m_cache.end()) + { + auto entry = std::move(iter->second); + m_cache.erase(iter); + return entry; + } + + std::unique_ptr<AbstractTexture> texture = g_gfx->CreateTexture(config); + if (!texture) + { + ERROR_LOG_FMT(VIDEO, "Failed to allocate a {}x{}x{} texture", config.width, config.height, + config.layers); + return {}; + } + return texture; +} + +void TexturePool::ReleaseTexture(std::unique_ptr<AbstractTexture> texture) +{ + auto config = texture->GetConfig(); + (void)m_cache.emplace(config, std::move(texture)); +} +} // namespace VideoCommon |
