Add move semantics to sf::RenderTarget and sf::RenderTexture

This commit is contained in:
Chris Thrasher 2023-06-06 16:12:44 -06:00
parent d304d1e57b
commit 332d11be41
6 changed files with 60 additions and 14 deletions

View File

@ -57,7 +57,7 @@ public:
/// \brief Destructor
///
////////////////////////////////////////////////////////////
virtual ~RenderTarget();
virtual ~RenderTarget() = default;
////////////////////////////////////////////////////////////
/// \brief Deleted copy constructor
@ -71,6 +71,18 @@ public:
////////////////////////////////////////////////////////////
RenderTarget& operator=(const RenderTarget&) = delete;
////////////////////////////////////////////////////////////
/// \brief Move constructor
///
////////////////////////////////////////////////////////////
RenderTarget(RenderTarget&&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Move assignment
///
////////////////////////////////////////////////////////////
RenderTarget& operator=(RenderTarget&&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Clear the entire target with a single color
///
@ -396,7 +408,7 @@ protected:
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
RenderTarget();
RenderTarget() = default;
////////////////////////////////////////////////////////////
/// \brief Performs the common initialization step after creation
@ -496,7 +508,7 @@ private:
////////////////////////////////////////////////////////////
View m_defaultView; //!< Default view
View m_view; //!< Current view
StatesCache m_cache; //!< Render states cache
StatesCache m_cache{}; //!< Render states cache
std::uint64_t m_id{}; //!< Unique number that identifies the RenderTarget
};
@ -525,6 +537,12 @@ private:
/// OpenGL states are not messed up by calling the
/// pushGLStates/popGLStates functions.
///
/// While render targets are moveable, it is not valid to move them
/// between threads. This will cause your program to crash. The
/// problem boils down to OpenGL being limited with regard to how it
/// works in multithreaded environments. Please ensure you only move
/// render targets within the same thread.
///
/// \see sf::RenderWindow, sf::RenderTexture, sf::View
///
////////////////////////////////////////////////////////////

View File

@ -68,6 +68,30 @@ public:
////////////////////////////////////////////////////////////
~RenderTexture() override;
////////////////////////////////////////////////////////////
/// \brief Deleted copy constructor
///
////////////////////////////////////////////////////////////
RenderTexture(const RenderTexture&) = delete;
////////////////////////////////////////////////////////////
/// \brief Deleted copy assignment
///
////////////////////////////////////////////////////////////
RenderTexture& operator=(const RenderTexture&) = delete;
////////////////////////////////////////////////////////////
/// \brief Move constructor
///
////////////////////////////////////////////////////////////
RenderTexture(RenderTexture&&) noexcept;
////////////////////////////////////////////////////////////
/// \brief Move assignment operator
///
////////////////////////////////////////////////////////////
RenderTexture& operator=(RenderTexture&&) noexcept;
////////////////////////////////////////////////////////////
/// \brief Create the render-texture
///

View File

@ -153,14 +153,6 @@ std::uint32_t equationToGlConstant(sf::BlendMode::Equation blendEquation)
namespace sf
{
////////////////////////////////////////////////////////////
RenderTarget::RenderTarget() = default;
////////////////////////////////////////////////////////////
RenderTarget::~RenderTarget() = default;
////////////////////////////////////////////////////////////
void RenderTarget::clear(const Color& color)
{

View File

@ -45,6 +45,14 @@ RenderTexture::RenderTexture() = default;
RenderTexture::~RenderTexture() = default;
////////////////////////////////////////////////////////////
RenderTexture::RenderTexture(RenderTexture&&) noexcept = default;
////////////////////////////////////////////////////////////
RenderTexture& RenderTexture::operator=(RenderTexture&&) noexcept = default;
////////////////////////////////////////////////////////////
bool RenderTexture::create(const Vector2u& size, const ContextSettings& settings)
{

View File

@ -8,6 +8,10 @@
class RenderTarget : public sf::RenderTarget
{
public:
RenderTarget() = default;
private:
sf::Vector2u getSize() const override
{
return {640, 480};
@ -22,7 +26,7 @@ TEST_CASE("[Graphics] sf::RenderTarget")
STATIC_CHECK(!std::is_copy_constructible_v<sf::RenderTarget>);
STATIC_CHECK(!std::is_copy_assignable_v<sf::RenderTarget>);
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::RenderTarget>);
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::RenderTarget>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RenderTarget>);
}
SECTION("Construction")

View File

@ -11,8 +11,8 @@ TEST_CASE("[Graphics] sf::RenderTexture", runDisplayTests())
{
STATIC_CHECK(!std::is_copy_constructible_v<sf::RenderTexture>);
STATIC_CHECK(!std::is_copy_assignable_v<sf::RenderTexture>);
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::RenderTexture>);
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::RenderTexture>);
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RenderTexture>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RenderTexture>);
}
SECTION("Construction")