diff options
Diffstat (limited to 'src/RenderBackend/OpenGL/Texture2D.cpp')
-rw-r--r-- | src/RenderBackend/OpenGL/Texture2D.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/RenderBackend/OpenGL/Texture2D.cpp b/src/RenderBackend/OpenGL/Texture2D.cpp index dcb9cef..f4326a8 100644 --- a/src/RenderBackend/OpenGL/Texture2D.cpp +++ b/src/RenderBackend/OpenGL/Texture2D.cpp @@ -39,6 +39,10 @@ namespace amalgine { static TextureIdAllocator *texture_id_allocator = nullptr; + Texture2D::Texture2D() : texture_id(-1), texture_ref(-1) { + + } + Texture2D::Texture2D(Image *image) { assert(image); @@ -46,6 +50,8 @@ namespace amalgine { texture_id_allocator = new TextureIdAllocator(); texture_id = texture_id_allocator->get_free_texture_id(); + printf("texture id: %d\n", texture_id); + texture_ref = -1; glGenTextures(1, &texture_ref); glActiveTexture(GL_TEXTURE0 + texture_id); glBindTexture(GL_TEXTURE_2D, texture_ref); @@ -60,7 +66,21 @@ namespace amalgine { Texture2D::~Texture2D() { - texture_id_allocator->free_texture_id(texture_id); - glDeleteTextures(1, &texture_ref); + if(texture_ref != -1) { + texture_id_allocator->free_texture_id(texture_id); + glDeleteTextures(1, &texture_ref); + } + } + + Texture2D::Texture2D(Texture2D &&other) { + this->operator=(std::move(other)); + } + + Texture2D& Texture2D::operator=(Texture2D &&other) { + texture_id = other.texture_id; + texture_ref = other.texture_ref; + other.texture_id = -1; + other.texture_ref = -1; + return *this; } } |