diff options
Diffstat (limited to 'source/Shader.hpp')
-rw-r--r-- | source/Shader.hpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/source/Shader.hpp b/source/Shader.hpp index b481bd6..e7a069b 100644 --- a/source/Shader.hpp +++ b/source/Shader.hpp @@ -1,17 +1,26 @@ #pragma once +#include "EditorAttachment.hpp" +#include "EditorInspector.hpp" #include "RcPtr.hpp" #include <glad/glad.h> +#include <tsl/array_map.h> #include <memory> #include <string_view> -class ShaderDetails : public RefCounted { +class ShaderDetails : public EditorAttachment, public IEditorInspectorTarget { public: + std::string fileName; + +public: + virtual void ShowInspector() override; }; class Shader : public RefCounted { private: + std::unique_ptr<ShaderDetails> mDetails; + std::unique_ptr<EditorAttachment> mEditorAttachment; GLuint mHandle = 0; public: @@ -45,19 +54,6 @@ public: /// into a Shader object. ErrorCode InitFromSources(const ShaderSources& sources); - struct ShaderFilePaths { - const char* vertex = nullptr; - const char* geometry = nullptr; - const char* tessControl = nullptr; - const char* tessEval = nullptr; - const char* fragment = nullptr; - }; - - /// Create shader by loading each specified file and combining them together to form a shader object. - /// Use the mental model that this function simply loads the files from disk (synchronously) and then - /// passing them to `FromSource(const ShaderSources& source)`. - ErrorCode InitFromFiles(const ShaderFilePaths& files); - /// The given text will be split into different shader sections according to #type directives, /// and combined to form a Shader object. /// For OpenGL, this process involves compililng each section separately and then linking them @@ -71,11 +67,26 @@ public: /// - `#type fragment`: Fragment shader ErrorCode InitFromSource(std::string_view source); - /// Create shader by loading the file at the `file`, and then giving the contents to - /// `FromSource(std::string_view source)`. - ErrorCode InitFromFile(const char* file); + EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } + void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } + void GatherDetailsIfAbsent(); + const ShaderDetails* GetDetails() const; GLuint GetProgram() const; bool IsValid() const; }; + +class ShaderManager { +public: + static inline ShaderManager* instance = nullptr; + +private: + tsl::array_map<char, RcPtr<Shader>> mShaders; + +public: + void DiscoverShaders(); + + const tsl::array_map<char, RcPtr<Shader>>& GetShaders() const { return mShaders; } + Shader* FindShader(std::string_view name); +}; |