BsHardwareBufferManager.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsVertexBuffer.h"
  5. #include "BsIndexBuffer.h"
  6. #include "BsVertexDeclaration.h"
  7. namespace BansheeEngine
  8. {
  9. /** @cond INTERNAL */
  10. /** @addtogroup RenderAPI
  11. * @{
  12. */
  13. /**
  14. * Handles creation of various hardware buffers.
  15. *
  16. * @note Sim thread only.
  17. */
  18. class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  19. {
  20. public:
  21. HardwareBufferManager();
  22. virtual ~HardwareBufferManager();
  23. /**
  24. * Creates a new vertex buffer used for holding number of vertices and other per-vertex data. Buffer can be bound
  25. * to the pipeline and its data can be passed to the active vertex GPU program.
  26. *
  27. * @param[in] vertexSize Size of a single vertex in the buffer, in bytes.
  28. * @param[in] numVerts Number of vertices the buffer can hold.
  29. * @param[in] usage Usage that tells the hardware how will be buffer be used.
  30. * @param[in] streamOut If true the buffer will be usable for streaming out data from the GPU.
  31. */
  32. virtual VertexBufferPtr createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  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] itype Index type, determines size of an index.
  38. * @param[in] numIndexes Number of indexes can buffer can hold.
  39. * @param[in] usage Usage that tells the hardware how will be buffer be used.
  40. */
  41. virtual IndexBufferPtr createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  42. /**
  43. * Creates an GPU parameter block that you can use for setting parameters for GPU programs. Parameter blocks may be
  44. * used for sharing parameter data between multiple GPU programs, requiring you to update only one buffer for all of
  45. * them, potentially improving performance.
  46. *
  47. * @param[in] size Size of the parameter buffer in bytes.
  48. * @param[in] usage Usage that tells the hardware how will be buffer be used.
  49. */
  50. virtual GpuParamBlockBufferPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  51. /**
  52. * Creates a generic buffer that can be passed as a parameter to a GPU program. This type of buffer can hold various
  53. * type of data and can be used for various purposes. See "GpuBufferType" for explanation of different buffer types.
  54. *
  55. * @param[in] elementCount Number of elements in the buffer.
  56. * @param[in] elementSize Size of each individual element in the buffer, in bytes.
  57. * @param[in] type Type of the buffer.
  58. * @param[in] usage Usage that tells the hardware how will be buffer be used.
  59. * @param[in] randomGpuWrite (optional) Allows the GPU to write to the resource.
  60. * @param[in] useCounter (optional) Binds a counter that can be used from a GPU program on the buffer.
  61. *
  62. * @note
  63. * Be aware that due to some render API restrictions some of these settings cannot be used together, and if so you
  64. * will receive an assert in debug mode.
  65. */
  66. virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  67. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  68. /** Creates a new vertex declaration from a list of vertex elements. */
  69. virtual VertexDeclarationPtr createVertexDeclaration(const List<VertexElement>& elements);
  70. };
  71. /**
  72. * Handles creation of various hardware buffers.
  73. *
  74. * @note Core thread only.
  75. */
  76. class BS_CORE_EXPORT HardwareBufferCoreManager : public Module<HardwareBufferCoreManager>
  77. {
  78. public:
  79. virtual ~HardwareBufferCoreManager() { }
  80. /** @copydoc HardwareBufferManager::createVertexBuffer */
  81. virtual SPtr<VertexBufferCore> createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  82. /** @copydoc HardwareBufferManager::createIndexBuffer */
  83. virtual SPtr<IndexBufferCore> createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  84. /** @copydoc HardwareBufferManager::createVertexDeclaration */
  85. virtual SPtr<VertexDeclarationCore> createVertexDeclaration(const List<VertexElement>& elements);
  86. /** @copydoc HardwareBufferManager::createGpuParamBlockBuffer */
  87. virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  88. /** @copydoc HardwareBufferManager::createGpuBuffer */
  89. virtual SPtr<GpuBufferCore> createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  90. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  91. protected:
  92. friend class IndexBuffer;
  93. friend class VertexBuffer;
  94. friend class VertexDeclaration;
  95. friend class GpuParamBlockBuffer;
  96. friend class GpuBuffer;
  97. /** @copydoc createVertexBuffer */
  98. virtual SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
  99. /** @copydoc createIndexBuffer */
  100. virtual SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
  101. /** @copydoc createGpuParamBlockBuffer */
  102. virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC) = 0;
  103. /** @copydoc createGpuBuffer */
  104. virtual SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
  105. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) = 0;
  106. /** @copydoc createVertexDeclaration */
  107. virtual SPtr<VertexDeclarationCore> createVertexDeclarationInternal(const List<VertexElement>& elements);
  108. };
  109. /** @} */
  110. /** @endcond */
  111. }