Improved the Geometry::verifyBinding() and computeCorrectBindingsAndArraySizes()
methods to check all atributes and to report warnigns when errors are detected. Added a CheckGeomtryVisitor to osgUtil::Optimizer to detect eroneous Geometry before rendering.
This commit is contained in:
@@ -51,53 +51,6 @@ class SG_EXPORT Geometry : public Drawable
|
||||
BIND_PER_VERTEX
|
||||
};
|
||||
|
||||
// template<typename T>
|
||||
// struct AttributeData
|
||||
// {
|
||||
// AttributeData():
|
||||
// binding(BIND_OFF),
|
||||
// normalize(GL_FALSE),
|
||||
// offset(0) {}
|
||||
//
|
||||
// AttributeData(T* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
// array(a),
|
||||
// indices(0),
|
||||
// binding(b),
|
||||
// normalize(n),
|
||||
// offset(0) {}
|
||||
//
|
||||
// AttributeData(T* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
// array(a),
|
||||
// indices(i),
|
||||
// binding(b),
|
||||
// normalize(n),
|
||||
// offset(0) {}
|
||||
//
|
||||
// // AttributeData(const AttributeData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY):
|
||||
// // array(dynamic_cast<T*>(copyop(rhs.array)),
|
||||
// // indices(dynamic_cast<IndexArray*>(copyop(rhs.indices)),
|
||||
// // binding(ths,binding),
|
||||
// // normalize(GL_FALSE),
|
||||
// // offset(rhs.offset) {}
|
||||
//
|
||||
// AttributeData& operator = (const AttributeData& rhs)
|
||||
// {
|
||||
// array = rhs.array;
|
||||
// indices = rhs.indices;
|
||||
// binding = rhs.binding;
|
||||
// normalize = rhs.normalize;
|
||||
// offset = rhs.offset;
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// ref_ptr<T> array;
|
||||
// ref_ptr<IndexArray> indices;
|
||||
// AttributeBinding binding;
|
||||
// GLboolean normalize;
|
||||
// mutable unsigned int offset;
|
||||
// };
|
||||
|
||||
// typedef AttributeData<Array> ArrayData;
|
||||
struct ArrayData
|
||||
{
|
||||
ArrayData():
|
||||
@@ -119,13 +72,6 @@ class SG_EXPORT Geometry : public Drawable
|
||||
normalize(n),
|
||||
offset(0) {}
|
||||
|
||||
// ArrayData(const ArrayData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY):
|
||||
// array(dynamic_cast<T*>(copyop(rhs.array)),
|
||||
// indices(dynamic_cast<IndexArray*>(copyop(rhs.indices)),
|
||||
// binding(ths,binding),
|
||||
// normalize(GL_FALSE),
|
||||
// offset(rhs.offset) {}
|
||||
|
||||
ArrayData& operator = (const ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
@@ -164,13 +110,6 @@ class SG_EXPORT Geometry : public Drawable
|
||||
normalize(n),
|
||||
offset(0) {}
|
||||
|
||||
// Vec3ArrayData(const Vec3ArrayData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY):
|
||||
// array(dynamic_cast<T*>(copyop(rhs.array)),
|
||||
// indices(dynamic_cast<IndexArray*>(copyop(rhs.indices)),
|
||||
// binding(ths,binding),
|
||||
// normalize(GL_FALSE),
|
||||
// offset(rhs.offset) {}
|
||||
|
||||
Vec3ArrayData& operator = (const Vec3ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
@@ -188,8 +127,6 @@ class SG_EXPORT Geometry : public Drawable
|
||||
mutable unsigned int offset;
|
||||
};
|
||||
|
||||
// typedef AttributeData<Vec3Array> Vec3ArrayData;
|
||||
|
||||
/** static ArrayData which is returned get getTexCoordData(i) const and getVertexAttribData(i) const
|
||||
* when i is out of range.*/
|
||||
static const ArrayData s_InvalidArrayData;
|
||||
@@ -360,8 +297,8 @@ class SG_EXPORT Geometry : public Drawable
|
||||
|
||||
bool computeFastPathsUsed();
|
||||
|
||||
|
||||
bool verifyBindings() const;
|
||||
|
||||
void computeCorrectBindingsAndArraySizes();
|
||||
|
||||
|
||||
@@ -412,6 +349,13 @@ class SG_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);
|
||||
|
||||
|
||||
PrimitiveSetList _primitives;
|
||||
|
||||
ArrayData _vertexData;
|
||||
|
||||
@@ -43,11 +43,13 @@ class OSGUTIL_EXPORT Optimizer
|
||||
COMBINE_ADJACENT_LODS = 0x4,
|
||||
SHARE_DUPLICATE_STATE = 0x8,
|
||||
MERGE_GEOMETRY = 0x10,
|
||||
CHECK_GEOMETRY = 0x20,
|
||||
ALL_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS |
|
||||
REMOVE_REDUNDANT_NODES |
|
||||
COMBINE_ADJACENT_LODS |
|
||||
SHARE_DUPLICATE_STATE |
|
||||
MERGE_GEOMETRY
|
||||
MERGE_GEOMETRY |
|
||||
CHECK_GEOMETRY
|
||||
};
|
||||
|
||||
/** traverse the node and its subgraph with a series of optimization
|
||||
@@ -175,6 +177,18 @@ class OSGUTIL_EXPORT Optimizer
|
||||
|
||||
};
|
||||
|
||||
class OSGUTIL_EXPORT CheckGeometryVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
/// default to traversing all children.
|
||||
CheckGeometryVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
virtual void apply(osg::Geode& geode) { checkGeode(geode); }
|
||||
|
||||
static void checkGeode(osg::Geode& geode);
|
||||
|
||||
};
|
||||
|
||||
class OSGUTIL_EXPORT MergeGeometryVisitor : public osg::NodeVisitor
|
||||
{
|
||||
|
||||
1501
src/osg/Geometry.cpp
1501
src/osg/Geometry.cpp
File diff suppressed because it is too large
Load Diff
@@ -98,6 +98,12 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
|
||||
osv.optimize();
|
||||
}
|
||||
|
||||
if (options & CHECK_GEOMETRY)
|
||||
{
|
||||
CheckGeometryVisitor mgv;
|
||||
node->accept(mgv);
|
||||
}
|
||||
|
||||
if (options & MERGE_GEOMETRY)
|
||||
{
|
||||
MergeGeometryVisitor mgv;
|
||||
@@ -1138,6 +1144,18 @@ struct LessGeometryPrimitiveType
|
||||
}
|
||||
};
|
||||
|
||||
void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode)
|
||||
{
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
|
||||
if (geom)
|
||||
{
|
||||
geom->computeCorrectBindingsAndArraySizes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode)
|
||||
{
|
||||
if (geode.getNumDrawables()>=2)
|
||||
@@ -1151,7 +1169,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode)
|
||||
unsigned int i;
|
||||
for(i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
|
||||
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
|
||||
if (geom)
|
||||
{
|
||||
//geom->computeCorrectBindingsAndArraySizes();
|
||||
|
||||
Reference in New Issue
Block a user