Browse Source

Text: ported GlyphCache to older OpenGL and OpenGL ES.

* Not requiring ARB_texture_storage, as Texture::setStorage() has
   already implemented fallback.
 * Not requiring EXT_texture_rg for single-channel texture on ES2, as
   this extension might not be available everywhere (unlike in ES3
   desktop OpenGL, where Mesa 8/9 with OpenGL 2.1 supports it), fallback
   to Luminance in GlyphCache and RGB in DistanceFieldGlyphCache,
   because Luminance might not be renderable everywhere.
 * Re-enabled building of Text library in all ES PKGBUILDs.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
7187ccb48b
  1. 1
      PKGBUILD-es2
  2. 1
      PKGBUILD-es2desktop
  3. 1
      PKGBUILD-es3
  4. 40
      src/Text/DistanceFieldGlyphCache.cpp
  5. 5
      src/Text/DistanceFieldGlyphCache.h
  6. 22
      src/Text/GlyphCache.cpp
  7. 7
      src/Text/GlyphCache.h

1
PKGBUILD-es2

@ -26,7 +26,6 @@ build() {
-DBUILD_TESTS=ON \ -DBUILD_TESTS=ON \
-DTARGET_GLES=ON \ -DTARGET_GLES=ON \
-DTARGET_GLES2=ON \ -DTARGET_GLES2=ON \
-DWITH_TEXT=OFF \
-DWITH_MAGNUMINFO=OFF \ -DWITH_MAGNUMINFO=OFF \
-DWITH_XEGLAPPLICATION=ON -DWITH_XEGLAPPLICATION=ON
make make

1
PKGBUILD-es2desktop

@ -27,7 +27,6 @@ build() {
-DTARGET_GLES=ON \ -DTARGET_GLES=ON \
-DTARGET_GLES2=ON \ -DTARGET_GLES2=ON \
-DTARGET_DESKTOP_GLES=ON \ -DTARGET_DESKTOP_GLES=ON \
-DWITH_TEXT=OFF \
-DWITH_MAGNUMINFO=OFF \ -DWITH_MAGNUMINFO=OFF \
-DWITH_XEGLAPPLICATION=ON -DWITH_XEGLAPPLICATION=ON
make make

1
PKGBUILD-es3

@ -26,7 +26,6 @@ build() {
-DBUILD_TESTS=ON \ -DBUILD_TESTS=ON \
-DTARGET_GLES=ON \ -DTARGET_GLES=ON \
-DTARGET_GLES2=OFF \ -DTARGET_GLES2=OFF \
-DWITH_TEXT=OFF \
-DWITH_MAGNUMINFO=OFF \ -DWITH_MAGNUMINFO=OFF \
-DWITH_XEGLAPPLICATION=ON -DWITH_XEGLAPPLICATION=ON
make make

40
src/Text/DistanceFieldGlyphCache.cpp

@ -26,30 +26,54 @@
#include "Extensions.h" #include "Extensions.h"
#include "Image.h" #include "Image.h"
#ifndef CORRADE_NO_ASSERT
#include "ImageFormat.h"
#endif
#include "TextureFormat.h" #include "TextureFormat.h"
#include "TextureTools/DistanceField.h" #include "TextureTools/DistanceField.h"
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
namespace { DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& distanceFieldSize, UnsignedInt radius): GlyphCache(originalSize, Vector2i(radius)), scale(Vector2(distanceFieldSize)/originalSize), radius(radius) {
#ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg);
#endif
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3)
const TextureFormat internalFormat = TextureFormat::R8; const TextureFormat internalFormat = TextureFormat::R8;
#else #else
const TextureFormat internalFormat = TextureFormat::Red; const TextureFormat internalFormat =
Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>() ?
TextureFormat::Red : TextureFormat::RGB;
if(internalFormat == TextureFormat::RGB)
Warning() << "Text::DistanceFieldGlyphCache:" << Extensions::GL::EXT::texture_rg::string() << "not supported, using inefficient RGB format for glyph cache texture";
#endif #endif
initialize(internalFormat, distanceFieldSize);
} }
DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& distanceFieldSize, UnsignedInt radius): GlyphCache(originalSize, Vector2i(radius)), scale(Vector2(distanceFieldSize)/originalSize), radius(radius) { void DistanceFieldGlyphCache::setImage(const Vector2i& offset, Image2D* const image) {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg);
#else
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg);
#endif #endif
initialize(internalFormat, distanceFieldSize); #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3)
} const TextureFormat internalFormat = TextureFormat::R8;
CORRADE_ASSERT(image->format() == ImageFormat::Red,
"Text::DistanceFieldGlyphCache::setImage(): expected" << ImageFormat::Red << "but got" << image->format(), );
#else
TextureFormat internalFormat;
if(Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>()) {
internalFormat = TextureFormat::Red;
CORRADE_ASSERT(image->format() == ImageFormat::Red,
"Text::DistanceFieldGlyphCache::setImage(): expected" << ImageFormat::Red << "but got" << image->format(), );
} else {
internalFormat = TextureFormat::Luminance;
CORRADE_ASSERT(image->format() == ImageFormat::Luminance,
"Text::DistanceFieldGlyphCache::setImage(): expected" << ImageFormat::Luminance << "but got" << image->format(), );
}
#endif
void DistanceFieldGlyphCache::setImage(const Vector2i& offset, Image2D* const image) {
Texture2D input; Texture2D input;
input.setWrapping(Sampler::Wrapping::ClampToEdge) input.setWrapping(Sampler::Wrapping::ClampToEdge)
->setMinificationFilter(Sampler::Filter::Linear) ->setMinificationFilter(Sampler::Filter::Linear)

5
src/Text/DistanceFieldGlyphCache.h

@ -62,7 +62,10 @@ class MAGNUM_TEXT_EXPORT DistanceFieldGlyphCache: public GlyphCache {
* @param radius Distance field computation radius * @param radius Distance field computation radius
* *
* See TextureTools::distanceField() for more information about the * See TextureTools::distanceField() for more information about the
* parameters. * parameters. Sets internal texture format to red channel only. On
* desktop OpenGL requires @extension{ARB,texture_rg} (also part of
* OpenGL ES 3.0), in ES2 uses @es_extension{EXT,texture_rg} if
* available or @ref TextureFormat "TextureFormat::RGB" as fallback.
*/ */
explicit DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& distanceFieldSize, UnsignedInt radius); explicit DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& distanceFieldSize, UnsignedInt radius);

22
src/Text/GlyphCache.cpp

@ -31,19 +31,17 @@
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
namespace {
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3)
const TextureFormat internalFormat = TextureFormat::R8;
#else
const TextureFormat internalFormat = TextureFormat::Red;
#endif
}
GlyphCache::GlyphCache(const Vector2i& size): _size(size) { GlyphCache::GlyphCache(const Vector2i& size): _size(size) {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg);
#endif
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3)
const TextureFormat internalFormat = TextureFormat::R8;
#else #else
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); const TextureFormat internalFormat =
Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>() ?
TextureFormat::Red : TextureFormat::Luminance;
#endif #endif
initialize(internalFormat, size); initialize(internalFormat, size);
@ -59,12 +57,6 @@ GlyphCache::~GlyphCache() = default;
/** @todo Delegating constructor when support for GCC 4.6 is dropped */ /** @todo Delegating constructor when support for GCC 4.6 is dropped */
void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i& size) { void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i& size) {
#ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_storage);
#else
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_storage);
#endif
_texture.setWrapping(Sampler::Wrapping::ClampToEdge) _texture.setWrapping(Sampler::Wrapping::ClampToEdge)
->setMinificationFilter(Sampler::Filter::Linear) ->setMinificationFilter(Sampler::Filter::Linear)
->setMagnificationFilter(Sampler::Filter::Linear) ->setMagnificationFilter(Sampler::Filter::Linear)

7
src/Text/GlyphCache.h

@ -69,9 +69,10 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
* @brief Constructor * @brief Constructor
* @param size Glyph cache texture size * @param size Glyph cache texture size
* *
* Sets internal texture format to red channel only. Requires * Sets internal texture format to red channel only. On desktop OpenGL
* @extension{ARB,texture_rg} (also part of OpenGL ES 3.0 or available * requires @extension{ARB,texture_rg} (also part of OpenGL ES 3.0), in
* as @es_extension{EXT,texture_rg} in ES 2.0). * ES2 uses @es_extension{EXT,texture_rg}, if available, or
* @ref TextureFormat "TextureFormat::Luminance" as fallback.
*/ */
explicit GlyphCache(const Vector2i& size); explicit GlyphCache(const Vector2i& size);

Loading…
Cancel
Save