Browse Source

Text: renamed {DistanceField,}GlyphCache to {DistanceField}GlyphCacheGL.

Like with TextureTools::DistanceField, to make room for non-GL
implementations. Old names are deprecated aliases, same for headers. The
only remaining bit in the Text library is the Renderer class, but for
that one I first need to invent a non-shitty API so I can just deprecate
the old thing as a whole and create something reasonable from scratch in
RendererGL.
pull/650/head
Vladimír Vondruš 2 years ago
parent
commit
42342cd3a5
  1. 2
      doc/changelog-old.dox
  2. 26
      doc/changelog.dox
  3. 20
      doc/snippets/Text-gl.cpp
  4. 13
      src/Magnum/Text/CMakeLists.txt
  5. 152
      src/Magnum/Text/DistanceFieldGlyphCache.h
  6. 22
      src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp
  7. 180
      src/Magnum/Text/DistanceFieldGlyphCacheGL.h
  8. 170
      src/Magnum/Text/GlyphCache.h
  9. 20
      src/Magnum/Text/GlyphCacheGL.cpp
  10. 198
      src/Magnum/Text/GlyphCacheGL.h
  11. 4
      src/Magnum/Text/Test/CMakeLists.txt
  12. 46
      src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp
  13. 18
      src/Magnum/Text/Test/DistanceFieldGlyphCacheGL_Test.cpp
  14. 40
      src/Magnum/Text/Test/GlyphCacheGLTest.cpp
  15. 18
      src/Magnum/Text/Test/GlyphCacheGL_Test.cpp
  16. 12
      src/Magnum/Text/Test/RendererGLTest.cpp
  17. 13
      src/Magnum/Text/Text.h
  18. 8
      src/Magnum/Text/fontconverter.cpp
  19. 4
      src/MagnumPlugins/MagnumFont/MagnumFont.cpp
  20. 10
      src/MagnumPlugins/MagnumFont/Test/MagnumFontGLTest.cpp

2
doc/changelog-old.dox

@ -149,7 +149,7 @@ Released 2018-05-01, tagged as
@subsubsection changelog-2018-04-changes-text Text library
- The @ref Text::GlyphCache now unconditionally uses
- The @cpp Text::GlyphCache @ce now unconditionally uses
@ref GL::TextureFormat::Luminance on ES2 and WebGL 1, instead of trying
@ref GL::TextureFormat::Red there first. That's done for consistency with
@ref GL::pixelFormat(), which unconditionally returns

26
doc/changelog.dox

@ -848,8 +848,8 @@ See also:
@ref Text::alignmentForDirection() utility that resolves those to concrete
`*Left` and `*Right` values based @ref Text::LayoutDirection and
@ref Text::ShapeDirection
- Added a @ref Text::GlyphCache::GlyphCache(NoCreateT) and
@ref Text::DistanceFieldGlyphCache::DistanceFieldGlyphCache(NoCreateT)
- Added a @ref Text::GlyphCacheGL::GlyphCacheGL(NoCreateT) and
@ref Text::DistanceFieldGlyphCacheGL::DistanceFieldGlyphCacheGL(NoCreateT)
constructor allowing to construct the object without a GL context present
- New @ref Text::AbstractFont::fillGlyphCache() overload taking a list of
glyph IDs instead of a UTF-8 string to allow filling the glyph cache with
@ -1410,11 +1410,11 @@ See also:
data to slices of @ref Text::AbstractGlyphCache::image() instead and
call @relativeref{Text::AbstractGlyphCache,flushImage()} instead. The
old API can only be called on 2D glyph caches now.
- @cpp Text::DistanceFieldGlyphCache::distanceFieldTextureSize() @ce and
@cpp setDistanceFieldImage() @ce is deprecated in favor of
- @cpp Text::DistanceFieldGlyphCacheGL::distanceFieldTextureSize() @ce
and @cpp setDistanceFieldImage() @ce is deprecated in favor of
@ref Text::AbstractGlyphCache::processedSize() and
@relativeref{Text::AbstractGlyphCache,setProcessedImage()}
- @ref Text::GlyphCache constructors taking either a
- @ref Text::GlyphCacheGL constructors taking either a
@ref GL::TextureFormat or no texture / pixel format at all are
deprecated in favor of constructors taking an explicit
@ref PixelFormat. The internal texture format is now considered an
@ -1423,7 +1423,9 @@ See also:
@ref TextureTools::AtlasLandfill, which has a vastly better packing
efficiency, supports incremental packing and doesn't force the caller to
use a @ref std::vector
- The @cpp TextureTools::DistanceField @ce class is deprecated in favor of
- The @cpp Text::GlyphCache @ce, @cpp Text::DistanceFieldGlyphCache @ce and
@cpp TextureTools::DistanceField @ce classes are deprecated in favor of
@ref Text::GlyphCacheGL, @ref Text::DistanceFieldGlyphCacheGL and
@ref TextureTools::DistanceFieldGL along with correspondingly renamed
headers, to make room for implementations with other backends such as
Vulkan
@ -2968,8 +2970,8 @@ Released 2019-10-24, tagged as
- A new @ref Text::AbstractGlyphCache base now makes @ref Text::AbstractFont
and @ref Text::AbstractFontConverter independent on the graphics API used,
meaning the @ref Text library now has just an optional dependency on
@ref GL. The @ref Text::Renderer, @ref Text::GlyphCache and
@ref Text::DistanceFieldGlyphCache classes are now built only if
@ref GL. The @ref Text::Renderer, @cpp Text::GlyphCache @ce and
@cpp Text::DistanceFieldGlyphCache @ce classes are now built only if
`TARGET_GL` is enabled (done by default).
- New @ref Text::AbstractFont::setFileCallback() to allow opening multi-file
fonts with an API similar to @ref Trade::AbstractImporter
@ -3622,8 +3624,8 @@ Released 2019-02-04, tagged as
information. See also [mosra/magnum#307](https://github.com/mosra/magnum/pull/307).
- The `Magnum::AndroidApplication` target was missing a few dependency
libraries when Magnum was used as a CMake subproject
- Fixed an ambiguous overload error in @ref Text::GlyphCache when compiling
this library under C++17 (see
- Fixed an ambiguous overload error in @cpp Text::GlyphCache @ce when
compiling this library under C++17 (see
[mosra/magnum#297](https://github.com/mosra/magnum/pull/297))
- Imroved initial Emscripten setup on Windows to be more frictionless (see
[mosra/toolchains#4](https://github.com/mosra/toolchains/pull/4))
@ -3643,8 +3645,8 @@ Released 2019-02-04, tagged as
`RESOURCE_MANAGER` (see [mosra/magnum#290](https://github.com/mosra/magnum/issues/290))
- Properly escaping log output on Emscripten @ref Platform::WindowlessEglApplication
- The @ref GL::Context::States enum set was missing value combining operators
- Fixed @ref Text::DistanceFieldGlyphCache internal formats on ES2 devices
that support @gl_extension{EXT,texture_storage} (see
- Fixed @cpp Text::DistanceFieldGlyphCache @ce internal formats on ES2
devices that support @gl_extension{EXT,texture_storage} (see
[mosra/magnum#289](https://github.com/mosra/magnum/pull/289))
- @ref PixelStorage::imageHeight() and Z value of @ref PixelStorage::skip()
was not properly handled on ES3 / WebGL 2 builds.

20
doc/snippets/Text-gl.cpp

@ -31,7 +31,7 @@
#include "Magnum/Math/Matrix3.h"
#include "Magnum/Shaders/VectorGL.h"
#include "Magnum/Text/AbstractFont.h"
#include "Magnum/Text/DistanceFieldGlyphCache.h"
#include "Magnum/Text/DistanceFieldGlyphCacheGL.h"
#include "Magnum/Text/Renderer.h"
#define DOXYGEN_ELLIPSIS(...) __VA_ARGS__
@ -58,7 +58,7 @@ Containers::Pointer<Text::AbstractFont> font =
if(!font->openFile("font.ttf", 12.0f))
Fatal{} << "Can't open font.ttf with StbTrueTypeFont";
Text::GlyphCache cache{PixelFormat::R8Unorm, Vector2i{128}};
Text::GlyphCacheGL cache{PixelFormat::R8Unorm, Vector2i{128}};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789?!:;,. ");
@ -67,7 +67,7 @@ font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
{
/* [AbstractGlyphCache-filling-construct] */
Text::GlyphCache cache{PixelFormat::R8Unorm, Vector2i{512}};
Text::GlyphCacheGL cache{PixelFormat::R8Unorm, Vector2i{512}};
/* [AbstractGlyphCache-filling-construct] */
}
@ -76,15 +76,15 @@ Text::GlyphCache cache{PixelFormat::R8Unorm, Vector2i{512}};
the font pointer. I don't care, I just want you to check compilation errors,
not more! */
PluginManager::Manager<Text::AbstractFont> manager;
/* [DistanceFieldGlyphCache-usage] */
/* [DistanceFieldGlyphCacheGL-usage] */
Containers::Pointer<Text::AbstractFont> font = DOXYGEN_ELLIPSIS(manager.loadAndInstantiate(""));
font->openFile("font.ttf", 96.0f);
Text::DistanceFieldGlyphCache cache{Vector2i{1024}, Vector2i{128}, 12};
Text::DistanceFieldGlyphCacheGL cache{Vector2i{1024}, Vector2i{128}, 12};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789?!:;,. ");
/* [DistanceFieldGlyphCache-usage] */
/* [DistanceFieldGlyphCacheGL-usage] */
}
{
@ -92,15 +92,15 @@ font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
the font pointer. I don't care, I just want you to check compilation errors,
not more! */
PluginManager::Manager<Text::AbstractFont> manager;
/* [GlyphCache-usage] */
/* [GlyphCacheGL-usage] */
Containers::Pointer<Text::AbstractFont> font = DOXYGEN_ELLIPSIS(manager.loadAndInstantiate(""));
font->openFile("font.ttf", 12.0f);
Text::GlyphCache cache{PixelFormat::R8Unorm, Vector2i{128}};
Text::GlyphCacheGL cache{PixelFormat::R8Unorm, Vector2i{128}};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789?!:;,. ");
/* [GlyphCache-usage] */
/* [GlyphCacheGL-usage] */
}
{
@ -116,7 +116,7 @@ Containers::Pointer<Text::AbstractFont> font = DOXYGEN_ELLIPSIS(manager.loadAndI
font->openFile("font.ttf", 12.0f);
/* Populate a glyph cache */
Text::GlyphCache cache{PixelFormat::R8Unorm, Vector2i{128}};
Text::GlyphCacheGL cache{PixelFormat::R8Unorm, Vector2i{128}};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789?!:;,. ");

13
src/Magnum/Text/CMakeLists.txt

@ -63,12 +63,17 @@ set(MagnumText_PRIVATE_HEADERS
if(MAGNUM_TARGET_GL)
list(APPEND MagnumText_SRCS
GlyphCache.cpp)
GlyphCacheGL.cpp)
list(APPEND MagnumText_GracefulAssert_SRCS
DistanceFieldGlyphCache.cpp)
DistanceFieldGlyphCacheGL.cpp)
list(APPEND MagnumText_HEADERS
DistanceFieldGlyphCache.h
GlyphCache.h)
DistanceFieldGlyphCacheGL.h
GlyphCacheGL.h)
if(MAGNUM_BUILD_DEPRECATED)
list(APPEND MagnumText_HEADERS
DistanceFieldGlyphCache.h
GlyphCache.h)
endif()
else()
# So MagnumTextObjects has at least something
list(APPEND MagnumText_SRCS ${PROJECT_SOURCE_DIR}/src/dummy.cpp)

152
src/Magnum/Text/DistanceFieldGlyphCache.h

@ -25,154 +25,34 @@
DEALINGS IN THE SOFTWARE.
*/
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file
* @brief Class @ref Magnum::Text::DistanceFieldGlyphCache
* @brief Typedef @ref Magnum::Text::DistanceFieldGlyphCache
* @m_deprecated_since_latest Use @ref Magnum/Text/DistanceFieldGlyphCacheGL.h
* and the @relativeref{Magnum::Text,DistanceFieldGlyphCacheGL} class
* instead.
*/
#endif
#include "Magnum/configure.h"
#ifdef MAGNUM_TARGET_GL
#include "Magnum/Text/GlyphCache.h"
#include "Magnum/TextureTools/DistanceFieldGL.h"
namespace Magnum { namespace Text {
/**
@brief Glyph cache with distance field rendering
Unlike the base @ref GlyphCache, this class converts each binary image to a
distance field. It's not possible to only use this cache for monochrome glyphs
as the internal texture format is single-channel.
@section Text-DistanceFieldGlyphCache-usage Usage
In order to create a distance field glyph cache, the font has to be loaded at a
size significantly larger than what the resulting text will be. The distance
field conversion process then converts the input to a fraction of its size
again, transferring the the extra spatial resolution to distance values. The
distance values are then used to render an arbitrarily sized text without it
being jaggy at small sizes and blurry when large.
The process requires three input parameters, size of the source image, size of
the resulting glyph cache image and a radius for the distance field creation.
The ratio between the input and output image size is usually four or eight
times, and the size of the font should match the larger size. So, for example,
if a @cpp {128, 128} @ce @ref GlyphCache was filled with a 12 pt font, a
@cpp {1024, 1024} @ce source image for the distance field should use a 96 pt
font. The radius should then be chosen so it's at least one or two pixels in
the scaled-down result, so in this case at least 8. Values less than that will
result in aliasing artifacts. Very high radius values are needed only if
outlining, thinning, thickening or shadow effects will be used when rendering,
using them leads to precision loss when the distance field is stored in 8-bit
channels.
@snippet Text-gl.cpp DistanceFieldGlyphCache-usage
See the @ref Renderer class for information about text rendering. The
@ref AbstractGlyphCache base class has more information about general glyph
cache usage.
@section Text-DistanceFieldGlyphCache-internal-format Internal texture format
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
The @ref format() is always @ref PixelFormat::R8Unorm.
#include "Magnum/Text/DistanceFieldGlyphCacheGL.h"
On desktop OpenGL, OpenGL ES 3.0+, WebGL 2, and OpenGL ES 2.0 if
@gl_extension{EXT,texture_rg} is supported, the @ref processedFormat() is
always @ref PixelFormat::R8Unorm, which maps to @ref GL::TextureFormat::R8 for
the @ref texture(), matching
@ref Text-GlyphCache-internal-format "the behavior listed in GlyphCache docs".
CORRADE_DEPRECATED_FILE("use Magnum/Text/DistanceFieldGlyphCacheGL.h and the DistanceFieldGlyphCacheGL class instead")
On OpenGL ES 2.0 without @gl_extension{EXT,texture_rg} and on WebGL 1,
@ref PixelFormat::R8Unorm maps to @ref GL::TextureFormat::Luminance, which
isn't renderable and thus cannot be used for calculating the distance field.
Instead, @ref PixelFormat::RGBA8Unorm is used for @ref processedFormat(). This
shouldn't affect common use through @ref image(), but code interacting with
@ref processedImage() or @ref setProcessedImage() may need to be aware of this.
@note This class is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features
for more information.
@see @ref TextureTools::DistanceFieldGL
*/
class MAGNUM_TEXT_EXPORT DistanceFieldGlyphCache: public GlyphCache {
public:
/**
* @brief Constructor
* @param size Size of the source image
* @param processedSize Resulting distance field texture size
* @param radius Distance field computation radius
*
* See @ref TextureTools::DistanceField for more information about the
* parameters. Size restrictions from it apply here as well, in
* particular the ratio of @p size and @p processedSize is expected to
* be a multiple of 2.
*
* Sets the @ref processedFormat() to @ref PixelFormat::R8Unorm, if
* available. On OpenGL ES 3.0+ and WebGL 2 uses always. On desktop
* OpenGL requires @gl_extension{ARB,texture_rg} (part of OpenGL 3.0),
* on ES2 uses @gl_extension{EXT,texture_rg} if available and uses
* @ref PixelFormat::RGB8Unorm as fallback if not, on WebGL 1 uses
* @ref PixelFormat::RGB8Unorm always.
*/
explicit DistanceFieldGlyphCache(const Vector2i& size, const Vector2i& processedSize, UnsignedInt radius);
/**
* @brief Construct without creating the internal state and the OpenGL texture object
* @m_since_latest
*
* The constructed instance is equivalent to moved-from state, i.e. no
* APIs can be safely called on the object. Useful in cases where you
* will overwrite the instance later anyway. Move another object over
* it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit DistanceFieldGlyphCache(NoCreateT) noexcept;
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Distance field texture size
*
* Compared to @ref textureSize(), which is the size of the source
* image, this function returns size of the resulting distance field
* texture.
* @m_deprecated_since_latest Use @ref processedSize() instead.
*/
CORRADE_DEPRECATED("use processedSize() instead") Vector2i distanceFieldTextureSize() const {
return processedSize().xy();
}
/**
* @brief Set a distance field cache image
*
* Compared to @ref setImage() uploads an already computed distance
* field image to given offset in the distance field texture. The
* @p offset and @ref ImageView::size() are expected to be in bounds
* for @ref distanceFieldTextureSize().
* @m_deprecated_since_latest Use @ref setProcessedImage() instead.
*/
CORRADE_DEPRECATED("use setProcessedImage() instead") void setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image);
#endif
private:
MAGNUM_TEXT_LOCAL GlyphCacheFeatures doFeatures() const override;
MAGNUM_TEXT_LOCAL void doSetImage(const Vector2i& offset, const ImageView2D& image) override;
MAGNUM_TEXT_LOCAL void doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) override;
#ifndef MAGNUM_TARGET_GLES
MAGNUM_TEXT_LOCAL Image3D doProcessedImage() override;
#endif
namespace Magnum { namespace Text {
TextureTools::DistanceFieldGL _distanceField;
};
/** @brief @copybrief DistanceFieldGlyphCacheGL
* @m_deprecated_since_latest Use @ref DistanceFieldGlyphCacheGL instead.
*/
typedef CORRADE_DEPRECATED("use DistanceFieldGlyphCacheGL instead") DistanceFieldGlyphCacheGL DistanceFieldGlyphCache;
}}
#else
#error this header is available only in the OpenGL build
#error use Magnum/Text/DistanceFieldGlyphCacheGL.h and the DistanceFieldGlyphCacheGL class instead
#endif
#endif

22
src/Magnum/Text/DistanceFieldGlyphCache.cpp → src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp

@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE.
*/
#include "DistanceFieldGlyphCache.h"
#include "DistanceFieldGlyphCacheGL.h"
#include "Magnum/Image.h"
#include "Magnum/ImageView.h"
@ -39,8 +39,8 @@
namespace Magnum { namespace Text {
DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& size, const Vector2i& processedSize, const UnsignedInt radius):
GlyphCache{PixelFormat::R8Unorm, size,
DistanceFieldGlyphCacheGL::DistanceFieldGlyphCacheGL(const Vector2i& size, const Vector2i& processedSize, const UnsignedInt radius):
GlyphCacheGL{PixelFormat::R8Unorm, size,
#if !defined(MAGNUM_TARGET_GLES) || !defined(MAGNUM_TARGET_GLES2)
PixelFormat::R8Unorm,
#else
@ -62,20 +62,20 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& size, const Vec
setImage() call */
CORRADE_ASSERT(size % processedSize == Vector2i{0} &&
(size/processedSize) % 2 == Vector2i{0},
"Text::DistanceFieldGlyphCache: expected source and processed size ratio to be a multiple of 2, got" << Debug::packed << size << "and" << Debug::packed << processedSize, );
"Text::DistanceFieldGlyphCacheGL: expected source and processed size ratio to be a multiple of 2, got" << Debug::packed << size << "and" << Debug::packed << processedSize, );
#if defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/* On ES2 print a warning to make it known that EXT_texture_rg wasn't
available. On WebGL 1 this is the case always, so a warning would be
just a noise. */
if(!GL::Context::current().isExtensionSupported<GL::Extensions::EXT::texture_rg>())
Warning() << "Text::DistanceFieldGlyphCache:" << GL::Extensions::EXT::texture_rg::string() << "not supported, using a full RGBA format for the distance field texture";
Warning() << "Text::DistanceFieldGlyphCacheGL:" << GL::Extensions::EXT::texture_rg::string() << "not supported, using a full RGBA format for the distance field texture";
#endif
}
DistanceFieldGlyphCache::DistanceFieldGlyphCache(NoCreateT) noexcept: GlyphCache{NoCreate}, _distanceField{NoCreate} {}
DistanceFieldGlyphCacheGL::DistanceFieldGlyphCacheGL(NoCreateT) noexcept: GlyphCacheGL{NoCreate}, _distanceField{NoCreate} {}
GlyphCacheFeatures DistanceFieldGlyphCache::doFeatures() const {
GlyphCacheFeatures DistanceFieldGlyphCacheGL::doFeatures() const {
return GlyphCacheFeature::ImageProcessing
#ifndef MAGNUM_TARGET_GLES
|GlyphCacheFeature::ProcessedImageDownload
@ -83,7 +83,7 @@ GlyphCacheFeatures DistanceFieldGlyphCache::doFeatures() const {
;
}
void DistanceFieldGlyphCache::doSetImage(const Vector2i& offset, const ImageView2D& image) {
void DistanceFieldGlyphCacheGL::doSetImage(const Vector2i& offset, const ImageView2D& image) {
GL::Texture2D input;
input.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMinificationFilter(GL::SamplerFilter::Linear)
@ -151,7 +151,7 @@ void DistanceFieldGlyphCache::doSetImage(const Vector2i& offset, const ImageView
}
#ifdef MAGNUM_BUILD_DEPRECATED
void DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image) {
void DistanceFieldGlyphCacheGL::setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image) {
/* The original function accepted GL pixel formats as well, try to
translate them back to the generic format. If that fails, pass the image
as-is let the base implementation deal with that instead.
@ -169,7 +169,7 @@ void DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, cons
}
#endif
void DistanceFieldGlyphCache::doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) {
void DistanceFieldGlyphCacheGL::doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) {
ImageView2D imageToUse = image;
/* On ES2, R8Unorm maps to Luminance, but here it's actually Red if
@ -189,7 +189,7 @@ void DistanceFieldGlyphCache::doSetProcessedImage(const Vector2i& offset, const
}
#ifndef MAGNUM_TARGET_GLES
Image3D DistanceFieldGlyphCache::doProcessedImage() {
Image3D DistanceFieldGlyphCacheGL::doProcessedImage() {
Image2D out = _texture.image(0, PixelFormat::R8Unorm);
return Image3D{out.format(), {out.size(), 1}, out.release()};
}

180
src/Magnum/Text/DistanceFieldGlyphCacheGL.h

@ -0,0 +1,180 @@
#ifndef Magnum_Text_DistanceFieldGlyphCacheGL_h
#define Magnum_Text_DistanceFieldGlyphCacheGL_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Class @ref Magnum::Text::DistanceFieldGlyphCacheGL
* @m_since_latest
*/
#include "Magnum/configure.h"
#ifdef MAGNUM_TARGET_GL
#include "Magnum/Text/GlyphCacheGL.h"
#include "Magnum/TextureTools/DistanceFieldGL.h"
namespace Magnum { namespace Text {
/**
@brief OpenGL glyph cache with distance field rendering
@m_since_latest
Unlike the base @ref GlyphCacheGL, this class converts each binary image to a
distance field. It's not possible to only use this cache for monochrome glyphs
as the internal texture format is single-channel.
@section Text-DistanceFieldGlyphCacheGL-usage Usage
In order to create a distance field glyph cache, the font has to be loaded at a
size significantly larger than what the resulting text will be. The distance
field conversion process then converts the input to a fraction of its size
again, transferring the the extra spatial resolution to distance values. The
distance values are then used to render an arbitrarily sized text without it
being jaggy at small sizes and blurry when large.
The process requires three input parameters, size of the source image, size of
the resulting glyph cache image and a radius for the distance field creation.
The ratio between the input and output image size is usually four or eight
times, and the size of the font should match the larger size. So, for example,
if a @cpp {128, 128} @ce @ref GlyphCacheGL was filled with a 12 pt font, a
@cpp {1024, 1024} @ce source image for the distance field should use a 96 pt
font. The radius should then be chosen so it's at least one or two pixels in
the scaled-down result, so in this case at least 8. Values less than that will
result in aliasing artifacts. Very high radius values are needed only if
outlining, thinning, thickening or shadow effects will be used when rendering,
using them leads to precision loss when the distance field is stored in 8-bit
channels.
@snippet Text-gl.cpp DistanceFieldGlyphCacheGL-usage
See the @ref Renderer class for information about text rendering. The
@ref AbstractGlyphCache base class has more information about general glyph
cache usage.
@section Text-DistanceFieldGlyphCacheGL-internal-format Internal texture format
The @ref format() is always @ref PixelFormat::R8Unorm.
On desktop OpenGL, OpenGL ES 3.0+, WebGL 2, and OpenGL ES 2.0 if
@gl_extension{EXT,texture_rg} is supported, the @ref processedFormat() is
always @ref PixelFormat::R8Unorm, which maps to @ref GL::TextureFormat::R8 for
the @ref texture(), matching
@ref Text-GlyphCacheGL-internal-format "the behavior listed in GlyphCacheGL docs".
On OpenGL ES 2.0 without @gl_extension{EXT,texture_rg} and on WebGL 1,
@ref PixelFormat::R8Unorm maps to @ref GL::TextureFormat::Luminance, which
isn't renderable and thus cannot be used for calculating the distance field.
Instead, @ref PixelFormat::RGBA8Unorm is used for @ref processedFormat(). This
shouldn't affect common use through @ref image(), but code interacting with
@ref processedImage() or @ref setProcessedImage() may need to be aware of this.
@note This class is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features
for more information.
@see @ref TextureTools::DistanceFieldGL
*/
class MAGNUM_TEXT_EXPORT DistanceFieldGlyphCacheGL: public GlyphCacheGL {
public:
/**
* @brief Constructor
* @param size Size of the source image
* @param processedSize Resulting distance field texture size
* @param radius Distance field computation radius
*
* See @ref TextureTools::DistanceField for more information about the
* parameters. Size restrictions from it apply here as well, in
* particular the ratio of @p size and @p processedSize is expected to
* be a multiple of 2.
*
* Sets the @ref processedFormat() to @ref PixelFormat::R8Unorm, if
* available. On OpenGL ES 3.0+ and WebGL 2 uses always. On desktop
* OpenGL requires @gl_extension{ARB,texture_rg} (part of OpenGL 3.0),
* on ES2 uses @gl_extension{EXT,texture_rg} if available and uses
* @ref PixelFormat::RGB8Unorm as fallback if not, on WebGL 1 uses
* @ref PixelFormat::RGB8Unorm always.
*/
explicit DistanceFieldGlyphCacheGL(const Vector2i& size, const Vector2i& processedSize, UnsignedInt radius);
/**
* @brief Construct without creating the internal state and the OpenGL texture object
* @m_since_latest
*
* The constructed instance is equivalent to moved-from state, i.e. no
* APIs can be safely called on the object. Useful in cases where you
* will overwrite the instance later anyway. Move another object over
* it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit DistanceFieldGlyphCacheGL(NoCreateT) noexcept;
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Distance field texture size
*
* Compared to @ref textureSize(), which is the size of the source
* image, this function returns size of the resulting distance field
* texture.
* @m_deprecated_since_latest Use @ref processedSize() instead.
*/
CORRADE_DEPRECATED("use processedSize() instead") Vector2i distanceFieldTextureSize() const {
return processedSize().xy();
}
/**
* @brief Set a distance field cache image
*
* Compared to @ref setImage() uploads an already computed distance
* field image to given offset in the distance field texture. The
* @p offset and @ref ImageView::size() are expected to be in bounds
* for @ref distanceFieldTextureSize().
* @m_deprecated_since_latest Use @ref setProcessedImage() instead.
*/
CORRADE_DEPRECATED("use setProcessedImage() instead") void setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image);
#endif
private:
MAGNUM_TEXT_LOCAL GlyphCacheFeatures doFeatures() const override;
MAGNUM_TEXT_LOCAL void doSetImage(const Vector2i& offset, const ImageView2D& image) override;
MAGNUM_TEXT_LOCAL void doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) override;
#ifndef MAGNUM_TARGET_GLES
MAGNUM_TEXT_LOCAL Image3D doProcessedImage() override;
#endif
TextureTools::DistanceFieldGL _distanceField;
};
}}
#else
#error this header is available only in the OpenGL build
#endif
#endif

170
src/Magnum/Text/GlyphCache.h

@ -25,172 +25,34 @@
DEALINGS IN THE SOFTWARE.
*/
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file
* @brief Class @ref Magnum::Text::GlyphCache
* @brief Typedef @ref Magnum::Text::GlyphCache
* @m_deprecated_since_latest Use @ref Magnum/Text/GlyphCacheGL.h
* and the @relativeref{Magnum::Text,GlyphCacheGL} class
* instead.
*/
#endif
#include "Magnum/configure.h"
#ifdef MAGNUM_TARGET_GL
#include "Magnum/GL/Texture.h"
#include "Magnum/Text/AbstractGlyphCache.h"
namespace Magnum { namespace Text {
/**
@brief Glyph cache
Contains font glyphs rendered into a texture atlas.
@section Text-GlyphCache-usage Usage
Create the @ref GlyphCache object with sufficient size and then call
@ref AbstractFont::createGlyphCache() to fill it with glyphs.
@snippet Text-gl.cpp GlyphCache-usage
See the @ref Renderer class for information about text rendering. The
@ref AbstractGlyphCache base class has more information about general glyph
cache usage.
@section Text-GlyphCache-internal-format Internal texture format
The @ref GL::TextureFormat used by @ref texture() is implicitly coming from
@ref GL::textureFormat(Magnum::PixelFormat) applied to @ref format(), or if
@ref GlyphCacheFeature::ImageProcessing is supported, to @ref processedFormat()
instead.
If @ref PixelFormat::R8Unorm is used for @ref format() or if
@ref GlyphCacheFeature::ImageProcessing is supported and
@ref PixelFormat::R8Unorm is used for @ref processedFormat(), on desktop OpenGL
the class expects that @gl_extension{ARB,texture_rg} (OpenGL 3.0) is supported
and uses @ref GL::TextureFormat::R8. On OpenGL ES 2.0, if
@gl_extension{EXT,texture_rg} is supported, @ref GL::TextureFormat::Red /
@ref GL::TextureFormat::R8 is used instead of @ref GL::TextureFormat::Luminance
for @ref PixelFormat::R8Unorm. On WebGL 1 @ref GL::TextureFormat::Luminance is
used for @ref PixelFormat::R8Unorm always.
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
While this is abstracted away to not affect common use through @ref image(),
@ref processedImage() or @ref setProcessedImage(), code interacting directly
with @ref texture() may need to special-case this. In particular, if image
processing needs to render to the texture, it may need to choose a different
format as luminance usually cannot be rendered to.
#include "Magnum/Text/GlyphCacheGL.h"
@todo Default glyph 0 with rect 0 0 0 0 will result in negative dimensions when
nonzero padding is removed
CORRADE_DEPRECATED_FILE("use Magnum/Text/GlyphCacheGL.h and the GlyphCacheGL class instead")
@note This class is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features
for more information.
*/
class MAGNUM_TEXT_EXPORT GlyphCache: public AbstractGlyphCache {
public:
/**
* @brief Constructor
* @param format Source image format
* @param size Source image size size in pixels
* @param padding Padding around every glyph in pixels
* @m_since_latest
*
* The @p size is expected to be non-zero. If the implementation
* advertises @ref GlyphCacheFeature::ImageProcessing, the
* @ref processedFormat() and @ref processedSize() is the same as
* @p format and @p size, use @ref AbstractGlyphCache(PixelFormat, const Vector3i&, PixelFormat, const Vector2i&, const Vector2i&)
* to specify different values.
*/
explicit GlyphCache(PixelFormat format, const Vector2i& size, const Vector2i& padding = Vector2i{1});
/**
* @brief Construct with a specific processed format and size
* @param format Source image format
* @param size Source image size size in pixels
* @param processedFormat Processed image format
* @param processedSize Processed glyph cache texture size in
* pixels
* @param padding Padding around every glyph in pixels. See
* @ref Text-AbstractGlyphCache-padding for more information about
* the default.
* @m_since_latest
*
* The @p size and @p processedSize is expected to be non-zero. All
* glyphs are saved in @p format relative to @p size and with
* @p padding, although the actual glyph cache texture is in
* @p processedFormat and has @p processedSize.
* @see @ref AbstractGlyphCache(PixelFormat, const Vector2i&, const Vector2i&)
*/
explicit GlyphCache(PixelFormat format, const Vector2i& size, PixelFormat processedFormat, const Vector2i& processedSize, const Vector2i& padding = Vector2i{1});
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Constructor
* @m_deprecated_since_latest Use @ref GlyphCache(PixelFormat, const Vector2i&, const Vector2i&)
* instead.
*/
CORRADE_DEPRECATED("use GlyphCache(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCache(GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& padding = Vector2i{1});
/**
* @brief Construct with a specific processed size
* @m_deprecated_since_latest Use @ref GlyphCache(PixelFormat, const Vector2i&, PixelFormat, const Vector2i&, const Vector2i&)
* instead.
*/
CORRADE_DEPRECATED("use GlyphCache(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCache(GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding);
/**
* @brief Construct with an implicit format
*
* Calls @ref GlyphCache(PixelFormat, const Vector2i&, const Vector2i&)
* with @p format set to @ref PixelFormat::R8Unorm.
* @m_deprecated_since_latest Use @ref GlyphCache(PixelFormat, const Vector2i&, const Vector2i&)
* and explicitly pass the format instead.
*/
CORRADE_DEPRECATED("use GlyphCache(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCache(const Vector2i& size, const Vector2i& padding = Vector2i{1});
/**
* @brief Construct with an implicit format and a specific processed size
*
* Calls @ref GlyphCache(PixelFormat, const Vector2i&, PixelFormat, const Vector2i&, const Vector2i&)
* with @p format and @p processedFormat set to
* @ref PixelFormat::R8Unorm.
* @m_deprecated_since_latest Use @ref GlyphCache(PixelFormat, const Vector2i&, PixelFormat, const Vector2i&, const Vector2i&)
* and explicitly pass the format instead.
*/
CORRADE_DEPRECATED("use GlyphCache(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCache(const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding);
#endif
/**
* @brief Construct without creating the internal state and the OpenGL texture object
* @m_since_latest
*
* The constructed instance is equivalent to moved-from state, i.e. no
* APIs can be safely called on the object. Useful in cases where you
* will overwrite the instance later anyway. Move another object over
* it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit GlyphCache(NoCreateT) noexcept;
/** @brief Cache texture */
GL::Texture2D& texture() { return _texture; }
#ifdef DOXYGEN_GENERATING_OUTPUT
private:
#else
protected:
#endif
GL::Texture2D _texture;
namespace Magnum { namespace Text {
private:
MAGNUM_TEXT_LOCAL GlyphCacheFeatures doFeatures() const override;
MAGNUM_TEXT_LOCAL void doSetImage(const Vector2i& offset, const ImageView2D& image) override;
};
/** @brief @copybrief GlyphCacheGL
* @m_deprecated_since_latest Use @ref GlyphCacheGL instead.
*/
typedef CORRADE_DEPRECATED("use GlyphCacheGL instead") GlyphCacheGL GlyphCache;
}}
#else
#error this header is available only in the OpenGL build
#error use Magnum/Text/GlyphCacheGL.h and the GlyphCacheGL class instead
#endif
#endif

20
src/Magnum/Text/GlyphCache.cpp → src/Magnum/Text/GlyphCacheGL.cpp

@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE.
*/
#include "GlyphCache.h"
#include "GlyphCacheGL.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Containers/Optional.h>
@ -45,7 +45,7 @@
namespace Magnum { namespace Text {
GlyphCache::GlyphCache(const PixelFormat format, const Vector2i& size, const PixelFormat processedFormat, const Vector2i& processedSize, const Vector2i& padding): AbstractGlyphCache{format, size, processedFormat, processedSize, padding} {
GlyphCacheGL::GlyphCacheGL(const PixelFormat format, const Vector2i& size, const PixelFormat processedFormat, const Vector2i& processedSize, const Vector2i& padding): AbstractGlyphCache{format, size, processedFormat, processedSize, padding} {
#ifndef MAGNUM_TARGET_GLES
if(processedFormat == PixelFormat::R8Unorm)
MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::texture_rg);
@ -87,26 +87,26 @@ GlyphCache::GlyphCache(const PixelFormat format, const Vector2i& size, const Pix
#endif
}
GlyphCache::GlyphCache(const PixelFormat format, const Vector2i& size, const Vector2i& padding): GlyphCache{format, size, format, size, padding} {}
GlyphCacheGL::GlyphCacheGL(const PixelFormat format, const Vector2i& size, const Vector2i& padding): GlyphCacheGL{format, size, format, size, padding} {}
#ifdef MAGNUM_BUILD_DEPRECATED
/* The unconditional Optional unwrap in these two may assert in rare cases.
Let's hope it doesn't in practice. */
GlyphCache::GlyphCache(const GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& padding): GlyphCache{*GL::genericPixelFormat(internalFormat), size, padding} {}
GlyphCacheGL::GlyphCacheGL(const GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& padding): GlyphCacheGL{*GL::genericPixelFormat(internalFormat), size, padding} {}
GlyphCache::GlyphCache(const GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding): GlyphCache{*GL::genericPixelFormat(internalFormat), size, *GL::genericPixelFormat(internalFormat), processedSize, padding} {}
GlyphCacheGL::GlyphCacheGL(const GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding): GlyphCacheGL{*GL::genericPixelFormat(internalFormat), size, *GL::genericPixelFormat(internalFormat), processedSize, padding} {}
GlyphCache::GlyphCache(const Vector2i& size, const Vector2i& padding): GlyphCache{PixelFormat::R8Unorm, size, padding} {}
GlyphCacheGL::GlyphCacheGL(const Vector2i& size, const Vector2i& padding): GlyphCacheGL{PixelFormat::R8Unorm, size, padding} {}
GlyphCache::GlyphCache(const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding): GlyphCache{PixelFormat::R8Unorm, size, PixelFormat::R8Unorm, processedSize, padding} {}
GlyphCacheGL::GlyphCacheGL(const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding): GlyphCacheGL{PixelFormat::R8Unorm, size, PixelFormat::R8Unorm, processedSize, padding} {}
#endif
GlyphCache::GlyphCache(NoCreateT) noexcept: AbstractGlyphCache{NoCreate}, _texture{NoCreate} {}
GlyphCacheGL::GlyphCacheGL(NoCreateT) noexcept: AbstractGlyphCache{NoCreate}, _texture{NoCreate} {}
GlyphCacheFeatures GlyphCache::doFeatures() const { return {}; }
GlyphCacheFeatures GlyphCacheGL::doFeatures() const { return {}; }
void GlyphCache::doSetImage(const Vector2i& offset, const ImageView2D& image) {
void GlyphCacheGL::doSetImage(const Vector2i& offset, const ImageView2D& image) {
/* On ES2 without EXT_unpack_subimage and on WebGL 1 there's no possibility
to upload just a slice of the input, upload the whole image instead by
ignoring the PixelStorage properties of the input */

198
src/Magnum/Text/GlyphCacheGL.h

@ -0,0 +1,198 @@
#ifndef Magnum_Text_GlyphCacheGL_h
#define Magnum_Text_GlyphCacheGL_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Class @ref Magnum::Text::GlyphCacheGL
* @m_since_latest
*/
#include "Magnum/configure.h"
#ifdef MAGNUM_TARGET_GL
#include "Magnum/GL/Texture.h"
#include "Magnum/Text/AbstractGlyphCache.h"
namespace Magnum { namespace Text {
/**
@brief OpenGL glyph cache
@m_since_latest
Contains font glyphs rendered into a texture atlas.
@section Text-GlyphCacheGL-usage Usage
Create the @ref GlyphCacheGL object with sufficient size and then call
@ref AbstractFont::createGlyphCache() to fill it with glyphs.
@snippet Text-gl.cpp GlyphCacheGL-usage
See the @ref Renderer class for information about text rendering. The
@ref AbstractGlyphCache base class has more information about general glyph
cache usage.
@section Text-GlyphCacheGL-internal-format Internal texture format
The @ref GL::TextureFormat used by @ref texture() is implicitly coming from
@ref GL::textureFormat(Magnum::PixelFormat) applied to @ref format(), or if
@ref GlyphCacheFeature::ImageProcessing is supported, to @ref processedFormat()
instead.
If @ref PixelFormat::R8Unorm is used for @ref format() or if
@ref GlyphCacheFeature::ImageProcessing is supported and
@ref PixelFormat::R8Unorm is used for @ref processedFormat(), on desktop OpenGL
the class expects that @gl_extension{ARB,texture_rg} (OpenGL 3.0) is supported
and uses @ref GL::TextureFormat::R8. On OpenGL ES 2.0, if
@gl_extension{EXT,texture_rg} is supported, @ref GL::TextureFormat::Red /
@ref GL::TextureFormat::R8 is used instead of @ref GL::TextureFormat::Luminance
for @ref PixelFormat::R8Unorm. On WebGL 1 @ref GL::TextureFormat::Luminance is
used for @ref PixelFormat::R8Unorm always.
While this is abstracted away to not affect common use through @ref image(),
@ref processedImage() or @ref setProcessedImage(), code interacting directly
with @ref texture() may need to special-case this. In particular, if image
processing needs to render to the texture, it may need to choose a different
format as luminance usually cannot be rendered to.
@todo Default glyph 0 with rect 0 0 0 0 will result in negative dimensions when
nonzero padding is removed
@note This class is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features
for more information.
*/
class MAGNUM_TEXT_EXPORT GlyphCacheGL: public AbstractGlyphCache {
public:
/**
* @brief Constructor
* @param format Source image format
* @param size Source image size size in pixels
* @param padding Padding around every glyph in pixels
* @m_since_latest
*
* The @p size is expected to be non-zero. If the implementation
* advertises @ref GlyphCacheFeature::ImageProcessing, the
* @ref processedFormat() and @ref processedSize() is the same as
* @p format and @p size, use @ref AbstractGlyphCache(PixelFormat, const Vector3i&, PixelFormat, const Vector2i&, const Vector2i&)
* to specify different values.
*/
explicit GlyphCacheGL(PixelFormat format, const Vector2i& size, const Vector2i& padding = Vector2i{1});
/**
* @brief Construct with a specific processed format and size
* @param format Source image format
* @param size Source image size size in pixels
* @param processedFormat Processed image format
* @param processedSize Processed glyph cache texture size in
* pixels
* @param padding Padding around every glyph in pixels. See
* @ref Text-AbstractGlyphCache-padding for more information about
* the default.
* @m_since_latest
*
* The @p size and @p processedSize is expected to be non-zero. All
* glyphs are saved in @p format relative to @p size and with
* @p padding, although the actual glyph cache texture is in
* @p processedFormat and has @p processedSize.
* @see @ref AbstractGlyphCache(PixelFormat, const Vector2i&, const Vector2i&)
*/
explicit GlyphCacheGL(PixelFormat format, const Vector2i& size, PixelFormat processedFormat, const Vector2i& processedSize, const Vector2i& padding = Vector2i{1});
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Constructor
* @m_deprecated_since_latest Use @ref GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&)
* instead.
*/
CORRADE_DEPRECATED("use GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCacheGL(GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& padding = Vector2i{1});
/**
* @brief Construct with a specific processed size
* @m_deprecated_since_latest Use @ref GlyphCacheGL(PixelFormat, const Vector2i&, PixelFormat, const Vector2i&, const Vector2i&)
* instead.
*/
CORRADE_DEPRECATED("use GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCacheGL(GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding);
/**
* @brief Construct with an implicit format
*
* Calls @ref GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&)
* with @p format set to @ref PixelFormat::R8Unorm.
* @m_deprecated_since_latest Use @ref GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&)
* and explicitly pass the format instead.
*/
CORRADE_DEPRECATED("use GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCacheGL(const Vector2i& size, const Vector2i& padding = Vector2i{1});
/**
* @brief Construct with an implicit format and a specific processed size
*
* Calls @ref GlyphCacheGL(PixelFormat, const Vector2i&, PixelFormat, const Vector2i&, const Vector2i&)
* with @p format and @p processedFormat set to
* @ref PixelFormat::R8Unorm.
* @m_deprecated_since_latest Use @ref GlyphCacheGL(PixelFormat, const Vector2i&, PixelFormat, const Vector2i&, const Vector2i&)
* and explicitly pass the format instead.
*/
CORRADE_DEPRECATED("use GlyphCacheGL(PixelFormat, const Vector2i&, const Vector2i&, const Vector2i&) instead") explicit GlyphCacheGL(const Vector2i& size, const Vector2i& processedSize, const Vector2i& padding);
#endif
/**
* @brief Construct without creating the internal state and the OpenGL texture object
* @m_since_latest
*
* The constructed instance is equivalent to moved-from state, i.e. no
* APIs can be safely called on the object. Useful in cases where you
* will overwrite the instance later anyway. Move another object over
* it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit GlyphCacheGL(NoCreateT) noexcept;
/** @brief Cache texture */
GL::Texture2D& texture() { return _texture; }
#ifdef DOXYGEN_GENERATING_OUTPUT
private:
#else
protected:
#endif
GL::Texture2D _texture;
private:
MAGNUM_TEXT_LOCAL GlyphCacheFeatures doFeatures() const override;
MAGNUM_TEXT_LOCAL void doSetImage(const Vector2i& offset, const ImageView2D& image) override;
};
}}
#else
#error this header is available only in the OpenGL build
#endif
#endif

4
src/Magnum/Text/Test/CMakeLists.txt

@ -84,8 +84,8 @@ corrade_add_test(TextRendererTest RendererTest.cpp LIBRARIES MagnumTextTestLib)
corrade_add_test(TextScriptTest ScriptTest.cpp LIBRARIES MagnumTextTestLib)
if(MAGNUM_TARGET_GL)
corrade_add_test(TextGlyphCacheTest GlyphCacheTest.cpp LIBRARIES MagnumText)
corrade_add_test(TextDistanceFieldGlyphCacheTest DistanceFieldGlyphCacheTest.cpp LIBRARIES MagnumText)
corrade_add_test(TextGlyphCacheGL_Test GlyphCacheGL_Test.cpp LIBRARIES MagnumText)
corrade_add_test(TextDistanceFieldGlyphCacheGL_Test DistanceFieldGlyphCacheGL_Test.cpp LIBRARIES MagnumText)
if(MAGNUM_BUILD_GL_TESTS)
corrade_add_test(TextDistanceFieldGlyphCacheGLTest DistanceFieldGlyphCacheGLTest.cpp

46
src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp

@ -44,7 +44,7 @@
#include "Magnum/GL/OpenGLTester.h"
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/PixelFormat.h"
#include "Magnum/Text/DistanceFieldGlyphCache.h"
#include "Magnum/Text/DistanceFieldGlyphCacheGL.h"
#include "Magnum/Trade/AbstractImporter.h"
#include "Magnum/Trade/ImageData.h"
@ -142,7 +142,7 @@ DistanceFieldGlyphCacheGLTest::DistanceFieldGlyphCacheGLTest() {
}
void DistanceFieldGlyphCacheGLTest::construct() {
DistanceFieldGlyphCache cache{{1024, 2048}, {128, 256}, 16};
DistanceFieldGlyphCacheGL cache{{1024, 2048}, {128, 256}, 16};
MAGNUM_VERIFY_NO_GL_ERROR();
/* The input format is always single-channel */
@ -175,44 +175,44 @@ void DistanceFieldGlyphCacheGLTest::constructSizeRatioNotMultipleOfTwo() {
CORRADE_SKIP_IF_NO_ASSERT();
/* This should be fine */
DistanceFieldGlyphCache{Vector2i{23*14}, Vector2i{23}, 4};
DistanceFieldGlyphCacheGL{Vector2i{23*14}, Vector2i{23}, 4};
/* It's the same assert as in TextureTools::DistanceFieldGL */
std::ostringstream out;
Error redirectError{&out};
DistanceFieldGlyphCache{Vector2i{23*14}, Vector2i{23*2}, 4};
DistanceFieldGlyphCacheGL{Vector2i{23*14}, Vector2i{23*2}, 4};
/* Verify also just one axis wrong */
DistanceFieldGlyphCache{Vector2i{23*14}, {23*2, 23}, 4};
DistanceFieldGlyphCache{Vector2i{23*14}, {23, 23*2}, 4};
DistanceFieldGlyphCacheGL{Vector2i{23*14}, {23*2, 23}, 4};
DistanceFieldGlyphCacheGL{Vector2i{23*14}, {23, 23*2}, 4};
/* Almost correct except that it's not an integer multiply */
DistanceFieldGlyphCache{Vector2i{23*14}, {22, 23}, 4};
DistanceFieldGlyphCache{Vector2i{23*14}, {23, 22}, 4};
DistanceFieldGlyphCacheGL{Vector2i{23*14}, {22, 23}, 4};
DistanceFieldGlyphCacheGL{Vector2i{23*14}, {23, 22}, 4};
CORRADE_COMPARE_AS(out.str(),
"Text::DistanceFieldGlyphCache: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {46, 46}\n"
"Text::DistanceFieldGlyphCache: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {46, 23}\n"
"Text::DistanceFieldGlyphCache: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {23, 46}\n"
"Text::DistanceFieldGlyphCache: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {22, 23}\n"
"Text::DistanceFieldGlyphCache: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {23, 22}\n",
"Text::DistanceFieldGlyphCacheGL: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {46, 46}\n"
"Text::DistanceFieldGlyphCacheGL: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {46, 23}\n"
"Text::DistanceFieldGlyphCacheGL: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {23, 46}\n"
"Text::DistanceFieldGlyphCacheGL: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {22, 23}\n"
"Text::DistanceFieldGlyphCacheGL: expected source and processed size ratio to be a multiple of 2, got {322, 322} and {23, 22}\n",
TestSuite::Compare::String);
}
void DistanceFieldGlyphCacheGLTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<DistanceFieldGlyphCache>{});
CORRADE_VERIFY(!std::is_copy_assignable<DistanceFieldGlyphCache>{});
CORRADE_VERIFY(!std::is_copy_constructible<DistanceFieldGlyphCacheGL>{});
CORRADE_VERIFY(!std::is_copy_assignable<DistanceFieldGlyphCacheGL>{});
}
void DistanceFieldGlyphCacheGLTest::constructMove() {
DistanceFieldGlyphCache a{{1024, 512}, {128, 64}, 3};
DistanceFieldGlyphCacheGL a{{1024, 512}, {128, 64}, 3};
DistanceFieldGlyphCache b = Utility::move(a);
DistanceFieldGlyphCacheGL b = Utility::move(a);
CORRADE_COMPARE(b.size(), (Vector3i{1024, 512, 1}));
DistanceFieldGlyphCache c{{2, 4}, {1, 2}, 1};
DistanceFieldGlyphCacheGL c{{2, 4}, {1, 2}, 1};
c = Utility::move(b);
CORRADE_COMPARE(c.size(), (Vector3i{1024, 512, 1}));
CORRADE_VERIFY(std::is_nothrow_move_constructible<DistanceFieldGlyphCache>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<DistanceFieldGlyphCache>::value);
CORRADE_VERIFY(std::is_nothrow_move_constructible<DistanceFieldGlyphCacheGL>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<DistanceFieldGlyphCacheGL>::value);
}
void DistanceFieldGlyphCacheGLTest::setImage() {
@ -230,7 +230,7 @@ void DistanceFieldGlyphCacheGLTest::setImage() {
CORRADE_COMPARE(inputImage->format(), PixelFormat::R8Unorm);
CORRADE_COMPARE(inputImage->size(), (Vector2i{256, 256}));
DistanceFieldGlyphCache cache{data.sourceSize, data.size, 32};
DistanceFieldGlyphCacheGL cache{data.sourceSize, data.size, 32};
Containers::StridedArrayView3D<const char> src = inputImage->pixels();
/* Test also uploading under an offset. The cache might be three-component
in some cases, slice the destination view to just the first component */
@ -284,7 +284,7 @@ void DistanceFieldGlyphCacheGLTest::setProcessedImage() {
setTestCaseDescription(data.name);
#endif
DistanceFieldGlyphCache cache({64, 32}, {16, 8}, 16);
DistanceFieldGlyphCacheGL cache({64, 32}, {16, 8}, 16);
#ifdef MAGNUM_TARGET_GLES2
/* Ugh, don't want to bother implementing this */
@ -368,7 +368,7 @@ void DistanceFieldGlyphCacheGLTest::setProcessedImage() {
void DistanceFieldGlyphCacheGLTest::setDistanceFieldImageUnsupportedGLFormat() {
CORRADE_SKIP_IF_NO_ASSERT();
DistanceFieldGlyphCache cache{{4, 4}, {1, 1}, 4};
DistanceFieldGlyphCacheGL cache{{4, 4}, {1, 1}, 4};
std::ostringstream out;
Error redirectError{&out};

18
src/Magnum/Text/Test/DistanceFieldGlyphCacheTest.cpp → src/Magnum/Text/Test/DistanceFieldGlyphCacheGL_Test.cpp

@ -25,30 +25,30 @@
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Text/DistanceFieldGlyphCache.h"
#include "Magnum/Text/DistanceFieldGlyphCacheGL.h"
namespace Magnum { namespace Text { namespace Test { namespace {
struct DistanceFieldGlyphCacheTest: TestSuite::Tester {
explicit DistanceFieldGlyphCacheTest();
struct DistanceFieldGlyphCacheGL_Test: TestSuite::Tester {
explicit DistanceFieldGlyphCacheGL_Test();
void constructNoCreate();
};
DistanceFieldGlyphCacheTest::DistanceFieldGlyphCacheTest() {
addTests({&DistanceFieldGlyphCacheTest::constructNoCreate});
DistanceFieldGlyphCacheGL_Test::DistanceFieldGlyphCacheGL_Test() {
addTests({&DistanceFieldGlyphCacheGL_Test::constructNoCreate});
}
void DistanceFieldGlyphCacheTest::constructNoCreate() {
DistanceFieldGlyphCache cache{NoCreate};
void DistanceFieldGlyphCacheGL_Test::constructNoCreate() {
DistanceFieldGlyphCacheGL cache{NoCreate};
/* Shouldn't crash or try to acces GL */
CORRADE_VERIFY(true);
/* Implicit construction is not allowed */
CORRADE_VERIFY(!std::is_convertible<NoCreateT, DistanceFieldGlyphCache>::value);
CORRADE_VERIFY(!std::is_convertible<NoCreateT, DistanceFieldGlyphCacheGL>::value);
}
}}}}
CORRADE_TEST_MAIN(Magnum::Text::Test::DistanceFieldGlyphCacheTest)
CORRADE_TEST_MAIN(Magnum::Text::Test::DistanceFieldGlyphCacheGL_Test)

40
src/Magnum/Text/Test/GlyphCacheGLTest.cpp

@ -43,7 +43,7 @@
#include "Magnum/GL/TextureFormat.h"
#include "Magnum/Math/Color.h"
#include "Magnum/Math/Range.h"
#include "Magnum/Text/GlyphCache.h"
#include "Magnum/Text/GlyphCacheGL.h"
namespace Magnum { namespace Text { namespace Test { namespace {
@ -88,7 +88,7 @@ GlyphCacheGLTest::GlyphCacheGLTest() {
}
void GlyphCacheGLTest::construct() {
GlyphCache cache{PixelFormat::R8Unorm, {1024, 2048}, {3, 2}};
GlyphCacheGL cache{PixelFormat::R8Unorm, {1024, 2048}, {3, 2}};
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(cache.format(), PixelFormat::R8Unorm);
@ -100,7 +100,7 @@ void GlyphCacheGLTest::construct() {
}
void GlyphCacheGLTest::constructNoPadding() {
GlyphCache cache{PixelFormat::RGBA8Unorm, {1024, 2048}};
GlyphCacheGL cache{PixelFormat::RGBA8Unorm, {1024, 2048}};
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(cache.format(), PixelFormat::RGBA8Unorm);
@ -112,8 +112,8 @@ void GlyphCacheGLTest::constructNoPadding() {
}
void GlyphCacheGLTest::constructProcessed() {
struct : GlyphCache {
using GlyphCache::GlyphCache;
struct: GlyphCacheGL {
using GlyphCacheGL::GlyphCacheGL;
GlyphCacheFeatures doFeatures() const override {
return GlyphCacheFeature::ImageProcessing;
@ -135,8 +135,8 @@ void GlyphCacheGLTest::constructProcessed() {
}
void GlyphCacheGLTest::constructProcessedNoPadding() {
struct : GlyphCache {
using GlyphCache::GlyphCache;
struct: GlyphCacheGL {
using GlyphCacheGL::GlyphCacheGL;
GlyphCacheFeatures doFeatures() const override {
return GlyphCacheFeature::ImageProcessing;
@ -160,7 +160,7 @@ void GlyphCacheGLTest::constructProcessedNoPadding() {
#ifdef MAGNUM_BUILD_DEPRECATED
void GlyphCacheGLTest::constructDeprecated() {
CORRADE_IGNORE_DEPRECATED_PUSH
GlyphCache cache{{1024, 2048}};
GlyphCacheGL cache{{1024, 2048}};
CORRADE_IGNORE_DEPRECATED_POP
MAGNUM_VERIFY_NO_GL_ERROR();
@ -172,7 +172,7 @@ void GlyphCacheGLTest::constructDeprecated() {
void GlyphCacheGLTest::constructDeprecatedProcessed() {
CORRADE_IGNORE_DEPRECATED_PUSH
GlyphCache cache{{1024, 2048}, {128, 256}, {}};
GlyphCacheGL cache{{1024, 2048}, {128, 256}, {}};
CORRADE_IGNORE_DEPRECATED_POP
MAGNUM_VERIFY_NO_GL_ERROR();
@ -184,7 +184,7 @@ void GlyphCacheGLTest::constructDeprecatedProcessed() {
void GlyphCacheGLTest::constructDeprecatedTextureFormat() {
CORRADE_IGNORE_DEPRECATED_PUSH
GlyphCache cache{
GlyphCacheGL cache{
#ifndef MAGNUM_TARGET_GLES2
GL::TextureFormat::RGBA8,
#else
@ -202,7 +202,7 @@ void GlyphCacheGLTest::constructDeprecatedTextureFormat() {
void GlyphCacheGLTest::constructDeprecatedTextureFormatProcessed() {
CORRADE_IGNORE_DEPRECATED_PUSH
GlyphCache cache{
GlyphCacheGL cache{
#ifndef MAGNUM_TARGET_GLES2
GL::TextureFormat::RGBA8,
#else
@ -220,24 +220,24 @@ void GlyphCacheGLTest::constructDeprecatedTextureFormatProcessed() {
#endif
void GlyphCacheGLTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<GlyphCache>{});
CORRADE_VERIFY(!std::is_copy_assignable<GlyphCache>{});
CORRADE_VERIFY(!std::is_copy_constructible<GlyphCacheGL>{});
CORRADE_VERIFY(!std::is_copy_assignable<GlyphCacheGL>{});
}
void GlyphCacheGLTest::constructMove() {
GlyphCache a{PixelFormat::R8Unorm, {1024, 512}};
GlyphCacheGL a{PixelFormat::R8Unorm, {1024, 512}};
GlyphCache b = Utility::move(a);
GlyphCacheGL b = Utility::move(a);
CORRADE_COMPARE(b.format(), PixelFormat::R8Unorm);
CORRADE_COMPARE(b.size(), (Vector3i{1024, 512, 1}));
GlyphCache c{PixelFormat::RGBA8Unorm, {2, 3}};
GlyphCacheGL c{PixelFormat::RGBA8Unorm, {2, 3}};
c = Utility::move(b);
CORRADE_COMPARE(c.format(), PixelFormat::R8Unorm);
CORRADE_COMPARE(c.size(), (Vector3i{1024, 512, 1}));
CORRADE_VERIFY(std::is_nothrow_move_constructible<GlyphCache>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<GlyphCache>::value);
CORRADE_VERIFY(std::is_nothrow_move_constructible<GlyphCacheGL>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<GlyphCacheGL>::value);
}
const UnsignedByte InputData[]{
@ -259,7 +259,7 @@ const UnsignedByte ExpectedData[]{
};
void GlyphCacheGLTest::setImage() {
GlyphCache cache{PixelFormat::R8Unorm, {16, 8}};
GlyphCacheGL cache{PixelFormat::R8Unorm, {16, 8}};
/* Fill the texture with non-zero data to verify the padding gets uploaded
as well. On ES2 with EXT_texture_rg the internal format isn't Luminance
@ -334,7 +334,7 @@ void GlyphCacheGLTest::setImageFourChannel() {
upload works, as there's a special case for when the EXT_unpack_subimage
extension isn't present. */
GlyphCache cache{PixelFormat::RGBA8Unorm, {4, 8}};
GlyphCacheGL cache{PixelFormat::RGBA8Unorm, {4, 8}};
/* Zero the texture to avoid comparing against garbage */
cache.texture().setSubImage(0, {}, Image2D{PixelFormat::RGBA8Unorm, {4, 8}, Containers::Array<char>{ValueInit, 4*4*8}});

18
src/Magnum/Text/Test/GlyphCacheTest.cpp → src/Magnum/Text/Test/GlyphCacheGL_Test.cpp

@ -25,30 +25,30 @@
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Text/GlyphCache.h"
#include "Magnum/Text/GlyphCacheGL.h"
namespace Magnum { namespace Text { namespace Test { namespace {
struct GlyphCacheTest: TestSuite::Tester {
explicit GlyphCacheTest();
struct GlyphCacheGL_Test: TestSuite::Tester {
explicit GlyphCacheGL_Test();
void constructNoCreate();
};
GlyphCacheTest::GlyphCacheTest() {
addTests({&GlyphCacheTest::constructNoCreate});
GlyphCacheGL_Test::GlyphCacheGL_Test() {
addTests({&GlyphCacheGL_Test::constructNoCreate});
}
void GlyphCacheTest::constructNoCreate() {
GlyphCache cache{NoCreate};
void GlyphCacheGL_Test::constructNoCreate() {
GlyphCacheGL cache{NoCreate};
/* Shouldn't crash or try to acces GL */
CORRADE_VERIFY(true);
/* Implicit construction is not allowed */
CORRADE_VERIFY(!std::is_convertible<NoCreateT, GlyphCache>::value);
CORRADE_VERIFY(!std::is_convertible<NoCreateT, GlyphCacheGL>::value);
}
}}}}
CORRADE_TEST_MAIN(Magnum::Text::Test::GlyphCacheTest)
CORRADE_TEST_MAIN(Magnum::Text::Test::GlyphCacheGL_Test)

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

@ -36,7 +36,7 @@
#include "Magnum/GL/OpenGLTester.h"
#include "Magnum/Text/AbstractFont.h"
#include "Magnum/Text/AbstractShaper.h"
#include "Magnum/Text/GlyphCache.h"
#include "Magnum/Text/GlyphCacheGL.h"
#include "Magnum/Text/Renderer.h"
namespace Magnum { namespace Text { namespace Test { namespace {
@ -113,9 +113,9 @@ struct TestFont: AbstractFont {
bool _opened = false;
};
GlyphCache testGlyphCache(AbstractFont& font) {
GlyphCacheGL testGlyphCache(AbstractFont& font) {
/* Default padding is 1 to avoid artifacts, set that to 0 to simplify */
GlyphCache cache{PixelFormat::R8Unorm, {20, 20}, {}};
GlyphCacheGL cache{PixelFormat::R8Unorm, {20, 20}, {}};
/* Add one more font to verify the right one gets picked */
cache.addFont(96);
@ -134,7 +134,7 @@ void RendererGLTest::renderMesh() {
TestFont font;
font.openFile({}, 0.5f);
GlyphCache cache = testGlyphCache(font);
GlyphCacheGL cache = testGlyphCache(font);
/* Capture the correct function name */
CORRADE_VERIFY(true);
@ -188,7 +188,7 @@ void RendererGLTest::renderMeshIndexType() {
#ifndef MAGNUM_TARGET_GLES
TestFont font;
font.openFile({}, 0.5f);
GlyphCache cache = testGlyphCache(font);
GlyphCacheGL cache = testGlyphCache(font);
/* Capture the correct function name */
CORRADE_VERIFY(true);
@ -246,7 +246,7 @@ void RendererGLTest::mutableText() {
TestFont font;
font.openFile({}, 0.5f);
GlyphCache cache = testGlyphCache(font);
GlyphCacheGL cache = testGlyphCache(font);
Renderer2D renderer(font, cache, 0.25f, Alignment::MiddleCenter);
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(renderer.capacity(), 0);

13
src/Magnum/Text/Text.h

@ -30,7 +30,10 @@
*/
#include "Magnum/Types.h"
#include "Magnum/configure.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Text {
@ -53,8 +56,12 @@ enum class Script: UnsignedInt;
class FeatureRange;
#ifdef MAGNUM_TARGET_GL
class DistanceFieldGlyphCache;
class GlyphCache;
class DistanceFieldGlyphCacheGL;
class GlyphCacheGL;
#ifdef MAGNUM_BUILD_DEPRECATED
typedef CORRADE_DEPRECATED("use DistanceFieldGlyphCacheGL instead") DistanceFieldGlyphCacheGL DistanceFieldGlyphCache;
typedef CORRADE_DEPRECATED("use GlyphCacheGL instead") GlyphCacheGL GlyphCache;
#endif
class AbstractRenderer;
template<UnsignedInt> class Renderer;
typedef Renderer<2> Renderer2D;

8
src/Magnum/Text/fontconverter.cpp

@ -33,7 +33,7 @@
#include "Magnum/Math/ConfigurationValue.h"
#include "Magnum/Text/AbstractFont.h"
#include "Magnum/Text/AbstractFontConverter.h"
#include "Magnum/Text/DistanceFieldGlyphCache.h"
#include "Magnum/Text/DistanceFieldGlyphCacheGL.h"
#include "Magnum/Trade/AbstractImageConverter.h"
#ifdef MAGNUM_TARGET_EGL
@ -199,11 +199,11 @@ int FontConverter::exec() {
}
/* Create distance field glyph cache if radius is specified */
Containers::Pointer<GlyphCache> cache;
Containers::Pointer<GlyphCacheGL> cache;
if(!args.value<Vector2i>("output-size").isZero()) {
Debug() << "Populating distance field glyph cache...";
cache.emplace<DistanceFieldGlyphCache>(
cache.emplace<DistanceFieldGlyphCacheGL>(
args.value<Vector2i>("atlas-size"),
args.value<Vector2i>("output-size"),
args.value<UnsignedInt>("radius"));
@ -212,7 +212,7 @@ int FontConverter::exec() {
} else {
Debug() << "Zero-size distance field output specified, populating normal glyph cache...";
cache.emplace<GlyphCache>(PixelFormat::R8Unorm, args.value<Vector2i>("atlas-size"));
cache.emplace<GlyphCacheGL>(PixelFormat::R8Unorm, args.value<Vector2i>("atlas-size"));
}
/* Fill the cache */

4
src/MagnumPlugins/MagnumFont/MagnumFont.cpp

@ -42,7 +42,7 @@
#include "Magnum/PixelFormat.h"
#include "Magnum/Math/ConfigurationValue.h"
#include "Magnum/Text/AbstractShaper.h"
#include "Magnum/Text/GlyphCache.h"
#include "Magnum/Text/GlyphCacheGL.h"
#include "Magnum/Trade/ImageData.h"
#include "MagnumPlugins/TgaImporter/TgaImporter.h"
@ -160,7 +160,7 @@ Vector2 MagnumFont::doGlyphAdvance(const UnsignedInt glyph) {
Containers::Pointer<AbstractGlyphCache> MagnumFont::doCreateGlyphCache() {
/* Set cache image */
Containers::Pointer<GlyphCache> cache{InPlaceInit,
Containers::Pointer<GlyphCacheGL> cache{InPlaceInit,
PixelFormat::R8Unorm,
_opened->conf.value<Vector2i>("originalImageSize"),
PixelFormat::R8Unorm,

10
src/MagnumPlugins/MagnumFont/Test/MagnumFontGLTest.cpp

@ -40,7 +40,7 @@
#include "Magnum/Math/Range.h"
#include "Magnum/GL/OpenGLTester.h"
#include "Magnum/Text/AbstractFont.h"
#include "Magnum/Text/GlyphCache.h"
#include "Magnum/Text/GlyphCacheGL.h"
#include "Magnum/Trade/AbstractImporter.h"
#include "configure.h"
@ -137,9 +137,9 @@ void MagnumFontGLTest::createGlyphCache() {
we cannot really verify that the size matches, but at least
something. */
#ifndef MAGNUM_TARGET_GLES
Image2D image = static_cast<GlyphCache&>(*cache).texture().image(0, {PixelFormat::R8Unorm});
Image2D image = static_cast<GlyphCacheGL&>(*cache).texture().image(0, {PixelFormat::R8Unorm});
#else
Image2D image = DebugTools::textureSubImage(static_cast<GlyphCache&>(*cache).texture(), 0, {{}, {128, 64}}, {PixelFormat::R8Unorm});
Image2D image = DebugTools::textureSubImage(static_cast<GlyphCacheGL&>(*cache).texture(), 0, {{}, {128, 64}}, {PixelFormat::R8Unorm});
#endif
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE_WITH(image,
@ -211,9 +211,9 @@ void MagnumFontGLTest::createGlyphCacheProcessedImage() {
we cannot really verify that the size matches, but at least
something. */
#ifndef MAGNUM_TARGET_GLES
Image2D image = static_cast<GlyphCache&>(*cache).texture().image(0, {PixelFormat::R8Unorm});
Image2D image = static_cast<GlyphCacheGL&>(*cache).texture().image(0, {PixelFormat::R8Unorm});
#else
Image2D image = DebugTools::textureSubImage(static_cast<GlyphCache&>(*cache).texture(), 0, {{}, {8, 4}}, {PixelFormat::R8Unorm});
Image2D image = DebugTools::textureSubImage(static_cast<GlyphCacheGL&>(*cache).texture(), 0, {{}, {8, 4}}, {PixelFormat::R8Unorm});
#endif
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE_WITH(image,

Loading…
Cancel
Save