CmTextureManager.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 CamelotEngine {
  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. protected:
  52. virtual Texture* createImpl() = 0;
  53. void destroy(Texture* texture);
  54. virtual void destroy_internal(Texture* texture);
  55. public:
  56. TextureManager(void);
  57. virtual ~TextureManager();
  58. /** Create a manual texture with specified width, height and depth (not loaded from a file).
  59. @param
  60. name The name to give the resulting texture
  61. @param
  62. group The name of the resource group to assign the texture to
  63. @param
  64. texType The type of texture to load/create, defaults to normal 2D textures
  65. @param
  66. width, height, depth The dimensions of the texture
  67. @param
  68. numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
  69. the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps())
  70. If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
  71. level, 1x1x1.
  72. @param
  73. format The internal format you wish to request; the manager reserves
  74. the right to create a different format if the one you select is
  75. not available in this context.
  76. @param
  77. usage The kind of usage this texture is intended for. It
  78. is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
  79. TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
  80. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  81. update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
  82. @param
  83. loader If you intend the contents of the manual texture to be
  84. regularly updated, to the extent that you don't need to recover
  85. the contents if the texture content is lost somehow, you can leave
  86. this parameter as 0. However, if you intend to populate the
  87. texture only once, then you should implement ManualResourceLoader
  88. and pass a pointer to it in this parameter; this means that if the
  89. manual texture ever needs to be reloaded, the ManualResourceLoader
  90. will be called to do it.
  91. @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
  92. (sRGB) on this texture. The hardware will convert from gamma space
  93. to linear space when reading from this texture. Only applicable for
  94. 8-bits per channel textures, will be ignored for other types. Has the advantage
  95. over pre-applied gamma that the texture precision is maintained.
  96. @param fsaa The level of multisampling to use if this is a render target. Ignored
  97. if usage does not include TU_RENDERTARGET or if the device does
  98. not support it.
  99. */
  100. TexturePtr create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  101. int num_mips, PixelFormat format, int usage = TU_DEFAULT,
  102. bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
  103. /** Create a manual texture with a depth of 1 (not loaded from a file).
  104. @param
  105. name The name to give the resulting texture
  106. @param
  107. group The name of the resource group to assign the texture to
  108. @param
  109. texType The type of texture to load/create, defaults to normal 2D textures
  110. @param
  111. width, height The dimensions of the texture
  112. @param
  113. numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
  114. the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()).
  115. If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
  116. level, 1x1x1.
  117. @param
  118. format The internal format you wish to request; the manager reserves
  119. the right to create a different format if the one you select is
  120. not available in this context.
  121. @param
  122. usage The kind of usage this texture is intended for. It
  123. is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY,
  124. TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
  125. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  126. update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
  127. @param
  128. loader If you intend the contents of the manual texture to be
  129. regularly updated, to the extent that you don't need to recover
  130. the contents if the texture content is lost somehow, you can leave
  131. this parameter as 0. However, if you intend to populate the
  132. texture only once, then you should implement ManualResourceLoader
  133. and pass a pointer to it in this parameter; this means that if the
  134. manual texture ever needs to be reloaded, the ManualResourceLoader
  135. will be called to do it.
  136. @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
  137. (sRGB) on this texture. The hardware will convert from gamma space
  138. to linear space when reading from this texture. Only applicable for
  139. 8-bits per channel textures, will be ignored for other types. Has the advantage
  140. over pre-applied gamma that the texture precision is maintained.
  141. @param fsaa The level of multisampling to use if this is a render target. Ignored
  142. if usage does not include TU_RENDERTARGET or if the device does
  143. not support it.
  144. */
  145. TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
  146. PixelFormat format, int usage = TU_DEFAULT,
  147. bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK)
  148. {
  149. return create(texType, width, height, 1,
  150. num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
  151. }
  152. /**
  153. * @brief Creates a completely empty and uninitialized Texture.
  154. * Should only be used for VERY specific purposes, like deserialization,
  155. * as it requires additional manual initialization that is not required normally.
  156. */
  157. TexturePtr createEmpty();
  158. /** Returns whether this render system can natively support the precise texture
  159. format requested with the given usage options.
  160. @remarks
  161. You can still create textures with this format even if this method returns
  162. false; the texture format will just be altered to one which the device does
  163. support.
  164. @note
  165. Sometimes the device may just slightly change the format, such as reordering the
  166. channels or packing the channels differently, without it making and qualitative
  167. differences to the texture. If you want to just detect whether the quality of a
  168. given texture will be reduced, use isEquivalentFormatSupport instead.
  169. @param format The pixel format requested
  170. @param usage The kind of usage this texture is intended for, a combination of
  171. the TextureUsage flags.
  172. @returns true if the format is natively supported, false if a fallback would be used.
  173. */
  174. virtual bool isFormatSupported(TextureType ttype, PixelFormat format, int usage);
  175. /** Returns whether this render system can support the texture format requested
  176. with the given usage options, or another format with no quality reduction.
  177. */
  178. virtual bool isEquivalentFormatSupported(TextureType ttype, PixelFormat format, int usage);
  179. /** Gets the format which will be natively used for a requested format given the
  180. constraints of the current device.
  181. */
  182. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0;
  183. /** Returns whether this render system has hardware filtering supported for the
  184. texture format requested with the given usage options.
  185. @remarks
  186. Not all texture format are supports filtering by the hardware, i.e. some
  187. cards support floating point format, but it doesn't supports filtering on
  188. the floating point texture at all, or only a subset floating point formats
  189. have flitering supported.
  190. @par
  191. In the case you want to write shader to work with floating point texture, and
  192. you want to produce better visual quality, it's necessary to flitering the
  193. texture manually in shader (potential requires four or more texture fetch
  194. instructions, plus several arithmetic instructions) if filtering doesn't
  195. supported by hardware. But in case on the hardware that supports floating
  196. point filtering natively, it had better to adopt this capability for
  197. performance (because only one texture fetch instruction are required) and
  198. doesn't loss visual quality.
  199. @par
  200. This method allow you queries hardware texture filtering capability to deciding
  201. which verion of the shader to be used. Note it's up to you to write multi-version
  202. shaders for support various hardware, internal engine can't do that for you
  203. automatically.
  204. @note
  205. Under GL, texture filtering are always supported by driver, but if it's not
  206. supported by hardware natively, software simulation will be used, and you
  207. will end up with very slow speed (less than 0.1 fps for example). To slove
  208. this performance problem, you must disable filtering manually (by use
  209. <b>filtering none</b> in the material script's texture_unit section, or
  210. call TextureUnitState::setTextureFiltering with TFO_NONE if populate
  211. material in code).
  212. @param ttype The texture type requested
  213. @param format The pixel format requested
  214. @param usage The kind of usage this texture is intended for, a combination of
  215. the TextureUsage flags.
  216. @param preciseFormatOnly Whether precise or fallback format mode is used to detecting.
  217. In case the pixel format doesn't supported by device, false will be returned
  218. if in precise mode, and natively used pixel format will be actually use to
  219. check if in fallback mode.
  220. @returns true if the texture filtering is supported.
  221. */
  222. virtual bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
  223. bool preciseFormatOnly = false) = 0;
  224. protected:
  225. };
  226. /** @} */
  227. /** @} */
  228. }// Namespace
  229. #endif