BsHardwareBufferManager.h 6.7 KB

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