From 97aeb16551659c18f71987de78d5faa72718f474 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Oct 2017 17:03:25 +0100 Subject: [PATCH] Moved osgText::GlyphTechnique::Features enum to osgText::ShaderTechinque enum to make it's roll clearer --- examples/osgfont/osgfont.cpp | 16 ++++++++-------- examples/osglogo/osglogo.cpp | 4 ++-- include/osgText/Font | 6 +++--- include/osgText/Glyph | 25 +++++++++++++------------ src/osgText/DefaultFont.cpp | 2 +- src/osgText/Font.cpp | 10 +++++----- src/osgText/Glyph.cpp | 8 ++++---- src/osgText/Text.cpp | 8 ++++---- 8 files changed, 40 insertions(+), 39 deletions(-) diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index f65e607fc..e16ab4079 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -68,7 +68,7 @@ struct TextSettings minFilter(osg::Texture::LINEAR_MIPMAP_LINEAR), magFilter(osg::Texture::LINEAR), maxAnisotropy(16.0f), - glyphTextureFeatures(osgText::GlyphTexture::GREYSCALE), + shaderTechnique(osgText::GREYSCALE), textColor(1.0f, 1.0f, 1.0f, 1.0f), backdropType(osgText::Text::NONE), backdropOffset(0.07f, 0.07f), @@ -102,9 +102,9 @@ struct TextSettings sizes.push_back(128); } - if (arguments.read("--GREYSCALE")) { glyphTextureFeatures = osgText::GlyphTexture::GREYSCALE; } - if (arguments.read("--SIGNED_DISTANCE_FIELD")) { glyphTextureFeatures = osgText::GlyphTexture::SIGNED_DISTANCE_FIELD; } - if (arguments.read("--ALL_FEATURES")) { glyphTextureFeatures = osgText::GlyphTexture::ALL_FEATURES; } + if (arguments.read("--GREYSCALE")) { shaderTechnique = osgText::GREYSCALE; } + if (arguments.read("--SIGNED_DISTANCE_FIELD")) { shaderTechnique = osgText::SIGNED_DISTANCE_FIELD; } + if (arguments.read("--ALL_FEATURES")) { shaderTechnique = osgText::ALL_FEATURES; } if (arguments.read("--font",fontFilename)) {} @@ -153,7 +153,7 @@ struct TextSettings font->setMinFilterHint(minFilter); font->setMagFilterHint(magFilter); font->setMaxAnisotropy(maxAnisotropy); - font->setGyphTextureFeatures(glyphTextureFeatures); + font->setShaderTechnique(shaderTechnique); text.setColor(textColor); text.setBackdropType(backdropType); @@ -168,7 +168,7 @@ struct TextSettings osg::Texture::FilterMode minFilter; osg::Texture::FilterMode magFilter; float maxAnisotropy; - osgText::GlyphTexture::Features glyphTextureFeatures; + osgText::ShaderTechnique shaderTechnique; osg::Vec4 textColor; osgText::Text::BackdropType backdropType; @@ -345,7 +345,7 @@ int main(int argc, char** argv) root->getOrCreateStateSet()->setAttribute(program.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); root->getOrCreateStateSet()->addUniform(new osg::Uniform("glyphTexture", 0)); - settings.glyphTextureFeatures = osgText::GlyphTexture::ALL_FEATURES; + settings.shaderTechnique = osgText::ALL_FEATURES; } @@ -396,7 +396,7 @@ int main(int argc, char** argv) osg::ref_ptr right_geode = new osg::Geode; right_geode->setNodeMask(0x2); - settings.glyphTextureFeatures = osgText::GlyphTexture::GREYSCALE; + settings.shaderTechnique = osgText::GREYSCALE; pos.set(0.0f, 0.0f, 0.0f); diff --git a/examples/osglogo/osglogo.cpp b/examples/osglogo/osglogo.cpp index fe8a12475..c419103cb 100644 --- a/examples/osglogo/osglogo.cpp +++ b/examples/osglogo/osglogo.cpp @@ -153,7 +153,7 @@ osg:: Node* createTextBelow(const osg::BoundingBox& bb, const std::string& label if (s_useSDF) { - text->getFont()->setGyphTextureFeatures(osgText::GlyphTexture::ALL_FEATURES); + text->getFont()->setShaderTechnique(osgText::ALL_FEATURES); } text->setAlignment(osgText::Text::CENTER_CENTER); @@ -186,7 +186,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label, if (s_useSDF) { - text->getFont()->setGyphTextureFeatures(osgText::GlyphTexture::ALL_FEATURES); + text->getFont()->setShaderTechnique(osgText::ALL_FEATURES); } text->setAlignment(osgText::Text::RIGHT_CENTER); diff --git a/include/osgText/Font b/include/osgText/Font index 0af593b91..f8fcc89b0 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -108,8 +108,8 @@ public: virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; } - void setGyphTextureFeatures(GlyphTexture::Features features) { _glyphTextureFeatures = features; } - GlyphTexture::Features getGlyphTextureFeatures() const { return _glyphTextureFeatures; } + void setShaderTechnique(ShaderTechnique features) { _shaderTechnique = features; } + ShaderTechnique getShaderTechnique() const { return _shaderTechnique; } /** Set the size of texture to create to store the glyph images when rendering. @@ -186,7 +186,7 @@ protected: // current active size of font FontResolution _fontSize; - GlyphTexture::Features _glyphTextureFeatures; + ShaderTechnique _shaderTechnique; unsigned int _textureWidthHint; unsigned int _textureHeightHint; diff --git a/include/osgText/Glyph b/include/osgText/Glyph index adba880bc..c7d717f25 100644 --- a/include/osgText/Glyph +++ b/include/osgText/Glyph @@ -38,6 +38,13 @@ class Glyph3D; class GlyphGeometry; class GlyphTexture; +enum ShaderTechnique +{ + GREYSCALE = 0x1, + SIGNED_DISTANCE_FIELD = 0x2, + ALL_FEATURES = GREYSCALE | SIGNED_DISTANCE_FIELD +}; + class OSGTEXT_EXPORT Glyph : public osg::Image { public: @@ -251,15 +258,9 @@ public: /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ virtual int compare(const osg::StateAttribute& rhs) const; - enum Features - { - GREYSCALE, - SIGNED_DISTANCE_FIELD, - ALL_FEATURES - }; + void setShaderTechnique(ShaderTechnique technique) { _shaderTechnique = technique; } - void setGlyphTextureFeatures(Features features) { _glyphTextureFeatures = features; } - Features getGlyphTextureFeatures() const { return _glyphTextureFeatures; } + ShaderTechnique getShaderTechnique() const { return _shaderTechnique; } int getEffectMargin(const Glyph* glyph); @@ -284,11 +285,11 @@ protected: void copyGlyphImage(Glyph* glyph); - Features _glyphTextureFeatures; + ShaderTechnique _shaderTechnique; - int _usedY; - int _partUsedX; - int _partUsedY; + int _usedY; + int _partUsedX; + int _partUsedY; typedef std::vector< osg::ref_ptr > GlyphRefList; typedef std::vector< const Glyph* > GlyphPtrList; diff --git a/src/osgText/DefaultFont.cpp b/src/osgText/DefaultFont.cpp index 94aac9be3..ac1a5d8ba 100644 --- a/src/osgText/DefaultFont.cpp +++ b/src/osgText/DefaultFont.cpp @@ -32,7 +32,7 @@ DefaultFont::DefaultFont() char *ptr; if ((ptr = getenv("OSG_SDF_TEXT")) != 0) { - _glyphTextureFeatures = osgText::GlyphTexture::ALL_FEATURES; + _shaderTechnique = osgText::ALL_FEATURES; } constructGlyphs(); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 3e3402b53..bfe67cd74 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -225,9 +225,9 @@ osg::ref_ptr osgText::readRefFontStream(std::istream& stream, const osgDB: Font::Font(FontImplementation* implementation): osg::Object(true), #if 0 - _glyphTextureFeatures(GlyphTexture::ALL_FEATURES), + _shaderTechnique(ALL_FEATURES), #else - _glyphTextureFeatures(GlyphTexture::GREYSCALE), + _shaderTechnique(GREYSCALE), #endif _textureWidthHint(1024), _textureHeightHint(1024), @@ -250,11 +250,11 @@ Font::Font(FontImplementation* implementation): if ((ptr = getenv("OSG_SDF_TEXT")) != 0) { - _glyphTextureFeatures = GlyphTexture::ALL_FEATURES; + _shaderTechnique = ALL_FEATURES; } else if ((ptr = getenv("OSG_GREYSCALE_TEXT")) != 0) { - _glyphTextureFeatures = GlyphTexture::GREYSCALE; + _shaderTechnique = GREYSCALE; } } @@ -485,7 +485,7 @@ void Font::addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* OSG_INFO<< " Font " << this<< ", numberOfTexturesAllocated "<setGlyphTextureFeatures(_glyphTextureFeatures); + glyphTexture->setShaderTechnique(_shaderTechnique); glyphTexture->setTextureSize(_textureWidthHint,_textureHeightHint); glyphTexture->setFilter(osg::Texture::MIN_FILTER,_minFilterHint); glyphTexture->setFilter(osg::Texture::MAG_FILTER,_magFilterHint); diff --git a/src/osgText/Glyph.cpp b/src/osgText/Glyph.cpp index 114f6649a..d7f2395fb 100644 --- a/src/osgText/Glyph.cpp +++ b/src/osgText/Glyph.cpp @@ -75,7 +75,7 @@ int GlyphTexture::compare(const osg::StateAttribute& rhs) const int GlyphTexture::getEffectMargin(const Glyph* glyph) { - if (_glyphTextureFeatures==GREYSCALE) return 0; + if (_shaderTechnique==GREYSCALE) return 0; else return osg::maximum(glyph->getFontResolution().second/6, 2u); } @@ -173,7 +173,7 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) { _image->dirty(); - if (_glyphTextureFeatures==GREYSCALE) + if (_shaderTechnique==GREYSCALE) { // OSG_NOTICE<<"GlyphTexture::copyGlyphImage() greyscale copying. glyphTexture="<getGlyphTextureFeatures()="<getGlyphTextureFeatures()<getShaderTechnique()="<getShaderTechnique()<getShaderHint(); - if (activeFont->getGlyphTextureFeatures()==GlyphTexture::GREYSCALE && shaderHint==osg::DisplaySettings::SHADER_NONE) + if (activeFont->getShaderTechnique()==GREYSCALE && shaderHint==osg::DisplaySettings::SHADER_NONE) { OSG_NOTICE<<"Font::Font() Fixed function pipeline"<addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX, "shaders/text.vert", text_vert)); } - if (activeFont->getGlyphTextureFeatures()==GlyphTexture::GREYSCALE) + if (activeFont->getShaderTechnique()==GREYSCALE) { OSG_NOTICE<<"Using shaders/text_greyscale.frag"<