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

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