1 | #ifndef SUBDIVISIONCANDIDATE_H
|
---|
2 | #define SUBDIVISIONCANDIDATE_H
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "FlexibleHeap.h"
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | class SubdivisionCandidate;
|
---|
12 |
|
---|
13 | typedef vector<SubdivisionCandidate *> SubdivisionCandidateContainer;
|
---|
14 | typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue;
|
---|
15 |
|
---|
16 | /** Candidate for a view space / object space split.
|
---|
17 | */
|
---|
18 | class SubdivisionCandidate: public Heapable
|
---|
19 | {
|
---|
20 | public:
|
---|
21 |
|
---|
22 | enum {OBJECT_SPACE, VIEW_SPACE};
|
---|
23 |
|
---|
24 | SubdivisionCandidate(): mRenderCostDecrease(0), mDirty(true) {};
|
---|
25 |
|
---|
26 | virtual ~SubdivisionCandidate() {};
|
---|
27 | /** Evaluate this subdivision candidate.
|
---|
28 | */
|
---|
29 | virtual void EvalCandidate(bool computeSplitplane = true) = 0;
|
---|
30 | /** Returns type of this subdivision candidate.
|
---|
31 | */
|
---|
32 | virtual int Type() const = 0;
|
---|
33 | /** Evaluate this candidate and put results into queue for further traversal.
|
---|
34 | */
|
---|
35 | virtual bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) = 0;
|
---|
36 | /** Returns true of the global termination criteria of this split were met,
|
---|
37 | false otherwise.
|
---|
38 | */
|
---|
39 | virtual bool GlobalTerminationCriteriaMet() const = 0;
|
---|
40 | /** Collects subdivision candidates that were affected by the
|
---|
41 | application of this one.
|
---|
42 | */
|
---|
43 | virtual void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList,
|
---|
44 | const bool onlyUnmailed) = 0;
|
---|
45 |
|
---|
46 | /** Set render cost decrease achieved through this split.
|
---|
47 | */
|
---|
48 | inline void SetRenderCostDecrease(const float renderCostDecr)
|
---|
49 | {
|
---|
50 | mRenderCostDecrease = renderCostDecr;
|
---|
51 | }
|
---|
52 |
|
---|
53 | inline float GetRenderCostDecrease() const
|
---|
54 | {
|
---|
55 | return mRenderCostDecrease;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /** Position in queue.
|
---|
59 | */
|
---|
60 | inline int GetPosition() const
|
---|
61 | {
|
---|
62 | return mPosition;
|
---|
63 | }
|
---|
64 |
|
---|
65 | inline void SetSplitAxis(const int splitAxis)
|
---|
66 | {
|
---|
67 | mSplitAxis = splitAxis;
|
---|
68 | }
|
---|
69 |
|
---|
70 | inline void SetMaxCostMisses(const int misses)
|
---|
71 | {
|
---|
72 | mMaxCostMisses = misses;
|
---|
73 | }
|
---|
74 |
|
---|
75 | inline void SetPvsEntriesIncr(const int pvsEntriesIncr)
|
---|
76 | {
|
---|
77 | mPvsEntriesIncr = pvsEntriesIncr;
|
---|
78 | }
|
---|
79 |
|
---|
80 | inline int GetSplitAxis() const
|
---|
81 | {
|
---|
82 | return mSplitAxis;
|
---|
83 | }
|
---|
84 |
|
---|
85 | inline int GetMaxCostMisses() const
|
---|
86 | {
|
---|
87 | return mMaxCostMisses;
|
---|
88 | }
|
---|
89 |
|
---|
90 | inline int GetPvsEntriesIncr() const
|
---|
91 | {
|
---|
92 | return mPvsEntriesIncr;
|
---|
93 | }
|
---|
94 |
|
---|
95 | inline bool IsDirty() const
|
---|
96 | {
|
---|
97 | return mDirty;
|
---|
98 | }
|
---|
99 |
|
---|
100 | inline void SetDirty(const bool dirty)
|
---|
101 | {
|
---|
102 | mDirty = dirty;
|
---|
103 | }
|
---|
104 |
|
---|
105 | //////////
|
---|
106 | //-- mailing stuff
|
---|
107 |
|
---|
108 | static void NewMail(const int reserve = 1)
|
---|
109 | {
|
---|
110 | sMailId += sReservedMailboxes;
|
---|
111 | sReservedMailboxes = reserve;
|
---|
112 | }
|
---|
113 |
|
---|
114 | void Mail() { mMailbox = sMailId; }
|
---|
115 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
116 |
|
---|
117 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
118 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
119 |
|
---|
120 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
121 |
|
---|
122 |
|
---|
123 | // last mail id -> warning not thread safe!
|
---|
124 | // both mailId and mailbox should be unique for each thread!!!
|
---|
125 | static int sMailId;
|
---|
126 | static int sReservedMailboxes;
|
---|
127 |
|
---|
128 | void *mEvaluationHack;
|
---|
129 |
|
---|
130 | protected:
|
---|
131 |
|
---|
132 | /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned)
|
---|
133 | int mSplitAxis;
|
---|
134 | /// the number of misses of max cost ratio until this split
|
---|
135 | int mMaxCostMisses;
|
---|
136 | /// render cost decrease achieved through this split
|
---|
137 | float mRenderCostDecrease;
|
---|
138 | /// the decrease of the number of pvs entries
|
---|
139 | int mPvsEntriesIncr;
|
---|
140 |
|
---|
141 | int mMailbox;
|
---|
142 |
|
---|
143 | bool mDirty;
|
---|
144 | };
|
---|
145 |
|
---|
146 |
|
---|
147 | }
|
---|
148 |
|
---|
149 | // SUBDIVISIONCANDIDATE_H
|
---|
150 | #endif
|
---|