Added support for texture object manager, which provides an automatic mechansim
for reusing deleted textures.
This commit is contained in:
@@ -387,16 +387,19 @@ void Font::GlyphTexture::apply(osg::State& state) const
|
||||
const Extensions* extensions = getExtensions(contextID,true);
|
||||
bool generateMipMapSupported = extensions->isGenerateMipMapSupported();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
GLuint& handle = getTextureObject(contextID);
|
||||
// get the texture object for the current contextID.
|
||||
TextureObject* textureObject = getTextureObject(contextID);
|
||||
|
||||
bool generateMipMapOn = false;
|
||||
|
||||
if (handle == 0)
|
||||
if (textureObject == 0)
|
||||
{
|
||||
|
||||
// being bound for the first time, need to allocate the texture
|
||||
glGenTextures( 1L, (GLuint *)&handle );
|
||||
glBindTexture( GL_TEXTURE_2D, handle );
|
||||
|
||||
_textureObjectBuffer[contextID] = textureObject = getTextureObjectManager()->reuseOrGenerateTextureObject(
|
||||
contextID,GL_TEXTURE_2D,1,GL_LUMINANCE_ALPHA,getTextureWidth(), getTextureHeight(),1,0);
|
||||
|
||||
textureObject->bind();
|
||||
|
||||
|
||||
applyTexParameters(GL_TEXTURE_2D,state);
|
||||
|
||||
@@ -411,7 +414,6 @@ void Font::GlyphTexture::apply(osg::State& state) const
|
||||
if (generateMipMapSupported)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
|
||||
generateMipMapOn = true;
|
||||
}
|
||||
else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, LINEAR);
|
||||
break;
|
||||
@@ -432,31 +434,31 @@ void Font::GlyphTexture::apply(osg::State& state) const
|
||||
else
|
||||
{
|
||||
// reuse texture by binding.
|
||||
glBindTexture( GL_TEXTURE_2D, handle );
|
||||
textureObject->bind();
|
||||
|
||||
if (getTextureParameterDirty(contextID))
|
||||
{
|
||||
applyTexParameters(GL_TEXTURE_2D,state);
|
||||
}
|
||||
bool generateMipMapOn = false;
|
||||
|
||||
// need to look at generate mip map extension if mip mapping required.
|
||||
switch(_min_filter)
|
||||
{
|
||||
case NEAREST_MIPMAP_NEAREST:
|
||||
case NEAREST_MIPMAP_LINEAR:
|
||||
case LINEAR_MIPMAP_NEAREST:
|
||||
case LINEAR_MIPMAP_LINEAR:
|
||||
if (generateMipMapSupported)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
|
||||
generateMipMapOn = true;
|
||||
}
|
||||
else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, LINEAR);
|
||||
break;
|
||||
default:
|
||||
// not mip mapping so no problems.
|
||||
break;
|
||||
}
|
||||
// // need to look at generate mip map extension if mip mapping required.
|
||||
// switch(_min_filter)
|
||||
// {
|
||||
// case NEAREST_MIPMAP_NEAREST:
|
||||
// case NEAREST_MIPMAP_LINEAR:
|
||||
// case LINEAR_MIPMAP_NEAREST:
|
||||
// case LINEAR_MIPMAP_LINEAR:
|
||||
// if (generateMipMapSupported)
|
||||
// {
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
|
||||
// generateMipMapOn = true;
|
||||
// }
|
||||
// else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, LINEAR);
|
||||
// break;
|
||||
// default:
|
||||
// // not mip mapping so no problems.
|
||||
// break;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -557,10 +559,10 @@ void Font::GlyphTexture::apply(osg::State& state) const
|
||||
|
||||
|
||||
|
||||
if (generateMipMapOn)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
|
||||
}
|
||||
// if (generateMipMapTurnedOn)
|
||||
// {
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -207,20 +207,7 @@ void Text::setDrawMode(unsigned int mode)
|
||||
{
|
||||
if (_drawMode==mode) return;
|
||||
|
||||
if ((_drawMode&3) != (mode&3))
|
||||
{
|
||||
_drawMode=mode;
|
||||
if (_drawMode&TEXT_PIXMAP)
|
||||
{
|
||||
setCharacterSizeMode(SCREEN_COORDS);
|
||||
setAutoRotateToScreen(true);
|
||||
}
|
||||
computeGlyphRepresentation();
|
||||
}
|
||||
else
|
||||
{
|
||||
_drawMode=mode;
|
||||
}
|
||||
_drawMode=mode;
|
||||
}
|
||||
|
||||
|
||||
@@ -660,7 +647,7 @@ void Text::drawImplementation(osg::State& state) const
|
||||
glNormal3fv(_normal.ptr());
|
||||
glColor4fv(_color.ptr());
|
||||
|
||||
if (_drawMode & TEXT && !(_drawMode & TEXT_PIXMAP))
|
||||
if (_drawMode & TEXT)
|
||||
{
|
||||
|
||||
state.disableAllVertexArrays();
|
||||
@@ -681,36 +668,6 @@ void Text::drawImplementation(osg::State& state) const
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (_drawMode & TEXT_PIXMAP)
|
||||
{
|
||||
|
||||
state.applyTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);
|
||||
|
||||
for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin();
|
||||
titr!=_textureGlyphQuadMap.end();
|
||||
++titr)
|
||||
{
|
||||
const GlyphQuads& glyphquad = titr->second;
|
||||
|
||||
int ci=1;
|
||||
|
||||
for(GlyphQuads::Glyphs::const_iterator gitr=glyphquad._glyphs.begin();
|
||||
gitr!=glyphquad._glyphs.end();
|
||||
++gitr, ci+=4)
|
||||
{
|
||||
|
||||
Font::Glyph* glyph = *gitr;
|
||||
|
||||
|
||||
glRasterPos3fv(glyphquad._transformedCoords[contextID][ci].ptr());
|
||||
|
||||
glyph->draw(state);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (_drawMode & BOUNDINGBOX)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user