SO3Engine
SO3DeferredLightManager.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
26
27template<> SO3::SDeferredLightManager* Ogre::Singleton<SO3::SDeferredLightManager>::msSingleton = 0;
28
29namespace SO3
30{
31
33{
34 deferredLightAmbientMaterialGenerator = new SDeferredLightAmbientMaterialGenerator();
35 deferredLightDirectionalMaterialGenerator = new SDeferredLightDirectionalMaterialGenerator();
36 deferredLightPointMaterialGenerator = new SDeferredLightPointMaterialGenerator();
37 deferredLightSpotMaterialGenerator = new SDeferredLightSpotMaterialGenerator();
38}
39
41{
42 DeferredLightList::iterator iDeferredLight = deferredLightList.begin();
43 while(iDeferredLight != deferredLightList.end())
44 {
45 iDeferredLight->first->setListener(0);
46 delete(iDeferredLight->second);
47 }
48 deferredLightList.clear();
49
50 SO3_SAFE_DELETE(deferredLightDirectionalMaterialGenerator);
51 SO3_SAFE_DELETE(deferredLightPointMaterialGenerator);
52 SO3_SAFE_DELETE(deferredLightSpotMaterialGenerator);
53 SO3_SAFE_DELETE(deferredLightAmbientMaterialGenerator);
54}
55
60
62{
63 assert(msSingleton);
64 return (*msSingleton);
65}
66
68{
69 DeferredLightList::iterator iSearchedDeferredLight = deferredLightList.find(existingLight);
70 if(iSearchedDeferredLight != deferredLightList.end())
71 {
72 return iSearchedDeferredLight->second;
73 }
74 else
75 {
76 SDeferredLight* newDeferredLight = new SDeferredLight(existingLight);
77 deferredLightList[existingLight] = newDeferredLight;
78 existingLight->setListener(this);
79 return newDeferredLight;
80 }
81}
82
83void SDeferredLightManager::objectDestroyed(Ogre::MovableObject* light)
84{
85 DeferredLightList::iterator iSearchedDeferredLight = deferredLightList.find(static_cast<Ogre::Light*>(light));
86 if(iSearchedDeferredLight != deferredLightList.end())
87 {
88 light->setListener(0);
89 delete(iSearchedDeferredLight->second);
90 deferredLightList.erase(iSearchedDeferredLight);
91 }
92}
93
98
103
108
113
114}
static SDeferredLightManager * getSingletonPtr()
SDeferredLightAmbientMaterialGenerator * GetDeferredLightAmbientMaterialGenerator()
static SDeferredLightManager & getSingleton()
SDeferredLightDirectionalMaterialGenerator * GetDeferredLightDirectionalMaterialGenerator()
SDeferredLight * CreateOrRetrieve(Ogre::Light *existingLight)
SDeferredLightPointMaterialGenerator * GetDeferredLightPointMaterialGenerator()
virtual void objectDestroyed(Ogre::MovableObject *light)
SDeferredLightSpotMaterialGenerator * GetDeferredLightSpotMaterialGenerator()