From 96d56c6d2f21d811df2702e33bedfacf1eaf4ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 11 Oct 2023 23:46:50 +0200 Subject: [PATCH] Text: the Renderer can take just AbstractGlyphCache, not GlyphCache. It doesn't need to access anything else than what the base API provides, doesn't render with it, and doesn't expose the instance via any getter either. Even though the Renderer is scheduled for a total rework and changing the old API may feel like throwaway work, this change alone doesn't break anything and allows me to test certain new corner cases. --- src/Magnum/Text/Renderer.cpp | 14 +++++++------- src/Magnum/Text/Renderer.h | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Magnum/Text/Renderer.cpp b/src/Magnum/Text/Renderer.cpp index f36cfc8a7..933016b69 100644 --- a/src/Magnum/Text/Renderer.cpp +++ b/src/Magnum/Text/Renderer.cpp @@ -36,7 +36,7 @@ #include "Magnum/Math/Functions.h" #include "Magnum/Shaders/GenericGL.h" #include "Magnum/Text/AbstractFont.h" -#include "Magnum/Text/GlyphCache.h" +#include "Magnum/Text/AbstractGlyphCache.h" namespace Magnum { namespace Text { @@ -66,7 +66,7 @@ struct Vertex { Vector2 position, textureCoordinates; }; -std::tuple, Range2D> renderVerticesInternal(AbstractFont& font, const GlyphCache& cache, const Float size, const std::string& text, const Alignment alignment) { +std::tuple, Range2D> renderVerticesInternal(AbstractFont& font, const AbstractGlyphCache& cache, const Float size, const std::string& text, const Alignment alignment) { /* Output data, reserve memory as when the text would be ASCII-only. In reality the actual vertex count will be smaller, but allocating more at once is better than reallocating many times later. */ @@ -201,7 +201,7 @@ std::pair, MeshIndexType> renderIndicesInternal(const Un return {Utility::move(indices), indexType}; } -std::tuple renderInternal(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment) { +std::tuple renderInternal(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment) { /* Render vertices and upload them */ std::vector vertices; Range2D rectangle; @@ -229,7 +229,7 @@ std::tuple renderInternal(AbstractFont& font, const GlyphCach } -std::tuple, std::vector, std::vector, Range2D> AbstractRenderer::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, Alignment alignment) { +std::tuple, std::vector, std::vector, Range2D> AbstractRenderer::render(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, Alignment alignment) { /* Render vertices */ std::vector vertices; Range2D rectangle; @@ -252,7 +252,7 @@ std::tuple, std::vector, std::vector, return std::make_tuple(Utility::move(positions), Utility::move(textureCoordinates), Utility::move(indices), rectangle); } -template std::tuple Renderer::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment) { +template std::tuple Renderer::render(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment) { /* Finalize mesh configuration and return the result */ auto r = renderInternal(font, cache, size, text, vertexBuffer, indexBuffer, usage, alignment); GL::Mesh& mesh = std::get<0>(r); @@ -299,7 +299,7 @@ void AbstractRenderer::bufferUnmapImplementationDefault(GL::Buffer& buffer) #endif } -AbstractRenderer::AbstractRenderer(AbstractFont& font, const GlyphCache& cache, const Float size, const Alignment alignment): _vertexBuffer{GL::Buffer::TargetHint::Array}, _indexBuffer{GL::Buffer::TargetHint::ElementArray}, font(font), cache(cache), _fontSize{size}, _alignment(alignment), _capacity(0) { +AbstractRenderer::AbstractRenderer(AbstractFont& font, const AbstractGlyphCache& cache, const Float size, const Alignment alignment): _vertexBuffer{GL::Buffer::TargetHint::Array}, _indexBuffer{GL::Buffer::TargetHint::ElementArray}, font(font), cache(cache), _fontSize{size}, _alignment(alignment), _capacity(0) { #ifndef MAGNUM_TARGET_GLES MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::map_buffer_range); #elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN) @@ -319,7 +319,7 @@ AbstractRenderer::AbstractRenderer(AbstractFont& font, const GlyphCache& cache, AbstractRenderer::~AbstractRenderer() = default; -template Renderer::Renderer(AbstractFont& font, const GlyphCache& cache, const Float size, const Alignment alignment): AbstractRenderer(font, cache, size, alignment) { +template Renderer::Renderer(AbstractFont& font, const AbstractGlyphCache& cache, const Float size, const Alignment alignment): AbstractRenderer(font, cache, size, alignment) { /* Finalize mesh configuration */ _mesh.addVertexBuffer(_vertexBuffer, 0, typename Shaders::GenericGL::Position( diff --git a/src/Magnum/Text/Renderer.h b/src/Magnum/Text/Renderer.h index 56beaa791..ee51726c6 100644 --- a/src/Magnum/Text/Renderer.h +++ b/src/Magnum/Text/Renderer.h @@ -70,7 +70,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer { * Returns tuple with vertex positions, texture coordinates, indices * and rectangle spanning the rendered text. */ - static std::tuple, std::vector, std::vector, Range2D> render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, Alignment alignment = Alignment::LineLeft); + static std::tuple, std::vector, std::vector, Range2D> render(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, Alignment alignment = Alignment::LineLeft); /** * @brief Capacity for rendered glyphs @@ -129,7 +129,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer { #else private: #endif - explicit MAGNUM_TEXT_LOCAL AbstractRenderer(AbstractFont& font, const GlyphCache& cache, Float size, Alignment alignment); + explicit MAGNUM_TEXT_LOCAL AbstractRenderer(AbstractFont& font, const AbstractGlyphCache& cache, Float size, Alignment alignment); ~AbstractRenderer(); @@ -141,7 +141,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer { private: AbstractFont& font; - const GlyphCache& cache; + const AbstractGlyphCache& cache; Float _fontSize; Alignment _alignment; UnsignedInt _capacity; @@ -190,8 +190,8 @@ mesh: @snippet MagnumText-gl.cpp Renderer-usage1 -See @ref render(AbstractFont&, const GlyphCache&, Float, const std::string&, Alignment) -and @ref render(AbstractFont&, const GlyphCache&, Float, const std::string&, GL::Buffer&, GL::Buffer&, GL::BufferUsage, Alignment) +See @ref render(AbstractFont&, const AbstractGlyphCache&, Float, const std::string&, Alignment) +and @ref render(AbstractFont&, const AbstractGlyphCache&, Float, const std::string&, GL::Buffer&, GL::Buffer&, GL::BufferUsage, Alignment) for more information. While this method is sufficient for one-shot rendering of static texts, for @@ -295,7 +295,7 @@ template class MAGNUM_TEXT_EXPORT Renderer: public Abstr * @ref Shaders::DistanceFieldVectorGL and rectangle spanning the * rendered text. */ - static std::tuple render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment = Alignment::LineLeft); + static std::tuple render(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment = Alignment::LineLeft); /** * @brief Constructor @@ -304,8 +304,8 @@ template class MAGNUM_TEXT_EXPORT Renderer: public Abstr * @param size Font size * @param alignment Text alignment */ - explicit Renderer(AbstractFont& font, const GlyphCache& cache, Float size, Alignment alignment = Alignment::LineLeft); - Renderer(AbstractFont&, GlyphCache&&, Float, Alignment alignment = Alignment::LineLeft) = delete; /**< @overload */ + explicit Renderer(AbstractFont& font, const AbstractGlyphCache& cache, Float size, Alignment alignment = Alignment::LineLeft); + Renderer(AbstractFont&, AbstractGlyphCache&&, Float, Alignment alignment = Alignment::LineLeft) = delete; /**< @overload */ #ifndef DOXYGEN_GENERATING_OUTPUT using AbstractRenderer::render;