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