[790] | 1 | #pragma once
|
---|
| 2 | #include "SharedRuns.h"
|
---|
| 3 | #include "OgreRenderable.h"
|
---|
| 4 | #include "Ogre.h"
|
---|
| 5 |
|
---|
| 6 | using namespace Ogre;
|
---|
| 7 |
|
---|
[1055] | 8 | enum GlobalTargetType
|
---|
| 9 | {
|
---|
| 10 | ILLUM_GLOBAL_TARGET_FIREPARTICLES
|
---|
| 11 | };
|
---|
| 12 |
|
---|
| 13 | class GlobalUseRenderTarget
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
| 16 | GlobalUseRenderTarget(){lastUpdated = 0; renderTarget = 0;}
|
---|
| 17 |
|
---|
| 18 | unsigned long lastUpdated;
|
---|
| 19 | RenderTarget* renderTarget;
|
---|
| 20 | };
|
---|
[790] | 21 | /**
|
---|
| 22 | @brief Class of SharedRuns used in an OGRE environment.
|
---|
| 23 | */
|
---|
| 24 | class OgreSharedRuns : public SharedRuns
|
---|
| 25 | {
|
---|
| 26 | public:
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | @brief Constructor.
|
---|
| 30 | */
|
---|
| 31 | OgreSharedRuns(){}
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | @brief Retrieves the contaied RenderingRuns with their type information
|
---|
| 35 |
|
---|
| 36 | @return map of renderables
|
---|
| 37 | */
|
---|
| 38 | std::map<RenderingRunType, RenderingRun*>& getSharedRuns(){return sharedRuns;}
|
---|
| 39 | /**
|
---|
| 40 | @brief Sets the bounding sphere of the node.
|
---|
| 41 |
|
---|
| 42 | @param sphere bounding sphere
|
---|
| 43 | */
|
---|
| 44 | void setBoundingSphere(Sphere& sphere){boundingSphere = sphere;}
|
---|
| 45 | /**
|
---|
| 46 | @brief Sets the axis-aligned bounding box of the node.
|
---|
| 47 |
|
---|
| 48 | @param box bounding box
|
---|
| 49 | */
|
---|
| 50 | void setBoundingBox(AxisAlignedBox& box){boundingBox = box;}
|
---|
| 51 | /**
|
---|
| 52 | @brief Returns the bounding sphere of the node.
|
---|
| 53 |
|
---|
| 54 | @return a reference to the bounding sphere
|
---|
| 55 | */
|
---|
| 56 | Sphere& getBoundingSphere(){ return boundingSphere;}
|
---|
| 57 | /**
|
---|
| 58 | @brief Returns the axis-aligned bounding box of the node.
|
---|
| 59 |
|
---|
| 60 | @return a reference to the bounding box
|
---|
| 61 | */
|
---|
| 62 | AxisAlignedBox& getBoundingBox(){ return boundingBox;}
|
---|
| 63 | /**
|
---|
| 64 | @brief Returns the bounding sphere of the root parent node.
|
---|
| 65 |
|
---|
| 66 | @return a reference to the bounding sphere
|
---|
| 67 | */
|
---|
| 68 | Sphere& getRootBoundingSphere()
|
---|
| 69 | {return ((OgreSharedRuns*)getRoot())->getBoundingSphere();}
|
---|
| 70 | /**
|
---|
| 71 | @brief Retrieves the bounding sphere of the topmost parent node
|
---|
| 72 | of this SharedRuns node, which have a specified RenderingRun type.
|
---|
| 73 |
|
---|
| 74 | @param runType the RenderingRun type
|
---|
| 75 |
|
---|
| 76 | @return a reference to the bounding sphere
|
---|
| 77 | */
|
---|
| 78 | Sphere& getRootBoundingSphere(RenderingRunType runType)
|
---|
| 79 | {return ((OgreSharedRuns*)getRoot(runType))->getBoundingSphere();}
|
---|
| 80 | /**
|
---|
| 81 | @brief Returns the axis-aligned bounding box of the root parent node.
|
---|
| 82 |
|
---|
| 83 | @return a reference to the bounding box
|
---|
| 84 | */
|
---|
| 85 | AxisAlignedBox& getRootBoundingBox()
|
---|
| 86 | {return ((OgreSharedRuns*)getRoot())->getBoundingBox();}
|
---|
| 87 | /**
|
---|
| 88 | @brief Retrieves the axis-aligned bounding box of the topmost parent node
|
---|
| 89 | of this SharedRuns node, which have a specified RenderingRun type.
|
---|
| 90 |
|
---|
| 91 | @param runType the RenderingRun type
|
---|
| 92 |
|
---|
| 93 | @return a reference to the bounding box
|
---|
| 94 | */
|
---|
| 95 | AxisAlignedBox& getRootBoundingBox(RenderingRunType runType)
|
---|
| 96 | {return ((OgreSharedRuns*)getRoot(runType))->getBoundingBox();}
|
---|
| 97 | /**
|
---|
| 98 | @brief Returns the world space center position of the root parent node.
|
---|
| 99 |
|
---|
| 100 | @return a reference to the center position
|
---|
| 101 | */
|
---|
| 102 | const Vector3& getRootPosition()
|
---|
| 103 | {return getRootBoundingSphere().getCenter();}
|
---|
| 104 | /**
|
---|
| 105 | @brief Retrieves the world space center position of the topmost parent node
|
---|
| 106 | of this SharedRuns node, which have a specified RenderingRun type.
|
---|
| 107 |
|
---|
| 108 | @param runType the RenderingRun type
|
---|
| 109 |
|
---|
| 110 | @return a reference to the center position
|
---|
| 111 | */
|
---|
| 112 | const Vector3& getRootPosition(RenderingRunType runType)
|
---|
| 113 | {return getRootBoundingSphere(runType).getCenter();}
|
---|
| 114 | /**
|
---|
| 115 | @brief Checks if two SharedRuns node can be joined.
|
---|
| 116 |
|
---|
| 117 | @param r1 pointer to one of the SharedRuns instance
|
---|
| 118 | @param r2 pointer to the other SharedRuns instance
|
---|
| 119 | */
|
---|
| 120 | static bool canJoin(SharedRuns* r1, SharedRuns* r2);
|
---|
| 121 | /**
|
---|
| 122 | @brief Checks if two SharedRuns have common resources so that they can be joined.
|
---|
| 123 |
|
---|
| 124 | @param r1 pointer to one of the SharedRuns instance
|
---|
| 125 | @param r2 pointer to the other SharedRuns instance
|
---|
| 126 | */
|
---|
[1055] | 127 | static bool haveCommonRuns(SharedRuns* r1, SharedRuns* r2, std::vector<RenderingRunType>& commonruns);
|
---|
[790] | 128 | /**
|
---|
| 129 | @brief Checks if this node has a resource with the given type.
|
---|
| 130 |
|
---|
| 131 | Only this node none of the child nodes are checked.
|
---|
| 132 |
|
---|
| 133 | @param the type of the RenderingRun to look for
|
---|
| 134 | */
|
---|
| 135 | bool hasOwnRun(RenderingRunType runType);
|
---|
| 136 | /**
|
---|
| 137 | @brief Adds all the Renderables connected to this node to a given RenderQueue.
|
---|
| 138 |
|
---|
| 139 | The function is called recoursively for all child nodes.
|
---|
| 140 |
|
---|
| 141 | @param pointer to the RenderQueue to add the Renderables to
|
---|
| 142 | */
|
---|
[1425] | 143 | void addRenderablesToQueue(RenderQueue* rq, bool checkVisible = true);
|
---|
[790] | 144 | /**
|
---|
| 145 | @brief Calls notifyCamera() to all the Renderables connected to this node
|
---|
| 146 |
|
---|
| 147 | The function is called recoursively for all child nodes.
|
---|
| 148 |
|
---|
| 149 | @param pointer to the Camera instance to call notifyCamera() with
|
---|
| 150 | */
|
---|
| 151 | void notifyCamera(Camera* cam);
|
---|
| 152 | /**
|
---|
| 153 | @brief Finds all the topmost nodes which have resources of the given type.
|
---|
| 154 |
|
---|
| 155 | This function is called for the root node, and will be called recoursively downwards in the tree for all childs.
|
---|
| 156 | If a node with with the given resource is found, the node can be added and it's childs don't need to be checked anymore.
|
---|
| 157 |
|
---|
| 158 | From a given group of objects (root node) a new set of groups will be created (they will be the members of the given vector).
|
---|
| 159 | Each new group will be a subtree of the original tree. They will form groups that contain the maximum number of objects
|
---|
| 160 | that can be joined by the the given resource type.
|
---|
| 161 |
|
---|
| 162 | @param runType the type of RenderingRun to look for
|
---|
| 163 | @param roots reference to the collection to add the new groups to
|
---|
| 164 | */
|
---|
| 165 | void findSharedRootsForType(RenderingRunType runType, std::vector<OgreSharedRuns*>& roots);
|
---|
| 166 |
|
---|
| 167 | //inherited
|
---|
| 168 | RenderingRun* getRun(RenderingRunType runType);
|
---|
| 169 | //inherited
|
---|
| 170 | void addRun(RenderingRunType runType, RenderingRun* run);
|
---|
| 171 | //inherited
|
---|
| 172 | void updateRun(RenderingRunType runType, unsigned long frameNum);
|
---|
| 173 | //inherited
|
---|
| 174 | void addRenderable(OgreRenderable* rend)
|
---|
| 175 | {
|
---|
| 176 | if(renderables[rend] != 0)
|
---|
| 177 | renderables[rend] = rend->isVisible();
|
---|
| 178 | }
|
---|
| 179 | //inherited
|
---|
| 180 | void updateBounds();
|
---|
| 181 | //inherited
|
---|
| 182 | void validate();
|
---|
| 183 | //inherited
|
---|
| 184 | void destroy();
|
---|
[1055] | 185 | void runUpdated(RenderingRunType runType, RenderingRun* run);
|
---|
| 186 | void runChanged(RenderingRunType runType, RenderingRun* run);
|
---|
| 187 | virtual void addTechniqueGroup(TechniqueGroup* group){childTechniqueGroups.push_back(group);}
|
---|
[790] | 188 |
|
---|
| 189 | protected:
|
---|
| 190 | /**
|
---|
[1055] | 191 | @brief child TechniqueGroup instance.
|
---|
| 192 |
|
---|
| 193 | If this SharedRuns node is a leaf, it containes a reference to a TechniqueGroup instance.
|
---|
| 194 | All messages will be transfered to this object,
|
---|
| 195 | and bounding information will be retrieved from this TechniqueGroup
|
---|
| 196 | */
|
---|
| 197 | std::vector<TechniqueGroup*> childTechniqueGroups;
|
---|
| 198 | /**
|
---|
[790] | 199 | @brief map of contained RenderingRuns
|
---|
| 200 | */
|
---|
| 201 | std::map<RenderingRunType, RenderingRun*> sharedRuns;
|
---|
| 202 | /**
|
---|
| 203 | @brief map of connected renderablis with visibility information
|
---|
| 204 |
|
---|
| 205 | Used to show or hide the renderables connected to a leaf OgreSharedRuns node.
|
---|
| 206 | */
|
---|
| 207 | std::map<OgreRenderable*, bool> renderables;
|
---|
| 208 | /**
|
---|
| 209 | @brief the bounding sphere of all the objects connected to this node.
|
---|
| 210 | */
|
---|
| 211 | Sphere boundingSphere;
|
---|
| 212 | /**
|
---|
| 213 | @brief the axis aligned bounding box of all the objects connected to this node.
|
---|
| 214 | */
|
---|
| 215 | AxisAlignedBox boundingBox;
|
---|
| 216 |
|
---|
| 217 | //inherited
|
---|
| 218 | void gatherRuns();
|
---|
| 219 | //inherited
|
---|
| 220 | void fireRunChanges();
|
---|
| 221 | //inherited
|
---|
| 222 | SharedRuns* createInstance();
|
---|
| 223 | //inherited
|
---|
| 224 | void hideRenderables()
|
---|
| 225 | {
|
---|
| 226 | std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
|
---|
| 227 | std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
|
---|
| 228 | while(it != itend)
|
---|
| 229 | {
|
---|
| 230 | (*it).second = (*it).first->isVisible();
|
---|
| 231 | (*it).first->setVisible(false);
|
---|
| 232 | it++;
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 | //inherited
|
---|
| 236 | void restoreRenderableVisibility()
|
---|
| 237 | {
|
---|
| 238 | std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
|
---|
| 239 | std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
|
---|
| 240 | while(it != itend)
|
---|
| 241 | {
|
---|
| 242 | (*it).first->setVisible((*it).second);
|
---|
| 243 | it++;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | //inherited
|
---|
| 247 | void setRenderablesVisible(bool visible)
|
---|
| 248 | {
|
---|
| 249 | std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
|
---|
| 250 | std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
|
---|
| 251 | while(it != itend)
|
---|
| 252 | {
|
---|
| 253 | (*it).first->setVisible(visible);
|
---|
| 254 | it++;
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | };
|
---|
| 259 |
|
---|