gl_resource_manager: Use std::exchange instead of std::swap in move assignment operators and constructors
Move assignment operators and move constructors should ideally leave the object moved from in a state where resources aren't accessable.
This commit is contained in:
parent
e9900d8035
commit
e3f9bfd850
|
@ -13,14 +13,16 @@
|
||||||
class OGLTexture : private NonCopyable {
|
class OGLTexture : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
OGLTexture() = default;
|
OGLTexture() = default;
|
||||||
OGLTexture(OGLTexture&& o) {
|
|
||||||
std::swap(handle, o.handle);
|
OGLTexture(OGLTexture&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
}
|
|
||||||
~OGLTexture() {
|
~OGLTexture() {
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
OGLTexture& operator=(OGLTexture&& o) {
|
OGLTexture& operator=(OGLTexture&& o) {
|
||||||
std::swap(handle, o.handle);
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,14 +48,16 @@ public:
|
||||||
class OGLSampler : private NonCopyable {
|
class OGLSampler : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
OGLSampler() = default;
|
OGLSampler() = default;
|
||||||
OGLSampler(OGLSampler&& o) {
|
|
||||||
std::swap(handle, o.handle);
|
OGLSampler(OGLSampler&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
}
|
|
||||||
~OGLSampler() {
|
~OGLSampler() {
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
OGLSampler& operator=(OGLSampler&& o) {
|
OGLSampler& operator=(OGLSampler&& o) {
|
||||||
std::swap(handle, o.handle);
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +83,16 @@ public:
|
||||||
class OGLShader : private NonCopyable {
|
class OGLShader : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
OGLShader() = default;
|
OGLShader() = default;
|
||||||
OGLShader(OGLShader&& o) {
|
|
||||||
std::swap(handle, o.handle);
|
OGLShader(OGLShader&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
}
|
|
||||||
~OGLShader() {
|
~OGLShader() {
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
OGLShader& operator=(OGLShader&& o) {
|
OGLShader& operator=(OGLShader&& o) {
|
||||||
std::swap(handle, o.handle);
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,14 +118,16 @@ public:
|
||||||
class OGLBuffer : private NonCopyable {
|
class OGLBuffer : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
OGLBuffer() = default;
|
OGLBuffer() = default;
|
||||||
OGLBuffer(OGLBuffer&& o) {
|
|
||||||
std::swap(handle, o.handle);
|
OGLBuffer(OGLBuffer&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
}
|
|
||||||
~OGLBuffer() {
|
~OGLBuffer() {
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
OGLBuffer& operator=(OGLBuffer&& o) {
|
OGLBuffer& operator=(OGLBuffer&& o) {
|
||||||
std::swap(handle, o.handle);
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +153,16 @@ public:
|
||||||
class OGLVertexArray : private NonCopyable {
|
class OGLVertexArray : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
OGLVertexArray() = default;
|
OGLVertexArray() = default;
|
||||||
OGLVertexArray(OGLVertexArray&& o) {
|
|
||||||
std::swap(handle, o.handle);
|
OGLVertexArray(OGLVertexArray&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
}
|
|
||||||
~OGLVertexArray() {
|
~OGLVertexArray() {
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
OGLVertexArray& operator=(OGLVertexArray&& o) {
|
OGLVertexArray& operator=(OGLVertexArray&& o) {
|
||||||
std::swap(handle, o.handle);
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,14 +188,16 @@ public:
|
||||||
class OGLFramebuffer : private NonCopyable {
|
class OGLFramebuffer : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
OGLFramebuffer() = default;
|
OGLFramebuffer() = default;
|
||||||
OGLFramebuffer(OGLFramebuffer&& o) {
|
|
||||||
std::swap(handle, o.handle);
|
OGLFramebuffer(OGLFramebuffer&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
}
|
|
||||||
~OGLFramebuffer() {
|
~OGLFramebuffer() {
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
OGLFramebuffer& operator=(OGLFramebuffer&& o) {
|
OGLFramebuffer& operator=(OGLFramebuffer&& o) {
|
||||||
std::swap(handle, o.handle);
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue