aboutsummaryrefslogtreecommitdiff
path: root/src/core/hdri_manager.cpp
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-20 02:27:02 +0200
committerhachem <im@hachem.wtf>2026-08-20 02:40:07 +0200
commit5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch)
tree34db1df17e8c7248aeeb92156d635d31c2484e3f /src/core/hdri_manager.cpp
parente3abaaf59777258ba06705135a0cafcb5918ad12 (diff)
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/core/hdri_manager.cpp')
-rw-r--r--src/core/hdri_manager.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/core/hdri_manager.cpp b/src/core/hdri_manager.cpp
new file mode 100644
index 0000000..605dcf6
--- /dev/null
+++ b/src/core/hdri_manager.cpp
@@ -0,0 +1,64 @@
+#include "hdri_manager.h"
+#include <filesystem>
+
+namespace Donut
+{
+ auto HDRIManager::load_hdri(const std::string& path) -> Ref<CubemapTexture>
+ {
+ auto it = m_hdri_cache.find(path);
+ if (it != m_hdri_cache.end())
+ {
+ DONUT_INFO("HDRI already cached: {}", path);
+ return it->second;
+ }
+
+ DONUT_INFO("Loading HDRI: {}", path);
+ auto hdri = CubemapTexture::create_from_hdri(path);
+
+ if (hdri)
+ {
+ m_hdri_cache[path] = hdri;
+ DONUT_INFO("Successfully loaded and cached HDRI: {}", path);
+ }
+ else
+ DONUT_ERROR("Failed to load HDRI: {}", path);
+
+ return hdri;
+ }
+
+ auto HDRIManager::set_current_hdri(const std::string& path) -> void
+ {
+ auto hdri = load_hdri(path);
+ if (hdri)
+ {
+ m_current_hdri = hdri;
+ DONUT_INFO("Set current HDRI to: {}", path);
+ }
+ else
+ DONUT_ERROR("Failed to set current HDRI: {}", path);
+ }
+
+ auto HDRIManager::get_hdri_name(const std::string& path) const -> std::string
+ {
+ std::filesystem::path file_path(path);
+ std::string filename = file_path.stem().string();
+ std::string name = filename;
+
+ for (size_t i = 0; i < name.length(); ++i)
+ {
+ if (name[i] == '_')
+ name[i] = ' ';
+ else if (i == 0 || name[i-1] == ' ')
+ name[i] = std::toupper(name[i]);
+ }
+
+ return name;
+ }
+
+ auto HDRIManager::clear_cache() -> void
+ {
+ m_hdri_cache.clear();
+ m_current_hdri.reset();
+ DONUT_INFO("HDRI cache cleared");
+ }
+};