Restructed the way that GlyphTexture is set up to better support control of osgText::ShaderTechnique from osgText::Text
This commit is contained in:
parent
817b6601d2
commit
4b295c46d1
@ -153,12 +153,12 @@ struct TextSettings
|
|||||||
font->setMinFilterHint(minFilter);
|
font->setMinFilterHint(minFilter);
|
||||||
font->setMagFilterHint(magFilter);
|
font->setMagFilterHint(magFilter);
|
||||||
font->setMaxAnisotropy(maxAnisotropy);
|
font->setMaxAnisotropy(maxAnisotropy);
|
||||||
font->setShaderTechnique(shaderTechnique);
|
|
||||||
|
|
||||||
text.setColor(textColor);
|
text.setColor(textColor);
|
||||||
text.setBackdropType(backdropType);
|
text.setBackdropType(backdropType);
|
||||||
text.setBackdropOffset(backdropOffset.x(), backdropOffset.y());
|
text.setBackdropOffset(backdropOffset.x(), backdropOffset.y());
|
||||||
text.setBackdropColor(backdropColor);
|
text.setBackdropColor(backdropColor);
|
||||||
|
text.setShaderTechnique(shaderTechnique);
|
||||||
|
|
||||||
text.setFont(font.get());
|
text.setFont(font.get());
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ osg:: Node* createTextBelow(const osg::BoundingBox& bb, const std::string& label
|
|||||||
|
|
||||||
if (s_useSDF)
|
if (s_useSDF)
|
||||||
{
|
{
|
||||||
text->getFont()->setShaderTechnique(osgText::ALL_FEATURES);
|
text->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()->setShaderTechnique(osgText::ALL_FEATURES);
|
text->setShaderTechnique(osgText::ALL_FEATURES);
|
||||||
}
|
}
|
||||||
|
|
||||||
text->setAlignment(osgText::Text::RIGHT_CENTER);
|
text->setAlignment(osgText::Text::RIGHT_CENTER);
|
||||||
|
@ -107,11 +107,6 @@ public:
|
|||||||
* return true on success, return false when not supported.*/
|
* return true on success, return false when not supported.*/
|
||||||
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 setShaderTechnique(ShaderTechnique features) { _shaderTechnique = features; }
|
|
||||||
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.
|
||||||
* Note, this doesn't affect already created Texture Glhph's.*/
|
* Note, this doesn't affect already created Texture Glhph's.*/
|
||||||
void setTextureSizeHint(unsigned int width,unsigned int height);
|
void setTextureSizeHint(unsigned int width,unsigned int height);
|
||||||
@ -162,6 +157,8 @@ public:
|
|||||||
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
||||||
GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
|
GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
|
||||||
|
|
||||||
|
void assignGlyphToGlyphTexture(Glyph* glyph, ShaderTechnique shaderTechnique);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual ~Font();
|
virtual ~Font();
|
||||||
@ -186,8 +183,6 @@ protected:
|
|||||||
// current active size of font
|
// current active size of font
|
||||||
FontResolution _fontSize;
|
FontResolution _fontSize;
|
||||||
|
|
||||||
ShaderTechnique _shaderTechnique;
|
|
||||||
|
|
||||||
unsigned int _textureWidthHint;
|
unsigned int _textureWidthHint;
|
||||||
unsigned int _textureHeightHint;
|
unsigned int _textureHeightHint;
|
||||||
osg::Texture::FilterMode _minFilterHint;
|
osg::Texture::FilterMode _minFilterHint;
|
||||||
|
@ -77,22 +77,40 @@ public:
|
|||||||
void setVerticalAdvance(float advance);
|
void setVerticalAdvance(float advance);
|
||||||
float getVerticalAdvance() const;
|
float getVerticalAdvance() const;
|
||||||
|
|
||||||
void setTexture(GlyphTexture* texture);
|
struct TextureInfo : public osg::Referenced
|
||||||
GlyphTexture* getTexture();
|
{
|
||||||
const GlyphTexture* getTexture() const;
|
TextureInfo():
|
||||||
|
texture(0),
|
||||||
|
texelMargin(0.0f) {}
|
||||||
|
|
||||||
void setTexturePosition(int posX,int posY);
|
TextureInfo(GlyphTexture* tex, int x, int y, const osg::Vec2& mintc, const osg::Vec2& maxtc, float margin):
|
||||||
int getTexturePositionX() const;
|
texture(tex),
|
||||||
int getTexturePositionY() const;
|
texturePositionX(x),
|
||||||
|
texturePositionY(y),
|
||||||
|
minTexCoord(mintc),
|
||||||
|
maxTexCoord(maxtc),
|
||||||
|
texelMargin(margin) {}
|
||||||
|
|
||||||
void setMinTexCoord(const osg::Vec2& coord);
|
GlyphTexture* texture;
|
||||||
const osg::Vec2& getMinTexCoord() const;
|
int texturePositionX;
|
||||||
|
int texturePositionY;
|
||||||
|
osg::Vec2 minTexCoord;
|
||||||
|
osg::Vec2 maxTexCoord;
|
||||||
|
float texelMargin;
|
||||||
|
};
|
||||||
|
|
||||||
void setMaxTexCoord(const osg::Vec2& coord);
|
void setTextureInfo(ShaderTechnique technique, TextureInfo* info)
|
||||||
const osg::Vec2& getMaxTexCoord() const;
|
{
|
||||||
|
if (technique>=_textureInfoList.size()) _textureInfoList.resize(technique+1);
|
||||||
|
_textureInfoList[technique] = info;
|
||||||
|
}
|
||||||
|
|
||||||
void setTexelMargin(float margin) { _texelMargin = margin; }
|
const TextureInfo* getTextureInfo(ShaderTechnique technique) const
|
||||||
float getTexelMargin() const { return _texelMargin; }
|
{
|
||||||
|
return (technique<_textureInfoList.size()) ? _textureInfoList[technique].get() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureInfo* getOrCreateTextureInfo(ShaderTechnique technique);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -112,16 +130,8 @@ protected:
|
|||||||
osg::Vec2 _verticalBearing;
|
osg::Vec2 _verticalBearing;
|
||||||
float _verticalAdvance;
|
float _verticalAdvance;
|
||||||
|
|
||||||
GlyphTexture* _texture;
|
typedef std::vector< osg::ref_ptr<TextureInfo> > TextureInfoList;
|
||||||
int _texturePosX;
|
TextureInfoList _textureInfoList;
|
||||||
int _texturePosY;
|
|
||||||
osg::Vec2 _minTexCoord;
|
|
||||||
osg::Vec2 _maxTexCoord;
|
|
||||||
float _texelMargin;
|
|
||||||
|
|
||||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
|
||||||
mutable GLObjectList _globjList;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class OSGTEXT_EXPORT GlyphGeometry : public osg::Referenced
|
class OSGTEXT_EXPORT GlyphGeometry : public osg::Referenced
|
||||||
@ -283,7 +293,7 @@ protected:
|
|||||||
|
|
||||||
virtual ~GlyphTexture();
|
virtual ~GlyphTexture();
|
||||||
|
|
||||||
void copyGlyphImage(Glyph* glyph);
|
void copyGlyphImage(Glyph* glyph, Glyph::TextureInfo* info);
|
||||||
|
|
||||||
ShaderTechnique _shaderTechnique;
|
ShaderTechnique _shaderTechnique;
|
||||||
|
|
||||||
|
@ -29,12 +29,6 @@ DefaultFont::DefaultFont()
|
|||||||
_minFilterHint = osg::Texture::LINEAR_MIPMAP_LINEAR;
|
_minFilterHint = osg::Texture::LINEAR_MIPMAP_LINEAR;
|
||||||
_magFilterHint = osg::Texture::LINEAR;
|
_magFilterHint = osg::Texture::LINEAR;
|
||||||
|
|
||||||
char *ptr;
|
|
||||||
if ((ptr = getenv("OSG_SDF_TEXT")) != 0)
|
|
||||||
{
|
|
||||||
_shaderTechnique = osgText::ALL_FEATURES;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructGlyphs();
|
constructGlyphs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,11 +224,6 @@ 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
|
|
||||||
_shaderTechnique(ALL_FEATURES),
|
|
||||||
#else
|
|
||||||
_shaderTechnique(GREYSCALE),
|
|
||||||
#endif
|
|
||||||
_textureWidthHint(1024),
|
_textureWidthHint(1024),
|
||||||
_textureHeightHint(1024),
|
_textureHeightHint(1024),
|
||||||
_minFilterHint(osg::Texture::LINEAR_MIPMAP_LINEAR),
|
_minFilterHint(osg::Texture::LINEAR_MIPMAP_LINEAR),
|
||||||
@ -247,15 +242,6 @@ Font::Font(FontImplementation* implementation):
|
|||||||
if (osg_max_size<_textureWidthHint) _textureWidthHint = osg_max_size;
|
if (osg_max_size<_textureWidthHint) _textureWidthHint = osg_max_size;
|
||||||
if (osg_max_size<_textureHeightHint) _textureHeightHint = osg_max_size;
|
if (osg_max_size<_textureHeightHint) _textureHeightHint = osg_max_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ptr = getenv("OSG_SDF_TEXT")) != 0)
|
|
||||||
{
|
|
||||||
_shaderTechnique = ALL_FEATURES;
|
|
||||||
}
|
|
||||||
else if ((ptr = getenv("OSG_GREYSCALE_TEXT")) != 0)
|
|
||||||
{
|
|
||||||
_shaderTechnique = GREYSCALE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::~Font()
|
Font::~Font()
|
||||||
@ -459,6 +445,10 @@ void Font::addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph*
|
|||||||
|
|
||||||
_sizeGlyphMap[fontRes][charcode]=glyph;
|
_sizeGlyphMap[fontRes][charcode]=glyph;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Font::assignGlyphToGlyphTexture(Glyph* glyph, ShaderTechnique shaderTechnique)
|
||||||
|
{
|
||||||
int posX=0,posY=0;
|
int posX=0,posY=0;
|
||||||
|
|
||||||
GlyphTexture* glyphTexture = 0;
|
GlyphTexture* glyphTexture = 0;
|
||||||
@ -485,7 +475,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->setShaderTechnique(_shaderTechnique);
|
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);
|
||||||
@ -503,5 +493,4 @@ void Font::addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph*
|
|||||||
|
|
||||||
// add the glyph into the texture.
|
// add the glyph into the texture.
|
||||||
glyphTexture->addGlyph(glyph,posX,posY);
|
glyphTexture->addGlyph(glyph,posX,posY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,6 @@ using namespace std;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define TEXTURE_IMAGE_NUM_CHANNELS 1
|
#define TEXTURE_IMAGE_NUM_CHANNELS 1
|
||||||
#define TEXTURE_IMAGE_FORMAT OSGTEXT_GLYPH_FORMAT
|
#define TEXTURE_IMAGE_FORMAT OSGTEXT_GLYPH_FORMAT
|
||||||
@ -52,6 +50,11 @@ using namespace std;
|
|||||||
#define TEXTURE_IMAGE_FORMAT GL_RGBA
|
#define TEXTURE_IMAGE_FORMAT GL_RGBA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// GlyphTexture
|
||||||
|
//
|
||||||
GlyphTexture::GlyphTexture():
|
GlyphTexture::GlyphTexture():
|
||||||
_usedY(0),
|
_usedY(0),
|
||||||
_partUsedX(0),
|
_partUsedX(0),
|
||||||
@ -154,22 +157,19 @@ void GlyphTexture::addGlyph(Glyph* glyph, int posX, int posY)
|
|||||||
|
|
||||||
_glyphs.push_back(glyph);
|
_glyphs.push_back(glyph);
|
||||||
|
|
||||||
// set up the details of where to place glyph's image in the texture.
|
osg::ref_ptr<Glyph::TextureInfo> info = new Glyph::TextureInfo(
|
||||||
glyph->setTexture(this);
|
this,
|
||||||
glyph->setTexturePosition(posX,posY);
|
posX, posY,
|
||||||
|
osg::Vec2( static_cast<float>(posX)/static_cast<float>(getTextureWidth()), static_cast<float>(posY)/static_cast<float>(getTextureHeight()) ), // minTexCoord
|
||||||
|
osg::Vec2( static_cast<float>(posX+glyph->s())/static_cast<float>(getTextureWidth()), static_cast<float>(posY+glyph->t())/static_cast<float>(getTextureHeight()) ), // maxTexCoord
|
||||||
|
float(getTexelMargin(glyph))); // margin
|
||||||
|
|
||||||
glyph->setMinTexCoord( osg::Vec2( static_cast<float>(posX)/static_cast<float>(getTextureWidth()),
|
glyph->setTextureInfo(_shaderTechnique, info.get());
|
||||||
static_cast<float>(posY)/static_cast<float>(getTextureHeight()) ) );
|
|
||||||
glyph->setMaxTexCoord( osg::Vec2( static_cast<float>(posX+glyph->s())/static_cast<float>(getTextureWidth()),
|
|
||||||
static_cast<float>(posY+glyph->t())/static_cast<float>(getTextureHeight()) ) );
|
|
||||||
|
|
||||||
|
copyGlyphImage(glyph, info);
|
||||||
glyph->setTexelMargin(float(getTexelMargin(glyph)));
|
|
||||||
|
|
||||||
copyGlyphImage(glyph);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphTexture::copyGlyphImage(Glyph* glyph)
|
void GlyphTexture::copyGlyphImage(Glyph* glyph, Glyph::TextureInfo* info)
|
||||||
{
|
{
|
||||||
_image->dirty();
|
_image->dirty();
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph)
|
|||||||
// 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.
|
||||||
glyph->setPixelFormat(_image->getPixelFormat());
|
glyph->setPixelFormat(_image->getPixelFormat());
|
||||||
glyph->setInternalTextureFormat(_image->getPixelFormat());
|
glyph->setInternalTextureFormat(_image->getPixelFormat());
|
||||||
_image->copySubImage(glyph->getTexturePositionX(), glyph->getTexturePositionY(), 0, glyph);
|
_image->copySubImage(info->texturePositionX, info->texturePositionY, 0, glyph);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph)
|
|||||||
|
|
||||||
int dest_columns = _image->s();
|
int dest_columns = _image->s();
|
||||||
int dest_rows = _image->t();
|
int dest_rows = _image->t();
|
||||||
unsigned char* dest_data = _image->data(glyph->getTexturePositionX(),glyph->getTexturePositionY());
|
unsigned char* dest_data = _image->data(info->texturePositionX, info->texturePositionY);
|
||||||
|
|
||||||
int search_distance = getEffectMargin(glyph);
|
int search_distance = getEffectMargin(glyph);
|
||||||
|
|
||||||
@ -204,11 +204,11 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph)
|
|||||||
|
|
||||||
float max_distance = sqrtf(float(search_distance)*float(search_distance)*2.0);
|
float max_distance = sqrtf(float(search_distance)*float(search_distance)*2.0);
|
||||||
|
|
||||||
if ((left+glyph->getTexturePositionX())<0) left = -glyph->getTexturePositionX();
|
if ((left+info->texturePositionX)<0) left = -info->texturePositionX;
|
||||||
if ((right+glyph->getTexturePositionX())>=dest_columns) right = dest_columns-glyph->getTexturePositionX()-1;
|
if ((right+info->texturePositionX)>=dest_columns) right = dest_columns-info->texturePositionX-1;
|
||||||
|
|
||||||
if ((lower+glyph->getTexturePositionY())<0) lower = -glyph->getTexturePositionY();
|
if ((lower+info->texturePositionY)<0) lower = -info->texturePositionY;
|
||||||
if ((upper+glyph->getTexturePositionY())>=dest_rows) upper = dest_rows-glyph->getTexturePositionY()-1;
|
if ((upper+info->texturePositionY)>=dest_rows) upper = dest_rows-info->texturePositionY-1;
|
||||||
|
|
||||||
|
|
||||||
int num_components = osg::Image::computeNumComponents(_image->getPixelFormat());
|
int num_components = osg::Image::computeNumComponents(_image->getPixelFormat());
|
||||||
@ -427,13 +427,18 @@ osg::Image* GlyphTexture::createImage()
|
|||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
Glyph* glyph = itr->get();
|
Glyph* glyph = itr->get();
|
||||||
copyGlyphImage(glyph);
|
// copyGlyphImage(glyph); // TODO!!!!!
|
||||||
|
OSG_NOTICE<<"GlyphTexture::createImage() need to implement copy"<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _image.get();
|
return _image.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Glyph
|
||||||
|
//
|
||||||
// all the methods in Font::Glyph have been made non inline because VisualStudio6.0 is STUPID, STUPID, STUPID PILE OF JUNK.
|
// all the methods in Font::Glyph have been made non inline because VisualStudio6.0 is STUPID, STUPID, STUPID PILE OF JUNK.
|
||||||
Glyph::Glyph(Font* font, unsigned int glyphCode):
|
Glyph::Glyph(Font* font, unsigned int glyphCode):
|
||||||
_font(font),
|
_font(font),
|
||||||
@ -443,12 +448,7 @@ Glyph::Glyph(Font* font, unsigned int glyphCode):
|
|||||||
_horizontalBearing(0.0f,0.f),
|
_horizontalBearing(0.0f,0.f),
|
||||||
_horizontalAdvance(0.f),
|
_horizontalAdvance(0.f),
|
||||||
_verticalBearing(0.0f,0.f),
|
_verticalBearing(0.0f,0.f),
|
||||||
_verticalAdvance(0.f),
|
_verticalAdvance(0.f)
|
||||||
_texture(0),
|
|
||||||
_texturePosX(0),
|
|
||||||
_texturePosY(0),
|
|
||||||
_minTexCoord(0.0f,0.0f),
|
|
||||||
_maxTexCoord(0.0f,0.0f)
|
|
||||||
{
|
{
|
||||||
setThreadSafeRefUnref(true);
|
setThreadSafeRefUnref(true);
|
||||||
}
|
}
|
||||||
@ -469,20 +469,20 @@ const osg::Vec2& Glyph::getVerticalBearing() const { return _verticalBearing; }
|
|||||||
void Glyph::setVerticalAdvance(float advance) { _verticalAdvance=advance; }
|
void Glyph::setVerticalAdvance(float advance) { _verticalAdvance=advance; }
|
||||||
float Glyph::getVerticalAdvance() const { return _verticalAdvance; }
|
float Glyph::getVerticalAdvance() const { return _verticalAdvance; }
|
||||||
|
|
||||||
void Glyph::setTexture(GlyphTexture* texture) { _texture = texture; }
|
Glyph::TextureInfo* Glyph::getOrCreateTextureInfo(ShaderTechnique technique)
|
||||||
GlyphTexture* Glyph::getTexture() { return _texture; }
|
{
|
||||||
const GlyphTexture* Glyph::getTexture() const { return _texture; }
|
if (technique>=_textureInfoList.size()) _textureInfoList.resize(technique+1);
|
||||||
|
if (!_textureInfoList[technique])
|
||||||
void Glyph::setTexturePosition(int posX,int posY) { _texturePosX = posX; _texturePosY = posY; }
|
{
|
||||||
int Glyph::getTexturePositionX() const { return _texturePosX; }
|
_font->assignGlyphToGlyphTexture(this, technique);
|
||||||
int Glyph::getTexturePositionY() const { return _texturePosY; }
|
}
|
||||||
|
return _textureInfoList[technique].get();
|
||||||
void Glyph::setMinTexCoord(const osg::Vec2& coord) { _minTexCoord=coord; }
|
}
|
||||||
const osg::Vec2& Glyph::getMinTexCoord() const { return _minTexCoord; }
|
|
||||||
|
|
||||||
void Glyph::setMaxTexCoord(const osg::Vec2& coord) { _maxTexCoord=coord; }
|
|
||||||
const osg::Vec2& Glyph::getMaxTexCoord() const { return _maxTexCoord; }
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Glyph3D
|
||||||
|
//
|
||||||
Glyph3D::Glyph3D(Font* font, unsigned int glyphCode):
|
Glyph3D::Glyph3D(Font* font, unsigned int glyphCode):
|
||||||
osg::Referenced(true),
|
osg::Referenced(true),
|
||||||
_font(font),
|
_font(font),
|
||||||
|
@ -47,6 +47,16 @@ Text::Text():
|
|||||||
{
|
{
|
||||||
_supportsVertexBufferObjects = true;
|
_supportsVertexBufferObjects = true;
|
||||||
|
|
||||||
|
char* ptr = 0;
|
||||||
|
if ((ptr = getenv("OSG_SDF_TEXT")) != 0)
|
||||||
|
{
|
||||||
|
_shaderTechnique = ALL_FEATURES;
|
||||||
|
}
|
||||||
|
else if ((ptr = getenv("OSG_GREYSCALE_TEXT")) != 0)
|
||||||
|
{
|
||||||
|
_shaderTechnique = GREYSCALE;
|
||||||
|
}
|
||||||
|
|
||||||
assignStateSet();
|
assignStateSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +139,7 @@ osg::StateSet* Text::createStateSet()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeFont->getShaderTechnique()!=GREYSCALE)
|
if (_shaderTechnique!=GREYSCALE)
|
||||||
{
|
{
|
||||||
ss<<std::fixed<<std::setprecision(1);
|
ss<<std::fixed<<std::setprecision(1);
|
||||||
|
|
||||||
@ -185,12 +195,12 @@ osg::StateSet* Text::createStateSet()
|
|||||||
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
|
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
|
||||||
OSG_NOTICE<<"Text::createStateSet() activeFont->getShaderTechnique()="<<activeFont->getShaderTechnique()<<std::endl;
|
OSG_NOTICE<<"Text::createStateSet() ShaderTechnique="<<_shaderTechnique<<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->getShaderTechnique()==GREYSCALE && shaderHint==osg::DisplaySettings::SHADER_NONE)
|
if (_shaderTechnique==GREYSCALE && shaderHint==osg::DisplaySettings::SHADER_NONE)
|
||||||
{
|
{
|
||||||
OSG_NOTICE<<"Font::Font() Fixed function pipeline"<<std::endl;
|
OSG_NOTICE<<"Font::Font() Fixed function pipeline"<<std::endl;
|
||||||
|
|
||||||
@ -212,7 +222,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->getShaderTechnique()==GREYSCALE)
|
if (_shaderTechnique==GREYSCALE)
|
||||||
{
|
{
|
||||||
OSG_NOTICE<<"Using shaders/text_greyscale.frag"<<std::endl;
|
OSG_NOTICE<<"Using shaders/text_greyscale.frag"<<std::endl;
|
||||||
|
|
||||||
@ -374,7 +384,9 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2& cursor, String::ite
|
|||||||
void Text::addGlyphQuad(Glyph* glyph, const osg::Vec2& minc, const osg::Vec2& maxc, const osg::Vec2& mintc, const osg::Vec2& maxtc)
|
void Text::addGlyphQuad(Glyph* glyph, const osg::Vec2& minc, const osg::Vec2& maxc, const osg::Vec2& mintc, const osg::Vec2& maxtc)
|
||||||
{
|
{
|
||||||
// set up the coords of the quad
|
// set up the coords of the quad
|
||||||
GlyphQuads& glyphquad = _textureGlyphQuadMap[glyph->getTexture()];
|
const Glyph::TextureInfo* info = glyph->getOrCreateTextureInfo(_shaderTechnique);
|
||||||
|
GlyphTexture* glyphTexture = info ? info->texture : 0;
|
||||||
|
GlyphQuads& glyphquad = _textureGlyphQuadMap[glyphTexture];
|
||||||
|
|
||||||
glyphquad._glyphs.push_back(glyph);
|
glyphquad._glyphs.push_back(glyph);
|
||||||
|
|
||||||
@ -625,16 +637,19 @@ void Text::computeGlyphRepresentation()
|
|||||||
local.x() += bearing.x() * wr;
|
local.x() += bearing.x() * wr;
|
||||||
local.y() += bearing.y() * hr;
|
local.y() += bearing.y() * hr;
|
||||||
|
|
||||||
|
const Glyph::TextureInfo* info = glyph->getOrCreateTextureInfo(_shaderTechnique);
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
|
||||||
// Adjust coordinates and texture coordinates to avoid
|
// Adjust coordinates and texture coordinates to avoid
|
||||||
// clipping the edges of antialiased characters.
|
// clipping the edges of antialiased characters.
|
||||||
osg::Vec2 mintc = glyph->getMinTexCoord();
|
osg::Vec2 mintc = info->minTexCoord;
|
||||||
osg::Vec2 maxtc = glyph->getMaxTexCoord();
|
osg::Vec2 maxtc = info->maxTexCoord;
|
||||||
osg::Vec2 vDiff = maxtc - mintc;
|
osg::Vec2 vDiff = maxtc - mintc;
|
||||||
float texelMargin = glyph->getTexelMargin();
|
float texelMargin = info->texelMargin;
|
||||||
|
|
||||||
float fHorizTCMargin = texelMargin / glyph->getTexture()->getTextureWidth();
|
float fHorizTCMargin = texelMargin / info->texture->getTextureWidth();
|
||||||
float fVertTCMargin = texelMargin / glyph->getTexture()->getTextureHeight();
|
float fVertTCMargin = texelMargin / info->texture->getTextureHeight();
|
||||||
float fHorizQuadMargin = vDiff.x() == 0.0f ? 0.0f : width * fHorizTCMargin / vDiff.x();
|
float fHorizQuadMargin = vDiff.x() == 0.0f ? 0.0f : width * fHorizTCMargin / vDiff.x();
|
||||||
float fVertQuadMargin = vDiff.y() == 0.0f ? 0.0f : height * fVertTCMargin / vDiff.y();
|
float fVertQuadMargin = vDiff.y() == 0.0f ? 0.0f : height * fVertTCMargin / vDiff.y();
|
||||||
|
|
||||||
@ -666,6 +681,11 @@ void Text::computeGlyphRepresentation()
|
|||||||
_textBB.expandBy(osg::Vec3(minc.x(),maxc.y(),0.0f)); //upper left corner
|
_textBB.expandBy(osg::Vec3(minc.x(),maxc.y(),0.0f)); //upper left corner
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"No TextureInfo for "<<charcode<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
previous_charcode = charcode;
|
previous_charcode = charcode;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user