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:
@@ -433,6 +433,7 @@ MARK_AS_ADVANCED(OSG_DISABLE_MSVC_WARNINGS)
|
||||
|
||||
OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON)
|
||||
|
||||
|
||||
OPTION(OSG_GL1_AVAILABLE "Set to OFF to disable use of OpenGL 1.x functions library." ON)
|
||||
OPTION(OSG_GL2_AVAILABLE "Set to OFF to disable use of OpenGL 2.x functions library." ON)
|
||||
OPTION(OSG_GL3_AVAILABLE "Set to OFF to disable use of OpenGL 3.x functions library." OFF)
|
||||
@@ -456,6 +457,8 @@ OPTION(OSG_GL_FIXED_FUNCTION_AVAILABLE "Set to OFF to disable use of OpenGL fixe
|
||||
|
||||
OPTION(OSG_CPP_EXCEPTIONS_AVAILABLE "Set to OFF to disable compile of OSG components that use C++ exceptions." ON)
|
||||
|
||||
OPTION(OSG_USE_DEPRECATED_GEOMETRY_METHODS "Set to ON to enable use of deprecated osg::Geometry functions." ON)
|
||||
|
||||
################################################################################
|
||||
# Set Config file
|
||||
|
||||
|
||||
@@ -130,40 +130,6 @@ struct Extents
|
||||
osg::Vec2d _max;
|
||||
};
|
||||
|
||||
class CheckValidVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
CheckValidVisitor():
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_numInvalidGeometries(0) {}
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
unsigned int local_numInvalidGeometries = 0;
|
||||
for(unsigned int i=0; i<geode.getNumDrawables(); ++i)
|
||||
{
|
||||
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
|
||||
if (geometry)
|
||||
{
|
||||
if (!geometry->verifyArrays(_errorReports)) ++local_numInvalidGeometries;
|
||||
}
|
||||
}
|
||||
if (local_numInvalidGeometries)
|
||||
{
|
||||
_errorReports<<"Geode "<<geode.getName()<<" contains problem geometries"<<std::endl;
|
||||
_numInvalidGeometries += local_numInvalidGeometries;
|
||||
}
|
||||
}
|
||||
|
||||
bool valid() const { return _numInvalidGeometries==0; }
|
||||
|
||||
unsigned int _numInvalidGeometries;
|
||||
std::stringstream _errorReports;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LoadDataVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
@@ -334,17 +300,6 @@ public:
|
||||
osg::notify(osg::NOTICE)<<"reading : "<<filename<<std::endl;
|
||||
node = osgDB::readNodeFile(filename);
|
||||
}
|
||||
|
||||
if (node)
|
||||
{
|
||||
CheckValidVisitor cvv;
|
||||
node->accept(cvv);
|
||||
if (!cvv.valid())
|
||||
{
|
||||
OSG_NOTICE<<"Warning, errors in geometry found in file "<<filename<<std::endl;
|
||||
OSG_NOTICE<<cvv._errorReports.str()<<std::endl;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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[] =
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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() );
|
||||
|
||||
|
||||
@@ -82,6 +82,9 @@ class OSG_EXPORT Array : public BufferData
|
||||
BIND_OFF=0,
|
||||
BIND_OVERALL=1,
|
||||
BIND_PER_PRIMITIVE_SET=2,
|
||||
#if defined(OSG_USE_DEPRECATED_GEOMETRY_METHODS)
|
||||
BIND_PER_PRIMITIVE=3,
|
||||
#endif
|
||||
BIND_PER_VERTEX=4,
|
||||
BIND_INSTANCE_DIVISOR_0=6,
|
||||
BIND_INSTANCE_DIVISOR_1=BIND_INSTANCE_DIVISOR_0+1,
|
||||
@@ -93,7 +96,7 @@ class OSG_EXPORT Array : public BufferData
|
||||
BIND_INSTANCE_DIVISOR_7=BIND_INSTANCE_DIVISOR_0+7
|
||||
};
|
||||
|
||||
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
|
||||
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0, Binding=BIND_UNDEFINED):
|
||||
_arrayType(arrayType),
|
||||
_dataSize(dataSize),
|
||||
_dataType(dataType),
|
||||
@@ -101,7 +104,7 @@ class OSG_EXPORT Array : public BufferData
|
||||
_normalize(false),
|
||||
_preserveDataType(false) {}
|
||||
|
||||
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
BufferData(array,copyop),
|
||||
_arrayType(array._arrayType),
|
||||
_dataSize(array._dataSize),
|
||||
@@ -131,9 +134,12 @@ class OSG_EXPORT Array : public BufferData
|
||||
virtual osg::Array* asArray() { return this; }
|
||||
virtual const osg::Array* asArray() const { return this; }
|
||||
|
||||
virtual unsigned int getElementSize() const = 0;
|
||||
virtual const GLvoid* getDataPointer() const = 0;
|
||||
virtual unsigned int getTotalDataSize() const = 0;
|
||||
virtual unsigned int getNumElements() const = 0;
|
||||
virtual void reserveArray(unsigned int num) = 0;
|
||||
virtual void resizeArray(unsigned int num) = 0;
|
||||
|
||||
|
||||
/** Specify how this array should be passed to OpenGL.*/
|
||||
@@ -186,7 +192,7 @@ class TemplateArray : public Array, public MixinVector<T>
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {}
|
||||
TemplateArray(Binding binding=BIND_UNDEFINED) : Array(ARRAYTYPE,DataSize,DataType, binding) {}
|
||||
|
||||
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Array(ta,copyop),
|
||||
@@ -200,6 +206,14 @@ class TemplateArray : public Array, public MixinVector<T>
|
||||
Array(ARRAYTYPE,DataSize,DataType),
|
||||
MixinVector<T>(ptr,ptr+no) {}
|
||||
|
||||
TemplateArray(Binding binding, unsigned int no) :
|
||||
Array(ARRAYTYPE,DataSize,DataType, binding),
|
||||
MixinVector<T>(no) {}
|
||||
|
||||
TemplateArray(Binding binding, unsigned int no,const T* ptr) :
|
||||
Array(ARRAYTYPE,DataSize,DataType, binding),
|
||||
MixinVector<T>(ptr,ptr+no) {}
|
||||
|
||||
template <class InputIterator>
|
||||
TemplateArray(InputIterator first,InputIterator last) :
|
||||
Array(ARRAYTYPE,DataSize,DataType),
|
||||
@@ -236,9 +250,12 @@ class TemplateArray : public Array, public MixinVector<T>
|
||||
MixinVector<T>( *this ).swap( *this );
|
||||
}
|
||||
|
||||
virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
|
||||
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
|
||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(ElementDataType)); }
|
||||
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
||||
virtual void reserveArray(unsigned int num) { this->reserve(num); }
|
||||
virtual void resizeArray(unsigned int num) { this->resize(num); }
|
||||
|
||||
typedef T ElementDataType; // expose T
|
||||
|
||||
@@ -322,9 +339,12 @@ class TemplateIndexArray : public IndexArray, public MixinVector<T>
|
||||
MixinVector<T>( *this ).swap( *this );
|
||||
}
|
||||
|
||||
virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
|
||||
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
|
||||
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
||||
virtual void reserveArray(unsigned int num) { this->reserve(num); }
|
||||
virtual void resizeArray(unsigned int num) { this->resize(num); }
|
||||
|
||||
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Array>
|
||||
#include <osg/Matrixd>
|
||||
#include <osg/GLBeginEndAdapter>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -27,7 +26,7 @@ class AttributeDispatchMap;
|
||||
|
||||
struct AttributeDispatch : public osg::Referenced
|
||||
{
|
||||
virtual void assign(const GLvoid*, const IndexArray*) {}
|
||||
virtual void assign(const GLvoid*) {}
|
||||
virtual void operator() (unsigned int) {};
|
||||
};
|
||||
|
||||
@@ -51,30 +50,30 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
if (at) _activeDispatchList[binding].push_back(at);
|
||||
}
|
||||
|
||||
void activateVertexArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), vertexDispatcher(array, 0)); }
|
||||
void activateColorArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array, 0)); }
|
||||
void activateNormalArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array, 0)); }
|
||||
void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array, 0)); }
|
||||
void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array, 0)); }
|
||||
void activateTexCoordArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), texCoordDispatcher(unit, array, 0)); }
|
||||
void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array, 0)); }
|
||||
void activateVertexArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexDispatcher(array)); }
|
||||
void activateColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array)); }
|
||||
void activateNormalArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array)); }
|
||||
void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array)); }
|
||||
void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array)); }
|
||||
void activateTexCoordArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), texCoordDispatcher(unit, array)); }
|
||||
void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array)); }
|
||||
|
||||
|
||||
AttributeDispatch* vertexDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* normalDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* colorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* secondaryColorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* fogCoordDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
AttributeDispatch* vertexDispatcher(Array* array);
|
||||
AttributeDispatch* normalDispatcher(Array* array);
|
||||
AttributeDispatch* colorDispatcher(Array* array);
|
||||
AttributeDispatch* secondaryColorDispatcher(Array* array);
|
||||
AttributeDispatch* fogCoordDispatcher(Array* array);
|
||||
AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array);
|
||||
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array);
|
||||
|
||||
void activateVertexArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexDispatcher(array, indices)); }
|
||||
void activateColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, colorDispatcher(array, indices)); }
|
||||
void activateNormalArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, normalDispatcher(array, indices)); }
|
||||
void activateSecondaryColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, secondaryColorDispatcher(array, indices)); }
|
||||
void activateFogCoordArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, fogCoordDispatcher(array, indices)); }
|
||||
void activateTexCoordArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, texCoordDispatcher(unit, array, indices)); }
|
||||
void activateVertexAttribArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexAttribDispatcher(unit, array, indices)); }
|
||||
void activateVertexArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, vertexDispatcher(array)); }
|
||||
void activateColorArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, colorDispatcher(array)); }
|
||||
void activateNormalArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, normalDispatcher(array)); }
|
||||
void activateSecondaryColorArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, secondaryColorDispatcher(array)); }
|
||||
void activateFogCoordArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, fogCoordDispatcher(array)); }
|
||||
void activateTexCoordArray(unsigned int binding, unsigned int unit, osg::Array* array) { if (binding && array) activate(binding, texCoordDispatcher(unit, array)); }
|
||||
void activateVertexAttribArray(unsigned int binding, unsigned int unit, osg::Array* array) { if (binding && array) activate(binding, vertexAttribDispatcher(unit, array)); }
|
||||
|
||||
void dispatch(unsigned int binding, unsigned int index)
|
||||
{
|
||||
@@ -89,30 +88,6 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
|
||||
bool active(unsigned int binding) const { return !_activeDispatchList[binding].empty(); }
|
||||
|
||||
void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; }
|
||||
bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; }
|
||||
|
||||
|
||||
void Begin(GLenum mode)
|
||||
{
|
||||
#ifdef OSG_GL1_AVAILABLE
|
||||
if (_useGLBeginEndAdapter) _glBeginEndAdapter->Begin(mode);
|
||||
else ::glBegin(mode);
|
||||
#else
|
||||
_glBeginEndAdapter->Begin(mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
void End()
|
||||
{
|
||||
#ifdef OSG_GL1_AVAILABLE
|
||||
if (_useGLBeginEndAdapter) _glBeginEndAdapter->End();
|
||||
else ::glEnd();
|
||||
#else
|
||||
_glBeginEndAdapter->End();
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void init();
|
||||
@@ -122,7 +97,6 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
|
||||
bool _initialized;
|
||||
State* _state;
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
|
||||
AttributeDispatchMap* _vertexDispatchers;
|
||||
AttributeDispatchMap* _normalDispatchers;
|
||||
@@ -140,7 +114,6 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
ActiveDispatchList _activeDispatchList;
|
||||
|
||||
bool _useVertexAttribAlias;
|
||||
bool _useGLBeginEndAdapter;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_GEOMETRY
|
||||
#define OSG_GEOMETRY 1
|
||||
#ifndef OSG_GEOMETRYNEW
|
||||
#define OSG_GEOMETRYNEW 1
|
||||
|
||||
#include <osg/Drawable>
|
||||
#include <osg/Vec2>
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
class OSG_EXPORT Geometry : public Drawable
|
||||
{
|
||||
public:
|
||||
@@ -44,164 +43,42 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
|
||||
bool empty() const;
|
||||
|
||||
enum AttributeBinding
|
||||
{
|
||||
BIND_OFF=0,
|
||||
BIND_OVERALL,
|
||||
BIND_PER_PRIMITIVE_SET,
|
||||
BIND_PER_PRIMITIVE,
|
||||
BIND_PER_VERTEX
|
||||
};
|
||||
|
||||
struct OSG_EXPORT ArrayData
|
||||
{
|
||||
ArrayData():
|
||||
binding(BIND_OFF),
|
||||
normalize(GL_FALSE) {}
|
||||
|
||||
ArrayData(const ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(0),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
ArrayData(Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(i),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
ArrayData& operator = (const ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
indices = rhs.indices;
|
||||
binding = rhs.binding;
|
||||
normalize = rhs.normalize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool empty() const { return !array.valid(); }
|
||||
|
||||
ref_ptr<Array> array;
|
||||
ref_ptr<IndexArray> indices; // deprecated.
|
||||
AttributeBinding binding;
|
||||
GLboolean normalize;
|
||||
};
|
||||
|
||||
struct OSG_EXPORT Vec3ArrayData
|
||||
{
|
||||
Vec3ArrayData():
|
||||
binding(BIND_OFF),
|
||||
normalize(GL_FALSE) {}
|
||||
|
||||
Vec3ArrayData(const Vec3ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(0),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
Vec3ArrayData(Vec3Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(i),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
Vec3ArrayData& operator = (const Vec3ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
indices = rhs.indices;
|
||||
binding = rhs.binding;
|
||||
normalize = rhs.normalize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool empty() const { return !array.valid(); }
|
||||
|
||||
ref_ptr<Vec3Array> array;
|
||||
ref_ptr<IndexArray> indices; // deprecated.
|
||||
AttributeBinding binding;
|
||||
GLboolean normalize;
|
||||
};
|
||||
|
||||
/** Static ArrayData which is returned from getTexCoordData(i) const and getVertexAttribData(i) const
|
||||
* when i is out of range.
|
||||
*/
|
||||
static const ArrayData s_InvalidArrayData;
|
||||
|
||||
typedef std::vector< ArrayData > ArrayDataList;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Array> > ArrayList;
|
||||
|
||||
void setVertexArray(Array* array);
|
||||
Array* getVertexArray() { return _vertexData.array.get(); }
|
||||
const Array* getVertexArray() const { return _vertexData.array.get(); }
|
||||
Array* getVertexArray() { return _vertexArray.get(); }
|
||||
const Array* getVertexArray() const { return _vertexArray.get(); }
|
||||
|
||||
void setVertexData(const ArrayData& arrayData);
|
||||
ArrayData& getVertexData() { return _vertexData; }
|
||||
const ArrayData& getVertexData() const { return _vertexData; }
|
||||
|
||||
|
||||
void setNormalBinding(AttributeBinding ab);
|
||||
AttributeBinding getNormalBinding() const { return _normalData.binding; }
|
||||
|
||||
void setNormalArray(Array* array);
|
||||
Array* getNormalArray() { return _normalData.array.get(); }
|
||||
const Array* getNormalArray() const { return _normalData.array.get(); }
|
||||
Array* getNormalArray() { return _normalArray.get(); }
|
||||
const Array* getNormalArray() const { return _normalArray.get(); }
|
||||
|
||||
void setNormalData(const ArrayData& arrayData);
|
||||
ArrayData& getNormalData() { return _normalData; }
|
||||
const ArrayData& getNormalData() const { return _normalData; }
|
||||
|
||||
void setColorBinding(AttributeBinding ab);
|
||||
AttributeBinding getColorBinding() const { return _colorData.binding; }
|
||||
|
||||
|
||||
void setColorArray(Array* array);
|
||||
Array* getColorArray() { return _colorData.array.get(); }
|
||||
const Array* getColorArray() const { return _colorData.array.get(); }
|
||||
|
||||
void setColorData(const ArrayData& arrayData);
|
||||
ArrayData& getColorData() { return _colorData; }
|
||||
const ArrayData& getColorData() const { return _colorData; }
|
||||
Array* getColorArray() { return _colorArray.get(); }
|
||||
const Array* getColorArray() const { return _colorArray.get(); }
|
||||
|
||||
|
||||
void setSecondaryColorBinding(AttributeBinding ab);
|
||||
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; }
|
||||
|
||||
void setSecondaryColorArray(Array* array);
|
||||
Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); }
|
||||
const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); }
|
||||
Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
|
||||
const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); }
|
||||
|
||||
void setSecondaryColorData(const ArrayData& arrayData);
|
||||
ArrayData& getSecondaryColorData() { return _secondaryColorData; }
|
||||
const ArrayData& getSecondaryColorData() const { return _secondaryColorData; }
|
||||
|
||||
|
||||
void setFogCoordBinding(AttributeBinding ab);
|
||||
AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; }
|
||||
|
||||
void setFogCoordArray(Array* array);
|
||||
Array* getFogCoordArray() { return _fogCoordData.array.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordData.array.get(); }
|
||||
|
||||
void setFogCoordData(const ArrayData& arrayData);
|
||||
ArrayData& getFogCoordData() { return _fogCoordData; }
|
||||
const ArrayData& getFogCoordData() const { return _fogCoordData; }
|
||||
Array* getFogCoordArray() { return _fogCoordArray.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
|
||||
|
||||
|
||||
void setTexCoordArray(unsigned int unit,Array*);
|
||||
Array* getTexCoordArray(unsigned int unit);
|
||||
const Array* getTexCoordArray(unsigned int unit) const;
|
||||
|
||||
void setTexCoordData(unsigned int index,const ArrayData& arrayData);
|
||||
ArrayData& getTexCoordData(unsigned int index);
|
||||
const ArrayData& getTexCoordData(unsigned int index) const;
|
||||
|
||||
unsigned int getNumTexCoordArrays() const { return static_cast<unsigned int>(_texCoordList.size()); }
|
||||
ArrayDataList& getTexCoordArrayList() { return _texCoordList; }
|
||||
const ArrayDataList& getTexCoordArrayList() const { return _texCoordList; }
|
||||
ArrayList& getTexCoordArrayList() { return _texCoordList; }
|
||||
const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
|
||||
|
||||
|
||||
|
||||
@@ -209,19 +86,10 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
Array *getVertexAttribArray(unsigned int index);
|
||||
const Array *getVertexAttribArray(unsigned int index) const;
|
||||
|
||||
void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
|
||||
AttributeBinding getVertexAttribBinding(unsigned int index) const;
|
||||
|
||||
void setVertexAttribNormalize(unsigned int index,GLboolean norm);
|
||||
GLboolean getVertexAttribNormalize(unsigned int index) const;
|
||||
|
||||
void setVertexAttribData(unsigned int index,const ArrayData& arrayData);
|
||||
ArrayData& getVertexAttribData(unsigned int index);
|
||||
const ArrayData& getVertexAttribData(unsigned int index) const;
|
||||
|
||||
unsigned int getNumVertexAttribArrays() const { return static_cast<unsigned int>(_vertexAttribList.size()); }
|
||||
ArrayDataList& getVertexAttribArrayList() { return _vertexAttribList; }
|
||||
const ArrayDataList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
||||
ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
|
||||
const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
||||
|
||||
|
||||
|
||||
@@ -255,43 +123,11 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
|
||||
|
||||
|
||||
/** return true if any arrays are shared.*/
|
||||
bool containsSharedArrays() const;
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setVertexIndices(IndexArray* array);
|
||||
IndexArray* getVertexIndices() { return _vertexData.indices.get(); }
|
||||
const IndexArray* getVertexIndices() const { return _vertexData.indices.get(); }
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setNormalIndices(IndexArray* array);
|
||||
IndexArray* getNormalIndices() { return _normalData.indices.get(); }
|
||||
const IndexArray* getNormalIndices() const { return _normalData.indices.get(); }
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setColorIndices(IndexArray* array);
|
||||
IndexArray* getColorIndices() { return _colorData.indices.get(); }
|
||||
const IndexArray* getColorIndices() const { return _colorData.indices.get(); }
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setSecondaryColorIndices(IndexArray* array);
|
||||
IndexArray* getSecondaryColorIndices() { return _secondaryColorData.indices.get(); }
|
||||
const IndexArray* getSecondaryColorIndices() const { return _secondaryColorData.indices.get(); }
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setFogCoordIndices(IndexArray* array);
|
||||
IndexArray* getFogCoordIndices() { return _fogCoordData.indices.get(); }
|
||||
const IndexArray* getFogCoordIndices() const { return _fogCoordData.indices.get(); }
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setTexCoordIndices(unsigned int unit,IndexArray*);
|
||||
IndexArray* getTexCoordIndices(unsigned int unit);
|
||||
const IndexArray* getTexCoordIndices(unsigned int unit) const;
|
||||
|
||||
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
||||
void setVertexAttribIndices(unsigned int index,IndexArray* array);
|
||||
IndexArray* getVertexAttribIndices(unsigned int index);
|
||||
const IndexArray* getVertexAttribIndices(unsigned int index) const;
|
||||
|
||||
|
||||
/** duplicate any shared arrays.*/
|
||||
void duplicateSharedArrays();
|
||||
|
||||
|
||||
/** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation
|
||||
@@ -310,69 +146,15 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
typedef std::vector<osg::Array*> ArrayList;
|
||||
bool getArrayList(ArrayList& arrayList) const;
|
||||
|
||||
typedef std::vector<osg::DrawElements*> DrawElementsList;
|
||||
bool getDrawElementsList(DrawElementsList& drawElementsList) const;
|
||||
|
||||
osg::VertexBufferObject* getOrCreateVertexBufferObject();
|
||||
|
||||
osg::ElementBufferObject* getOrCreateElementBufferObject();
|
||||
|
||||
|
||||
/** Set whether fast paths should be used when supported. */
|
||||
void setFastPathHint(bool on) { _fastPathHint = on; }
|
||||
|
||||
/** Get whether fast paths should be used when supported. */
|
||||
bool getFastPathHint() const { return _fastPathHint; }
|
||||
|
||||
|
||||
/** Return true if OpenGL fast paths will be used with drawing this Geometry.
|
||||
* Fast paths directly use vertex arrays, and glDrawArrays/glDrawElements so have low CPU overhead.
|
||||
* With Slow paths the osg::Geometry::drawImplementation has to dynamically assemble OpenGL
|
||||
* compatible vertex arrays from the osg::Geometry arrays data and then dispatch these to OpenGL,
|
||||
* so have higher CPU overhead than the Fast paths.
|
||||
* Use of per primitive bindings or per vertex indexed arrays will drop the rendering path off the fast path.
|
||||
*/
|
||||
inline bool areFastPathsUsed() const
|
||||
{
|
||||
if (_internalOptimizedGeometry.valid())
|
||||
return _internalOptimizedGeometry->areFastPathsUsed();
|
||||
else
|
||||
return _fastPath && _fastPathHint;
|
||||
}
|
||||
|
||||
bool computeFastPathsUsed();
|
||||
|
||||
bool verifyBindings() const;
|
||||
|
||||
void computeCorrectBindingsAndArraySizes();
|
||||
|
||||
/** check whether the arrays, indices, bindings and primitives all match correctly, return false is .*/
|
||||
bool verifyArrays(std::ostream& out) const;
|
||||
|
||||
bool suitableForOptimization() const;
|
||||
|
||||
void copyToAndOptimize(Geometry& target);
|
||||
|
||||
|
||||
bool containsSharedArrays() const;
|
||||
|
||||
void duplicateSharedArrays();
|
||||
|
||||
|
||||
void computeInternalOptimizedGeometry();
|
||||
|
||||
void removeInternalOptimizedGeometry() { _internalOptimizedGeometry = 0; }
|
||||
|
||||
void setInternalOptimizedGeometry(osg::Geometry* geometry) { _internalOptimizedGeometry = geometry; }
|
||||
|
||||
osg::Geometry* getInternalOptimizedGeometry() { return _internalOptimizedGeometry.get(); }
|
||||
|
||||
const osg::Geometry* getInternalOptimizedGeometry() const { return _internalOptimizedGeometry.get(); }
|
||||
|
||||
|
||||
/** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.
|
||||
* This size is used a hint for reuse of deleted display lists/vertex buffer objects. */
|
||||
virtual unsigned int getGLObjectSizeHint() const;
|
||||
@@ -419,29 +201,97 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
|
||||
virtual ~Geometry();
|
||||
|
||||
bool verifyBindings(const ArrayData& arrayData) const;
|
||||
bool verifyBindings(const Vec3ArrayData& arrayData) const;
|
||||
|
||||
void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName);
|
||||
void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,const char* arrayName);
|
||||
|
||||
void addVertexBufferObjectIfRequired(osg::Array* array);
|
||||
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
|
||||
|
||||
|
||||
PrimitiveSetList _primitives;
|
||||
ArrayData _vertexData;
|
||||
ArrayData _normalData;
|
||||
ArrayData _colorData;
|
||||
ArrayData _secondaryColorData;
|
||||
ArrayData _fogCoordData;
|
||||
ArrayDataList _texCoordList;
|
||||
ArrayDataList _vertexAttribList;
|
||||
osg::ref_ptr<Array> _vertexArray;
|
||||
osg::ref_ptr<Array> _normalArray;
|
||||
osg::ref_ptr<Array> _colorArray;
|
||||
osg::ref_ptr<Array> _secondaryColorArray;
|
||||
osg::ref_ptr<Array> _fogCoordArray;
|
||||
ArrayList _texCoordList;
|
||||
ArrayList _vertexAttribList;
|
||||
|
||||
bool _containsDeprecatedData;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/** Return true if the deprecated use array indicies or BIND_PER_PRIMITIVE binding has been assigned to arrays.*/
|
||||
bool containsDeprecatedData() const { return _containsDeprecatedData; }
|
||||
|
||||
mutable bool _fastPath;
|
||||
bool _fastPathHint;
|
||||
/** fallback for deprecated functionality. Return true if the Geometry contains any array indices or BIND_PER_PRIMITIVE arrays. */
|
||||
bool checkForDeprecatedData();
|
||||
|
||||
ref_ptr<Geometry> _internalOptimizedGeometry;
|
||||
/** fallback for deprecated functionality. Removes any array indices and BIND_PER_PRIMITIVE arrays.*/
|
||||
void fixDeprecatedData();
|
||||
|
||||
/** Same values as Array::Binding.*/
|
||||
enum AttributeBinding
|
||||
{
|
||||
BIND_OFF=0,
|
||||
BIND_OVERALL=1,
|
||||
BIND_PER_PRIMITIVE_SET=2,
|
||||
BIND_PER_PRIMITIVE=3, /// no longer supported
|
||||
BIND_PER_VERTEX=4
|
||||
};
|
||||
|
||||
/** deprecated, use array->setBinding(..). */
|
||||
void setNormalBinding(AttributeBinding ab);
|
||||
AttributeBinding getNormalBinding() const;
|
||||
|
||||
/** deprecated, use array->setBinding(..). */
|
||||
void setColorBinding(AttributeBinding ab);
|
||||
AttributeBinding getColorBinding() const;
|
||||
|
||||
/** deprecated, use array->setBinding(..). */
|
||||
void setSecondaryColorBinding(AttributeBinding ab);
|
||||
AttributeBinding getSecondaryColorBinding() const;
|
||||
|
||||
/** deprecated, use array->setBinding(..). */
|
||||
void setFogCoordBinding(AttributeBinding ab);
|
||||
AttributeBinding getFogCoordBinding() const;
|
||||
|
||||
/** deprecated, use array->setBinding(..). */
|
||||
void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
|
||||
AttributeBinding getVertexAttribBinding(unsigned int index) const;
|
||||
|
||||
/** deprecated, use array->setNormalize(..). */
|
||||
void setVertexAttribNormalize(unsigned int index,GLboolean norm);
|
||||
GLboolean getVertexAttribNormalize(unsigned int index) const;
|
||||
|
||||
#if defined(OSG_USE_DEPRECATED_GEOMETRY_METHODS)
|
||||
/** no longer supported.*/
|
||||
inline void setVertexIndices(IndexArray* array);
|
||||
inline const IndexArray* getVertexIndices() const;
|
||||
|
||||
/** no longer supported.*/
|
||||
inline void setNormalIndices(IndexArray* array);
|
||||
inline const IndexArray* getNormalIndices() const;
|
||||
|
||||
/** no longer supported.*/
|
||||
inline void setColorIndices(IndexArray* array);
|
||||
inline const IndexArray* getColorIndices() const;
|
||||
|
||||
/** no longer supported.*/
|
||||
inline void setSecondaryColorIndices(IndexArray* array);
|
||||
inline const IndexArray* getSecondaryColorIndices() const;
|
||||
|
||||
/** no longer supported.*/
|
||||
inline void setFogCoordIndices(IndexArray* array);
|
||||
inline const IndexArray* getFogCoordIndices() const;
|
||||
|
||||
/** no longer supported.*/
|
||||
inline void setTexCoordIndices(unsigned int unit,IndexArray*);
|
||||
inline const IndexArray* getTexCoordIndices(unsigned int unit) const;
|
||||
|
||||
/** no longer supported.*/
|
||||
inline void setVertexAttribIndices(unsigned int index,IndexArray* array);
|
||||
inline const IndexArray* getVertexAttribIndices(unsigned int index) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
/** Convenience function to be used for creating quad geometry with texture coords.
|
||||
@@ -458,6 +308,89 @@ inline Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& width
|
||||
}
|
||||
|
||||
|
||||
#if defined(OSG_USE_DEPRECATED_GEOMETRY_METHODS)
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
inline void Geometry::setVertexIndices(IndexArray* array)
|
||||
{
|
||||
if (_vertexArray.valid()) { _vertexArray->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setVertexIndicies(..) function failed as there is no vertex array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
|
||||
inline const IndexArray* Geometry::getVertexIndices() const
|
||||
{
|
||||
if (_vertexArray.valid()) return dynamic_cast<IndexArray*>(_vertexArray->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
|
||||
inline void Geometry::setNormalIndices(IndexArray* array)
|
||||
{
|
||||
if (_normalArray.valid()) { _normalArray->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setNormalIndicies(..) function failed as there is no normal array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
inline const IndexArray* Geometry::getNormalIndices() const
|
||||
{
|
||||
if (_normalArray.valid()) return dynamic_cast<IndexArray*>(_normalArray->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
|
||||
inline void Geometry::setColorIndices(IndexArray* array)
|
||||
{
|
||||
if (_colorArray.valid()) { _colorArray->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setColorIndicies(..) function failed as there is no color array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
inline const IndexArray* Geometry::getColorIndices() const
|
||||
{
|
||||
if (_colorArray.valid()) return dynamic_cast<IndexArray*>(_colorArray->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
|
||||
inline void Geometry::setSecondaryColorIndices(IndexArray* array)
|
||||
{
|
||||
if (_secondaryColorArray.valid()) { _secondaryColorArray->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setSecondaryColorArray(..) function failed as there is no secondary color array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
inline const IndexArray* Geometry::getSecondaryColorIndices() const
|
||||
{
|
||||
if (_secondaryColorArray.valid()) return dynamic_cast<IndexArray*>(_secondaryColorArray->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
|
||||
inline void Geometry::setFogCoordIndices(IndexArray* array)
|
||||
{
|
||||
if (_fogCoordArray.valid()) { _fogCoordArray->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setFogCoordIndicies(..) function failed as there is no fog coord array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
inline const IndexArray* Geometry::getFogCoordIndices() const
|
||||
{
|
||||
if (_fogCoordArray.valid()) return dynamic_cast<IndexArray*>(_fogCoordArray->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
|
||||
inline void Geometry::setTexCoordIndices(unsigned int unit,IndexArray* array)
|
||||
{
|
||||
if (unit<_texCoordList.size() && _texCoordList[unit].valid()) { _texCoordList[unit]->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setTexCoordIndices(..) function failed as there is no texcoord array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
inline const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const
|
||||
{
|
||||
if (unit<_texCoordList.size() && _texCoordList[unit].valid()) return dynamic_cast<IndexArray*>(_texCoordList[unit]->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
|
||||
inline void Geometry::setVertexAttribIndices(unsigned int index,IndexArray* array)
|
||||
{
|
||||
if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) { _vertexAttribList[index]->setUserData(array); if (array) _containsDeprecatedData = true; }
|
||||
else { OSG_WARN<<"Geometry::setVertexAttribIndices(..) function failed as there is no vertex attrib array to associate inidices with."<<std::endl; }
|
||||
}
|
||||
inline const IndexArray* Geometry::getVertexAttribIndices(unsigned int index) const
|
||||
{
|
||||
if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) return dynamic_cast<IndexArray*>(_vertexAttribList[index]->getUserData());
|
||||
else return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,7 +44,7 @@ class TemplateAttributeDispatch : public AttributeDispatch
|
||||
TemplateAttributeDispatch(F functionPtr, unsigned int stride):
|
||||
_functionPtr(functionPtr), _stride(stride), _array(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray*)
|
||||
virtual void assign(const GLvoid* array)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
}
|
||||
@@ -59,89 +59,6 @@ class TemplateAttributeDispatch : public AttributeDispatch
|
||||
const T* _array;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class TemplateAttributeWithIndicesDispatch : public AttributeDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (GL_APIENTRY * F) (const T*);
|
||||
|
||||
TemplateAttributeWithIndicesDispatch(F functionPtr, unsigned int stride):
|
||||
_functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray* indices)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
virtual void operator () (unsigned int pos)
|
||||
{
|
||||
_functionPtr(&(_array[_indices->index(pos) * _stride]));
|
||||
}
|
||||
|
||||
F _functionPtr;
|
||||
unsigned int _stride;
|
||||
const T* _array;
|
||||
const IndexArray* _indices;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class TemplateBeginEndAttributeDispatch : public AttributeDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (GLBeginEndAdapter::*F) (const T*);
|
||||
|
||||
TemplateBeginEndAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride):
|
||||
_glBeginEndAdapter(glBeginEndAdapter),
|
||||
_functionPtr(functionPtr), _stride(stride), _array(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray*)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
}
|
||||
|
||||
virtual void operator () (unsigned int pos)
|
||||
{
|
||||
(_glBeginEndAdapter->*_functionPtr)(&(_array[pos*_stride]));
|
||||
}
|
||||
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
F _functionPtr;
|
||||
unsigned int _stride;
|
||||
const T* _array;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class TemplateBeginEndAttributeWithIndicesDispatch : public AttributeDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (GLBeginEndAdapter::*F) (const T*);
|
||||
|
||||
TemplateBeginEndAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride):
|
||||
_glBeginEndAdapter(glBeginEndAdapter),
|
||||
_functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray* indices)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
virtual void operator () (unsigned int pos)
|
||||
{
|
||||
(_glBeginEndAdapter->*_functionPtr)(&(_array[_indices->index(pos) * _stride]));
|
||||
}
|
||||
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
F _functionPtr;
|
||||
unsigned int _stride;
|
||||
const T* _array;
|
||||
const IndexArray* _indices;
|
||||
};
|
||||
|
||||
|
||||
template<typename I, typename T>
|
||||
class TemplateTargetAttributeDispatch : public AttributeDispatch
|
||||
@@ -169,108 +86,18 @@ class TemplateTargetAttributeDispatch : public AttributeDispatch
|
||||
const T* _array;
|
||||
};
|
||||
|
||||
template<typename I, typename T>
|
||||
class TemplateTargetAttributeWithIndicesDispatch : public AttributeDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (GL_APIENTRY * F) (I, const T*);
|
||||
|
||||
TemplateTargetAttributeWithIndicesDispatch(I target, F functionPtr, unsigned int stride):
|
||||
_functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray* indices)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
virtual void operator () (unsigned int pos)
|
||||
{
|
||||
_functionPtr(_target, &(_array[_indices->index(pos) * _stride]));
|
||||
}
|
||||
|
||||
F _functionPtr;
|
||||
I _target;
|
||||
unsigned int _stride;
|
||||
const T* _array;
|
||||
const IndexArray* _indices;
|
||||
};
|
||||
|
||||
|
||||
template<typename I, typename T>
|
||||
class TemplateBeginEndTargetAttributeDispatch : public AttributeDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (GLBeginEndAdapter::*F) (I, const T*);
|
||||
|
||||
TemplateBeginEndTargetAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride):
|
||||
_glBeginEndAdapter(glBeginEndAdapter),
|
||||
_functionPtr(functionPtr), _target(target), _stride(stride), _array(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray*)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
}
|
||||
|
||||
virtual void operator () (unsigned int pos)
|
||||
{
|
||||
(_glBeginEndAdapter->*_functionPtr)(_target, &(_array[pos * _stride]));
|
||||
}
|
||||
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
F _functionPtr;
|
||||
I _target;
|
||||
unsigned int _stride;
|
||||
const T* _array;
|
||||
};
|
||||
|
||||
template<typename I, typename T>
|
||||
class TemplateBeginEndTargetAttributeWithIndicesDispatch : public AttributeDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (GLBeginEndAdapter::*F) (I, const T*);
|
||||
|
||||
TemplateBeginEndTargetAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride):
|
||||
_glBeginEndAdapter(glBeginEndAdapter),
|
||||
_functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {}
|
||||
|
||||
virtual void assign(const GLvoid* array, const IndexArray* indices)
|
||||
{
|
||||
_array = reinterpret_cast<const T*>(array);
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
virtual void operator () (unsigned int pos)
|
||||
{
|
||||
(_glBeginEndAdapter->*_functionPtr)(_target, &(_array[_indices->index(pos) * _stride]));
|
||||
}
|
||||
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
F _functionPtr;
|
||||
I _target;
|
||||
unsigned int _stride;
|
||||
const T* _array;
|
||||
const IndexArray* _indices;
|
||||
};
|
||||
|
||||
class AttributeDispatchMap
|
||||
{
|
||||
public:
|
||||
|
||||
AttributeDispatchMap(GLBeginEndAdapter* glBeginEndAdapter):
|
||||
_glBeginEndAdapter(glBeginEndAdapter) {}
|
||||
AttributeDispatchMap() {}
|
||||
|
||||
template<typename T>
|
||||
void assign(Array::Type type, void (GL_APIENTRY *functionPtr) (const T*), unsigned int stride)
|
||||
{
|
||||
if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1);
|
||||
_attributeDispatchList[type] = functionPtr ? new TemplateAttributeDispatch<T>(functionPtr, stride) : 0;
|
||||
|
||||
if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1);
|
||||
_attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateAttributeWithIndicesDispatch<T>(functionPtr, stride) : 0;
|
||||
}
|
||||
|
||||
template<typename I, typename T>
|
||||
@@ -278,35 +105,11 @@ public:
|
||||
{
|
||||
if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1);
|
||||
_attributeDispatchList[type] = functionPtr ? new TemplateTargetAttributeDispatch<I,T>(target, functionPtr, stride) : 0;
|
||||
|
||||
if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1);
|
||||
_attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateTargetAttributeWithIndicesDispatch<I,T>(target, functionPtr, stride) : 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void assignGLBeginEnd(Array::Type type, void (GLBeginEndAdapter::*functionPtr) (const T*), unsigned int stride)
|
||||
AttributeDispatch* dispatcher(const Array* array)
|
||||
{
|
||||
if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1);
|
||||
_glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndAttributeDispatch<T>(_glBeginEndAdapter, functionPtr, stride) : 0;
|
||||
|
||||
if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1);
|
||||
_glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndAttributeWithIndicesDispatch<T>(_glBeginEndAdapter, functionPtr, stride) : 0;
|
||||
}
|
||||
|
||||
template<typename I, typename T>
|
||||
void targetGLBeginEndAssign(I target, Array::Type type, void (GLBeginEndAdapter::*functionPtr) (I, const T*), unsigned int stride)
|
||||
{
|
||||
if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1);
|
||||
_glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndTargetAttributeDispatch<I,T>(_glBeginEndAdapter, target, functionPtr, stride) : 0;
|
||||
|
||||
if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1);
|
||||
_glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndTargetAttributeWithIndicesDispatch<I,T>(_glBeginEndAdapter, target, functionPtr, stride) : 0;
|
||||
}
|
||||
|
||||
|
||||
AttributeDispatch* dispatcher(bool useGLBeginEndAdapter, const Array* array, const IndexArray* indices)
|
||||
{
|
||||
// OSG_NOTICE<<"dispatcher("<<useGLBeginEndAdapter<<", "<<array<<", "<<indices<<")"<<std::endl;
|
||||
// OSG_NOTICE<<"dispatcher("<<array<<")"<<std::endl;
|
||||
|
||||
if (!array) return 0;
|
||||
|
||||
@@ -314,44 +117,17 @@ public:
|
||||
AttributeDispatch* dispatcher = 0;
|
||||
|
||||
// OSG_NOTICE<<" array->getType()="<<type<<std::endl;
|
||||
// OSG_NOTICE<<" _glBeginEndAttributeDispatchList.size()="<<_glBeginEndAttributeDispatchList.size()<<std::endl;
|
||||
// OSG_NOTICE<<" _glBeginEndAttributeDispatchWithIndicesList.size()="<<_glBeginEndAttributeDispatchWithIndicesList.size()<<std::endl;
|
||||
// OSG_NOTICE<<" _attributeDispatchIndicesList.size()="<<_attributeDispatchList.size()<<std::endl;
|
||||
// OSG_NOTICE<<" _attributeDispatchWithIndicesList.size()="<<_attributeDispatchWithIndicesList.size()<<std::endl;
|
||||
// OSG_NOTICE<<" _attributeDispatchList.size()="<<_attributeDispatchList.size()<<std::endl;
|
||||
|
||||
if (useGLBeginEndAdapter)
|
||||
if ((unsigned int)type<_attributeDispatchList.size())
|
||||
{
|
||||
if (indices)
|
||||
{
|
||||
if ((unsigned int)type<_glBeginEndAttributeDispatchWithIndicesList.size())
|
||||
{
|
||||
dispatcher = _glBeginEndAttributeDispatchWithIndicesList[array->getType()].get();
|
||||
}
|
||||
}
|
||||
else if ((unsigned int)type<_glBeginEndAttributeDispatchList.size())
|
||||
{
|
||||
dispatcher = _glBeginEndAttributeDispatchList[array->getType()].get();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (indices)
|
||||
{
|
||||
if ((unsigned int)type<_attributeDispatchWithIndicesList.size())
|
||||
{
|
||||
dispatcher = _attributeDispatchWithIndicesList[array->getType()].get();
|
||||
}
|
||||
}
|
||||
else if ((unsigned int)type<_attributeDispatchList.size())
|
||||
{
|
||||
dispatcher = _attributeDispatchList[array->getType()].get();
|
||||
}
|
||||
dispatcher = _attributeDispatchList[array->getType()].get();
|
||||
}
|
||||
|
||||
if (dispatcher)
|
||||
{
|
||||
// OSG_NOTICE<<" returning dispatcher="<<dispatcher<<std::endl;
|
||||
dispatcher->assign(array->getDataPointer(), indices);
|
||||
dispatcher->assign(array->getDataPointer());
|
||||
return dispatcher;
|
||||
}
|
||||
else
|
||||
@@ -362,24 +138,18 @@ public:
|
||||
}
|
||||
|
||||
typedef std::vector< ref_ptr<AttributeDispatch> > AttributeDispatchList;
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
AttributeDispatchList _attributeDispatchList;
|
||||
AttributeDispatchList _attributeDispatchWithIndicesList;
|
||||
AttributeDispatchList _glBeginEndAttributeDispatchList;
|
||||
AttributeDispatchList _glBeginEndAttributeDispatchWithIndicesList;
|
||||
};
|
||||
|
||||
ArrayDispatchers::ArrayDispatchers():
|
||||
_initialized(false),
|
||||
_state(0),
|
||||
_glBeginEndAdapter(0),
|
||||
_vertexDispatchers(0),
|
||||
_normalDispatchers(0),
|
||||
_colorDispatchers(0),
|
||||
_secondaryColorDispatchers(0),
|
||||
_fogCoordDispatchers(0),
|
||||
_useVertexAttribAlias(false),
|
||||
_useGLBeginEndAdapter(false)
|
||||
_useVertexAttribAlias(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -410,7 +180,6 @@ ArrayDispatchers::~ArrayDispatchers()
|
||||
void ArrayDispatchers::setState(osg::State* state)
|
||||
{
|
||||
_state = state;
|
||||
_glBeginEndAdapter = &(state->getGLBeginEndAdapter());
|
||||
}
|
||||
|
||||
void ArrayDispatchers::init()
|
||||
@@ -419,21 +188,12 @@ void ArrayDispatchers::init()
|
||||
|
||||
_initialized = true;
|
||||
|
||||
_vertexDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
|
||||
_normalDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
|
||||
_colorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
|
||||
_secondaryColorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
|
||||
_fogCoordDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
|
||||
_vertexDispatchers = new AttributeDispatchMap();
|
||||
_normalDispatchers = new AttributeDispatchMap();
|
||||
_colorDispatchers = new AttributeDispatchMap();
|
||||
_secondaryColorDispatchers = new AttributeDispatchMap();
|
||||
_fogCoordDispatchers = new AttributeDispatchMap();
|
||||
|
||||
_glBeginEndAdapter = &(_state->getGLBeginEndAdapter());
|
||||
_useGLBeginEndAdapter = false;
|
||||
|
||||
_vertexDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Vertex3fv, 3);
|
||||
_vertexDispatchers->assignGLBeginEnd<GLdouble>(Array::Vec3dArrayType, &GLBeginEndAdapter::Vertex3dv, 3);
|
||||
_normalDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Normal3fv, 3);
|
||||
_colorDispatchers->assignGLBeginEnd<GLubyte>(Array::Vec4ubArrayType, &GLBeginEndAdapter::Color4ubv, 4);
|
||||
_colorDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Color3fv, 3);
|
||||
_colorDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec4ArrayType, &GLBeginEndAdapter::Color4fv, 4);
|
||||
|
||||
#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
|
||||
Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true);
|
||||
@@ -469,53 +229,53 @@ void ArrayDispatchers::init()
|
||||
//
|
||||
// With inidices
|
||||
//
|
||||
AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array)
|
||||
{
|
||||
return _useVertexAttribAlias ?
|
||||
vertexAttribDispatcher(_state->getVertexAlias()._location, array, indices) :
|
||||
_vertexDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
vertexAttribDispatcher(_state->getVertexAlias()._location, array) :
|
||||
_vertexDispatchers->dispatcher(array);
|
||||
}
|
||||
|
||||
AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array)
|
||||
{
|
||||
return _useVertexAttribAlias ?
|
||||
vertexAttribDispatcher(_state->getNormalAlias()._location, array, indices) :
|
||||
_normalDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
vertexAttribDispatcher(_state->getNormalAlias()._location, array) :
|
||||
_normalDispatchers->dispatcher(array);
|
||||
}
|
||||
|
||||
AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array)
|
||||
{
|
||||
return _useVertexAttribAlias ?
|
||||
vertexAttribDispatcher(_state->getColorAlias()._location, array, indices) :
|
||||
_colorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
vertexAttribDispatcher(_state->getColorAlias()._location, array) :
|
||||
_colorDispatchers->dispatcher(array);
|
||||
}
|
||||
|
||||
AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array)
|
||||
{
|
||||
return _useVertexAttribAlias ?
|
||||
vertexAttribDispatcher(_state->getSecondaryColorAlias()._location, array, indices) :
|
||||
_secondaryColorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
vertexAttribDispatcher(_state->getSecondaryColorAlias()._location, array) :
|
||||
_secondaryColorDispatchers->dispatcher(array);
|
||||
}
|
||||
|
||||
AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array)
|
||||
{
|
||||
return _useVertexAttribAlias ?
|
||||
vertexAttribDispatcher(_state->getFogCoordAlias()._location, array, indices) :
|
||||
_fogCoordDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
vertexAttribDispatcher(_state->getFogCoordAlias()._location, array) :
|
||||
_fogCoordDispatchers->dispatcher(array);
|
||||
}
|
||||
|
||||
AttributeDispatch* ArrayDispatchers::texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::texCoordDispatcher(unsigned int unit, Array* array)
|
||||
{
|
||||
if (_useVertexAttribAlias) return vertexAttribDispatcher(_state->getTexCoordAliasList()[unit]._location, array, indices);
|
||||
if (_useVertexAttribAlias) return vertexAttribDispatcher(_state->getTexCoordAliasList()[unit]._location, array);
|
||||
|
||||
if (unit>=_texCoordDispatchers.size()) assignTexCoordDispatchers(unit);
|
||||
return _texCoordDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
return _texCoordDispatchers[unit]->dispatcher(array);
|
||||
}
|
||||
|
||||
AttributeDispatch* ArrayDispatchers::vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices)
|
||||
AttributeDispatch* ArrayDispatchers::vertexAttribDispatcher(unsigned int unit, Array* array)
|
||||
{
|
||||
if (unit>=_vertexAttribDispatchers.size()) assignVertexAttribDispatchers(unit);
|
||||
return _vertexAttribDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices);
|
||||
return _vertexAttribDispatchers[unit]->dispatcher(array);
|
||||
}
|
||||
|
||||
void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
|
||||
@@ -526,7 +286,7 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
|
||||
|
||||
for(unsigned int i=_texCoordDispatchers.size(); i<=unit; ++i)
|
||||
{
|
||||
_texCoordDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter));
|
||||
_texCoordDispatchers.push_back(new AttributeDispatchMap());
|
||||
AttributeDispatchMap& texCoordDispatcher = *_texCoordDispatchers[i];
|
||||
if (i==0)
|
||||
{
|
||||
@@ -536,10 +296,6 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
|
||||
texCoordDispatcher.assign<GLfloat>(Array::Vec3ArrayType, glTexCoord3fv, 3);
|
||||
texCoordDispatcher.assign<GLfloat>(Array::Vec4ArrayType, glTexCoord4fv, 4);
|
||||
#endif
|
||||
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::FloatArrayType, &GLBeginEndAdapter::TexCoord1fv, 1);
|
||||
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec2ArrayType, &GLBeginEndAdapter::TexCoord2fv, 2);
|
||||
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::TexCoord3fv, 3);
|
||||
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec4ArrayType, &GLBeginEndAdapter::TexCoord4fv, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -549,10 +305,6 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
|
||||
texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec3ArrayType, extensions->_glMultiTexCoord3fv, 3);
|
||||
texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, extensions->_glMultiTexCoord4fv, 4);
|
||||
#endif
|
||||
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::FloatArrayType, &GLBeginEndAdapter::MultiTexCoord1fv, 1);
|
||||
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec2ArrayType, &GLBeginEndAdapter::MultiTexCoord2fv, 2);
|
||||
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec3ArrayType, &GLBeginEndAdapter::MultiTexCoord3fv, 3);
|
||||
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, &GLBeginEndAdapter::MultiTexCoord4fv, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,16 +316,12 @@ void ArrayDispatchers::assignVertexAttribDispatchers(unsigned int unit)
|
||||
|
||||
for(unsigned int i=_vertexAttribDispatchers.size(); i<=unit; ++i)
|
||||
{
|
||||
_vertexAttribDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter));
|
||||
_vertexAttribDispatchers.push_back(new AttributeDispatchMap());
|
||||
AttributeDispatchMap& vertexAttribDispatcher = *_vertexAttribDispatchers[i];
|
||||
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::FloatArrayType, extensions->_glVertexAttrib1fv, 1);
|
||||
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec2ArrayType, extensions->_glVertexAttrib2fv, 2);
|
||||
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec3ArrayType, extensions->_glVertexAttrib3fv, 3);
|
||||
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec4ArrayType, extensions->_glVertexAttrib4fv, 4);
|
||||
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::FloatArrayType, &GLBeginEndAdapter::VertexAttrib1fv, 1);
|
||||
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::Vec2ArrayType, &GLBeginEndAdapter::VertexAttrib2fv, 2);
|
||||
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::Vec3ArrayType, &GLBeginEndAdapter::VertexAttrib3fv, 3);
|
||||
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::Vec4ArrayType, &GLBeginEndAdapter::VertexAttrib4fv, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,9 +331,6 @@ void ArrayDispatchers::reset()
|
||||
|
||||
_useVertexAttribAlias = false;
|
||||
|
||||
_useGLBeginEndAdapter = false;
|
||||
_glBeginEndAdapter->reset();
|
||||
|
||||
for(ActiveDispatchList::iterator itr = _activeDispatchList.begin();
|
||||
itr != _activeDispatchList.end();
|
||||
++itr)
|
||||
|
||||
@@ -257,7 +257,6 @@ SET(TARGET_SRC
|
||||
FrontFace.cpp
|
||||
Geode.cpp
|
||||
Geometry.cpp
|
||||
GeometryNew.cpp
|
||||
GL2Extensions.cpp
|
||||
GLExtensions.cpp
|
||||
GLBeginEndAdapter.cpp
|
||||
|
||||
@@ -44,4 +44,6 @@
|
||||
#cmakedefine OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
#cmakedefine OSG_GL_FIXED_FUNCTION_AVAILABLE
|
||||
|
||||
#cmakedefine OSG_USE_DEPRECATED_GEOMETRY_METHODS
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -51,6 +52,10 @@ bool Geode::addDrawable( Drawable *drawable )
|
||||
{
|
||||
if (drawable /* && !containsDrawable(drawable)*/)
|
||||
{
|
||||
// fallback for handling geometry with deprecated data
|
||||
osg::Geometry* geometry = drawable->asGeometry();
|
||||
if (geometry && geometry->containsDeprecatedData()) geometry->fixDeprecatedData();
|
||||
|
||||
// note ref_ptr<> automatically handles incrementing drawable's reference count.
|
||||
_drawables.push_back(drawable);
|
||||
|
||||
|
||||
2751
src/osg/Geometry.cpp
2751
src/osg/Geometry.cpp
File diff suppressed because it is too large
Load Diff
@@ -52,7 +52,7 @@ void GeometryCostEstimator::calibrate(osg::RenderInfo& renderInfo)
|
||||
CostPair GeometryCostEstimator::estimateCompileCost(const osg::Geometry* geometry) const
|
||||
{
|
||||
|
||||
bool usesVBO = geometry->getUseVertexBufferObjects() && geometry->areFastPathsUsed();
|
||||
bool usesVBO = geometry->getUseVertexBufferObjects();
|
||||
bool usesDL = !usesVBO && geometry->getUseDisplayList() && geometry->getSupportsDisplayList();
|
||||
|
||||
if (usesVBO || usesDL)
|
||||
|
||||
@@ -40,8 +40,6 @@ MorphGeometry::MorphGeometry(const osg::Geometry& b) :
|
||||
setUpdateCallback(new UpdateVertex);
|
||||
setDataVariance(osg::Object::DYNAMIC);
|
||||
setUseVertexBufferObjects(true);
|
||||
if (b.getInternalOptimizedGeometry())
|
||||
computeInternalOptimizedGeometry();
|
||||
}
|
||||
|
||||
MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop) :
|
||||
@@ -55,8 +53,6 @@ MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop)
|
||||
{
|
||||
setUseDisplayList(false);
|
||||
setUseVertexBufferObjects(true);
|
||||
if (b.getInternalOptimizedGeometry())
|
||||
computeInternalOptimizedGeometry();
|
||||
}
|
||||
|
||||
void MorphGeometry::transformSoftwareMethod()
|
||||
@@ -65,8 +61,6 @@ void MorphGeometry::transformSoftwareMethod()
|
||||
{
|
||||
// See if we have an internal optimized geometry
|
||||
osg::Geometry* morphGeometry = this;
|
||||
if (_internalOptimizedGeometry.valid())
|
||||
morphGeometry = _internalOptimizedGeometry.get();
|
||||
|
||||
osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(morphGeometry->getVertexArray());
|
||||
if (pos && _positionSource.size() != pos->size())
|
||||
@@ -134,9 +128,7 @@ void MorphGeometry::transformSoftwareMethod()
|
||||
if (_morphTargets[i].getWeight() > 0)
|
||||
{
|
||||
// See if any the targets use the internal optimized geometry
|
||||
osg::Geometry* targetGeometry = _morphTargets[i].getGeometry()->getInternalOptimizedGeometry();
|
||||
if (!targetGeometry)
|
||||
targetGeometry = _morphTargets[i].getGeometry();
|
||||
osg::Geometry* targetGeometry = _morphTargets[i].getGeometry();
|
||||
|
||||
osg::Vec3Array* targetPos = dynamic_cast<osg::Vec3Array*>(targetGeometry->getVertexArray());
|
||||
osg::Vec3Array* targetNormals = dynamic_cast<osg::Vec3Array*>(targetGeometry->getNormalArray());
|
||||
|
||||
@@ -153,28 +153,28 @@ void RigGeometry::copyFrom(osg::Geometry& from)
|
||||
if (!copyToSelf) target.setVertexArray(from.getVertexArray());
|
||||
}
|
||||
|
||||
target.setNormalBinding(from.getNormalBinding());
|
||||
if (from.getNormalArray())
|
||||
{
|
||||
if (!copyToSelf) target.setNormalArray(from.getNormalArray());
|
||||
target.setNormalBinding(from.getNormalBinding());
|
||||
}
|
||||
|
||||
target.setColorBinding(from.getColorBinding());
|
||||
if (from.getColorArray())
|
||||
{
|
||||
if (!copyToSelf) target.setColorArray(from.getColorArray());
|
||||
target.setColorBinding(from.getColorBinding());
|
||||
}
|
||||
|
||||
target.setSecondaryColorBinding(from.getSecondaryColorBinding());
|
||||
if (from.getSecondaryColorArray())
|
||||
{
|
||||
if (!copyToSelf) target.setSecondaryColorArray(from.getSecondaryColorArray());
|
||||
target.setSecondaryColorBinding(from.getSecondaryColorBinding());
|
||||
}
|
||||
|
||||
target.setFogCoordBinding(from.getFogCoordBinding());
|
||||
if (from.getFogCoordArray())
|
||||
{
|
||||
if (!copyToSelf) target.setFogCoordArray(from.getFogCoordArray());
|
||||
target.setFogCoordBinding(from.getFogCoordBinding());
|
||||
}
|
||||
|
||||
for(unsigned int ti=0;ti<from.getNumTexCoordArrays();++ti)
|
||||
@@ -185,13 +185,13 @@ void RigGeometry::copyFrom(osg::Geometry& from)
|
||||
}
|
||||
}
|
||||
|
||||
ArrayDataList& arrayList = from.getVertexAttribArrayList();
|
||||
osg::Geometry::ArrayList& arrayList = from.getVertexAttribArrayList();
|
||||
for(unsigned int vi=0;vi< arrayList.size();++vi)
|
||||
{
|
||||
ArrayData& arrayData = arrayList[vi];
|
||||
if (arrayData.array.valid())
|
||||
osg::Array* array = arrayList[vi].get();
|
||||
if (array)
|
||||
{
|
||||
if (!copyToSelf) target.setVertexAttribData(vi,arrayData);
|
||||
if (!copyToSelf) target.setVertexAttribArray(vi,array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ bool RigTransformHardware::init(RigGeometry& geom)
|
||||
std::stringstream ss;
|
||||
ss << "boneWeight" << i;
|
||||
program->addBindAttribLocation(ss.str(), attribIndex + i);
|
||||
geom.setVertexAttribData(attribIndex + i, osg::Geometry::ArrayData(getVertexAttrib(i),osg::Geometry::BIND_PER_VERTEX));
|
||||
geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i));
|
||||
OSG_INFO << "set vertex attrib " << ss.str() << std::endl;
|
||||
}
|
||||
program->addShader(_shader.get());
|
||||
|
||||
@@ -597,11 +597,11 @@ void BumpMapping::prepareGeometry(osg::Geometry* geo)
|
||||
osg::ref_ptr<osgUtil::TangentSpaceGenerator> tsg = new osgUtil::TangentSpaceGenerator;
|
||||
tsg->generate(geo, _normal_unit);
|
||||
if (!geo->getVertexAttribArray(6))
|
||||
geo->setVertexAttribData(6, osg::Geometry::ArrayData(tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX,GL_FALSE));
|
||||
geo->setVertexAttribArray(6, tsg->getTangentArray());
|
||||
if (!geo->getVertexAttribArray(7))
|
||||
geo->setVertexAttribData(7, osg::Geometry::ArrayData(tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE));
|
||||
geo->setVertexAttribArray(7, tsg->getBinormalArray());
|
||||
if (!geo->getVertexAttribArray(15))
|
||||
geo->setVertexAttribData(15, osg::Geometry::ArrayData(tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE));
|
||||
geo->setVertexAttribArray(15, tsg->getNormalArray());
|
||||
}
|
||||
|
||||
void BumpMapping::prepareNode(osg::Node* node)
|
||||
|
||||
@@ -758,8 +758,8 @@ void Geode::ProcessGeometry(ostream& fout, const unsigned int ioffset)
|
||||
if (NULL != pVertexArray)
|
||||
{
|
||||
const unsigned int iNumVertices = pVertexArray->getNumElements(); // size();
|
||||
const osg::IndexArray *pVertexIndices = pGeometry->getVertexIndices();
|
||||
const osg::IndexArray * pTexIndices = pGeometry->getTexCoordIndices(0);
|
||||
const osg::IndexArray *pVertexIndices = 0;
|
||||
const osg::IndexArray * pTexIndices = 0;
|
||||
const osg::Vec2 *pTexCoords = NULL;
|
||||
fout << "OBJECT poly" << std::endl;
|
||||
fout << "name \"" << getName() << "\"" << std::endl;
|
||||
|
||||
@@ -129,40 +129,52 @@ void Geometry::write(DataOutputStream* out){
|
||||
out->writeArray(getFogCoordIndices());
|
||||
}
|
||||
// Write texture coord arrays
|
||||
Geometry::ArrayDataList& tcal = getTexCoordArrayList();
|
||||
Geometry::ArrayList& tcal = getTexCoordArrayList();
|
||||
out->writeInt(tcal.size());
|
||||
unsigned int j;
|
||||
for(j=0;j<tcal.size();j++)
|
||||
{
|
||||
// Write coords if valid
|
||||
out->writeBool(tcal[j].array.valid());
|
||||
if (tcal[j].array.valid()){
|
||||
out->writeArray(tcal[j].array.get());
|
||||
out->writeBool(tcal[j].valid());
|
||||
if (tcal[j].valid()){
|
||||
out->writeArray(tcal[j].get());
|
||||
}
|
||||
|
||||
// Write indices if valid
|
||||
out->writeBool(tcal[j].indices.valid());
|
||||
if (tcal[j].indices.valid()){
|
||||
out->writeArray(tcal[j].indices.get());
|
||||
const osg::IndexArray* indices = getTexCoordIndices(j);
|
||||
out->writeBool(indices!=0);
|
||||
if (indices!=0){
|
||||
out->writeArray(indices);
|
||||
}
|
||||
}
|
||||
|
||||
// Write vertex attributes
|
||||
Geometry::ArrayDataList& vaal = getVertexAttribArrayList();
|
||||
Geometry::ArrayList& vaal = getVertexAttribArrayList();
|
||||
out->writeInt(vaal.size());
|
||||
for(j=0;j<vaal.size();j++)
|
||||
{
|
||||
// Write coords if valid
|
||||
const osg::Geometry::ArrayData& arrayData = vaal[j];
|
||||
out->writeBinding(arrayData.binding);
|
||||
out->writeBool(arrayData.normalize==GL_TRUE);
|
||||
out->writeBool(arrayData.array.valid());
|
||||
if (arrayData.array.valid()){
|
||||
out->writeArray(arrayData.array.get());
|
||||
const osg::Array* array = vaal[j].get();
|
||||
if (array)
|
||||
{
|
||||
out->writeBinding(static_cast<osg::Geometry::AttributeBinding>(array->getBinding()));
|
||||
out->writeBool(array->getNormalize());
|
||||
out->writeBool(true);
|
||||
out->writeArray(array);
|
||||
|
||||
// Write indices if valid
|
||||
const osg::IndexArray* indices = getVertexAttribIndices(j);
|
||||
out->writeBool(indices!=0);
|
||||
if (indices!=0){
|
||||
out->writeArray(indices);
|
||||
}
|
||||
}
|
||||
// Write indices if valid
|
||||
out->writeBool(arrayData.indices.valid());
|
||||
if (arrayData.indices.valid()){
|
||||
out->writeArray(arrayData.indices.get());
|
||||
else
|
||||
{
|
||||
out->writeBinding(BIND_OFF);
|
||||
out->writeBool(false);
|
||||
out->writeBool(false);
|
||||
out->writeBool(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,19 +527,6 @@ void POVWriterNodeVisitor::processGeometry( const Geometry *g,
|
||||
if( g->getVertexArray() == NULL || g->getVertexArray()->getNumElements() == 0 )
|
||||
return;
|
||||
|
||||
if(( g->getVertexIndices() != NULL &&
|
||||
g->getVertexIndices()->getNumElements() != 0 ) ||
|
||||
( g->getNormalIndices() != NULL &&
|
||||
g->getNormalIndices()->getNumElements() != 0 ) ||
|
||||
( g->getTexCoordIndices(0) != NULL &&
|
||||
g->getTexCoordIndices(0)->getNumElements() != 0 ))
|
||||
{
|
||||
notify( WARN ) << "POV Writer WARNING: "
|
||||
"Geometry with indices is not " << endl <<
|
||||
"supported yet by POV plugin. Skipping geometry." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// mesh2
|
||||
_fout << "mesh2" << endl;
|
||||
_fout << "{" << endl;
|
||||
|
||||
@@ -448,14 +448,6 @@ void EdgeCollector::setGeometry(osg::Geometry* geometry)
|
||||
{
|
||||
_geometry = geometry;
|
||||
|
||||
// check to see if vertex attributes indices exists, if so expand them to remove them
|
||||
if (_geometry->suitableForOptimization())
|
||||
{
|
||||
// removing coord indices
|
||||
OSG_INFO<<"EdgeCollector::setGeometry(..): Removing attribute indices"<<std::endl;
|
||||
_geometry->copyToAndOptimize(*_geometry);
|
||||
}
|
||||
|
||||
unsigned int numVertices = geometry->getVertexArray()->getNumElements();
|
||||
|
||||
_originalPointList.resize(numVertices);
|
||||
|
||||
@@ -279,17 +279,7 @@ void IndexMeshVisitor::makeMesh(Geometry& geom)
|
||||
// nothing to index
|
||||
if (!numSurfacePrimitives || !numNonIndexedPrimitives) return;
|
||||
|
||||
// check to see if vertex attributes indices exists, if so expand them to remove them
|
||||
if (geom.suitableForOptimization())
|
||||
{
|
||||
// removing coord indices
|
||||
OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Removing attribute indices"<<std::endl;
|
||||
geom.copyToAndOptimize(geom);
|
||||
}
|
||||
|
||||
|
||||
// compute duplicate vertices
|
||||
|
||||
typedef std::vector<unsigned int> IndexList;
|
||||
unsigned int numVertices = geom.getVertexArray()->getNumElements();
|
||||
IndexList indices(numVertices);
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
using namespace osgUtil;
|
||||
|
||||
// #define GEOMETRYDEPRECATED
|
||||
|
||||
void Optimizer::reset()
|
||||
{
|
||||
@@ -1684,33 +1685,18 @@ struct LessGeometry
|
||||
if (lhs->getStateSet()<rhs->getStateSet()) return true;
|
||||
if (rhs->getStateSet()<lhs->getStateSet()) return false;
|
||||
|
||||
if (rhs->getVertexIndices()) { if (!lhs->getVertexIndices()) return true; }
|
||||
else if (lhs->getVertexIndices()) return false;
|
||||
|
||||
if (lhs->getNormalBinding()<rhs->getNormalBinding()) return true;
|
||||
if (rhs->getNormalBinding()<lhs->getNormalBinding()) return false;
|
||||
|
||||
if (rhs->getNormalIndices()) { if (!lhs->getNormalIndices()) return true; }
|
||||
else if (lhs->getNormalIndices()) return false;
|
||||
|
||||
if (lhs->getColorBinding()<rhs->getColorBinding()) return true;
|
||||
if (rhs->getColorBinding()<lhs->getColorBinding()) return false;
|
||||
|
||||
if (rhs->getColorIndices()) { if (!lhs->getColorIndices()) return true; }
|
||||
else if (lhs->getColorIndices()) return false;
|
||||
|
||||
if (lhs->getSecondaryColorBinding()<rhs->getSecondaryColorBinding()) return true;
|
||||
if (rhs->getSecondaryColorBinding()<lhs->getSecondaryColorBinding()) return false;
|
||||
|
||||
if (rhs->getSecondaryColorIndices()) { if (!lhs->getSecondaryColorIndices()) return true; }
|
||||
else if (lhs->getSecondaryColorIndices()) return false;
|
||||
|
||||
if (lhs->getFogCoordBinding()<rhs->getFogCoordBinding()) return true;
|
||||
if (rhs->getFogCoordBinding()<lhs->getFogCoordBinding()) return false;
|
||||
|
||||
if (rhs->getFogCoordIndices()) { if (!lhs->getFogCoordIndices()) return true; }
|
||||
else if (lhs->getFogCoordIndices()) return false;
|
||||
|
||||
if (lhs->getNumTexCoordArrays()<rhs->getNumTexCoordArrays()) return true;
|
||||
if (rhs->getNumTexCoordArrays()<lhs->getNumTexCoordArrays()) return false;
|
||||
|
||||
@@ -1724,9 +1710,6 @@ struct LessGeometry
|
||||
if (!lhs->getTexCoordArray(i)) return true;
|
||||
}
|
||||
else if (lhs->getTexCoordArray(i)) return false;
|
||||
|
||||
if (rhs->getTexCoordIndices(i)) { if (!lhs->getTexCoordIndices(i)) return true; }
|
||||
else if (lhs->getTexCoordIndices(i)) return false;
|
||||
}
|
||||
|
||||
for(i=0;i<lhs->getNumVertexAttribArrays();++i)
|
||||
@@ -1736,9 +1719,6 @@ struct LessGeometry
|
||||
if (!lhs->getVertexAttribArray(i)) return true;
|
||||
}
|
||||
else if (lhs->getVertexAttribArray(i)) return false;
|
||||
|
||||
if (rhs->getVertexAttribIndices(i)) { if (!lhs->getVertexAttribIndices(i)) return true; }
|
||||
else if (lhs->getVertexAttribIndices(i)) return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1828,7 +1808,10 @@ void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode)
|
||||
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
|
||||
if (geom && isOperationPermissibleForObject(geom))
|
||||
{
|
||||
geom->computeCorrectBindingsAndArraySizes();
|
||||
#ifdef GEOMETRYDEPRECATED
|
||||
geom1829
|
||||
->computeCorrectBindingsAndArraySizes();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1836,6 +1819,7 @@ void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode)
|
||||
|
||||
void Optimizer::MakeFastGeometryVisitor::checkGeode(osg::Geode& geode)
|
||||
{
|
||||
// GeometryDeprecated CAN REMOVED
|
||||
if (isOperationPermissibleForObject(&geode))
|
||||
{
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
@@ -1843,9 +1827,9 @@ void Optimizer::MakeFastGeometryVisitor::checkGeode(osg::Geode& geode)
|
||||
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
|
||||
if (geom && isOperationPermissibleForObject(geom))
|
||||
{
|
||||
if (!geom->areFastPathsUsed() && !geom->getInternalOptimizedGeometry())
|
||||
if (geom->checkForDeprecatedData())
|
||||
{
|
||||
geom->computeInternalOptimizedGeometry();
|
||||
geom->fixDeprecatedData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2457,7 +2441,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
MergeArrayVisitor merger;
|
||||
|
||||
unsigned int base = 0;
|
||||
unsigned int vbase = lhs.getVertexArray() ? lhs.getVertexArray()->getNumElements() : 0;
|
||||
if (lhs.getVertexArray() && rhs.getVertexArray())
|
||||
{
|
||||
|
||||
@@ -2473,23 +2456,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
lhs.setVertexArray(rhs.getVertexArray());
|
||||
}
|
||||
|
||||
if (lhs.getVertexIndices() && rhs.getVertexIndices())
|
||||
{
|
||||
|
||||
base = lhs.getVertexIndices()->getNumElements();
|
||||
if (!merger.merge(lhs.getVertexIndices(),rhs.getVertexIndices(),vbase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: vertex indices not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
else if (rhs.getVertexIndices())
|
||||
{
|
||||
base = 0;
|
||||
lhs.setVertexIndices(rhs.getVertexIndices());
|
||||
}
|
||||
|
||||
|
||||
unsigned int nbase = lhs.getNormalArray() ? lhs.getNormalArray()->getNumElements() : 0;
|
||||
if (lhs.getNormalArray() && rhs.getNormalArray() && lhs.getNormalBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getNormalArray(),rhs.getNormalArray()))
|
||||
@@ -2502,21 +2469,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
lhs.setNormalArray(rhs.getNormalArray());
|
||||
}
|
||||
|
||||
if (lhs.getNormalIndices() && rhs.getNormalIndices() && lhs.getNormalBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getNormalIndices(),rhs.getNormalIndices(),nbase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: Vertex Array not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
else if (rhs.getNormalIndices())
|
||||
{
|
||||
// this assignment makes the assumption that lhs.NormalArray is empty as well and NormalIndices
|
||||
lhs.setNormalIndices(rhs.getNormalIndices());
|
||||
}
|
||||
|
||||
|
||||
unsigned int cbase = lhs.getColorArray() ? lhs.getColorArray()->getNumElements() : 0;
|
||||
if (lhs.getColorArray() && rhs.getColorArray() && lhs.getColorBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getColorArray(),rhs.getColorArray()))
|
||||
@@ -2529,20 +2482,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
lhs.setColorArray(rhs.getColorArray());
|
||||
}
|
||||
|
||||
if (lhs.getColorIndices() && rhs.getColorIndices() && lhs.getColorBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getColorIndices(),rhs.getColorIndices(),cbase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: color indices not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
else if (rhs.getColorIndices())
|
||||
{
|
||||
// this assignment makes the assumption that lhs.ColorArray is empty as well and ColorIndices
|
||||
lhs.setColorIndices(rhs.getColorIndices());
|
||||
}
|
||||
|
||||
unsigned int scbase = lhs.getSecondaryColorArray() ? lhs.getSecondaryColorArray()->getNumElements() : 0;
|
||||
if (lhs.getSecondaryColorArray() && rhs.getSecondaryColorArray() && lhs.getSecondaryColorBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getSecondaryColorArray(),rhs.getSecondaryColorArray()))
|
||||
@@ -2555,20 +2494,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
lhs.setSecondaryColorArray(rhs.getSecondaryColorArray());
|
||||
}
|
||||
|
||||
if (lhs.getSecondaryColorIndices() && rhs.getSecondaryColorIndices() && lhs.getSecondaryColorBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getSecondaryColorIndices(),rhs.getSecondaryColorIndices(),scbase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: secondary color indices not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
else if (rhs.getSecondaryColorIndices())
|
||||
{
|
||||
// this assignment makes the assumption that lhs.SecondaryColorArray is empty as well and SecondaryColorIndices
|
||||
lhs.setSecondaryColorIndices(rhs.getSecondaryColorIndices());
|
||||
}
|
||||
|
||||
unsigned int fcbase = lhs.getFogCoordArray() ? lhs.getFogCoordArray()->getNumElements() : 0;
|
||||
if (lhs.getFogCoordArray() && rhs.getFogCoordArray() && lhs.getFogCoordBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getFogCoordArray(),rhs.getFogCoordArray()))
|
||||
@@ -2581,53 +2506,22 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
lhs.setFogCoordArray(rhs.getFogCoordArray());
|
||||
}
|
||||
|
||||
if (lhs.getFogCoordIndices() && rhs.getFogCoordIndices() && lhs.getFogCoordBinding()!=osg::Geometry::BIND_OVERALL)
|
||||
{
|
||||
if (!merger.merge(lhs.getFogCoordIndices(),rhs.getFogCoordIndices(),fcbase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: fog coord indices not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
else if (rhs.getFogCoordIndices())
|
||||
{
|
||||
// this assignment makes the assumption that lhs.FogCoordArray is empty as well and FogCoordIndices
|
||||
lhs.setFogCoordIndices(rhs.getFogCoordIndices());
|
||||
}
|
||||
|
||||
|
||||
unsigned int unit;
|
||||
for(unit=0;unit<lhs.getNumTexCoordArrays();++unit)
|
||||
{
|
||||
unsigned int tcbase = lhs.getTexCoordArray(unit) ? lhs.getTexCoordArray(unit)->getNumElements() : 0;
|
||||
if (!merger.merge(lhs.getTexCoordArray(unit),rhs.getTexCoordArray(unit)))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: tex coord array not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
|
||||
if (lhs.getTexCoordIndices(unit) && rhs.getTexCoordIndices(unit))
|
||||
{
|
||||
if (!merger.merge(lhs.getTexCoordIndices(unit),rhs.getTexCoordIndices(unit),tcbase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: tex coord indices not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(unit=0;unit<lhs.getNumVertexAttribArrays();++unit)
|
||||
{
|
||||
unsigned int vabase = lhs.getVertexAttribArray(unit) ? lhs.getVertexAttribArray(unit)->getNumElements() : 0;
|
||||
if (!merger.merge(lhs.getVertexAttribArray(unit),rhs.getVertexAttribArray(unit)))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: vertex attrib array not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
|
||||
if (lhs.getVertexAttribIndices(unit) && rhs.getVertexAttribIndices(unit))
|
||||
{
|
||||
if (!merger.merge(lhs.getVertexAttribIndices(unit),rhs.getVertexAttribIndices(unit),vabase))
|
||||
{
|
||||
OSG_DEBUG << "MergeGeometry: vertex attrib indices not merged. Some data may be lost." <<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -543,8 +543,7 @@ bool RenderBin::getStats(Statistics& stats) const
|
||||
const Geometry* geom = dw->asGeometry();
|
||||
if (geom)
|
||||
{
|
||||
if (geom->areFastPathsUsed())
|
||||
stats.addFastDrawable();
|
||||
stats.addFastDrawable();
|
||||
}
|
||||
|
||||
if (rl->_modelview.get())
|
||||
@@ -576,8 +575,7 @@ bool RenderBin::getStats(Statistics& stats) const
|
||||
const Geometry* geom = dw->asGeometry();
|
||||
if (geom)
|
||||
{
|
||||
if (geom->areFastPathsUsed())
|
||||
stats.addFastDrawable();
|
||||
stats.addFastDrawable();
|
||||
}
|
||||
|
||||
if (rl->_modelview.get()) stats.addMatrix(); // number of matrices
|
||||
|
||||
@@ -1419,14 +1419,6 @@ void EdgeCollapse::setGeometry(osg::Geometry* geometry, const Simplifier::IndexL
|
||||
{
|
||||
_geometry = geometry;
|
||||
|
||||
// check to see if vertex attributes indices exists, if so expand them to remove them
|
||||
if (_geometry->suitableForOptimization())
|
||||
{
|
||||
// removing coord indices
|
||||
OSG_INFO<<"EdgeCollapse::setGeometry(..): Removing attribute indices"<<std::endl;
|
||||
_geometry->copyToAndOptimize(*_geometry);
|
||||
}
|
||||
|
||||
// check to see if vertex attributes indices exists, if so expand them to remove them
|
||||
if (_geometry->containsSharedArrays())
|
||||
{
|
||||
|
||||
@@ -143,10 +143,8 @@ static void smooth_old(osg::Geometry& geom)
|
||||
nitr->normalize();
|
||||
}
|
||||
geom.setNormalArray( normals );
|
||||
geom.setNormalIndices( geom.getVertexIndices() );
|
||||
geom.setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
|
||||
geom.dirtyDisplayList();
|
||||
}
|
||||
|
||||
|
||||
@@ -278,11 +278,8 @@ void StatsVisitor::apply(osg::Drawable& drawable)
|
||||
++_numInstancedGeometry;
|
||||
_geometrySet.insert(geometry);
|
||||
|
||||
if (geometry->areFastPathsUsed())
|
||||
{
|
||||
++_numInstancedFastGeometry;
|
||||
_fastGeometrySet.insert(geometry);
|
||||
}
|
||||
++_numInstancedFastGeometry;
|
||||
_fastGeometrySet.insert(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ TangentSpaceGenerator::TangentSpaceGenerator()
|
||||
B_(new osg::Vec4Array),
|
||||
N_(new osg::Vec4Array)
|
||||
{
|
||||
T_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false);
|
||||
B_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false);
|
||||
N_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false);
|
||||
}
|
||||
|
||||
TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator ©, const osg::CopyOp ©op)
|
||||
@@ -23,14 +26,6 @@ TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator ©,
|
||||
|
||||
void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit)
|
||||
{
|
||||
// check to see if vertex attributes indices exists, if so expand them to remove them
|
||||
if (geo->suitableForOptimization())
|
||||
{
|
||||
// removing coord indices so we don't have to deal with them in the binormal code.
|
||||
OSG_INFO<<"TangentSpaceGenerator::generate(Geometry*,int): Removing attribute indices"<<std::endl;
|
||||
geo->copyToAndOptimize(*geo);
|
||||
}
|
||||
|
||||
const osg::Array *vx = geo->getVertexArray();
|
||||
const osg::Array *nx = geo->getNormalArray();
|
||||
const osg::Array *tx = geo->getTexCoordArray(normal_map_tex_unit);
|
||||
@@ -39,21 +34,9 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit
|
||||
|
||||
|
||||
unsigned int vertex_count = vx->getNumElements();
|
||||
if (geo->getVertexIndices() == NULL) {
|
||||
T_->assign(vertex_count, osg::Vec4());
|
||||
B_->assign(vertex_count, osg::Vec4());
|
||||
N_->assign(vertex_count, osg::Vec4());
|
||||
} else {
|
||||
unsigned int index_count = geo->getVertexIndices()->getNumElements();
|
||||
T_->assign(index_count, osg::Vec4());
|
||||
B_->assign(index_count, osg::Vec4());
|
||||
N_->assign(index_count, osg::Vec4());
|
||||
indices_ = new osg::UIntArray();
|
||||
unsigned int i;
|
||||
for (i=0;i<index_count;i++) {
|
||||
indices_->push_back(i);
|
||||
}
|
||||
}
|
||||
T_->assign(vertex_count, osg::Vec4());
|
||||
B_->assign(vertex_count, osg::Vec4());
|
||||
N_->assign(vertex_count, osg::Vec4());
|
||||
|
||||
unsigned int i; // VC6 doesn't like for-scoped variables
|
||||
|
||||
@@ -163,9 +146,6 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit
|
||||
// normalize basis vectors and force the normal vector to match
|
||||
// the triangle normal's direction
|
||||
unsigned int attrib_count = vx->getNumElements();
|
||||
if (geo->getVertexIndices() != NULL) {
|
||||
attrib_count = geo->getVertexIndices()->getNumElements();
|
||||
}
|
||||
for (i=0; i<attrib_count; ++i) {
|
||||
osg::Vec4 &vT = (*T_)[i];
|
||||
osg::Vec4 &vB = (*B_)[i];
|
||||
|
||||
@@ -182,20 +182,6 @@ void Tessellator::retessellatePolygons(osg::Geometry &geom)
|
||||
|
||||
if (!vertices || vertices->empty() || geom.getPrimitiveSetList().empty()) return;
|
||||
|
||||
|
||||
// we currently don't handle geometry which use indices...
|
||||
if (geom.getVertexIndices() ||
|
||||
geom.getNormalIndices() ||
|
||||
geom.getColorIndices() ||
|
||||
geom.getSecondaryColorIndices() ||
|
||||
geom.getFogCoordIndices()) return;
|
||||
|
||||
// not even text coord indices don't handle geometry which use indices...
|
||||
for(unsigned int unit=0;unit<geom.getNumTexCoordArrays();++unit)
|
||||
{
|
||||
if (geom.getTexCoordIndices(unit)) return;
|
||||
}
|
||||
|
||||
if (_ttype==TESS_TYPE_POLYGONS || _ttype==TESS_TYPE_DRAWABLE) _numberVerts=0; // 09.04.04 GWM reset Tessellator
|
||||
// the reset is needed by the flt loader which reuses a Tessellator for triangulating polygons.
|
||||
// as such it might be reset by other loaders/developers in future.
|
||||
@@ -470,14 +456,14 @@ void Tessellator::handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &ver
|
||||
arrays.push_back(geom.getFogCoordArray());
|
||||
}
|
||||
|
||||
osg::Geometry::ArrayDataList& tcal = geom.getTexCoordArrayList();
|
||||
for(osg::Geometry::ArrayDataList::iterator tcalItr=tcal.begin();
|
||||
osg::Geometry::ArrayList& tcal = geom.getTexCoordArrayList();
|
||||
for(osg::Geometry::ArrayList::iterator tcalItr=tcal.begin();
|
||||
tcalItr!=tcal.end();
|
||||
++tcalItr)
|
||||
{
|
||||
if (tcalItr->array.valid())
|
||||
if (tcalItr->valid())
|
||||
{
|
||||
arrays.push_back(tcalItr->array.get());
|
||||
arrays.push_back(tcalItr->get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -230,14 +230,6 @@ void TriStripVisitor::stripify(Geometry& geom)
|
||||
// no point tri stripping if we don't have enough vertices.
|
||||
if (!geom.getVertexArray() || geom.getVertexArray()->getNumElements()<3) return;
|
||||
|
||||
// check to see if vertex attributes indices exists, if so expand them to remove them
|
||||
if (geom.suitableForOptimization())
|
||||
{
|
||||
// removing coord indices
|
||||
OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Removing attribute indices"<<std::endl;
|
||||
geom.copyToAndOptimize(geom);
|
||||
}
|
||||
|
||||
// check for the existence of surface primitives
|
||||
unsigned int numSurfacePrimitives = 0;
|
||||
unsigned int numNonSurfacePrimitives = 0;
|
||||
|
||||
@@ -132,7 +132,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
Geometry::AttributeBinding normalBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),normalBinding))
|
||||
{
|
||||
geom.setNormalBinding(normalBinding);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -182,6 +181,8 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
geom.setNormalBinding(normalBinding);
|
||||
}
|
||||
if (fr[0].matchWord("NormalIndices"))
|
||||
{
|
||||
@@ -197,7 +198,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
Geometry::AttributeBinding colorBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding))
|
||||
{
|
||||
geom.setColorBinding(colorBinding);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -209,6 +209,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
if (colors)
|
||||
{
|
||||
geom.setColorArray(colors);
|
||||
geom.setColorBinding(colorBinding);
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -228,7 +229,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
Geometry::AttributeBinding secondaryColorBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))
|
||||
{
|
||||
geom.setSecondaryColorBinding(secondaryColorBinding);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -240,6 +240,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
if (colors)
|
||||
{
|
||||
geom.setSecondaryColorArray(colors);
|
||||
geom.setSecondaryColorBinding(secondaryColorBinding);
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -259,7 +260,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
Geometry::AttributeBinding fogCoordBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("FogCoordBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding))
|
||||
{
|
||||
geom.setFogCoordBinding(fogCoordBinding);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -271,6 +271,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
if (fogcoords)
|
||||
{
|
||||
geom.setFogCoordArray(fogcoords);
|
||||
geom.setFogCoordBinding(fogCoordBinding);
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -1361,43 +1362,48 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
|
||||
Array_writeLocalData(*geom.getFogCoordIndices(),fw);
|
||||
}
|
||||
|
||||
const Geometry::ArrayDataList& tcal=geom.getTexCoordArrayList();
|
||||
const Geometry::ArrayList& tcal=geom.getTexCoordArrayList();
|
||||
unsigned int i;
|
||||
for(i=0;i<tcal.size();++i)
|
||||
{
|
||||
if (tcal[i].array.valid())
|
||||
const osg::Array* array = tcal[i].get();
|
||||
if (array)
|
||||
{
|
||||
fw.indent()<<"TexCoordArray "<<i<<" ";
|
||||
Array_writeLocalData(*(tcal[i].array),fw);
|
||||
Array_writeLocalData(*array,fw);
|
||||
}
|
||||
if (tcal[i].indices.valid())
|
||||
|
||||
const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
|
||||
if (indices)
|
||||
{
|
||||
fw.indent()<<"TexCoordIndices "<<i<<" ";
|
||||
Array_writeLocalData(*(tcal[i].indices),fw);
|
||||
Array_writeLocalData(*indices,fw);
|
||||
}
|
||||
}
|
||||
|
||||
const Geometry::ArrayDataList& vaal=geom.getVertexAttribArrayList();
|
||||
const Geometry::ArrayList& vaal=geom.getVertexAttribArrayList();
|
||||
for(i=0;i<vaal.size();++i)
|
||||
{
|
||||
const osg::Geometry::ArrayData& arrayData = vaal[i];
|
||||
const osg::Array* array = vaal[i].get();
|
||||
|
||||
if (arrayData.array.valid())
|
||||
if (array)
|
||||
{
|
||||
fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(arrayData.binding)<<std::endl;
|
||||
fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(static_cast<osg::Geometry::AttributeBinding>(array->getBinding()))<<std::endl;
|
||||
|
||||
if (arrayData.normalize)
|
||||
if (array->getNormalize())
|
||||
fw.indent()<<"VertexAttribNormalize "<<i<<" TRUE"<<std::endl;
|
||||
else
|
||||
fw.indent()<<"VertexAttribNormalize "<<i<<" FALSE"<<std::endl;
|
||||
|
||||
fw.indent()<<"VertexAttribArray "<<i<<" ";
|
||||
Array_writeLocalData(*(arrayData.array),fw);
|
||||
fw.indent()<<"VertexAttribArray "<<i<<" ";
|
||||
Array_writeLocalData(*array,fw);
|
||||
}
|
||||
if (arrayData.indices.valid())
|
||||
|
||||
const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
|
||||
if (indices)
|
||||
{
|
||||
fw.indent()<<"VertexAttribIndices "<<i<<" ";
|
||||
Array_writeLocalData(*(arrayData.indices),fw);
|
||||
Array_writeLocalData(*indices,fw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
@@ -14,7 +15,10 @@ static bool readDrawables( osgDB::InputStream& is, osg::Geode& node )
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>( is.readObject() );
|
||||
if ( drawable ) node.addDrawable( drawable );
|
||||
if ( drawable )
|
||||
{
|
||||
node.addDrawable( drawable );
|
||||
}
|
||||
}
|
||||
is >> is.END_BRACKET;
|
||||
return true;
|
||||
|
||||
@@ -14,88 +14,98 @@ END_USER_TABLE()
|
||||
USER_READ_FUNC( AttributeBinding, readAttributeBinding )
|
||||
USER_WRITE_FUNC( AttributeBinding, writeAttributeBinding )
|
||||
|
||||
static void readArrayData( osgDB::InputStream& is, osg::Geometry::ArrayData& data )
|
||||
static osg::Array* readArray( osgDB::InputStream& is)
|
||||
{
|
||||
osg::ref_ptr<osg::Array> array;
|
||||
bool hasArray = false;
|
||||
is >> is.PROPERTY("Array") >> hasArray;
|
||||
if ( hasArray ) data.array = is.readArray();
|
||||
if ( hasArray ) array = is.readArray();
|
||||
|
||||
bool hasIndices = false;
|
||||
is >> is.PROPERTY("Indices") >> hasIndices;
|
||||
if ( hasIndices ) data.indices = dynamic_cast<osg::IndexArray*>( is.readArray() );
|
||||
if ( hasIndices )
|
||||
{
|
||||
osg::ref_ptr<osg::Array> indices_array = is.readArray();
|
||||
osg::ref_ptr<osg::IndexArray> indices = dynamic_cast<osg::IndexArray*>( indices_array.get() );
|
||||
if (array.valid() && indices.valid()) array->setUserData(indices.get());
|
||||
}
|
||||
|
||||
is >> is.PROPERTY("Binding");
|
||||
data.binding = (osg::Geometry::AttributeBinding)readAttributeBinding(is);
|
||||
int binding = readAttributeBinding(is);
|
||||
if (array.valid()) array->setBinding(static_cast<osg::Array::Binding>(binding));
|
||||
|
||||
int normalizeValue = 0;
|
||||
is >> is.PROPERTY("Normalize") >> normalizeValue;
|
||||
data.normalize = normalizeValue;
|
||||
if (array.valid()) array->setNormalize(normalizeValue!=0);
|
||||
|
||||
return array.release();
|
||||
}
|
||||
|
||||
static void writeArrayData( osgDB::OutputStream& os, const osg::Geometry::ArrayData& data )
|
||||
static void writeArray( osgDB::OutputStream& os, const osg::Array* array)
|
||||
{
|
||||
os << os.PROPERTY("Array") << data.array.valid();
|
||||
if ( data.array.valid() ) os << data.array.get();
|
||||
os << os.PROPERTY("Array") << (array!=0);
|
||||
if ( array!=0 ) os << array;
|
||||
else os << std::endl;
|
||||
|
||||
os << os.PROPERTY("Indices") << data.indices.valid();
|
||||
if ( data.indices.valid() ) os << data.indices.get();
|
||||
const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
|
||||
os << os.PROPERTY("Indices") << (indices!=0);
|
||||
if ( indices!=0 ) os << indices;
|
||||
else os << std::endl;
|
||||
|
||||
os << os.PROPERTY("Binding"); writeAttributeBinding(os, data.binding); os << std::endl;
|
||||
os << os.PROPERTY("Normalize") << (int)data.normalize << std::endl;
|
||||
os << os.PROPERTY("Binding"); writeAttributeBinding(os, (array!=0) ? static_cast<osg::Geometry::AttributeBinding>(array->getBinding()) : osg::Geometry::BIND_OFF); os << std::endl;
|
||||
os << os.PROPERTY("Normalize") << ((array!=0 && array->getNormalize()) ? 1:0) << std::endl;
|
||||
}
|
||||
|
||||
#define ADD_ARRAYDATA_FUNCTIONS( PROP ) \
|
||||
static bool check##PROP( const osg::Geometry& geom ) \
|
||||
{ return geom.get##PROP().array.valid(); } \
|
||||
static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
|
||||
osg::Geometry::ArrayData data; \
|
||||
is >> is.BEGIN_BRACKET; readArrayData(is, data); \
|
||||
#define ADD_ARRAYDATA_FUNCTIONS( ORIGINAL_PROP, PROP ) \
|
||||
static bool check##ORIGINAL_PROP( const osg::Geometry& geom ) \
|
||||
{ return geom.get##PROP()!=0; } \
|
||||
static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
|
||||
is >> is.BEGIN_BRACKET; \
|
||||
osg::Array* array = readArray(is); \
|
||||
geom.set##PROP(array); \
|
||||
is >> is.END_BRACKET; \
|
||||
geom.set##PROP(data); \
|
||||
return true; \
|
||||
} \
|
||||
static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
|
||||
static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
|
||||
os << os.BEGIN_BRACKET << std::endl; \
|
||||
writeArrayData(os, geom.get##PROP()); \
|
||||
writeArray(os, geom.get##PROP()); \
|
||||
os << os.END_BRACKET << std::endl; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
ADD_ARRAYDATA_FUNCTIONS( VertexData )
|
||||
ADD_ARRAYDATA_FUNCTIONS( NormalData )
|
||||
ADD_ARRAYDATA_FUNCTIONS( ColorData )
|
||||
ADD_ARRAYDATA_FUNCTIONS( SecondaryColorData )
|
||||
ADD_ARRAYDATA_FUNCTIONS( FogCoordData )
|
||||
ADD_ARRAYDATA_FUNCTIONS( VertexData, VertexArray )
|
||||
ADD_ARRAYDATA_FUNCTIONS( NormalData, NormalArray )
|
||||
ADD_ARRAYDATA_FUNCTIONS( ColorData, ColorArray )
|
||||
ADD_ARRAYDATA_FUNCTIONS( SecondaryColorData, SecondaryColorArray )
|
||||
ADD_ARRAYDATA_FUNCTIONS( FogCoordData, FogCoordArray )
|
||||
|
||||
#define ADD_ARRAYLIST_FUNCTIONS( PROP, LISTNAME ) \
|
||||
static bool check##PROP( const osg::Geometry& geom ) \
|
||||
#define ADD_ARRAYLIST_FUNCTIONS( ORIGINAL_PROP, PROP, LISTNAME ) \
|
||||
static bool check##ORIGINAL_PROP( const osg::Geometry& geom ) \
|
||||
{ return geom.get##LISTNAME().size()>0; } \
|
||||
static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
|
||||
static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
|
||||
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; \
|
||||
for ( unsigned int i=0; i<size; ++i ) { \
|
||||
osg::Geometry::ArrayData data; \
|
||||
is >> is.PROPERTY("Data") >> is.BEGIN_BRACKET; \
|
||||
readArrayData(is, data); \
|
||||
is >> is.END_BRACKET; geom.set##PROP(i, data); } \
|
||||
osg::Array* array = readArray(is); \
|
||||
geom.set##PROP(i, array); \
|
||||
is >> is.END_BRACKET; } \
|
||||
is >> is.END_BRACKET; \
|
||||
return true; \
|
||||
} \
|
||||
static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
|
||||
const osg::Geometry::ArrayDataList& LISTNAME = geom.get##LISTNAME(); \
|
||||
static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
|
||||
const osg::Geometry::ArrayList& LISTNAME = geom.get##LISTNAME(); \
|
||||
os.writeSize(LISTNAME.size()); os << os.BEGIN_BRACKET << std::endl; \
|
||||
for ( osg::Geometry::ArrayDataList::const_iterator itr=LISTNAME.begin(); \
|
||||
for ( osg::Geometry::ArrayList::const_iterator itr=LISTNAME.begin(); \
|
||||
itr!=LISTNAME.end(); ++itr ) { \
|
||||
os << os.PROPERTY("Data") << os.BEGIN_BRACKET << std::endl; \
|
||||
writeArrayData(os, *itr); os << os.END_BRACKET << std::endl; \
|
||||
writeArray(os, *itr); os << os.END_BRACKET << std::endl; \
|
||||
} \
|
||||
os << os.END_BRACKET << std::endl; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
ADD_ARRAYLIST_FUNCTIONS( TexCoordData, TexCoordArrayList )
|
||||
ADD_ARRAYLIST_FUNCTIONS( VertexAttribData, VertexAttribArrayList )
|
||||
ADD_ARRAYLIST_FUNCTIONS( TexCoordData, TexCoordArray, TexCoordArrayList )
|
||||
ADD_ARRAYLIST_FUNCTIONS( VertexAttribData, VertexAttribArray, VertexAttribArrayList )
|
||||
|
||||
struct GeometryFinishedObjectReadCallback : public osgDB::FinishedObjectReadCallback
|
||||
{
|
||||
@@ -110,6 +120,26 @@ struct GeometryFinishedObjectReadCallback : public osgDB::FinishedObjectReadCall
|
||||
}
|
||||
};
|
||||
|
||||
// implement backwards compatibility with reading/writing the FastPathHint
|
||||
static bool checkFastPathHint( const osg::Geometry& geom ) { return false; }
|
||||
static bool readFastPathHint( osgDB::InputStream& is, osg::Geometry& geom )
|
||||
{
|
||||
bool value = false;
|
||||
if ( is.isBinary() )
|
||||
{
|
||||
is >> value;
|
||||
}
|
||||
else if ( is.matchString("FastPathHint") )
|
||||
{
|
||||
is >> value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool writeFastPathHint( osgDB::OutputStream& os, const osg::Geometry& geom )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( Geometry,
|
||||
new osg::Geometry,
|
||||
osg::Geometry,
|
||||
@@ -123,8 +153,8 @@ REGISTER_OBJECT_WRAPPER( Geometry,
|
||||
ADD_USER_SERIALIZER( FogCoordData ); // _fogCoordData
|
||||
ADD_USER_SERIALIZER( TexCoordData ); // _texCoordList
|
||||
ADD_USER_SERIALIZER( VertexAttribData ); // _vertexAttribList
|
||||
ADD_BOOL_SERIALIZER( FastPathHint, true ); // _fastPathHint
|
||||
//ADD_OBJECT_SERIALIZER( InternalOptimizedGeometry, osg::Geometry, NULL ); // _internalOptimizedGeometry
|
||||
|
||||
ADD_USER_SERIALIZER( FastPathHint ); // _fastPathHint
|
||||
|
||||
wrapper->addFinishedObjectReadCallback( new GeometryFinishedObjectReadCallback() );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user