Replaced deprecated osg::Geometry::set*Binding() usage.

This commit is contained in:
Robert Osfield
2013-06-27 09:54:12 +00:00
parent c1ebc3ac0c
commit 4b9aa1fd24
49 changed files with 1471 additions and 1559 deletions

View File

@@ -56,11 +56,11 @@ public:
_minFilterList.push_back(osg::Texture2D::NEAREST);
_magFilterList.push_back(osg::Texture2D::NEAREST);
_textList.push_back("Nearest filtering\nsetFilter(MIN_FILTER,NEAREST)\nsetFilter(MAG_FILTER,NEAREST)");
_minFilterList.push_back(osg::Texture2D::LINEAR);
_magFilterList.push_back(osg::Texture2D::LINEAR);
_textList.push_back("Linear filtering\nsetFilter(MIN_FILTER,LINEAR)\nsetFilter(MAG_FILTER,LINEAR)");
_minFilterList.push_back(osg::Texture2D::NEAREST_MIPMAP_NEAREST);
_magFilterList.push_back(osg::Texture2D::LINEAR);
_textList.push_back("nearest mip mapping (default filtering)\nsetFilter(MIN_FILTER,)\nsetFilter(MAG_FILTER,LINEAR)");
@@ -73,7 +73,7 @@ public:
_magFilterList.push_back(osg::Texture2D::LINEAR);
_textList.push_back("bi-linear mip mapping\nsetFilter(MIN_FILTER,NEAREST_MIPMAP_LINEAR)\nsetFilter(MAG_FILTER,LINEAR)");
setValues();
}
@@ -82,21 +82,21 @@ public:
if (nv->getFrameStamp())
{
double currTime = nv->getFrameStamp()->getSimulationTime();
if (currTime-_prevTime>_delay)
if (currTime-_prevTime>_delay)
{
// update filter modes and text.
setValues();
// advance the current positon, wrap round if required.
_currPos++;
if (_currPos>=_minFilterList.size()) _currPos=0;
if (_currPos>=_minFilterList.size()) _currPos=0;
// record time
_prevTime = currTime;
}
}
}
void setValues()
{
_texture->setFilter(osg::Texture2D::MIN_FILTER,_minFilterList[_currPos]);
@@ -113,38 +113,38 @@ protected:
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osgText::Text> _text;
double _delay;
FilterList _minFilterList;
FilterList _magFilterList;
TextList _textList;
unsigned int _currPos;
double _prevTime;
};
osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename)
{
osg::Group* group = new osg::Group;
// left hand side of bounding box.
osg::Vec3 top_left(bb.xMin(),bb.yMin(),bb.zMax());
osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin());
osg::Vec3 bottom_right(bb.xMin(),bb.yMax(),bb.zMin());
osg::Vec3 top_right(bb.xMin(),bb.yMax(),bb.zMax());
osg::Vec3 center(bb.xMin(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
osg::Vec3 center(bb.xMin(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
float height = bb.zMax()-bb.zMin();
// create the geometry for the wall.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array(4);
(*vertices)[0] = top_left;
(*vertices)[1] = bottom_left;
(*vertices)[2] = bottom_right;
(*vertices)[3] = top_right;
geom->setVertexArray(vertices);
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(0.0f,1.0f);
(*texcoords)[1].set(0.0f,0.0f);
@@ -154,31 +154,29 @@ osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename)
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(1.0f,0.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
group->addChild(geom_geode);
// set up the texture state.
// set up the texture state.
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
texture->setImage(osgDB::readImageFile(filename));
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
// create the text label.
osgText::Text* text = new osgText::Text;
text->setDataVariance(osg::Object::DYNAMIC);
@@ -187,20 +185,20 @@ osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename)
text->setCharacterSize(height*0.03f);
text->setAlignment(osgText::Text::CENTER_CENTER);
text->setAxisAlignment(osgText::Text::YZ_PLANE);
osg::Geode* text_geode = new osg::Geode;
text_geode->addDrawable(text);
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
group->addChild(text_geode);
// set the update callback to cycle through the various min and mag filter modes.
group->setUpdateCallback(new FilterCallback(texture,text));
return group;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -222,16 +220,16 @@ public:
_maxAnisotropyList.push_back(1.0f);
_textList.push_back("No anisotropic filtering (default)\nsetMaxAnisotropy(1.0f)");
_maxAnisotropyList.push_back(2.0f);
_textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(2.0f)");
_maxAnisotropyList.push_back(4.0f);
_textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(4.0f)");
_maxAnisotropyList.push_back(8.0f);
_textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(8.0f)");
_maxAnisotropyList.push_back(16.0f);
_textList.push_back("Higest quality anisotropic filtering\nsetMaxAnisotropy(16.0f)");
@@ -243,21 +241,21 @@ public:
if (nv->getFrameStamp())
{
double currTime = nv->getFrameStamp()->getSimulationTime();
if (currTime-_prevTime>_delay)
if (currTime-_prevTime>_delay)
{
// update filter modes and text.
setValues();
// advance the current positon, wrap round if required.
_currPos++;
if (_currPos>=_maxAnisotropyList.size()) _currPos=0;
if (_currPos>=_maxAnisotropyList.size()) _currPos=0;
// record time
_prevTime = currTime;
}
}
}
void setValues()
{
_texture->setMaxAnisotropy(_maxAnisotropyList[_currPos]);
@@ -273,37 +271,37 @@ protected:
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osgText::Text> _text;
double _delay;
AnisotropyList _maxAnisotropyList;
TextList _textList;
unsigned int _currPos;
double _prevTime;
};
osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filename)
{
osg::Group* group = new osg::Group;
// left hand side of bounding box.
osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMin());
osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin());
osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin());
osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMin());
osg::Vec3 center((bb.xMin()+bb.xMax())*0.5f,(bb.yMin()+bb.yMax())*0.5f,bb.zMin());
osg::Vec3 center((bb.xMin()+bb.xMax())*0.5f,(bb.yMin()+bb.yMax())*0.5f,bb.zMin());
float height = bb.yMax()-bb.yMin();
// create the geometry for the wall.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array(4);
(*vertices)[0] = top_left;
(*vertices)[1] = bottom_left;
(*vertices)[2] = bottom_right;
(*vertices)[3] = top_right;
geom->setVertexArray(vertices);
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(0.0f,1.0f);
(*texcoords)[1].set(0.0f,0.0f);
@@ -313,31 +311,29 @@ osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filenam
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(0.0f,0.0f,1.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
group->addChild(geom_geode);
// set up the texture state.
// set up the texture state.
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
texture->setImage(osgDB::readImageFile(filename));
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
// create the text label.
osgText::Text* text = new osgText::Text;
text->setDataVariance(osg::Object::DYNAMIC);
text->setFont("fonts/arial.ttf");
@@ -349,17 +345,17 @@ osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filenam
osg::Geode* text_geode = new osg::Geode;
text_geode->addDrawable(text);
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
group->addChild(text_geode);
// set the update callback to cycle through the various min and mag filter modes.
group->setUpdateCallback(new AnisotropicCallback(texture,text));
return group;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -380,16 +376,16 @@ public:
_wrapList.push_back(osg::Texture2D::CLAMP);
_textList.push_back("Default tex coord clamp\nsetWrap(WRAP_S,CLAMP)");
_wrapList.push_back(osg::Texture2D::CLAMP_TO_EDGE);
_textList.push_back("Clamp to edge extension\nsetWrap(WRAP_S,CLAMP_TO_EDGE)");
_wrapList.push_back(osg::Texture2D::CLAMP_TO_BORDER);
_textList.push_back("Clamp to border color extension\nsetWrap(WRAP_S,CLAMP_TO_BORDER)");
_wrapList.push_back(osg::Texture2D::REPEAT);
_textList.push_back("Repeat wrap\nsetWrap(WRAP_S,REPEAT)");
_wrapList.push_back(osg::Texture2D::MIRROR);
_textList.push_back("Mirror wrap extension\nsetWrap(WRAP_S,MIRROR)");
@@ -401,21 +397,21 @@ public:
if (nv->getFrameStamp())
{
double currTime = nv->getFrameStamp()->getSimulationTime();
if (currTime-_prevTime>_delay)
if (currTime-_prevTime>_delay)
{
// update filter modes and text.
setValues();
// advance the current positon, wrap round if required.
_currPos++;
if (_currPos>=_wrapList.size()) _currPos=0;
if (_currPos>=_wrapList.size()) _currPos=0;
// record time
_prevTime = currTime;
}
}
}
void setValues()
{
_texture->setWrap(osg::Texture2D::WRAP_S,_wrapList[_currPos]);
@@ -432,37 +428,37 @@ protected:
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osgText::Text> _text;
double _delay;
WrapList _wrapList;
TextList _textList;
unsigned int _currPos;
double _prevTime;
};
osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename)
{
osg::Group* group = new osg::Group;
// left hand side of bounding box.
osg::Vec3 top_left(bb.xMax(),bb.yMax(),bb.zMax());
osg::Vec3 bottom_left(bb.xMax(),bb.yMax(),bb.zMin());
osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin());
osg::Vec3 top_right(bb.xMax(),bb.yMin(),bb.zMax());
osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
float height = bb.zMax()-bb.zMin();
// create the geometry for the wall.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array(4);
(*vertices)[0] = top_left;
(*vertices)[1] = bottom_left;
(*vertices)[2] = bottom_right;
(*vertices)[3] = top_right;
geom->setVertexArray(vertices);
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(-1.0f,2.0f);
(*texcoords)[1].set(-1.0f,-1.0f);
@@ -472,34 +468,32 @@ osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename)
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(-1.0f,0.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
group->addChild(geom_geode);
// set up the texture state.
// set up the texture state.
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDER
texture->setImage(osgDB::readImageFile(filename));
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
// create the text label.
osgText::Text* text = new osgText::Text;
text->setDataVariance(osg::Object::DYNAMIC);
text->setFont("fonts/arial.ttf");
@@ -510,17 +504,17 @@ osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename)
osg::Geode* text_geode = new osg::Geode;
text_geode->addDrawable(text);
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
group->addChild(text_geode);
// set the update callback to cycle through the various min and mag filter modes.
group->setUpdateCallback(new WrapCallback(texture,text));
return group;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -540,7 +534,7 @@ public:
_prevTime(0.0)
{
#if 1
#if 1
osg::ref_ptr<osg::Image> originalImage = osgDB::readImageFile("Images/dog_left_eye.jpg");
osg::ref_ptr<osg::Image> subImage = new osg::Image;
@@ -576,19 +570,19 @@ public:
*d = 255-*d;
}
}
#endif
#endif
_imageList.push_back(subImage.get());
#else
_imageList.push_back(osgDB::readImageFile("Images/dog_left_eye.jpg"));
#endif
_textList.push_back("Subloaded Image 1 - dog_left_eye.jpg");
_imageList.push_back(osgDB::readImageFile("Images/dog_right_eye.jpg"));
_textList.push_back("Subloaded Image 2 - dog_right_eye.jpg");
setValues();
}
@@ -597,21 +591,21 @@ public:
if (nv->getFrameStamp())
{
double currTime = nv->getFrameStamp()->getSimulationTime();
if (currTime-_prevTime>_delay)
if (currTime-_prevTime>_delay)
{
// update filter modes and text.
setValues();
// advance the current positon, wrap round if required.
_currPos++;
if (_currPos>=_imageList.size()) _currPos=0;
if (_currPos>=_imageList.size()) _currPos=0;
// record time
_prevTime = currTime;
}
}
}
void setValues()
{
// Note, as long as the images are the same dimensions subloading will be used
@@ -622,7 +616,7 @@ public:
// the setImage which just updates internal pointers and modifed flags.
_texture->setImage(_imageList[_currPos].get());
//_texture->dirtyTextureObject();
_text->setText(_textList[_currPos]);
@@ -630,44 +624,44 @@ public:
protected:
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
typedef std::vector<std::string> TextList;
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osgText::Text> _text;
double _delay;
ImageList _imageList;
TextList _textList;
unsigned int _currPos;
double _prevTime;
};
osg::Node* createSubloadWall(osg::BoundingBox& bb)
{
osg::Group* group = new osg::Group;
// left hand side of bounding box.
osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax());
osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin());
osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin());
osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax());
osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f);
osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f);
float height = bb.zMax()-bb.zMin();
// create the geometry for the wall.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array(4);
(*vertices)[0] = top_left;
(*vertices)[1] = bottom_left;
(*vertices)[2] = bottom_right;
(*vertices)[3] = top_right;
geom->setVertexArray(vertices);
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(0.0f,1.0f);
(*texcoords)[1].set(0.0f,0.0f);
@@ -677,32 +671,30 @@ osg::Node* createSubloadWall(osg::BoundingBox& bb)
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(0.0f,-1.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
group->addChild(geom_geode);
// set up the texture state.
// set up the texture state.
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
// create the text label.
osgText::Text* text = new osgText::Text;
text->setDataVariance(osg::Object::DYNAMIC);
text->setFont("fonts/arial.ttf");
@@ -710,20 +702,20 @@ osg::Node* createSubloadWall(osg::BoundingBox& bb)
text->setCharacterSize(height*0.03f);
text->setAlignment(osgText::Text::CENTER_CENTER);
text->setAxisAlignment(osgText::Text::XZ_PLANE);
osg::Geode* text_geode = new osg::Geode;
text_geode->addDrawable(text);
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
group->addChild(text_geode);
// set the update callback to cycle through the various min and mag filter modes.
group->setUpdateCallback(new ImageUpdateCallback(texture,text));
return group;
}
@@ -732,8 +724,8 @@ osg::Node* createModel()
// create the root node which will hold the model.
osg::Group* root = new osg::Group();
// turn off lighting
// turn off lighting
root->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
osg::BoundingBox bb(0.0f,0.0f,0.0f,1.0f,1.0f,1.0f);
@@ -742,7 +734,7 @@ osg::Node* createModel()
root->addChild(createAnisotripicWall(bb,"Images/primitives.gif"));
root->addChild(createWrapWall(bb,"Images/tree0.rgba"));
root->addChild(createSubloadWall(bb));
return root;
}