1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
8 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | #ifndef _TextureManager_H__ |
---|
29 | #define _TextureManager_H__ |
---|
30 | |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | |
---|
34 | #include "OgreResourceManager.h" |
---|
35 | #include "OgreTexture.h" |
---|
36 | #include "OgreSingleton.h" |
---|
37 | |
---|
38 | |
---|
39 | namespace Ogre { |
---|
40 | |
---|
41 | /** \addtogroup Core |
---|
42 | * @{ |
---|
43 | */ |
---|
44 | /** \addtogroup Resources |
---|
45 | * @{ |
---|
46 | */ |
---|
47 | /** Class for loading & managing textures. |
---|
48 | @remarks |
---|
49 | Note that this class is abstract - the particular |
---|
50 | RenderSystem that is in use at the time will create |
---|
51 | a concrete subclass of this. Note that the concrete |
---|
52 | class will be available via the abstract singleton |
---|
53 | obtained from TextureManager::getSingleton(), but |
---|
54 | you should not assume that it is available until you |
---|
55 | have a) initialised Ogre (after selecting a RenderSystem |
---|
56 | and calling initialise from the Root object), and b) |
---|
57 | created at least one window - this may be done at the |
---|
58 | same time as part a if you allow Ogre to autocreate one. |
---|
59 | */ |
---|
60 | class _OgreExport TextureManager : public ResourceManager, public Singleton<TextureManager> |
---|
61 | { |
---|
62 | public: |
---|
63 | |
---|
64 | TextureManager(void); |
---|
65 | virtual ~TextureManager(); |
---|
66 | |
---|
67 | |
---|
68 | /// Create a new texture |
---|
69 | /// @see ResourceManager::createResource |
---|
70 | TexturePtr create (const String& name, const String& group, |
---|
71 | bool isManual = false, ManualResourceLoader* loader = 0, |
---|
72 | const NameValuePairList* createParams = 0); |
---|
73 | /// Get a resource by name |
---|
74 | /// @see ResourceManager::getResourceByName |
---|
75 | TexturePtr getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); |
---|
76 | |
---|
77 | /** Create a new texture, or retrieve an existing one with the same |
---|
78 | name if it already exists. |
---|
79 | @param |
---|
80 | texType The type of texture to load/create, defaults to normal 2D textures |
---|
81 | @param |
---|
82 | numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
83 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()) |
---|
84 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
85 | level, 1x1x1. |
---|
86 | @param |
---|
87 | gamma The gamma adjustment factor to apply to this texture (brightening/darkening) |
---|
88 | @param |
---|
89 | isAlpha Only applicable to greyscale images. If true, specifies that |
---|
90 | the image should be loaded into an alpha texture rather than a |
---|
91 | single channel colour texture - useful for fixed-function systems. |
---|
92 | @param |
---|
93 | desiredFormat The format you would like to have used instead of |
---|
94 | the format being based on the contents of the texture |
---|
95 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
96 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
97 | to linear space when reading from this texture. Only applicable for |
---|
98 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
99 | over pre-applied gamma that the texture precision is maintained. |
---|
100 | @see ResourceManager::createOrRetrieve |
---|
101 | */ |
---|
102 | virtual ResourceCreateOrRetrieveResult createOrRetrieve( |
---|
103 | const String &name, const String& group, bool isManual = false, |
---|
104 | ManualResourceLoader* loader = 0, const NameValuePairList* createParams = 0, |
---|
105 | TextureType texType = TEX_TYPE_2D, int numMipmaps = MIP_DEFAULT, |
---|
106 | Real gamma = 1.0f, bool isAlpha = false, |
---|
107 | PixelFormat desiredFormat = PF_UNKNOWN, bool hwGammaCorrection = false); |
---|
108 | |
---|
109 | /** Prepares to loads a texture from a file. |
---|
110 | @param |
---|
111 | name The file to load, or a String identifier in some cases |
---|
112 | @param |
---|
113 | group The name of the resource group to assign the texture to |
---|
114 | @param |
---|
115 | texType The type of texture to load/create, defaults to normal 2D textures |
---|
116 | @param |
---|
117 | numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
118 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()) |
---|
119 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
120 | level, 1x1x1. |
---|
121 | @param |
---|
122 | gamma The gamma adjustment factor to apply to this texture (brightening/darkening) |
---|
123 | @param |
---|
124 | isAlpha Only applicable to greyscale images. If true, specifies that |
---|
125 | the image should be loaded into an alpha texture rather than a |
---|
126 | single channel colour texture - useful for fixed-function systems. |
---|
127 | @param |
---|
128 | desiredFormat The format you would like to have used instead of |
---|
129 | the format being based on the contents of the texture |
---|
130 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
131 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
132 | to linear space when reading from this texture. Only applicable for |
---|
133 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
134 | over pre-applied gamma that the texture precision is maintained. |
---|
135 | */ |
---|
136 | virtual TexturePtr prepare( |
---|
137 | const String& name, const String& group, |
---|
138 | TextureType texType = TEX_TYPE_2D, int numMipmaps = MIP_DEFAULT, |
---|
139 | Real gamma = 1.0f, bool isAlpha = false, |
---|
140 | PixelFormat desiredFormat = PF_UNKNOWN, bool hwGammaCorrection = false); |
---|
141 | |
---|
142 | /** Loads a texture from a file. |
---|
143 | @param |
---|
144 | name The file to load, or a String identifier in some cases |
---|
145 | @param |
---|
146 | group The name of the resource group to assign the texture to |
---|
147 | @param |
---|
148 | texType The type of texture to load/create, defaults to normal 2D textures |
---|
149 | @param |
---|
150 | numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
151 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()) |
---|
152 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
153 | level, 1x1x1. |
---|
154 | @param |
---|
155 | gamma The gamma adjustment factor to apply to this texture (brightening/darkening) |
---|
156 | during loading |
---|
157 | @param |
---|
158 | isAlpha Only applicable to greyscale images. If true, specifies that |
---|
159 | the image should be loaded into an alpha texture rather than a |
---|
160 | single channel colour texture - useful for fixed-function systems. |
---|
161 | @param |
---|
162 | desiredFormat The format you would like to have used instead of |
---|
163 | the format being based on the contents of the texture. Pass PF_UNKNOWN |
---|
164 | to default. |
---|
165 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
166 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
167 | to linear space when reading from this texture. Only applicable for |
---|
168 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
169 | over pre-applied gamma that the texture precision is maintained. |
---|
170 | */ |
---|
171 | virtual TexturePtr load( |
---|
172 | const String& name, const String& group, |
---|
173 | TextureType texType = TEX_TYPE_2D, int numMipmaps = MIP_DEFAULT, |
---|
174 | Real gamma = 1.0f, bool isAlpha = false, |
---|
175 | PixelFormat desiredFormat = PF_UNKNOWN, |
---|
176 | bool hwGammaCorrection = false); |
---|
177 | |
---|
178 | /** Loads a texture from an Image object. |
---|
179 | @note |
---|
180 | The texture will create as manual texture without loader. |
---|
181 | @param |
---|
182 | name The name to give the resulting texture |
---|
183 | @param |
---|
184 | group The name of the resource group to assign the texture to |
---|
185 | @param |
---|
186 | img The Image object which contains the data to load |
---|
187 | @param |
---|
188 | texType The type of texture to load/create, defaults to normal 2D textures |
---|
189 | @param |
---|
190 | numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
191 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()) |
---|
192 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
193 | level, 1x1x1. |
---|
194 | @param |
---|
195 | gamma The gamma adjustment factor to apply to this texture (brightening/darkening) |
---|
196 | @param |
---|
197 | isAlpha Only applicable to greyscale images. If true, specifies that |
---|
198 | the image should be loaded into an alpha texture rather than a |
---|
199 | single channel colour texture - useful for fixed-function systems. |
---|
200 | @param |
---|
201 | desiredFormat The format you would like to have used instead of |
---|
202 | the format being based on the contents of the texture |
---|
203 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
204 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
205 | to linear space when reading from this texture. Only applicable for |
---|
206 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
207 | over pre-applied gamma that the texture precision is maintained. |
---|
208 | */ |
---|
209 | virtual TexturePtr loadImage( |
---|
210 | const String &name, const String& group, const Image &img, |
---|
211 | TextureType texType = TEX_TYPE_2D, |
---|
212 | int numMipmaps = MIP_DEFAULT, Real gamma = 1.0f, bool isAlpha = false, |
---|
213 | PixelFormat desiredFormat = PF_UNKNOWN, bool hwGammaCorrection = false); |
---|
214 | |
---|
215 | /** Loads a texture from a raw data stream. |
---|
216 | @note |
---|
217 | The texture will create as manual texture without loader. |
---|
218 | @param name |
---|
219 | The name to give the resulting texture |
---|
220 | @param group |
---|
221 | The name of the resource group to assign the texture to |
---|
222 | @param stream |
---|
223 | Incoming data stream |
---|
224 | @param width |
---|
225 | The width of the texture |
---|
226 | @param height |
---|
227 | The height of the texture |
---|
228 | @param format |
---|
229 | The format of the data being passed in; the manager reserves |
---|
230 | the right to create a different format for the texture if the |
---|
231 | original format is not available in this context. |
---|
232 | @param texType |
---|
233 | The type of texture to load/create, defaults to normal 2D textures |
---|
234 | @param numMipmaps |
---|
235 | The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
236 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()) |
---|
237 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
238 | level, 1x1x1. |
---|
239 | @param gamma |
---|
240 | The gamma adjustment factor to apply to this texture (brightening/darkening) |
---|
241 | while loading |
---|
242 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
243 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
244 | to linear space when reading from this texture. Only applicable for |
---|
245 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
246 | over pre-applied gamma that the texture precision is maintained. |
---|
247 | */ |
---|
248 | virtual TexturePtr loadRawData(const String &name, const String& group, |
---|
249 | DataStreamPtr& stream, ushort width, ushort height, |
---|
250 | PixelFormat format, TextureType texType = TEX_TYPE_2D, |
---|
251 | int numMipmaps = MIP_DEFAULT, Real gamma = 1.0f, bool hwGammaCorrection = false); |
---|
252 | |
---|
253 | /** Create a manual texture with specified width, height and depth (not loaded from a file). |
---|
254 | @param |
---|
255 | name The name to give the resulting texture |
---|
256 | @param |
---|
257 | group The name of the resource group to assign the texture to |
---|
258 | @param |
---|
259 | texType The type of texture to load/create, defaults to normal 2D textures |
---|
260 | @param width |
---|
261 | The width of the texture |
---|
262 | @param height |
---|
263 | The height of the texture |
---|
264 | @param depth |
---|
265 | The depth of the texture |
---|
266 | @param |
---|
267 | numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
268 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()) |
---|
269 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
270 | level, 1x1x1. |
---|
271 | @param |
---|
272 | format The internal format you wish to request; the manager reserves |
---|
273 | the right to create a different format if the one you select is |
---|
274 | not available in this context. |
---|
275 | @param |
---|
276 | usage The kind of usage this texture is intended for. It |
---|
277 | is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY, |
---|
278 | TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are |
---|
279 | strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to |
---|
280 | update regularly, consider HBU_DYNAMIC_WRITE_ONLY. |
---|
281 | @param |
---|
282 | loader If you intend the contents of the manual texture to be |
---|
283 | regularly updated, to the extent that you don't need to recover |
---|
284 | the contents if the texture content is lost somehow, you can leave |
---|
285 | this parameter as 0. However, if you intend to populate the |
---|
286 | texture only once, then you should implement ManualResourceLoader |
---|
287 | and pass a pointer to it in this parameter; this means that if the |
---|
288 | manual texture ever needs to be reloaded, the ManualResourceLoader |
---|
289 | will be called to do it. |
---|
290 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
291 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
292 | to linear space when reading from this texture. Only applicable for |
---|
293 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
294 | over pre-applied gamma that the texture precision is maintained. |
---|
295 | @param fsaa The level of multisampling to use if this is a render target. Ignored |
---|
296 | if usage does not include TU_RENDERTARGET or if the device does |
---|
297 | not support it. |
---|
298 | */ |
---|
299 | virtual TexturePtr createManual(const String & name, const String& group, |
---|
300 | TextureType texType, uint width, uint height, uint depth, |
---|
301 | int numMipmaps, PixelFormat format, int usage = TU_DEFAULT, ManualResourceLoader* loader = 0, |
---|
302 | bool hwGammaCorrection = false, uint fsaa = 0, const String& fsaaHint = StringUtil::BLANK); |
---|
303 | |
---|
304 | /** Create a manual texture with a depth of 1 (not loaded from a file). |
---|
305 | @param |
---|
306 | name The name to give the resulting texture |
---|
307 | @param |
---|
308 | group The name of the resource group to assign the texture to |
---|
309 | @param |
---|
310 | texType The type of texture to load/create, defaults to normal 2D textures |
---|
311 | @param width |
---|
312 | The width of the texture |
---|
313 | @param height |
---|
314 | The height of the texture |
---|
315 | @param |
---|
316 | numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then |
---|
317 | the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()). |
---|
318 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
319 | level, 1x1x1. |
---|
320 | @param |
---|
321 | format The internal format you wish to request; the manager reserves |
---|
322 | the right to create a different format if the one you select is |
---|
323 | not available in this context. |
---|
324 | @param |
---|
325 | usage The kind of usage this texture is intended for. It |
---|
326 | is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY, |
---|
327 | TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are |
---|
328 | strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to |
---|
329 | update regularly, consider HBU_DYNAMIC_WRITE_ONLY. |
---|
330 | @param |
---|
331 | loader If you intend the contents of the manual texture to be |
---|
332 | regularly updated, to the extent that you don't need to recover |
---|
333 | the contents if the texture content is lost somehow, you can leave |
---|
334 | this parameter as 0. However, if you intend to populate the |
---|
335 | texture only once, then you should implement ManualResourceLoader |
---|
336 | and pass a pointer to it in this parameter; this means that if the |
---|
337 | manual texture ever needs to be reloaded, the ManualResourceLoader |
---|
338 | will be called to do it. |
---|
339 | @param hwGammaCorrection Pass 'true' to enable hardware gamma correction |
---|
340 | (sRGB) on this texture. The hardware will convert from gamma space |
---|
341 | to linear space when reading from this texture. Only applicable for |
---|
342 | 8-bits per channel textures, will be ignored for other types. Has the advantage |
---|
343 | over pre-applied gamma that the texture precision is maintained. |
---|
344 | @param fsaa The level of multisampling to use if this is a render target. Ignored |
---|
345 | if usage does not include TU_RENDERTARGET or if the device does |
---|
346 | not support it. |
---|
347 | */ |
---|
348 | TexturePtr createManual(const String & name, const String& group, |
---|
349 | TextureType texType, uint width, uint height, int numMipmaps, |
---|
350 | PixelFormat format, int usage = TU_DEFAULT, ManualResourceLoader* loader = 0, |
---|
351 | bool hwGammaCorrection = false, uint fsaa = 0, const String& fsaaHint = StringUtil::BLANK) |
---|
352 | { |
---|
353 | return createManual(name, group, texType, width, height, 1, |
---|
354 | numMipmaps, format, usage, loader, hwGammaCorrection, fsaa, fsaaHint); |
---|
355 | } |
---|
356 | |
---|
357 | /** Sets preferred bit depth for integer pixel format textures. |
---|
358 | @param |
---|
359 | bits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep |
---|
360 | original format as it is. This value is number of bits for the pixel. |
---|
361 | @param |
---|
362 | reloadTextures If true (the default), will reloading all reloadable textures. |
---|
363 | */ |
---|
364 | virtual void setPreferredIntegerBitDepth(ushort bits, bool reloadTextures = true); |
---|
365 | |
---|
366 | /** Gets preferred bit depth for integer pixel format textures. |
---|
367 | */ |
---|
368 | virtual ushort getPreferredIntegerBitDepth(void) const; |
---|
369 | |
---|
370 | /** Sets preferred bit depth for float pixel format textures. |
---|
371 | @param |
---|
372 | bits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep |
---|
373 | original format as it is. This value is number of bits for a channel of the pixel. |
---|
374 | @param |
---|
375 | reloadTextures If true (the default), will reloading all reloadable textures. |
---|
376 | */ |
---|
377 | virtual void setPreferredFloatBitDepth(ushort bits, bool reloadTextures = true); |
---|
378 | |
---|
379 | /** Gets preferred bit depth for float pixel format textures. |
---|
380 | */ |
---|
381 | virtual ushort getPreferredFloatBitDepth(void) const; |
---|
382 | |
---|
383 | /** Sets preferred bit depth for integer and float pixel format. |
---|
384 | @param |
---|
385 | integerBits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep |
---|
386 | original format as it is. This value is number of bits for the pixel. |
---|
387 | @param |
---|
388 | floatBits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep |
---|
389 | original format as it is. This value is number of bits for a channel of the pixel. |
---|
390 | @param |
---|
391 | reloadTextures If true (the default), will reloading all reloadable textures. |
---|
392 | */ |
---|
393 | virtual void setPreferredBitDepths(ushort integerBits, ushort floatBits, bool reloadTextures = true); |
---|
394 | |
---|
395 | /** Returns whether this render system can natively support the precise texture |
---|
396 | format requested with the given usage options. |
---|
397 | @remarks |
---|
398 | You can still create textures with this format even if this method returns |
---|
399 | false; the texture format will just be altered to one which the device does |
---|
400 | support. |
---|
401 | @note |
---|
402 | Sometimes the device may just slightly change the format, such as reordering the |
---|
403 | channels or packing the channels differently, without it making and qualitative |
---|
404 | differences to the texture. If you want to just detect whether the quality of a |
---|
405 | given texture will be reduced, use isEquivalentFormatSupport instead. |
---|
406 | @param format The pixel format requested |
---|
407 | @param usage The kind of usage this texture is intended for, a combination of |
---|
408 | the TextureUsage flags. |
---|
409 | @return true if the format is natively supported, false if a fallback would be used. |
---|
410 | */ |
---|
411 | virtual bool isFormatSupported(TextureType ttype, PixelFormat format, int usage); |
---|
412 | |
---|
413 | /** Returns whether this render system can support the texture format requested |
---|
414 | with the given usage options, or another format with no quality reduction. |
---|
415 | */ |
---|
416 | virtual bool isEquivalentFormatSupported(TextureType ttype, PixelFormat format, int usage); |
---|
417 | |
---|
418 | /** Gets the format which will be natively used for a requested format given the |
---|
419 | constraints of the current device. |
---|
420 | */ |
---|
421 | virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0; |
---|
422 | |
---|
423 | /** Returns whether this render system has hardware filtering supported for the |
---|
424 | texture format requested with the given usage options. |
---|
425 | @remarks |
---|
426 | Not all texture format are supports filtering by the hardware, i.e. some |
---|
427 | cards support floating point format, but it doesn't supports filtering on |
---|
428 | the floating point texture at all, or only a subset floating point formats |
---|
429 | have flitering supported. |
---|
430 | @par |
---|
431 | In the case you want to write shader to work with floating point texture, and |
---|
432 | you want to produce better visual quality, it's necessary to flitering the |
---|
433 | texture manually in shader (potential requires four or more texture fetch |
---|
434 | instructions, plus several arithmetic instructions) if filtering doesn't |
---|
435 | supported by hardware. But in case on the hardware that supports floating |
---|
436 | point filtering natively, it had better to adopt this capability for |
---|
437 | performance (because only one texture fetch instruction are required) and |
---|
438 | doesn't loss visual quality. |
---|
439 | @par |
---|
440 | This method allow you queries hardware texture filtering capability to deciding |
---|
441 | which verion of the shader to be used. Note it's up to you to write multi-version |
---|
442 | shaders for support various hardware, internal engine can't do that for you |
---|
443 | automatically. |
---|
444 | @note |
---|
445 | Under GL, texture filtering are always supported by driver, but if it's not |
---|
446 | supported by hardware natively, software simulation will be used, and you |
---|
447 | will end up with very slow speed (less than 0.1 fps for example). To slove |
---|
448 | this performance problem, you must disable filtering manually (by use |
---|
449 | <b>filtering none</b> in the material script's texture_unit section, or |
---|
450 | call TextureUnitState::setTextureFiltering with TFO_NONE if populate |
---|
451 | material in code). |
---|
452 | @param ttype The texture type requested |
---|
453 | @param format The pixel format requested |
---|
454 | @param usage The kind of usage this texture is intended for, a combination of |
---|
455 | the TextureUsage flags. |
---|
456 | @param preciseFormatOnly Whether precise or fallback format mode is used to detecting. |
---|
457 | In case the pixel format doesn't supported by device, false will be returned |
---|
458 | if in precise mode, and natively used pixel format will be actually use to |
---|
459 | check if in fallback mode. |
---|
460 | @return true if the texture filtering is supported. |
---|
461 | */ |
---|
462 | virtual bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage, |
---|
463 | bool preciseFormatOnly = false) = 0; |
---|
464 | |
---|
465 | /** Sets the default number of mipmaps to be used for loaded textures, for when textures are |
---|
466 | loaded automatically (e.g. by Material class) or when 'load' is called with the default |
---|
467 | parameters by the application. |
---|
468 | If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible |
---|
469 | level, 1x1x1. |
---|
470 | @note |
---|
471 | The default value is 0. |
---|
472 | */ |
---|
473 | virtual void setDefaultNumMipmaps(size_t num); |
---|
474 | |
---|
475 | /** Gets the default number of mipmaps to be used for loaded textures. |
---|
476 | */ |
---|
477 | virtual size_t getDefaultNumMipmaps() |
---|
478 | { |
---|
479 | return mDefaultNumMipmaps; |
---|
480 | } |
---|
481 | |
---|
482 | /** Override standard Singleton retrieval. |
---|
483 | @remarks |
---|
484 | Why do we do this? Well, it's because the Singleton |
---|
485 | implementation is in a .h file, which means it gets compiled |
---|
486 | into anybody who includes it. This is needed for the |
---|
487 | Singleton template to work, but we actually only want it |
---|
488 | compiled into the implementation of the class based on the |
---|
489 | Singleton, not all of them. If we don't change this, we get |
---|
490 | link errors when trying to use the Singleton-based class from |
---|
491 | an outside dll. |
---|
492 | @par |
---|
493 | This method just delegates to the template version anyway, |
---|
494 | but the implementation stays in this single compilation unit, |
---|
495 | preventing link errors. |
---|
496 | */ |
---|
497 | static TextureManager& getSingleton(void); |
---|
498 | /** Override standard Singleton retrieval. |
---|
499 | @remarks |
---|
500 | Why do we do this? Well, it's because the Singleton |
---|
501 | implementation is in a .h file, which means it gets compiled |
---|
502 | into anybody who includes it. This is needed for the |
---|
503 | Singleton template to work, but we actually only want it |
---|
504 | compiled into the implementation of the class based on the |
---|
505 | Singleton, not all of them. If we don't change this, we get |
---|
506 | link errors when trying to use the Singleton-based class from |
---|
507 | an outside dll. |
---|
508 | @par |
---|
509 | This method just delegates to the template version anyway, |
---|
510 | but the implementation stays in this single compilation unit, |
---|
511 | preventing link errors. |
---|
512 | */ |
---|
513 | static TextureManager* getSingletonPtr(void); |
---|
514 | |
---|
515 | protected: |
---|
516 | |
---|
517 | ushort mPreferredIntegerBitDepth; |
---|
518 | ushort mPreferredFloatBitDepth; |
---|
519 | size_t mDefaultNumMipmaps; |
---|
520 | }; |
---|
521 | /** @} */ |
---|
522 | /** @} */ |
---|
523 | }// Namespace |
---|
524 | |
---|
525 | #endif |
---|