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

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