BsHardwareBufferManager.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "BsModule.h"
  6. #include "BsVertexBuffer.h"
  7. #include "BsIndexBuffer.h"
  8. #include "BsVertexDeclaration.h"
  9. namespace BansheeEngine
  10. {
  11. struct GPU_BUFFER_DESC;
  12. struct GPU_PARAMS_DESC;
  13. /** @addtogroup RenderAPI-Internal
  14. * @{
  15. */
  16. /**
  17. * Handles creation of various hardware buffers.
  18. *
  19. * @note Sim thread only.
  20. */
  21. class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  22. {
  23. public:
  24. HardwareBufferManager();
  25. virtual ~HardwareBufferManager();
  26. /**
  27. * Creates a new vertex buffer used for holding number of vertices and other per-vertex data. Buffer can be bound
  28. * to the pipeline and its data can be passed to the active vertex GPU program.
  29. *
  30. * @param[in] desc Description of the buffer to create.
  31. */
  32. SPtr<VertexBuffer> createVertexBuffer(const VERTEX_BUFFER_DESC& desc);
  33. /**
  34. * Creates a new index buffer that holds indices referencing vertices in a vertex buffer. Indices are interpreted
  35. * by the pipeline and vertices are drawn in the order specified in the index buffer.
  36. *
  37. * @param[in] desc Description of the buffer to create.
  38. */
  39. SPtr<IndexBuffer> createIndexBuffer(const INDEX_BUFFER_DESC& desc);
  40. /**
  41. * Creates an GPU parameter block that you can use for setting parameters for GPU programs. Parameter blocks may be
  42. * used for sharing parameter data between multiple GPU programs, requiring you to update only one buffer for all of
  43. * them, potentially improving performance.
  44. *
  45. * @param[in] size Size of the parameter buffer in bytes.
  46. * @param[in] usage Usage that tells the hardware how will be buffer be used.
  47. */
  48. SPtr<GpuParamBlockBuffer> createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  49. /**
  50. * Creates a generic buffer that can be passed as a parameter to a GPU program. This type of buffer can hold various
  51. * type of data and can be used for various purposes. See GpuBufferType for explanation of different buffer types.
  52. *
  53. * @param[in] desc Description of the buffer to create.
  54. */
  55. SPtr<GpuBuffer> createGpuBuffer(const GPU_BUFFER_DESC& desc);
  56. /** Creates a new vertex declaration from a list of vertex elements. */
  57. SPtr<VertexDeclaration> createVertexDeclaration(const SPtr<VertexDataDesc>& desc);
  58. /** Creates a new GpuParams object from the provided set of GPU parameter descriptors. */
  59. SPtr<GpuParams> createGpuParams(const GPU_PARAMS_DESC& desc);
  60. };
  61. /**
  62. * Handles creation of various hardware buffers.
  63. *
  64. * @note Core thread only.
  65. */
  66. class BS_CORE_EXPORT HardwareBufferCoreManager : public Module<HardwareBufferCoreManager>
  67. {
  68. public:
  69. virtual ~HardwareBufferCoreManager() { }
  70. /**
  71. * @copydoc HardwareBufferManager::createVertexBuffer
  72. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  73. */
  74. SPtr<VertexBufferCore> createVertexBuffer(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  75. /**
  76. * @copydoc HardwareBufferManager::createIndexBuffer
  77. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  78. */
  79. SPtr<IndexBufferCore> createIndexBuffer(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  80. /** @copydoc HardwareBufferManager::createVertexDeclaration */
  81. SPtr<VertexDeclarationCore> createVertexDeclaration(const SPtr<VertexDataDesc>& desc);
  82. /** @copydoc HardwareBufferManager::createVertexDeclaration */
  83. SPtr<VertexDeclarationCore> createVertexDeclaration(const List<VertexElement>& elements);
  84. /** @copydoc HardwareBufferManager::createGpuParamBlockBuffer */
  85. SPtr<GpuParamBlockBufferCore> createGpuParamBlockBuffer(UINT32 size,
  86. GpuParamBlockUsage usage = GPBU_DYNAMIC);
  87. /**
  88. * @copydoc HardwareBufferManager::createGpuBuffer
  89. * @param[in] deviceMask Mask that determines on which GPU devices should the buffer be created on.
  90. */
  91. SPtr<GpuBufferCore> createGpuBuffer(const GPU_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  92. /** @copydoc HardwareBufferManager::createGpuParams */
  93. SPtr<GpuParamsCore> createGpuParams(const GPU_PARAMS_DESC& desc);
  94. protected:
  95. friend class IndexBuffer;
  96. friend class IndexBufferCore;
  97. friend class VertexBuffer;
  98. friend class VertexBufferCore;
  99. friend class VertexDeclaration;
  100. friend class GpuParamBlockBuffer;
  101. friend class GpuBuffer;
  102. friend class GpuBufferCore;
  103. /** @copydoc createVertexBuffer */
  104. virtual SPtr<VertexBufferCore> createVertexBufferInternal(const VERTEX_BUFFER_DESC& desc,
  105. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  106. /** @copydoc createIndexBuffer */
  107. virtual SPtr<IndexBufferCore> createIndexBufferInternal(const INDEX_BUFFER_DESC& desc,
  108. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  109. /** @copydoc createGpuParamBlockBuffer */
  110. virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size,
  111. GpuParamBlockUsage usage = GPBU_DYNAMIC) = 0;
  112. /** @copydoc createGpuBuffer */
  113. virtual SPtr<GpuBufferCore> createGpuBufferInternal(const GPU_BUFFER_DESC& desc,
  114. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  115. /** @copydoc createVertexDeclaration */
  116. virtual SPtr<VertexDeclarationCore> createVertexDeclarationInternal(const List<VertexElement>& elements);
  117. /** @copydoc createGpuParams */
  118. virtual SPtr<GpuParamsCore> createGpuParamsInternal(const GPU_PARAMS_DESC& desc);
  119. };
  120. /** @} */
  121. }