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 | @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 | */
|
---|
127 | static bool haveCommonRuns(SharedRuns* r1, SharedRuns* r2, std::vector<RenderingRunType>& commonruns);
|
---|
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 | */
|
---|
143 | void addRenderablesToQueue(RenderQueue* rq, bool checkVisible = true);
|
---|
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();
|
---|
185 | void runUpdated(RenderingRunType runType, RenderingRun* run);
|
---|
186 | void runChanged(RenderingRunType runType, RenderingRun* run);
|
---|
187 | virtual void addTechniqueGroup(TechniqueGroup* group){childTechniqueGroups.push_back(group);}
|
---|
188 | void setMaterial(String materialName);
|
---|
189 | void restoreMaterial();
|
---|
190 |
|
---|
191 | protected:
|
---|
192 | /**
|
---|
193 | @brief child TechniqueGroup instance.
|
---|
194 |
|
---|
195 | If this SharedRuns node is a leaf, it containes a reference to a TechniqueGroup instance.
|
---|
196 | All messages will be transfered to this object,
|
---|
197 | and bounding information will be retrieved from this TechniqueGroup
|
---|
198 | */
|
---|
199 | std::vector<TechniqueGroup*> childTechniqueGroups;
|
---|
200 | /**
|
---|
201 | @brief map of contained RenderingRuns
|
---|
202 | */
|
---|
203 | std::map<RenderingRunType, RenderingRun*> sharedRuns;
|
---|
204 | /**
|
---|
205 | @brief map of connected renderablis with visibility information
|
---|
206 |
|
---|
207 | Used to show or hide the renderables connected to a leaf OgreSharedRuns node.
|
---|
208 | */
|
---|
209 | std::map<OgreRenderable*, bool> renderables;
|
---|
210 | std::map<OgreRenderable*, String> renderableMaterials;
|
---|
211 | /**
|
---|
212 | @brief the bounding sphere of all the objects connected to this node.
|
---|
213 | */
|
---|
214 | Sphere boundingSphere;
|
---|
215 | /**
|
---|
216 | @brief the axis aligned bounding box of all the objects connected to this node.
|
---|
217 | */
|
---|
218 | AxisAlignedBox boundingBox;
|
---|
219 |
|
---|
220 | //inherited
|
---|
221 | void gatherRuns();
|
---|
222 | //inherited
|
---|
223 | void fireRunChanges();
|
---|
224 | //inherited
|
---|
225 | SharedRuns* createInstance();
|
---|
226 | //inherited
|
---|
227 | void hideRenderables()
|
---|
228 | {
|
---|
229 | std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
|
---|
230 | std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
|
---|
231 | while(it != itend)
|
---|
232 | {
|
---|
233 | (*it).second = (*it).first->isVisible();
|
---|
234 | (*it).first->setVisible(false);
|
---|
235 | it++;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | //inherited
|
---|
239 | void restoreRenderableVisibility()
|
---|
240 | {
|
---|
241 | std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
|
---|
242 | std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
|
---|
243 | while(it != itend)
|
---|
244 | {
|
---|
245 | (*it).first->setVisible((*it).second);
|
---|
246 | it++;
|
---|
247 | }
|
---|
248 | }
|
---|
249 | //inherited
|
---|
250 | void setRenderablesVisible(bool visible)
|
---|
251 | {
|
---|
252 | std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
|
---|
253 | std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
|
---|
254 | while(it != itend)
|
---|
255 | {
|
---|
256 | (*it).first->setVisible(visible);
|
---|
257 | it++;
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | };
|
---|
262 |
|
---|