From 8d525bc1c3506f15a5f68672245f845cebe18eef Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 28 Oct 2021 17:33:57 +0200 Subject: More, todo interfaces --- src/graphics/Texture.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/graphics/Texture.cpp') diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 14e18df..cdaa3ba 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -1,4 +1,5 @@ #include "../../include/mglpp/graphics/Texture.hpp" +#include "../../include/mglpp/graphics/Image.hpp" namespace mgl { Texture::Texture() { @@ -6,7 +7,16 @@ namespace mgl { } Texture::~Texture() { - mgl_texture_unload(&texture); + if(owned) + mgl_texture_unload(&texture); + } + + // static + Texture Texture::reference(mgl_texture ref) { + Texture instance; + instance.texture = ref; + instance.owned = false; + return instance; } bool Texture::load_from_file(const char *filepath) { @@ -16,6 +26,13 @@ namespace mgl { return mgl_texture_load_from_file(&texture, filepath, nullptr) == 0; } + bool Texture::load_from_image(Image &image) { + if(texture.id) + return false; + /* TODO: use the last arg (load options) */ + return mgl_texture_load_from_image(&texture, image.internal_image(), nullptr) == 0; + } + vec2i Texture::get_size() const { return { texture.width, texture.height }; } -- cgit v1.2.3