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

Revision 1130, 10.0 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        unsigned int focusingMapSize;
70        unsigned int shadowMapSize;
71        std::map<RenderingRunType,float> maxRads;
72        /**
73                @brief The camera attached to the player.
74        */
75        Camera* mainCamera;
76        /**
77                @brief The viewport of the player camera.
78        */
79        Viewport* mainViewport;
80        /**
81                @brief VisibleFinderVisitor instance.
82               
83                Used for adding visible renderables with valid TechniqueGroups to the visibleObjects vector.
84        */
85        class VisibleFinderVisitor* visitor;
86        /**
87                @brief The one and only OgreIlluminationManager instance.
88        */
89        static OgreIlluminationManager* instance;
90        /**
91                @brief Vector containing visible renderables with valid TechniqueGroups that must be refreshed.
92        */
93        std::vector<const Renderable*> visibleObjects;
94        /**
95                @brief List containing SharedRuns roots.
96
97                It is the IlluminationManager's task to find the SharedRuns which can be joined.
98                Only the root SharedRuns needs to be checked.
99        */
100        std::list<SharedRuns*> sharedRunRoots;
101        /**
102                @brief Group of RenderingRuns that are used globaly.
103
104                Some RenderingRuns have only one instance per application (for example scene depth map).
105                These resources are shared between all RenderTechniques.
106        */
107        OgreSharedRuns globalSharedRuns;
108        /**
109                @brief Stores groups of RenderingRuns that are attached to individual light sources.
110
111                These resources need separate instances for each lightsource ( for example depth shadow maps).
112                They are grouped by the name of the lightsource.
113        */
114        std::map<String, OgreSharedRuns*> perLightRuns;
115
116        std::map<GlobalTargetType, GlobalUseRenderTarget*> globalTargets;
117
118        std::vector<UpdateListener*> updateListeners;
119
120public:
121
122        void addUpdateListener(UpdateListener* l){updateListeners.push_back(l);}
123        /**
124                @brief registers a RenderTechniqueFactory
125        */
126        void addRenderTechniqueFactory(RenderTechniqueFactory* factory)
127        {
128                techniqueFactories.push_back(factory);
129        }
130        /**
131                @brief retirieves the maximum bounding sphere radius with two SharedRuns can be joined.
132        */
133        float getMaxJoinRadius(){return maxRad;}
134        float getMaxJoinRadius(RenderingRunType type){return maxRads[type];}
135        /**
136                @brief sets the maximum bounding sphere radius with two SharedRuns can be joined.
137        */
138        void setMaxJoinRadius(float rad)
139        {
140                std::map<RenderingRunType,float> ::iterator it = maxRads.begin();
141                std::map<RenderingRunType,float> ::iterator itend = maxRads.end();
142               
143                maxRad = rad;
144       
145                while(it != itend)
146                {
147                        (*it).second = maxRad;
148                        it++;
149                }
150               
151        }
152        void setMaxJoinRadius(RenderingRunType type, float rad){maxRads[type] = rad;}
153        void setFocusingMapSize(unsigned int size){focusingMapSize = size;}
154        void setShadowMapSize(unsigned int size){shadowMapSize = size;}
155        /**
156                @brief Returns the one and only OgreIlluminationManager instance.
157        */
158        static OgreIlluminationManager& getSingleton();
159        /**
160                @brief The function to be called to render one frame.
161
162                This is the main refreshing function. It seasrches for visible objects, manages shared runs, updates render techniques and
163                finally renders the scene to framebuffer.
164
165                @param frameNumber current framenumber
166                @param rt the rendertarget window. Needed to find the viewports that need to be refresh.
167        */
168        void update(unsigned long frameNumber, RenderTarget* rt);
169        /**
170                @brief searches for RenderTechniques in materials and creates them for all objects.
171        */
172        void initTechniques();
173        /**
174                @brief searches for RenderTechniques in materials and creates them for an Entity.
175        */
176        void initTechniques(Entity* e);
177        /**
178                @brief searches for RenderTechniques in materials and creates them for a Billboardset.
179        */
180        void initTechniques(BillboardSet* bbs, ParticleSystem* sys);
181        /**
182                @brief Returns a pointer to the player camera.
183
184                @return pointer to the main player camera. Needed by RenderTechnique and RenderingRun classes.
185        */
186        Camera* getMainCamera(){return mainCamera;}
187        /**
188                @brief Returns a pointer to the viewport attached to the player camera.
189
190                @return pointer to the viewport. Needed by RenderTechnique and RenderingRun classes.
191        */
192        Viewport* getMainViewport(){return mainViewport;}
193        /**
194                @brief Sets the player camera.
195
196                @param camera pointer to the main player camera
197        */
198        void setMainCamera(Camera* camera){mainCamera = camera;}
199        /**
200                @brief Sets the viewport attached to the player camera.
201
202                @param viewport pointer to the viewport
203        */
204        void setMainViewport(Viewport* viewport){mainViewport = viewport;}
205        /**
206                @brief The function to be called when a shared run is splitted.
207
208                @param old pointer to the SharedRuns instance that is split
209                @param new1 pointer to one of the SharedRuns instance that remain after split
210                @param new2 pointer to the other SharedRuns instance that remain after split
211        */
212        void sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2);
213        /**
214                @brief The function to be called when two shared runs are joined.
215
216                @param old1 pointer to one of the SharedRuns instance that are joined
217                @param old2 pointer to the other SharedRuns instance that are joined
218                @param newsr pointer to the resulting parent SharedRuns instance
219        */
220        void sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr);
221        /**
222                @brief Joins shared runs if needed.
223
224                Searches the registered shared run roots and join them if necessary (they are close enough).
225        */
226        void joinSharedRuns();
227        /**
228                @brief Register a shared run object.
229               
230                Only called when new techniques are created.
231
232                @param runs pointer to the SharedRuns instance to add
233        */
234        void addSharedRuns(SharedRuns* runs);
235        /**
236                @brief Searches for the nearest object groups (SharedRuns) that are caustic casters from a given point.
237
238                @param position the point to obtain distances from
239                @param nearestcasters vector to put the nearest caustic caster SharedRuns to
240                @param maxCount the maximum number of nearest casters to search for
241        */
242        void getNearestCausticCasters(Vector3 position, std::vector<OgreSharedRuns*>* nearestcasters, unsigned int maxCount);
243        /**
244                @brief Creates a global RenderingRun of the given type.
245
246                If  a RenderingRun with the given type already exist there is nothing to do.
247
248                @param runType type enum of the RenderingRun to create
249        */
250        void createGlobalRun(RenderingRunType runType);
251        /**
252                @brief Returns the global RendderingRun with the given type
253
254                @param runType type enum of the RenderingRun to retrieve
255
256                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
257        */
258        RenderingRun* getGlobalRun(RenderingRunType runType);
259
260        GlobalUseRenderTarget* getGlobalTarget(GlobalTargetType type);
261        void addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target);
262        /**
263                @brief Updates a global RenderingRun with the given type.
264
265                @param runType type enum of the RenderingRun to update
266                @param frameNum current framenumber
267        */
268        void updateGlobalRun(RenderingRunType runType, unsigned long frameNum);
269        /**
270                @brief Creates a RenderingRun attached to a lightsource with the given type.
271
272                @param lightName name of the lightsource
273                @param runType type enum of the RenderingRun to create
274        */
275        void createPerLightRun(String lightName, RenderingRunType runType);
276        /**
277                @brief Retuns 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 return
281
282                @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
283        */
284        RenderingRun* getPerLightRun(String lightName, RenderingRunType runType);
285        /**
286                @brief Updates a RenderingRun attached to a lightsource with the given type.
287
288                @param lightName name of the lightsource
289                @param runType type enum of the RenderingRun to update
290                @param frameNum current framenumber
291        */
292        void updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum);
293
294        bool frameStarted(const FrameEvent& evt)
295    {
296                update(Root::getSingleton().getCurrentFrameNumber(), mainViewport->getTarget());
297                return FrameListener::frameStarted(evt);
298        }
299};
300
Note: See TracBrowser for help on using the repository browser.