diff --git a/inferno/src/inferno/application.cpp b/inferno/src/inferno/application.cpp index c5a00d2..e73a5b7 100644 --- a/inferno/src/inferno/application.cpp +++ b/inferno/src/inferno/application.cpp @@ -37,19 +37,28 @@ namespace Inferno { Input::initialize(); + ShaderManager* shaderManager = new ShaderManager(); + shaderManager->initialize(); + + TextureManager* textureManager = new TextureManager(); + textureManager->initialize(); + m_cameraO = std::make_shared(); m_cameraP = std::make_shared(); - TextureManager textureManager; - m_texture = textureManager.load("assets/gfx/test.png"); - m_texture2 = textureManager.load("assets/gfx/test-inverted.png"); - Renderer2D::initialize(); + + // Load assets + + m_texture = TextureManager::the().load("assets/gfx/test.png"); + m_texture2 = TextureManager::the().load("assets/gfx/test-inverted.png"); } Application::~Application() { Renderer2D::destroy(); + TextureManager::the().destroy(); + ShaderManager::the().destroy(); // Input::destroy(); Settings::destroy(); } diff --git a/inferno/src/inferno/render/shader.cpp b/inferno/src/inferno/render/shader.cpp index 88532fe..76b3dbe 100644 --- a/inferno/src/inferno/render/shader.cpp +++ b/inferno/src/inferno/render/shader.cpp @@ -191,6 +191,22 @@ namespace Inferno { // ----------------------------------------- + ShaderManager* ShaderManager::s_instance = nullptr; + + void ShaderManager::initialize() + { + ASSERT(!s_instance, "ShaderManager already exists!"); + s_instance = this; + + dbg(Log::Info) << "ShaderManager initialized"; + } + + void ShaderManager::destroy() + { + delete s_instance; + s_instance = nullptr; + } + void ShaderManager::add(const std::string& name, const std::shared_ptr& shader) { // Construct (key, value) pair and insert it into the unordered_map diff --git a/inferno/src/inferno/render/shader.h b/inferno/src/inferno/render/shader.h index d885130..53ed55c 100644 --- a/inferno/src/inferno/render/shader.h +++ b/inferno/src/inferno/render/shader.h @@ -47,6 +47,9 @@ namespace Inferno { class ShaderManager { public: + void initialize(); + void destroy(); + void add(const std::string& name, const std::shared_ptr& shader); std::shared_ptr load(const std::string& name); std::shared_ptr load(const std::string& vertexSource, @@ -57,12 +60,16 @@ namespace Inferno { void remove(const std::string& name); void remove(const std::shared_ptr& shader); + static inline ShaderManager& the() { return *s_instance; } + protected: std::string computeName(const std::string& vertexSource, const std::string& fragmentSource); private: std::unordered_map> m_shaderList; + + static ShaderManager* s_instance; }; } diff --git a/inferno/src/inferno/render/texture.cpp b/inferno/src/inferno/render/texture.cpp index f1c14a8..a099c79 100644 --- a/inferno/src/inferno/render/texture.cpp +++ b/inferno/src/inferno/render/texture.cpp @@ -101,6 +101,22 @@ namespace Inferno { // ----------------------------------------- + TextureManager* TextureManager::s_instance = nullptr; + + void TextureManager::initialize() + { + ASSERT(!s_instance, "TextureManager already exists!"); + s_instance = this; + + dbg(Log::Info) << "TextureManager initialized"; + } + + void TextureManager::destroy() + { + delete s_instance; + s_instance = nullptr; + } + void TextureManager::add(const std::string& path, const std::shared_ptr& texture) { // Construct (key, value) pair and insert it into the unordered_map diff --git a/inferno/src/inferno/render/texture.h b/inferno/src/inferno/render/texture.h index 7f9996b..0ac8e51 100644 --- a/inferno/src/inferno/render/texture.h +++ b/inferno/src/inferno/render/texture.h @@ -39,6 +39,9 @@ namespace Inferno { class TextureManager { public: + void initialize(); + void destroy(); + void add(const std::string& path, const std::shared_ptr& texture); std::shared_ptr load(const std::string& path); std::shared_ptr get(const std::string& path); @@ -47,8 +50,12 @@ namespace Inferno { void remove(const std::string& path); void remove(const std::shared_ptr& texture); + static inline TextureManager& the() { return *s_instance; } + private: std::unordered_map> m_textureList; + + static TextureManager* s_instance; }; }