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

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