1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of the GameTools Project
|
---|
4 | http://www.gametools.org
|
---|
5 |
|
---|
6 | Author: Martin Szydlowski
|
---|
7 | -----------------------------------------------------------------------------
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef _OgreBihRenderable_H__
|
---|
11 | #define _OgreBihRenderable_H__
|
---|
12 |
|
---|
13 | #include "OgreBiHierarchy.h"
|
---|
14 |
|
---|
15 | namespace Ogre
|
---|
16 | {
|
---|
17 |
|
---|
18 | // interface which must be implemented by all objects which desire to be
|
---|
19 | // placed in the kd-tree
|
---|
20 | class BihRenderable
|
---|
21 | {
|
---|
22 | public:
|
---|
23 | BihRenderable():mSide(BihPlaneEvent::PES_BOTH), mClassified(false), mLastQueued(0), mBiHierarchy(0)
|
---|
24 | {
|
---|
25 | setDecided(0,false); setDecided(1,false); setDecided(2,false);
|
---|
26 | };
|
---|
27 | virtual ~BihRenderable()
|
---|
28 | {
|
---|
29 | if (mBiHierarchy)
|
---|
30 | mBiHierarchy->remove(this);
|
---|
31 | }
|
---|
32 |
|
---|
33 | // gather the information required for the creation of the kd-tree
|
---|
34 | virtual void computeScene(BihPlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren = true) = 0;
|
---|
35 |
|
---|
36 | // put all objects this element holds in the renedering queue
|
---|
37 | virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters) = 0;
|
---|
38 |
|
---|
39 | // place all entities in geometry queue (for CHC)
|
---|
40 | virtual void getGeometryList(GeometryVector *geometryList) = 0;
|
---|
41 |
|
---|
42 | // return a bounding box enclosing all objects
|
---|
43 | virtual AxisAlignedBox getBoundingBox() const = 0;
|
---|
44 |
|
---|
45 | // TODO: reconsider getters/setters !!!
|
---|
46 | inline bool isClassified()
|
---|
47 | {
|
---|
48 | return mClassified;
|
---|
49 | };
|
---|
50 | inline void setClassified(bool q)
|
---|
51 | {
|
---|
52 | mClassified = q;
|
---|
53 | };
|
---|
54 |
|
---|
55 | inline isDecided(int w)
|
---|
56 | {
|
---|
57 | return mDecided[w];
|
---|
58 | };
|
---|
59 | inline void setDecided(int w,bool b)
|
---|
60 | {
|
---|
61 | mDecided[w] = b;
|
---|
62 | };
|
---|
63 |
|
---|
64 | inline BihPlaneEvent::Side getSide()
|
---|
65 | {
|
---|
66 | return mSide;
|
---|
67 | };
|
---|
68 | inline void setSide(BihPlaneEvent::Side s)
|
---|
69 | {
|
---|
70 | mSide = s;
|
---|
71 | };
|
---|
72 |
|
---|
73 | inline void setActualSide(int d,BihPlaneEvent::Side s)
|
---|
74 | {
|
---|
75 | mActualSide[d] = s;
|
---|
76 | };
|
---|
77 |
|
---|
78 | inline void FinalizeSide(int d)
|
---|
79 | {
|
---|
80 | mFinalSide[d]=mActualSide[d];
|
---|
81 | };
|
---|
82 |
|
---|
83 | inline BihPlaneEvent::Side GetFinalSide(int d)
|
---|
84 | {
|
---|
85 | return mFinalSide[d];
|
---|
86 | };
|
---|
87 |
|
---|
88 | // funcions for attachment/detachment of renderables to/from the kd-tree
|
---|
89 | inline bool isAttached()
|
---|
90 | {
|
---|
91 | return mLeaves.size() != 0;
|
---|
92 | };
|
---|
93 | // the following functions should work in O(log N)
|
---|
94 | inline bool isAttached(BiHierarchy::LeafPtr leaf)
|
---|
95 | {
|
---|
96 | return mLeaves.find(leaf) != mLeaves.end();
|
---|
97 | };
|
---|
98 | inline bool attachTo(BiHierarchy::LeafPtr leaf, BiHierarchy * BiHierarchy)
|
---|
99 | {
|
---|
100 | if (mBiHierarchy == 0 || mBiHierarchy == BiHierarchy)
|
---|
101 | mBiHierarchy = BiHierarchy;
|
---|
102 | else
|
---|
103 | return false;
|
---|
104 |
|
---|
105 | BiHierarchy::LeafSet::_Pairib p = mLeaves.insert(leaf);
|
---|
106 | return p.second;
|
---|
107 | };
|
---|
108 | inline bool detachFrom(BiHierarchy::LeafPtr leaf)
|
---|
109 | {
|
---|
110 | bool success = (mLeaves.erase(leaf) == 1);
|
---|
111 | if (mLeaves.size() == 0)
|
---|
112 | mBiHierarchy = 0;
|
---|
113 |
|
---|
114 | return success;
|
---|
115 | };
|
---|
116 |
|
---|
117 | inline bool isQueued(unsigned long currentFrame, Camera * currentCam)
|
---|
118 | {
|
---|
119 | if (mLastQueued == currentFrame && mLastCam == currentCam)
|
---|
120 | {
|
---|
121 | return true;
|
---|
122 | }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | mLastQueued = currentFrame;
|
---|
126 | mLastCam = currentCam;
|
---|
127 | return false;
|
---|
128 | }
|
---|
129 | };
|
---|
130 |
|
---|
131 | BiHierarchy::LeafSet& getLeaves()
|
---|
132 | {
|
---|
133 | return mLeaves;
|
---|
134 | };
|
---|
135 |
|
---|
136 | protected:
|
---|
137 | // number of the frame in which this renderable was last queued for rendering
|
---|
138 | unsigned long mLastQueued;
|
---|
139 | // the camera for which this renderable was last queued for rendering
|
---|
140 | Camera * mLastCam;
|
---|
141 |
|
---|
142 | // BiHierarchy to which this renderable is attached
|
---|
143 | BiHierarchy * mBiHierarchy;
|
---|
144 | // BiHierarchy leaves which overlap this renderable
|
---|
145 | BiHierarchy::LeafSet mLeaves;
|
---|
146 |
|
---|
147 | // Flag for the SAH determining the "cheaper" side of the split plane
|
---|
148 | BihPlaneEvent::Side mSide;
|
---|
149 | BihPlaneEvent::Side mFinalSide[3];
|
---|
150 | BihPlaneEvent::Side mActualSide[3];
|
---|
151 | // Flag for the SAH which marks if this renderable was already placed in the list after a split
|
---|
152 | bool mClassified;
|
---|
153 |
|
---|
154 | bool mDecided[3];
|
---|
155 | }; // class BihRenderable
|
---|
156 |
|
---|
157 | } // namespace Ogre
|
---|
158 |
|
---|
159 | #endif // _OgreBihRenderable_H__
|
---|