From f0b7489554fede81ba1d030d37e336631d8d5b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 17:44:05 +0200 Subject: [PATCH] Text: fix and improve format checking of passed image in DFGlyphCache. --- src/Text/DistanceFieldGlyphCache.cpp | 19 +++++++++++++++---- src/Text/GlyphCache.cpp | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Text/DistanceFieldGlyphCache.cpp b/src/Text/DistanceFieldGlyphCache.cpp index d0643d212..8de12233e 100644 --- a/src/Text/DistanceFieldGlyphCache.cpp +++ b/src/Text/DistanceFieldGlyphCache.cpp @@ -38,6 +38,7 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, c #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) GlyphCache(TextureFormat::R8, originalSize, size, Vector2i(radius)), #else + /* Luminance is not renderable in most cases */ GlyphCache(Context::current()->isExtensionSupported() ? TextureFormat::Red : TextureFormat::RGB, originalSize, size, Vector2i(radius)), #endif @@ -48,16 +49,13 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, c #endif #ifdef MAGNUM_TARGET_GLES2 + /* Luminance is not renderable in most cases */ if(!Context::current()->isExtensionSupported()) Warning() << "Text::DistanceFieldGlyphCache:" << Extensions::GL::EXT::texture_rg::string() << "not supported, using inefficient RGB format for glyph cache texture"; #endif } void DistanceFieldGlyphCache::setImage(const Vector2i& offset, const ImageReference2D& image) { - #ifndef MAGNUM_TARGET_GLES - MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); - #endif - #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) const TextureFormat internalFormat = TextureFormat::R8; CORRADE_ASSERT(image.format() == ImageFormat::Red, @@ -86,6 +84,19 @@ void DistanceFieldGlyphCache::setImage(const Vector2i& offset, const ImageRefere } void DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, const ImageReference2D& image) { + #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) + CORRADE_ASSERT(image.format() == ImageFormat::Red, + "Text::DistanceFieldGlyphCache::setDistanceFieldImage(): expected" << ImageFormat::Red << "but got" << image.format(), ); + #else + if(Context::current()->isExtensionSupported()) + CORRADE_ASSERT(image.format() == ImageFormat::Red, + "Text::DistanceFieldGlyphCache::setDistanceFieldImage(): expected" << ImageFormat::Red << "but got" << image.format(), ); + + /* Luminance is not renderable in most cases */ + else CORRADE_ASSERT(image.format() == ImageFormat::RGB, + "Text::DistanceFieldGlyphCache::setDistanceFieldImage(): expected" << ImageFormat::RGB << "but got" << image.format(), ); + #endif + texture()->setSubImage(0, offset, image); } diff --git a/src/Text/GlyphCache.cpp b/src/Text/GlyphCache.cpp index 3e054803c..78355ad7f 100644 --- a/src/Text/GlyphCache.cpp +++ b/src/Text/GlyphCache.cpp @@ -98,6 +98,7 @@ void GlyphCache::insert(const UnsignedInt glyph, Vector2i position, Rectanglei r } void GlyphCache::setImage(const Vector2i& offset, const ImageReference2D& image) { + /** @todo some internalformat/format checking also here (if querying internal format is not slow) */ _texture.setSubImage(0, offset, image); }