[5] | 1 | /*------------------------------------------------------------------------- |
---|
| 2 | This source file is a part of OGRE |
---|
| 3 | (Object-oriented Graphics Rendering Engine) |
---|
| 4 | |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This library is free software; you can redistribute it and/or modify it |
---|
| 11 | under the terms of the GNU Lesser General Public License (LGPL) as |
---|
| 12 | published by the Free Software Foundation; either version 2.1 of the |
---|
| 13 | License, or (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This library is distributed in the hope that it will be useful, but |
---|
| 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
---|
| 18 | License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU Lesser General Public License |
---|
| 21 | along with this library; if not, write to the Free Software Foundation, |
---|
| 22 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or go to |
---|
| 23 | http://www.gnu.org/copyleft/lesser.txt |
---|
| 24 | |
---|
| 25 | You may alternatively use this source under the terms of a specific version of |
---|
| 26 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 27 | Torus Knot Software Ltd. |
---|
| 28 | -------------------------------------------------------------------------*/ |
---|
| 29 | #ifndef __ShadowTextureManager_H__ |
---|
| 30 | #define __ShadowTextureManager_H__ |
---|
| 31 | |
---|
| 32 | // Precompiler options |
---|
| 33 | #include "OgrePrerequisites.h" |
---|
| 34 | #include "OgreSingleton.h" |
---|
| 35 | #include "OgrePixelFormat.h" |
---|
| 36 | #include "OgreTexture.h" |
---|
| 37 | #include "OgreIteratorWrappers.h" |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | namespace Ogre |
---|
| 41 | { |
---|
| 42 | typedef std::vector<TexturePtr> ShadowTextureList; |
---|
| 43 | |
---|
| 44 | /** Structure containing the configuration for one shadow texture. */ |
---|
| 45 | struct ShadowTextureConfig |
---|
| 46 | { |
---|
| 47 | unsigned int width; |
---|
| 48 | unsigned int height; |
---|
| 49 | PixelFormat format; |
---|
| 50 | |
---|
| 51 | ShadowTextureConfig() |
---|
| 52 | : width(512), height(512), format(PF_X8R8G8B8) {} |
---|
| 53 | }; |
---|
| 54 | |
---|
| 55 | typedef std::vector<ShadowTextureConfig> ShadowTextureConfigList; |
---|
| 56 | typedef ConstVectorIterator<ShadowTextureConfigList> ConstShadowTextureConfigIterator; |
---|
| 57 | |
---|
| 58 | inline _OgreExport bool operator== ( const ShadowTextureConfig& lhs, const ShadowTextureConfig& rhs ); |
---|
| 59 | inline _OgreExport bool operator!= ( const ShadowTextureConfig& lhs, const ShadowTextureConfig& rhs ); |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | /** Class to manage the available shadow textures which may be shared between |
---|
| 63 | many SceneManager instances if formats agree. |
---|
| 64 | @remarks |
---|
| 65 | The management of the list of shadow textures has been separated out into |
---|
| 66 | a dedicated class to enable the clean management of shadow textures |
---|
| 67 | across many scene manager instances. Where multiple scene managers are |
---|
| 68 | used with shadow textures, the configuration of those shadows may or may |
---|
| 69 | not be consistent - if it is, it is good to centrally manage the textures |
---|
| 70 | so that creation and destruction responsibility is clear. |
---|
| 71 | */ |
---|
| 72 | class _OgreExport ShadowTextureManager : public Singleton<ShadowTextureManager> |
---|
| 73 | { |
---|
| 74 | protected: |
---|
| 75 | ShadowTextureList mTextureList; |
---|
| 76 | ShadowTextureList mNullTextureList; |
---|
| 77 | size_t mCount; |
---|
| 78 | |
---|
| 79 | public: |
---|
| 80 | ShadowTextureManager(); |
---|
| 81 | virtual ~ShadowTextureManager(); |
---|
| 82 | |
---|
| 83 | /** Populate an incoming list with shadow texture references as requested |
---|
| 84 | in the configuration list. |
---|
| 85 | */ |
---|
| 86 | virtual void getShadowTextures(const ShadowTextureConfigList& config, |
---|
| 87 | ShadowTextureList& listToPopulate); |
---|
| 88 | |
---|
| 89 | /** Get an appropriately defined 'null' texture, ie one which will always |
---|
| 90 | result in no shadows. |
---|
| 91 | */ |
---|
| 92 | virtual TexturePtr getNullShadowTexture(PixelFormat format); |
---|
| 93 | |
---|
| 94 | /** Remove any shadow textures that are no longer being referenced. |
---|
| 95 | @remarks |
---|
| 96 | This should be called fairly regularly since references may take a |
---|
| 97 | little while to disappear in some cases (if referenced by materials) |
---|
| 98 | */ |
---|
| 99 | virtual void clearUnused(); |
---|
| 100 | /** Dereference all the shadow textures kept in this class and remove them |
---|
| 101 | from TextureManager; note that it is up to the SceneManagers to clear |
---|
| 102 | their local references. |
---|
| 103 | */ |
---|
| 104 | virtual void clear(); |
---|
| 105 | |
---|
| 106 | /** Override standard Singleton retrieval. |
---|
| 107 | @remarks |
---|
| 108 | Why do we do this? Well, it's because the Singleton |
---|
| 109 | implementation is in a .h file, which means it gets compiled |
---|
| 110 | into anybody who includes it. This is needed for the |
---|
| 111 | Singleton template to work, but we actually only want it |
---|
| 112 | compiled into the implementation of the class based on the |
---|
| 113 | Singleton, not all of them. If we don't change this, we get |
---|
| 114 | link errors when trying to use the Singleton-based class from |
---|
| 115 | an outside dll. |
---|
| 116 | @par |
---|
| 117 | This method just delegates to the template version anyway, |
---|
| 118 | but the implementation stays in this single compilation unit, |
---|
| 119 | preventing link errors. |
---|
| 120 | */ |
---|
| 121 | static ShadowTextureManager& getSingleton(void); |
---|
| 122 | /** Override standard Singleton retrieval. |
---|
| 123 | @remarks |
---|
| 124 | Why do we do this? Well, it's because the Singleton |
---|
| 125 | implementation is in a .h file, which means it gets compiled |
---|
| 126 | into anybody who includes it. This is needed for the |
---|
| 127 | Singleton template to work, but we actually only want it |
---|
| 128 | compiled into the implementation of the class based on the |
---|
| 129 | Singleton, not all of them. If we don't change this, we get |
---|
| 130 | link errors when trying to use the Singleton-based class from |
---|
| 131 | an outside dll. |
---|
| 132 | @par |
---|
| 133 | This method just delegates to the template version anyway, |
---|
| 134 | but the implementation stays in this single compilation unit, |
---|
| 135 | preventing link errors. |
---|
| 136 | */ |
---|
| 137 | static ShadowTextureManager* getSingletonPtr(void); |
---|
| 138 | |
---|
| 139 | }; |
---|
| 140 | |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | #endif |
---|
| 145 | |
---|