From 83c78e2b5cc9b0cb737ec3785722ae280bd29b65 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 14 Feb 2020 10:43:26 +0100 Subject: Use shader from file.. --- include/RenderBackend/OpenGL/DeviceMemory.hpp | 3 ++- include/RenderBackend/OpenGL/ShaderProgram.hpp | 7 ++++++- include/RenderBackend/OpenGL/Uniform.hpp | 29 ++++++++++++++++++++++++++ include/Result.hpp | 12 +++++++---- include/Triangle.hpp | 23 ++++++++++++++++++++ include/Triangle2D.hpp | 16 -------------- include/Vertex.hpp | 28 +++++++++++++++++++++++++ include/Vertex2D.hpp | 18 ---------------- 8 files changed, 96 insertions(+), 40 deletions(-) create mode 100644 include/RenderBackend/OpenGL/Uniform.hpp create mode 100644 include/Triangle.hpp delete mode 100644 include/Triangle2D.hpp create mode 100644 include/Vertex.hpp delete mode 100644 include/Vertex2D.hpp (limited to 'include') 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 &data, StorageType storageType, PrimitiveType primitiveType = PrimitiveType::TRIANGLE); void copy(const DataView &triangles, StorageType storageType); + void copy(const DataView &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 #include +#include +#include namespace amalgine { class Shader; @@ -17,7 +21,8 @@ namespace amalgine { public: ~ShaderProgram(); static Result> build(const std::vector &shaders); - int set_uniform(const char *name, const vec3f &value); + + Result 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 + +namespace amalgine { + class Uniform { + DISABLE_COPY(Uniform) + friend class ShaderProgram; + friend class Result; + 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 Ok(T data) { - Result result; - result.data = std::move(data); - result.errorCode = 0; + Result 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; - }; -} -- cgit v1.2.3