BsHardwareBufferManager.h 5.9 KB

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