aboutsummaryrefslogtreecommitdiff
path: root/include/RenderBackend/OpenGL/Shader.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-11-04 00:50:45 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-18 15:21:48 +0100
commit23a37b2cdd8ffde8bb85a4159888bf3a7ec35966 (patch)
tree83db7b81936621b6a2435e9b5db0de18496cd12f /include/RenderBackend/OpenGL/Shader.hpp
parentfbd2e5d9a802db4fb5e056705ec599ac423e09be (diff)
Use external shaders instead of generating shader code from c++ code...
Diffstat (limited to 'include/RenderBackend/OpenGL/Shader.hpp')
-rw-r--r--include/RenderBackend/OpenGL/Shader.hpp81
1 files changed, 14 insertions, 67 deletions
diff --git a/include/RenderBackend/OpenGL/Shader.hpp b/include/RenderBackend/OpenGL/Shader.hpp
index 7aecc4e..0f802ec 100644
--- a/include/RenderBackend/OpenGL/Shader.hpp
+++ b/include/RenderBackend/OpenGL/Shader.hpp
@@ -1,79 +1,26 @@
#pragma once
-#include "../../DataView.hpp"
-#include "../../utils.hpp"
#include "../../Result.hpp"
-#include "CommonShader.hpp"
-#include "ShaderVec.hpp"
-#include <string>
-#include <unordered_map>
-#include <vector>
-#include <stdexcept>
-#include <functional>
+#include "../../utils.hpp"
+#include "../../types.hpp"
+#include <memory>
namespace amalgine {
- class ShaderTooManyAttributes : public std::runtime_error
- {
- public:
- ShaderTooManyAttributes(i32 maxAttributes);
- };
-
- class ShaderAttributeAlreadyDefined : public std::runtime_error
- {
- public:
- ShaderAttributeAlreadyDefined(const std::string &attributeName);
- };
-
- class ShaderInvalidAttributeName : public std::runtime_error
- {
- public:
- ShaderInvalidAttributeName(const std::string &attributeName);
- };
-
- class ShaderFunctionAlreadyDefined : public std::runtime_error
- {
- public:
- ShaderFunctionAlreadyDefined(const std::string &funcName);
- };
-
class Shader
{
DISABLE_COPY(Shader)
friend class ShaderProgram;
public:
- Shader();
-
- const std::string& getOutputAttributeName(i32 attributeIndex);
- const std::string& getInputAttributeName(i32 attributeIndex) const;
- AttributeType getInputAttributeType(i32 attributeIndex) const;
- ShaderOutputVec4 defineOutputVec4(const std::string &name);
- ShaderGlobalVec3 defineGlobalVec3(const std::string &name);
- ShaderInputVec2 defineInputVec2(const std::string &name);
- i32 defineInputVariable(const std::string &variableName, const char *typeName);
-
- void assign(const ShaderOutputVec4 &lhsVariable, const ShaderVec4 &rhsVariable);
- protected:
- void writeHeader(const std::string &code);
- void writeBody(const std::string &code);
- std::string build() const;
-
- /*
- * Throws ShaderTooManyAttributes if too many attributes are defined for the platform.
- * Throws ShaderAttributeAlreadyDefined if a attribute with the same name has already been defined.
- */
- i32 defineOutputVariable(const std::string &variableName, const char *typeName);
- protected:
- std::string header;
- std::string body;
- int inputLocationCounter;
- int outputLocationCounter;
- // TOOD: Verify if this is correct. This same variable is used for both output and input variables
- i32 maxAttribs; // Could make this static
- std::unordered_map<std::string, i32> inputAttributes;
- std::vector<ShaderAttribute> inputAttributeNames;
- std::unordered_map<std::string, i32> outputAttributes;
- std::vector<ShaderAttribute> outputAttributeNames;
- std::unordered_map<std::string, ShaderGlobalVec> uniforms;
- bool mainFuncDefined;
+ enum class Type {
+ VERTEX,
+ PIXEL
+ };
+
+ ~Shader();
+
+ static Result<std::unique_ptr<Shader>> compile(Type type, const char *str, int size);
+ const u32 id;
+ private:
+ Shader(u32 shader_id);
};
}