diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-18 06:48:50 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 06:48:50 +0100 |
commit | a2ac8b537a61fb7a7be1a3e08635ffc88e17d966 (patch) | |
tree | b7594e7d1cff0abaecdd8e96ef0ad90bce8f1098 | |
parent | 3f8099b9b5c64e912a2ca227a9e3b2ce774f5ff3 (diff) |
Disable copy constructors for opengl resource items
-rw-r--r-- | include/mglpp/graphics/Font.hpp | 2 | ||||
-rw-r--r-- | include/mglpp/graphics/Image.hpp | 2 | ||||
-rw-r--r-- | include/mglpp/graphics/Shader.hpp | 2 | ||||
-rw-r--r-- | include/mglpp/graphics/Texture.hpp | 5 | ||||
-rw-r--r-- | include/mglpp/system/MemoryMappedFile.hpp | 2 | ||||
-rw-r--r-- | include/mglpp/window/Window.hpp | 2 | ||||
-rw-r--r-- | src/graphics/Texture.cpp | 15 |
7 files changed, 29 insertions, 1 deletions
diff --git a/include/mglpp/graphics/Font.hpp b/include/mglpp/graphics/Font.hpp index ca6a146..afba8d3 100644 --- a/include/mglpp/graphics/Font.hpp +++ b/include/mglpp/graphics/Font.hpp @@ -22,6 +22,8 @@ namespace mgl { class Font { public: Font(); + Font(const Font&) = delete; + Font& operator=(const Font&) = delete; ~Font(); bool load_from_file(const MemoryMappedFile &mapped_file, unsigned int character_size); diff --git a/include/mglpp/graphics/Image.hpp b/include/mglpp/graphics/Image.hpp index a868ad6..4a55ba5 100644 --- a/include/mglpp/graphics/Image.hpp +++ b/include/mglpp/graphics/Image.hpp @@ -11,6 +11,8 @@ namespace mgl { class Image { public: Image(); + Image(const Image&) = delete; + Image& operator=(const Image&) = delete; ~Image(); bool load_from_file(const char *filepath); diff --git a/include/mglpp/graphics/Shader.hpp b/include/mglpp/graphics/Shader.hpp index 0aedc47..2d1336d 100644 --- a/include/mglpp/graphics/Shader.hpp +++ b/include/mglpp/graphics/Shader.hpp @@ -17,6 +17,8 @@ namespace mgl { }; Shader(); + Shader(const Shader&) = delete; + Shader& operator=(const Shader&) = delete; ~Shader(); bool load_from_file(const char *filepath, Type type); diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp index 633d2cd..5ef94a0 100644 --- a/include/mglpp/graphics/Texture.hpp +++ b/include/mglpp/graphics/Texture.hpp @@ -17,17 +17,22 @@ namespace mgl { }; Texture(); + Texture(Texture &&other); ~Texture(); static Texture reference(mgl_texture ref); bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false}); bool load_from_image(Image &image, const LoadOptions load_options = {false, false}); + void clear(); vec2i get_size() const; bool is_valid() const; mgl_texture* internal_texture(); private: + Texture(const Texture&); + Texture& operator=(const Texture&); + private: mgl_texture texture; bool owned = true; }; diff --git a/include/mglpp/system/MemoryMappedFile.hpp b/include/mglpp/system/MemoryMappedFile.hpp index 508518a..1be23d4 100644 --- a/include/mglpp/system/MemoryMappedFile.hpp +++ b/include/mglpp/system/MemoryMappedFile.hpp @@ -14,6 +14,8 @@ namespace mgl { }; MemoryMappedFile(); + MemoryMappedFile(const MemoryMappedFile&) = delete; + MemoryMappedFile& operator=(const MemoryMappedFile&) = delete; ~MemoryMappedFile(); bool load(const char *filepath, LoadOptions load_options = { true, true }); diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 1ce399c..1b7c292 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -38,6 +38,8 @@ namespace mgl { }; Window(); + Window(const Window&) = delete; + Window& operator=(const Window&) = delete; ~Window(); bool create(const char *title, CreateParams create_params); diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index f543c37..29c2eea 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -1,9 +1,15 @@ #include "../../include/mglpp/graphics/Texture.hpp" #include "../../include/mglpp/graphics/Image.hpp" +#include <string.h> namespace mgl { Texture::Texture() { - texture.id = 0; + memset(&texture, 0, sizeof(mgl_texture)); + } + + Texture::Texture(Texture &&other) { + memcpy(&texture, &other.texture, sizeof(mgl_texture)); + other.texture.id = 0; } Texture::~Texture() { @@ -47,6 +53,13 @@ namespace mgl { return mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0; } + void Texture::clear() { + if(owned) + mgl_texture_unload(&texture); + memset(&texture, 0, sizeof(mgl_texture)); + owned = true; + } + vec2i Texture::get_size() const { return { texture.width, texture.height }; } |