BsHardwareBufferManager.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. /**
  57. * Creates a new vertex declaration from a list of vertex elements.
  58. *
  59. * @param[in] desc Description of the object to create.
  60. */
  61. SPtr<VertexDeclaration> createVertexDeclaration(const SPtr<VertexDataDesc>& desc);
  62. /**
  63. * Creates a new GpuParams object from the provided set of GPU parameter descriptors.
  64. *
  65. * @param[in] desc Description of the object to create.
  66. */
  67. SPtr<GpuParams> createGpuParams(const GPU_PARAMS_DESC& desc);
  68. };
  69. /**
  70. * Handles creation of various hardware buffers.
  71. *
  72. * @note Core thread only.
  73. */
  74. class BS_CORE_EXPORT HardwareBufferCoreManager : public Module<HardwareBufferCoreManager>
  75. {
  76. public:
  77. virtual ~HardwareBufferCoreManager() { }
  78. /**
  79. * @copydoc HardwareBufferManager::createVertexBuffer
  80. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  81. */
  82. SPtr<VertexBufferCore> createVertexBuffer(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  83. /**
  84. * @copydoc HardwareBufferManager::createIndexBuffer
  85. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  86. */
  87. SPtr<IndexBufferCore> createIndexBuffer(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  88. /**
  89. * @copydoc HardwareBufferManager::createVertexDeclaration
  90. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  91. */
  92. SPtr<VertexDeclarationCore> createVertexDeclaration(const SPtr<VertexDataDesc>& desc,
  93. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  94. /**
  95. * Creates a new vertex declaration from a list of vertex elements.
  96. *
  97. * @param[in] elements List of elements to initialize the declaration with.
  98. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  99. */
  100. SPtr<VertexDeclarationCore> createVertexDeclaration(const List<VertexElement>& elements,
  101. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  102. /**
  103. * @copydoc HardwareBufferManager::createGpuParamBlockBuffer
  104. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  105. */
  106. SPtr<GpuParamBlockBufferCore> createGpuParamBlockBuffer(UINT32 size,
  107. GpuParamBlockUsage usage = GPBU_DYNAMIC, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  108. /**
  109. * @copydoc HardwareBufferManager::createGpuBuffer
  110. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  111. */
  112. SPtr<GpuBufferCore> createGpuBuffer(const GPU_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  113. /**
  114. * @copydoc HardwareBufferManager::createGpuParams
  115. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  116. */
  117. SPtr<GpuParamsCore> createGpuParams(const GPU_PARAMS_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  118. protected:
  119. friend class IndexBuffer;
  120. friend class IndexBufferCore;
  121. friend class VertexBuffer;
  122. friend class VertexBufferCore;
  123. friend class VertexDeclaration;
  124. friend class GpuParamBlockBuffer;
  125. friend class GpuBuffer;
  126. friend class GpuBufferCore;
  127. /** @copydoc createVertexBuffer */
  128. virtual SPtr<VertexBufferCore> createVertexBufferInternal(const VERTEX_BUFFER_DESC& desc,
  129. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  130. /** @copydoc createIndexBuffer */
  131. virtual SPtr<IndexBufferCore> createIndexBufferInternal(const INDEX_BUFFER_DESC& desc,
  132. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  133. /** @copydoc createGpuParamBlockBuffer */
  134. virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size,
  135. GpuParamBlockUsage usage = GPBU_DYNAMIC, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  136. /** @copydoc createGpuBuffer */
  137. virtual SPtr<GpuBufferCore> createGpuBufferInternal(const GPU_BUFFER_DESC& desc,
  138. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  139. /** @copydoc createVertexDeclaration(const List<VertexElement>&, GpuDeviceFlags) */
  140. virtual SPtr<VertexDeclarationCore> createVertexDeclarationInternal(const List<VertexElement>& elements,
  141. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  142. /** @copydoc createGpuParams */
  143. virtual SPtr<GpuParamsCore> createGpuParamsInternal(const GPU_PARAMS_DESC& desc,
  144. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  145. };
  146. /** @} */
  147. }