Bug fixes to osgText to handle the osgUtil::Optimizer being used on a scene
graph containing text. Fixed warning in MD2 plugin.
This commit is contained in:
@@ -79,7 +79,7 @@ osg::Node* createHUD()
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setText("Then place a osg::Projection node above the subgraph\nto create an orthographic projection.");
|
||||
text->setText("Then place an osg::Projection node above the subgraph\nto create an orthographic projection.");
|
||||
text->setPosition(position);
|
||||
|
||||
position += delta;
|
||||
|
||||
@@ -59,6 +59,8 @@ class SG_EXPORT Image : public Object
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "Image"; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const Image& rhs) const;
|
||||
|
||||
void setFileName(const std::string& fileName);
|
||||
inline const std::string& getFileName() const { return _fileName; }
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <osgText/Export>
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
namespace osgText {
|
||||
|
||||
@@ -116,7 +115,6 @@ protected:
|
||||
|
||||
typedef std::pair< unsigned int, unsigned int > SizePair;
|
||||
typedef std::map< SizePair, GlyphMap > SizeGlyphMap;
|
||||
typedef std::set< Text* > TextList;
|
||||
|
||||
SizeGlyphMap _sizeGlyphMap;
|
||||
GlyphTextureList _glyphTextureList;
|
||||
@@ -175,6 +173,9 @@ public:
|
||||
|
||||
GlyphTexture();
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
void setStateSet(osg::StateSet* stateset) { _stateset = stateset; }
|
||||
osg::StateSet* getStateSet() { return _stateset; }
|
||||
const osg::StateSet* getStateSet() const { return _stateset; }
|
||||
|
||||
@@ -109,7 +109,7 @@ osg::Node* createHUD()
|
||||
geode->addDrawable( text );
|
||||
|
||||
text->setFont(timesFont);
|
||||
text->setText("Then place a osg::Projection node above the subgraph\nto create an orthographic projection.");
|
||||
text->setText("Then place an osg::Projection node above the subgraph\nto create an orthographic projection.");
|
||||
text->setPosition(position);
|
||||
|
||||
position += delta;
|
||||
|
||||
@@ -81,6 +81,27 @@ void Image::deallocateData()
|
||||
}
|
||||
}
|
||||
|
||||
int Image::compare(const Image& rhs) const
|
||||
{
|
||||
if (getFileName()<rhs.getFileName()) return -1;
|
||||
else if (getFileName()>rhs.getFileName()) return 1;
|
||||
|
||||
// need to test against image contents here...
|
||||
COMPARE_StateAttribute_Parameter(_s)
|
||||
COMPARE_StateAttribute_Parameter(_t)
|
||||
COMPARE_StateAttribute_Parameter(_internalTextureFormat)
|
||||
COMPARE_StateAttribute_Parameter(_pixelFormat)
|
||||
COMPARE_StateAttribute_Parameter(_dataType)
|
||||
COMPARE_StateAttribute_Parameter(_packing)
|
||||
COMPARE_StateAttribute_Parameter(_modifiedTag)
|
||||
|
||||
// still need implement checks for
|
||||
// _data
|
||||
// _mipmapData
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Image::setFileName(const std::string& fileName)
|
||||
{
|
||||
_fileName = fileName;
|
||||
|
||||
@@ -212,7 +212,8 @@ void State::apply(const StateSet* dstate)
|
||||
//pushStateSet(dstate);
|
||||
//apply();
|
||||
//popStateSet();
|
||||
|
||||
//return;
|
||||
|
||||
if (dstate)
|
||||
{
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ int Texture1D::compare(const StateAttribute& sa) const
|
||||
{
|
||||
if (rhs._image.valid())
|
||||
{
|
||||
if (_image->getFileName()<rhs._image->getFileName()) return -1;
|
||||
else if (_image->getFileName()>rhs._image->getFileName()) return 1;;
|
||||
int result = _image->compare(*rhs._image);
|
||||
if (result!=0) return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -52,8 +52,8 @@ int Texture2D::compare(const StateAttribute& sa) const
|
||||
{
|
||||
if (rhs._image.valid())
|
||||
{
|
||||
if (_image->getFileName()<rhs._image->getFileName()) return -1;
|
||||
else if (_image->getFileName()>rhs._image->getFileName()) return 1;;
|
||||
int result = _image->compare(*rhs._image);
|
||||
if (result!=0) return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -57,8 +57,8 @@ int Texture3D::compare(const StateAttribute& sa) const
|
||||
{
|
||||
if (rhs._image.valid())
|
||||
{
|
||||
if (_image->getFileName()<rhs._image->getFileName()) return -1;
|
||||
else if (_image->getFileName()>rhs._image->getFileName()) return 1;;
|
||||
int result = _image->compare(*rhs._image);
|
||||
if (result!=0) return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -129,8 +129,8 @@ int TextureCubeMap::compare(const StateAttribute& sa) const
|
||||
{
|
||||
if (rhs._images[n].valid())
|
||||
{
|
||||
if (_images[n]->getFileName()<rhs._images[n]->getFileName()) return -1;
|
||||
else if (_images[n]->getFileName()>rhs._images[n]->getFileName()) return 1;;
|
||||
int result = _images[n]->compare(*rhs._images[n]);
|
||||
if (result!=0) return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -119,6 +119,8 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode)
|
||||
glyph->setVerticalAdvance((float)metrics->vertAdvance/64.0f);
|
||||
|
||||
addGlyph(_facade->getWidth(),_facade->getHeight(),charcode,glyph.get());
|
||||
|
||||
// cout << " in getGlyph() implementation="<<this<<" "<<_filename<<" facade="<<_facade<<endl;
|
||||
|
||||
return glyph.get();
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ load_md2 (const char *filename)
|
||||
for (int curFrame = 0; curFrame < md2_header->numFrames; curFrame++) {
|
||||
// std::cerr << "Num vertices " << md2_header->numVertices << std::endl;
|
||||
|
||||
long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands);
|
||||
//long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands);
|
||||
|
||||
MD2_FRAME *frame = (MD2_FRAME *) ((unsigned char *) mapbase + md2_header->offsetFrames + (md2_header->frameSize * curFrame));
|
||||
MD2_VERTEX *frame_vertices = frame->vertices;
|
||||
|
||||
@@ -210,6 +210,9 @@ bool Font::hasVertical() const
|
||||
|
||||
void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph)
|
||||
{
|
||||
|
||||
//cout << "charcode "<<(char)charcode<<" "<<&_glyphTextureList<<endl;
|
||||
|
||||
_sizeGlyphMap[SizePair(width,height)][charcode]=glyph;
|
||||
|
||||
|
||||
@@ -223,18 +226,24 @@ void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charco
|
||||
if ((*itr)->getSpaceForGlyph(glyph,posX,posY)) glyphTexture = itr->get();
|
||||
}
|
||||
|
||||
if (glyphTexture)
|
||||
{
|
||||
//cout << " found space for texture "<<glyphTexture<<" posX="<<posX<<" posY="<<posY<<endl;
|
||||
}
|
||||
|
||||
if (!glyphTexture)
|
||||
{
|
||||
//std::cout<<"Creating new GlyphTexture & StateSet"<<std::endl;
|
||||
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
_stateSetList.push_back(stateset);
|
||||
|
||||
glyphTexture = new GlyphTexture;
|
||||
|
||||
// static int numberOfTexturesAllocated = 0;
|
||||
// ++numberOfTexturesAllocated;
|
||||
// std::cout << this<< " numberOfTexturesAllocated "<<numberOfTexturesAllocated<<std::endl;
|
||||
//std::cout<<" Creating new GlyphTexture "<<glyphTexture<<"& StateSet "<<stateset<<std::endl;
|
||||
|
||||
static int numberOfTexturesAllocated = 0;
|
||||
++numberOfTexturesAllocated;
|
||||
//std::cout << " " << this<< " numberOfTexturesAllocated "<<numberOfTexturesAllocated<<std::endl;
|
||||
|
||||
// reserve enough space for the glyphs.
|
||||
glyphTexture->setGlyphImageMargin(_margin);
|
||||
@@ -277,6 +286,15 @@ Font::GlyphTexture::~GlyphTexture()
|
||||
{
|
||||
}
|
||||
|
||||
// return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
|
||||
int Font::GlyphTexture::compare(const StateAttribute& rhs) const
|
||||
{
|
||||
if (this<&rhs) return -1;
|
||||
else if (this>&rhs) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Font::GlyphTexture::getSpaceForGlyph(Glyph* glyph, int& posX, int& posY)
|
||||
{
|
||||
|
||||
|
||||
@@ -219,6 +219,8 @@ void Text::computeGlyphRepresentation()
|
||||
|
||||
_textureGlyphQuadMap.clear();
|
||||
|
||||
if (_text.empty()) return;
|
||||
|
||||
osg::Vec2 startOfLine(0.0f,0.0f);
|
||||
osg::Vec2 cursor(startOfLine);
|
||||
osg::Vec2 local(0.0f,0.0f);
|
||||
|
||||
Reference in New Issue
Block a user