BsTextureManager.h 6.4 KB

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