diff options
Diffstat (limited to 'source/Material.hpp')
-rw-r--r-- | source/Material.hpp | 62 |
1 files changed, 12 insertions, 50 deletions
diff --git a/source/Material.hpp b/source/Material.hpp index 469cb7b..7cf5603 100644 --- a/source/Material.hpp +++ b/source/Material.hpp @@ -1,24 +1,20 @@ #pragma once -#include "EditorAttachment.hpp" +#include "Ires.hpp" #include "RcPtr.hpp" #include "Shader.hpp" #include "Texture.hpp" -// #include "Ires.hpp" #include <glad/glad.h> #include <robin_hood.h> #include <cstddef> #include <cstdint> -#include <filesystem> #include <glm/glm.hpp> #include <memory> #include <span> #include <string_view> #include <vector> -// TODO migrate material editor to Ires -class MaterialManager; class Material : public RefCounted { public: // NOTE: public for internal helpers and editor // NOTE: specialize between scalar vs matrix vs vector to save memory @@ -66,8 +62,6 @@ public: // NOTE: public for internal helpers and editor /* Transient */ GLint location; }; - std::string mName; - std::unique_ptr<EditorAttachment> mEditorAttachment; RcPtr<Shader> mShader; std::vector<ScalarUniform> mBoundScalars; std::vector<VectorUniform> mBoundVectors; @@ -76,7 +70,6 @@ public: // NOTE: public for internal helpers and editor public: Material(); - Material(std::string name); void SetFloat(const char* name, float value); void SetInt(const char* name, int32_t value); @@ -97,58 +90,27 @@ public: std::span<const TextureUniform> GetTextures() const; Shader* GetShader() const; void SetShader(Shader* shader); - const std::string& GetName() const; - bool IsAnnoymous() const; bool IsValid() const; void UseUniforms() const; - EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } - void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } - - void GetDesignatedPath(char* buffer, int bufferSize); - std::filesystem::path GetDesignatedPath(); - - bool SaveToFile(const std::filesystem::path& filePath) const; - bool LoadFromFile(const std::filesystem::path& filePath); + bool Write(rapidjson::Value& value, rapidjson::Document& root) const; + bool Read(const rapidjson::Value& value); }; -// class IresMaterial : public IresObject { -// public: -// RcPtr<Material> mInstance; - -// public: -// IresMaterial() -// : IresObject(KD_Spritesheet) {} - -// bool IsValid() const; - -// Material* CreateInstance() const; -// Material* GetInstance(); -// void InvalidateInstance(); - -// void ShowEditor() override; - -// void Write(rapidjson::Value& value, rapidjson::Document& root) const override; -// void Read(const rapidjson::Value& value) override; -// }; - -class MaterialManager { -public: - static inline MaterialManager* instance = nullptr; - +class IresMaterial : public IresObject { private: - robin_hood::unordered_map<std::string_view, RcPtr<Material>> mMaterials; + RcPtr<Material> mInstance; public: - void DiscoverMaterials(); + IresMaterial(); + + Material* GetInstance() const; + void InvalidateInstance(); - std::pair<Material*, bool> SaveMaterial(Material* mat); - void DeleteMaterial(Material* mat, bool onDisk = false); - Material* LoadMaterial(std::string_view name); - bool RenameMaterial(Material* mat, std::string newName); + void ShowEditor(EditorInstance& editor) override; - const auto& GetMaterials() const { return mMaterials; } - Material* FindMaterial(std::string_view name); + void Write(rapidjson::Value& value, rapidjson::Document& root) const override; + void Read(const rapidjson::Value& value) override; }; |