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 | virtual ~BihRenderable()
|
---|
25 | {
|
---|
26 | if (mBiHierarchy)
|
---|
27 | mBiHierarchy->remove(this);
|
---|
28 | }
|
---|
29 |
|
---|
30 | // gather the information required for the creation of the kd-tree
|
---|
31 | virtual void computeScene(BihPlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren = true) = 0;
|
---|
32 |
|
---|
33 | // put all objects this element holds in the renedering queue
|
---|
34 | virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters) = 0;
|
---|
35 |
|
---|
36 | // place all entities in geometry queue (for CHC)
|
---|
37 | virtual void getGeometryList(GeometryVector *geometryList) = 0;
|
---|
38 |
|
---|
39 | // return a bounding box enclosing all objects
|
---|
40 | virtual AxisAlignedBox getBoundingBox() const = 0;
|
---|
41 |
|
---|
42 | // TODO: reconsider getters/setters !!!
|
---|
43 | inline bool isClassified()
|
---|
44 | {
|
---|
45 | return mClassified;
|
---|
46 | };
|
---|
47 | inline void setClassified(bool q)
|
---|
48 | {
|
---|
49 | mClassified = q;
|
---|
50 | };
|
---|
51 |
|
---|
52 | inline BihPlaneEvent::Side getSide()
|
---|
53 | {
|
---|
54 | return mSide;
|
---|
55 | };
|
---|
56 | inline void setSide(BihPlaneEvent::Side s)
|
---|
57 | {
|
---|
58 | mSide = s;
|
---|
59 | };
|
---|
60 |
|
---|
61 | // funcions for attachment/detachment of renderables to/from the kd-tree
|
---|
62 | inline bool isAttached()
|
---|
63 | {
|
---|
64 | return mLeaves.size() != 0;
|
---|
65 | };
|
---|
66 | // the following functions should work in O(log N)
|
---|
67 | inline bool isAttached(BiHierarchy::LeafPtr leaf)
|
---|
68 | {
|
---|
69 | return mLeaves.find(leaf) != mLeaves.end();
|
---|
70 | };
|
---|
71 | inline bool attachTo(BiHierarchy::LeafPtr leaf, BiHierarchy * BiHierarchy)
|
---|
72 | {
|
---|
73 | if (mBiHierarchy == 0 || mBiHierarchy == BiHierarchy)
|
---|
74 | mBiHierarchy = BiHierarchy;
|
---|
75 | else
|
---|
76 | return false;
|
---|
77 |
|
---|
78 | BiHierarchy::LeafSet::_Pairib p = mLeaves.insert(leaf);
|
---|
79 | return p.second;
|
---|
80 | };
|
---|
81 | inline bool detachFrom(BiHierarchy::LeafPtr leaf)
|
---|
82 | {
|
---|
83 | bool success = (mLeaves.erase(leaf) == 1);
|
---|
84 | if (mLeaves.size() == 0)
|
---|
85 | mBiHierarchy = 0;
|
---|
86 |
|
---|
87 | return success;
|
---|
88 | };
|
---|
89 |
|
---|
90 | inline bool isQueued(unsigned long currentFrame, Camera * currentCam)
|
---|
91 | {
|
---|
92 | if (mLastQueued == currentFrame && mLastCam == currentCam)
|
---|
93 | {
|
---|
94 | return true;
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | mLastQueued = currentFrame;
|
---|
99 | mLastCam = currentCam;
|
---|
100 | return false;
|
---|
101 | }
|
---|
102 | };
|
---|
103 |
|
---|
104 | BiHierarchy::LeafSet& getLeaves()
|
---|
105 | {
|
---|
106 | return mLeaves;
|
---|
107 | };
|
---|
108 |
|
---|
109 | protected:
|
---|
110 | // number of the frame in which this renderable was last queued for rendering
|
---|
111 | unsigned long mLastQueued;
|
---|
112 | // the camera for which this renderable was last queued for rendering
|
---|
113 | Camera * mLastCam;
|
---|
114 |
|
---|
115 | // BiHierarchy to which this renderable is attached
|
---|
116 | BiHierarchy * mBiHierarchy;
|
---|
117 | // BiHierarchy leaves which overlap this renderable
|
---|
118 | BiHierarchy::LeafSet mLeaves;
|
---|
119 |
|
---|
120 | // Flag for the SAH determining the "cheaper" side of the split plane
|
---|
121 | BihPlaneEvent::Side mSide;
|
---|
122 | // Flag for the SAH which marks if this renderable was already placed in the list after a split
|
---|
123 | bool mClassified;
|
---|
124 | }; // class BihRenderable
|
---|
125 |
|
---|
126 | } // namespace Ogre
|
---|
127 |
|
---|
128 | #endif // _OgreBihRenderable_H__
|
---|