Reworked the state management within osgText::Text and osgText::Font so that it
only applies textures locally rather than whole StateSet.
This commit is contained in:
parent
b81cea3963
commit
9e7b07fbcf
@ -22,7 +22,6 @@
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/TexEnv>
|
||||
|
||||
#include <osgText/Export>
|
||||
|
||||
@ -161,7 +160,6 @@ protected:
|
||||
osg::ref_ptr<osg::StateSet> _stateset;
|
||||
SizeGlyphMap _sizeGlyphMap;
|
||||
GlyphTextureList _glyphTextureList;
|
||||
StateSetList _stateSetList;
|
||||
|
||||
// current active size of font
|
||||
unsigned int _width;
|
||||
@ -173,8 +171,6 @@ protected:
|
||||
osg::Texture::FilterMode _minFilterHint;
|
||||
osg::Texture::FilterMode _magFilterHint;
|
||||
|
||||
osg::ref_ptr<osg::TexEnv > _texEnv;
|
||||
|
||||
osg::ref_ptr<FontImplementation> _implementation;
|
||||
|
||||
|
||||
@ -222,10 +218,6 @@ public:
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const osg::StateAttribute& rhs) const;
|
||||
|
||||
void setStateSet(osg::StateSet* stateset) { _stateset = stateset; }
|
||||
osg::StateSet* getStateSet() { return _stateset; }
|
||||
const osg::StateSet* getStateSet() const { return _stateset; }
|
||||
|
||||
/** 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; }
|
||||
@ -240,8 +232,6 @@ public:
|
||||
|
||||
virtual ~GlyphTexture();
|
||||
|
||||
osg::StateSet* _stateset;
|
||||
|
||||
// parameter used to compute the size and position of empty space
|
||||
// in the texture which could accomodate new glyphs.
|
||||
int _margin;
|
||||
@ -283,9 +273,6 @@ public:
|
||||
GlyphTexture* getTexture();
|
||||
const GlyphTexture* getTexture() const;
|
||||
|
||||
osg::StateSet* getStateSet();
|
||||
const osg::StateSet* getStateSet() const;
|
||||
|
||||
void setTexturePosition(int posX,int posY);
|
||||
int getTexturePositionX() const;
|
||||
int getTexturePositionY() const;
|
||||
|
@ -479,12 +479,12 @@ public:
|
||||
const LineNumbers& getLineNumbers() const { return _lineNumbers; }
|
||||
};
|
||||
|
||||
typedef std::map<osg::ref_ptr<osg::StateSet>,GlyphQuads> TextureGlyphQuadMap;
|
||||
typedef std::map<osg::ref_ptr<Font::GlyphTexture>,GlyphQuads> TextureGlyphQuadMap;
|
||||
|
||||
/** Direct Access to GlyphQuads */
|
||||
const GlyphQuads* getGlyphQuads(osg::StateSet* stateSet) const
|
||||
const GlyphQuads* getGlyphQuads(Font::GlyphTexture* texture) const
|
||||
{
|
||||
TextureGlyphQuadMap::iterator itGlyphQuad = _textureGlyphQuadMap.find(stateSet);
|
||||
TextureGlyphQuadMap::iterator itGlyphQuad = _textureGlyphQuadMap.find(texture);
|
||||
if (itGlyphQuad == _textureGlyphQuadMap.end()) return NULL;
|
||||
|
||||
return &itGlyphQuad->second;
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
#include <osg/TexEnv>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
@ -138,9 +137,10 @@ Font::Font(FontImplementation* implementation):
|
||||
_magFilterHint(osg::Texture::LINEAR)
|
||||
{
|
||||
setImplementation(implementation);
|
||||
_texEnv = new osg::TexEnv(osg::TexEnv::BLEND);
|
||||
|
||||
_stateset = new osg::StateSet;
|
||||
//_stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
//_stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::ON);
|
||||
_stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
}
|
||||
|
||||
@ -301,15 +301,11 @@ void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charco
|
||||
if (!glyphTexture)
|
||||
{
|
||||
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
_stateSetList.push_back(stateset);
|
||||
|
||||
glyphTexture = new GlyphTexture;
|
||||
|
||||
static int numberOfTexturesAllocated = 0;
|
||||
++numberOfTexturesAllocated;
|
||||
|
||||
osg::notify(osg::INFO)<<" Creating new GlyphTexture "<<glyphTexture<<"& StateSet "<<stateset<<std::endl;
|
||||
osg::notify(osg::INFO)<< " Font " << this<< ", numberOfTexturesAllocated "<<numberOfTexturesAllocated<<std::endl;
|
||||
|
||||
// reserve enough space for the glyphs.
|
||||
@ -321,12 +317,6 @@ void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charco
|
||||
|
||||
_glyphTextureList.push_back(glyphTexture);
|
||||
|
||||
glyphTexture->setStateSet(stateset);
|
||||
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
stateset->setTextureAttributeAndModes(0,glyphTexture,osg::StateAttribute::ON);
|
||||
if (_texEnv.valid()) stateset->setTextureAttribute(0,_texEnv.get());
|
||||
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
|
||||
if (!glyphTexture->getSpaceForGlyph(glyph,posX,posY))
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Warning: unable to allocate texture big enough for glyph"<<std::endl;
|
||||
@ -342,7 +332,6 @@ void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charco
|
||||
|
||||
|
||||
Font::GlyphTexture::GlyphTexture():
|
||||
_stateset(0),
|
||||
_margin(2),
|
||||
_usedY(0),
|
||||
_partUsedX(0),
|
||||
@ -652,9 +641,6 @@ void Font::Glyph::setTexture(GlyphTexture* texture) { _texture = texture; }
|
||||
Font::GlyphTexture* Font::Glyph::getTexture() { return _texture; }
|
||||
const Font::GlyphTexture* Font::Glyph::getTexture() const { return _texture; }
|
||||
|
||||
osg::StateSet* Font::Glyph::getStateSet() { return _texture?_texture->getStateSet():0; }
|
||||
const osg::StateSet* Font::Glyph::getStateSet() const { return _texture?_texture->getStateSet():0; }
|
||||
|
||||
void Font::Glyph::setTexturePosition(int posX,int posY) { _texturePosX = posX; _texturePosY = posY; }
|
||||
int Font::Glyph::getTexturePositionX() const { return _texturePosX; }
|
||||
int Font::Glyph::getTexturePositionY() const { return _texturePosY; }
|
||||
|
@ -631,7 +631,7 @@ void Text::computeGlyphRepresentation()
|
||||
local.x() += bearing.x() * wr;
|
||||
local.y() += bearing.y() * hr;
|
||||
|
||||
GlyphQuads& glyphquad = _textureGlyphQuadMap[glyph->getTexture()->getStateSet()];
|
||||
GlyphQuads& glyphquad = _textureGlyphQuadMap[glyph->getTexture()];
|
||||
|
||||
glyphquad._glyphs.push_back(glyph);
|
||||
glyphquad._lineNumbers.push_back(lineNumber);
|
||||
@ -1386,6 +1386,9 @@ void Text::drawImplementation(osg::State& state) const
|
||||
{
|
||||
unsigned int contextID = state.getContextID();
|
||||
|
||||
state.applyMode(GL_BLEND,true);
|
||||
state.applyTextureMode(0,GL_TEXTURE_2D,true);
|
||||
|
||||
if (_characterSizeMode!=OBJECT_COORDS || _autoRotateToScreen)
|
||||
{
|
||||
int frameNumber = state.getFrameStamp()?state.getFrameStamp()->getFrameNumber():0;
|
||||
@ -1858,7 +1861,7 @@ void Text::renderOnlyForegroundText(osg::State& state) const
|
||||
++titr)
|
||||
{
|
||||
// need to set the texture here...
|
||||
state.apply(titr->first.get());
|
||||
state.applyTextureAttribute(0,titr->first.get());
|
||||
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
@ -1887,7 +1890,7 @@ void Text::renderWithPolygonOffset(osg::State& state) const
|
||||
++titr)
|
||||
{
|
||||
// need to set the texture here...
|
||||
state.apply(titr->first.get());
|
||||
state.applyTextureAttribute(0,titr->first.get());
|
||||
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
@ -1942,7 +1945,7 @@ void Text::renderWithNoDepthBuffer(osg::State& state) const
|
||||
++titr)
|
||||
{
|
||||
// need to set the texture here...
|
||||
state.apply(titr->first.get());
|
||||
state.applyTextureAttribute(0,titr->first.get());
|
||||
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
@ -1994,7 +1997,7 @@ void Text::renderWithDepthRange(osg::State& state) const
|
||||
++titr)
|
||||
{
|
||||
// need to set the texture here...
|
||||
state.apply(titr->first.get());
|
||||
state.applyTextureAttribute(0,titr->first.get());
|
||||
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
@ -2088,7 +2091,7 @@ void Text::renderWithStencilBuffer(osg::State& state) const
|
||||
++titr)
|
||||
{
|
||||
// need to set the texture here...
|
||||
state.apply(titr->first.get());
|
||||
state.applyTextureAttribute(0,titr->first.get());
|
||||
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
@ -2155,7 +2158,7 @@ void Text::renderWithStencilBuffer(osg::State& state) const
|
||||
++titr)
|
||||
{
|
||||
// need to set the texture here...
|
||||
state.apply(titr->first.get());
|
||||
state.applyTextureAttribute(0,titr->first.get());
|
||||
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user