Browse Source

Text: make GlyphCache movable.

And thus the DistanceFieldGlyphCache subclass as well. The
deinlined destructor wasn't really needed as the GL::Texture has its
destructor deinlined as well, so it wouldn't cause too much extra work
for the compiler to have it implicit.

Also, I suspect the destructor was just a leftover from when there was
no AbstractGlyphCache base.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
43efac8ed3
  1. 2
      src/Magnum/Text/GlyphCache.cpp
  2. 2
      src/Magnum/Text/GlyphCache.h
  3. 31
      src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp
  4. 37
      src/Magnum/Text/Test/GlyphCacheGLTest.cpp

2
src/Magnum/Text/GlyphCache.cpp

@ -63,8 +63,6 @@ GlyphCache::GlyphCache(const Vector2i& originalSize, const Vector2i& size, const
#endif
}
GlyphCache::~GlyphCache() = default;
GlyphCacheFeatures GlyphCache::doFeatures() const { return {}; }
void GlyphCache::doSetImage(const Vector2i& offset, const ImageView2D& image) {

2
src/Magnum/Text/GlyphCache.h

@ -109,8 +109,6 @@ class MAGNUM_TEXT_EXPORT GlyphCache: public AbstractGlyphCache {
*/
explicit GlyphCache(const Vector2i& size, const Vector2i& padding = {});
~GlyphCache();
/** @brief Cache texture */
GL::Texture2D& texture() { return _texture; }

31
src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp

@ -54,7 +54,10 @@ namespace Magnum { namespace Text { namespace Test { namespace {
struct DistanceFieldGlyphCacheGLTest: GL::OpenGLTester {
explicit DistanceFieldGlyphCacheGLTest();
void initialize();
void construct();
void constructCopy();
void constructMove();
void setImage();
@ -78,7 +81,10 @@ const struct {
};
DistanceFieldGlyphCacheGLTest::DistanceFieldGlyphCacheGLTest() {
addTests({&DistanceFieldGlyphCacheGLTest::initialize});
addTests({&DistanceFieldGlyphCacheGLTest::construct,
&DistanceFieldGlyphCacheGLTest::constructCopy,
&DistanceFieldGlyphCacheGLTest::constructMove});
addInstancedTests({&DistanceFieldGlyphCacheGLTest::setImage},
Containers::arraySize(SetImageData));
@ -96,7 +102,7 @@ DistanceFieldGlyphCacheGLTest::DistanceFieldGlyphCacheGLTest() {
#endif
}
void DistanceFieldGlyphCacheGLTest::initialize() {
void DistanceFieldGlyphCacheGLTest::construct() {
DistanceFieldGlyphCache cache{{1024, 2048}, {128, 256}, 16};
MAGNUM_VERIFY_NO_GL_ERROR();
@ -107,6 +113,25 @@ void DistanceFieldGlyphCacheGLTest::initialize() {
#endif
}
void DistanceFieldGlyphCacheGLTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<DistanceFieldGlyphCache>{});
CORRADE_VERIFY(!std::is_copy_assignable<DistanceFieldGlyphCache>{});
}
void DistanceFieldGlyphCacheGLTest::constructMove() {
DistanceFieldGlyphCache a{{1024, 512}, {128, 64}, 3};
DistanceFieldGlyphCache b = Utility::move(a);
CORRADE_COMPARE(b.size(), (Vector3i{1024, 512, 1}));
DistanceFieldGlyphCache c{{2, 3}, {1, 1}, 1};
c = Utility::move(b);
CORRADE_COMPARE(c.size(), (Vector3i{1024, 512, 1}));
CORRADE_VERIFY(std::is_nothrow_move_constructible<DistanceFieldGlyphCache>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<DistanceFieldGlyphCache>::value);
}
void DistanceFieldGlyphCacheGLTest::setImage() {
auto&& data = SetImageData[testCaseInstanceId()];
setTestCaseDescription(data.name);

37
src/Magnum/Text/Test/GlyphCacheGLTest.cpp

@ -45,22 +45,28 @@ namespace Magnum { namespace Text { namespace Test { namespace {
struct GlyphCacheGLTest: GL::OpenGLTester {
explicit GlyphCacheGLTest();
void initialize();
void initializeCustomFormat();
void construct();
void constructCustomFormat();
void constructCopy();
void constructMove();
void setImage();
void setImageCustomFormat();
};
GlyphCacheGLTest::GlyphCacheGLTest() {
addTests({&GlyphCacheGLTest::initialize,
&GlyphCacheGLTest::initializeCustomFormat,
addTests({&GlyphCacheGLTest::construct,
&GlyphCacheGLTest::constructCustomFormat,
&GlyphCacheGLTest::constructCopy,
&GlyphCacheGLTest::constructMove,
&GlyphCacheGLTest::setImage,
&GlyphCacheGLTest::setImageCustomFormat});
}
void GlyphCacheGLTest::initialize() {
void GlyphCacheGLTest::construct() {
GlyphCache cache{{1024, 2048}};
MAGNUM_VERIFY_NO_GL_ERROR();
@ -70,7 +76,7 @@ void GlyphCacheGLTest::initialize() {
#endif
}
void GlyphCacheGLTest::initializeCustomFormat() {
void GlyphCacheGLTest::constructCustomFormat() {
GlyphCache cache{
#ifndef MAGNUM_TARGET_GLES2
GL::TextureFormat::RGBA8,
@ -86,6 +92,25 @@ void GlyphCacheGLTest::initializeCustomFormat() {
#endif
}
void GlyphCacheGLTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<GlyphCache>{});
CORRADE_VERIFY(!std::is_copy_assignable<GlyphCache>{});
}
void GlyphCacheGLTest::constructMove() {
GlyphCache a{{1024, 512}};
GlyphCache b = Utility::move(a);
CORRADE_COMPARE(b.size(), (Vector3i{1024, 512, 1}));
GlyphCache c{{2, 3}};
c = Utility::move(b);
CORRADE_COMPARE(c.size(), (Vector3i{1024, 512, 1}));
CORRADE_VERIFY(std::is_nothrow_move_constructible<GlyphCache>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<GlyphCache>::value);
}
const UnsignedByte InputData[]{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,

Loading…
Cancel
Save