CmTextureManager.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. #pragma once
  25. #include "CmPrerequisites.h"
  26. #include "CmTexture.h"
  27. #include "CmModule.h"
  28. namespace CamelotFramework
  29. {
  30. /**
  31. * @brief Class for loading and managing textures.
  32. *
  33. * @note Must be initialized when RenderSystem is first started.
  34. */
  35. class CM_EXPORT TextureManager : public Module<TextureManager>
  36. {
  37. public:
  38. TextureManager();
  39. virtual ~TextureManager();
  40. /** Create a manual texture with specified width, height and depth (not loaded from a file).
  41. @param
  42. name The name to give the resulting texture
  43. @param
  44. group The name of the resource group to assign the texture to
  45. @param
  46. texType The type of texture to load/create, defaults to normal 2D textures
  47. @param
  48. width, height, depth The dimensions of the texture
  49. @param
  50. numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
  51. the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps())
  52. If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
  53. level, 1x1x1.
  54. @param
  55. format The internal format you wish to request; the manager reserves
  56. the right to create a different format if the one you select is
  57. not available in this context.
  58. @param
  59. usage The kind of usage this texture is intended for. It
  60. is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
  61. TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
  62. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  63. update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
  64. @param
  65. loader If you intend the contents of the manual texture to be
  66. regularly updated, to the extent that you don't need to recover
  67. the contents if the texture content is lost somehow, you can leave
  68. this parameter as 0. However, if you intend to populate the
  69. texture only once, then you should implement ManualResourceLoader
  70. and pass a pointer to it in this parameter; this means that if the
  71. manual texture ever needs to be reloaded, the ManualResourceLoader
  72. will be called to do it.
  73. @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
  74. (sRGB) on this texture. The hardware will convert from gamma space
  75. to linear space when reading from this texture. Only applicable for
  76. 8-bits per channel textures, will be ignored for other types. Has the advantage
  77. over pre-applied gamma that the texture precision is maintained.
  78. @param fsaa The level of multisampling to use if this is a render target. Ignored
  79. if usage does not include TU_RENDERTARGET or if the device does
  80. not support it.
  81. */
  82. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  83. int num_mips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  84. UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
  85. /** Create a manual texture with a depth of 1 (not loaded from a file).
  86. @param
  87. name The name to give the resulting texture
  88. @param
  89. group The name of the resource group to assign the texture to
  90. @param
  91. texType The type of texture to load/create, defaults to normal 2D textures
  92. @param
  93. width, height The dimensions of the texture
  94. @param
  95. numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
  96. the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()).
  97. If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
  98. level, 1x1x1.
  99. @param
  100. format The internal format you wish to request; the manager reserves
  101. the right to create a different format if the one you select is
  102. not available in this context.
  103. @param
  104. usage The kind of usage this texture is intended for. It
  105. is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
  106. TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
  107. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  108. update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
  109. @param
  110. loader If you intend the contents of the manual texture to be
  111. regularly updated, to the extent that you don't need to recover
  112. the contents if the texture content is lost somehow, you can leave
  113. this parameter as 0. However, if you intend to populate the
  114. texture only once, then you should implement ManualResourceLoader
  115. and pass a pointer to it in this parameter; this means that if the
  116. manual texture ever needs to be reloaded, the ManualResourceLoader
  117. will be called to do it.
  118. @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
  119. (sRGB) on this texture. The hardware will convert from gamma space
  120. to linear space when reading from this texture. Only applicable for
  121. 8-bits per channel textures, will be ignored for other types. Has the advantage
  122. over pre-applied gamma that the texture precision is maintained.
  123. @param fsaa The level of multisampling to use if this is a render target. Ignored
  124. if usage does not include TU_RENDERTARGET or if the device does
  125. not support it.
  126. */
  127. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int num_mips,
  128. PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 fsaa = 0,
  129. const String& fsaaHint = StringUtil::BLANK)
  130. {
  131. return createTexture(texType, width, height, 1,
  132. num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
  133. }
  134. /**
  135. * @brief Creates a completely empty and uninitialized Texture.
  136. * Should only be used for VERY specific purposes, like deserialization,
  137. * as it requires additional manual initialization that is not required normally.
  138. */
  139. TexturePtr createEmpty();
  140. /**
  141. * @brief Creates a new RenderTexture and automatically generates a color surface
  142. * and (optionally) a depth/stencil surface
  143. */
  144. virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  145. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "",
  146. bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  147. /**
  148. * @brief Creates a RenderTexture using the description struct.
  149. */
  150. virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  151. /**
  152. * @brief Creates a new multi render texture. You may use this type of texture
  153. * to render to multiple output textures at once.
  154. */
  155. virtual MultiRenderTexturePtr createEmptyMultiRenderTexture();
  156. /** Returns whether this render system can natively support the precise texture
  157. format requested with the given usage options.
  158. @remarks
  159. You can still create textures with this format even if this method returns
  160. false; the texture format will just be altered to one which the device does
  161. support.
  162. @note
  163. Sometimes the device may just slightly change the format, such as reordering the
  164. channels or packing the channels differently, without it making and qualitative
  165. differences to the texture. If you want to just detect whether the quality of a
  166. given texture will be reduced, use isEquivalentFormatSupport instead.
  167. @param format The pixel format requested
  168. @param usage The kind of usage this texture is intended for, a combination of
  169. the TextureUsage flags.
  170. @returns true if the format is natively supported, false if a fallback would be used.
  171. */
  172. virtual bool isFormatSupported(TextureType ttype, PixelFormat format, int usage);
  173. /**
  174. * @brief Gets the format which will be natively used for a requested format given the
  175. * constraints of the current device.
  176. *
  177. * @note Thread safe.
  178. */
  179. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0;
  180. const HTexture& getDummyTexture() const { return mDummyTexture; }
  181. protected:
  182. HTexture mDummyTexture;
  183. virtual TexturePtr createTextureImpl() = 0;
  184. virtual RenderTexturePtr createRenderTextureImpl() = 0;
  185. virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
  186. virtual void onStartUp();
  187. };
  188. }