Refactored Callback system in osg::Node, osg::Drawable, osg::StateSet and osg::StateAttribute to use a new osg::Callback base class.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14244 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#include <osg/Geometry>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/Node>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Notify>
|
||||
#include <osg/observer_ptr>
|
||||
#include <osg/Projection>
|
||||
|
||||
@@ -10,40 +10,41 @@ class PosterVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
typedef std::set<std::string> PagedNodeNameSet;
|
||||
|
||||
|
||||
PosterVisitor();
|
||||
META_NodeVisitor( osgPoster, PosterVisitor );
|
||||
|
||||
|
||||
void insertName( const std::string& name )
|
||||
{ if ( _pagedNodeNames.insert(name).second ) _needToApplyCount++; }
|
||||
|
||||
|
||||
void eraseName( const std::string& name )
|
||||
{ if ( _pagedNodeNames.erase(name)>0 ) _needToApplyCount--; }
|
||||
|
||||
|
||||
void clearNames() { _pagedNodeNames.clear(); _needToApplyCount = 0; _appliedCount = 0; }
|
||||
unsigned int getNumNames() const { return _pagedNodeNames.size(); }
|
||||
|
||||
|
||||
PagedNodeNameSet& getPagedNodeNames() { return _pagedNodeNames; }
|
||||
const PagedNodeNameSet& getPagedNodeNames() const { return _pagedNodeNames; }
|
||||
|
||||
|
||||
unsigned int getNeedToApplyCount() const { return _needToApplyCount; }
|
||||
unsigned int getAppliedCount() const { return _appliedCount; }
|
||||
unsigned int inQueue() const { return _needToApplyCount>_appliedCount ? _needToApplyCount-_appliedCount : 0; }
|
||||
|
||||
|
||||
void setAddingCallbacks( bool b ) { _addingCallbacks = b; }
|
||||
bool getAddingCallbacks() const { return _addingCallbacks; }
|
||||
|
||||
|
||||
virtual void apply( osg::LOD& node );
|
||||
virtual void apply( osg::PagedLOD& node );
|
||||
|
||||
|
||||
protected:
|
||||
bool hasCullCallback( osg::NodeCallback* nc, osg::NodeCallback* target )
|
||||
|
||||
bool hasCullCallback( osg::Callback* nc, osg::Callback* target )
|
||||
{
|
||||
if ( nc==target ) return true;
|
||||
else if ( !nc ) return false;
|
||||
return hasCullCallback( nc->getNestedCallback(), target );
|
||||
}
|
||||
|
||||
|
||||
PagedNodeNameSet _pagedNodeNames;
|
||||
unsigned int _appliedCount;
|
||||
unsigned int _needToApplyCount;
|
||||
@@ -55,24 +56,24 @@ class PosterIntersector : public osgUtil::Intersector
|
||||
{
|
||||
public:
|
||||
typedef std::set<std::string> PagedNodeNameSet;
|
||||
|
||||
|
||||
PosterIntersector( const osg::Polytope& polytope );
|
||||
PosterIntersector( double xMin, double yMin, double xMax, double yMax );
|
||||
|
||||
|
||||
void setPosterVisitor( PosterVisitor* pcv ) { _visitor = pcv; }
|
||||
PosterVisitor* getPosterVisitor() { return _visitor.get(); }
|
||||
const PosterVisitor* getPosterVisitor() const { return _visitor.get(); }
|
||||
|
||||
|
||||
virtual Intersector* clone( osgUtil::IntersectionVisitor& iv );
|
||||
|
||||
|
||||
virtual bool containsIntersections()
|
||||
{ return _visitor.valid()&&_visitor->getNumNames()>0; }
|
||||
|
||||
|
||||
virtual bool enter( const osg::Node& node );
|
||||
virtual void leave() {}
|
||||
virtual void reset();
|
||||
virtual void intersect( osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable );
|
||||
|
||||
|
||||
protected:
|
||||
osgUtil::IntersectionVisitor* _intersectionVisitor;
|
||||
osg::ref_ptr<PosterVisitor> _visitor;
|
||||
@@ -86,60 +87,60 @@ class PosterPrinter : public osg::Referenced
|
||||
public:
|
||||
typedef std::pair<unsigned int, unsigned int> TilePosition;
|
||||
typedef std::map< TilePosition, osg::ref_ptr<osg::Image> > TileImages;
|
||||
|
||||
|
||||
PosterPrinter();
|
||||
|
||||
|
||||
/** Set to output each sub-image-tile to disk */
|
||||
void setOutputTiles( bool b ) { _outputTiles = b; }
|
||||
bool getOutputTiles() const { return _outputTiles; }
|
||||
|
||||
|
||||
/** Set the output sub-image-tile extension, e.g. bmp */
|
||||
void setOutputTileExtension( const std::string& ext ) { _outputTileExt = ext; }
|
||||
const std::string& getOutputTileExtension() const { return _outputTileExt; }
|
||||
|
||||
|
||||
/** Set the output poster name, e.g. output.bmp */
|
||||
void setOutputPosterName( const std::string& name ) { _outputPosterName = name; }
|
||||
const std::string& getOutputPosterName() const { return _outputPosterName; }
|
||||
|
||||
|
||||
/** Set the size of each sub-image-tile, e.g. 640x480 */
|
||||
void setTileSize( int w, int h ) { _tileSize.set(w, h); }
|
||||
const osg::Vec2& getTileSize() const { return _tileSize; }
|
||||
|
||||
|
||||
/** Set the final size of the high-res poster, e.g. 6400x4800 */
|
||||
void setPosterSize( int w, int h ) { _posterSize.set(w, h); }
|
||||
const osg::Vec2& getPosterSize() const { return _posterSize; }
|
||||
|
||||
|
||||
/** Set the capturing camera */
|
||||
void setCamera( osg::Camera* camera ) { _camera = camera; }
|
||||
const osg::Camera* getCamera() const { return _camera.get(); }
|
||||
|
||||
|
||||
/** Set the final poster image, should be already allocated */
|
||||
void setFinalPoster( osg::Image* image ) { _finalPoster = image; }
|
||||
const osg::Image* getFinalPoster() const { return _finalPoster.get(); }
|
||||
|
||||
|
||||
PosterVisitor* getPosterVisitor() { return _visitor.get(); }
|
||||
const PosterVisitor* getPosterVisitor() const { return _visitor.get(); }
|
||||
|
||||
|
||||
bool done() const { return !_isRunning && !_isFinishing; }
|
||||
|
||||
|
||||
void init( const osg::Camera* camera );
|
||||
void init( const osg::Matrixd& view, const osg::Matrixd& proj );
|
||||
void frame( const osg::FrameStamp* fs, osg::Node* node );
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~PosterPrinter() {}
|
||||
|
||||
|
||||
bool addCullCallbacks( const osg::FrameStamp* fs, osg::Node* node );
|
||||
void removeCullCallbacks( osg::Node* node );
|
||||
void bindCameraToImage( osg::Camera* camera, int row, int col );
|
||||
void recordImages();
|
||||
|
||||
|
||||
bool _outputTiles;
|
||||
std::string _outputTileExt;
|
||||
std::string _outputPosterName;
|
||||
osg::Vec2 _tileSize;
|
||||
osg::Vec2 _posterSize;
|
||||
|
||||
|
||||
bool _isRunning;
|
||||
bool _isFinishing;
|
||||
unsigned int _lastBindingFrame;
|
||||
@@ -149,7 +150,7 @@ protected:
|
||||
int _currentColumn;
|
||||
osg::ref_ptr<PosterIntersector> _intersector;
|
||||
osg::ref_ptr<PosterVisitor> _visitor;
|
||||
|
||||
|
||||
osg::Matrixd _currentViewMatrix;
|
||||
osg::Matrixd _currentProjectionMatrix;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <osg/Geode>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Material>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Depth>
|
||||
#include <osg/CullFace>
|
||||
#include <osg/TexMat>
|
||||
@@ -220,7 +219,7 @@ class MoveEarthySkyWithEyePointTransform : public osg::Transform
|
||||
{
|
||||
public:
|
||||
/** Get the transformation matrix which moves from local coords to world coords.*/
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
@@ -270,7 +269,7 @@ osg::Node* createSkyBox()
|
||||
// clear the depth to the far plane.
|
||||
osg::Depth* depth = new osg::Depth;
|
||||
depth->setFunction(osg::Depth::ALWAYS);
|
||||
depth->setRange(1.0,1.0);
|
||||
depth->setRange(1.0,1.0);
|
||||
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON );
|
||||
|
||||
stateset->setRenderBinDetails(-1,"RenderBin");
|
||||
@@ -305,7 +304,7 @@ osg::Node* addRefractStateSet(osg::Node* node)
|
||||
osg::TextureCubeMap* reflectmap = readCubeMap();
|
||||
stateset->setTextureAttributeAndModes( 0, reflectmap, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
|
||||
stateset->setTextureAttributeAndModes( 1, reflectmap, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
|
||||
|
||||
|
||||
osg::TexMat* texMat = new osg::TexMat;
|
||||
stateset->setTextureAttribute(0, texMat);
|
||||
|
||||
@@ -329,14 +328,14 @@ osg::Node* addRefractStateSet(osg::Node* node)
|
||||
|
||||
// REPLACE function: Arg0
|
||||
// = T0
|
||||
osg::TexEnvCombine *te0 = new osg::TexEnvCombine;
|
||||
osg::TexEnvCombine *te0 = new osg::TexEnvCombine;
|
||||
te0->setCombine_RGB(osg::TexEnvCombine::REPLACE);
|
||||
te0->setSource0_RGB(osg::TexEnvCombine::TEXTURE0);
|
||||
te0->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
|
||||
// INTERPOLATE function: Arg0 * (Arg2) + Arg1 * (1-Arg2)
|
||||
// = T1 * C0.a + Cp * (1-C0.a)
|
||||
osg::TexEnvCombine *te1 = new osg::TexEnvCombine;
|
||||
osg::TexEnvCombine *te1 = new osg::TexEnvCombine;
|
||||
|
||||
// rgb = Cp + Ct
|
||||
te1->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
||||
@@ -354,7 +353,7 @@ osg::Node* addRefractStateSet(osg::Node* node)
|
||||
group->addChild(node);
|
||||
group->setCullCallback(new TexMatCallback(*texMat));
|
||||
group->setStateSet( stateset );
|
||||
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -385,7 +384,7 @@ int main(int argc, char *argv[])
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(model);
|
||||
|
||||
// create normals.
|
||||
// create normals.
|
||||
osgUtil::SmoothingVisitor smoother;
|
||||
model->accept(smoother);
|
||||
|
||||
@@ -393,7 +392,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user