CmTextureManager.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef _TextureManager_H__
  25. #define _TextureManager_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmTexture.h"
  28. #include "CmModule.h"
  29. namespace CamelotFramework {
  30. /** \addtogroup Core
  31. * @{
  32. */
  33. /** \addtogroup Resources
  34. * @{
  35. */
  36. /** Class for loading & managing textures.
  37. @remarks
  38. Note that this class is abstract - the particular
  39. RenderSystem that is in use at the time will create
  40. a concrete subclass of this. Note that the concrete
  41. class will be available via the abstract singleton
  42. obtained from TextureManager::getSingleton(), but
  43. you should not assume that it is available until you
  44. have a) initialised Ogre (after selecting a RenderSystem
  45. and calling initialise from the Root object), and b)
  46. created at least one window - this may be done at the
  47. same time as part a if you allow Ogre to autocreate one.
  48. */
  49. class CM_EXPORT TextureManager : public Module<TextureManager>
  50. {
  51. public:
  52. TextureManager();
  53. virtual ~TextureManager();
  54. /** Create a manual texture with specified width, height and depth (not loaded from a file).
  55. @param
  56. name The name to give the resulting texture
  57. @param
  58. group The name of the resource group to assign the texture to
  59. @param
  60. texType The type of texture to load/create, defaults to normal 2D textures
  61. @param
  62. width, height, depth The dimensions of the texture
  63. @param
  64. numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
  65. the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps())
  66. If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
  67. level, 1x1x1.
  68. @param
  69. format The internal format you wish to request; the manager reserves
  70. the right to create a different format if the one you select is
  71. not available in this context.
  72. @param
  73. usage The kind of usage this texture is intended for. It
  74. is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
  75. TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
  76. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  77. update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
  78. @param
  79. loader If you intend the contents of the manual texture to be
  80. regularly updated, to the extent that you don't need to recover
  81. the contents if the texture content is lost somehow, you can leave
  82. this parameter as 0. However, if you intend to populate the
  83. texture only once, then you should implement ManualResourceLoader
  84. and pass a pointer to it in this parameter; this means that if the
  85. manual texture ever needs to be reloaded, the ManualResourceLoader
  86. will be called to do it.
  87. @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
  88. (sRGB) on this texture. The hardware will convert from gamma space
  89. to linear space when reading from this texture. Only applicable for
  90. 8-bits per channel textures, will be ignored for other types. Has the advantage
  91. over pre-applied gamma that the texture precision is maintained.
  92. @param fsaa The level of multisampling to use if this is a render target. Ignored
  93. if usage does not include TU_RENDERTARGET or if the device does
  94. not support it.
  95. */
  96. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  97. int num_mips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  98. UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
  99. /** Create a manual texture with a depth of 1 (not loaded from a file).
  100. @param
  101. name The name to give the resulting texture
  102. @param
  103. group The name of the resource group to assign the texture to
  104. @param
  105. texType The type of texture to load/create, defaults to normal 2D textures
  106. @param
  107. width, height The dimensions of the texture
  108. @param
  109. numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
  110. the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()).
  111. If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
  112. level, 1x1x1.
  113. @param
  114. format The internal format you wish to request; the manager reserves
  115. the right to create a different format if the one you select is
  116. not available in this context.
  117. @param
  118. usage The kind of usage this texture is intended for. It
  119. is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
  120. TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
  121. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  122. update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
  123. @param
  124. loader If you intend the contents of the manual texture to be
  125. regularly updated, to the extent that you don't need to recover
  126. the contents if the texture content is lost somehow, you can leave
  127. this parameter as 0. However, if you intend to populate the
  128. texture only once, then you should implement ManualResourceLoader
  129. and pass a pointer to it in this parameter; this means that if the
  130. manual texture ever needs to be reloaded, the ManualResourceLoader
  131. will be called to do it.
  132. @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
  133. (sRGB) on this texture. The hardware will convert from gamma space
  134. to linear space when reading from this texture. Only applicable for
  135. 8-bits per channel textures, will be ignored for other types. Has the advantage
  136. over pre-applied gamma that the texture precision is maintained.
  137. @param fsaa The level of multisampling to use if this is a render target. Ignored
  138. if usage does not include TU_RENDERTARGET or if the device does
  139. not support it.
  140. */
  141. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int num_mips,
  142. PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 fsaa = 0,
  143. const String& fsaaHint = StringUtil::BLANK)
  144. {
  145. return createTexture(texType, width, height, 1,
  146. num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
  147. }
  148. /**
  149. * @brief Creates a completely empty and uninitialized Texture.
  150. * Should only be used for VERY specific purposes, like deserialization,
  151. * as it requires additional manual initialization that is not required normally.
  152. */
  153. TexturePtr createEmpty();
  154. /**
  155. * @brief Creates a new RenderTexture and automatically generates a color surface
  156. * and (optionally) a depth/stencil surface
  157. */
  158. virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  159. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "",
  160. bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  161. /**
  162. * @brief Creates a RenderTexture using the description struct.
  163. */
  164. virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  165. /**
  166. * @brief Creates a new multi render texture. You may use this type of texture
  167. * to render to multiple output textures at once.
  168. */
  169. virtual MultiRenderTexturePtr createEmptyMultiRenderTexture();
  170. /** Returns whether this render system can natively support the precise texture
  171. format requested with the given usage options.
  172. @remarks
  173. You can still create textures with this format even if this method returns
  174. false; the texture format will just be altered to one which the device does
  175. support.
  176. @note
  177. Sometimes the device may just slightly change the format, such as reordering the
  178. channels or packing the channels differently, without it making and qualitative
  179. differences to the texture. If you want to just detect whether the quality of a
  180. given texture will be reduced, use isEquivalentFormatSupport instead.
  181. @param format The pixel format requested
  182. @param usage The kind of usage this texture is intended for, a combination of
  183. the TextureUsage flags.
  184. @returns true if the format is natively supported, false if a fallback would be used.
  185. */
  186. virtual bool isFormatSupported(TextureType ttype, PixelFormat format, int usage);
  187. /** Returns whether this render system can support the texture format requested
  188. with the given usage options, or another format with no quality reduction.
  189. */
  190. virtual bool isEquivalentFormatSupported(TextureType ttype, PixelFormat format, int usage);
  191. /** Gets the format which will be natively used for a requested format given the
  192. constraints of the current device.
  193. */
  194. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0;
  195. HTexture getDummyTexture() const { return mDummyTexture; }
  196. protected:
  197. HTexture mDummyTexture;
  198. virtual TexturePtr createTextureImpl() = 0;
  199. virtual RenderTexturePtr createRenderTextureImpl() = 0;
  200. virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
  201. virtual void onStartUp();
  202. };
  203. /** @} */
  204. /** @} */
  205. }// Namespace
  206. #endif