BsTextureManager.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "BsModule.h"
  8. namespace BansheeEngine
  9. {
  10. /** @addtogroup Resources-Internal
  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, UINT32) */
  23. SPtr<Texture> 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, UINT32 numArraySlices = 1);
  26. /** @copydoc Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, UINT32) */
  27. SPtr<Texture> createTexture(TextureType texType, UINT32 width, UINT32 height, int numMips,
  28. PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0,
  29. UINT32 numArraySlices = 1)
  30. {
  31. return createTexture(texType, width, height, 1,
  32. numMips, format, usage, hwGammaCorrection, multisampleCount, numArraySlices);
  33. }
  34. /** @copydoc Texture::create(const SPtr<PixelData>&, int, bool) */
  35. SPtr<Texture> createTexture(const SPtr<PixelData>& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
  36. /**
  37. * Creates a completely empty and uninitialized Texture.
  38. *
  39. * @note
  40. * Internal method. Should only be used for very specific purposes, like deserialization, as it requires additional
  41. * manual initialization that is not required normally.
  42. */
  43. SPtr<Texture> _createEmpty();
  44. /**
  45. * Creates a new RenderTexture and automatically generates a single color surface and (optionally) a depth/stencil
  46. * surface.
  47. *
  48. * @param[in] textureType 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] createDepth Determines will a depth/stencil buffer of the same size as the color buffer be
  56. * created for the render texture.
  57. * @param[in] depthStencilFormat Format of the depth/stencil buffer if enabled.
  58. */
  59. virtual SPtr<RenderTexture> createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  60. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  61. bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  62. /** Creates a RenderTexture using the description struct. */
  63. virtual SPtr<RenderTexture> createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  64. /**
  65. * Gets the format which will be natively used for a requested format given the constraints of the current device.
  66. *
  67. * @note Thread safe.
  68. */
  69. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
  70. protected:
  71. /**
  72. * Creates an empty and uninitialized render texture of a specific type. This is to be implemented by render
  73. * systems with their own implementations.
  74. */
  75. virtual SPtr<RenderTexture> createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
  76. mutable HTexture mDummyTexture;
  77. };
  78. /**
  79. * Defines interface for creation of textures. Render systems provide their own implementations.
  80. *
  81. * @note Core thread only.
  82. */
  83. class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
  84. {
  85. public:
  86. virtual ~TextureCoreManager() { }
  87. /** @copydoc Module::onStartUp */
  88. void onStartUp() override;
  89. /** @copydoc Module::onShutDown */
  90. void onShutDown() override;
  91. /**
  92. * @copydoc TextureManager::createTexture(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, UINT32)
  93. */
  94. SPtr<TextureCore> createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  95. int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  96. UINT32 multisampleCount = 0, UINT32 numArraySlices = 1);
  97. /** @copydoc TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&) */
  98. SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_DESC_CORE& desc);
  99. protected:
  100. friend class Texture;
  101. friend class TextureCore;
  102. friend class RenderTexture;
  103. /**
  104. * Creates an empty and uninitialized texture of a specific type. This is to be implemented by render systems with
  105. * their own implementations.
  106. */
  107. virtual SPtr<TextureCore> createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  108. int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  109. UINT32 multisampleCount = 0, UINT32 numArraySlices = 1, const SPtr<PixelData>& initialData = nullptr) = 0;
  110. /** @copydoc TextureManager::createRenderTextureImpl */
  111. virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC_CORE& desc) = 0;
  112. };
  113. /** @} */
  114. }