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