diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-26 09:00:38 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-26 09:03:21 +0100 |
commit | aaf0b6edbbda67c2414b4736b82a00e6fe4025f5 (patch) | |
tree | e1fb563f5fcc17209dedc9cc11b2dc328a77e6b4 /src/graphics | |
parent | 1d4cc1d1c2c4f6a574775914078c80cf496fc7de (diff) |
Allow reloading images, textures and memory mapped files
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/Font.cpp | 6 | ||||
-rw-r--r-- | src/graphics/Image.cpp | 12 | ||||
-rw-r--r-- | src/graphics/Shader.cpp | 6 | ||||
-rw-r--r-- | src/graphics/Texture.cpp | 4 |
4 files changed, 18 insertions, 10 deletions
diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index 535daae..2efae40 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -13,8 +13,10 @@ namespace mgl { } bool Font::load_from_file(const MemoryMappedFile &mapped_file, unsigned int character_size) { - if(font.texture.id) - return false; + if(font.texture.id) { + mgl_font_unload(&font); + memset(&font, 0, sizeof(font)); + } return mgl_font_load_from_file(&font, mapped_file.internal_mapped_file(), character_size) == 0; } diff --git a/src/graphics/Image.cpp b/src/graphics/Image.cpp index 74a9866..30cdb93 100644 --- a/src/graphics/Image.cpp +++ b/src/graphics/Image.cpp @@ -11,14 +11,18 @@ namespace mgl { } bool Image::load_from_file(const char *filepath) { - if(image.data) - return false; + if(image.data) { + mgl_image_unload(&image); + memset(&image, 0, sizeof(image)); + } return mgl_image_load_from_file(&image, filepath) == 0; } bool Image::load_from_memory(const unsigned char *data, size_t size) { - if(image.data) - return false; + if(image.data) { + mgl_image_unload(&image); + memset(&image, 0, sizeof(image)); + } return mgl_image_load_from_memory(&image, data, size) == 0; } diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp index 0d0e651..2bdc9b2 100644 --- a/src/graphics/Shader.cpp +++ b/src/graphics/Shader.cpp @@ -10,8 +10,10 @@ namespace mgl { } bool Shader::load_from_file(const char *filepath, Type type) { - if(shader_program.id) - return false; + if(shader_program.id) { + mgl_shader_program_deinit(&shader_program); + shader_program.id = 0; + } int res = mgl_shader_program_init(&shader_program); if(res != 0) diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 29c2eea..794c563 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -27,7 +27,7 @@ namespace mgl { bool Texture::load_from_file(const char *filepath, const LoadOptions load_options) { if(texture.id) - return false; + clear(); if(mgl_texture_init(&texture) != 0) return false; @@ -41,7 +41,7 @@ namespace mgl { bool Texture::load_from_image(Image &image, const LoadOptions load_options) { if(texture.id) - return false; + clear(); if(mgl_texture_init(&texture) != 0) return false; |