2005-10-10 18:10:44 +08:00
|
|
|
#ifndef _OF_DEPTHPARTITIONNODE_
|
|
|
|
#define _OF_DEPTHPARTITIONNODE_
|
|
|
|
|
|
|
|
#include "DistanceAccumulator.h"
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osg/Camera>
|
2005-10-10 18:10:44 +08:00
|
|
|
|
|
|
|
#define CURRENT_CLASS DepthPartitionNode
|
|
|
|
/**********************************************************
|
|
|
|
* Ravi Mathur
|
|
|
|
* OpenFrames API, class DepthPartitionNode
|
|
|
|
* A type of osg::Group that analyzes a scene, then partitions it into
|
|
|
|
* several segments that can be rendered separately. Each segment
|
|
|
|
* is small enough in the z-direction to avoid depth buffer problems
|
|
|
|
* for very large scenes.
|
|
|
|
**********************************************************/
|
|
|
|
class CURRENT_CLASS : public osg::Group
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CURRENT_CLASS();
|
|
|
|
CURRENT_CLASS(const CURRENT_CLASS& dpn,
|
|
|
|
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Node( OpenFrames, CURRENT_CLASS ); // Common Node functions
|
|
|
|
|
|
|
|
/** Set the active state. If not active, this node will simply add the
|
|
|
|
specified scene as it's child, without analyzing it at all. */
|
|
|
|
void setActive(bool active);
|
|
|
|
inline bool getActive() const { return _active; }
|
|
|
|
|
|
|
|
/** Specify whether the color buffer should be cleared before the first
|
2006-11-27 22:52:07 +08:00
|
|
|
Camera draws it's scene. */
|
2005-10-10 18:10:44 +08:00
|
|
|
void setClearColorBuffer(bool clear);
|
|
|
|
inline bool getClearColorBuffer() const { return _clearColorBuffer; }
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Specify the render order for each Camera */
|
|
|
|
void setRenderOrder(osg::Camera::RenderOrder order);
|
|
|
|
inline osg::Camera::RenderOrder getRenderOrder() const
|
2005-10-10 18:10:44 +08:00
|
|
|
{ return _renderOrder; }
|
|
|
|
|
2005-10-27 17:38:06 +08:00
|
|
|
/** Set/get the maximum depth that the scene will be traversed to.
|
|
|
|
Defaults to UINT_MAX. */
|
|
|
|
void setMaxTraversalDepth(unsigned int depth)
|
|
|
|
{ _distAccumulator->setMaxDepth(depth); }
|
|
|
|
|
|
|
|
inline unsigned int getMaxTraversalDepth() const
|
|
|
|
{ return _distAccumulator->getMaxDepth(); }
|
|
|
|
|
2005-10-10 18:10:44 +08:00
|
|
|
/** Override update and cull traversals */
|
|
|
|
virtual void traverse(osg::NodeVisitor &nv);
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Catch child management functions so the Cameras can be informed
|
2005-10-27 17:38:06 +08:00
|
|
|
of added or removed children. */
|
2005-10-10 18:10:44 +08:00
|
|
|
virtual bool addChild(osg::Node *child);
|
|
|
|
virtual bool insertChild(unsigned int index, osg::Node *child);
|
2006-05-02 17:45:31 +08:00
|
|
|
virtual bool removeChildren(unsigned int pos, unsigned int numRemove = 1);
|
2005-10-10 18:10:44 +08:00
|
|
|
virtual bool setChild(unsigned int i, osg::Node *node);
|
|
|
|
|
|
|
|
protected:
|
2006-11-27 22:52:07 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<osg::Camera> > CameraList;
|
2005-10-10 18:10:44 +08:00
|
|
|
|
|
|
|
~CURRENT_CLASS();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
// Creates a new Camera object with default settings
|
|
|
|
osg::Camera* createOrReuseCamera(const osg::Matrix& proj,
|
2005-11-11 03:16:01 +08:00
|
|
|
double znear, double zfar,
|
|
|
|
const unsigned int &camNum);
|
2005-10-10 18:10:44 +08:00
|
|
|
|
|
|
|
bool _active; // Whether partitioning is active on the scene
|
|
|
|
|
|
|
|
// The NodeVisitor that computes cameras for the scene
|
|
|
|
osg::ref_ptr<DistanceAccumulator> _distAccumulator;
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::Camera::RenderOrder _renderOrder;
|
2005-10-10 18:10:44 +08:00
|
|
|
bool _clearColorBuffer;
|
|
|
|
|
|
|
|
// Cameras that should be used to draw the scene. These cameras
|
|
|
|
// will be reused on every frame in order to save time and memory.
|
|
|
|
CameraList _cameraList;
|
2006-11-27 22:52:07 +08:00
|
|
|
unsigned int _numCameras; // Number of Cameras actually being used
|
2005-10-10 18:10:44 +08:00
|
|
|
};
|
|
|
|
#undef CURRENT_CLASS
|
|
|
|
|
|
|
|
#endif
|