diff options
author | hnOsmium0001 <[email protected]> | 2022-04-19 12:36:02 -0700 |
---|---|---|
committer | hnOsmium0001 <[email protected]> | 2022-04-19 12:36:02 -0700 |
commit | 497a0ddb2ab57f6c517543ca20ea1b8333214710 (patch) | |
tree | aa2b806837310e8abe8fdcc32a5b590496196e2b /source/Shader.hpp | |
parent | 2a5234a512c19582d261a7ccb692fc634dcb74f0 (diff) |
Add hardcoded dependencies for IresManager, migrate Shader to Ires
Diffstat (limited to 'source/Shader.hpp')
-rw-r--r-- | source/Shader.hpp | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/source/Shader.hpp b/source/Shader.hpp index 7ad2bbb..fefa67c 100644 --- a/source/Shader.hpp +++ b/source/Shader.hpp @@ -1,22 +1,21 @@ #pragma once -#include "EditorAttachment.hpp" #include "GraphicsTags.hpp" +#include "Ires.hpp" #include "RcPtr.hpp" #include "Utils.hpp" #include <glad/glad.h> #include <robin_hood.h> -#include <filesystem> #include <memory> #include <string_view> #include <vector> // TODO move to variable after pattern matching is in the language -// TODO migrate shader editor to Ires // Forward declarations class Shader; +class IresShader; struct ShaderVariable { enum Kind { @@ -84,10 +83,11 @@ struct ShaderInfo { }; class Shader : public RefCounted { + friend class IresShader; + private: - std::string mName; + IresShader* mIres = nullptr; ShaderInfo mInfo; - std::unique_ptr<EditorAttachment> mEditorAttachment; GLuint mProgram = 0; public: @@ -96,7 +96,7 @@ public: GLuint autofillLoc_DeltaTime = Tags::kInvalidLocation; public: - Shader(std::string name = ""); + Shader(); ~Shader(); Shader(const Shader&) = delete; Shader& operator=(const Shader&) = delete; @@ -139,38 +139,31 @@ public: /// - `#type fragment`: Fragment shader ErrorCode InitFromSource(std::string_view source); - EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } - void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } - - void GetDesignatedMetadataPath(char* buffer, int bufferSize); - std::filesystem::path GetDesignatedMetadataPath(); - /// Rebuild info object using OpenGL shader introspection API. Requires OpenGL 4.3 or above. Overrides existing info object. bool GatherInfoShaderIntrospection(); const ShaderInfo& GetInfo() const { return mInfo; } ShaderInfo& GetInfo() { return mInfo; } /// If not empty, this name must not duplicate with any other shader object in the process. - const std::string& GetName() const { return mName; } GLuint GetProgram() const { return mProgram; } - bool IsAnnoymous() const; - bool IsValid() const; + IresShader* GetIres() const { return mIres; } - bool SaveMetadataToFile(const std::filesystem::path& filePath) const; - /// Overrides existing info object. - bool LoadMetadataFromFile(const std::filesystem::path& filePath); + bool IsValid() const; }; -class ShaderManager { -public: - static inline ShaderManager* instance = nullptr; - +class IresShader : public IresObject { private: - robin_hood::unordered_map<std::string_view, RcPtr<Shader>> mShaders; + RcPtr<Shader> mInstance; + std::string mSourceFile; public: - void DiscoverShaders(); + IresShader(); + + Shader* GetInstance() const; + void InvalidateInstance(); + + void ShowEditor(EditorInstance& editor) override; - const auto& GetShaders() const { return mShaders; } - Shader* FindShader(std::string_view name); + void Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjson::Document& root) const override; + void Read(IresLoadingContext& ctx, const rapidjson::Value& value) override; }; |