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 _OgreBvhRenderable_H__
|
---|
11 | #define _OgreBvhRenderable_H__
|
---|
12 |
|
---|
13 | #include "OgreBvHierarchy.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 BvhRenderable
|
---|
21 | {
|
---|
22 | public:
|
---|
23 | BvhRenderable():mSide(BvhPlaneEvent::PES_BOTH), mClassified(false), mLastQueued(0), mBvHierarchy(0) {};
|
---|
24 | virtual ~BvhRenderable()
|
---|
25 | {
|
---|
26 | if (mBvHierarchy)
|
---|
27 | mBvHierarchy->remove(this);
|
---|
28 | }
|
---|
29 |
|
---|
30 | // gather the information required for the creation of the kd-tree
|
---|
31 | virtual void computeScene(BvhPlaneEventList& 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(GtpVisibility::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 BvhPlaneEvent::Side getSide()
|
---|
53 | {
|
---|
54 | return mSide;
|
---|
55 | };
|
---|
56 | inline void setSide(BvhPlaneEvent::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(BvHierarchy::LeafPtr leaf)
|
---|
68 | {
|
---|
69 | return mLeaves.find(leaf) != mLeaves.end();
|
---|
70 | };
|
---|
71 | inline bool attachTo(BvHierarchy::LeafPtr leaf, BvHierarchy * BvHierarchy)
|
---|
72 | {
|
---|
73 | if (mBvHierarchy == 0 || mBvHierarchy == BvHierarchy)
|
---|
74 | mBvHierarchy = BvHierarchy;
|
---|
75 | else
|
---|
76 | return false;
|
---|
77 |
|
---|
78 | BvHierarchy::LeafSet::_Pairib p = mLeaves.insert(leaf);
|
---|
79 | return p.second;
|
---|
80 | };
|
---|
81 | inline bool detachFrom(BvHierarchy::LeafPtr leaf)
|
---|
82 | {
|
---|
83 | bool success = (mLeaves.erase(leaf) == 1);
|
---|
84 | if (mLeaves.size() == 0)
|
---|
85 | mBvHierarchy = 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 | BvHierarchy::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 | // BvHierarchy to which this renderable is attached
|
---|
116 | BvHierarchy * mBvHierarchy;
|
---|
117 | // BvHierarchy leaves which overlap this renderable
|
---|
118 | BvHierarchy::LeafSet mLeaves;
|
---|
119 |
|
---|
120 | // Flag for the SAH determining the "cheaper" side of the split plane
|
---|
121 | BvhPlaneEvent::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 BvhRenderable
|
---|
125 |
|
---|
126 | } // namespace Ogre
|
---|
127 |
|
---|
128 | #endif // _OgreBvhRenderable_H__
|
---|