mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Made max amount of thumbnail generated per frame for performance
This commit is contained in:
@@ -43,13 +43,23 @@ Ref<Nuake::Texture> 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<Texture> thumbnail = CreateRef<Texture>(m_ThumbnailSize, GL_RGB, GL_RGB16F, GL_FLOAT);
|
||||
GenerateThumbnail(path, thumbnail);
|
||||
|
||||
m_Thumbnails[path] = thumbnail;
|
||||
|
||||
m_ThumbnailGeneratedThisFrame++;
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
@@ -208,4 +218,9 @@ Ref<Nuake::Texture> ThumbnailManager::GenerateThumbnail(const std::string& path,
|
||||
|
||||
|
||||
return m_ShadedFramebuffer->GetTexture(GL_COLOR_ATTACHMENT0);
|
||||
}
|
||||
}
|
||||
|
||||
void ThumbnailManager::OnEndFrame()
|
||||
{
|
||||
m_ThumbnailGeneratedThisFrame = 0;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ private:
|
||||
Ref<Nuake::FrameBuffer> 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<Nuake::Texture> GetThumbnail(const std::string& path);
|
||||
void MarkThumbnailAsDirty(const std::string& path);
|
||||
Ref<Nuake::Texture> GenerateThumbnail(const std::string& path, Ref<Nuake::Texture> texture);
|
||||
void OnEndFrame();
|
||||
};
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user