BsHardwareBufferManager.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /**
  10. * @brief Handles creation of various hardware buffers.
  11. *
  12. * @note Sim thread only.
  13. */
  14. class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  15. {
  16. public:
  17. HardwareBufferManager();
  18. virtual ~HardwareBufferManager();
  19. /**
  20. * @brief Creates a new vertex buffer used for holding number of vertices and other
  21. * per-vertex data. Buffer can be bound to the pipeline and its data can
  22. * be passed to the active vertex GPU program.
  23. *
  24. * @param vertexSize Size of a single vertex in the buffer, in bytes.
  25. * @param numVerts Number of vertices the buffer can hold.
  26. * @param usage Usage that tells the hardware how will be buffer be used.
  27. * @param streamOut If true the buffer will be usable for streaming out data from the GPU.
  28. */
  29. virtual VertexBufferPtr createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  30. /**
  31. * @brief Creates a new index buffer that holds indices referencing vertices in a vertex buffer.
  32. * Indices are interpreted by the pipeline and vertices are drawn in the order specified in
  33. * the index buffer.
  34. *
  35. * @param itype Index type, determines size of an index.
  36. * @param numIndexes Number of indexes can buffer can hold.
  37. * @param usage Usage that tells the hardware how will be buffer be used.
  38. */
  39. virtual IndexBufferPtr createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  40. /**
  41. * @brief Creates an GPU parameter block that you can use for setting parameters for GPU programs.
  42. * Parameter blocks may be used for sharing parameter data between multiple GPU programs, requiring
  43. * you to update only one buffer for all of them, potentially improving performance.
  44. *
  45. * @param size Size of the parameter buffer in bytes.
  46. * @param usage Usage that tells the hardware how will be buffer be used.
  47. */
  48. virtual GpuParamBlockBufferPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  49. /**
  50. * @brief Creates a generic buffer that can be passed as a parameter to a GPU program. This type of buffer can hold
  51. * various type of data and can be used for various purposes. See "GpuBufferType" for explanation of
  52. * different buffer types.
  53. *
  54. * @param elementCount Number of elements in the buffer.
  55. * @param elementSize Size of each individual element in the buffer, in bytes.
  56. * @param type Type of the buffer.
  57. * @param usage Usage that tells the hardware how will be buffer be used.
  58. * @param randomGpuWrite (optional) Allows the GPU to write to the resource.
  59. * @param useCounter (optional) Binds a counter that can be used from a GPU program on the buffer.
  60. *
  61. * @note Be aware that due to some render API restrictions some of these settings cannot be used together,
  62. * and if so you will receive an assert in debug mode.
  63. */
  64. virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  65. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  66. /**
  67. * @brief Creates a new vertex declaration from a list of vertex elements.
  68. */
  69. virtual VertexDeclarationPtr createVertexDeclaration(const List<VertexElement>& elements);
  70. };
  71. /**
  72. * @brief 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. /**
  81. * @copydoc HardwareBufferManager::createVertexBuffer
  82. */
  83. virtual SPtr<VertexBufferCore> createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  84. /**
  85. * @copydoc HardwareBufferManager::createIndexBuffer
  86. */
  87. virtual SPtr<IndexBufferCore> createIndexBuffer(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  88. /**
  89. * @copydoc HardwareBufferManager::createVertexDeclaration
  90. */
  91. virtual SPtr<VertexDeclarationCore> createVertexDeclaration(const List<VertexElement>& elements);
  92. /**
  93. * @copydoc HardwareBufferManager::createGpuParamBlockBuffer
  94. */
  95. virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  96. /**
  97. * @copydoc HardwareBufferManager::createGpuBuffer
  98. */
  99. virtual SPtr<GpuBufferCore> createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  100. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  101. protected:
  102. friend class IndexBuffer;
  103. friend class VertexBuffer;
  104. friend class VertexDeclaration;
  105. friend class GpuParamBlockBuffer;
  106. friend class GpuBuffer;
  107. /**
  108. * @copydoc createVertexBuffer
  109. */
  110. virtual SPtr<VertexBufferCore> createVertexBufferInternal(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
  111. /**
  112. * @copydoc createIndexBuffer
  113. */
  114. virtual SPtr<IndexBufferCore> createIndexBufferInternal(IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
  115. /**
  116. * @copydoc createGpuParamBlockBuffer
  117. */
  118. virtual SPtr<GpuParamBlockBufferCore> createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC) = 0;
  119. /**
  120. * @copydoc createGpuBuffer
  121. */
  122. virtual SPtr<GpuBufferCore> createGpuBufferInternal(UINT32 elementCount, UINT32 elementSize,
  123. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) = 0;
  124. /**
  125. * @copydoc createVertexDeclaration
  126. */
  127. virtual SPtr<VertexDeclarationCore> createVertexDeclarationInternal(const List<VertexElement>& elements);
  128. };
  129. }