BsTextureManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /** Creates a RenderTexture using the description struct. */
  51. virtual SPtr<RenderTexture> createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  52. /**
  53. * Gets the format which will be natively used for a requested format given the constraints of the current device.
  54. *
  55. * @note Thread safe.
  56. */
  57. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
  58. protected:
  59. /**
  60. * Creates an empty and uninitialized render texture of a specific type. This is to be implemented by render
  61. * systems with their own implementations.
  62. */
  63. virtual SPtr<RenderTexture> createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
  64. mutable HTexture mDummyTexture;
  65. };
  66. /**
  67. * Defines interface for creation of textures. Render systems provide their own implementations.
  68. *
  69. * @note Core thread only.
  70. */
  71. class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
  72. {
  73. public:
  74. virtual ~TextureCoreManager() { }
  75. /** @copydoc Module::onStartUp */
  76. void onStartUp() override;
  77. /** @copydoc Module::onShutDown */
  78. void onShutDown() override;
  79. /**
  80. * @copydoc TextureManager::createTexture(const TEXTURE_DESC&)
  81. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  82. */
  83. SPtr<TextureCore> createTexture(const TEXTURE_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  84. /**
  85. * @copydoc TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&)
  86. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  87. */
  88. SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_DESC_CORE& desc,
  89. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  90. protected:
  91. friend class Texture;
  92. friend class TextureCore;
  93. friend class RenderTexture;
  94. /**
  95. * Creates an empty and uninitialized texture of a specific type. This is to be implemented by render systems with
  96. * their own implementations.
  97. */
  98. virtual SPtr<TextureCore> createTextureInternal(const TEXTURE_DESC& desc,
  99. const SPtr<PixelData>& initialData = nullptr, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  100. /** @copydoc createRenderTexture */
  101. virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_DESC_CORE& desc,
  102. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  103. };
  104. /** @} */
  105. }