Added non-trivial move operations.

Removed the default move constructor and operator.
This commit is contained in:
Jim-Marsden 2022-11-20 11:30:46 -08:00 committed by Chris Thrasher
parent c0acaef204
commit 487c97afaf
2 changed files with 37 additions and 5 deletions

View File

@ -113,16 +113,16 @@ public:
Shader& operator=(const Shader&) = delete;
////////////////////////////////////////////////////////////
/// \brief Defaulted move constructor
/// \brief Move constructor
///
////////////////////////////////////////////////////////////
Shader(Shader&&) noexcept = default;
Shader(Shader&& source) noexcept;
////////////////////////////////////////////////////////////
/// \brief Defaulted move assignment
/// \brief Move assignment
///
////////////////////////////////////////////////////////////
Shader& operator=(Shader&&) noexcept = default;
Shader& operator=(Shader&& right) noexcept;
////////////////////////////////////////////////////////////

View File

@ -40,9 +40,9 @@
#include <iomanip>
#include <mutex>
#include <ostream>
#include <utility>
#include <vector>
#ifndef SFML_OPENGL_ES
#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS)
@ -250,6 +250,38 @@ Shader::~Shader()
glCheck(GLEXT_glDeleteObject(castToGlHandle(m_shaderProgram)));
}
////////////////////////////////////////////////////////////
Shader::Shader(Shader&& source) noexcept :
m_shaderProgram(std::exchange(source.m_shaderProgram, 0U)),
m_currentTexture(std::exchange(source.m_currentTexture, -1)),
m_textures(std::move(source.m_textures)),
m_uniforms(std::move(source.m_uniforms))
{
}
////////////////////////////////////////////////////////////
Shader& Shader::operator=(Shader&& right) noexcept
{
// Make sure we aren't moving ourselves.
if (&right == this)
{
return *this;
}
// Explicit scope for RAII
{
// Destroy effect program
TransientContextLock lock;
if (m_shaderProgram)
glCheck(GLEXT_glDeleteObject(castToGlHandle(m_shaderProgram)));
}
// Move the contents of right.
m_shaderProgram = std::exchange(right.m_shaderProgram, 0U);
m_currentTexture = std::exchange(right.m_currentTexture, -1);
m_textures = std::move(right.m_textures);
m_uniforms = std::move(right.m_uniforms);
return *this;
}
////////////////////////////////////////////////////////////
bool Shader::loadFromFile(const std::filesystem::path& filename, Type type)