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