Browse Source

Text: fall back to full RGBA on WebGL 1 or ES2 w/o EXT_texture_rg.

RGB was a hopeful intention that never really worked in practice. Or, if
it worked, it couldn't be queried back, and the driver used RGBA
internally anyway.
pull/650/head
Vladimír Vondruš 2 years ago
parent
commit
5bb132aeb9
  1. 10
      src/Magnum/Text/DistanceFieldGlyphCache.cpp
  2. 4
      src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp

10
src/Magnum/Text/DistanceFieldGlyphCache.cpp

@ -43,11 +43,13 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& size, const Vec
#if !(defined(MAGNUM_TARGET_GLES) && defined(MAGNUM_TARGET_GLES2))
GlyphCache(GL::TextureFormat::R8, size, processedSize, Vector2i(radius)),
#elif !defined(MAGNUM_TARGET_WEBGL)
/* Luminance is not renderable in most cases */
/* Luminance is not renderable in most cases. RGB is *theoretically*
space-efficient but practically the driver uses RGBA internally anyway,
so just use RGBA. */
GlyphCache(GL::Context::current().isExtensionSupported<GL::Extensions::EXT::texture_rg>() ?
GL::TextureFormat::R8 : GL::TextureFormat::RGB8, size, processedSize, Vector2i(radius)),
GL::TextureFormat::R8 : GL::TextureFormat::RGBA8, size, processedSize, Vector2i(radius)),
#else
GlyphCache(GL::TextureFormat::RGB, size, processedSize, Vector2i(radius)),
GlyphCache(GL::TextureFormat::RGBA, size, processedSize, Vector2i(radius)),
#endif
_distanceField{radius}
{
@ -65,7 +67,7 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& size, const Vec
#if defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/* Luminance is not renderable in most cases */
if(!GL::Context::current().isExtensionSupported<GL::Extensions::EXT::texture_rg>())
Warning() << "Text::DistanceFieldGlyphCache:" << GL::Extensions::EXT::texture_rg::string() << "not supported, using inefficient RGB format for glyph cache texture";
Warning() << "Text::DistanceFieldGlyphCache:" << GL::Extensions::EXT::texture_rg::string() << "not supported, using a full RGBA format for the distance field texture";
#endif
}

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

@ -258,8 +258,8 @@ void DistanceFieldGlyphCacheGLTest::setProcessedImage() {
#ifdef MAGNUM_TARGET_GLES2
/* Ugh, don't want to bother implementing this */
if(cache.processedFormat() == PixelFormat::RGB8Unorm)
CORRADE_SKIP("A three-component input is expected on ES2, skipping due to developer laziness.");
if(cache.processedFormat() == PixelFormat::RGBA8Unorm)
CORRADE_SKIP("A four-component input is expected on ES2, skipping due to developer laziness.");
#endif
/* Clear the texture first, as it'd have random garbage otherwise */

Loading…
Cancel
Save