From 07e8754e4d799e44678b595177e79e6eaa621268 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 18 Apr 2022 20:59:57 -0700 Subject: Changeset: 11 Migrate Material to Ires --- source/Material.hpp | 62 +++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 50 deletions(-) (limited to 'source/Material.hpp') 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 #include #include #include -#include #include #include #include #include #include -// 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 mEditorAttachment; RcPtr mShader; std::vector mBoundScalars; std::vector 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 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 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> mMaterials; + RcPtr mInstance; public: - void DiscoverMaterials(); + IresMaterial(); + + Material* GetInstance() const; + void InvalidateInstance(); - std::pair 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; }; -- cgit v1.2.3-70-g09d2