@@ -202,26 +201,23 @@ be found at Vterrain.org and TerrainEngine.com, both of which integrate
with the OpenSceneGraph.
Productivity
-
-The core scene graph provides encapsulate the majority of OpenGL
+
The core scene graph provides encapsulate the majority of OpenGL
functionality including latest extensions, provides rending
optimizations
such as culling and sorting, and a whole set of add on libraries which
make
it possible to develop high peformance graphics applications very
rapidly. The application developer is freed to concentrate on content
-and how that content is controlled rather than low level coding.
-
-
-Combining lessons learned from established scene graphs like Performer
+and how that content is controlled rather than low level coding.
+ Combining lessons learned from established scene graphs like
+Performer
and Open Inventor, with modern software engineering methods like Design
Patterns, along with a great deal of feedback early on in the
development cycle, it has been possible to design a library that is
clean and extensible. This has made it easy for users to adopt to the
-OpenSceneGraph and to integrate it with their own applications.
-
-
-For reading and writing databases an the database library (osgDB) adds
+OpenSceneGraph and to integrate it with their own applications.
+ For reading and writing databases an the database library (osgDB)
+adds
support for a wide
variety of database formats via a extensible dynamic plugin mechansim -
the distribution now includes 33
@@ -235,33 +231,30 @@ native .osg ASCII format.
Image loaders include .rgb, .gif, .jpg, .png, .tiff, .pic, .bmp, .dds
(include compressed mip mapped imagery), .tga and qucktime (under OSX).
A whole set of high quality, anti-aliased fonts can also be loaded via
-the freetype plugin.
-
-
-The scene graph also has a set of Node Kits which are seperate
+the freetype plugin.
+ The scene graph also has a set of Node Kits which are
+seperate
libraries,
that can be compiled in with your applications or loaded in at runtime,
which add support for particle systems (osgParticle),
high quality anti-aliased text (osgText) and navigational light points
(osgSim).
-
-The community has also developed a number of additional Node Kits
+
The community has also developed a number of additional Node
+Kits
such as osgNV (which
includes support for NVidia's vertex, fragment, combiner etc extension
and NVidia's Cg shader language.), Demeter (CLOD terrain +
integration with OSG). osgCal
(which integrates Cal3D
-and the OSG), osgVortex
+and the OSG), osgVortex
(which integrates the CM-Labs Vortex
physics enginer with OSG)
and a whole set libraries that integrating the leading Windowing API's
Links can be found in the bazaar sections on the download page of
OpenSceneGraph webiste.
-
-The project has also been integrated with The project has also been integrated with VR Juggler and Vess virtual realilty the
frameworks, with others in developments.
diff --git a/examples/osgshaders/GL2Scene.cpp b/examples/osgshaders/GL2Scene.cpp
index ba1d4145f..807fa1d72 100644
--- a/examples/osgshaders/GL2Scene.cpp
+++ b/examples/osgshaders/GL2Scene.cpp
@@ -138,19 +138,19 @@ make1DSineTexture( int texSize )
///////////////////////////////////////////////////////////////////////////
-static osg::Node* createGlobe()
-{
- osg::Geode* geode = new osg::Geode();
- osg::StateSet* stateset = geode->getOrCreateStateSet();
-
- osg::Texture2D* texture = new osg::Texture2D;
- texture->setImage( osgDB::readImageFile("Images/land_shallow_topo_2048.jpg") );
- stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
-
- geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0,0,0), 2.0f)));
-
- return geode;
-}
+// static osg::Node* createGlobe()
+// {
+// osg::Geode* geode = new osg::Geode();
+// osg::StateSet* stateset = geode->getOrCreateStateSet();
+//
+// osg::Texture2D* texture = new osg::Texture2D;
+// texture->setImage( osgDB::readImageFile("Images/land_shallow_topo_2048.jpg") );
+// stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
+//
+// geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0,0,0), 2.0f)));
+//
+// return geode;
+// }
///////////////////////////////////////////////////////////////////////////
// OpenGL Shading Language source code for the "microshader" example,
diff --git a/include/osg/Array b/include/osg/Array
index 7b1aa1068..2bdd6c2b2 100644
--- a/include/osg/Array
+++ b/include/osg/Array
@@ -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
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
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 _internalOptimizedGeometry;
diff --git a/include/osg/Multisample b/include/osg/Multisample
index e0c12b32f..d6d2f8bbf 100644
--- a/include/osg/Multisample
+++ b/include/osg/Multisample
@@ -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& modes) const {}
+ virtual void getAssociatedModes(std::vector& /*modes*/) const {}
void setSampleCoverage(float coverage, bool invert)
{
diff --git a/include/osg/Polytope b/include/osg/Polytope
index 1e13b5a83..967e740f9 100644
--- a/include/osg/Polytope
+++ b/include/osg/Polytope
@@ -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.*/
diff --git a/include/osg/TexEnvCombine b/include/osg/TexEnvCombine
index 2921d0338..dd8f75d0e 100644
--- a/include/osg/TexEnvCombine
+++ b/include/osg/TexEnvCombine
@@ -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; }
diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer
index 6ec599577..3c3238daf 100644
--- a/include/osgUtil/Optimizer
+++ b/include/osgUtil/Optimizer
@@ -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 SharedNodeList;
+ SharedNodeList _sharedNodeList;
+
+ };
};
}
diff --git a/include/osgUtil/TriStripVisitor b/include/osgUtil/TriStripVisitor
index ba46f3b54..0c65fe764 100644
--- a/include/osgUtil/TriStripVisitor
+++ b/include/osgUtil/TriStripVisitor
@@ -20,6 +20,8 @@
#include
+#include
+
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 GeometryList;
+
unsigned int _cacheSize;
unsigned int _minStripSize;
+ GeometryList _geometryList;
};
}
diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp
index 3fb157896..a7ba0030f 100644
--- a/src/osg/Geometry.cpp
+++ b/src/osg/Geometry.cpp
@@ -358,6 +358,23 @@ class DrawFogCoord : public osg::ConstValueVisitor
const Drawable::Extensions * _extensions;
};
+Geometry::ArrayData::ArrayData(const ArrayData& data,const CopyOp& copyop):
+ array(data.array.valid()?dynamic_cast(data.array->clone(copyop)):0),
+ indices(data.indices.valid()?dynamic_cast(data.indices->clone(copyop)):0),
+ binding(data.binding),
+ normalize(data.normalize),
+ offset(data.offset)
+{
+}
+
+Geometry::Vec3ArrayData::Vec3ArrayData(const Vec3ArrayData& data,const CopyOp& copyop):
+ array(data.array.valid()?dynamic_cast(data.array->clone(copyop)):0),
+ indices(data.indices.valid()?dynamic_cast(data.indices->clone(copyop)):0),
+ binding(data.binding),
+ normalize(data.normalize),
+ offset(data.offset)
+{
+}
Geometry::Geometry()
{
@@ -367,11 +384,11 @@ Geometry::Geometry()
Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
Drawable(geometry,copyop),
- _vertexData(geometry._vertexData),
- _normalData(geometry._normalData),
- _colorData(geometry._colorData),
- _secondaryColorData(geometry._secondaryColorData),
- _fogCoordData(geometry._fogCoordData),
+ _vertexData(geometry._vertexData,copyop),
+ _normalData(geometry._normalData,copyop),
+ _colorData(geometry._colorData,copyop),
+ _secondaryColorData(geometry._secondaryColorData,copyop),
+ _fogCoordData(geometry._fogCoordData,copyop),
_fastPath(geometry._fastPath),
_fastPathHint(geometry._fastPathHint)
{
diff --git a/src/osg/TexEnvCombine.cpp b/src/osg/TexEnvCombine.cpp
index cfdf42c22..5107f1507 100644
--- a/src/osg/TexEnvCombine.cpp
+++ b/src/osg/TexEnvCombine.cpp
@@ -12,6 +12,7 @@
*/
#include
#include
+#include
using namespace osg;
@@ -100,3 +101,42 @@ void TexEnvCombine::apply(State&) const
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}
+void TexEnvCombine::setCombine_RGB(GLint cm) { _combine_RGB = cm; }
+void TexEnvCombine::setCombine_Alpha(GLint cm) { _combine_Alpha = cm; }
+
+void TexEnvCombine::setSource0_RGB(GLint sp) { _source0_RGB = sp; computeNeedoForTexEnvCombiners(); }
+void TexEnvCombine::setSource1_RGB(GLint sp) { _source1_RGB = sp; computeNeedoForTexEnvCombiners(); }
+void TexEnvCombine::setSource2_RGB(GLint sp) { _source2_RGB = sp; computeNeedoForTexEnvCombiners(); }
+
+void TexEnvCombine::setSource0_Alpha(GLint sp) { _source0_Alpha = sp; computeNeedoForTexEnvCombiners(); }
+void TexEnvCombine::setSource1_Alpha(GLint sp) { _source1_Alpha = sp; computeNeedoForTexEnvCombiners(); }
+void TexEnvCombine::setSource2_Alpha(GLint sp) { _source2_Alpha = sp; computeNeedoForTexEnvCombiners(); }
+
+void TexEnvCombine::setOperand0_RGB(GLint op) { _operand0_RGB = op; }
+void TexEnvCombine::setOperand1_RGB(GLint op) { _operand1_RGB = op; }
+void TexEnvCombine::setOperand2_RGB(GLint op) { _operand2_RGB = op; }
+
+static GLint Valid_Operand_Alpha(GLint op, const char* functionName)
+{
+ if (op==TexEnvCombine::SRC_ALPHA || op==TexEnvCombine::ONE_MINUS_SRC_ALPHA) return op;
+
+ notify(WARN)<<"Warning:: TexEnvCombine::"<
#include
+#include
#include
#include
@@ -48,19 +49,101 @@ static bool isNodeEmpty(const osg::Node& node)
return true;
}
+void Optimizer::optimize(osg::Node* node)
+{
+ unsigned int options = 0;
+
+ const char* env = getenv("OSG_OPTIMIZER");
+ if (env)
+ {
+ std::string str(env);
+
+
+ if(str.find("!DEFAULT")!=std::string::npos) options ^= DEFAULT_OPTIMIZATIONS;
+ else if(str.find("DEFAULT")!=std::string::npos) options |= DEFAULT_OPTIMIZATIONS;
+
+ if(str.find("!FLATTEN_STATIC_TRANSFORMS")!=std::string::npos) options ^= FLATTEN_STATIC_TRANSFORMS;
+ else if(str.find("FLATTEN_STATIC_TRANSFORMS")!=std::string::npos) options |= FLATTEN_STATIC_TRANSFORMS;
+
+ if(str.find("!REMOVE_REDUNDANT_NODES")!=std::string::npos) options ^= REMOVE_REDUNDANT_NODES;
+ else if(str.find("REMOVE_REDUNDANT_NODES")!=std::string::npos) options |= REMOVE_REDUNDANT_NODES;
+
+ if(str.find("!COMBINE_ADJACENT_LODS")!=std::string::npos) options ^= COMBINE_ADJACENT_LODS;
+ else if(str.find("COMBINE_ADJACENT_LODS")!=std::string::npos) options |= COMBINE_ADJACENT_LODS;
+
+ if(str.find("!SHARE_DUPLICATE_STATE")!=std::string::npos) options ^= SHARE_DUPLICATE_STATE;
+ else if(str.find("SHARE_DUPLICATE_STATE")!=std::string::npos) options |= SHARE_DUPLICATE_STATE;
+
+ if(str.find("!MERGE_GEOMETRY")!=std::string::npos) options ^= MERGE_GEOMETRY;
+ else if(str.find("MERGE_GEOMETRY")!=std::string::npos) options |= MERGE_GEOMETRY;
+
+ if(str.find("!SPATIALIZE_GROUPS")!=std::string::npos) options ^= SPATIALIZE_GROUPS;
+ else if(str.find("SPATIALIZE_GROUPS")!=std::string::npos) options |= SPATIALIZE_GROUPS;
+
+ if(str.find("!COPY_SHARED_NODES")!=std::string::npos) options ^= COPY_SHARED_NODES;
+ else if(str.find("COPY_SHARED_NODES")!=std::string::npos) options |= COPY_SHARED_NODES;
+
+ if(str.find("!TRISTRIP_GEOMETRY")!=std::string::npos) options ^= TRISTRIP_GEOMETRY;
+ else if(str.find("TRISTRIP_GEOMETRY")!=std::string::npos) options |= TRISTRIP_GEOMETRY;
+
+ }
+ else
+ {
+ options = DEFAULT_OPTIMIZATIONS;
+ }
+
+ optimize(node,options);
+}
void Optimizer::optimize(osg::Node* node, unsigned int options)
{
if (options & COMBINE_ADJACENT_LODS)
{
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing COMBINE_ADJACENT_LODS"<accept(clv);
clv.combineLODs();
}
+ if (options & SHARE_DUPLICATE_STATE)
+ {
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing SHARE_DUPLICATE_STATE"<accept(osv);
+ osv.optimize();
+ }
+
+ if (options & CHECK_GEOMETRY)
+ {
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing CHECK_GEOMETRY"<accept(mgv);
+ }
+
+ if (options & MERGE_GEOMETRY)
+ {
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing MERGE_GEOMETRY"<accept(mgv);
+ }
+
+ if (options & COPY_SHARED_NODES)
+ {
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing COPY_SHARED_NODES"<accept(cssv);
+ cssv.copySharedNodes();
+ }
+
if (options & FLATTEN_STATIC_TRANSFORMS)
{
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing FLATTEN_STATIC_TRANSFORMS"<accept(renv);
@@ -89,33 +173,22 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
}
-
-
- if (options & SHARE_DUPLICATE_STATE)
- {
- StateVisitor osv;
- node->accept(osv);
- osv.optimize();
- }
-
- if (options & CHECK_GEOMETRY)
- {
- CheckGeometryVisitor mgv;
- node->accept(mgv);
- }
-
- if (options & MERGE_GEOMETRY)
- {
- MergeGeometryVisitor mgv;
- node->accept(mgv);
- }
-
if (options & SPATIALIZE_GROUPS)
{
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing SPATIALIZE_GROUPS"<accept(sv);
sv.divide();
-
+ }
+
+ if (options & TRISTRIP_GEOMETRY)
+ {
+ osg::notify(osg::INFO)<<"Optimizer::optimize() doing TRISTRIP_GEOMETRY"<accept(tsv);
+ tsv.stripify();
}
}
@@ -1532,6 +1605,7 @@ bool Optimizer::MergeGeometryVisitor::mergePrimitive(osg::DrawElementsUInt& lhs,
return true;
}
+
////////////////////////////////////////////////////////////////////////////////////////////
//
// Spatialize the scene to accelerate culling
@@ -1718,3 +1792,41 @@ bool Optimizer::SpatializeGroupsVisitor::divide(osg::Group* group, unsigned int
return (numChildrenOnEntrygetNumChildren());
}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Spatialize the scene to accelerate culling
+//
+
+void Optimizer::CopySharedSubgraphsVisitor::apply(osg::Node& node)
+{
+ if (node.getNumParents()>1)
+ {
+ _sharedNodeList.insert(&node);
+ }
+ traverse(node);
+}
+
+void Optimizer::CopySharedSubgraphsVisitor::copySharedNodes()
+{
+ std::cout<<"Shared node "<<_sharedNodeList.size()<getNumParents()<getNumParents()-1;i>0;--i)
+ {
+ // create a clone.
+ osg::ref_ptr new_object = node->clone(osg::CopyOp::DEEP_COPY_NODES |
+ osg::CopyOp::DEEP_COPY_DRAWABLES);
+ // cast it to node.
+ osg::Node* new_node = dynamic_cast(new_object.get());
+
+ // replace the node by new_new
+ if (new_node) node->getParent(i)->replaceChild(node,new_node);
+ }
+ }
+}
diff --git a/src/osgUtil/TriStripVisitor.cpp b/src/osgUtil/TriStripVisitor.cpp
index 01de50dde..cdca2aae0 100644
--- a/src/osgUtil/TriStripVisitor.cpp
+++ b/src/osgUtil/TriStripVisitor.cpp
@@ -14,6 +14,7 @@
#include
#include
+#include
#include
#include
@@ -23,6 +24,484 @@
using namespace osg;
using namespace osgUtil;
+typedef std::vector IndexList;
+
+class WriteValue : public osg::ConstValueVisitor
+{
+ public:
+ WriteValue(std::ostream& o):_o(o) {}
+
+ std::ostream& _o;
+
+ virtual void apply(const GLbyte& v) { _o << v; }
+ virtual void apply(const GLshort& v) { _o << v; }
+ virtual void apply(const GLint& v) { _o << v; }
+ virtual void apply(const GLushort& v) { _o << v; }
+ virtual void apply(const GLubyte& v) { _o << v; }
+ virtual void apply(const GLuint& v) { _o << v; }
+ virtual void apply(const GLfloat& v) { _o << v; }
+ virtual void apply(const UByte4& v) { _o << v; }
+ virtual void apply(const Vec2& v) { _o << v; }
+ virtual void apply(const Vec3& v) { _o << v; }
+ virtual void apply(const Vec4& v) { _o << v; }
+};
+
+
+struct VertexAttribComparitor
+{
+ VertexAttribComparitor(osg::Geometry& geometry)
+ {
+ add(geometry.getVertexArray(),osg::Geometry::BIND_PER_VERTEX);
+ add(geometry.getNormalArray(),geometry.getNormalBinding());
+ add(geometry.getColorArray(),geometry.getColorBinding());
+ add(geometry.getSecondaryColorArray(),geometry.getSecondaryColorBinding());
+ add(geometry.getFogCoordArray(),geometry.getFogCoordBinding());
+ unsigned int i;
+ for(i=0;i ArrayList;
+
+ ArrayList _arrayList;
+
+ bool operator() (unsigned int lhs, unsigned int rhs) const
+ {
+ for(ArrayList::const_iterator itr=_arrayList.begin();
+ itr!=_arrayList.end();
+ ++itr)
+ {
+ int compare = (*itr)->compare(lhs,rhs);
+ if (compare==-1) return true;
+ if (compare==1) return false;
+ }
+ return false;
+ }
+
+ int compare(unsigned int lhs, unsigned int rhs)
+ {
+ for(ArrayList::iterator itr=_arrayList.begin();
+ itr!=_arrayList.end();
+ ++itr)
+ {
+ int compare = (*itr)->compare(lhs,rhs);
+ if (compare==-1) return -1;
+ if (compare==1) return 1;
+ }
+//
+// WriteValue wv(std::cout);
+//
+// std::cout<<"Values equal"<accept(lhs,wv);
+// std::cout<<" rhs["<accept(rhs,wv);
+// std::cout<accept(av);
+ }
+ }
+
+};
+
+class RemapArray : public osg::ArrayVisitor
+{
+ public:
+ RemapArray(const IndexList& remapping):_remapping(remapping) {}
+
+ const IndexList& _remapping;
+
+ template
+ inline void remap(T& array)
+ {
+ for(unsigned int i=0;i<_remapping.size();++i)
+ {
+ if (i!=_remapping[i])
+ {
+ array[i] = array[_remapping[i]];
+ }
+ }
+ array.erase(array.begin()+_remapping.size(),array.end());
+ }
+
+ virtual void apply(osg::Array&) {}
+ virtual void apply(osg::ByteArray& array) { remap(array); }
+ virtual void apply(osg::ShortArray& array) { remap(array); }
+ virtual void apply(osg::IntArray& array) { remap(array); }
+ virtual void apply(osg::UByteArray& array) { remap(array); }
+ virtual void apply(osg::UShortArray& array) { remap(array); }
+ virtual void apply(osg::UIntArray& array) { remap(array); }
+ virtual void apply(osg::UByte4Array& array) { remap(array); }
+ virtual void apply(osg::FloatArray& array) { remap(array); }
+ virtual void apply(osg::Vec2Array& array) { remap(array); }
+ virtual void apply(osg::Vec3Array& array) { remap(array); }
+ virtual void apply(osg::Vec4Array& array) { remap(array); }
+};
+
+class TriangleIndexFunctor : public osg::Drawable::PrimitiveFunctor
+{
+public:
+
+
+ IndexList _remapIndices;
+ triangle_stripper::tri_stripper::indices _in_indices;
+
+ inline void triangle(unsigned int p1, unsigned int p2, unsigned int p3)
+ {
+ if (_remapIndices.empty())
+ {
+ _in_indices.push_back(p1);
+ _in_indices.push_back(p2);
+ _in_indices.push_back(p3);
+ }
+ else
+ {
+ _in_indices.push_back(_remapIndices[p1]);
+ _in_indices.push_back(_remapIndices[p2]);
+ _in_indices.push_back(_remapIndices[p3]);
+ }
+ }
+
+ virtual void setVertexArray(unsigned int,const Vec2*)
+ {
+ notify(WARN)<<"TriangleIndexFunctor does not support Vec2* vertex arrays"< taf;
+ // compute duplicate vertices
+
+ typedef std::vector IndexList;
+ unsigned int numVertices = geom.getVertexArray()->getNumElements();
+ IndexList indices(numVertices);
+ unsigned int i,j;
+ for(i=0;iin_numVertices) in_numVertices=*itr;
@@ -135,7 +717,7 @@ void TriStripVisitor::stripify(Geometry& geom)
// so increment to give to the corrent number of verticies.
++in_numVertices;
- triangle_stripper::tri_stripper stripifier(taf.in_indices);
+ triangle_stripper::tri_stripper stripifier(taf._in_indices);
stripifier.SetCacheSize(_cacheSize);
stripifier.SetMinStripSize(_minStripSize);
@@ -170,17 +752,42 @@ void TriStripVisitor::stripify(Geometry& geom)
new_primitives.push_back(elements);
}
}
-
geom.setPrimitiveSetList(new_primitives);
+
+#if 0
+// debugging code for indentifying the tri-strips.
+ osg::Vec4Array* colors = new osg::Vec4Array(new_primitives.size());
+ for(i=0;isize();++i)
+ {
+ (*colors)[i].set(((float)rand()/(float)RAND_MAX),
+ ((float)rand()/(float)RAND_MAX),
+ ((float)rand()/(float)RAND_MAX),
+ 1.0f);
+ }
+ geom.setColorArray(colors);
+ geom.setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
+#endif
}
}
+void TriStripVisitor::stripify()
+{
+ for(GeometryList::iterator itr=_geometryList.begin();
+ itr!=_geometryList.end();
+ ++itr)
+ {
+ stripify(*(*itr));
+
+ // osgUtil::SmoothingVisitor sv;
+ // sv.smooth(*(*itr));
+ }
+}
void TriStripVisitor::apply(Geode& geode)
{
for(unsigned int i = 0; i < geode.getNumDrawables(); ++i )
{
osg::Geometry* geom = dynamic_cast(geode.getDrawable(i));
- if (geom) stripify(*geom);
+ if (geom) _geometryList.insert(geom);
}
}