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:
Robert Osfield
2006-08-02 21:05:56 +00:00
parent b81cea3963
commit 9e7b07fbcf
4 changed files with 15 additions and 39 deletions

View File

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

View File

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