Added move constructor, and move assignment operator.
This commit is contained in:
parent
2d2f684786
commit
a8bc8cf889
@ -69,6 +69,12 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Texture();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
@ -78,10 +84,22 @@ public:
|
||||
Texture(const Texture& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
/// \brief Copy assignment operator
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Texture();
|
||||
Texture& operator=(const Texture&);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture(Texture&&) noexcept;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move assignment operator
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture& operator=(Texture&&) noexcept;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the texture
|
||||
@ -502,16 +520,6 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] bool generateMipmap();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture& operator=(const Texture& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Swap the contents of this texture with those of another
|
||||
///
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace
|
||||
@ -99,6 +100,49 @@ Texture::~Texture()
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture::Texture(Texture&& right) noexcept :
|
||||
m_size(std::exchange(right.m_size, {})),
|
||||
m_actualSize(std::exchange(right.m_actualSize, {})),
|
||||
m_texture(std::exchange(right.m_texture, 0)),
|
||||
m_isSmooth(std::exchange(right.m_isSmooth, false)),
|
||||
m_sRgb(std::exchange(right.m_sRgb, false)),
|
||||
m_isRepeated(std::exchange(right.m_isRepeated, false)),
|
||||
m_fboAttachment(std::exchange(right.m_fboAttachment, false)),
|
||||
m_cacheId(std::exchange(right.m_cacheId, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture& Texture::operator=(Texture&& right) noexcept
|
||||
{
|
||||
// Catch self-moving.
|
||||
if (&right == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Destroy the OpenGL texture
|
||||
if (m_texture)
|
||||
{
|
||||
TransientContextLock lock;
|
||||
|
||||
GLuint texture = m_texture;
|
||||
glCheck(glDeleteTextures(1, &texture));
|
||||
}
|
||||
|
||||
// Move old to new.
|
||||
m_size = std::exchange(right.m_size, {});
|
||||
m_actualSize = std::exchange(right.m_actualSize, {});
|
||||
m_texture = std::exchange(right.m_texture, 0);
|
||||
m_isSmooth = std::exchange(right.m_isSmooth, false);
|
||||
m_sRgb = std::exchange(right.m_sRgb, false);
|
||||
m_isRepeated = std::exchange(right.m_isRepeated, false);
|
||||
m_fboAttachment = std::exchange(right.m_fboAttachment, false);
|
||||
m_cacheId = std::exchange(right.m_cacheId, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Texture::create(const Vector2u& size)
|
||||
|
@ -7,10 +7,8 @@
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Texture>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Texture>);
|
||||
static_assert(std::is_move_constructible_v<sf::Texture>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::Texture>);
|
||||
static_assert(std::is_move_assignable_v<sf::Texture>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::Texture>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Texture>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Texture>);
|
||||
static_assert(std::is_nothrow_swappable_v<sf::Texture>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
|
Loading…
Reference in New Issue
Block a user