Browse Source

TextureTools: make the DistanceField class movable.

No reason not to, even though the move is destructive. Also unblocks
Text::DistanceFieldGlyphCache which wasn't movable due to this and one
other problem.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
f091b80fae
  1. 4
      src/Magnum/TextureTools/DistanceField.cpp
  2. 18
      src/Magnum/TextureTools/DistanceField.h
  3. 44
      src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp

4
src/Magnum/TextureTools/DistanceField.cpp

@ -186,8 +186,12 @@ DistanceField::DistanceField(const UnsignedInt radius): _state{new State{radius}
} }
} }
DistanceField::DistanceField(DistanceField&&) noexcept = default;
DistanceField::~DistanceField() = default; DistanceField::~DistanceField() = default;
DistanceField& DistanceField::operator=(DistanceField&&) noexcept = default;
UnsignedInt DistanceField::radius() const { return _state->radius; } UnsignedInt DistanceField::radius() const { return _state->radius; }
void DistanceField::operator()(GL::Texture2D& input, GL::Framebuffer& output, const Range2Di& rectangle, const Vector2i& void DistanceField::operator()(GL::Texture2D& input, GL::Framebuffer& output, const Range2Di& rectangle, const Vector2i&

18
src/Magnum/TextureTools/DistanceField.h

@ -104,8 +104,26 @@ class MAGNUM_TEXTURETOOLS_EXPORT DistanceField {
*/ */
explicit DistanceField(UnsignedInt radius); explicit DistanceField(UnsignedInt radius);
/** @brief Copying is not allowed */
DistanceField(const DistanceField&) = delete;
/**
* @brief Move constructor
* @m_since_latest
*
* Performs a destructive move, i.e. the original object isn't usable
* afterwards anymore.
*/
DistanceField(DistanceField&&) noexcept;
~DistanceField(); ~DistanceField();
/** @brief Copying is not allowed */
DistanceField& operator=(const DistanceField&) = delete;
/** @brief Move constructor */
DistanceField& operator=(DistanceField&&) noexcept;
/** @brief Max lookup radius */ /** @brief Max lookup radius */
UnsignedInt radius() const; UnsignedInt radius() const;

44
src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp

@ -63,9 +63,13 @@ namespace Magnum { namespace TextureTools { namespace Test { namespace {
struct DistanceFieldGLTest: GL::OpenGLTester { struct DistanceFieldGLTest: GL::OpenGLTester {
explicit DistanceFieldGLTest(); explicit DistanceFieldGLTest();
void construct();
void constructCopy();
void constructMove();
/* This tests the GL::Texture overload, which itself calls into the /* This tests the GL::Texture overload, which itself calls into the
GL::Framebuffer overload so both are covered */ GL::Framebuffer overload so both are covered */
void test(); void run();
#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_WEBGL
void benchmark(); void benchmark();
#endif #endif
@ -79,7 +83,7 @@ const struct {
const char* name; const char* name;
Vector2i size; Vector2i size;
Vector2i offset; Vector2i offset;
} TestData[]{ } RunData[]{
{"", {64, 64}, {}}, {"", {64, 64}, {}},
{"with offset", {128, 96}, {64, 32}}, {"with offset", {128, 96}, {64, 32}},
}; };
@ -89,8 +93,12 @@ using namespace Containers::Literals; /* for SwiftShader detection */
#endif #endif
DistanceFieldGLTest::DistanceFieldGLTest() { DistanceFieldGLTest::DistanceFieldGLTest() {
addInstancedTests({&DistanceFieldGLTest::test}, addTests({&DistanceFieldGLTest::construct,
Containers::arraySize(TestData)); &DistanceFieldGLTest::constructCopy,
&DistanceFieldGLTest::constructMove});
addInstancedTests({&DistanceFieldGLTest::run},
Containers::arraySize(RunData));
#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_WEBGL
addBenchmarks({&DistanceFieldGLTest::benchmark}, 5, BenchmarkType::GpuTime); addBenchmarks({&DistanceFieldGLTest::benchmark}, 5, BenchmarkType::GpuTime);
@ -120,8 +128,32 @@ DistanceFieldGLTest::DistanceFieldGLTest() {
} }
} }
void DistanceFieldGLTest::test() { void DistanceFieldGLTest::construct() {
auto&& data = TestData[testCaseInstanceId()]; DistanceField distanceField{32};
CORRADE_COMPARE(distanceField.radius(), 32);
}
void DistanceFieldGLTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<DistanceField>{});
CORRADE_VERIFY(!std::is_copy_assignable<DistanceField>{});
}
void DistanceFieldGLTest::constructMove() {
DistanceField a{16};
DistanceField b = Utility::move(a);
CORRADE_COMPARE(b.radius(), 16);
DistanceField c{8};
c = Utility::move(b);
CORRADE_COMPARE(c.radius(), 16);
CORRADE_VERIFY(std::is_nothrow_move_constructible<DistanceField>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<DistanceField>::value);
}
void DistanceFieldGLTest::run() {
auto&& data = RunData[testCaseInstanceId()];
setTestCaseDescription(data.name); setTestCaseDescription(data.name);
Containers::Pointer<Trade::AbstractImporter> importer; Containers::Pointer<Trade::AbstractImporter> importer;

Loading…
Cancel
Save