Browse Source

Text: test that calling Renderer2D::render() replaces the contents.

Apart from the fact that it blew up when the text was indeed empty,
which is fixed now (ugh), it was kinda obvious with the current
implementation but won't be when the guts get replaced with something
reasonable. So ensure we don't break existing use cases.
pull/674/head
Vladimír Vondruš 1 year ago
parent
commit
5385f12cfb
  1. 14
      src/Magnum/Text/Renderer.cpp
  2. 6
      src/Magnum/Text/Test/RendererGLTest.cpp

14
src/Magnum/Text/Renderer.cpp

@ -2044,12 +2044,14 @@ void AbstractRenderer::render(const std::string& text) {
CORRADE_ASSERT(glyphCount <= _capacity, CORRADE_ASSERT(glyphCount <= _capacity,
"Text::Renderer::render(): capacity" << _capacity << "too small to render" << glyphCount << "glyphs", ); "Text::Renderer::render(): capacity" << _capacity << "too small to render" << glyphCount << "glyphs", );
/* Interleave the data into mapped buffer*/ /* Interleave the data into mapped buffer, if there are any glyphs */
Containers::ArrayView<Vertex> vertices(static_cast<Vertex*>(bufferMapImplementation(_vertexBuffer, if(vertexCount) {
vertexCount*sizeof(Vertex))), vertexCount); Containers::ArrayView<Vertex> vertices(static_cast<Vertex*>(bufferMapImplementation(_vertexBuffer,
CORRADE_INTERNAL_ASSERT_OUTPUT(vertices); vertexCount*sizeof(Vertex))), vertexCount);
std::copy(vertexData.begin(), vertexData.end(), vertices.begin()); CORRADE_INTERNAL_ASSERT_OUTPUT(vertices);
bufferUnmapImplementation(_vertexBuffer); std::copy(vertexData.begin(), vertexData.end(), vertices.begin());
bufferUnmapImplementation(_vertexBuffer);
}
/* Update index count */ /* Update index count */
_mesh.setCount(indexCount); _mesh.setCount(indexCount);

6
src/Magnum/Text/Test/RendererGLTest.cpp

@ -1147,6 +1147,12 @@ void RendererGLTest::mutableText() {
Vector2{ 9.0f, 9.0f} + offset, {1.0f, 1.0f}, Vector2{ 9.0f, 9.0f} + offset, {1.0f, 1.0f},
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
#endif #endif
/* Rendering again replaces previous contents. I.e., if rendering an empty
string, it makes the output empty. */
renderer.render("");
CORRADE_COMPARE(renderer.rectangle(), (Range2D{{0.0f, -1.75f}, {0.0f, 1.75f}}));
CORRADE_COMPARE(renderer.mesh().count(), 0);
} }
void RendererGLTest::arrayGlyphCache() { void RendererGLTest::arrayGlyphCache() {

Loading…
Cancel
Save