diff options
author | rtk0c <[email protected]> | 2025-08-16 11:23:49 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2025-08-16 11:23:49 -0700 |
commit | 047f294de1b4d385b811ac9f5afc393d81cc4ae9 (patch) | |
tree | f96100a813a4ffb28dcd074455d3a2f8ee426430 /source/30-game/Shader.hpp | |
parent | 488fb8b4b9da7f99a5cc37e39fff9f1cb700f2a8 (diff) |
Copy changes from the no-history fork, generated back in 2023
Original commit message:
> commit f138311d2d2e0cc9ba0496d523bb46f2c1c9fb73
> Author: rtk0c <[email protected]>
> Date: Wed Sep 20 23:58:58 2023 -0700
>
> Copy from the PlasticSCM repo, replace vendored glm wtih conan
In reality, this also introduced a few uncommitted changes in the
original PlasticSCM repo. See the modified and new files in this patch.
Diffstat (limited to 'source/30-game/Shader.hpp')
-rw-r--r-- | source/30-game/Shader.hpp | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/source/30-game/Shader.hpp b/source/30-game/Shader.hpp index 707e6cc..cb980cd 100644 --- a/source/30-game/Shader.hpp +++ b/source/30-game/Shader.hpp @@ -7,8 +7,10 @@ #include <glad/glad.h> #include <robin_hood.h> +#include <json_dto/pub.hpp> #include <memory> #include <string_view> +#include <variant> #include <vector> // TODO move to variable after pattern matching is in the language @@ -17,44 +19,44 @@ class Shader; class IresShader; -struct ShaderVariable { - enum Kind { - KD_Math, - KD_Sampler, - }; - +struct ShaderMathVariable { std::string name; - Kind kind; GLuint location; Tags::VertexElementSemantic semantic = Tags::VES_Generic; - - virtual void ShowInfo() const = 0; - -protected: - ShaderVariable(Kind kind) - : kind{ kind } {} -}; - -struct ShaderMathVariable : public ShaderVariable { GLenum scalarType; - int arrayLength; int width; int height; + int arrayLength = 1; - ShaderMathVariable() - : ShaderVariable(KD_Math) {} + void ShowInfo() const; - virtual void ShowInfo() const override; + template <typename TJsonIo> + void json_io(TJsonIo& io) { + io& json_dto::mandatory("Name", name); + io& json_dto::mandatory("Semantic", static_cast<int>(semantic)); + io& json_dto::mandatory("ScalarType", scalarType); + io& json_dto::mandatory("Width", width); + io& json_dto::mandatory("Height", height); + io& json_dto::optional("ArrayLength", arrayLength, 1); + } }; -struct ShaderSamplerVariable : public ShaderVariable { - GLenum type; - int arrayLength; +struct ShaderSamplerVariable { + std::string name; + GLuint location; + Tags::VertexElementSemantic semantic = Tags::VES_Generic; + GLenum samplerType; + int arrayLength = 1; - ShaderSamplerVariable() - : ShaderVariable(KD_Sampler) {} + void ShowInfo() const; - virtual void ShowInfo() const override; + template <typename TJsonIo> + void json_io(TJsonIo& io) { + io& json_dto::mandatory("Name", name); + io& json_dto::mandatory("Semantic", static_cast<int>(semantic)); + io& json_dto::mandatory("SamplerType", samplerType); + io& json_dto::optional("ArrayLength", arrayLength, 1); + } }; struct ShaderThingId { @@ -62,24 +64,29 @@ struct ShaderThingId { KD_Input, KD_Output, KD_Uniform, - KD_Invalid, }; - Kind kind = KD_Invalid; - int index = 0; - - bool IsValid() const; + Kind kind; + int index; }; struct ShaderInfo { robin_hood::unordered_map<std::string, ShaderThingId, StringHash, StringEqual> things; std::vector<ShaderMathVariable> inputs; std::vector<ShaderMathVariable> outputs; - std::vector<std::unique_ptr<ShaderVariable>> uniforms; + std::vector<std::variant<ShaderMathVariable, ShaderSamplerVariable>> uniforms; + // Find the first variable with the matching semantic GLuint FindInputLocation(Tags::VertexElementSemantic semantic); GLuint FindOutputLocation(Tags::VertexElementSemantic semantic); - ShaderVariable* FindVariable(const ShaderThingId& thing); + + template <typename TJsonIo> + void json_io(TJsonIo& io) { + io& json_dto::mandatory("Inputs", inputs); + io& json_dto::mandatory("Outputs", outputs); + // TODO make json_dto support std::variant +// io& json_dto::mandatory("Uniforms", uniforms); + } }; class Shader : public RefCounted { |