diff --git a/Editor/src/Misc/ThumbnailManager.cpp b/Editor/src/Misc/ThumbnailManager.cpp index 1b9ca420..0fa5a8c8 100644 --- a/Editor/src/Misc/ThumbnailManager.cpp +++ b/Editor/src/Misc/ThumbnailManager.cpp @@ -43,13 +43,23 @@ Ref ThumbnailManager::GetThumbnail(const std::string& path) { return m_Thumbnails[path]; } + + int i = 0; + std::string m = "masing" + std::to_string(i) + std::endl; using namespace Nuake; + if (m_ThumbnailGeneratedThisFrame > MAX_THUMBNAIL_PER_FRAME) + { + return nullptr; + } + // Generate Thumbnail Ref thumbnail = CreateRef(m_ThumbnailSize, GL_RGB, GL_RGB16F, GL_FLOAT); GenerateThumbnail(path, thumbnail); m_Thumbnails[path] = thumbnail; + + m_ThumbnailGeneratedThisFrame++; return thumbnail; } @@ -208,4 +218,9 @@ Ref ThumbnailManager::GenerateThumbnail(const std::string& path, return m_ShadedFramebuffer->GetTexture(GL_COLOR_ATTACHMENT0); -} \ No newline at end of file +} + +void ThumbnailManager::OnEndFrame() +{ + m_ThumbnailGeneratedThisFrame = 0; +} diff --git a/Editor/src/Misc/ThumbnailManager.h b/Editor/src/Misc/ThumbnailManager.h index 8718a150..32483984 100644 --- a/Editor/src/Misc/ThumbnailManager.h +++ b/Editor/src/Misc/ThumbnailManager.h @@ -12,6 +12,9 @@ private: Ref m_ShadedFramebuffer; const Nuake::Vector2 m_ThumbnailSize = { 128, 128 }; + const uint32_t MAX_THUMBNAIL_PER_FRAME = 1; + uint32_t m_ThumbnailGeneratedThisFrame = 0; + public: ThumbnailManager(); ~ThumbnailManager() = default; @@ -22,4 +25,5 @@ public: Ref GetThumbnail(const std::string& path); void MarkThumbnailAsDirty(const std::string& path); Ref GenerateThumbnail(const std::string& path, Ref texture); + void OnEndFrame(); }; \ No newline at end of file diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index ceefe5e4..8c3d01c7 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -326,7 +326,11 @@ namespace Nuake const auto fileType = file->GetFileType(); if (fileType == FileType::Material) { - textureImage = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath()); + auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath()); + if (image) + { + textureImage = image; + } } else if (fileType == FileType::Image) { @@ -355,7 +359,11 @@ namespace Nuake } else if (fileType == FileType::Prefab) { - textureImage = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath()); + auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath()); + if (image) + { + textureImage = image; + } } ImGui::SetCursorPos(prevCursor); @@ -918,6 +926,8 @@ namespace Nuake ImGui::EndChild(); } + ThumbnailManager::Get().OnEndFrame(); + ImGui::EndChild(); } ImGui::End();