From 364f29e0dfdeed6a3a37a23fec1df89d3ee0d624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2013 02:46:01 +0200 Subject: [PATCH] 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. --- src/Text/GlyphCache.cpp | 3 ++- src/Text/Test/GlyphCacheGLTest.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Text/GlyphCache.cpp b/src/Text/GlyphCache.cpp index 6fbfc5313..a11338b0a 100644 --- a/src/Text/GlyphCache.cpp +++ b/src/Text/GlyphCache.cpp @@ -69,7 +69,8 @@ void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i& } std::vector GlyphCache::reserve(const std::vector& 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()), + "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); } diff --git a/src/Text/Test/GlyphCacheGLTest.cpp b/src/Text/Test/GlyphCacheGLTest.cpp index a46e8f583..7578f57b5 100644 --- a/src/Text/Test/GlyphCacheGLTest.cpp +++ b/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)