diff options
author | hnOsmium0001 <[email protected]> | 2022-04-15 20:30:39 -0700 |
---|---|---|
committer | hnOsmium0001 <[email protected]> | 2022-04-15 20:30:39 -0700 |
commit | 509201784d6525fc26345e55a56ab81e4a7616b3 (patch) | |
tree | bcd68f247937324d06480b58a284b47e1c6bb2b8 /source/Shader.hpp | |
parent | 989f90ebe2c37e8a517691a35d7e0d827fbe7006 (diff) |
Work on Material system
Diffstat (limited to 'source/Shader.hpp')
-rw-r--r-- | source/Shader.hpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/source/Shader.hpp b/source/Shader.hpp index cda5531..79262a6 100644 --- a/source/Shader.hpp +++ b/source/Shader.hpp @@ -13,13 +13,18 @@ // TODO move to variable after pattern matching is in the language +// Forward declarations +class Shader; + struct ShaderVariable { enum Kind { KD_Math, KD_Sampler, }; + std::string name; Kind kind; + GLuint location; protected: ShaderVariable(Kind kind) @@ -27,8 +32,6 @@ protected: }; struct ShaderMathVariable : public ShaderVariable { - std::string name; - GLuint location; GLenum scalarType; int arrayLength; int width; @@ -39,8 +42,6 @@ struct ShaderMathVariable : public ShaderVariable { }; struct ShaderSamplerVariable : public ShaderVariable { - std::string name; - GLuint location; GLenum type; int arrayLength; @@ -48,31 +49,36 @@ struct ShaderSamplerVariable : public ShaderVariable { : ShaderVariable(KD_Sampler) {} }; -struct ShaderInfo { - enum ThingKind { - TKD_Input, - TKD_Output, - TKD_Uniform, - TKD_UniformBlock, +struct ShaderThingId { + enum Kind { + KD_Input, + KD_Output, + KD_Uniform, + KD_Invalid, }; - struct ThingId { - ThingKind kind; - int index; - }; + Kind kind = KD_Invalid; + int index = 0; + + bool IsValid() const; +}; +struct ShaderInfo { struct InputOutputThing { ShaderMathVariable variable; Tags::VertexElementSemantic semantic = Tags::VES_Generic; }; - absl::flat_hash_map<std::string, ThingId> things; + absl::flat_hash_map<std::string, ShaderThingId> things; std::vector<InputOutputThing> inputs; std::vector<InputOutputThing> outputs; std::vector<std::unique_ptr<ShaderVariable>> uniforms; + ShaderVariable* FindVariable(const ShaderThingId& thing); + bool SaveToFile(const std::filesystem::path& filePath) const; bool LoadFromFile(const std::filesystem::path& filePath); + void LoadLocations(const Shader& ownerShader); }; class Shader : public RefCounted { @@ -129,6 +135,9 @@ public: EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } + void GetDesignatedMetadataPath(char* buffer, int bufferSize); + std::filesystem::path GetDesignatedMetadataPath(); + bool CreateEmptyInfoIfAbsent(); bool GatherInfoIfAbsent(); ShaderInfo* GetInfo() const; |