diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-02-14 10:43:26 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 15:22:09 +0100 |
commit | 83c78e2b5cc9b0cb737ec3785722ae280bd29b65 (patch) | |
tree | 8c1f522bc19d4adc7df849fe09f8afc9513f9d65 /include | |
parent | 23a37b2cdd8ffde8bb85a4159888bf3a7ec35966 (diff) |
Use shader from file..
Diffstat (limited to 'include')
-rw-r--r-- | include/RenderBackend/OpenGL/DeviceMemory.hpp | 3 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/ShaderProgram.hpp | 7 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/Uniform.hpp | 29 | ||||
-rw-r--r-- | include/Result.hpp | 12 | ||||
-rw-r--r-- | include/Triangle.hpp | 23 | ||||
-rw-r--r-- | include/Triangle2D.hpp | 16 | ||||
-rw-r--r-- | include/Vertex.hpp | 28 | ||||
-rw-r--r-- | include/Vertex2D.hpp | 18 |
8 files changed, 96 insertions, 40 deletions
diff --git a/include/RenderBackend/OpenGL/DeviceMemory.hpp b/include/RenderBackend/OpenGL/DeviceMemory.hpp index c9c8b23..3ccd0c9 100644 --- a/include/RenderBackend/OpenGL/DeviceMemory.hpp +++ b/include/RenderBackend/OpenGL/DeviceMemory.hpp @@ -2,7 +2,7 @@ #include "../../DataView.hpp" #include "../../utils.hpp" -#include "../../Triangle2D.hpp" +#include "../../Triangle.hpp" namespace amalgine { enum class DeviceMemoryType { @@ -37,6 +37,7 @@ namespace amalgine { ~DeviceMemory(); //void copy(const DataView<f32> &data, StorageType storageType, PrimitiveType primitiveType = PrimitiveType::TRIANGLE); void copy(const DataView<Triangle2D> &triangles, StorageType storageType); + void copy(const DataView<Triangle3D> &triangles, StorageType storageType); void draw(); DeviceMemoryType get_type() const { return type; } diff --git a/include/RenderBackend/OpenGL/ShaderProgram.hpp b/include/RenderBackend/OpenGL/ShaderProgram.hpp index ca96d0c..f1fea00 100644 --- a/include/RenderBackend/OpenGL/ShaderProgram.hpp +++ b/include/RenderBackend/OpenGL/ShaderProgram.hpp @@ -4,9 +4,13 @@ #include "../../types.hpp" #include "../../utils.hpp" #include "../../Vec.hpp" +#include "Uniform.hpp" #include "DeviceMemory.hpp" + #include <vector> #include <memory> +#include <glm/gtc/matrix_transform.hpp> +#include <glm/gtc/type_ptr.hpp> namespace amalgine { class Shader; @@ -17,7 +21,8 @@ namespace amalgine { public: ~ShaderProgram(); static Result<std::unique_ptr<ShaderProgram>> build(const std::vector<Shader*> &shaders); - int set_uniform(const char *name, const vec3f &value); + + Result<Uniform> get_uniform_by_name(const char *name); int set_vertex_input(const char *name, const DeviceMemory &data); void use(); diff --git a/include/RenderBackend/OpenGL/Uniform.hpp b/include/RenderBackend/OpenGL/Uniform.hpp new file mode 100644 index 0000000..288c9b8 --- /dev/null +++ b/include/RenderBackend/OpenGL/Uniform.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "../../Result.hpp" +#include "../../types.hpp" +#include "../../utils.hpp" +#include "../../Vec.hpp" + +#include <glm/gtc/type_ptr.hpp> + +namespace amalgine { + class Uniform { + DISABLE_COPY(Uniform) + friend class ShaderProgram; + friend class Result<Uniform>; + public: + Uniform(Uniform&&) = default; + ~Uniform(); + + void set(const vec3f &value); + void set(const glm::mat4 &value); + private: + Uniform(){} + Uniform(i32 uniform_id, u32 shader_program_id); + void use(); + private: + i32 uniform_id; + u32 program_id; + }; +} diff --git a/include/Result.hpp b/include/Result.hpp index 50a0d0c..86ae176 100644 --- a/include/Result.hpp +++ b/include/Result.hpp @@ -11,9 +11,7 @@ namespace amalgine public: static Result<T> Ok(T data) { - Result<T> result; - result.data = std::move(data); - result.errorCode = 0; + Result<T> result(std::move(data)); return result; } @@ -42,11 +40,17 @@ namespace amalgine assert(isOk()); return data; } + + T* operator -> () { + assert(isOk()); + return &data; + } const std::string& getErrorMsg() const { return errorMsg; } int getErrorCode() const { return errorCode; } private: - Result(){} + Result() {} + Result(T data) : data(std::move(data)), errorCode(0) {} private: T data; int errorCode; diff --git a/include/Triangle.hpp b/include/Triangle.hpp new file mode 100644 index 0000000..5caff05 --- /dev/null +++ b/include/Triangle.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "Vertex.hpp" + +namespace amalgine { + class Triangle2D { + public: + Triangle2D(const Vertex2D &_p1, const Vertex2D &_p2, const Vertex2D &_p3) : p1(_p1), p2(_p2), p3(_p3) {} + + Vertex2D p1; + Vertex2D p2; + Vertex2D p3; + }; + + class Triangle3D { + public: + Triangle3D(const Vertex3D &_p1, const Vertex3D &_p2, const Vertex3D &_p3) : p1(_p1), p2(_p2), p3(_p3) {} + + Vertex3D p1; + Vertex3D p2; + Vertex3D p3; + }; +} diff --git a/include/Triangle2D.hpp b/include/Triangle2D.hpp deleted file mode 100644 index d5d76bd..0000000 --- a/include/Triangle2D.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Vertex2D.hpp" - -namespace amalgine -{ - class Triangle2D - { - public: - Triangle2D(const Vertex2D &_p1, const Vertex2D &_p2, const Vertex2D &_p3) : p1(_p1), p2(_p2), p3(_p3) {} - - Vertex2D p1; - Vertex2D p2; - Vertex2D p3; - }; -} diff --git a/include/Vertex.hpp b/include/Vertex.hpp new file mode 100644 index 0000000..ab98d3b --- /dev/null +++ b/include/Vertex.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "types.hpp" + +namespace amalgine { + class Vertex2D { + public: + Vertex2D(f32 _x = 0.0f, f32 _y = 0.0f) : x(_x), y(_y) + { + + } + + f32 x; + f32 y; + }; + + class Vertex3D { + public: + Vertex3D(f32 _x = 0.0f, f32 _y = 0.0f, f32 _z = 0.0f) : x(_x), y(_y), z(_z) + { + + } + + f32 x; + f32 y; + f32 z; + }; +}
\ No newline at end of file diff --git a/include/Vertex2D.hpp b/include/Vertex2D.hpp deleted file mode 100644 index de22cd9..0000000 --- a/include/Vertex2D.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "types.hpp" - -namespace amalgine -{ - class Vertex2D - { - public: - Vertex2D(f32 _x = 0.0f, f32 _y = 0.0f) : x(_x), y(_y) - { - - } - - f32 x; - f32 y; - }; -} |