aboutsummaryrefslogtreecommitdiff
path: root/source/Shader.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Shader.hpp')
-rw-r--r--source/Shader.hpp45
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;
};