diff --git a/src/Magnum/Text/Renderer.cpp b/src/Magnum/Text/Renderer.cpp index 3840b4098..fe368389b 100644 --- a/src/Magnum/Text/Renderer.cpp +++ b/src/Magnum/Text/Renderer.cpp @@ -1974,6 +1974,14 @@ AbstractRenderer::AbstractRenderer(AbstractFont& font, const AbstractGlyphCache& } #endif + /* These two are done in renderVerticesInternal() as well, but it makes + sense to verify the same here already, not only once .render() is + called */ + CORRADE_ASSERT(cache.size().z() == 1, + "Text::AbstractRenderer: array glyph caches are not supported", ); + CORRADE_ASSERT(cache.findFont(font), + "Text::AbstractRenderer: font not found among" << cache.fontCount() << "fonts in passed glyph cache", ); + /* Vertex buffer configuration depends on dimension count, done in subclass */ _mesh.setPrimitive(MeshPrimitive::Triangles); } diff --git a/src/Magnum/Text/Renderer.h b/src/Magnum/Text/Renderer.h index d694e61a2..37b7ed12c 100644 --- a/src/Magnum/Text/Renderer.h +++ b/src/Magnum/Text/Renderer.h @@ -1664,6 +1664,9 @@ template class MAGNUM_TEXT_EXPORT BasicRenderer: public * @param cache Glyph cache * @param size Font size * @param alignment Text alignment + * + * Expects that @p font is present in @p cache and that @p cache isn't + * an array. */ explicit BasicRenderer(AbstractFont& font, const AbstractGlyphCache& cache, Float size, Alignment alignment = Alignment::LineLeft); BasicRenderer(AbstractFont&, AbstractGlyphCache&&, Float, Alignment alignment = Alignment::LineLeft) = delete; /**< @overload */ diff --git a/src/Magnum/Text/Test/RendererGLTest.cpp b/src/Magnum/Text/Test/RendererGLTest.cpp index 27cf0c7a5..77932e444 100644 --- a/src/Magnum/Text/Test/RendererGLTest.cpp +++ b/src/Magnum/Text/Test/RendererGLTest.cpp @@ -81,6 +81,9 @@ struct RendererGLTest: GL::OpenGLTester { void renderMeshIndexType(); void mutableText(); + void arrayGlyphCache(); + void fontNotFoundInCache(); + private: PluginManager::Manager _manager{"nonexistent"}; @@ -219,7 +222,10 @@ RendererGLTest::RendererGLTest() { addTests({&RendererGLTest::renderMesh, &RendererGLTest::renderMeshIndexType, - &RendererGLTest::mutableText}); + &RendererGLTest::mutableText, + + &RendererGLTest::arrayGlyphCache, + &RendererGLTest::fontNotFoundInCache}); /* Load the plugins directly from the build tree. Otherwise they're either static and already loaded or not present in the build tree */ @@ -1069,6 +1075,53 @@ void RendererGLTest::mutableText() { #endif } +void RendererGLTest::arrayGlyphCache() { + CORRADE_SKIP_IF_NO_ASSERT(); + + TestFont font; + font.openFile({}, 0.5f); + struct: AbstractGlyphCache { + using AbstractGlyphCache::AbstractGlyphCache; + + GlyphCacheFeatures doFeatures() const override { return {}; } + } cache{PixelFormat::R8Unorm, {100, 100, 3}}; + + GL::Buffer buffer; + + Containers::String out; + Error redirectError{&out}; + Renderer2D::render(font, cache, 1.0f, "", buffer, buffer, GL::BufferUsage::StaticDraw); + Renderer2D{font, cache, 1.0f}; + CORRADE_COMPARE(out, + "Text::Renderer: array glyph caches are not supported\n" + "Text::AbstractRenderer: array glyph caches are not supported\n"); +} + +void RendererGLTest::fontNotFoundInCache() { + CORRADE_SKIP_IF_NO_ASSERT(); + + TestFont font; + font.openFile({}, 0.5f); + + struct: AbstractGlyphCache { + using AbstractGlyphCache::AbstractGlyphCache; + + GlyphCacheFeatures doFeatures() const override { return {}; } + } cache{PixelFormat::R8Unorm, {100, 100}}; + cache.addFont(34); + cache.addFont(25); + + GL::Buffer buffer; + + Containers::String out; + Error redirectError{&out}; + Renderer2D::render(font, cache, 1.0f, "", buffer, buffer, GL::BufferUsage::StaticDraw); + Renderer2D{font, cache, 1.0f}; + CORRADE_COMPARE(out, + "Text::Renderer: font not found among 2 fonts in passed glyph cache\n" + "Text::AbstractRenderer: font not found among 2 fonts in passed glyph cache\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Text::Test::RendererGLTest)