BsTextureManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsTexture.h"
  4. #include "BsMultiRenderTexture.h"
  5. #include "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Defines interface for creation of textures. Render systems
  10. * provide their own implementations.
  11. *
  12. * @note Thread safe.
  13. */
  14. class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
  15. {
  16. public:
  17. TextureManager();
  18. virtual ~TextureManager();
  19. /**
  20. * @copydoc Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, const String&)
  21. */
  22. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  23. int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
  24. UINT32 multisampleCount = 0, const String& multisampleHint = StringUtil::BLANK);
  25. /**
  26. * @copydoc Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, const String&)
  27. */
  28. TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int numMips,
  29. PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0,
  30. const String& multisampleHint = StringUtil::BLANK)
  31. {
  32. return createTexture(texType, width, height, 1,
  33. numMips, format, usage, hwGammaCorrection, multisampleCount, multisampleHint);
  34. }
  35. /**
  36. * @brief Creates a completely empty and uninitialized Texture.
  37. *
  38. * @note Internal method. Should only be used for very specific purposes, like deserialization,
  39. * as it requires additional manual initialization that is not required normally.
  40. */
  41. TexturePtr _createEmpty();
  42. /**
  43. * @brief Creates a new RenderTexture and automatically generates a color surface
  44. * and (optionally) a depth/stencil surface.
  45. *
  46. * @param texType Type of the texture.
  47. * @param width Width of the texture in pixels.
  48. * @param height Height of the texture in pixels.
  49. * @param format Format of the pixels.
  50. * @param hwGamma If true, any color data will be gamma corrected before being written
  51. * into the texture.
  52. * @param multisampleCount If higher than 1, texture containing multiple samples per pixel is created.
  53. * @param multisampleHint Hint about what kind of multisampling to use. Render system specific.
  54. * @param createDepth Determines will a depth/stencil buffer of the same size as the color buffer be created
  55. * for the render texture.
  56. * @param depthStencilFormat Format of the depth/stencil buffer if enabled.
  57. */
  58. virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  59. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  60. const String& multisampleHint = "", bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  61. /**
  62. * @brief Creates a RenderTexture using the description struct.
  63. */
  64. virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
  65. /**
  66. * @brief Creates a new multi render texture. You may use this type of texture
  67. * to render to multiple output textures at once.
  68. */
  69. virtual MultiRenderTexturePtr createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
  70. /**
  71. * @brief Gets the format which will be natively used for a requested format given the
  72. * constraints of the current device.
  73. *
  74. * @note Thread safe.
  75. */
  76. virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
  77. /**
  78. * @brief Returns tiny dummy texture for use when no other is available.
  79. */
  80. const HTexture& getDummyTexture() const { return mDummyTexture; }
  81. protected:
  82. /**
  83. * @brief Creates an empty and uninitialized texture of a specific type. This is to be implemented
  84. * by render systems with their own implementations.
  85. */
  86. virtual TexturePtr createTextureImpl() = 0;
  87. /**
  88. * @brief Creates an empty and uninitialized render texture of a specific type. This
  89. * is to be implemented by render systems with their own implementations.
  90. */
  91. virtual RenderTexturePtr createRenderTextureImpl() = 0;
  92. /**
  93. * @brief Creates an empty and uninitialized multi render texture of a specific type. This is
  94. * to be implemented by render systems with their own implementations.
  95. */
  96. virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
  97. /**
  98. * @copydoc Module::onStartUp
  99. */
  100. virtual void onStartUp();
  101. protected:
  102. HTexture mDummyTexture;
  103. };
  104. }