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-2013 Torus Knot Software Ltd |
---|
8 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
9 | of this software and associated documentation files (the "Software"), to deal |
---|
10 | in the Software without restriction, including without limitation the rights |
---|
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
12 | copies of the Software, and to permit persons to whom the Software is |
---|
13 | furnished to do so, subject to the following conditions: |
---|
14 | |
---|
15 | The above copyright notice and this permission notice shall be included in |
---|
16 | all copies or substantial portions of the Software. |
---|
17 | |
---|
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
24 | THE SOFTWARE |
---|
25 | |
---|
26 | You may alternatively use this source under the terms of a specific version of |
---|
27 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
28 | Torus Knot Software Ltd. |
---|
29 | -------------------------------------------------------------------------*/ |
---|
30 | #ifndef __ShadowTextureManager_H__ |
---|
31 | #define __ShadowTextureManager_H__ |
---|
32 | |
---|
33 | // Precompiler options |
---|
34 | #include "OgrePrerequisites.h" |
---|
35 | #include "OgreSingleton.h" |
---|
36 | #include "OgrePixelFormat.h" |
---|
37 | #include "OgreTexture.h" |
---|
38 | #include "OgreIteratorWrappers.h" |
---|
39 | #include "OgreHeaderPrefix.h" |
---|
40 | |
---|
41 | namespace Ogre |
---|
42 | { |
---|
43 | /** \addtogroup Core |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | /** \addtogroup Scene |
---|
47 | * @{ |
---|
48 | */ |
---|
49 | typedef vector<TexturePtr>::type ShadowTextureList; |
---|
50 | |
---|
51 | /** Structure containing the configuration for one shadow texture. */ |
---|
52 | struct ShadowTextureConfig |
---|
53 | { |
---|
54 | unsigned int width; |
---|
55 | unsigned int height; |
---|
56 | PixelFormat format; |
---|
57 | unsigned int fsaa; |
---|
58 | uint16 depthBufferPoolId; |
---|
59 | |
---|
60 | ShadowTextureConfig() |
---|
61 | : width(512), height(512), format(PF_X8R8G8B8), fsaa(0), depthBufferPoolId(1) {} |
---|
62 | }; |
---|
63 | |
---|
64 | typedef vector<ShadowTextureConfig>::type ShadowTextureConfigList; |
---|
65 | typedef ConstVectorIterator<ShadowTextureConfigList> ConstShadowTextureConfigIterator; |
---|
66 | |
---|
67 | inline _OgreExport bool operator== ( const ShadowTextureConfig& lhs, const ShadowTextureConfig& rhs ); |
---|
68 | inline _OgreExport bool operator!= ( const ShadowTextureConfig& lhs, const ShadowTextureConfig& rhs ); |
---|
69 | |
---|
70 | |
---|
71 | /** Class to manage the available shadow textures which may be shared between |
---|
72 | many SceneManager instances if formats agree. |
---|
73 | @remarks |
---|
74 | The management of the list of shadow textures has been separated out into |
---|
75 | a dedicated class to enable the clean management of shadow textures |
---|
76 | across many scene manager instances. Where multiple scene managers are |
---|
77 | used with shadow textures, the configuration of those shadows may or may |
---|
78 | not be consistent - if it is, it is good to centrally manage the textures |
---|
79 | so that creation and destruction responsibility is clear. |
---|
80 | */ |
---|
81 | class _OgreExport ShadowTextureManager : public Singleton<ShadowTextureManager>, public ShadowDataAlloc |
---|
82 | { |
---|
83 | protected: |
---|
84 | ShadowTextureList mTextureList; |
---|
85 | ShadowTextureList mNullTextureList; |
---|
86 | size_t mCount; |
---|
87 | |
---|
88 | public: |
---|
89 | ShadowTextureManager(); |
---|
90 | virtual ~ShadowTextureManager(); |
---|
91 | |
---|
92 | /** Populate an incoming list with shadow texture references as requested |
---|
93 | in the configuration list. |
---|
94 | */ |
---|
95 | virtual void getShadowTextures(const ShadowTextureConfigList& config, |
---|
96 | ShadowTextureList& listToPopulate); |
---|
97 | |
---|
98 | /** Get an appropriately defined 'null' texture, i.e. one which will always |
---|
99 | result in no shadows. |
---|
100 | */ |
---|
101 | virtual TexturePtr getNullShadowTexture(PixelFormat format); |
---|
102 | |
---|
103 | /** Remove any shadow textures that are no longer being referenced. |
---|
104 | @remarks |
---|
105 | This should be called fairly regularly since references may take a |
---|
106 | little while to disappear in some cases (if referenced by materials) |
---|
107 | */ |
---|
108 | virtual void clearUnused(); |
---|
109 | /** Dereference all the shadow textures kept in this class and remove them |
---|
110 | from TextureManager; note that it is up to the SceneManagers to clear |
---|
111 | their local references. |
---|
112 | */ |
---|
113 | virtual void clear(); |
---|
114 | |
---|
115 | /** Override standard Singleton retrieval. |
---|
116 | @remarks |
---|
117 | Why do we do this? Well, it's because the Singleton |
---|
118 | implementation is in a .h file, which means it gets compiled |
---|
119 | into anybody who includes it. This is needed for the |
---|
120 | Singleton template to work, but we actually only want it |
---|
121 | compiled into the implementation of the class based on the |
---|
122 | Singleton, not all of them. If we don't change this, we get |
---|
123 | link errors when trying to use the Singleton-based class from |
---|
124 | an outside dll. |
---|
125 | @par |
---|
126 | This method just delegates to the template version anyway, |
---|
127 | but the implementation stays in this single compilation unit, |
---|
128 | preventing link errors. |
---|
129 | */ |
---|
130 | static ShadowTextureManager& getSingleton(void); |
---|
131 | /** Override standard Singleton retrieval. |
---|
132 | @remarks |
---|
133 | Why do we do this? Well, it's because the Singleton |
---|
134 | implementation is in a .h file, which means it gets compiled |
---|
135 | into anybody who includes it. This is needed for the |
---|
136 | Singleton template to work, but we actually only want it |
---|
137 | compiled into the implementation of the class based on the |
---|
138 | Singleton, not all of them. If we don't change this, we get |
---|
139 | link errors when trying to use the Singleton-based class from |
---|
140 | an outside dll. |
---|
141 | @par |
---|
142 | This method just delegates to the template version anyway, |
---|
143 | but the implementation stays in this single compilation unit, |
---|
144 | preventing link errors. |
---|
145 | */ |
---|
146 | static ShadowTextureManager* getSingletonPtr(void); |
---|
147 | |
---|
148 | }; |
---|
149 | |
---|
150 | /** @} */ |
---|
151 | /** @} */ |
---|
152 | } |
---|
153 | |
---|
154 | #include "OgreHeaderSuffix.h" |
---|
155 | |
---|
156 | #endif |
---|
157 | |
---|