Clean up up osg::Geometry, removing long deprecated support for array indices and BIND_PER_PRIMITIVE binding that forced OpenGL slow paths. osg::Geometry is now smaller and only supports OpenGL fasts paths.

New methods osg::Geometry::containsDeprecatedData() and osg::Geometry::fixDeprecatedData() provide a means for converting geometries that still use the array indices and BIND_PER_PRIMITIVE across to complient
versions.

Cleaned up the rest of the OSG where use of array indices and BIND_PER_PRIMITIVE were accessed or used.
This commit is contained in:
Robert Osfield
2013-06-18 11:18:28 +00:00
parent 05b72e9b4c
commit 7d40c7258f
35 changed files with 1379 additions and 2880 deletions

View File

@@ -115,7 +115,7 @@ struct MyRigTransformHardware : public osgAnimation::RigTransformHardware
{
std::stringstream ss;
ss << "boneWeight" << i;
geom.setVertexAttribData(attribIndex + i, osg::Geometry::ArrayData(getVertexAttrib(i),osg::Geometry::BIND_PER_VERTEX));
geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i));
}
osg::ref_ptr<osg::StateSet> ss = new osg::StateSet;

View File

@@ -17,7 +17,7 @@
*/
#include <osg/Geode>
#include <osg/GeometryNew>
#include <osg/Geometry>
#include <osg/Material>
#include <osg/Vec3>
#include <osg/MatrixTransform>
@@ -93,7 +93,7 @@ osg::Node* createScene()
// create POINTS
{
// create Geometry object to store all the vertices and points primitive.
osg::GeometryNew* pointsGeom = new osg::GeometryNew();
osg::Geometry* pointsGeom = new osg::Geometry();
// create a Vec3Array and add to it all my coordinates.
// Like all the *Array variants (see include/osg/Array) , Vec3Array is derived from both osg::Array
@@ -122,14 +122,14 @@ osg::Node* createScene()
// pass the color array to points geometry, note the binding to tell the geometry
// that only use one color for the whole object.
pointsGeom->setColorArray(colors);
pointsGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
pointsGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
pointsGeom->setNormalArray(normals);
pointsGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
pointsGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// create and add a DrawArray Primitive (see include/osg/Primitive). The first
@@ -147,7 +147,7 @@ osg::Node* createScene()
// create LINES
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* linesGeom = new osg::GeometryNew();
osg::Geometry* linesGeom = new osg::Geometry();
// this time we'll preallocate the vertex array to the size we
// need and then simple set them as array elements, 8 points
@@ -170,14 +170,14 @@ osg::Node* createScene()
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -192,7 +192,7 @@ osg::Node* createScene()
// create LINE_STRIP
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* linesGeom = new osg::GeometryNew();
osg::Geometry* linesGeom = new osg::Geometry();
// this time we'll preallocate the vertex array to the size
// and then use an iterator to fill in the values, a bit perverse
@@ -212,14 +212,14 @@ osg::Node* createScene()
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -234,7 +234,7 @@ osg::Node* createScene()
// create LINE_LOOP
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* linesGeom = new osg::GeometryNew();
osg::Geometry* linesGeom = new osg::Geometry();
// this time we'll a C arrays to initialize the vertices.
@@ -259,14 +259,14 @@ osg::Node* createScene()
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -307,7 +307,7 @@ osg::Node* createScene()
// create POLYGON
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* polyGeom = new osg::GeometryNew();
osg::Geometry* polyGeom = new osg::Geometry();
// this time we'll use C arrays to initialize the vertices.
// note, anticlockwise ordering.
@@ -333,12 +333,12 @@ osg::Node* createScene()
// use the shared color array.
polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// use the shared normal array.
polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -355,7 +355,7 @@ osg::Node* createScene()
// create QUADS
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* polyGeom = new osg::GeometryNew();
osg::Geometry* polyGeom = new osg::Geometry();
// note, anticlockwise ordering.
osg::Vec3 myCoords[] =
@@ -380,12 +380,12 @@ osg::Node* createScene()
// use the shared color array.
polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// use the shared normal array.
polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -402,7 +402,7 @@ osg::Node* createScene()
// create QUAD_STRIP
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* polyGeom = new osg::GeometryNew();
osg::Geometry* polyGeom = new osg::Geometry();
// note, first coord at top, second at bottom, reverse to that buggy OpenGL image..
osg::Vec3 myCoords[] =
@@ -429,12 +429,12 @@ osg::Node* createScene()
// use the shared color array.
polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// use the shared normal array.
polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -451,7 +451,7 @@ osg::Node* createScene()
// create TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN all in one Geometry/
{
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* polyGeom = new osg::GeometryNew();
osg::Geometry* polyGeom = new osg::Geometry();
// note, first coord at top, second at bottom, reverse to that buggy OpenGL image..
osg::Vec3 myCoords[] =
@@ -497,12 +497,12 @@ osg::Node* createScene()
// use the shared color array.
polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// use the shared normal array.
polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
@@ -571,7 +571,7 @@ osg::Node* createBackground()
// create Geometry object to store all the vertices and lines primitive.
osg::GeometryNew* polyGeom = new osg::GeometryNew();
osg::Geometry* polyGeom = new osg::Geometry();
// note, anticlockwise ordering.
osg::Vec3 myCoords[] =
@@ -590,14 +590,14 @@ osg::Node* createBackground()
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
polyGeom->setColorArray(colors);
polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
polyGeom->setNormalArray(normals);
polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec2 myTexCoords[] =
{

View File

@@ -43,7 +43,7 @@ typedef NodeContainer::iterator NodeIterator;
NodeContainer nodes;
//
osg::Group * Root = 0;
osg::ref_ptr<osg::Group> Root = 0;
const int HOUSES_SIZE = 25000; // total number of houses
double XDim = 5000.0f; // area dimension +/- XDim
@@ -81,11 +81,11 @@ void CreateHouses()
};
// use the same color, normal and indices for all houses.
osg::Vec4Array* colors = new osg::Vec4Array(1);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(1);
(*colors)[0] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
// normals
osg::Vec3Array * normals = new osg::Vec3Array(16);
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(16);
(*normals)[0] = osg::Vec3( 0.0f, -0.0f, -1.0f);
(*normals)[1] = osg::Vec3( 0.0f, -0.0f, -1.0f);
(*normals)[2] = osg::Vec3( 0.0f, -1.0f, 0.0f);
@@ -104,10 +104,10 @@ void CreateHouses()
(*normals)[15] = osg::Vec3(-0.707107f, 0.0f, 0.707107f);
// coordIndices
osg::UByteArray* coordIndices = new osg::UByteArray(48,indices);
osg::ref_ptr<osg::UByteArray> coordIndices = new osg::UByteArray(48,indices);
// share the primitive set.
osg::PrimitiveSet* primitives = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,48);
// share the primitive set.
osg::PrimitiveSet* primitives = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,48);
for (int q = 0; q < HOUSES_SIZE; q++)
{
@@ -121,10 +121,10 @@ void CreateHouses()
float scale = 10.0f;
osg::Vec3 offset(xPos,yPos,0.0f);
osg::Vec3 offset(xPos,yPos,0.0f);
// coords
osg::Vec3Array* coords = new osg::Vec3Array(10);
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array(10);
(*coords)[0] = osg::Vec3( 0.5f, -0.7f, 0.0f);
(*coords)[1] = osg::Vec3( 0.5f, 0.7f, 0.0f);
(*coords)[2] = osg::Vec3(-0.5f, 0.7f, 0.0f);
@@ -143,23 +143,23 @@ void CreateHouses()
// create geometry
osg::Geometry * geometry = new osg::Geometry();
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
geometry->addPrimitiveSet(primitives);
geometry->setVertexArray(coords);
geometry->setVertexIndices(coordIndices);
geometry->setVertexArray(coords.get());
geometry->setVertexIndices(coordIndices.get());
geometry->setColorArray(colors);
geometry->setColorArray(colors.get());
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
geometry->setNormalArray(normals);
geometry->setNormalArray(normals.get());
geometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
osg::Geode * geode = new osg::Geode();
geode->addDrawable(geometry);
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable(geometry.get());
nodes.push_back(geode);
nodes.push_back(geode.get());
}
}

View File

@@ -106,6 +106,8 @@ public:
return 0;
}
virtual unsigned int getElementSize() const { return sizeof(osg::Vec3); }
/** Returns a pointer to the first element of the array. */
virtual const GLvoid* getDataPointer() const {
return _ptr;
@@ -123,6 +125,9 @@ public:
return _numElements * sizeof(osg::Vec3);
}
virtual void reserveArray(unsigned int num) { OSG_NOTICE<<"reserveArray() not supported"<<std::endl; }
virtual void resizeArray(unsigned int num) { OSG_NOTICE<<"resizeArray() not supported"<<std::endl; }
private:
unsigned int _numElements;
osg::Vec3* _ptr;
@@ -277,11 +282,9 @@ osg::Geode* createGeometry()
// Changing these flags will tickle different cases in
// Geometry::drawImplementation. They should all work fine
// with the shared array. Setting VertexIndices will hit
// some other cases.
// with the shared array.
geom->setUseVertexBufferObjects(false);
geom->setUseDisplayList(false);
geom->setFastPathHint(false);
geode->addDrawable( geom.get() );