source: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp @ 2555

Revision 2555, 6.1 KB checked in by mattausch, 17 years ago (diff)

added partial implementation of chc++. problem: bounding box rendering in Ogre is VERY slow

RevLine 
[59]1#include "VisibilityManager.h"
2#include "StopAndWaitCullingManager.h"
3#include "CoherentHierarchicalCullingManager.h"
4#include "FrustumCullingManager.h"
[65]5#include "DummyPreprocessingManager.h"
[2278]6#include "RandomUpdateCullingManager.h"
[2555]7#include "CoherentHierarchicalCullingPlusPlusManager.h"
[2280]8#include "CullingLogManager.h"
[59]9
[2280]10
[59]11namespace GtpVisibility {
[95]12
[74]13//-----------------------------------------------------------------------
14VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment):
[722]15mVisibilityThreshold(0),
16mCullingManager(NULL),
[153]17mQueryManager(NULL),
[100]18mPreprocessingManager(new DummyPreprocessingManager(NULL)),
[147]19mVisibilityEnvironment(visEnvironment),
[155]20mAssumedVisibilityForChc(0)
[59]21{
[107]22        SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
[59]23}
[74]24//-----------------------------------------------------------------------
[59]25VisibilityManager::~VisibilityManager()
26{
27        delete mCullingManager;
[153]28        delete mPreprocessingManager;
[2280]29        CullingLogManager::DelSingleton();
[59]30}
[74]31//-----------------------------------------------------------------------
[155]32void VisibilityManager::SetCullingManager(VisibilityEnvironment::
33                                                                                  CullingManagerType ocmType)
[59]34{
[94]35        // change only if necessary
36        if (!mCullingManager || (mCullingManagerType != ocmType))
[59]37        {
[92]38                // delete old culling manager
[100]39                if (mCullingManager)
[94]40                        delete mCullingManager;
[155]41
[92]42                mCullingManagerType = ocmType;
43               
[59]44                switch (ocmType)
45                {
46                case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
[2455]47                        {
48                                CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
49                                chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
50                                mCullingManager = chcm;
51                        }
[59]52                        break;
53                case VisibilityEnvironment::FRUSTUM_CULLING:
[2289]54                        mCullingManager = new FrustumCullingManager();
55                        break;
[2555]56                case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS:
[2455]57                        {
[2555]58                                CoherentHierarchicalCullingPlusPlusManager *chcm =
59                                        new CoherentHierarchicalCullingPlusPlusManager(mAssumedVisibilityForChc);
60                                mCullingManager = chcm;
[2455]61                        }
[59]62                        break;
[2287]63                case VisibilityEnvironment::STOP_AND_WAIT_CULLING:
64                        mCullingManager = new StopAndWaitCullingManager();
65                        break;
[59]66                default:
[2280]67                        mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
[59]68                        break;
69                }
[114]70
[2280]71                /////////
[254]72                //-- set threshold
[2455]73
[2280]74                mCullingManager->SetVisibilityThreshold(mVisibilityThreshold); 
[59]75        }
76}
[74]77//-----------------------------------------------------------------------
78void VisibilityManager::SetVisibilityCullingThreshold(unsigned int visibilityThreshold)
79{
80        mVisibilityThreshold = visibilityThreshold;
81        mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
82}
83//-----------------------------------------------------------------------
[59]84CullingManager *VisibilityManager::GetCullingManager()
85{
86        return mCullingManager;
87}
[74]88//-----------------------------------------------------------------------
[59]89void VisibilityManager::ApplyVisibilityCulling()
90{
91        mCullingManager->RenderScene();
92}
[100]93//-----------------------------------------------------------------------
[92]94VisibilityEnvironment::CullingManagerType VisibilityManager::GetCullingManagerType()
95{
96        return mCullingManagerType;
97}
[130]98//-----------------------------------------------------------------------
99void VisibilityManager::SetQueryManager(QueryManager *queryManager)
100{
101        mQueryManager = queryManager;
102}
103//-----------------------------------------------------------------------
104QueryManager *VisibilityManager::GetQueryManager()
105{
106        return mQueryManager;
107}
[153]108//-----------------------------------------------------------------------
[2455]109void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility)                                                                       
[146]110{
[155]111        mAssumedVisibilityForChc = assumedVisibility;
[146]112
[2555]113        switch (mCullingManagerType)
[146]114        {
[2555]115        case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
[2066]116                static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
[2455]117                                SetAssumedVisibility(mAssumedVisibilityForChc);
[2555]118                break;
119        case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS:
120                static_cast<CoherentHierarchicalCullingPlusPlusManager *>(mCullingManager)->
121                                SetAssumedVisibility(mAssumedVisibilityForChc);
122                break;
[146]123        }
124}
[925]125//-----------------------------------------------------------------------
[2455]126void VisibilityManager::SetRandomUpdateCandidatesForRuc(unsigned int randomCandidates)                                                                   
127{
128        mRandomCandidatesForRuc = randomCandidates;
129
[2555]130        if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS)
[2455]131        {
132                static_cast<RandomUpdateCullingManager *>(mCullingManager)->
133                                SetRandomCandidates(mRandomCandidatesForRuc);
134        }
135}
136//-----------------------------------------------------------------------
[925]137VisibilityEnvironment *VisibilityManager::GetVisibilityEnvironment()
138{
139        return mVisibilityEnvironment;
140}
[2455]141//-----------------------------------------------------------------------
142unsigned int VisibilityManager::GetAssumedVisibilityForChc()
143{
144        return mAssumedVisibilityForChc;
145}
146//-----------------------------------------------------------------------
147unsigned int VisibilityManager::GetRandomUpdateCandidatesForRuc()
148{
149        return mRandomCandidatesForRuc;
150}
151//-----------------------------------------------------------------------
152void VisibilityManager::SetTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves)
153{
154        mTestGeometryForVisibleLeaves = testGeometryForVisibleLeaves;
[155]155
[2455]156        if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
157        {
158                static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
159                                SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
160        }
[2555]161        /*else if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS)
[2455]162        {
163                static_cast<RandomUpdateCullingManager *>(mCullingManager)->
164                                SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
[2555]165        }*/
[2455]166}
167//-----------------------------------------------------------------------
168bool VisibilityManager::GetTestGeometryForVisibleLeaves()
169{
170        return mTestGeometryForVisibleLeaves;
171}
172
[59]173} // namespace GtpVisibility
Note: See TracBrowser for help on using the repository browser.