mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 12:28:51 +02:00
cr and cleanup
This commit is contained in:
parent
3ae52c0e0e
commit
6990dda48d
3 changed files with 13 additions and 9 deletions
|
@ -772,7 +772,7 @@ void GLBackend::recycle() const {
|
|||
|
||||
GLVariableAllocationSupport::manageMemory();
|
||||
GLVariableAllocationSupport::_frameTexturesCreated = 0;
|
||||
Texture::KtxStorage::clearKtxFiles();
|
||||
Texture::KtxStorage::releaseOpenKtxFiles();
|
||||
}
|
||||
|
||||
void GLBackend::setCameraCorrection(const Mat4& correction) {
|
||||
|
|
|
@ -322,9 +322,7 @@ public:
|
|||
void reset() override { }
|
||||
|
||||
// Don't keep files open forever. We close them at the beginning of each frame (GLBackend::recycle)
|
||||
static std::vector<std::pair<std::shared_ptr<storage::FileStorage>, std::shared_ptr<std::mutex>>> _cachedKtxFiles;
|
||||
static std::mutex _cachedKtxFilesMutex;
|
||||
static void clearKtxFiles();
|
||||
static void releaseOpenKtxFiles();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<storage::FileStorage> maybeOpenFile() const;
|
||||
|
@ -332,6 +330,9 @@ public:
|
|||
mutable std::shared_ptr<std::mutex> _cacheFileMutex { std::make_shared<std::mutex>() };
|
||||
mutable std::shared_ptr<storage::FileStorage> _cacheFile;
|
||||
|
||||
static std::vector<std::pair<std::shared_ptr<storage::FileStorage>, std::shared_ptr<std::mutex>>> _cachedKtxFiles;
|
||||
static std::mutex _cachedKtxFilesMutex;
|
||||
|
||||
std::string _filename;
|
||||
cache::FilePointer _cacheEntry;
|
||||
std::atomic<uint8_t> _minMipLevelAvailable;
|
||||
|
|
|
@ -193,19 +193,22 @@ KtxStorage::KtxStorage(const std::string& filename) : _filename(filename) {
|
|||
std::shared_ptr<storage::FileStorage> KtxStorage::maybeOpenFile() const {
|
||||
if (!_cacheFile) {
|
||||
_cacheFile = std::make_shared<storage::FileStorage>(_filename.c_str());
|
||||
std::lock_guard<std::mutex> lock(KtxStorage::_cachedKtxFilesMutex);
|
||||
std::lock_guard<std::mutex> lock(_cachedKtxFilesMutex);
|
||||
_cachedKtxFiles.emplace_back(_cacheFile, _cacheFileMutex);
|
||||
}
|
||||
return _cacheFile;
|
||||
}
|
||||
|
||||
void KtxStorage::clearKtxFiles() {
|
||||
std::lock_guard<std::mutex> lock(KtxStorage::_cachedKtxFilesMutex);
|
||||
for (auto& cacheFileAndMutex : KtxStorage::_cachedKtxFiles) {
|
||||
void KtxStorage::releaseOpenKtxFiles() {
|
||||
std::vector<std::pair<std::shared_ptr<storage::FileStorage>, std::shared_ptr<std::mutex>>> localKtxFiles;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_cachedKtxFilesMutex);
|
||||
localKtxFiles.swap(_cachedKtxFiles);
|
||||
}
|
||||
for (auto& cacheFileAndMutex : localKtxFiles) {
|
||||
std::lock_guard<std::mutex> lock(*(cacheFileAndMutex.second));
|
||||
cacheFileAndMutex.first.reset();
|
||||
}
|
||||
_cachedKtxFiles.clear();
|
||||
}
|
||||
|
||||
PixelsPointer KtxStorage::getMipFace(uint16 level, uint8 face) const {
|
||||
|
|
Loading…
Reference in a new issue