18 #include <matrix/vlVector.h>
20 #include <osgUtil/LineSegmentIntersector>
21 #include <osgViewer/Renderer>
23 #include <osg/ref_ptr>
24 #include <osg/LightSource>
26 #include <boost/unordered_map.hpp>
28 #define DT_INSTANCE_MANAGER_CULL_IS_PARALLEL 1
29 #define DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL 1
31 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
35 #define DT_INSTANCE_MANAGER_UPDATEDISTANCESTOEYE_IS_PARALLEL 1
57 class DtGlTextureBufferObject;
58 class DtInstanceProcessor;
59 class DtInstanceLpProcessor;
60 class DtOsgIntersectorResult;
61 class DtChannelManager;
63 class DtPerViewUniformCallback;
66 class DtOsgCullVisitorParameters;
67 class DtViewSpecificGroup;
76 typedef std::vector<osg::ref_ptr<osg::Geometry> >
GeometryVec;
79 typedef std::map<osg::ref_ptr< osgEarth::VirtualProgram >, osg::ref_ptr<osgEarth::VirtualProgram> >
VpMap;
80 typedef std::vector<osg::ref_ptr<osgEarth::VirtualProgram> >
VpRefList;
86 static const unsigned int NumVec4PerInstance = 8;
246 typedef std::vector<InstancedLod*>
LodVec;
308 bool intersect(
const osg::Vec3d& start,
const osg::Vec3d& end,
310 std::list<DtUniqueID>* ignoreList = 0);
313 bool intersect(
const osg::Vec3d& start,
const osg::Vec3d& end,
314 std::vector<DtOsgIntersectorResult>& results,
315 std::list<DtUniqueID>* ignoreList = 0);
322 void setSequenceSpeed(
const DtInstanceState& instance,
unsigned int sequenceIndex,
float speed);
325 void setSequencePlayTime(
const DtInstanceState& instance,
unsigned int sequenceIndex,
float loopTime);
338 void setDofAnimation(osg::Vec3f& hpr,
const osg::Vec3f& hprVel,
const DtInstanceState& state,
unsigned int partIndex);
341 void setDofTranslation(osg::Vec3f& trans, osg::Vec3f& transVel,
const DtInstanceState& state,
unsigned int partIndex);
346 void setSwitchState(
const DtInstanceState& instance,
unsigned int partIndex,
unsigned int childIndex,
bool state);
351 void setUVOffset(
DtUniqueID id,
unsigned int drawableIx, osg::Vec2f uvOffset);
356 void setUserDefined(
DtUniqueID id,
float userDefined);
361 void setLightpointRange(
DtUniqueID id,
float range);
368 osg::StateSet* getModelTypeRootStateSet(
const std::string &modelType);
382 virtual void reset();
385 virtual osg::Node* instanceRoot();
388 bool isRegistered(
const std::string& modelType);
391 void registerModel(
const std::string& modelType,
GeometryVec& drawables,
LodVec& lods,
394 unsigned int nodeMask, osg::ref_ptr<osg::StateSet> rootNodeSS,
bool daylightControlledLights =
false);
397 osg::Geode *setupModelGeode(
const std::string& modelType,
unsigned int nodeMask);
400 void allocateImage(
const osg::View* view);
409 bool newInstance(
const std::string& modelType,
DtUniqueID id,
DtElementID elementId, osg::Node* rootNode,
const std::string &lightPointGroup,
bool isSimpleModel);
425 void setOrientation(
DtUniqueID uniqueID,
const DtTaitBryan& orientation);
428 void setPosition(
DtUniqueID uniqueID,
const osg::Vec3d& vPosition);
429 void setOrientation(
DtUniqueID uniqueID,
const osg::Quat& orientation);
432 void setVisible(
DtUniqueID uniqueID,
bool bVisible);
435 void setBlendColor(
DtUniqueID uniqueID,
float r,
float g,
float b,
float a);
441 void setModelScaling(
DtUniqueID uniqueID,
bool bModelScaling,
float scale);
444 void setCullParameters(
DtUniqueID uniqueID,
short modelSet,
unsigned int nodeMask,
bool visible);
516 inline const osg::View*
lastView() {
return myLastView; }
519 inline const osg::Camera*
lastCamera() {
return myLastCamera; }
522 inline unsigned int drawableIndex(
unsigned int instanceIx);
525 void reloadShaders();
529 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
530 inline unsigned int visibleCount()
const {
return myVisibleCount.get(); }
533 inline unsigned int visibleCount()
const {
return myVisibleCount; }
539 virtual bool isDaylight();
542 virtual void traverse(osg::NodeVisitor& nv);
548 virtual void updateForIntersection(
double simTime,
const osg::View *view, osg::Camera *camera,
unsigned int nodeMask,
DtOsgCullVisitorParameters *params);
554 virtual float lightpointRange(
unsigned int instanceIx);
559 virtual void setDefaultLightPointMaxDistance(
float distance );
562 virtual float defaultLightPointMaxDistance()
const;
569 virtual void setLightPointFadeBias(
float bias );
574 virtual std::string modelDefinitionNameProxy(
const std::string& modelDefName);
578 DtVirtualBaseClass* findCachedData(
const std::string& modelType,
const std::string& name);
584 void setCachedData(
const std::string& modelType,
const std::string& name,
DtVirtualBaseClass* data);
587 void clearCachedData();
589 void releaseGLObjects(
void);
664 typedef boost::unordered_map<std::string, DtVirtualBaseClass*>
CacheMap;
682 double l, r, b,
t, n, f;
691 osgUtil::LineSegmentIntersector::Intersection
result;
695 friend class DtInstanceManagerTBOUpdater;
705 void update(
double simTime,
const osg::View *view, osg::Camera *camera,
706 unsigned int nodeMask, osgUtil::CullVisitor *cv,
710 void registerGeometry(
unsigned int templateIx, osg::Geometry* geometry,
VpMap& vpMap);
713 float computeDistanceToEye(
const Eyepoint& eye,
const osg::Vec3d& pos)
const;
716 void updateDistancesToEye(
const Eyepoint& eye);
719 void _updateDistancesToEye(
const Eyepoint& eye,
unsigned int instanceOffset,
unsigned int numInstances);
722 void allocateRenderList();
725 unsigned int updateDataAndDrawables(
const osg::View* view,
const ArrayRange& drawableRange,
726 unsigned int bufferOffset, osg::Vec4* bufferStorage);
731 unsigned int updateRenderList(
const Eyepoint& eye,
const osg::Matrixd& viewMat,
unsigned int nodeMask);
733 void updateLights(
const osg::View* view);
734 void resizeBuffersIfNecessary(
const osg::View* view,
int visibleCount);
735 void resizeTBOIfNecessary(
const osg::View* view,
int visibleCount);
736 void updateBuffers(
const osg::View* view);
739 void updateLightPoints(
const osg::Camera *camera,
const osg::FrameStamp *frameStamp, osgUtil::CullVisitor *cv,
const osg::Camera *sceneCamera = NULL);
744 void allocateInstanceData();
749 unsigned int fillRenderList(
unsigned visibleSetStride,
unsigned int instanceOffset,
unsigned int numInstances);
753 ,
const std::vector<osg::Vec4d>& planes,
bool useScale,
unsigned int nodeMask
754 ,
unsigned int instanceOffset,
unsigned int instanceCount);
763 void createHitList(
const osg::Vec3d& end,
const osg::Vec3d& start, std::vector<InstancingHit>& hitList);
766 void loadInstanceShaders(osg::ref_ptr<osgEarth::VirtualProgram> vp);
769 const std::list<DtUniqueID>& ignoreList);
799 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
801 unsigned int getcount()
const
889 virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo)
const
917 typedef boost::unordered_map<const osg::View*, osg::ref_ptr<DtViewSpecificGroup> >
ViewToGroup;
921 typedef boost::unordered_map<osg::Geometry*, osg::ref_ptr<DtPerViewUniformCallback> >
GeometryToCallback;
930 void addInstanceRootToSceneGraphIfNecessary(
void);
934 void processNewInstanceSwitches(
const InstanceTemplate& instanceTemplate,
bool isSimpleModel);
938 void processNewInstanceLightPoints(
const InstanceTemplate& instanceTemplate,
const std::string &lightPointGroup);
940 void preCull(
unsigned int maxChunkSize);
941 void frustumCull(
const osg::View* view,
const Eyepoint& eye,
unsigned int nodeMask);
942 void postCull(
unsigned int maxChunkSize);
946 void _fillRenderList(
bool globalScaling,
unsigned int instanceOffset,
unsigned int numInstances);
948 #if DT_INSTANCE_MANAGER_FILLRENDERLIST_IS_PARALLEL
951 unsigned int myVisibleCount;