Browse Source

Text: allow calling GlyphCache::reserve() for cache with default glyph 0.

The default glyph 0 is not positioned anywhere, so it won't interfere
with atlas creation.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
364f29e0df
  1. 3
      src/Text/GlyphCache.cpp
  2. 11
      src/Text/Test/GlyphCacheGLTest.cpp

3
src/Text/GlyphCache.cpp

@ -69,7 +69,8 @@ void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i&
}
std::vector<Rectanglei> GlyphCache::reserve(const std::vector<Vector2i>& sizes) {
CORRADE_ASSERT(glyphs.empty(), "Text::GlyphCache::reserve(): reserving space in non-empty cache is not yet implemented", {});
CORRADE_ASSERT((glyphs.size() == 1 && glyphs.at(0) == std::pair<Vector2i, Rectanglei>()),
"Text::GlyphCache::reserve(): reserving space in non-empty cache is not yet implemented", {});
glyphs.reserve(glyphs.size() + sizes.size());
return TextureTools::atlas(_size, sizes, _padding);
}

11
src/Text/Test/GlyphCacheGLTest.cpp

@ -33,11 +33,13 @@ class GlyphCacheGLTest: public Magnum::Test::AbstractOpenGLTester {
void initialize();
void access();
void reserve();
};
GlyphCacheGLTest::GlyphCacheGLTest() {
addTests({&GlyphCacheGLTest::initialize,
&GlyphCacheGLTest::access});
&GlyphCacheGLTest::access,
&GlyphCacheGLTest::reserve});
}
void GlyphCacheGLTest::initialize() {
@ -78,6 +80,13 @@ void GlyphCacheGLTest::access() {
CORRADE_COMPARE(rectangle, Rectanglei({10, 10}, {23, 45}));
}
void GlyphCacheGLTest::reserve() {
Text::GlyphCache cache(Vector2i(236));
/* Verify that this works for "empty" cache */
CORRADE_VERIFY(!cache.reserve({{5, 3}}).empty());
}
}}}
CORRADE_TEST_MAIN(Magnum::Text::Test::GlyphCacheGLTest)

Loading…
Cancel
Save