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

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