From 0d5a42f635d7e5b433995e9b86e91d87135a7e6e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 12 Sep 2017 19:13:01 +0100 Subject: [PATCH] Added setting of the Text::BackdropImplementation type to USE_SHADERS when setting up shaders --- examples/osgfont/osgfont.cpp | 10 ++++- src/osgText/Text.cpp | 74 ++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index 2d37f4862..3c3fd6128 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -147,12 +147,20 @@ struct TextSettings font->setMaxAnisotropy(maxAnisotropy); font->setGlyphInterval(glyphInterval); font->setGyphTextureFeatures(glyphTextureFeatures); - text.setFont(font.get()); + // text.setFont(font.get()); text.setColor(textColor); text.setBackdropType(backdropType); text.setBackdropOffset(backdropOffset.x(), backdropOffset.y()); text.setBackdropColor(backdropColor); + + if (glyphTextureFeatures==osgText::GlyphTexture::ALL_FEATURES) + { + text.setBackdropImplementation(osgText::Text::USE_SHADERS); + } + + text.setFont(font.get()); + } std::string fontFilename; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index f4cb94bd7..97e7c2c70 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -149,6 +149,8 @@ Text::~Text() { } +#include + osg::StateSet* Text::createStateSet() { Font* activeFont = getActiveFont(); @@ -156,13 +158,79 @@ osg::StateSet* Text::createStateSet() Font::StateSets& statesets = activeFont->getCachedStateSets(); - if (!statesets.empty()) + osg::StateSet::DefineList defineList; + if (_backdropType!=NONE && _backdropImplementation==USE_SHADERS) { - return statesets.front().get(); + std::stringstream ss; + + ss.str(""); + ss << "vec4("<<_backdropColor.r()<<", "<<_backdropColor.g()<<", "<<_backdropColor.b()<<", "<<_backdropColor.a()<<")"; + + defineList["BACKDROP_COLOR"] = osg::StateSet::DefinePair(ss.str(), osg::StateAttribute::ON); + + if (_backdropType==OUTLINE) + { + ss.str(""); + ss <<_backdropHorizontalOffset; + defineList["OUTLINE"] = osg::StateSet::DefinePair(ss.str(), osg::StateAttribute::ON); + } + else + { + osg::Vec2 offset(_backdropHorizontalOffset, _backdropVerticalOffset); + switch(_backdropType) + { + case(DROP_SHADOW_BOTTOM_RIGHT) : offset.set(_backdropHorizontalOffset, -_backdropVerticalOffset); break; + case(DROP_SHADOW_CENTER_RIGHT) : offset.set(_backdropHorizontalOffset, 0.0f); break; + case(DROP_SHADOW_TOP_RIGHT) : offset.set(_backdropHorizontalOffset, _backdropVerticalOffset); break; + case(DROP_SHADOW_BOTTOM_CENTER) : offset.set(0.0f, -_backdropVerticalOffset); break; + case(DROP_SHADOW_TOP_CENTER) : offset.set(0.0f, _backdropVerticalOffset); break; + case(DROP_SHADOW_BOTTOM_LEFT) : offset.set(-_backdropHorizontalOffset, -_backdropVerticalOffset); break; + case(DROP_SHADOW_CENTER_LEFT) : offset.set(-_backdropHorizontalOffset, 0.0f); break; + case(DROP_SHADOW_TOP_LEFT) : offset.set(-_backdropHorizontalOffset, _backdropVerticalOffset); break; + default : break; + } + + ss.str(""); + ss << "vec2("<first<<"] = "<second.first<getDefineList()==defineList) + { + // OSG_NOTICE<<"Text::createStateSet() : Matched DefineList, return StateSet "<get()<get(); + } + else + { + } + } + } + + // OSG_NOTICE<<"Text::createStateSet() : Not Matched DefineList, creating new StateSet"< stateset = new osg::StateSet; + stateset->setDefineList(defineList); + statesets.push_back(stateset.get()); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); @@ -1281,7 +1349,7 @@ void Text::drawImplementationSinglePass(osg::State& state, const osg::Vec4& colo } else { - OSG_NOTICE<<"Using shaders for backdrop"<