From ebf0107ab9e52f9f5e0940ffd0778f392b3ddaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 15:34:31 +0100 Subject: [PATCH] Move constructor and move assignment for textures. --- src/AbstractTexture.cpp | 25 ++++++++++++++++++++++++- src/AbstractTexture.h | 15 ++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 1e14bf5d6..cd8cd661c 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -83,7 +83,10 @@ GLfloat AbstractTexture::maxSupportedAnisotropy() { return value; } -AbstractTexture::~AbstractTexture() { +void AbstractTexture::destroy() { + /* Moved out */ + if(!_id) return; + /* Remove all bindings */ for(GLuint& binding: Context::current()->state()->texture->bindings) if(binding == _id) binding = 0; @@ -91,6 +94,26 @@ AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &_id); } +void AbstractTexture::move() { + _id = 0; +} + +AbstractTexture::~AbstractTexture() { destroy(); } + +AbstractTexture::AbstractTexture(AbstractTexture&& other): _target(other._target), _id(other._id) { + other.move(); +} + +AbstractTexture& AbstractTexture::operator=(AbstractTexture&& other) { + destroy(); + + _target = other._target; + _id = other._id; + + other.move(); + return *this; +} + void AbstractTexture::bind(GLint layer) { Implementation::TextureState* const textureState = Context::current()->state()->texture; diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 31d8f916c..5dd689f48 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -55,14 +55,14 @@ can optimize the data to match your settings. @todo Add glPixelStore encapsulation @todo Texture copying +@todo Move constructor/assignment - how to avoid creation of empty texture and + then deleting it immediately? */ class MAGNUM_EXPORT AbstractTexture { friend class Context; AbstractTexture(const AbstractTexture& other) = delete; - AbstractTexture(AbstractTexture&& other) = delete; AbstractTexture& operator=(const AbstractTexture& other) = delete; - AbstractTexture& operator=(AbstractTexture&& other) = delete; public: /** @@ -986,6 +986,12 @@ class MAGNUM_EXPORT AbstractTexture { */ virtual ~AbstractTexture() = 0; + /** @brief Move constructor */ + AbstractTexture(AbstractTexture&& other); + + /** @brief Move assignment */ + AbstractTexture& operator=(AbstractTexture&& other); + /** @brief OpenGL texture ID */ inline GLuint id() const { return _id; } @@ -1109,7 +1115,7 @@ class MAGNUM_EXPORT AbstractTexture { /* Unlike bind() this also sets the binding layer as active */ void MAGNUM_LOCAL bindInternal(); - const GLenum _target; + GLenum _target; #endif private: @@ -1184,6 +1190,9 @@ class MAGNUM_EXPORT AbstractTexture { void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage3DImplementation subImage3DImplementation; + void MAGNUM_LOCAL destroy(); + void MAGNUM_LOCAL move(); + GLuint _id; };