aboutsummaryrefslogtreecommitdiff
path: root/source/Shader.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-15 20:30:39 -0700
committerrtk0c <[email protected]>2022-04-15 20:30:39 -0700
commitafcac59c7d04f4337d6b04ebed8cac7e871ccc50 (patch)
tree8c32b90b4a0ab762a68f228dc8cc4e7f52fc5bd7 /source/Shader.hpp
parentf2a1481123ac23aeb4937df5f61c57e0e4f1ff52 (diff)
Changeset: 7 Work on Material system
Diffstat (limited to 'source/Shader.hpp')
-rw-r--r--source/Shader.hpp39
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;