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 |
|
---|
17 | using namespace Ogre;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | @brief Implementation of IlluminationManager in an OGRE environment.
|
---|
21 | */
|
---|
22 | class OgreIlluminationManager: public FrameListener
|
---|
23 | {
|
---|
24 | protected:
|
---|
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 |
|
---|
109 | public:
|
---|
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 for all objects.
|
---|
142 | */
|
---|
143 | void initTechniques();
|
---|
144 | /**
|
---|
145 | @brief searches for RenderTechniques in materials and creates them for an Entity.
|
---|
146 | */
|
---|
147 | void initTechniques(Entity* e);
|
---|
148 | /**
|
---|
149 | @brief Returns a pointer to the player camera.
|
---|
150 |
|
---|
151 | @return pointer to the main player camera. Needed by RenderTechnique and RenderingRun classes.
|
---|
152 | */
|
---|
153 | Camera* getMainCamera(){return mainCamera;}
|
---|
154 | /**
|
---|
155 | @brief Returns a pointer to the viewport attached to the player camera.
|
---|
156 |
|
---|
157 | @return pointer to the viewport. Needed by RenderTechnique and RenderingRun classes.
|
---|
158 | */
|
---|
159 | Viewport* getMainViewport(){return mainViewport;}
|
---|
160 | /**
|
---|
161 | @brief Sets the player camera.
|
---|
162 |
|
---|
163 | @param camera pointer to the main player camera
|
---|
164 | */
|
---|
165 | void setMainCamera(Camera* camera){mainCamera = camera;}
|
---|
166 | /**
|
---|
167 | @brief Sets the viewport attached to the player camera.
|
---|
168 |
|
---|
169 | @param viewport pointer to the viewport
|
---|
170 | */
|
---|
171 | void setMainViewport(Viewport* viewport){mainViewport = viewport;}
|
---|
172 | /**
|
---|
173 | @brief The function to be called when a shared run is splitted.
|
---|
174 |
|
---|
175 | @param old pointer to the SharedRuns instance that is split
|
---|
176 | @param new1 pointer to one of the SharedRuns instance that remain after split
|
---|
177 | @param new2 pointer to the other SharedRuns instance that remain after split
|
---|
178 | */
|
---|
179 | void sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2);
|
---|
180 | /**
|
---|
181 | @brief The function to be called when two shared runs are joined.
|
---|
182 |
|
---|
183 | @param old1 pointer to one of the SharedRuns instance that are joined
|
---|
184 | @param old2 pointer to the other SharedRuns instance that are joined
|
---|
185 | @param newsr pointer to the resulting parent SharedRuns instance
|
---|
186 | */
|
---|
187 | void sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr);
|
---|
188 | /**
|
---|
189 | @brief Joins shared runs if needed.
|
---|
190 |
|
---|
191 | Searches the registered shared run roots and join them if necessary (they are close enough).
|
---|
192 | */
|
---|
193 | void joinSharedRuns();
|
---|
194 | /**
|
---|
195 | @brief Register a shared run object.
|
---|
196 |
|
---|
197 | Only called when new techniques are created.
|
---|
198 |
|
---|
199 | @param runs pointer to the SharedRuns instance to add
|
---|
200 | */
|
---|
201 | void addSharedRuns(SharedRuns* runs);
|
---|
202 | /**
|
---|
203 | @brief Searches for the nearest object groups (SharedRuns) that are caustic casters from a given point.
|
---|
204 |
|
---|
205 | @param position the point to obtain distances from
|
---|
206 | @param nearestcasters vector to put the nearest caustic caster SharedRuns to
|
---|
207 | @param maxCount the maximum number of nearest casters to search for
|
---|
208 | */
|
---|
209 | void getNearestCausticCasters(Vector3 position, std::vector<OgreSharedRuns*>* nearestcasters, unsigned int maxCount);
|
---|
210 | /**
|
---|
211 | @brief Creates a global RenderingRun of the given type.
|
---|
212 |
|
---|
213 | If a RenderingRun with the given type already exist there is nothing to do.
|
---|
214 |
|
---|
215 | @param runType type enum of the RenderingRun to create
|
---|
216 | */
|
---|
217 | void createGlobalRun(RenderingRunType runType);
|
---|
218 | /**
|
---|
219 | @brief Returns the global RendderingRun with the given type
|
---|
220 |
|
---|
221 | @param runType type enum of the RenderingRun to retrieve
|
---|
222 |
|
---|
223 | @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
|
---|
224 | */
|
---|
225 | RenderingRun* getGlobalRun(RenderingRunType runType);
|
---|
226 | /**
|
---|
227 | @brief Updates a global RenderingRun with the given type.
|
---|
228 |
|
---|
229 | @param runType type enum of the RenderingRun to update
|
---|
230 | @param frameNum current framenumber
|
---|
231 | */
|
---|
232 | void updateGlobalRun(RenderingRunType runType, unsigned long frameNum);
|
---|
233 | /**
|
---|
234 | @brief Creates a RenderingRun attached to a lightsource with the given type.
|
---|
235 |
|
---|
236 | @param lightName name of the lightsource
|
---|
237 | @param runType type enum of the RenderingRun to create
|
---|
238 | */
|
---|
239 | void createPerLightRun(String lightName, RenderingRunType runType);
|
---|
240 | /**
|
---|
241 | @brief Retuns a RenderingRun attached to a lightsource with the given type.
|
---|
242 |
|
---|
243 | @param lightName name of the lightsource
|
---|
244 | @param runType type enum of the RenderingRun to return
|
---|
245 |
|
---|
246 | @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists
|
---|
247 | */
|
---|
248 | RenderingRun* getPerLightRun(String lightName, RenderingRunType runType);
|
---|
249 | /**
|
---|
250 | @brief Updates a RenderingRun attached to a lightsource with the given type.
|
---|
251 |
|
---|
252 | @param lightName name of the lightsource
|
---|
253 | @param runType type enum of the RenderingRun to update
|
---|
254 | @param frameNum current framenumber
|
---|
255 | */
|
---|
256 | void updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum);
|
---|
257 |
|
---|
258 | bool frameStarted(const FrameEvent& evt)
|
---|
259 | {
|
---|
260 | update(Root::getSingleton().getCurrentFrameNumber(), mainViewport->getTarget());
|
---|
261 | return FrameListener::frameStarted(evt);
|
---|
262 | }
|
---|
263 | };
|
---|
264 |
|
---|