| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- /*
- -----------------------------------------------------------------------------
- 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.
- -----------------------------------------------------------------------------
- */
- #pragma once
- #include "CmPrerequisites.h"
- #include "CmTexture.h"
- #include "CmModule.h"
- namespace CamelotFramework
- {
- /**
- * @brief Class for loading and managing textures.
- *
- * @note Must be initialized when RenderSystem is first started.
- */
- class CM_EXPORT TextureManager : public Module<TextureManager>
- {
- public:
- TextureManager();
- 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 createTexture(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 createTexture(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 createTexture(texType, width, height, 1,
- num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
- }
- /**
- * @brief Creates a completely empty and uninitialized Texture.
- * Should only be used for VERY specific purposes, like deserialization,
- * as it requires additional manual initialization that is not required normally.
- */
- TexturePtr createEmpty();
- /**
- * @brief Creates a new RenderTexture and automatically generates a color surface
- * and (optionally) a depth/stencil surface
- */
- virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
- PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "",
- bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
- /**
- * @brief Creates a RenderTexture using the description struct.
- */
- virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
- /**
- * @brief Creates a new multi render texture. You may use this type of texture
- * to render to multiple output textures at once.
- */
- virtual MultiRenderTexturePtr createEmptyMultiRenderTexture();
- /** 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);
- /**
- * @brief Gets the format which will be natively used for a requested format given the
- * constraints of the current device.
- *
- * @note Thread safe.
- */
- virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0;
- const HTexture& getDummyTexture() const { return mDummyTexture; }
- protected:
- HTexture mDummyTexture;
- virtual TexturePtr createTextureImpl() = 0;
- virtual RenderTexturePtr createRenderTextureImpl() = 0;
- virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
- virtual void onStartUp();
- };
- }
|