[1318] | 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 |
|
---|
[1320] | 10 | #ifndef _OgreBvhRenderable_H__
|
---|
| 11 | #define _OgreBvhRenderable_H__
|
---|
[1318] | 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
|
---|
[1320] | 20 | class BvhRenderable
|
---|
[1318] | 21 | {
|
---|
| 22 | public:
|
---|
[1320] | 23 | BvhRenderable():mSide(BvhPlaneEvent::PES_BOTH), mClassified(false), mLastQueued(0), mBvHierarchy(0) {};
|
---|
| 24 | virtual ~BvhRenderable()
|
---|
[1318] | 25 | {
|
---|
| 26 | if (mBvHierarchy)
|
---|
| 27 | mBvHierarchy->remove(this);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | // gather the information required for the creation of the kd-tree
|
---|
[1320] | 31 | virtual void computeScene(BvhPlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren = true) = 0;
|
---|
[1318] | 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 |
|
---|
[1320] | 52 | inline BvhPlaneEvent::Side getSide()
|
---|
[1318] | 53 | {
|
---|
| 54 | return mSide;
|
---|
| 55 | };
|
---|
[1320] | 56 | inline void setSide(BvhPlaneEvent::Side s)
|
---|
[1318] | 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)
|
---|
[1320] | 67 | inline bool isAttached(BvHierarchy::LeafPtr leaf)
|
---|
[1318] | 68 | {
|
---|
| 69 | return mLeaves.find(leaf) != mLeaves.end();
|
---|
| 70 | };
|
---|
[1320] | 71 | inline bool attachTo(BvHierarchy::LeafPtr leaf, BvHierarchy * BvHierarchy)
|
---|
[1318] | 72 | {
|
---|
[1320] | 73 | if (mBvHierarchy == 0 || mBvHierarchy == BvHierarchy)
|
---|
| 74 | mBvHierarchy = BvHierarchy;
|
---|
[1318] | 75 | else
|
---|
| 76 | return false;
|
---|
| 77 |
|
---|
[1320] | 78 | BvHierarchy::LeafSet::_Pairib p = mLeaves.insert(leaf);
|
---|
[1318] | 79 | return p.second;
|
---|
| 80 | };
|
---|
[1320] | 81 | inline bool detachFrom(BvHierarchy::LeafPtr leaf)
|
---|
[1318] | 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 |
|
---|
[1320] | 104 | BvHierarchy::LeafSet& getLeaves()
|
---|
[1318] | 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 |
|
---|
[1320] | 115 | // BvHierarchy to which this renderable is attached
|
---|
| 116 | BvHierarchy * mBvHierarchy;
|
---|
| 117 | // BvHierarchy leaves which overlap this renderable
|
---|
| 118 | BvHierarchy::LeafSet mLeaves;
|
---|
[1318] | 119 |
|
---|
| 120 | // Flag for the SAH determining the "cheaper" side of the split plane
|
---|
[1320] | 121 | BvhPlaneEvent::Side mSide;
|
---|
[1318] | 122 | // Flag for the SAH which marks if this renderable was already placed in the list after a split
|
---|
| 123 | bool mClassified;
|
---|
[1320] | 124 | }; // class BvhRenderable
|
---|
[1318] | 125 |
|
---|
| 126 | } // namespace Ogre
|
---|
| 127 |
|
---|
[1320] | 128 | #endif // _OgreBvhRenderable_H__
|
---|