diff --git a/src/Application.cpp b/src/Application.cpp index e83a9dd..a23e298 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -31,8 +31,7 @@ void Application::Quit() { delete topology; - lol::ShaderManager::GetInstance().Cleanup(); - lol::ObjectManager::GetInstance().Cleanup(); + manager.Clear(); glfwDestroyWindow(window); window = nullptr; @@ -138,7 +137,7 @@ void Application::Init(int width, int height, const std::string& title) data.camera = &camera; data.aspectRatio = (float)width / (float)height; - topology = new Topology(glm::vec2(15.0f, 7.5f), glm::uvec2(200, 100)); + topology = new Topology(manager, glm::vec2(15.0f, 7.5f), glm::uvec2(200, 100)); glm::uvec2 size = topology->GetSize(); float* pixels = topology->GetTopology(); diff --git a/src/Application.hpp b/src/Application.hpp index 7e4549c..0c271fc 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -43,6 +43,7 @@ public: private: GLFWwindow* window = nullptr; WindowData data; + lol::ObjectManager manager; OrbitingCamera camera; float pitch, yaw, distance; diff --git a/src/Topology.cpp b/src/Topology.cpp index ebb0bf4..68d137b 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -5,8 +5,8 @@ #include "Util.hpp" #include "Colormaps.hpp" -Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) : - texture(nullptr) +Topology::Topology(lol::ObjectManager& manager, const glm::vec2& size, const glm::uvec2& subdivisions) : + texture(nullptr), manager(manager) { // Create VAO vao = std::make_shared(); @@ -52,10 +52,13 @@ Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) : vao->SetElementBuffer(elementBuffer); // Set up shader - shader = lol::ShaderManager::GetInstance().Get(TOPOLOGY_ID); - if (shader == nullptr) + try { - shader = std::make_shared( + shader = manager.Get(TOPOLOGY_ID); + } + catch(const lol::ObjectNotFoundException& ex) + { + shader = manager.Create(TOPOLOGY_ID, R"( #version 460 core @@ -103,8 +106,6 @@ Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) : } )" ); - - lol::ShaderManager::GetInstance().Register(TOPOLOGY_ID, shader); } // Generate image @@ -119,8 +120,7 @@ Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) : Topology::~Topology() { - lol::ShaderManager::GetInstance().CleanupUnused(); - lol::ObjectManager::GetInstance().CleanupUnused(); + manager.ClearUnused(); if (texture != nullptr) delete texture; @@ -146,15 +146,18 @@ void Topology::PreRender(const lol::CameraBase& camera) void Topology::SetColormap(const Colormap& cm) { - colormap = lol::ObjectManager::GetInstance().Get(cm.id); + colormap = manager.Get(cm.id); } void Topology::RegisterColormap(const Colormap& cm) { - std::shared_ptr texColormap = lol::ObjectManager::GetInstance().Get(cm.id); - if(texColormap == nullptr) + try { - texColormap = std::make_shared( + manager.Get(cm.id); + } + catch(const lol::ObjectNotFoundException& e) + { + std::shared_ptr colormap = manager.Create(cm.id, cm.data.size() / 3, cm.data.data(), lol::PixelFormat::RGB, @@ -162,9 +165,7 @@ void Topology::RegisterColormap(const Colormap& cm) lol::TextureFormat::RGB32F ); - texColormap->SetWrap(lol::TextureWrap::ClampToEdge, lol::TextureWrap::Repeat); - - lol::ObjectManager::GetInstance().Register(cm.id, texColormap); + colormap->SetWrap(lol::TextureWrap::ClampToEdge, lol::TextureWrap::Repeat); } } diff --git a/src/Topology.hpp b/src/Topology.hpp index fe98171..2dfd939 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -11,7 +11,7 @@ inline float Map(const glm::vec2& from, const glm::vec2& to, float val) class Topology : public lol::Drawable { public: - Topology(const glm::vec2& size, const glm::uvec2& subdivision); + Topology(lol::ObjectManager& manager, const glm::vec2& size, const glm::uvec2& subdivision); ~Topology(); void PreRender(const lol::CameraBase& camera) override; @@ -32,6 +32,8 @@ private: private: lol::Image image; lol::Texture2D* texture; + + lol::ObjectManager& manager; std::shared_ptr colormap; float offset = 0.0f; diff --git a/vendor/lol b/vendor/lol index e23d221..967bf6b 160000 --- a/vendor/lol +++ b/vendor/lol @@ -1 +1 @@ -Subproject commit e23d22153c88822a2a15e798ad2643fdcbdf6dc3 +Subproject commit 967bf6b161b7082e4e68f4a79330039cfc9c5569