diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-20 20:55:05 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 15:21:46 +0100 |
commit | ca92d8c90f7103db6d7cae4cef49b278d804b474 (patch) | |
tree | baf44e42fcc1cf7e871a7b2f1d3d92f680f3a845 /include/RenderBackend/OpenGL/PixelShader.hpp | |
parent | 3d7f123c0fc0af4b8df3ad791b264d22268bd423 (diff) |
Create shader using c++ code
Diffstat (limited to 'include/RenderBackend/OpenGL/PixelShader.hpp')
-rw-r--r-- | include/RenderBackend/OpenGL/PixelShader.hpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/include/RenderBackend/OpenGL/PixelShader.hpp b/include/RenderBackend/OpenGL/PixelShader.hpp new file mode 100644 index 0000000..3d33155 --- /dev/null +++ b/include/RenderBackend/OpenGL/PixelShader.hpp @@ -0,0 +1,71 @@ +#pragma once + +#include "../../DataView.hpp" +#include "ShaderVec.hpp" +#include <string> +#include <unordered_map> +#include <vector> +#include <stdexcept> +#include <functional> + +namespace amalgine +{ + class PixelShaderTooManyAttributes : public std::runtime_error + { + public: + PixelShaderTooManyAttributes(i32 maxPixelAttributes); + }; + + class PixelShaderAttributeAlreadyDefined : public std::runtime_error + { + public: + PixelShaderAttributeAlreadyDefined(const std::string &attributeName); + }; + + class PixelShaderInvalidAttributeName : public std::runtime_error + { + public: + PixelShaderInvalidAttributeName(const std::string &attributeName); + }; + + class PixelShaderFunctionAlreadyDefined : public std::runtime_error + { + public: + PixelShaderFunctionAlreadyDefined(const std::string &funcName); + }; + + using PixelShaderMainFunc = std::function<void()>; + + /* + * Using the same PixelShader instance in multiple threads to define data is not thread safe. + * All get*** functions are thread safe. + */ + class PixelShader + { + public: + PixelShader(); + + const std::string& getOutputAttributeName(i32 attributeIndex); + ShaderOutputVec4 defineOutputVec4(const std::string &name); + void defineMain(PixelShaderMainFunc mainFunc); + void assign(const ShaderOutputVec4 &lhsVariable, const ShaderVec4 &rhsVariable); + std::string build(); + private: + void writeHeader(const std::string &code); + void writeBody(const std::string &code); + + /* + * Throws PixelShaderTooManyAttributes if too many pixel attributes are defined for the platform. + * Throws PixelShaderAttributeAlreadyDefined if a pixel attribute with the same name has already been defined. + */ + i32 defineOutputVariable(const std::string &variableName, const char *typeName); + private: + std::string header; + std::string body; + int locationCounter; + i32 maxPixelAttribs; // Could make this static + std::unordered_map<std::string, i32> pixelAttributes; + std::vector<std::string> pixelAttributeNames; + bool mainFuncDefined; + }; +} |