source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityPredictor.cpp @ 2558

Revision 2558, 2.5 KB checked in by mattausch, 17 years ago (diff)
Line 
1#include "OgreVisibilityPredictor.h"
2#include "OgreBoundingBoxConverter.h"
3#include "DistanceQueue.h"
4
5
6const static int maxInvisibleNodesSize = 50;
7
8
9namespace Ogre
10{
11        struct EntityQuery
12        {
13                GtpVisibility::OcclusionQuery *mQuery;
14                vector<Entity *> mEntities;
15        };
16
17        typedef std::queue<EntityQuery> EntityQueryQueue;
18
19        VisibilityPredictor::VisibilityPredictor()
20        {
21        }
22
23        void VisibilityPredictor::HandleProbablyVisibleObjects(GtpVisibilityPreprocessor::ViewCell *vc)
24        {
25                EntityQueryQueue queryQueue;
26                vector<Entity *> invisibleEntities;
27
28                // use multiqueries for the objects that are probably invisible
29        GtpVisibilityPreprocessor::ObjectPvsIterator pit = vc->GetPvs().GetIterator();
30
31                while (pit.HasMoreEntries())
32                {               
33                        GtpVisibilityPreprocessor::Intersectable *obj = pit.Next();
34           
35                        if (obj->Type() != GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE)
36                                continue;
37               
38                        EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
39
40                        EntityContainer *entries = oi->GetItem();
41                       
42                        EntityContainer::const_iterator eit, eit_end = entries->end();
43
44                        for (eit = entries->begin(); eit != eit_end; ++ eit)
45                        {
46                                // collect entities for multiqueries
47                                invisibleEntities.push_back(*eit);
48
49                                if ((int)invisibleEntities.size() >= maxInvisibleNodesSize)
50                                {
51                                        // issue the batched queries
52                                        IssueMultiQuery(invisibleEntities);
53                                        invisibleEntities.clear();
54                                }
55                        }
56                }
57       
58                while(!queryQueue.empty())
59                {
60                        unsigned int visiblePixels;
61
62                        // fetch multiquery result
63                        queryQueue.front().mQuery->GetQueryResult(visiblePixels, false);
64
65                        size_t n = queryQueue.front().mEntities.size();
66
67                        // tested visible
68                        if (visiblePixels > 0)
69                        {
70                                // render nodes assoziated with current multiquery
71                                for (size_t i = 0; i < n; ++ i)
72                                {
73                                        Entity *ent = queryQueue.front().mEntities[i];
74                                        // render entity
75
76                                        // we have to store the entity and test it individually later
77                                        mEntityBuffer.push_back(ent);
78                                }
79                        }
80
81                        queryQueue.pop();
82                }       
83        }
84
85
86        void VisibilityPredictor::UpdateVisibility(GtpVisibilityPreprocessor::ViewCell *vc)
87        {
88                GtpVisibility::HierarchyNodeContainer::const_iterator nit, nit_end = mEntityBuffer.end();
89
90                // test individual nodes
91                for (nit = mEntityBuffer.begin(); nit != nit_end; ++ nit)
92                {
93
94                }
95
96                // fetch query results, update PVS of view cell
97                for (nit = mEntityBuffer.begin(); nit != nit_end; ++ nit)
98                {
99
100                }
101
102                mEntityBuffer.clear();
103        }
104
105       
106        void VisibilityPredictor::IssueMultiQuery(const vector<Entity *> &mEntities)
107        {
108        }
109}
Note: See TracBrowser for help on using the repository browser.