BsTextureManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 bs
  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_D32);
  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. namespace ct
  71. {
  72. /**
  73. * Defines interface for creation of textures. Render systems provide their own implementations.
  74. *
  75. * @note Core thread only.
  76. */
  77. class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
  78. {
  79. public:
  80. virtual ~TextureManager() { }
  81. /** @copydoc Module::onStartUp */
  82. void onStartUp() override;
  83. /** @copydoc Module::onShutDown */
  84. void onShutDown() override;
  85. /**
  86. * @copydoc bs::TextureManager::createTexture(const TEXTURE_DESC&)
  87. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  88. */
  89. SPtr<Texture> createTexture(const TEXTURE_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  90. /**
  91. * @copydoc bs::TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&)
  92. * @param[in] deviceIdx Index of the GPU device to create the object on.
  93. */
  94. SPtr<RenderTexture> createRenderTexture(const RENDER_TEXTURE_DESC& desc, UINT32 deviceIdx = 0);
  95. protected:
  96. friend class bs::Texture;
  97. friend class Texture;
  98. friend class bs::RenderTexture;
  99. /**
  100. * Creates an empty and uninitialized texture of a specific type. This is to be implemented by render systems with
  101. * their own implementations.
  102. */
  103. virtual SPtr<Texture> createTextureInternal(const TEXTURE_DESC& desc,
  104. const SPtr<PixelData>& initialData = nullptr, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  105. /** @copydoc createRenderTexture */
  106. virtual SPtr<RenderTexture> createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc,
  107. UINT32 deviceIdx = 0) = 0;
  108. };
  109. }
  110. /** @} */
  111. }