Simplified and improved the glyph margin computation and usage

This commit is contained in:
Robert Osfield
2017-09-29 20:21:13 +01:00
parent beb5801eee
commit d2fa7c4317
8 changed files with 41 additions and 116 deletions

View File

@@ -107,23 +107,6 @@ public:
* return true on success, return false when not supported.*/
virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; }
/** Set the margin around each glyph,
* to ensure that texture filtering doesn't bleed adjacent glyph's into each other.
* Default margin is 1 texels.*/
void setGlyphImageMargin(unsigned int margin);
unsigned int getGlyphImageMargin() const;
/** Set the margin ratio around each glyph, relative to the glyph's size.
* to ensure that texture filtering doesn't bleed adjacent glyph's into each other.
* Default margin is 0.05.*/
void setGlyphImageMarginRatio(float margin);
float getGlyphImageMarginRatio() const;
/** Set the interval that glyph positions are clamped to.
* Default interval is 1 texels.*/
void setGlyphInterval(int interval);
int getGlyphInterval() const;
void setGyphTextureFeatures(GlyphTexture::Features features) { _glyphTextureFeatures = features; }
GlyphTexture::Features getGlyphTextureFeatures() const { return _glyphTextureFeatures; }
@@ -202,9 +185,7 @@ protected:
// current active size of font
FontResolution _fontSize;
unsigned int _margin;
float _marginRatio;
int _glyphInterval;
GlyphTexture::Features _glyphTextureFeatures;
unsigned int _textureWidthHint;

View File

@@ -93,6 +93,9 @@ public:
void setMaxTexCoord(const osg::Vec2& coord);
const osg::Vec2& getMaxTexCoord() const;
void setTexelMargin(float margin) { _texelMargin = margin; }
float getTexelMargin() const { return _texelMargin; }
protected:
virtual ~Glyph();
@@ -116,6 +119,7 @@ protected:
int _texturePosY;
osg::Vec2 _minTexCoord;
osg::Vec2 _maxTexCoord;
float _texelMargin;
typedef osg::buffered_value<GLuint> GLObjectList;
mutable GLObjectList _globjList;
@@ -256,16 +260,6 @@ public:
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
virtual int compare(const osg::StateAttribute& rhs) const;
/** Set the margin around each glyph, to ensure that texture filtering doesn't bleed adjacent glyph's into each other.*/
void setGlyphImageMargin(unsigned int margin) { _margin = margin; }
unsigned int getGlyphImageMargin() const { return _margin; }
void setGlyphImageMarginRatio(float margin) { _marginRatio = margin; }
float getGlyphImageMarginRatio() const { return _marginRatio; }
void setGlyphInterval(int interval) { _interval = interval; }
int getGlyphInterval() const { return _interval; }
enum Features
{
GREYSCALE,
@@ -277,6 +271,10 @@ public:
void setGlyphTextureFeatures(Features features) { _glyphTextureFeatures = features; }
Features getGlyphTextureFeatures() const { return _glyphTextureFeatures; }
int getEffectMargin(const Glyph* glyph);
int getTexelMargin(const Glyph* glyph);
bool getSpaceForGlyph(Glyph* glyph, int& posX, int& posY);
void addGlyph(Glyph* glyph,int posX, int posY);
@@ -296,12 +294,6 @@ protected:
void copyGlyphImage(Glyph* glyph);
// parameter used to compute the size and position of empty space
// in the texture which could accommodate new glyphs.
int _margin;
float _marginRatio;
int _interval;
Features _glyphTextureFeatures;
int _usedY;