BsHardwareBufferManager.h 7.0 KB

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