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