Browse Source

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.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
96d56c6d2f
  1. 14
      src/Magnum/Text/Renderer.cpp
  2. 16
      src/Magnum/Text/Renderer.h

14
src/Magnum/Text/Renderer.cpp

@ -36,7 +36,7 @@
#include "Magnum/Math/Functions.h" #include "Magnum/Math/Functions.h"
#include "Magnum/Shaders/GenericGL.h" #include "Magnum/Shaders/GenericGL.h"
#include "Magnum/Text/AbstractFont.h" #include "Magnum/Text/AbstractFont.h"
#include "Magnum/Text/GlyphCache.h" #include "Magnum/Text/AbstractGlyphCache.h"
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
@ -66,7 +66,7 @@ struct Vertex {
Vector2 position, textureCoordinates; Vector2 position, textureCoordinates;
}; };
std::tuple<std::vector<Vertex>, Range2D> renderVerticesInternal(AbstractFont& font, const GlyphCache& cache, const Float size, const std::string& text, const Alignment alignment) { std::tuple<std::vector<Vertex>, 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 /* 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 reality the actual vertex count will be smaller, but allocating more at
once is better than reallocating many times later. */ once is better than reallocating many times later. */
@ -201,7 +201,7 @@ std::pair<Containers::Array<char>, MeshIndexType> renderIndicesInternal(const Un
return {Utility::move(indices), indexType}; return {Utility::move(indices), indexType};
} }
std::tuple<GL::Mesh, Range2D> 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<GL::Mesh, Range2D> 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 */ /* Render vertices and upload them */
std::vector<Vertex> vertices; std::vector<Vertex> vertices;
Range2D rectangle; Range2D rectangle;
@ -229,7 +229,7 @@ std::tuple<GL::Mesh, Range2D> renderInternal(AbstractFont& font, const GlyphCach
} }
std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>, Range2D> AbstractRenderer::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, Alignment alignment) { std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>, Range2D> AbstractRenderer::render(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, Alignment alignment) {
/* Render vertices */ /* Render vertices */
std::vector<Vertex> vertices; std::vector<Vertex> vertices;
Range2D rectangle; Range2D rectangle;
@ -252,7 +252,7 @@ std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>,
return std::make_tuple(Utility::move(positions), Utility::move(textureCoordinates), Utility::move(indices), rectangle); return std::make_tuple(Utility::move(positions), Utility::move(textureCoordinates), Utility::move(indices), rectangle);
} }
template<UnsignedInt dimensions> std::tuple<GL::Mesh, Range2D> Renderer<dimensions>::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment) { template<UnsignedInt dimensions> std::tuple<GL::Mesh, Range2D> Renderer<dimensions>::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 */ /* Finalize mesh configuration and return the result */
auto r = renderInternal(font, cache, size, text, vertexBuffer, indexBuffer, usage, alignment); auto r = renderInternal(font, cache, size, text, vertexBuffer, indexBuffer, usage, alignment);
GL::Mesh& mesh = std::get<0>(r); GL::Mesh& mesh = std::get<0>(r);
@ -299,7 +299,7 @@ void AbstractRenderer::bufferUnmapImplementationDefault(GL::Buffer& buffer)
#endif #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 #ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::map_buffer_range); MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::map_buffer_range);
#elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN) #elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN)
@ -319,7 +319,7 @@ AbstractRenderer::AbstractRenderer(AbstractFont& font, const GlyphCache& cache,
AbstractRenderer::~AbstractRenderer() = default; AbstractRenderer::~AbstractRenderer() = default;
template<UnsignedInt dimensions> Renderer<dimensions>::Renderer(AbstractFont& font, const GlyphCache& cache, const Float size, const Alignment alignment): AbstractRenderer(font, cache, size, alignment) { template<UnsignedInt dimensions> Renderer<dimensions>::Renderer(AbstractFont& font, const AbstractGlyphCache& cache, const Float size, const Alignment alignment): AbstractRenderer(font, cache, size, alignment) {
/* Finalize mesh configuration */ /* Finalize mesh configuration */
_mesh.addVertexBuffer(_vertexBuffer, 0, _mesh.addVertexBuffer(_vertexBuffer, 0,
typename Shaders::GenericGL<dimensions>::Position( typename Shaders::GenericGL<dimensions>::Position(

16
src/Magnum/Text/Renderer.h

@ -70,7 +70,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
* Returns tuple with vertex positions, texture coordinates, indices * Returns tuple with vertex positions, texture coordinates, indices
* and rectangle spanning the rendered text. * and rectangle spanning the rendered text.
*/ */
static std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>, Range2D> render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, Alignment alignment = Alignment::LineLeft); static std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>, Range2D> render(AbstractFont& font, const AbstractGlyphCache& cache, Float size, const std::string& text, Alignment alignment = Alignment::LineLeft);
/** /**
* @brief Capacity for rendered glyphs * @brief Capacity for rendered glyphs
@ -129,7 +129,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
#else #else
private: private:
#endif #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(); ~AbstractRenderer();
@ -141,7 +141,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
private: private:
AbstractFont& font; AbstractFont& font;
const GlyphCache& cache; const AbstractGlyphCache& cache;
Float _fontSize; Float _fontSize;
Alignment _alignment; Alignment _alignment;
UnsignedInt _capacity; UnsignedInt _capacity;
@ -190,8 +190,8 @@ mesh:
@snippet MagnumText-gl.cpp Renderer-usage1 @snippet MagnumText-gl.cpp Renderer-usage1
See @ref render(AbstractFont&, const GlyphCache&, Float, const std::string&, Alignment) See @ref render(AbstractFont&, const AbstractGlyphCache&, Float, const std::string&, Alignment)
and @ref render(AbstractFont&, const GlyphCache&, Float, const std::string&, GL::Buffer&, GL::Buffer&, GL::BufferUsage, Alignment) and @ref render(AbstractFont&, const AbstractGlyphCache&, Float, const std::string&, GL::Buffer&, GL::Buffer&, GL::BufferUsage, Alignment)
for more information. for more information.
While this method is sufficient for one-shot rendering of static texts, for While this method is sufficient for one-shot rendering of static texts, for
@ -295,7 +295,7 @@ template<UnsignedInt dimensions> class MAGNUM_TEXT_EXPORT Renderer: public Abstr
* @ref Shaders::DistanceFieldVectorGL and rectangle spanning the * @ref Shaders::DistanceFieldVectorGL and rectangle spanning the
* rendered text. * rendered text.
*/ */
static std::tuple<GL::Mesh, Range2D> 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<GL::Mesh, Range2D> 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 * @brief Constructor
@ -304,8 +304,8 @@ template<UnsignedInt dimensions> class MAGNUM_TEXT_EXPORT Renderer: public Abstr
* @param size Font size * @param size Font size
* @param alignment Text alignment * @param alignment Text alignment
*/ */
explicit Renderer(AbstractFont& font, const GlyphCache& cache, Float size, Alignment alignment = Alignment::LineLeft); explicit Renderer(AbstractFont& font, const AbstractGlyphCache& cache, Float size, Alignment alignment = Alignment::LineLeft);
Renderer(AbstractFont&, GlyphCache&&, Float, Alignment alignment = Alignment::LineLeft) = delete; /**< @overload */ Renderer(AbstractFont&, AbstractGlyphCache&&, Float, Alignment alignment = Alignment::LineLeft) = delete; /**< @overload */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
using AbstractRenderer::render; using AbstractRenderer::render;

Loading…
Cancel
Save