From 047f294de1b4d385b811ac9f5afc393d81cc4ae9 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 16 Aug 2025 11:23:49 -0700 Subject: Copy changes from the no-history fork, generated back in 2023 Original commit message: > commit f138311d2d2e0cc9ba0496d523bb46f2c1c9fb73 > Author: rtk0c > 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. --- source/30-game/Shader.hpp | 81 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'source/30-game/Shader.hpp') 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 #include +#include #include #include +#include #include // 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; - - ShaderMathVariable() - : ShaderVariable(KD_Math) {} - - virtual void ShowInfo() const override; + int arrayLength = 1; + + void ShowInfo() const; + + template + void json_io(TJsonIo& io) { + io& json_dto::mandatory("Name", name); + io& json_dto::mandatory("Semantic", static_cast(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; - - ShaderSamplerVariable() - : ShaderVariable(KD_Sampler) {} - - virtual void ShowInfo() const override; +struct ShaderSamplerVariable { + std::string name; + GLuint location; + Tags::VertexElementSemantic semantic = Tags::VES_Generic; + GLenum samplerType; + int arrayLength = 1; + + void ShowInfo() const; + + template + void json_io(TJsonIo& io) { + io& json_dto::mandatory("Name", name); + io& json_dto::mandatory("Semantic", static_cast(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 things; std::vector inputs; std::vector outputs; - std::vector> uniforms; + std::vector> 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 + 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 { -- cgit v1.2.3-70-g09d2