BsHardwareBufferManager.h 5.6 KB

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