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),
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<osg::Geode> 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);

View File

@ -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);

View File

@ -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;

View File

@ -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<Glyph> > GlyphRefList;
typedef std::vector< const Glyph* > GlyphPtrList;

View File

@ -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();

View File

@ -225,9 +225,9 @@ osg::ref_ptr<Font> 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 "<<numberOfTexturesAllocated<<std::endl;
// reserve enough space for the glyphs.
glyphTexture->setGlyphTextureFeatures(_glyphTextureFeatures);
glyphTexture->setShaderTechnique(_shaderTechnique);
glyphTexture->setTextureSize(_textureWidthHint,_textureHeightHint);
glyphTexture->setFilter(osg::Texture::MIN_FILTER,_minFilterHint);
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)
{
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="<<this<<", glyph="<<glyph->getGlyphCode()<<std::endl;
// 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;
GLenum imageFormat = (_glyphTextureFeatures==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_FORMAT : OSGTEXT_GLYPH_SDF_FORMAT;
GLenum internalFormat = (_glyphTextureFeatures==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_INTERNALFORMAT : OSGTEXT_GLYPH_SDF_INTERNALFORMAT;
GLenum imageFormat = (_shaderTechnique==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_FORMAT : OSGTEXT_GLYPH_SDF_FORMAT;
GLenum internalFormat = (_shaderTechnique==GREYSCALE) ? OSGTEXT_GLYPH_ALPHA_INTERNALFORMAT : OSGTEXT_GLYPH_SDF_INTERNALFORMAT;
_image->allocateImage(getTextureWidth(), getTextureHeight(), 1, imageFormat, GL_UNSIGNED_BYTE);
_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);
@ -172,12 +172,12 @@ osg::StateSet* Text::createStateSet()
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)
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;
@ -199,7 +199,7 @@ osg::StateSet* Text::createStateSet()
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;