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