BsTextureManager.h 5.7 KB

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