From 24bec09b9e56fe87044ffae1f0203e988110e8a2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 13 Oct 2017 13:01:57 +0100 Subject: [PATCH] Removed the glyph image outline support as it's no longer required. --- examples/osgfont/osgfont.cpp | 1 - include/osgText/Glyph | 1 - src/osgText/Glyph.cpp | 84 ++---------------------------------- 3 files changed, 4 insertions(+), 82 deletions(-) diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index b20ad43e1..f65e607fc 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -103,7 +103,6 @@ struct TextSettings } if (arguments.read("--GREYSCALE")) { glyphTextureFeatures = osgText::GlyphTexture::GREYSCALE; } - if (arguments.read("--OUTLINE_GREYSCALE")) { glyphTextureFeatures = osgText::GlyphTexture::OUTLINE_GREYSCALE; } if (arguments.read("--SIGNED_DISTANCE_FIELD")) { glyphTextureFeatures = osgText::GlyphTexture::SIGNED_DISTANCE_FIELD; } if (arguments.read("--ALL_FEATURES")) { glyphTextureFeatures = osgText::GlyphTexture::ALL_FEATURES; } diff --git a/include/osgText/Glyph b/include/osgText/Glyph index fb842eb8b..5dcfd12b3 100644 --- a/include/osgText/Glyph +++ b/include/osgText/Glyph @@ -263,7 +263,6 @@ public: enum Features { GREYSCALE, - OUTLINE_GREYSCALE, SIGNED_DISTANCE_FIELD, ALL_FEATURES }; diff --git a/src/osgText/Glyph.cpp b/src/osgText/Glyph.cpp index e8a11ea87..8ca21f5bc 100644 --- a/src/osgText/Glyph.cpp +++ b/src/osgText/Glyph.cpp @@ -32,7 +32,7 @@ using namespace std; #define TEXTURE_IMAGE_NUM_CHANNELS 1 #define TEXTURE_IMAGE_FORMAT OSGTEXT_GLYPH_FORMAT #else - #define TEXTURE_IMAGE_NUM_CHANNELS 4 + #define TEXTURE_IMAGE_NUM_CHANNELS 2 #define TEXTURE_IMAGE_FORMAT GL_RGBA #endif @@ -60,9 +60,7 @@ int GlyphTexture::compare(const osg::StateAttribute& rhs) const int GlyphTexture::getEffectMargin(const Glyph* glyph) { if (_glyphTextureFeatures==GREYSCALE) return 0; -// else return glyph->getFontResolution().second/4; else return osg::maximum(glyph->getFontResolution().second/6, 2u); -// else return osg::maximum(glyph->getFontResolution().second/8,1u); } int GlyphTexture::getTexelMargin(const Glyph* glyph) @@ -195,10 +193,6 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) if ((lower+glyph->getTexturePositionY())<0) lower = -glyph->getTexturePositionY(); if ((upper+glyph->getTexturePositionY())>=dest_rows) upper = dest_rows-glyph->getTexturePositionY()-1; - bool use_SDF_for_Outline = true; - - float outer_outline_distance = float(glyph->getFontResolution().first)*0.1f; - float inner_outline_distance = outer_outline_distance*0.5f; unsigned char full_on = 255; unsigned char mid_point = full_on/2; @@ -213,17 +207,11 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) unsigned char center_value = 0; if (dr>=0 && dr=0 && dc0 && center_value=mid_point_f) { min_distance = center_value_f-mid_point_f; @@ -263,9 +251,6 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) else local_distance += (local_value_f - mid_point_f)*local_multiplier; if (local_distanceinner_max_value && local_distance<=inner_outline_distance) inner_max_value = local_value; - if (local_value>outer_max_value && local_distance<=outer_outline_distance) outer_max_value = local_value; } } @@ -291,9 +276,6 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) else local_distance += (local_value_f - mid_point_f)*local_multiplier; if (local_distanceinner_max_value && local_distance<=inner_outline_distance) inner_max_value = local_value; - if (local_value>outer_max_value && local_distance<=outer_outline_distance) outer_max_value = local_value; } } @@ -320,9 +302,6 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) else local_distance += (local_value_f - mid_point_f)*local_multiplier; if (local_distanceinner_max_value && local_distance<=inner_outline_distance) inner_max_value = local_value; - if (local_value>outer_max_value && local_distance<=outer_outline_distance) outer_max_value = local_value; } } @@ -348,9 +327,6 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) else local_distance += (local_value_f - mid_point_f)*local_multiplier; if (local_distanceinner_max_value && local_distance<=inner_outline_distance) inner_max_value = local_value; - if (local_value>outer_max_value && local_distance<=outer_outline_distance) outer_max_value = local_value; } } } @@ -368,63 +344,11 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) unsigned char* dest_ptr = dest_data + (dr*dest_columns + dc)*num_channels; - if (num_channels==4) + if (num_channels==2) { // signed distance field value *(dest_ptr++) = value; - float outline_distance = inner_outline_distance; - - // compute the alpha value of outline, one texel thick - unsigned char outline = 0; - - if (use_SDF_for_Outline) - { - if (center_value<255) - { - float inner_outline = outline_distance-1.0f; - if (min_distancecenter_value) - { - outline -= center_value; - } - } - else - { - outline = inner_max_value-center_value; - } - - *(dest_ptr++) = outline; - - - outline_distance = outer_outline_distance; - - // compute the alpha value of outline, one texel thick - outline = 0; - if (use_SDF_for_Outline) - { - if (center_value<255) - { - float inner_outline = outline_distance-1.0f; - if (min_distancecenter_value) - { - outline -= center_value; - } - } - else - { - outline = outer_max_value-center_value; - } - - *(dest_ptr++) = outline; - // original alpha value from glyph image *(dest_ptr) = center_value; } @@ -468,9 +392,9 @@ osg::Image* GlyphTexture::createImage() _image = new osg::Image; #if defined(OSG_GL3_AVAILABLE) && !defined(OSG_GL2_AVAILABLE) && !defined(OSG_GL1_AVAILABLE) - GLenum imageFormat = (_glyphTextureFeatures==GREYSCALE) ? GL_RED : GL_RGBA; + GLenum imageFormat = (_glyphTextureFeatures==GREYSCALE) ? GL_RED : GL_RG; #else - GLenum imageFormat = (_glyphTextureFeatures==GREYSCALE) ? GL_ALPHA : GL_RGBA; + GLenum imageFormat = (_glyphTextureFeatures==GREYSCALE) ? GL_ALPHA : GL_LUMINANCE_ALPHA; #endif _image->allocateImage(getTextureWidth(), getTextureHeight(), 1, imageFormat, GL_UNSIGNED_BYTE);