source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h @ 1062

Revision 1062, 9.8 KB checked in by szirmay, 18 years ago (diff)
Line 
1#pragma once
2
3#include "Ogre.h"
4#include "OgreTechniqueGroup.h"
5#include "OgreRenderable.h"
6#include "OgreCubeMapRenderTechnique.h"
7#include "OgreDistanceCubeMapRenderTechnique.h"
8#include "OgreConvolvedCubeMapRenderTechnique.h"
9#include "OgreCausticCasterRenderTechnique.h"
10#include "OgreCausticRecieverRenderTechnique.h"
11#include "OgreSceneCameraDepthRenderingRun.h"
12#include "OgreSBBRenderTechnique.h"
13#include "OgreDepthShadowMapRenderingRun.h"
14#include "OgreDepthShadowRecieverRenderTechnique.h"
15#include "OgreFireRenderTechnique.h"
16#include "OgreHierarchicalParticleSystemTechnique.h"
17
18
19
20using namespace Ogre;
21
22/**
23        @brief Implementation of IlluminationManager in an OGRE environment.
24*/
25class OgreIlluminationManager: public FrameListener
26{
27protected:
28        /**
29                @brief Protected constructor (OgreIlluminationManager is a singleton).
30        */
31        OgreIlluminationManager();
32        /**
33                @brief Protected destructor.
34        */
35        virtual ~OgreIlluminationManager();
36       
37        /**
38                @brief Searches for visible renderables with valid TechniqueGroups in a renderqueue.
39
40                @param rq pointer to the RenderQueue instance to search in
41        */
42        void fillVisibleList(  RenderQueue * rq);
43        /**
44                @brief creates a specific type of RenderTechnique for a Renderable's pass.
45
46                It searches all registered RenderTechniqueFactories.
47        */
48        void createTechnique(IllumTechniqueParams* params, Pass* pass, OgreRenderable* rend, OgreSharedRuns* sRuns);
49        /**
50                @brief A helper function to find the renderable object attached to a particle system (ONLY BILLBOARDSETS ARE SUPPORTED).
51
52                @param system pointer to the ParticleSystem instance to search in
53                @return pointer the connected BillboardSet instance
54        */
55        BillboardSet* findRenderableInParticleSystem(ParticleSystem* system);
56        void preAllUpdates();
57        void postAllUpdates();
58
59        /**
60                @brief registered RenderTechniqueFactories
61        */
62        std::list<RenderTechniqueFactory*> techniqueFactories;
63        /**
64                @brief The maximum bounding sphere radius that groupped objects ( see SharedRuns class ) can have
65                @see canJoin
66                @see joinRuns
67        */
68        float maxRad;
69        std::map<RenderingRunType,float> maxRads;
70        /**
71                @brief The camera attached to the player.
72        */
73        Camera* mainCamera;
74        /**
75                @brief The viewport of the player camera.
76        */
77        Viewport* mainViewport;
78        /**
79                @brief VisibleFinderVisitor instance.
80               
81                Used for adding visible renderables with valid TechniqueGroups to the visibleObjects vector.
82        */
83        class VisibleFinderVisitor* visitor;
84        /**
85                @brief The one and only OgreIlluminationManager instance.
86        */
87        static OgreIlluminationManager* instance;
88        /**
89                @brief Vector containing visible renderables with valid TechniqueGroups that must be refreshed.
90        */
91        std::vector<const Renderable*> visibleObjects;
92        /**
93                @brief List containing SharedRuns roots.
94
95                It is the IlluminationManager's task to find the SharedRuns which can be joined.
96                Only the root SharedRuns needs to be checked.
97        */
98        std::list<SharedRuns*> sharedRunRoots;
99        /**
100                @brief Group of RenderingRuns that are used globaly.
101
102                Some RenderingRuns have only one instance per application (for example scene depth map).
103                These resources are shared between all RenderTechniques.
104        */
105        OgreSharedRuns globalSharedRuns;
106        /**
107                @brief Stores groups of RenderingRuns that are attached to individual light sources.
108
109                These resources need separate instances for each lightsource ( for example depth shadow maps).
110                They are grouped by the name of the lightsource.
111        */
112        std::map<String, OgreSharedRuns*> perLightRuns;
113
114        std::map<GlobalTargetType, GlobalUseRenderTarget*> globalTargets;
115
116        std::vector<UpdateListener*> updateListeners;
117
118public:
119
120        void addUpdateListener(UpdateListener* l){updateListeners.push_back(l);}
121        /**
122                @brief registers a RenderTechniqueFactory
123        */
124        void addRenderTechniqueFactory(RenderTechniqueFactory* factory)
125        {
126                techniqueFactories.push_back(factory);
127        }
128        /**
129                @brief retirieves the maximum bounding sphere radius with two SharedRuns can be joined.
130        */
131        float getMaxJoinRadius(){return maxRad;}
132        float getMaxJoinRadius(RenderingRunType type){return maxRads[type];}
133        /**
134                @brief sets the maximum bounding sphere radius with two SharedRuns can be joined.
135        */
136        void setMaxJoinRadius(float rad)
137        {
138                std::map<RenderingRunType,float> ::iterator it = maxRads.begin();
139                std::map<RenderingRunType,float> ::iterator itend = maxRads.end();
140               
141                maxRad = rad;
142       
143                while(it != itend)
144                {
145                        (*it).second = maxRad;
146                        it++;
147                }
148               
149        }
150        void setMaxJoinRadius(RenderingRunType type, float rad){maxRads[type] = rad;}
151        /**
152                @brief Returns the one and only OgreIlluminationManager instance.
153        */
154        static OgreIlluminationManager& getSingleton();
155        /**
156                @brief The function to be called to render one frame.
157
158                This is the main refreshing function. It seasrches for visible objects, manages shared runs, updates render techniques and
159                finally renders the scene to framebuffer.
160
161                @param frameNumber current framenumber
162                @param rt the rendertarget window. Needed to find the viewports that need to be refresh.
163        */
164        void update(unsigned long frameNumber, RenderTarget* rt);
165        /**
166                @brief searches for RenderTechniques in materials and creates them for all objects.
167        */
168        void initTechniques();
169        /**
170                @brief searches for RenderTechniques in materials and creates them for an Entity.
171        */
172        void initTechniques(Entity* e);
173        /**
174                @brief searches for RenderTechniques in materials and creates them for a Billboardset.
175        */
176        void initTechniques(BillboardSet* bbs, ParticleSystem* sys);
177        /**
178                @brief Returns a pointer to the player camera.
179
180                @return pointer to the main player camera. Needed by RenderTechnique and RenderingRun classes.
181        */
182        Camera* getMainCamera(){return mainCamera;}
183        /**
184                @brief Returns a pointer to the viewport attached to the player camera.
185
186                @return pointer to the viewport. Needed by RenderTechnique and RenderingRun classes.
187        */
188        Viewport* getMainViewport(){return mainViewport;}
189        /**
190                @brief Sets the player camera.
191
192                @param camera pointer to the main player camera
193        */
194        void setMainCamera(Camera* camera){mainCamera = camera;}
195        /**
196                @brief Sets the viewport attached to the player camera.
197
198                @param viewport pointer to the viewport
199        */
200        void setMainViewport(Viewport* viewport){mainViewport = viewport;}
201        /**
202                @brief The function to be called when a shared run is splitted.
203
204                @param old pointer to the SharedRuns instance that is split
205                @param new1 pointer to one of the SharedRuns instance that remain after split
206                @param new2 pointer to the other SharedRuns instance that remain after split
207        */
208        void sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2);
209        /**
210                @brief The function to be called when two shared runs are joined.
211
212                @param old1 pointer to one of the SharedRuns instance that are joined
213                @param old2 pointer to the other SharedRuns instance that are joined
214                @param newsr pointer to the resulting parent SharedRuns instance
215        */
216        void sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr);
217        /**
218                @brief Joins shared runs if needed.
219
220                Searches the registered shared run roots and join them if necessary (they are close enough).
221        */
222        void joinSharedRuns();
223        /**
224                @brief Register a shared run object.
225               
226                Only called when new techniques are created.
227
228                @param runs pointer to the SharedRuns instance to add
229        */
230        void addSharedRuns(SharedRuns* runs);
231        /**
232                @brief Searches for the nearest object groups (SharedRuns) that are caustic casters from a given point.
233
234                @param position the point to obtain distances from
235                @param nearestcasters vector to put the nearest caustic caster SharedRuns to
236                @param maxCount the maximum number of nearest casters to search for
237        */
238        void getNearestCausticCasters(Vector3 position, std::vector<OgreSharedRuns*>* nearestcasters, unsigned int maxCount);
239        /**
240                @brief Creates a global RenderingRun of the given type.
241
242                If  a RenderingRun with the given type already exist there is nothing to do.
243
244                @param runType type enum of the RenderingRun to create
245        */
246        void createGlobalRun(RenderingRunType runType);
247        /**
248                @brief Returns the global RendderingRun with the given type
249
250                @param runType type enum of the RenderingRun to retrieve
251
252                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
253        */
254        RenderingRun* getGlobalRun(RenderingRunType runType);
255
256        GlobalUseRenderTarget* getGlobalTarget(GlobalTargetType type);
257        void addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target);
258        /**
259                @brief Updates a global RenderingRun with the given type.
260
261                @param runType type enum of the RenderingRun to update
262                @param frameNum current framenumber
263        */
264        void updateGlobalRun(RenderingRunType runType, unsigned long frameNum);
265        /**
266                @brief Creates a RenderingRun attached to a lightsource with the given type.
267
268                @param lightName name of the lightsource
269                @param runType type enum of the RenderingRun to create
270        */
271        void createPerLightRun(String lightName, RenderingRunType runType);
272        /**
273                @brief Retuns a RenderingRun attached to a lightsource with the given type.
274
275                @param lightName name of the lightsource
276                @param runType type enum of the RenderingRun to return
277
278                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
279        */
280        RenderingRun* getPerLightRun(String lightName, RenderingRunType runType);
281        /**
282                @brief Updates a RenderingRun attached to a lightsource with the given type.
283
284                @param lightName name of the lightsource
285                @param runType type enum of the RenderingRun to update
286                @param frameNum current framenumber
287        */
288        void updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum);
289
290        bool frameStarted(const FrameEvent& evt)
291    {
292                update(Root::getSingleton().getCurrentFrameNumber(), mainViewport->getTarget());
293                return FrameListener::frameStarted(evt);
294        }
295};
296
Note: See TracBrowser for help on using the repository browser.