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

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