BsTextureManager.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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(const TEXTURE_DESC&) */
  23. SPtr<Texture> createTexture(const TEXTURE_DESC& desc);
  24. /**
  25. * Creates a new 2D or 3D texture initialized using the provided pixel data. Texture will not have any mipmaps.
  26. *
  27. * @param[in] desc Description of the texture to create. Must match the pixel data.
  28. * @param[in] pixelData Data to initialize the texture width.
  29. */
  30. SPtr<Texture> createTexture(const TEXTURE_DESC& desc, const SPtr<PixelData>& pixelData);
  31. /**
  32. * Creates a completely empty and uninitialized Texture.
  33. *
  34. * @note
  35. * Internal method. Should only be used for very specific purposes, like deserialization, as it requires additional
  36. * manual initialization that is not required normally.
  37. */
  38. SPtr<Texture> _createEmpty();
  39. /**
  40. * Creates a new RenderTexture and automatically generates a single color surface and (optionally) a depth/stencil
  41. * surface.
  42. *
  43. * @param[in] colorDesc Description of the color surface to create.
  44. * @param[in] createDepth Determines will a depth/stencil buffer of the same size as the color buffer be
  45. * created for the render texture.
  46. * @param[in] depthStencilFormat Format of the depth/stencil buffer if enabled.
  47. */
  48. virtual SPtr<RenderTexture> createRenderTexture(const TEXTURE_DESC& colorDesc,
  49. bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  50. /**
  51. * Creates a RenderTexture using the description struct.
  52. *
  53. * @param[in] desc Description of the render texture to create.
  54. */
  55. virtual SPtr<RenderTexture> createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  56. /**
  57. * Gets the format which will be natively used for a requested format given the constraints of the current device.
  58. *
  59. * @note Thread safe.
  60. */
  61. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
  62. protected:
  63. /**
  64. * Creates an empty and uninitialized render texture of a specific type. This is to be implemented by render
  65. * systems with their own implementations.
  66. */
  67. virtual SPtr<RenderTexture> createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
  68. mutable HTexture mDummyTexture;
  69. };
  70. /**
  71. * Defines interface for creation of textures. Render systems provide their own implementations.
  72. *
  73. * @note Core thread only.
  74. */
  75. class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
  76. {
  77. public:
  78. virtual ~TextureCoreManager() { }
  79. /** @copydoc Module::onStartUp */
  80. void onStartUp() override;
  81. /** @copydoc Module::onShutDown */
  82. void onShutDown() override;
  83. /**
  84. * @copydoc TextureManager::createTexture(const TEXTURE_DESC&)
  85. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  86. */
  87. SPtr<TextureCore> createTexture(const TEXTURE_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  88. /**
  89. * @copydoc TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&)
  90. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  91. */
  92. SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_DESC_CORE& desc,
  93. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  94. protected:
  95. friend class Texture;
  96. friend class TextureCore;
  97. friend class RenderTexture;
  98. /**
  99. * Creates an empty and uninitialized texture of a specific type. This is to be implemented by render systems with
  100. * their own implementations.
  101. */
  102. virtual SPtr<TextureCore> createTextureInternal(const TEXTURE_DESC& desc,
  103. const SPtr<PixelData>& initialData = nullptr, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  104. /** @copydoc createRenderTexture */
  105. virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC_CORE& desc,
  106. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  107. };
  108. /** @} */
  109. }