18 #include <matrix/vlVector.h>
20 #include <osgUtil/LineSegmentIntersector>
22 #include <osg/ref_ptr>
23 #include <osg/LightSource>
25 #include <boost/unordered_map.hpp>
27 #define DT_INSTANCE_MANAGER_CULL_IS_PARALLEL 1
28 #define DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL 1
30 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
34 #define DT_INSTANCE_MANAGER_UPDATEDISTANCESTOEYE_IS_PARALLEL 1
56 class DtGLTextureBufferObject;
57 class DtInstanceProcessor;
58 class DtOsgIntersectorResult;
59 class DtChannelManager;
61 class DtPerViewUniformCallback;
64 class DtOsgCullVisitorParameters;
65 class DtViewSpecificGroup;
74 typedef std::vector<osg::ref_ptr<osg::Geometry> >
GeometryVec;
77 typedef std::map<osg::ref_ptr< osgEarth::VirtualProgram >, osg::ref_ptr<osgEarth::VirtualProgram> >
VpMap;
78 typedef std::vector<osg::ref_ptr<osgEarth::VirtualProgram> >
VpRefList;
84 static const unsigned int NumVec4PerInstance = 8;
231 typedef std::vector<InstancedLod*>
LodVec;
289 bool intersect(
const osg::Vec3d& start,
const osg::Vec3d& end,
291 std::list<DtUniqueID>* ignoreList=0);
294 bool intersect(
const osg::Vec3d& start,
const osg::Vec3d& end,
295 std::vector<DtOsgIntersectorResult>& results,
296 std::list<DtUniqueID>* ignoreList=0);
303 void setSequenceSpeed(
const DtInstanceState& instance,
unsigned int sequenceIndex,
float speed);
306 void setSequencePlayTime(
const DtInstanceState& instance,
unsigned int sequenceIndex,
float loopTime);
319 void setDofAnimation(osg::Vec3f& hpr, osg::Vec3f hprVel,
const DtInstanceState& state,
unsigned int partIndex);
322 void setDofTranslation(osg::Vec3f& trans, osg::Vec3f& transVel,
const DtInstanceState& state,
unsigned int partIndex);
327 void setSwitchState(
const DtInstanceState& instance,
unsigned int partIndex,
unsigned int childIndex,
bool state);
332 void setUVOffset(
DtUniqueID id,
unsigned int drawableIx, osg::Vec2f uvOffset);
337 void setUserDefined(
DtUniqueID id,
float userDefined);
355 virtual void reset();
358 virtual osg::Node* instanceRoot();
361 bool isRegistered(
const std::string& modelType);
364 void registerModel(
const std::string& modelType,
GeometryVec& drawables,
LodVec& lods,
367 unsigned int nodeMask, osg::ref_ptr<osg::StateSet> rootNodeSS,
bool daylightControlledLights =
false);
370 osg::Geode *setupModelGeode(
const std::string& modelType,
unsigned int nodeMask);
373 void allocateImage(
const osg::View* view );
382 bool newInstance(
const std::string& modelType,
DtUniqueID id,
DtElementID elementId, osg::Node* rootNode);
398 void setOrientation(
DtUniqueID uniqueID,
const DtTaitBryan& orientation);
401 void setPosition(
DtUniqueID uniqueID,
const osg::Vec3d& vPosition);
402 void setOrientation(
DtUniqueID uniqueID,
const osg::Quat& orientation);
405 void setVisible(
DtUniqueID uniqueID,
bool bVisible);
408 void setBlendColor(
DtUniqueID uniqueID,
float r,
float g,
float b,
float a);
411 void setModelScaling(
DtUniqueID uniqueID,
bool bModelScaling);
414 void setCullParameters(
DtUniqueID uniqueID,
short modelSet,
unsigned int nodeMask,
bool visible);
486 inline const osg::View*
lastView() {
return myLastView; }
489 inline unsigned int drawableIndex(
unsigned int instanceIx);
492 void reloadShaders();
497 virtual bool isDaylight();
579 double l, r, b,
t, n, f;
588 osgUtil::LineSegmentIntersector::Intersection
result;
601 unsigned int nodeMask,
bool suppressLastUpdateTime =
false);
604 void registerGeometry(
unsigned int templateIx, osg::Geometry* geometry,
VpMap& vpMap);
607 float computeDistanceToEye(
const Eyepoint& eye,
const osg::Vec3d& pos)
const;
610 void updateDistancesToEye(
const Eyepoint& eye);
613 void _updateDistancesToEye(
const Eyepoint& eye,
unsigned int instanceOffset,
unsigned int numInstances);
616 void allocateRenderList();
619 unsigned int updateBuffers(
const osg::View* view,
DtGLTextureBufferObject* tbo,
const ArrayRange& drawableRange,
unsigned int bufferOffset, osg::Vec4* bufferStorage );
624 unsigned int updateRenderList(
const Eyepoint& eye,
const osg::Matrixd& viewMat,
unsigned int nodeMask);
626 void updateLights(
const osg::View* view);
627 void resizeBuffersIfNecessary(
const osg::View* view,
unsigned int visibleCount);
628 void updateBuffers(
const osg::View* view);
633 void allocateInstanceData();
638 unsigned int fillRenderList(
unsigned visibleSetStride,
unsigned int instanceOffset,
unsigned int numInstances );
642 ,
const std::vector<osg::Vec4d>& planes,
bool useScale,
unsigned int nodeMask
643 ,
unsigned int instanceOffset,
unsigned int instanceCount);
652 void createHitList(
const osg::Vec3d& end,
const osg::Vec3d& start, std::vector<InstancingHit>& hitList);
655 void loadInstanceShaders(osg::ref_ptr<osgEarth::VirtualProgram> vp);
658 const std::list<DtUniqueID>& ignoreList);
685 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
687 unsigned int getcount()
const
775 virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo)
const
803 typedef boost::unordered_map<const osg::View*, osg::ref_ptr<DtViewSpecificGroup> >
ViewToGroup;
807 typedef boost::unordered_map<osg::Geometry*, osg::ref_ptr<DtPerViewUniformCallback> >
GeometryToCallback;
813 void addInstanceRootToSceneGraphIfNecessary(
void);
820 void preCull(
unsigned int maxChunkSize);
821 void frustumCull(
const osg::View* view,
const Eyepoint& eye,
unsigned int nodeMask);
822 void postCull(
unsigned int maxChunkSize);
826 void _fillRenderList(
bool globalScaling,
unsigned int instanceOffset,
unsigned int numInstances);
828 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
831 unsigned int myVisibleCount;