BsHardwareBufferManager.h 6.7 KB

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