diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 393aa7415..0609cf0c6 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -325,6 +325,10 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced void setShaderHint(ShaderHint hint, bool setShaderValues=true); ShaderHint getShaderHint() const { return _shaderHint; } + /** Set the TextShaderTechnique that is used in the Text default constructor to choose which osgText::ShaderTechnique to use.*/ + void setTextShaderTechnique(const std::string& str) { _textShaderTechnique = str; } + const std::string& getTextShaderTechnique() const { return _textShaderTechnique; } + void setKeystoneHint(bool enabled) { _keystoneHint = enabled; } bool getKeystoneHint() const { return _keystoneHint; } @@ -423,6 +427,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced VertexBufferHint _vertexBufferHint; ShaderHint _shaderHint; + std::string _textShaderTechnique; bool _keystoneHint; FileNames _keystoneFileNames; diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 8346d11ed..5e7259956 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -385,6 +385,9 @@ static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_ static ApplicationUsageProxy DisplaySetting_e32(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_VERTEX_BUFFER_HINT ", "Set the hint to what backend osg::Geometry implementation to use. NO_PREFERENCE | VERTEX_BUFFER_OBJECT | VERTEX_ARRAY_OBJECT"); +static ApplicationUsageProxy DisplaySetting_e33(ApplicationUsage::ENVIRONMENTAL_VARIABLE, + "OSG_TEXT_SHADER_TECHNIQUE ", + "Set the defafult osgText::ShaderTechnique. ALL_FEATURES | ALL | GREYSCALE | SIGNED_DISTANCE_FIELD | SDF | NO_TEXT_SHADER | NONE"); void DisplaySettings::readEnvironmentalVariables() { @@ -740,6 +743,10 @@ void DisplaySettings::readEnvironmentalVariables() } } + if ((ptr = getenv("OSG_TEXT_SHADER_TECHNIQUE")) != 0) + { + setTextShaderTechnique(ptr); + } if( (ptr = getenv("OSG_KEYSTONE")) != 0) { diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 0bd1efade..cfc7cf969 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -28,6 +28,8 @@ #include #include +#define DEBUG_MESSAGE_LEVEL osg::INFO +#define DEBUG_MESSAGE osg::notify(DEBUG_MESSAGE_LEVEL) using namespace osg; using namespace osgText; @@ -47,17 +49,15 @@ Text::Text(): { _supportsVertexBufferObjects = true; - char* ptr = 0; - if ((ptr = getenv("OSG_TEXT_SHADER_TECHNIQUE")) != 0) + const std::string& str = osg::DisplaySettings::instance()->getTextShaderTechnique(); + if (!str.empty()) { - if (strcmp(ptr,"ALL_FEATURES")==0) _shaderTechnique = ALL_FEATURES; - else if (strcmp(ptr,"GREYSCALE")==0) _shaderTechnique = GREYSCALE; - else if (strcmp(ptr,"SIGNED_DISTANCE_FIELD")==0 || strcmp(ptr,"SDF")==0) _shaderTechnique = SIGNED_DISTANCE_FIELD; - else if (strcmp(ptr,"NO_TEXT_SHADER")==0 || strcmp(ptr,"NONE")==0) _shaderTechnique = NO_TEXT_SHADER; + if (str=="ALL_FEATURES" || str=="ALL") _shaderTechnique = ALL_FEATURES; + else if (str=="GREYSCALE") _shaderTechnique = GREYSCALE; + else if (str=="SIGNED_DISTANCE_FIELD" || str=="SDF") _shaderTechnique = SIGNED_DISTANCE_FIELD; + else if (str=="NO_TEXT_SHADER" || str=="NONE") _shaderTechnique = NO_TEXT_SHADER; } - OSG_NOTICE<<"Text::Text() "<<_shaderTechnique< stateset = new osg::StateSet; @@ -198,14 +211,11 @@ osg::StateSet* Text::createStateSet() stateset->setMode(GL_BLEND, osg::StateAttribute::ON); - OSG_INFO<<"Text::createStateSet() ShaderTechnique="<<_shaderTechnique<getShaderHint(); if (_shaderTechnique==NO_TEXT_SHADER && shaderHint==osg::DisplaySettings::SHADER_NONE) { - OSG_INFO<<"Font::Font() Fixed function pipeline"<setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON); return stateset.release(); @@ -219,14 +229,14 @@ osg::StateSet* Text::createStateSet() stateset->setAttributeAndModes(program.get()); { - OSG_INFO<<"Using shaders/text.vert"<addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX, "shaders/text.vert", text_vert)); } { - OSG_INFO<<"Using shaders/text.frag"<addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::FRAGMENT, "shaders/text.frag", text_frag));