Implemented duplicate removal code into TriStripVisitor and added an

extra pass to doing tri stripping in the osgUtil::Optimzer.

Added validity checks into osg::TexEnvCombine to catch eronous enumarant values.

Improved the efficient of CullingSet's handling of new transforms.

Added a copy shared subgraphs and subdivision code into osgUtil::Optimizer.
This commit is contained in:
Robert Osfield
2003-12-03 21:45:32 +00:00
parent cdb6f9a1df
commit db66abd6d6
14 changed files with 985 additions and 112 deletions

View File

@@ -73,6 +73,9 @@ class SG_EXPORT Array : public Object
virtual void accept(unsigned int index,ValueVisitor&) = 0;
virtual void accept(unsigned int index,ConstValueVisitor&) const = 0;
/** return -1 if lhs element is less than rhs element, 0 is equal, 1 if lhs element is greater than rhs element.*/
virtual int compare(unsigned int lhs,unsigned int rhs) const = 0;
Type getType() const { return _arrayType; }
GLint getDataSize() const { return _dataSize; }
GLenum getDataType() const { return _dataType; }
@@ -122,6 +125,15 @@ class TemplateArray : public Array, public std::vector<T>
virtual void accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); }
virtual void accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );}
virtual int compare(unsigned int lhs,unsigned int rhs) const
{
const T& elem_lhs = (*this)[lhs];
const T& elem_rhs = (*this)[rhs];
if (elem_lhs<elem_rhs) return -1;
if (elem_rhs<elem_lhs) return 1;
return 0;
}
virtual const GLvoid* getDataPointer() const { if (!empty()) return &front(); else return 0; }
virtual unsigned int getTotalDataSize() const { return size()*sizeof(T); }
virtual unsigned int getNumElements() const { return size(); }
@@ -184,6 +196,15 @@ class TemplateIndexArray : public IndexArray, public std::vector<T>
virtual void accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); }
virtual void accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );}
virtual int compare(unsigned int lhs,unsigned int rhs) const
{
const T& elem_lhs = (*this)[lhs];
const T& elem_rhs = (*this)[rhs];
if (elem_lhs<elem_rhs) return -1;
if (elem_rhs<elem_lhs) return 1;
return 0;
}
virtual const GLvoid* getDataPointer() const { if (!empty()) return &front(); else return 0; }
virtual unsigned int getTotalDataSize() const { return size()*sizeof(T); }
virtual unsigned int getNumElements() const { return size(); }

View File

@@ -81,12 +81,14 @@ class SG_EXPORT CullingSet : public Referenced
inline void set(const CullingSet& cs,const Matrix& matrix, const Vec4& pixelSizeVector)
{
_mask = cs._mask;
_frustum = cs._frustum;
_occluderList = cs._occluderList;
_pixelSizeVector = pixelSizeVector;
_smallFeatureCullingPixelSize = cs._smallFeatureCullingPixelSize;
_frustum.transformProvidingInverse(matrix);
//_frustum = cs._frustum;
//_frustum.transformProvidingInverse(matrix);
_frustum.setAndTransformProvidingInverse(cs._frustum,matrix);
for(OccluderList::iterator itr=_occluderList.begin();
itr!=_occluderList.end();

View File

@@ -58,6 +58,8 @@ class SG_EXPORT Geometry : public Drawable
normalize(GL_FALSE),
offset(0) {}
ArrayData(const ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
array(a),
indices(0),
@@ -96,6 +98,8 @@ class SG_EXPORT Geometry : public Drawable
normalize(GL_FALSE),
offset(0) {}
Vec3ArrayData(const Vec3ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
array(a),
indices(0),
@@ -357,24 +361,15 @@ class SG_EXPORT Geometry : public Drawable
PrimitiveSetList _primitives;
ArrayData _vertexData;
Vec3ArrayData _normalData;
ArrayData _colorData;
ArrayData _secondaryColorData;
ArrayData _fogCoordData;
ArrayList _texCoordList;
ArrayList _vertexAttribList;
mutable bool _fastPath;
bool _fastPathHint;
ref_ptr<Geometry> _internalOptimizedGeometry;

View File

@@ -77,7 +77,7 @@ class SG_EXPORT Multisample : public StateAttribute
return 0; // passed all the above comparison macro's, must be equal.
}
virtual void getAssociatedModes(std::vector<GLMode>& modes) const {}
virtual void getAssociatedModes(std::vector<GLMode>& /*modes*/) const {}
void setSampleCoverage(float coverage, bool invert)
{

View File

@@ -69,8 +69,56 @@ class SG_EXPORT Polytope
setupMask();
}
inline void setAndTransformProvidingInverse(const Polytope& pt, const osg::Matrix& matrix)
{
_referenceVertexList = pt._referenceVertexList;
unsigned int resultMask = pt._maskStack.back();
if (resultMask==0)
{
_maskStack.back() = 0;
_resultMask = 0;
_planeList.clear();
return;
}
ClippingMask selector_mask = 0x1;
unsigned int numActivePlanes = 0;
// count number active planes.
PlaneList::const_iterator itr;
for(itr=pt._planeList.begin();
itr!=pt._planeList.end();
++itr)
{
if (resultMask&selector_mask) ++numActivePlanes;
selector_mask <<= 1;
}
_planeList.resize(numActivePlanes);
_resultMask = 0;
selector_mask = 0x1;
unsigned int index = 0;
for(itr=pt._planeList.begin();
itr!=pt._planeList.end();
++itr)
{
if (resultMask&selector_mask)
{
_planeList[index] = *itr;
_planeList[index++].transformProvidingInverse(matrix);
_resultMask = (_resultMask<<1) | 1;
}
selector_mask <<= 1;
}
_maskStack.back() = _resultMask;
}
inline void set(const PlaneList& pl) { _planeList = pl; setupMask(); }
inline void add(const osg::Plane& pl) { _planeList.push_back(pl); setupMask(); }
/** flip/reverse the orientation of all the planes.*/

View File

@@ -134,8 +134,8 @@ class SG_EXPORT TexEnvCombine : public StateAttribute
DOT3_RGBA = GL_DOT3_RGBA_ARB
};
void setCombine_RGB(GLint cm) { _combine_RGB = cm; }
void setCombine_Alpha(GLint cm) { _combine_Alpha = cm; }
void setCombine_RGB(GLint cm);
void setCombine_Alpha(GLint cm);
GLint getCombine_RGB() const { return _combine_RGB; }
GLint getCombine_Alpha() const { return _combine_Alpha; }
@@ -156,13 +156,13 @@ class SG_EXPORT TexEnvCombine : public StateAttribute
TEXTURE7 = GL_TEXTURE0+7
};
void setSource0_RGB(GLint sp) { _source0_RGB = sp; computeNeedoForTexEnvCombiners(); }
void setSource1_RGB(GLint sp) { _source1_RGB = sp; computeNeedoForTexEnvCombiners(); }
void setSource2_RGB(GLint sp) { _source2_RGB = sp; computeNeedoForTexEnvCombiners(); }
void setSource0_RGB(GLint sp);
void setSource1_RGB(GLint sp);
void setSource2_RGB(GLint sp);
void setSource0_Alpha(GLint sp) { _source0_Alpha = sp; computeNeedoForTexEnvCombiners(); }
void setSource1_Alpha(GLint sp) { _source1_Alpha = sp; computeNeedoForTexEnvCombiners(); }
void setSource2_Alpha(GLint sp) { _source2_Alpha = sp; computeNeedoForTexEnvCombiners(); }
void setSource0_Alpha(GLint sp);
void setSource1_Alpha(GLint sp);
void setSource2_Alpha(GLint sp);
GLint getSource0_RGB() const { return _source0_RGB; }
GLint getSource1_RGB() const { return _source1_RGB; }
@@ -180,13 +180,13 @@ class SG_EXPORT TexEnvCombine : public StateAttribute
ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA
};
void setOperand0_RGB(GLint op) { _operand0_RGB = op; }
void setOperand1_RGB(GLint op) { _operand1_RGB = op; }
void setOperand2_RGB(GLint op) { _operand2_RGB = op; }
void setOperand0_RGB(GLint op);
void setOperand1_RGB(GLint op);
void setOperand2_RGB(GLint op);
void setOperand0_Alpha(GLint op) { _operand0_Alpha = op; }
void setOperand1_Alpha(GLint op) { _operand1_Alpha = op; }
void setOperand2_Alpha(GLint op) { _operand2_Alpha = op; }
void setOperand0_Alpha(GLint op);
void setOperand1_Alpha(GLint op);
void setOperand2_Alpha(GLint op);
GLint getOperand0_RGB() const { return _operand0_RGB; }
GLint getOperand1_RGB() const { return _operand1_RGB; }
@@ -197,8 +197,8 @@ class SG_EXPORT TexEnvCombine : public StateAttribute
GLint getOperand2_Alpha() const { return _operand2_Alpha; }
void setScale_RGB(float scale) { _scale_RGB = scale; }
void setScale_Alpha(float scale) { _scale_Alpha = scale; }
void setScale_RGB(float scale);
void setScale_Alpha(float scale);
float getScale_RGB() const { return _scale_RGB; }
float getScale_Alpha() const { return _scale_Alpha; }

View File

@@ -38,25 +38,39 @@ class OSGUTIL_EXPORT Optimizer
enum OptimizationOptions
{
FLATTEN_STATIC_TRANSFORMS = 0x1,
REMOVE_REDUNDANT_NODES = 0x2,
COMBINE_ADJACENT_LODS = 0x4,
SHARE_DUPLICATE_STATE = 0x8,
MERGE_GEOMETRY = 0x10,
CHECK_GEOMETRY = 0x20,
SPATIALIZE_GROUPS = 0x40,
FLATTEN_STATIC_TRANSFORMS = 0x001,
REMOVE_REDUNDANT_NODES = 0x002,
COMBINE_ADJACENT_LODS = 0x004,
SHARE_DUPLICATE_STATE = 0x008,
MERGE_GEOMETRY = 0x010,
CHECK_GEOMETRY = 0x020,
SPATIALIZE_GROUPS = 0x040,
COPY_SHARED_NODES = 0x080,
TRISTRIP_GEOMETRY = 0x100,
DEFAULT_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS |
REMOVE_REDUNDANT_NODES |
COMBINE_ADJACENT_LODS |
SHARE_DUPLICATE_STATE |
MERGE_GEOMETRY |
CHECK_GEOMETRY,
ALL_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS |
REMOVE_REDUNDANT_NODES |
COMBINE_ADJACENT_LODS |
SHARE_DUPLICATE_STATE |
MERGE_GEOMETRY |
CHECK_GEOMETRY |
SPATIALIZE_GROUPS
SPATIALIZE_GROUPS |
COPY_SHARED_NODES |
TRISTRIP_GEOMETRY
};
/** traverse the node and its subgraph with a series of optimization
* visitors, specificied by the OptizationOptions.*/
virtual void optimize(osg::Node* node, unsigned int options = ALL_OPTIMIZATIONS);
void optimize(osg::Node* node);
/** traverse the node and its subgraph with a series of optimization
* visitors, specificied by the OptizationOptions.*/
virtual void optimize(osg::Node* node, unsigned int options);
@@ -233,6 +247,22 @@ class OSGUTIL_EXPORT Optimizer
GroupsToDivideList _groupsToDivideList;
};
/** Copy any shared subgraphs, enabling flattening of static transforms.*/
class OSGUTIL_EXPORT CopySharedSubgraphsVisitor : public osg::NodeVisitor
{
public:
CopySharedSubgraphsVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
virtual void apply(osg::Node& node);
void copySharedNodes();
typedef std::set<osg::Node*> SharedNodeList;
SharedNodeList _sharedNodeList;
};
};
}

View File

@@ -20,6 +20,8 @@
#include <osgUtil/Export>
#include <set>
namespace osgUtil {
/** A tri stripping visitor for converting Geometry surface primitives into tri strips.
@@ -42,7 +44,10 @@ class OSGUTIL_EXPORT TriStripVisitor : public osg::NodeVisitor
*/
void stripify(osg::Geometry& drawable);
/// apply stripify method to all geode geometry.
/** Stripfy the accumulated list of Geometry drawables.*/
void stripify();
/// accumulate the Geometry drawables to stripify
virtual void apply(osg::Geode& geode);
inline void setCacheSize( unsigned int size )
@@ -77,8 +82,11 @@ class OSGUTIL_EXPORT TriStripVisitor : public osg::NodeVisitor
private:
typedef std::set<osg::Geometry*> GeometryList;
unsigned int _cacheSize;
unsigned int _minStripSize;
GeometryList _geometryList;
};
}