| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- /*
- -----------------------------------------------------------------------------
- This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
- For the latest info, see http://www.ogre3d.org/
- Copyright (c) 2000-2011 Torus Knot Software Ltd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -----------------------------------------------------------------------------
- */
- #ifndef _TextureManager_H__
- #define _TextureManager_H__
- #include "CmPrerequisites.h"
- #include "CmTexture.h"
- #include "CmModule.h"
- namespace CamelotEngine {
- /** \addtogroup Core
- * @{
- */
- /** \addtogroup Resources
- * @{
- */
- /** Class for loading & managing textures.
- @remarks
- Note that this class is abstract - the particular
- RenderSystem that is in use at the time will create
- a concrete subclass of this. Note that the concrete
- class will be available via the abstract singleton
- obtained from TextureManager::getSingleton(), but
- you should not assume that it is available until you
- have a) initialised Ogre (after selecting a RenderSystem
- and calling initialise from the Root object), and b)
- created at least one window - this may be done at the
- same time as part a if you allow Ogre to autocreate one.
- */
- class CM_EXPORT TextureManager : public Module<TextureManager>
- {
- protected:
- virtual Texture* createImpl() = 0;
- public:
- TextureManager(void);
- virtual ~TextureManager();
- /** Create a manual texture with specified width, height and depth (not loaded from a file).
- @param
- name The name to give the resulting texture
- @param
- group The name of the resource group to assign the texture to
- @param
- texType The type of texture to load/create, defaults to normal 2D textures
- @param
- width, height, depth The dimensions of the texture
- @param
- numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
- the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps())
- If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
- level, 1x1x1.
- @param
- format The internal format you wish to request; the manager reserves
- the right to create a different format if the one you select is
- not available in this context.
- @param
- usage The kind of usage this texture is intended for. It
- is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
- TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
- strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
- update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
- @param
- loader If you intend the contents of the manual texture to be
- regularly updated, to the extent that you don't need to recover
- the contents if the texture content is lost somehow, you can leave
- this parameter as 0. However, if you intend to populate the
- texture only once, then you should implement ManualResourceLoader
- and pass a pointer to it in this parameter; this means that if the
- manual texture ever needs to be reloaded, the ManualResourceLoader
- will be called to do it.
- @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
- (sRGB) on this texture. The hardware will convert from gamma space
- to linear space when reading from this texture. Only applicable for
- 8-bits per channel textures, will be ignored for other types. Has the advantage
- over pre-applied gamma that the texture precision is maintained.
- @param fsaa The level of multisampling to use if this is a render target. Ignored
- if usage does not include TU_RENDERTARGET or if the device does
- not support it.
- */
- TexturePtr create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
- int num_mips, PixelFormat format, int usage = TU_DEFAULT,
- bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
-
- /** Create a manual texture with a depth of 1 (not loaded from a file).
- @param
- name The name to give the resulting texture
- @param
- group The name of the resource group to assign the texture to
- @param
- texType The type of texture to load/create, defaults to normal 2D textures
- @param
- width, height The dimensions of the texture
- @param
- numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
- the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()).
- If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
- level, 1x1x1.
- @param
- format The internal format you wish to request; the manager reserves
- the right to create a different format if the one you select is
- not available in this context.
- @param
- usage The kind of usage this texture is intended for. It
- is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
- TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
- strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
- update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
- @param
- loader If you intend the contents of the manual texture to be
- regularly updated, to the extent that you don't need to recover
- the contents if the texture content is lost somehow, you can leave
- this parameter as 0. However, if you intend to populate the
- texture only once, then you should implement ManualResourceLoader
- and pass a pointer to it in this parameter; this means that if the
- manual texture ever needs to be reloaded, the ManualResourceLoader
- will be called to do it.
- @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
- (sRGB) on this texture. The hardware will convert from gamma space
- to linear space when reading from this texture. Only applicable for
- 8-bits per channel textures, will be ignored for other types. Has the advantage
- over pre-applied gamma that the texture precision is maintained.
- @param fsaa The level of multisampling to use if this is a render target. Ignored
- if usage does not include TU_RENDERTARGET or if the device does
- not support it.
- */
- TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
- PixelFormat format, int usage = TU_DEFAULT,
- bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK)
- {
- return create(texType, width, height, 1,
- num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
- }
- /** Sets preferred bit depth for integer pixel format textures.
- @param
- bits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
- original format as it is. This value is number of bits for the pixel.
- */
- virtual void setPreferredIntegerBitDepth(UINT16 bits);
- /** gets preferred bit depth for integer pixel format textures.
- */
- virtual UINT16 getPreferredIntegerBitDepth(void) const;
- /** Sets preferred bit depth for float pixel format textures.
- @param
- bits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
- original format as it is. This value is number of bits for a channel of the pixel.
- */
- virtual void setPreferredFloatBitDepth(UINT16 bits);
- /** gets preferred bit depth for float pixel format textures.
- */
- virtual UINT16 getPreferredFloatBitDepth(void) const;
- /** Sets preferred bit depth for integer and float pixel format.
- @param
- integerBits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
- original format as it is. This value is number of bits for the pixel.
- @param
- floatBits Number of bits. Available values: 0, 16 and 32, where 0 (the default) means keep
- original format as it is. This value is number of bits for a channel of the pixel.
- */
- virtual void setPreferredBitDepths(UINT16 integerBits, UINT16 floatBits);
- /** Returns whether this render system can natively support the precise texture
- format requested with the given usage options.
- @remarks
- You can still create textures with this format even if this method returns
- false; the texture format will just be altered to one which the device does
- support.
- @note
- Sometimes the device may just slightly change the format, such as reordering the
- channels or packing the channels differently, without it making and qualitative
- differences to the texture. If you want to just detect whether the quality of a
- given texture will be reduced, use isEquivalentFormatSupport instead.
- @param format The pixel format requested
- @param usage The kind of usage this texture is intended for, a combination of
- the TextureUsage flags.
- @returns true if the format is natively supported, false if a fallback would be used.
- */
- virtual bool isFormatSupported(TextureType ttype, PixelFormat format, int usage);
- /** Returns whether this render system can support the texture format requested
- with the given usage options, or another format with no quality reduction.
- */
- virtual bool isEquivalentFormatSupported(TextureType ttype, PixelFormat format, int usage);
- /** Gets the format which will be natively used for a requested format given the
- constraints of the current device.
- */
- virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0;
- /** Returns whether this render system has hardware filtering supported for the
- texture format requested with the given usage options.
- @remarks
- Not all texture format are supports filtering by the hardware, i.e. some
- cards support floating point format, but it doesn't supports filtering on
- the floating point texture at all, or only a subset floating point formats
- have flitering supported.
- @par
- In the case you want to write shader to work with floating point texture, and
- you want to produce better visual quality, it's necessary to flitering the
- texture manually in shader (potential requires four or more texture fetch
- instructions, plus several arithmetic instructions) if filtering doesn't
- supported by hardware. But in case on the hardware that supports floating
- point filtering natively, it had better to adopt this capability for
- performance (because only one texture fetch instruction are required) and
- doesn't loss visual quality.
- @par
- This method allow you queries hardware texture filtering capability to deciding
- which verion of the shader to be used. Note it's up to you to write multi-version
- shaders for support various hardware, internal engine can't do that for you
- automatically.
- @note
- Under GL, texture filtering are always supported by driver, but if it's not
- supported by hardware natively, software simulation will be used, and you
- will end up with very slow speed (less than 0.1 fps for example). To slove
- this performance problem, you must disable filtering manually (by use
- <b>filtering none</b> in the material script's texture_unit section, or
- call TextureUnitState::setTextureFiltering with TFO_NONE if populate
- material in code).
- @param ttype The texture type requested
- @param format The pixel format requested
- @param usage The kind of usage this texture is intended for, a combination of
- the TextureUsage flags.
- @param preciseFormatOnly Whether precise or fallback format mode is used to detecting.
- In case the pixel format doesn't supported by device, false will be returned
- if in precise mode, and natively used pixel format will be actually use to
- check if in fallback mode.
- @returns true if the texture filtering is supported.
- */
- virtual bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
- bool preciseFormatOnly = false) = 0;
- /** Sets the default number of mipmaps to be used for loaded textures, for when textures are
- loaded automatically (e.g. by Material class) or when 'load' is called with the default
- parameters by the application.
- If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
- level, 1x1x1.
- @note
- The default value is 0.
- */
- virtual void setDefaultNumMipmaps(size_t num);
- /** Gets the default number of mipmaps to be used for loaded textures.
- */
- virtual size_t getDefaultNumMipmaps()
- {
- return mDefaultNumMipmaps;
- }
- protected:
- UINT16 mPreferredIntegerBitDepth;
- UINT16 mPreferredFloatBitDepth;
- size_t mDefaultNumMipmaps;
- };
- /** @} */
- /** @} */
- }// Namespace
- #endif
|