diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 2fafde784..e7a97767e 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -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; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 210cf7d4f..e24048804 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -40,9 +40,9 @@ #include #include #include +#include #include - #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)