From be41f208c6660a879818321e2904795c7d45fe3e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 31 Jul 2024 20:56:23 +0200 Subject: Add mipmap, texture load from memory --- src/graphics/Sprite.cpp | 6 ++---- src/graphics/Texture.cpp | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index f2ba460..de9e96c 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -35,10 +35,8 @@ namespace mgl { } vec2f Sprite::get_size() const { - if(texture) - return get_scale() * mgl::vec2f(texture->get_size().x, texture->get_size().y); - else - return { 0.0f, 0.0f }; + const mgl_vec2f v = mgl_sprite_get_size(&sprite); + return { v.x, v.y }; } void Sprite::set_scale(vec2f scale) { diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 86c4ac0..1bcf3af 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -47,9 +47,10 @@ namespace mgl { if(mgl_texture_init(&texture) != 0) return false; - mgl_texture_load_options texture_load_options = { + const mgl_texture_load_options texture_load_options = { load_options.compressed, - load_options.pixel_coordinates + load_options.pixel_coordinates, + load_options.mipmap }; return mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0; } @@ -61,13 +62,29 @@ namespace mgl { if(mgl_texture_init(&texture) != 0) return false; - mgl_texture_load_options texture_load_options = { + const mgl_texture_load_options texture_load_options = { load_options.compressed, - load_options.pixel_coordinates + load_options.pixel_coordinates, + load_options.mipmap }; return mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0; } + bool Texture::load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options) { + if(texture.id) + clear(); + + if(mgl_texture_init(&texture) != 0) + return false; + + const mgl_texture_load_options texture_load_options = { + load_options.compressed, + load_options.pixel_coordinates, + load_options.mipmap + }; + return mgl_texture_load_from_memory(&texture, data, width, height, format, &texture_load_options) == 0; + } + void Texture::clear() { if(owned) mgl_texture_unload(&texture); -- cgit v1.2.3