Browse Source

Text: put do{Set,}ProcessedImage() directly into GlyphCacheGL.

They don't have anything specific to DistanceFieldGlyphCacheGL and on
the other hand contain special-casing for Luminance vs Red on ES2 that's
specific to GlyphCacheGL internals.

Additionally, in DistanceFieldGlyphCacheGL the code could assume that
the pixel format is either R8 with EXT_texture_rg present or RGBA8
without, here it has to check for EXT_texture_rg presence as
GlyphCacheGL can use R8 even without EXT_texture_rg.
pull/650/head
Vladimír Vondruš 2 years ago
parent
commit
ca7de799eb
  1. 27
      src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp
  2. 5
      src/Magnum/Text/DistanceFieldGlyphCacheGL.h
  3. 27
      src/Magnum/Text/GlyphCacheGL.cpp
  4. 6
      src/Magnum/Text/GlyphCacheGL.h
  5. 12
      src/Magnum/Text/Test/GlyphCacheGLTest.cpp

27
src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp

@ -25,7 +25,6 @@
#include "DistanceFieldGlyphCacheGL.h"
#include "Magnum/Image.h"
#include "Magnum/ImageView.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/GL/Context.h"
@ -169,30 +168,4 @@ void DistanceFieldGlyphCacheGL::setDistanceFieldImage(const Vector2i& offset, co
}
#endif
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
EXT_texture_rg is supported. Reinterpret the image format in that
case. If the format is something else (such as RGBA8Unorm), no
reinterpret is done. WebGL doesn't have the EXT_texture_rg extension so
there it isn't done either. */
#if defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(processedFormat() == PixelFormat::R8Unorm) {
/* This is checked inside setProcessedImage() already */
CORRADE_INTERNAL_ASSERT(image.format() == PixelFormat::R8Unorm);
imageToUse = ImageView2D{image.storage(), GL::PixelFormat::Red, GL::PixelType::UnsignedByte, image.size(), image.data()};
}
#endif
texture().setSubImage(0, offset, imageToUse);
}
#ifndef MAGNUM_TARGET_GLES
Image3D DistanceFieldGlyphCacheGL::doProcessedImage() {
Image2D out = _texture.image(0, PixelFormat::R8Unorm);
return Image3D{out.format(), {out.size(), 1}, out.release()};
}
#endif
}}

5
src/Magnum/Text/DistanceFieldGlyphCacheGL.h

@ -163,11 +163,6 @@ class MAGNUM_TEXT_EXPORT DistanceFieldGlyphCacheGL: public GlyphCacheGL {
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;
};

27
src/Magnum/Text/GlyphCacheGL.cpp

@ -29,6 +29,7 @@
#include <Corrade/Containers/Optional.h>
#endif
#include "Magnum/Image.h"
#include "Magnum/ImageView.h"
#include "Magnum/GL/TextureFormat.h"
#ifdef MAGNUM_BUILD_DEPRECATED
@ -151,4 +152,30 @@ void GlyphCacheGL::doSetImage(const Vector2i& offset, const ImageView2D& image)
#endif
}
void GlyphCacheGL::doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) {
ImageView2D imageToUse = image;
/* On ES2, R8Unorm maps to Luminance, but here it's actually Red if
EXT_texture_rg is supported. Reinterpret the image format in that
case. If the format is something else (such as RGBA8Unorm), no
reinterpret is done. WebGL doesn't have the EXT_texture_rg extension so
there it isn't done either. */
#if defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(processedFormat() == PixelFormat::R8Unorm && GL::Context::current().isExtensionSupported<GL::Extensions::EXT::texture_rg>()) {
/* This is checked inside setProcessedImage() already */
CORRADE_INTERNAL_ASSERT(image.format() == PixelFormat::R8Unorm);
imageToUse = ImageView2D{image.storage(), GL::PixelFormat::Red, GL::PixelType::UnsignedByte, image.size(), image.data()};
}
#endif
texture().setSubImage(0, offset, imageToUse);
}
#ifndef MAGNUM_TARGET_GLES
Image3D GlyphCacheGL::doProcessedImage() {
Image2D out = _texture.image(0, PixelFormat::R8Unorm);
return Image3D{out.format(), {out.size(), 1}, out.release()};
}
#endif
}}

6
src/Magnum/Text/GlyphCacheGL.h

@ -188,6 +188,12 @@ class MAGNUM_TEXT_EXPORT GlyphCacheGL: public AbstractGlyphCache {
private:
MAGNUM_TEXT_LOCAL GlyphCacheFeatures doFeatures() const override;
MAGNUM_TEXT_LOCAL void doSetImage(const Vector2i& offset, const ImageView2D& image) override;
/* Used if a subclass advertises GlyphCacheFeature::ImageProcessing /
ProcessedImageDownload in its doFeatures() */
MAGNUM_TEXT_LOCAL void doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) override;
#ifndef MAGNUM_TARGET_GLES
MAGNUM_TEXT_LOCAL Image3D doProcessedImage() override;
#endif
};
}}

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

@ -118,9 +118,13 @@ void GlyphCacheGLTest::constructProcessed() {
GlyphCacheFeatures doFeatures() const override {
return GlyphCacheFeature::ImageProcessing;
}
/* The symbol is private, we don't actually need it here, so just
/* The symbols are private, we don't actually need them here, so just
override with an empty implementation */
void doSetImage(const Vector2i&, const ImageView2D&) override {}
void doSetProcessedImage(const Vector2i&, const ImageView2D&) override {}
Image3D doProcessedImage() override {
CORRADE_INTERNAL_ASSERT_UNREACHABLE();
}
} cache{PixelFormat::R8Unorm, {1024, 2048}, PixelFormat::RGBA8Unorm, {128, 256}, {3, 2}};
MAGNUM_VERIFY_NO_GL_ERROR();
@ -141,9 +145,13 @@ void GlyphCacheGLTest::constructProcessedNoPadding() {
GlyphCacheFeatures doFeatures() const override {
return GlyphCacheFeature::ImageProcessing;
}
/* The symbol is private, we don't actually need it here, so just
/* The symbols are private, we don't actually need them here, so just
override with an empty implementation */
void doSetImage(const Vector2i&, const ImageView2D&) override {}
void doSetProcessedImage(const Vector2i&, const ImageView2D&) override {}
Image3D doProcessedImage() override {
CORRADE_INTERNAL_ASSERT_UNREACHABLE();
}
} cache{PixelFormat::R8Unorm, {1024, 2048}, PixelFormat::RGBA8Unorm, {128, 256}};
MAGNUM_VERIFY_NO_GL_ERROR();

Loading…
Cancel
Save