Moved osgText::GlyphTechnique::Features enum to osgText::ShaderTechinque enum to make it's roll clearer

This commit is contained in:
Robert Osfield 2017-10-20 17:03:25 +01:00
parent 6b75439ae4
commit 97aeb16551
8 changed files with 40 additions and 39 deletions

View File

@ -68,7 +68,7 @@ struct TextSettings
minFilter(osg::Texture::LINEAR_MIPMAP_LINEAR), minFilter(osg::Texture::LINEAR_MIPMAP_LINEAR),
magFilter(osg::Texture::LINEAR), magFilter(osg::Texture::LINEAR),
maxAnisotropy(16.0f), maxAnisotropy(16.0f),
glyphTextureFeatures(osgText::GlyphTexture::GREYSCALE), shaderTechnique(osgText::GREYSCALE),
textColor(1.0f, 1.0f, 1.0f, 1.0f), textColor(1.0f, 1.0f, 1.0f, 1.0f),
backdropType(osgText::Text::NONE), backdropType(osgText::Text::NONE),
backdropOffset(0.07f, 0.07f), backdropOffset(0.07f, 0.07f),
@ -102,9 +102,9 @@ struct TextSettings
sizes.push_back(128); sizes.push_back(128);
} }
if (arguments.read("--GREYSCALE")) { glyphTextureFeatures = osgText::GlyphTexture::GREYSCALE; } if (arguments.read("--GREYSCALE")) { shaderTechnique = osgText::GREYSCALE; }
if (arguments.read("--SIGNED_DISTANCE_FIELD")) { glyphTextureFeatures = osgText::GlyphTexture::SIGNED_DISTANCE_FIELD; } if (arguments.read("--SIGNED_DISTANCE_FIELD")) { shaderTechnique = osgText::SIGNED_DISTANCE_FIELD; }
if (arguments.read("--ALL_FEATURES")) { glyphTextureFeatures = osgText::GlyphTexture::ALL_FEATURES; } if (arguments.read("--ALL_FEATURES")) { shaderTechnique = osgText::ALL_FEATURES; }
if (arguments.read("--font",fontFilename)) {} if (arguments.read("--font",fontFilename)) {}
@ -153,7 +153,7 @@ struct TextSettings
font->setMinFilterHint(minFilter); font->setMinFilterHint(minFilter);
font->setMagFilterHint(magFilter); font->setMagFilterHint(magFilter);
font->setMaxAnisotropy(maxAnisotropy); font->setMaxAnisotropy(maxAnisotropy);
font->setGyphTextureFeatures(glyphTextureFeatures); font->setShaderTechnique(shaderTechnique);
text.setColor(textColor); text.setColor(textColor);
text.setBackdropType(backdropType); text.setBackdropType(backdropType);
@ -168,7 +168,7 @@ struct TextSettings
osg::Texture::FilterMode minFilter; osg::Texture::FilterMode minFilter;
osg::Texture::FilterMode magFilter; osg::Texture::FilterMode magFilter;
float maxAnisotropy; float maxAnisotropy;
osgText::GlyphTexture::Features glyphTextureFeatures; osgText::ShaderTechnique shaderTechnique;
osg::Vec4 textColor; osg::Vec4 textColor;
osgText::Text::BackdropType backdropType; 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()->setAttribute(program.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
root->getOrCreateStateSet()->addUniform(new osg::Uniform("glyphTexture", 0)); 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<osg::Geode> right_geode = new osg::Geode; osg::ref_ptr<osg::Geode> right_geode = new osg::Geode;
right_geode->setNodeMask(0x2); right_geode->setNodeMask(0x2);
settings.glyphTextureFeatures = osgText::GlyphTexture::GREYSCALE; settings.shaderTechnique = osgText::GREYSCALE;
pos.set(0.0f, 0.0f, 0.0f); pos.set(0.0f, 0.0f, 0.0f);

View File

@ -153,7 +153,7 @@ osg:: Node* createTextBelow(const osg::BoundingBox& bb, const std::string& label
if (s_useSDF) if (s_useSDF)
{ {
text->getFont()->setGyphTextureFeatures(osgText::GlyphTexture::ALL_FEATURES); text->getFont()->setShaderTechnique(osgText::ALL_FEATURES);
} }
text->setAlignment(osgText::Text::CENTER_CENTER); text->setAlignment(osgText::Text::CENTER_CENTER);
@ -186,7 +186,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label,
if (s_useSDF) if (s_useSDF)
{ {
text->getFont()->setGyphTextureFeatures(osgText::GlyphTexture::ALL_FEATURES); text->getFont()->setShaderTechnique(osgText::ALL_FEATURES);
} }
text->setAlignment(osgText::Text::RIGHT_CENTER); text->setAlignment(osgText::Text::RIGHT_CENTER);

View File

@ -108,8 +108,8 @@ public:
virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; } virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; }
void setGyphTextureFeatures(GlyphTexture::Features features) { _glyphTextureFeatures = features; } void setShaderTechnique(ShaderTechnique features) { _shaderTechnique = features; }
GlyphTexture::Features getGlyphTextureFeatures() const { return _glyphTextureFeatures; } ShaderTechnique getShaderTechnique() const { return _shaderTechnique; }
/** Set the size of texture to create to store the glyph images when rendering. /** Set the size of texture to create to store the glyph images when rendering.
@ -186,7 +186,7 @@ protected:
// current active size of font // current active size of font
FontResolution _fontSize; FontResolution _fontSize;
GlyphTexture::Features _glyphTextureFeatures; ShaderTechnique _shaderTechnique;
unsigned int _textureWidthHint; unsigned int _textureWidthHint;
unsigned int _textureHeightHint; unsigned int _textureHeightHint;

View File

@ -38,6 +38,13 @@ class Glyph3D;
class GlyphGeometry; class GlyphGeometry;
class GlyphTexture; class GlyphTexture;
enum ShaderTechnique
{
GREYSCALE = 0x1,
SIGNED_DISTANCE_FIELD = 0x2,
ALL_FEATURES = GREYSCALE | SIGNED_DISTANCE_FIELD
};
class OSGTEXT_EXPORT Glyph : public osg::Image class OSGTEXT_EXPORT Glyph : public osg::Image
{ {
public: public:
@ -251,15 +258,9 @@ public:
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
virtual int compare(const osg::StateAttribute& rhs) const; virtual int compare(const osg::StateAttribute& rhs) const;
enum Features void setShaderTechnique(ShaderTechnique technique) { _shaderTechnique = technique; }
{
GREYSCALE,
SIGNED_DISTANCE_FIELD,
ALL_FEATURES
};
void setGlyphTextureFeatures(Features features) { _glyphTextureFeatures = features; } ShaderTechnique getShaderTechnique() const { return _shaderTechnique; }
Features getGlyphTextureFeatures() const { return _glyphTextureFeatures; }
int getEffectMargin(const Glyph* glyph); int getEffectMargin(const Glyph* glyph);
@ -284,7 +285,7 @@ protected:
void copyGlyphImage(Glyph* glyph); void copyGlyphImage(Glyph* glyph);
Features _glyphTextureFeatures; ShaderTechnique _shaderTechnique;
int _usedY; int _usedY;
int _partUsedX; int _partUsedX;

View File

@ -32,7 +32,7 @@ DefaultFont::DefaultFont()
char *ptr; char *ptr;
if ((ptr = getenv("OSG_SDF_TEXT")) != 0) if ((ptr = getenv("OSG_SDF_TEXT")) != 0)
{ {
_glyphTextureFeatures = osgText::GlyphTexture::ALL_FEATURES; _shaderTechnique = osgText::ALL_FEATURES;
} }
constructGlyphs(); constructGlyphs();

View File

@ -225,9 +225,9 @@ osg::ref_ptr<Font> osgText::readRefFontStream(std::istream& stream, const osgDB:
Font::Font(FontImplementation* implementation): Font::Font(FontImplementation* implementation):
osg::Object(true), osg::Object(true),
#if 0 #if 0
_glyphTextureFeatures(GlyphTexture::ALL_FEATURES), _shaderTechnique(ALL_FEATURES),
#else #else
_glyphTextureFeatures(GlyphTexture::GREYSCALE), _shaderTechnique(GREYSCALE),
#endif #endif
_textureWidthHint(1024), _textureWidthHint(1024),
_textureHeightHint(1024), _textureHeightHint(1024),
@ -250,11 +250,11 @@ Font::Font(FontImplementation* implementation):
if ((ptr = getenv("OSG_SDF_TEXT")) != 0) if ((ptr = getenv("OSG_SDF_TEXT")) != 0)
{ {
_glyphTextureFeatures = GlyphTexture::ALL_FEATURES; _shaderTechnique = ALL_FEATURES;
} }
else if ((ptr = getenv("OSG_GREYSCALE_TEXT")) != 0) 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 "<<numberOfTexturesAllocated<<std::endl; OSG_INFO<< " Font " << this<< ", numberOfTexturesAllocated "<<numberOfTexturesAllocated<<std::endl;
// reserve enough space for the glyphs. // reserve enough space for the glyphs.
glyphTexture->setGlyphTextureFeatures(_glyphTextureFeatures); glyphTexture->setShaderTechnique(_shaderTechnique);
glyphTexture->setTextureSize(_textureWidthHint,_textureHeightHint); glyphTexture->setTextureSize(_textureWidthHint,_textureHeightHint);
glyphTexture->setFilter(osg::Texture::MIN_FILTER,_minFilterHint); glyphTexture->setFilter(osg::Texture::MIN_FILTER,_minFilterHint);
glyphTexture->setFilter(osg::Texture::MAG_FILTER,_magFilterHint); glyphTexture->setFilter(osg::Texture::MAG_FILTER,_magFilterHint);

View File

@ -75,7 +75,7 @@ int GlyphTexture::compare(const osg::StateAttribute& rhs) const
int GlyphTexture::getEffectMargin(const Glyph* glyph) 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); else return osg::maximum(glyph->getFontResolution().second/6, 2u);
} }
@ -173,7 +173,7 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph)
{ {
_image->dirty(); _image->dirty();
if (_glyphTextureFeatures==GREYSCALE) if (_shaderTechnique==GREYSCALE)
{ {
// OSG_NOTICE<<"GlyphTexture::copyGlyphImage() greyscale copying. glyphTexture="<<this<<", glyph="<<glyph->getGlyphCode()<<std::endl; // OSG_NOTICE<<"GlyphTexture::copyGlyphImage() greyscale copying. glyphTexture="<<this<<", glyph="<<glyph->getGlyphCode()<<std::endl;
// make sure the glyph image settings and the target image are consisent before copying. // make sure the glyph image settings and the target image are consisent before copying.
@ -414,8 +414,8 @@ osg::Image* GlyphTexture::createImage()
_image = new osg::Image; _image = new osg::Image;
GLenum imageFormat = (_glyphTextureFeatures==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_FORMAT : OSGTEXT_GLYPH_SDF_FORMAT; GLenum imageFormat = (_shaderTechnique==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_FORMAT : OSGTEXT_GLYPH_SDF_FORMAT;
GLenum internalFormat = (_glyphTextureFeatures==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_INTERNALFORMAT : OSGTEXT_GLYPH_SDF_INTERNALFORMAT; GLenum internalFormat = (_shaderTechnique==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_INTERNALFORMAT : OSGTEXT_GLYPH_SDF_INTERNALFORMAT;
_image->allocateImage(getTextureWidth(), getTextureHeight(), 1, imageFormat, GL_UNSIGNED_BYTE); _image->allocateImage(getTextureWidth(), getTextureHeight(), 1, imageFormat, GL_UNSIGNED_BYTE);
_image->setInternalTextureFormat(internalFormat); _image->setInternalTextureFormat(internalFormat);

View File

@ -116,7 +116,7 @@ osg::StateSet* Text::createStateSet()
} }
} }
if (activeFont->getGlyphTextureFeatures()!=GlyphTexture::GREYSCALE) if (activeFont->getShaderTechnique()!=GREYSCALE)
{ {
ss<<std::fixed<<std::setprecision(1); ss<<std::fixed<<std::setprecision(1);
@ -172,12 +172,12 @@ osg::StateSet* Text::createStateSet()
stateset->setMode(GL_BLEND, osg::StateAttribute::ON); stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
OSG_NOTICE<<"Text::createStateSet() activeFont->getGlyphTextureFeatures()="<<activeFont->getGlyphTextureFeatures()<<std::endl; OSG_NOTICE<<"Text::createStateSet() activeFont->getShaderTechnique()="<<activeFont->getShaderTechnique()<<std::endl;
#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) #if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
osg::DisplaySettings::ShaderHint shaderHint = osg::DisplaySettings::instance()->getShaderHint(); osg::DisplaySettings::ShaderHint shaderHint = osg::DisplaySettings::instance()->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"<<std::endl; OSG_NOTICE<<"Font::Font() Fixed function pipeline"<<std::endl;
@ -199,7 +199,7 @@ osg::StateSet* Text::createStateSet()
program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX, "shaders/text.vert", text_vert)); program->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"<<std::endl; OSG_NOTICE<<"Using shaders/text_greyscale.frag"<<std::endl;