Changeset 1185 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Timestamp:
- 08/07/06 16:12:39 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
r1182 r1185 20 20 namespace Ogre 21 21 { 22 class KdTreeSceneNode; 23 class WireBoundingBox; 24 //typedef std::list < WireBoundingBox * > WBBList; 25 26 class KdTreeSceneManager : public SceneManager 22 23 class KdTreeSceneNode; 24 //class WireBoundingBox; 25 26 class KdTreeSceneManager : public SceneManager 27 { 28 public: 29 KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm); 30 ~KdTreeSceneManager(void); 31 32 virtual const String& getTypeName(void) const; 33 34 //typedef std::list<KdTreeSceneNode *> NodeList; 35 //typedef std::list<WireBoundingBox *> BoxList; 36 37 /************************************************************************/ 38 /* Functions overridden form SceneManager for KdTree */ 39 /************************************************************************/ 40 41 /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode 42 */ 43 virtual SceneNode* createSceneNode(void); 44 /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode 45 */ 46 virtual SceneNode* createSceneNode(const String& name); 47 48 /** Override from Scenemanager, employ kd-tree based culling or CHC 49 */ 50 virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters); 51 52 virtual bool setOption(const String& strKey, const void* pValue); 53 virtual bool getOption(const String& strKey, void* pDestValue); 54 55 bool getOptionValues(const String & key, StringVector &refValueList); 56 bool getOptionKeys(StringVector &refKeys); 57 58 /** Overide from scene manager to destroy kdtree properly (before the scene graph is destroyed) 59 */ 60 virtual void clearScene() 27 61 { 28 public: 29 KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm); 30 ~KdTreeSceneManager(void); 31 32 virtual const String& getTypeName(void) const; 33 34 35 /************************************************************************/ 36 /* Functions overridden form SceneManager for KdTree */ 37 /************************************************************************/ 38 39 /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode 40 */ 41 virtual SceneNode* createSceneNode(void); 42 /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode 43 */ 44 virtual SceneNode* createSceneNode(const String& name); 45 46 /** Override from Scenemanager, employ kd-tree based culling or CHC 47 */ 48 virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters); 49 50 virtual bool setOption(const String& strKey, const void* pValue); 51 virtual bool getOption(const String& strKey, void* pDestValue); 52 53 bool getOptionValues(const String & key, StringVector &refValueList); 54 bool getOptionKeys(StringVector &refKeys); 55 56 /** Overide from scene manager to destroy kdtree properly (before the scene graph is destroyed) 57 */ 58 virtual void clearScene() 59 { 60 // DEBUG 61 //if (mKdTree) 62 // mKdTree->dump(); 63 64 // must happen before actual scene is cleared 65 OGRE_DELETE(mKdTree); 66 67 SceneManager::clearScene(); 68 } 69 70 /************************************************************************/ 71 /* Functions overridden from SceneManager for CHC */ 72 /************************************************************************/ 73 74 /** Override from SceneManager so that sub entities can be assigned an id for item buffer. 75 */ 76 Entity* createEntity(const String& entityName, const String& meshName); 77 78 /** Override from scene manager to set up culling manager 79 */ 80 virtual void _updateSceneGraph(Camera* cam); 81 82 /** Override from SceneManager, employ normal rendering or CHC 83 */ 84 virtual void _renderVisibleObjects(); 85 86 /** Override pass so we can do the z-fail pass. 87 */ 88 const Pass* _setPass(Pass* pass); 89 90 /** Render a queue group. 91 Override so we can handle delayed rendering of transparent objects 92 */ 93 void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 94 QueuedRenderableCollection::OrganisationMode om); 95 96 /** Override from scene manager 97 */ 98 void _renderQueueGroupObjects(RenderQueueGroup* pGroup, 99 QueuedRenderableCollection::OrganisationMode om); 100 101 /** Override from SceneManager so we can skip all but first pass for depth pass. 102 */ 103 bool validatePassForRendering(Pass* pass); 104 105 /** Override from SceneManager because idontknow 106 */ 107 void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, 108 QueuedRenderableCollection::OrganisationMode om); 109 void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, 110 QueuedRenderableCollection::OrganisationMode om); 111 112 113 /************************************************************************/ 114 /* Functions which are specific to the KdTree */ 115 /************************************************************************/ 116 117 /** Update the KdTree with the node (more or less disabled now) 118 */ 119 virtual void _updateNode(KdTreeSceneNode *node); // TODO: 120 121 /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options 122 */ 123 virtual void setShowBoxes(bool showboxes); 124 /** Tell if show boxes is enabled - obsolete, use options 125 */ 126 virtual bool getShowBoxes(void) const; 127 128 /************************************************************************/ 129 /* Functions for CHC */ 130 /************************************************************************/ 131 132 /** Render a list of scenenodes 133 */ 134 virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam, 135 bool onlyShadowCasters, int leavePassesInQueue); 136 137 /** Sets the visibility manager. 138 @param visManager the visibility manager 139 */ 140 void setVisibilityManager(GtpVisibility::VisibilityManager *visManager); 141 /** See set. 142 */ 143 GtpVisibility::VisibilityManager *getVisibilityManager(); 144 145 /** Returns pointer to visibility manager. 146 */ 147 GtpVisibility::VisibilityManager *GetVisibilityManager(); 148 149 /** Returns hierarchy interface. 150 */ 151 KdTreeHierarchyInterface *GetHierarchyInterface(); 152 153 /** Creates material for depth pass, e.g., a pass that only fills the depth buffer. 154 */ 155 void InitDepthPass(); 156 /** Creates material for item buffer. 157 */ 158 void InitItemBufferPass(); 159 /** Fills render queue so that a visualization can be rendered. 160 */ 161 void PrepareVisualization(Camera *cam); 162 /** Initialises necessary parameters for hierarchical visibility culling. 163 */ 164 void InitVisibilityCulling(Camera *cam); 165 166 /** Writes out stats into the Ogre log file. 167 */ 168 void WriteLog(); 169 170 171 172 protected: 173 /************************************************************************/ 174 /* CHC-specific options & members */ 175 /************************************************************************/ 176 // pointer to the visibility manager 177 GtpVisibility::VisibilityManager *mVisibilityManager; 178 179 // the hierarchy interface for CHC 180 KdTreeHierarchyInterface *mHierarchyInterface; 181 182 // if hierarchical culling is currently in use 183 bool mIsHierarchicalCulling; 184 185 // if a visualization of the hierarchical culling is shown 186 bool mShowVisualization; 187 188 // if the culled nodes are indicated in the visualization 189 bool mVisualizeCulledNodes; 190 191 // consecutive number for sub-entities 192 int mCurrentEntityId; 193 194 // flag for passes which should not be deleted from queue during first traversal 195 int mLeavePassesInQueue; 196 197 // if symbols for the nodes are shown in the visualization 198 bool mRenderNodesForViz; 199 // if content of the nodes is shown in the visualization 200 bool mRenderNodesContentForViz; 201 /// render transparents after the hierarchical traversal 202 bool mDelayRenderTransparents; 203 204 // if transparent object are considered for item buffer visibility 205 bool mRenderTransparentsForItemBuffer; 206 // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer 207 bool mExecuteVertexProgramForAllPasses; 208 209 // the depth pass (no lighting, just filling the depth buffer) 210 Pass *mDepthPass; 211 // use a depth pass (i.e., fill only the depth buffer in the first pass) 212 bool mUseDepthPass; 213 // flag indicating if we currently render the depth pass 214 bool mIsDepthPassPhase; 215 // if depth write should be enabled 216 bool mEnableDepthWrite; 217 // if transparents are skipped during rendering 218 bool mSkipTransparents; 219 220 // the item buffer pass (render items color-coded) 221 Pass *mItemBufferPass; 222 // if we use an item buffer for rendering (i.e., object ids as color codes 223 bool mUseItemBuffer; 224 // if we currently render the item buffer 225 bool mIsItemBufferPhase; 226 227 /************************************************************************/ 228 /* Kd-Tree specific options & members */ 229 /************************************************************************/ 230 // maximum depth of the kdtree 231 int mMaxDepth; 232 233 // the kdtree which holds the scene 234 KdTree *mKdTree; 235 236 // if bounding boxes of kdtree nodes are shown 237 bool mShowBoxes; 238 239 // the method/algorithm used when rendering the scene 240 KdTree::RenderMethod mRenderMethod; 241 242 // the method of building the tree 243 KdTree::BuildMethod mBuildMethod; 62 // DEBUG 63 //if (mKdTree) 64 // mKdTree->dump(); 65 66 // must happen before actual scene is cleared 67 OGRE_DELETE(mKdTree); 68 69 SceneManager::clearScene(); 70 } 71 72 /************************************************************************/ 73 /* Functions overridden from SceneManager for CHC */ 74 /************************************************************************/ 75 76 /** Override from SceneManager so that sub entities can be assigned an id for item buffer. 77 */ 78 Entity* createEntity(const String& entityName, const String& meshName); 79 80 /** Override from scene manager to set up culling manager 81 */ 82 virtual void _updateSceneGraph(Camera* cam); 83 84 /** Override from SceneManager, employ normal rendering or CHC 85 */ 86 virtual void _renderVisibleObjects(); 87 88 /** Override pass so we can do the z-fail pass. 89 */ 90 const Pass* _setPass(Pass* pass); 91 92 /** Render a queue group. 93 Override so we can handle delayed rendering of transparent objects 94 */ 95 void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, 96 QueuedRenderableCollection::OrganisationMode om); 97 98 /** Override from scene manager 99 */ 100 void _renderQueueGroupObjects(RenderQueueGroup* pGroup, 101 QueuedRenderableCollection::OrganisationMode om); 102 103 /** Override from SceneManager so we can skip all but first pass for depth pass. 104 */ 105 bool validatePassForRendering(Pass* pass); 106 107 /** Override from SceneManager because idontknow 108 */ 109 void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, 110 QueuedRenderableCollection::OrganisationMode om); 111 void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, 112 QueuedRenderableCollection::OrganisationMode om); 113 114 115 /************************************************************************/ 116 /* Functions which are specific to the KdTree */ 117 /************************************************************************/ 118 119 /** Update the KdTree with the node (more or less disabled now) 120 */ 121 virtual void _updateNode(KdTreeSceneNode *node); // TODO: 122 123 /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options 124 */ 125 virtual void setShowBoxes(bool showboxes); 126 /** Tell if show boxes is enabled - obsolete, use options 127 */ 128 virtual bool getShowBoxes(void) const; 129 130 /************************************************************************/ 131 /* Functions for CHC */ 132 /************************************************************************/ 133 134 /** Render a list of scenenodes 135 */ 136 virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam, 137 bool onlyShadowCasters, int leavePassesInQueue); 138 139 /** Sets the visibility manager. 140 @param visManager the visibility manager 141 */ 142 void setVisibilityManager(GtpVisibility::VisibilityManager *visManager); 143 /** See set. 144 */ 145 GtpVisibility::VisibilityManager *getVisibilityManager(); 146 147 /** Returns pointer to visibility manager. 148 */ 149 GtpVisibility::VisibilityManager *GetVisibilityManager(); 150 151 /** Returns hierarchy interface. 152 */ 153 KdTreeHierarchyInterface *GetHierarchyInterface(); 154 155 protected: 156 /** Creates material for depth pass, e.g., a pass that only fills the depth buffer. 157 */ 158 void InitDepthPass(); 159 /** Creates material for item buffer. 160 */ 161 void InitItemBufferPass(); 162 /** Fills render queue so that a visualization can be rendered. 163 */ 164 void PrepareVisualization(Camera *cam); 165 /** Initialises necessary parameters for hierarchical visibility culling. 166 */ 167 void InitVisibilityCulling(Camera *cam); 168 169 /** Writes out stats into the Ogre log file. 170 */ 171 void WriteLog(); 172 173 174 /************************************************************************/ 175 /* CHC-specific options & members */ 176 /************************************************************************/ 177 // pointer to the visibility manager 178 GtpVisibility::VisibilityManager *mVisibilityManager; 179 180 // the hierarchy interface for CHC 181 KdTreeHierarchyInterface *mHierarchyInterface; 182 183 // if hierarchical culling is currently in use 184 bool mIsHierarchicalCulling; 185 186 // if a visualization of the hierarchical culling is shown 187 bool mShowVisualization; 188 189 // if the culled nodes are indicated in the visualization 190 bool mVisualizeCulledNodes; 191 192 // consecutive number for sub-entities 193 int mCurrentEntityId; 194 195 // flag for passes which should not be deleted from queue during first traversal 196 int mLeavePassesInQueue; 197 198 // if symbols for the nodes are shown in the visualization 199 bool mRenderNodesForViz; 200 // if content of the nodes is shown in the visualization 201 bool mRenderNodesContentForViz; 202 /// render transparents after the hierarchical traversal 203 bool mDelayRenderTransparents; 204 205 // if transparent object are considered for item buffer visibility 206 bool mRenderTransparentsForItemBuffer; 207 // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer 208 bool mExecuteVertexProgramForAllPasses; 209 210 // the depth pass (no lighting, just filling the depth buffer) 211 Pass *mDepthPass; 212 // use a depth pass (i.e., fill only the depth buffer in the first pass) 213 bool mUseDepthPass; 214 // flag indicating if we currently render the depth pass 215 bool mIsDepthPassPhase; 216 // if depth write should be enabled 217 bool mEnableDepthWrite; 218 // if transparents are skipped during rendering 219 bool mSkipTransparents; 220 221 // the item buffer pass (render items color-coded) 222 Pass *mItemBufferPass; 223 // if we use an item buffer for rendering (i.e., object ids as color codes 224 bool mUseItemBuffer; 225 // if we currently render the item buffer 226 bool mIsItemBufferPhase; 227 228 // remember visited scene nodes for viz 229 KdRenderableList mVisibleNodes; 230 231 /************************************************************************/ 232 /* Kd-Tree specific options & members */ 233 /************************************************************************/ 234 // maximum depth of the kdtree 235 int mMaxDepth; 236 237 // the kdtree which holds the scene 238 KdTree *mKdTree; 239 240 // if bounding boxes of kdtree nodes are shown 241 bool mShowBoxes; 242 243 // the method/algorithm used when rendering the scene 244 KdTree::RenderMethod mRenderMethod; 245 246 // the method of building the tree 247 KdTree::BuildMethod mBuildMethod; 244 248 #ifdef KDTREE_DEBUG 245 246 247 248 249 // bounding boxes of kd nodes will be highlighted on this level of the kd tree 250 int mHighlighLevel; 251 // if all bounding boxes shall be displayed, not only the highlighted level 252 bool mShowAllBoxes; 249 253 #endif 254 }; 255 256 257 258 /// Factory for KdTreeSceneManager 259 class KdTreeSceneManagerFactory : public SceneManagerFactory 260 { 261 protected: 262 void initMetaData(void) const; 263 GtpVisibility::VisibilityManager *visManager; 264 public: 265 KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm) 266 { 267 visManager = vm; 250 268 }; 251 252 253 254 /// Factory for KdTreeSceneManager 255 class KdTreeSceneManagerFactory : public SceneManagerFactory 256 { 257 protected: 258 void initMetaData(void) const; 259 GtpVisibility::VisibilityManager *visManager; 260 public: 261 KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm) 262 { 263 visManager = vm; 264 }; 265 ~KdTreeSceneManagerFactory(void) {}; 266 /// Factory type name 267 static const String FACTORY_TYPE_NAME; 268 SceneManager* createInstance(const String& instanceName); 269 void destroyInstance(SceneManager* instance); 270 }; 269 ~KdTreeSceneManagerFactory(void) {}; 270 /// Factory type name 271 static const String FACTORY_TYPE_NAME; 272 SceneManager* createInstance(const String& instanceName); 273 void destroyInstance(SceneManager* instance); 274 }; 271 275 272 276 } // namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
r1183 r1185 41 41 mLeavePassesInQueue(0), 42 42 mDelayRenderTransparents(true), 43 mUseDepthPass( false),43 mUseDepthPass(true), 44 44 mIsDepthPassPhase(false), 45 45 mUseItemBuffer(false), … … 589 589 } 590 590 } 591 592 mVisibleNodes.clear(); 591 593 } 592 594 … … 695 697 if (mUseDepthPass) 696 698 { 697 //NodeList::const_iterator it, it_end = mVisible.end();698 699 // //getRenderQueue()->clear();700 //for (it = mVisible.begin(); it != it_end; ++ it)701 //{702 // (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);703 //}699 KdRenderableList::const_iterator it, it_end = mVisibleNodes.end(); 700 701 //getRenderQueue()->clear(); 702 for (it = mVisibleNodes.begin(); it != it_end; ++ it) 703 { 704 (*it)->queueObjects(mCameraInProgress, getRenderQueue(), false); 705 } 704 706 } 705 707 #endif … … 722 724 } 723 725 724 // TODO: looks too easy, verify if it works725 726 void KdTreeSceneManager::_renderNodes(const KdRenderableList& nodelist, Camera * cam, 726 727 bool onlyShadowCasters, int leavePassesInQueue) 727 728 { 728 729 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 729 _deleteRenderedQueueGroups(leavePassesInQueue); //try avoiding modified ogre code 730 RenderQueueGroup *currentGroup = 731 getRenderQueue()->getQueueGroup(getRenderQueue()->getDefaultQueueGroup()); 732 currentGroup->clear(leavePassesInQueue); 730 733 #else 731 734 getRenderQueue()->clear(); … … 737 740 if (!(*it)->isQueued(mHierarchyInterface->GetFrameId(), cam)) 738 741 { 742 mVisibleNodes.push_back(*it); 739 743 (*it)->queueObjects(cam, getRenderQueue(), onlyShadowCasters); 740 744 } … … 742 746 } 743 747 744 SceneManager::_renderVisibleObjects(); 745 748 _renderQueueGroupObjects(currentGroup, QueuedRenderableCollection::OM_PASS_GROUP); 746 749 } 747 750 //----------------------------------------------------------------------- … … 946 949 //} 947 950 948 if (mRenderNodesForViz || mRenderNodesContentForViz) 949 { 950 // HACK: change node material so it is better suited for visualization 951 MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial"); 952 nodeMat->setAmbient(1, 1, 0); 953 nodeMat->setLightingEnabled(true); 954 nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 955 956 //for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 957 //{ 958 // if (mRenderNodesForViz) 959 // { 960 // // render the leaf nodes 961 // if ((*it)->numAttachedObjects() && 962 // !(*it)->numChildren() && 963 // ((*it)->getAttachedObject(0)->getMovableType() == "Entity") && 964 // (*it)->getAttachedObject(0)->isVisible()) 965 // { 966 // getRenderQueue()->addRenderable((*it)); 967 // } 968 969 // // addbounding boxes instead of node itself 970 // //(*it)->_addBoundingBoxToQueue(getRenderQueue()); 971 // } 972 // // add renderables itself 973 // if (mRenderNodesContentForViz) 974 // { 975 // (*it)->_addToRenderQueue(cam, getRenderQueue(), false); 976 // } 977 //} 978 } 951 if (mRenderNodesForViz || mRenderNodesContentForViz) 952 { 953 // HACK: change node material so it is better suited for visualization 954 MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial"); 955 nodeMat->setAmbient(1, 1, 0); 956 nodeMat->setLightingEnabled(true); 957 nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 958 959 for (KdRenderableList::iterator it = mVisibleNodes.begin(); it != mVisibleNodes.end(); ++it) 960 { 961 if (mRenderNodesForViz) 962 { 963 KdTreeSceneNode * node = static_cast<KdTreeSceneNode *>(*it); 964 // render the leaf nodes 965 if (node->numAttachedObjects() && 966 !node->numChildren() && 967 (node->getAttachedObject(0)->getMovableType() == "Entity") && 968 node->getAttachedObject(0)->isVisible()) 969 { 970 getRenderQueue()->addRenderable(node); 971 } 972 973 // addbounding boxes instead of node itself 974 //(*it)->_addBoundingBoxToQueue(getRenderQueue()); 975 } 976 // add renderables itself 977 if (mRenderNodesContentForViz) 978 { 979 (*it)->queueObjects(cam, getRenderQueue(), false); 980 } 981 } 982 } 979 983 } 980 984 //-----------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.