Browse Source

Text: full test coverage for the GlyphCache classes.

About time this got done. This also has an XFAIL for the case where a
distance field image is processed with an offset, have to fix the
underlying issue in TextureTools first.

Also added a range assertion for the distance field image setter to
match what the abstract base does, together with a corresponding getter.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
82691fcd50
  1. 3
      src/Magnum/Text/CMakeLists.txt
  2. 8
      src/Magnum/Text/DistanceFieldGlyphCache.cpp
  3. 17
      src/Magnum/Text/DistanceFieldGlyphCache.h
  4. 18
      src/Magnum/Text/Test/AbstractGlyphCacheTest.cpp
  5. 2
      src/Magnum/Text/Test/AbstractLayouterTest.cpp
  6. 57
      src/Magnum/Text/Test/CMakeLists.txt
  7. 179
      src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp
  8. 73
      src/Magnum/Text/Test/GlyphCacheGLTest.cpp
  9. 3
      src/Magnum/Text/Test/configure.h.cmake

3
src/Magnum/Text/CMakeLists.txt

@ -49,9 +49,10 @@ set(MagnumText_HEADERS
if(MAGNUM_TARGET_GL)
list(APPEND MagnumText_SRCS
DistanceFieldGlyphCache.cpp
GlyphCache.cpp
Renderer.cpp)
list(APPEND MagnumText_GracefulAssert_SRCS
DistanceFieldGlyphCache.cpp)
list(APPEND MagnumText_HEADERS
DistanceFieldGlyphCache.h
GlyphCache.h

8
src/Magnum/Text/DistanceFieldGlyphCache.cpp

@ -46,7 +46,7 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, c
#else
GlyphCache(GL::TextureFormat::RGB, originalSize, size, Vector2i(radius)),
#endif
_scale{Vector2(size)/Vector2(originalSize)}, _distanceField{radius}
_size{size}, _distanceField{radius}
{
#ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::texture_rg);
@ -91,10 +91,14 @@ void DistanceFieldGlyphCache::doSetImage(const Vector2i& offset, const ImageView
#endif
/* Create distance field from input texture */
_distanceField(input, texture(), Range2Di::fromSize(offset*_scale, image.size()*_scale), image.size());
const Vector2 scale = Vector2{_size}/Vector2{textureSize()};
_distanceField(input, texture(), Range2Di::fromSize(offset*scale, image.size()*scale), image.size());
}
void DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image) {
CORRADE_ASSERT((offset >= Vector2i{} && offset + image.size() <= _size).all(),
"Text::DistanceFieldGlyphCache::setDistanceFieldImage():" << Range2Di::fromSize(offset, image.size()) << "out of bounds for texture size" << _size, );
#ifndef CORRADE_NO_ASSERT
const GL::PixelFormat format = GL::pixelFormat(image.format());
#endif

17
src/Magnum/Text/DistanceFieldGlyphCache.h

@ -76,18 +76,29 @@ class MAGNUM_TEXT_EXPORT DistanceFieldGlyphCache: public GlyphCache {
*/
explicit DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& size, UnsignedInt radius);
/**
* @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.
*/
Vector2i distanceFieldTextureSize() const { return _size; }
/**
* @brief Set a distance field cache image
*
* Uploads already computed distance field image to given offset in
* distance field texture.
* 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().
*/
void setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image);
private:
void doSetImage(const Vector2i& offset, const ImageView2D& image) override;
Vector2 _scale;
Vector2i _size;
TextureTools::DistanceField _distanceField;
};

18
src/Magnum/Text/Test/AbstractGlyphCacheTest.cpp

@ -25,8 +25,10 @@
#include <sstream>
#include <tuple>
#include <Corrade/Containers/StringStl.h> /**< @todo drop once Debug is stream-free */
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/TestSuite/Compare/String.h>
#include <Corrade/Utility/DebugStl.h> /**< @todo drop once Debug is stream-free */
#include "Magnum/Image.h"
#include "Magnum/ImageView.h"
@ -138,15 +140,21 @@ void AbstractGlyphCacheTest::setImageOutOfBounds() {
DummyGlyphCache cache{{100, 200}};
/* This is fine */
cache.setImage({80, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
std::ostringstream out;
Error redirectError{&out};
cache.setImage({80, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setImage({81, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setImage({80, 176}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setImage({-1, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setImage({80, -1}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
CORRADE_COMPARE(out.str(),
CORRADE_COMPARE_AS(out.str(),
"Text::AbstractGlyphCache::setImage(): Range({81, 175}, {101, 200}) out of bounds for texture size Vector(100, 200)\n"
"Text::AbstractGlyphCache::setImage(): Range({80, -1}, {100, 24}) out of bounds for texture size Vector(100, 200)\n");
"Text::AbstractGlyphCache::setImage(): Range({80, 176}, {100, 201}) out of bounds for texture size Vector(100, 200)\n"
"Text::AbstractGlyphCache::setImage(): Range({-1, 175}, {19, 200}) out of bounds for texture size Vector(100, 200)\n"
"Text::AbstractGlyphCache::setImage(): Range({80, -1}, {100, 24}) out of bounds for texture size Vector(100, 200)\n",
TestSuite::Compare::String);
}
void AbstractGlyphCacheTest::image() {

2
src/Magnum/Text/Test/AbstractLayouterTest.cpp

@ -83,6 +83,8 @@ void AbstractLayouterTest::renderGlyph() {
}
void AbstractLayouterTest::renderGlyphOutOfBounds() {
CORRADE_SKIP_IF_NO_ASSERT();
struct Layouter: AbstractLayouter {
explicit Layouter(): AbstractLayouter{3} {}

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

@ -30,27 +30,72 @@ set(CMAKE_FOLDER "Magnum/Text/Test")
if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID)
set(TEXT_TEST_DIR ".")
set(TEXT_TEST_OUTPUT_DIR "./write")
set(TEXTURETOOLS_DISTANCEFIELDGLTEST_DIR ".")
else()
set(TEXT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TEXT_TEST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(TEXTURETOOLS_DISTANCEFIELDGLTEST_DIR ${PROJECT_SOURCE_DIR}/src/Magnum/TextureTools/Test/DistanceFieldGLTestFiles)
endif()
if(MAGNUM_TARGET_GL AND MAGNUM_BUILD_GL_TESTS)
if(NOT MAGNUM_BUILD_PLUGINS_STATIC)
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
set(ANYIMAGEIMPORTER_PLUGIN_FILENAME $<TARGET_FILE:AnyImageImporter>)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
set(TGAIMPORTER_PLUGIN_FILENAME $<TARGET_FILE:TgaImporter>)
endif()
endif()
endif()
# First replace ${} variables, then $<> generator expressions
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)
${CMAKE_CURRENT_BINARY_DIR}/configure.h.in)
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/configure.h
INPUT ${CMAKE_CURRENT_BINARY_DIR}/configure.h.in)
corrade_add_test(TextAbstractFontTest AbstractFontTest.cpp
LIBRARIES Magnum MagnumTextTestLib
FILES data.bin)
target_include_directories(TextAbstractFontTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(TextAbstractFontTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
corrade_add_test(TextAbstractFontConverterTest AbstractFontConverterTest.cpp
LIBRARIES Magnum MagnumTextTestLib
FILES data.bin)
target_include_directories(TextAbstractFontConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(TextAbstractFontConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
corrade_add_test(TextAbstractGlyphCacheTest AbstractGlyphCacheTest.cpp LIBRARIES MagnumTextTestLib)
corrade_add_test(TextAbstractLayouterTest AbstractLayouterTest.cpp LIBRARIES Magnum MagnumText)
corrade_add_test(TextAbstractLayouterTest AbstractLayouterTest.cpp LIBRARIES Magnum MagnumTextTestLib)
if(MAGNUM_TARGET_GL AND MAGNUM_BUILD_GL_TESTS)
corrade_add_test(TextDistanceFieldGlyphCacheGLTest DistanceFieldGlyphCacheGLTest.cpp LIBRARIES MagnumText MagnumOpenGLTester)
corrade_add_test(TextGlyphCacheGLTest GlyphCacheGLTest.cpp LIBRARIES MagnumText MagnumOpenGLTester)
corrade_add_test(TextDistanceFieldGlyphCacheGLTest DistanceFieldGlyphCacheGLTest.cpp
LIBRARIES
MagnumTextTestLib
MagnumOpenGLTester
MagnumDebugTools
FILES
${PROJECT_SOURCE_DIR}/src/Magnum/TextureTools/Test/DistanceFieldGLTestFiles/input.tga
${PROJECT_SOURCE_DIR}/src/Magnum/TextureTools/Test/DistanceFieldGLTestFiles/output.tga)
target_include_directories(TextDistanceFieldGlyphCacheGLTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
if(MAGNUM_BUILD_PLUGINS_STATIC)
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
target_link_libraries(TextDistanceFieldGlyphCacheGLTest PRIVATE AnyImageImporter)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
target_link_libraries(TextDistanceFieldGlyphCacheGLTest PRIVATE TgaImporter)
endif()
else()
# So the plugins get properly built when building the test
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
add_dependencies(TextDistanceFieldGlyphCacheGLTest AnyImageImporter)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
add_dependencies(TextDistanceFieldGlyphCacheGLTest TgaImporter)
endif()
endif()
corrade_add_test(TextGlyphCacheGLTest GlyphCacheGLTest.cpp
LIBRARIES
MagnumText
MagnumOpenGLTester
MagnumDebugTools)
corrade_add_test(TextRendererGLTest RendererGLTest.cpp LIBRARIES MagnumText MagnumOpenGLTester)
endif()

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

@ -23,8 +23,26 @@
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
#include <Corrade/Containers/StridedArrayView.h>
#include <Corrade/Containers/StringStl.h> /**< @todo remove once Debug is stream-free */
#include <Corrade/PluginManager/AbstractManager.h>
#include <Corrade/TestSuite/Compare/String.h>
#include <Corrade/Utility/DebugStl.h> /**< @todo remove once Debug is stream-free */
#include <Corrade/Utility/Path.h>
#include "Magnum/Image.h"
#include "Magnum/ImageView.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/DebugTools/CompareImage.h"
#include "Magnum/GL/OpenGLTester.h"
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/PixelFormat.h"
#include "Magnum/Text/DistanceFieldGlyphCache.h"
#include "Magnum/Trade/AbstractImporter.h"
#include "Magnum/Trade/ImageData.h"
#include "configure.h"
namespace Magnum { namespace Text { namespace Test { namespace {
@ -32,21 +50,178 @@ struct DistanceFieldGlyphCacheGLTest: GL::OpenGLTester {
explicit DistanceFieldGlyphCacheGLTest();
void initialize();
void setImage();
void setDistanceFieldImage();
void setDistanceFieldImageOutOfBounds();
PluginManager::Manager<Trade::AbstractImporter> _manager{"nonexistent"};
};
const struct {
const char* name;
Vector2i sourceSize, size, sourceOffset;
Containers::Size2D offset;
} SetImageData[]{
{"",
{256, 256}, {64, 64},
{}, {}},
{"upload with offset",
{512, 384}, {128, 96},
{256, 128}, {128/4, 256/4}},
};
DistanceFieldGlyphCacheGLTest::DistanceFieldGlyphCacheGLTest() {
addTests({&DistanceFieldGlyphCacheGLTest::initialize});
addInstancedTests({&DistanceFieldGlyphCacheGLTest::setImage},
Containers::arraySize(SetImageData));
addTests({&DistanceFieldGlyphCacheGLTest::setDistanceFieldImage,
&DistanceFieldGlyphCacheGLTest::setDistanceFieldImageOutOfBounds});
/* Load the plugin directly from the build tree. Otherwise it's either
static and already loaded or not present in the build tree */
#ifdef ANYIMAGEIMPORTER_PLUGIN_FILENAME
CORRADE_INTERNAL_ASSERT_OUTPUT(_manager.load(ANYIMAGEIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
#endif
#ifdef TGAIMPORTER_PLUGIN_FILENAME
CORRADE_INTERNAL_ASSERT_OUTPUT(_manager.load(TGAIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
#endif
}
void DistanceFieldGlyphCacheGLTest::initialize() {
DistanceFieldGlyphCache cache{{1024, 2048}, {256, 256}, 16};
DistanceFieldGlyphCache cache{{1024, 2048}, {128, 256}, 16};
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(cache.textureSize(), (Vector2i{1024, 2048}));
CORRADE_COMPARE(cache.distanceFieldTextureSize(), (Vector2i{128, 256}));
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(cache.texture().imageSize(0), (Vector2i{128, 256}));
#endif
}
void DistanceFieldGlyphCacheGLTest::setImage() {
auto&& data = SetImageData[testCaseInstanceId()];
setTestCaseDescription(data.name);
Containers::Pointer<Trade::AbstractImporter> importer;
if(!(importer = _manager.loadAndInstantiate("TgaImporter")))
CORRADE_SKIP("TgaImporter plugin not found.");
CORRADE_VERIFY(importer->openFile(Utility::Path::join(TEXTURETOOLS_DISTANCEFIELDGLTEST_DIR, "input.tga")));
CORRADE_COMPARE(importer->image2DCount(), 1);
Containers::Optional<Trade::ImageData2D> inputImage = importer->image2D(0);
CORRADE_VERIFY(inputImage);
CORRADE_COMPARE(inputImage->format(), PixelFormat::R8Unorm);
CORRADE_COMPARE(inputImage->size(), (Vector2i{256, 256}));
DistanceFieldGlyphCache cache{data.sourceSize, data.size, 32};
/* Test also uploading under an offset */
cache.setImage(data.sourceOffset, *inputImage);
MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES
Image2D actual = cache.image();
MAGNUM_VERIFY_NO_GL_ERROR();
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) ||
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("AnyImageImporter / TgaImporter plugins not found.");
CORRADE_EXPECT_FAIL_IF(!data.sourceOffset.isZero(),
"The distance field tool is currently broken if a non-zero offset is used.");
CORRADE_COMPARE_WITH(actual.pixels<UnsignedByte>().exceptPrefix(data.offset),
Utility::Path::join(TEXTURETOOLS_DISTANCEFIELDGLTEST_DIR, "output.tga"),
/* Same threshold as in TextureTools DistanceFieldGLTest */
(DebugTools::CompareImageToFile{_manager, 1.0f, 0.178f}));
#else
CORRADE_SKIP("Skipping image download test as it's not available on GLES.");
#endif
}
void DistanceFieldGlyphCacheGLTest::setDistanceFieldImage() {
DistanceFieldGlyphCache cache({64, 32}, {16, 8}, 16);
/* Pick a format that matches the internal texture format. This is rather
shitty, TBH. */
#if !(defined(MAGNUM_TARGET_GLES) && defined(MAGNUM_TARGET_GLES2))
const GL::PixelFormat format = GL::PixelFormat::Red;
#else
GL::PixelFormat format;
#ifndef MAGNUM_TARGET_WEBGL
if(GL::Context::current().isExtensionSupported<GL::Extensions::EXT::texture_rg>()) {
format = GL::PixelFormat::Red;
} else
#endif
{
/* Ugh, don't want to bother implementing this */
CORRADE_SKIP("A three-component input is expected on ES2, skipping due to developer laziness.");
}
#endif
/* Clear the texture first, as it'd have random garbage otherwise */
UnsignedByte zeros[16*8]{};
cache.setDistanceFieldImage({}, ImageView2D{format, GL::PixelType::UnsignedByte, {16, 8}, zeros});
MAGNUM_VERIFY_NO_GL_ERROR();
UnsignedByte data[]{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
cache.setDistanceFieldImage({8, 4}, ImageView2D{format, GL::PixelType::UnsignedByte, {8, 4}, data});
MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(cache.texture().imageSize(0), (Vector2i{256, 256}));
Image2D actual = cache.image();
MAGNUM_VERIFY_NO_GL_ERROR();
UnsignedByte expected[]{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
CORRADE_COMPARE_AS(actual,
(ImageView2D{PixelFormat::R8Unorm, {16, 8}, expected}),
DebugTools::CompareImage);
#else
CORRADE_SKIP("Skipping image download test as it's not available on GLES.");
#endif
}
void DistanceFieldGlyphCacheGLTest::setDistanceFieldImageOutOfBounds() {
CORRADE_SKIP_IF_NO_ASSERT();
DistanceFieldGlyphCache cache{{200, 300}, {100, 200}, 4};
/* This is fine. Not testing on ES2 as there it would need the complicated
format logic from above. */
#if !(defined(MAGNUM_TARGET_GLES) && defined(MAGNUM_TARGET_GLES2))
cache.setDistanceFieldImage({80, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
#endif
std::ostringstream out;
Error redirectError{&out};
cache.setDistanceFieldImage({81, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setDistanceFieldImage({80, 176}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setDistanceFieldImage({-1, 175}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
cache.setDistanceFieldImage({80, -1}, ImageView2D{PixelFormat::R8Unorm, {20, 25}});
CORRADE_COMPARE_AS(out.str(),
"Text::DistanceFieldGlyphCache::setDistanceFieldImage(): Range({81, 175}, {101, 200}) out of bounds for texture size Vector(100, 200)\n"
"Text::DistanceFieldGlyphCache::setDistanceFieldImage(): Range({80, 176}, {100, 201}) out of bounds for texture size Vector(100, 200)\n"
"Text::DistanceFieldGlyphCache::setDistanceFieldImage(): Range({-1, 175}, {19, 200}) out of bounds for texture size Vector(100, 200)\n"
"Text::DistanceFieldGlyphCache::setDistanceFieldImage(): Range({80, -1}, {100, 24}) out of bounds for texture size Vector(100, 200)\n",
TestSuite::Compare::String);
}
}}}}
CORRADE_TEST_MAIN(Magnum::Text::Test::DistanceFieldGlyphCacheGLTest)

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

@ -23,7 +23,14 @@
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/Containers/StringView.h>
#include "Magnum/Image.h"
#include "Magnum/ImageView.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/DebugTools/CompareImage.h"
#include "Magnum/GL/OpenGLTester.h"
#include "Magnum/GL/TextureFormat.h"
#include "Magnum/Text/GlyphCache.h"
namespace Magnum { namespace Text { namespace Test { namespace {
@ -32,18 +39,80 @@ struct GlyphCacheGLTest: GL::OpenGLTester {
explicit GlyphCacheGLTest();
void initialize();
void initializeExplicitFormat();
void setImage();
};
GlyphCacheGLTest::GlyphCacheGLTest() {
addTests({&GlyphCacheGLTest::initialize});
addTests({&GlyphCacheGLTest::initialize,
&GlyphCacheGLTest::initializeExplicitFormat,
&GlyphCacheGLTest::setImage});
}
void GlyphCacheGLTest::initialize() {
GlyphCache cache{{1024, 2048}};
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(cache.textureSize(), (Vector2i{1024, 2048}));
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(cache.texture().imageSize(0), (Vector2i{1024, 2048}));
#endif
}
void GlyphCacheGLTest::initializeExplicitFormat() {
GlyphCache cache{
#ifndef MAGNUM_TARGET_GLES2
GL::TextureFormat::RGBA8,
#else
GL::TextureFormat::RGBA,
#endif
{256, 512}};
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(cache.textureSize(), (Vector2i{256, 512}));
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(cache.texture().imageSize(0), (Vector2i{256, 512}));
#endif
}
void GlyphCacheGLTest::setImage() {
GlyphCache cache{{16, 8}};
/* Clear the texture first, as it'd have random garbage otherwise */
UnsignedByte zeros[16*8]{};
cache.setImage({}, ImageView2D{PixelFormat::R8Unorm, {16, 8}, zeros});
MAGNUM_VERIFY_NO_GL_ERROR();
UnsignedByte data[]{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
cache.setImage({8, 4}, ImageView2D{PixelFormat::R8Unorm, {8, 4}, data});
MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(cache.texture().imageSize(0), Vector2i(1024, 2048));
Image2D actual = cache.image();
MAGNUM_VERIFY_NO_GL_ERROR();
UnsignedByte expected[]{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
};
CORRADE_COMPARE_AS(actual,
(ImageView2D{PixelFormat::R8Unorm, {16, 8}, expected}),
DebugTools::CompareImage);
#else
CORRADE_SKIP("Skipping image download test as it's not available on GLES.");
#endif
}

3
src/Magnum/Text/Test/configure.h.cmake

@ -23,5 +23,8 @@
DEALINGS IN THE SOFTWARE.
*/
#cmakedefine ANYIMAGEIMPORTER_PLUGIN_FILENAME "${ANYIMAGEIMPORTER_PLUGIN_FILENAME}"
#cmakedefine TGAIMPORTER_PLUGIN_FILENAME "${TGAIMPORTER_PLUGIN_FILENAME}"
#define TEXT_TEST_DIR "${TEXT_TEST_DIR}"
#define TEXT_TEST_OUTPUT_DIR "${TEXT_TEST_OUTPUT_DIR}"
#define TEXTURETOOLS_DISTANCEFIELDGLTEST_DIR "${TEXTURETOOLS_DISTANCEFIELDGLTEST_DIR}"

Loading…
Cancel
Save