Browse Source

Move constructor and move assignment for textures.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
ebf0107ab9
  1. 25
      src/AbstractTexture.cpp
  2. 15
      src/AbstractTexture.h

25
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;

15
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;
};

Loading…
Cancel
Save