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

Revision 2240, 8.4 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        virtual void addTechniqueGroup(TechniqueGroup* group){childTechniqueGroups.push_back(group);}
192        /**
193         @brief Sets the given material for all connected renderables.
194
195         The previous materials will be stored so later can be restored. @see restoreMaterial
196
197         @param name of the material to be set.
198        */
199        void setMaterial(String materialName);
200        /**
201                @brief Restores the prevoius materials for the connected renderables. @see setMaterial
202        */
203        void restoreMaterial();
204
205protected:
206        /**
207                @brief child TechniqueGroup instance.
208
209                If this SharedRuns node is a leaf, it containes a reference to a TechniqueGroup instance.
210                All messages will be transfered to this object,
211                and bounding information will be retrieved from this TechniqueGroup
212        */
213        std::vector<TechniqueGroup*> childTechniqueGroups;
214        /**
215                @brief map of contained RenderingRuns
216        */
217        std::map<RenderingRunType, RenderingRun*> sharedRuns;
218        /**
219                @brief map of connected renderables with visibility information
220
221                Used to show or hide the renderables connected to a leaf OgreSharedRuns node.
222        */
223        std::map<OgreRenderable*, bool> renderables;
224        /**
225                @brief map of connected renderables with material name information
226
227                Used to resture the original materials of the renderables connected to a leaf OgreSharedRuns node.
228        */
229        std::map<OgreRenderable*, String> renderableMaterials;
230        /**
231                @brief the bounding sphere of all the objects connected to this node.
232        */
233        Sphere boundingSphere;
234        /**
235                @brief the axis aligned bounding box of all the objects connected to this node.
236        */
237        AxisAlignedBox boundingBox;
238
239        //inherited
240        void gatherRuns();
241        //inherited
242        void fireRunChanges();
243        //inherited
244        SharedRuns* createInstance();
245        //inherited
246        void hideRenderables()
247        {
248                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
249                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
250                while(it != itend)
251                {               
252                        (*it).second = (*it).first->isVisible();
253                        (*it).first->setVisible(false);
254                        it++;
255                }               
256        }
257        //inherited
258        void restoreRenderableVisibility()
259        {
260                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
261                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
262                while(it != itend)
263                {               
264                        (*it).first->setVisible((*it).second);
265                        it++;
266                }
267        }
268        //inherited
269        void setRenderablesVisible(bool visible)
270        {
271                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
272                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
273                while(it != itend)
274                {               
275                        (*it).first->setVisible(visible);
276                        it++;
277                }
278        }
279       
280};
281
Note: See TracBrowser for help on using the repository browser.