From 487c97afaf7c4014c11688cac1e1a96525b88900 Mon Sep 17 00:00:00 2001 From: Jim-Marsden Date: Sun, 20 Nov 2022 11:30:46 -0800 Subject: [PATCH] Added non-trivial move operations. Removed the default move constructor and operator. --- include/SFML/Graphics/Shader.hpp | 8 ++++---- src/SFML/Graphics/Shader.cpp | 34 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 2fafde78..e7a97767 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 210cf7d4..e2404880 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)