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:
@@ -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