BsTextureManager.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsTexture.h"
  4. #include "BsRenderTexture.h"
  5. #include "BsMultiRenderTexture.h"
  6. #include "BsModule.h"
  7. namespace BansheeEngine
  8. {
  9. /** @cond INTERNAL */
  10. /** @addtogroup Resources
  11. * @{
  12. */
  13. /**
  14. * Defines interface for creation of textures. Render systems provide their own implementations.
  15. *
  16. * @note Sim thread only.
  17. */
  18. class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
  19. {
  20. public:
  21. virtual ~TextureManager() { }
  22. /** @copydoc Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32) */
  23. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  24. int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  25. UINT32 multisampleCount = 0);
  26. /** @copydoc Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32) */
  27. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int numMips,
  28. PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0)
  29. {
  30. return createTexture(texType, width, height, 1,
  31. numMips, format, usage, hwGammaCorrection, multisampleCount);
  32. }
  33. /** @copydoc Texture::create(const PixelDataPtr&, int, bool) */
  34. TexturePtr createTexture(const PixelDataPtr& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
  35. /**
  36. * Creates a completely empty and uninitialized Texture.
  37. *
  38. * @note
  39. * Internal method. Should only be used for very specific purposes, like deserialization, as it requires additional
  40. * manual initialization that is not required normally.
  41. */
  42. TexturePtr _createEmpty();
  43. /**
  44. * Creates a new RenderTexture and automatically generates a color surface and (optionally) a depth/stencil surface.
  45. *
  46. * @param[in] texType Type of the texture.
  47. * @param[in] width Width of the texture in pixels.
  48. * @param[in] height Height of the texture in pixels.
  49. * @param[in] format Format of the pixels.
  50. * @param[in] hwGamma If true, any color data will be gamma corrected before being written into the
  51. * texture.
  52. * @param[in] multisampleCount If higher than 1, texture containing multiple samples per pixel is created.
  53. * @param[in] multisampleHint Hint about what kind of multisampling to use. Render system specific.
  54. * @param[in] createDepth Determines will a depth/stencil buffer of the same size as the color buffer be
  55. * created for the render texture.
  56. * @param[in] depthStencilFormat Format of the depth/stencil buffer if enabled.
  57. */
  58. virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  59. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  60. bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  61. /** Creates a RenderTexture using the description struct. */
  62. virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  63. /**
  64. * Creates a new multi render texture. You may use this type of texture to render to multiple output textures at
  65. * once.
  66. */
  67. virtual MultiRenderTexturePtr createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
  68. /**
  69. * Gets the format which will be natively used for a requested format given the constraints of the current device.
  70. *
  71. * @note Thread safe.
  72. */
  73. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
  74. protected:
  75. /**
  76. * Creates an empty and uninitialized render texture of a specific type. This is to be implemented by render
  77. * systems with their own implementations.
  78. */
  79. virtual RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
  80. /**
  81. * Creates an empty and uninitialized multi render texture of a specific type. This is to be implemented by render
  82. * systems with their own implementations.
  83. */
  84. virtual MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc) = 0;
  85. mutable HTexture mDummyTexture;
  86. };
  87. /**
  88. * Defines interface for creation of textures. Render systems provide their own implementations.
  89. *
  90. * @note Core thread only.
  91. */
  92. class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
  93. {
  94. public:
  95. virtual ~TextureCoreManager() { }
  96. /**
  97. * @copydoc TextureManager::createTexture(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
  98. */
  99. SPtr<TextureCore> createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  100. int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  101. UINT32 multisampleCount = 0);
  102. /** @copydoc TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&) */
  103. SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_CORE_DESC& desc);
  104. /** @copydoc TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC&) */
  105. SPtr<MultiRenderTextureCore> createMultiRenderTexture(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
  106. protected:
  107. friend class Texture;
  108. friend class RenderTexture;
  109. friend class MultiRenderTexture;
  110. /**
  111. * Creates an empty and uninitialized texture of a specific type. This is to be implemented by render systems with
  112. * their own implementations.
  113. */
  114. virtual SPtr<TextureCore> createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  115. int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  116. UINT32 multisampleCount = 0, const PixelDataPtr& initialData = nullptr) = 0;
  117. /** @copydoc TextureManager::createRenderTextureImpl */
  118. virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_CORE_DESC& desc) = 0;
  119. /** @copydoc TextureManager::createMultiRenderTextureImpl */
  120. virtual SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_CORE_DESC& desc) = 0;
  121. };
  122. /** @} */
  123. /** @endcond */
  124. }