From e4d073947d09634e95325ddaf8f1615f85e85901 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 15 Feb 2020 01:36:41 +0100 Subject: Load texture in obj model loader.. broken --- include/Image.hpp | 26 ++++++++++++++++++++++++++ include/RenderBackend/OpenGL/DeviceMemory.hpp | 2 ++ include/RenderBackend/OpenGL/Image.hpp | 26 -------------------------- include/RenderBackend/OpenGL/ShaderProgram.hpp | 2 +- include/RenderBackend/OpenGL/Texture2D.hpp | 6 +++++- include/RenderBackend/OpenGL/Uniform.hpp | 3 +++ include/Triangle.hpp | 4 ---- include/Vec.hpp | 10 +++++++++- include/Vertex.hpp | 10 ---------- include/model_loader/ObjModelLoader.hpp | 5 ++++- 10 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 include/Image.hpp delete mode 100644 include/RenderBackend/OpenGL/Image.hpp (limited to 'include') diff --git a/include/Image.hpp b/include/Image.hpp new file mode 100644 index 0000000..19a5e8b --- /dev/null +++ b/include/Image.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "utils.hpp" +#include "types.hpp" +#include "Result.hpp" + +namespace amalgine +{ + class Image + { + DISABLE_COPY(Image) + public: + static Result loadFromFile(const char *filepath); + ~Image(); + + const unsigned char* getData() const; + i32 getWidth() const; + i32 getHeight() const; + private: + Image(unsigned char *_imageData, i32 width, i32 height); + private: + unsigned char *imageData; + i32 width; + i32 height; + }; +} diff --git a/include/RenderBackend/OpenGL/DeviceMemory.hpp b/include/RenderBackend/OpenGL/DeviceMemory.hpp index 3ccd0c9..3e0fede 100644 --- a/include/RenderBackend/OpenGL/DeviceMemory.hpp +++ b/include/RenderBackend/OpenGL/DeviceMemory.hpp @@ -3,6 +3,7 @@ #include "../../DataView.hpp" #include "../../utils.hpp" #include "../../Triangle.hpp" +#include "../../Vec.hpp" namespace amalgine { enum class DeviceMemoryType { @@ -36,6 +37,7 @@ namespace amalgine { ~DeviceMemory(); //void copy(const DataView &data, StorageType storageType, PrimitiveType primitiveType = PrimitiveType::TRIANGLE); + void copy(const DataView &texture_coords, StorageType storageType); void copy(const DataView &triangles, StorageType storageType); void copy(const DataView &triangles, StorageType storageType); void draw(); diff --git a/include/RenderBackend/OpenGL/Image.hpp b/include/RenderBackend/OpenGL/Image.hpp deleted file mode 100644 index 06f0630..0000000 --- a/include/RenderBackend/OpenGL/Image.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../utils.hpp" -#include "../../types.hpp" -#include "../../Result.hpp" - -namespace amalgine -{ - class Image - { - DISABLE_COPY(Image) - public: - static Result loadFromFile(const char *filepath); - ~Image(); - - const unsigned char* getData() const; - i32 getWidth() const; - i32 getHeight() const; - private: - Image(unsigned char *_imageData, i32 width, i32 height); - private: - unsigned char *imageData; - i32 width; - i32 height; - }; -} diff --git a/include/RenderBackend/OpenGL/ShaderProgram.hpp b/include/RenderBackend/OpenGL/ShaderProgram.hpp index f1fea00..177e43c 100644 --- a/include/RenderBackend/OpenGL/ShaderProgram.hpp +++ b/include/RenderBackend/OpenGL/ShaderProgram.hpp @@ -23,7 +23,7 @@ namespace amalgine { static Result> build(const std::vector &shaders); Result get_uniform_by_name(const char *name); - int set_vertex_input(const char *name, const DeviceMemory &data); + int set_input_data(const char *name, const DeviceMemory &data); void use(); private: diff --git a/include/RenderBackend/OpenGL/Texture2D.hpp b/include/RenderBackend/OpenGL/Texture2D.hpp index 9f7c855..48b613b 100644 --- a/include/RenderBackend/OpenGL/Texture2D.hpp +++ b/include/RenderBackend/OpenGL/Texture2D.hpp @@ -11,9 +11,13 @@ namespace amalgine { DISABLE_COPY(Texture2D) public: + // Not thread safe Texture2D(Image *image); ~Texture2D(); + + i32 get_texture_id() const { return texture_id; } private: - u32 textureId; + i32 texture_id; + u32 texture_ref; }; } diff --git a/include/RenderBackend/OpenGL/Uniform.hpp b/include/RenderBackend/OpenGL/Uniform.hpp index 288c9b8..dbffa03 100644 --- a/include/RenderBackend/OpenGL/Uniform.hpp +++ b/include/RenderBackend/OpenGL/Uniform.hpp @@ -4,6 +4,7 @@ #include "../../types.hpp" #include "../../utils.hpp" #include "../../Vec.hpp" +#include "Texture2D.hpp" #include @@ -16,8 +17,10 @@ namespace amalgine { Uniform(Uniform&&) = default; ~Uniform(); + void set(float value); void set(const vec3f &value); void set(const glm::mat4 &value); + void set(const Texture2D &texture); private: Uniform(){} Uniform(i32 uniform_id, u32 shader_program_id); diff --git a/include/Triangle.hpp b/include/Triangle.hpp index 5caff05..393c45a 100644 --- a/include/Triangle.hpp +++ b/include/Triangle.hpp @@ -5,8 +5,6 @@ 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; @@ -14,8 +12,6 @@ namespace amalgine { 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/Vec.hpp b/include/Vec.hpp index 339a98b..87e9bea 100644 --- a/include/Vec.hpp +++ b/include/Vec.hpp @@ -3,12 +3,20 @@ #include "types.hpp" namespace amalgine { + struct vec2f { + f32 x; + f32 y; + + vec2f() : x(0.0f), y(0.0f) {} + vec2f(f32 x, f32 y) : x(x), y(y) {} + }; + struct vec3f { f32 x; f32 y; f32 z; - vec3f() : x(0.0f), y(0.0f) {} + vec3f() : x(0.0f), y(0.0f), z(0.0f) {} vec3f(f32 x, f32 y, f32 z) : x(x), y(y), z(z) {} }; } \ No newline at end of file diff --git a/include/Vertex.hpp b/include/Vertex.hpp index ab98d3b..3526d99 100644 --- a/include/Vertex.hpp +++ b/include/Vertex.hpp @@ -5,22 +5,12 @@ 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; diff --git a/include/model_loader/ObjModelLoader.hpp b/include/model_loader/ObjModelLoader.hpp index 3cdeb7d..5078244 100644 --- a/include/model_loader/ObjModelLoader.hpp +++ b/include/model_loader/ObjModelLoader.hpp @@ -1,11 +1,14 @@ #pragma once #include "../Triangle.hpp" +#include "../Vec.hpp" #include namespace amalgine { + class Image; + class ObjModelLoader { public: - static void load_from_file(const char *filepath, std::vector &triangles); + static void load_from_file(const char *filepath, std::vector &triangles, std::vector &texture_coords, Image **image); }; } \ No newline at end of file -- cgit v1.2.3