source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h @ 2320

Revision 2320, 8.8 KB checked in by szirmay, 17 years ago (diff)
Line 
1#pragma once
2#include "SharedRuns.h"
3#include "OgreRenderable.h"
4#include "Ogre.h"
5
6using namespace Ogre;
7
8enum GlobalTargetType
9{
10        ILLUM_GLOBAL_TARGET_FIREPARTICLES
11};
12
13class GlobalUseRenderTarget
14{
15public:
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*/
25class OgreSharedRuns : public SharedRuns
26{
27public:
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
220protected:
221        /**
222                @brief child TechniqueGroup instance.
223
224                If this SharedRuns node is a leaf, it containes a reference to a TechniqueGroup instance.
225                All messages will be transfered to this object,
226                and bounding information will be retrieved from this TechniqueGroup
227        */
228        std::vector<TechniqueGroup*> childTechniqueGroups;
229        /**
230                @brief map of contained RenderingRuns
231        */
232        std::map<RenderingRunType, RenderingRun*> sharedRuns;
233        /**
234                @brief map of connected renderables with visibility information
235
236                Used to show or hide the renderables connected to a leaf OgreSharedRuns node.
237        */
238        std::map<OgreRenderable*, bool> renderables;
239        /**
240                @brief map of connected renderables with material name information
241
242                Used to resture the original materials of the renderables connected to a leaf OgreSharedRuns node.
243        */
244        std::map<OgreRenderable*, String> renderableMaterials;
245        /**
246                @brief the bounding sphere of all the objects connected to this node.
247        */
248        Sphere boundingSphere;
249        /**
250                @brief the axis aligned bounding box of all the objects connected to this node.
251        */
252        AxisAlignedBox boundingBox;
253
254        //inherited
255        void gatherRuns();
256        //inherited
257        void fireRunChanges();
258        //inherited
259        SharedRuns* createInstance();
260        //inherited
261        void hideRenderables()
262        {
263                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
264                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
265                while(it != itend)
266                {               
267                        (*it).second = (*it).first->isVisible();
268                        (*it).first->setVisible(false);
269                        it++;
270                }               
271        }
272        //inherited
273        void restoreRenderableVisibility()
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).first->setVisible((*it).second);
280                        it++;
281                }
282        }
283        //inherited
284        void setRenderablesVisible(bool visible)
285        {
286                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
287                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
288                while(it != itend)
289                {               
290                        (*it).first->setVisible(visible);
291                        it++;
292                }
293        }
294       
295};
296
Note: See TracBrowser for help on using the repository browser.