BsHardwareBufferManager.h 4.9 KB

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