mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 06:16:18 +02:00
clear all _cacheFiles on recycle
This commit is contained in:
parent
3477aa57a8
commit
3ae52c0e0e
3 changed files with 23 additions and 4 deletions
|
@ -772,7 +772,7 @@ void GLBackend::recycle() const {
|
|||
|
||||
GLVariableAllocationSupport::manageMemory();
|
||||
GLVariableAllocationSupport::_frameTexturesCreated = 0;
|
||||
|
||||
Texture::KtxStorage::clearKtxFiles();
|
||||
}
|
||||
|
||||
void GLBackend::setCameraCorrection(const Mat4& correction) {
|
||||
|
|
|
@ -321,10 +321,15 @@ 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();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<storage::FileStorage> maybeOpenFile() const;
|
||||
|
||||
mutable std::mutex _cacheFileMutex;
|
||||
mutable std::shared_ptr<std::mutex> _cacheFileMutex { std::make_shared<std::mutex>() };
|
||||
mutable std::shared_ptr<storage::FileStorage> _cacheFile;
|
||||
|
||||
std::string _filename;
|
||||
|
|
|
@ -23,6 +23,9 @@ using namespace gpu;
|
|||
using PixelsPointer = Texture::PixelsPointer;
|
||||
using KtxStorage = Texture::KtxStorage;
|
||||
|
||||
std::vector<std::pair<std::shared_ptr<storage::FileStorage>, std::shared_ptr<std::mutex>>> KtxStorage::_cachedKtxFiles;
|
||||
std::mutex KtxStorage::_cachedKtxFilesMutex;
|
||||
|
||||
struct GPUKTXPayload {
|
||||
using Version = uint8;
|
||||
|
||||
|
@ -190,15 +193,26 @@ 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);
|
||||
_cachedKtxFiles.emplace_back(_cacheFile, _cacheFileMutex);
|
||||
}
|
||||
return _cacheFile;
|
||||
}
|
||||
|
||||
void KtxStorage::clearKtxFiles() {
|
||||
std::lock_guard<std::mutex> lock(KtxStorage::_cachedKtxFilesMutex);
|
||||
for (auto& cacheFileAndMutex : KtxStorage::_cachedKtxFiles) {
|
||||
std::lock_guard<std::mutex> lock(*(cacheFileAndMutex.second));
|
||||
cacheFileAndMutex.first.reset();
|
||||
}
|
||||
_cachedKtxFiles.clear();
|
||||
}
|
||||
|
||||
PixelsPointer KtxStorage::getMipFace(uint16 level, uint8 face) const {
|
||||
auto faceOffset = _ktxDescriptor->getMipFaceTexelsOffset(level, face);
|
||||
auto faceSize = _ktxDescriptor->getMipFaceTexelsSize(level, face);
|
||||
if (faceSize != 0 && faceOffset != 0) {
|
||||
std::lock_guard<std::mutex> lock(_cacheFileMutex);
|
||||
std::lock_guard<std::mutex> lock(*_cacheFileMutex);
|
||||
auto file = maybeOpenFile();
|
||||
if (file) {
|
||||
auto storageView = file->createView(faceSize, faceOffset);
|
||||
|
@ -244,7 +258,7 @@ void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& stor
|
|||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(_cacheFileMutex);
|
||||
std::lock_guard<std::mutex> lock(*_cacheFileMutex);
|
||||
auto file = maybeOpenFile();
|
||||
if (!file) {
|
||||
qWarning() << "Failed to open file to assign mip data " << QString::fromStdString(_filename);
|
||||
|
|
Loading…
Reference in a new issue