BsHardwareBufferManager.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsModule.h"
  7. #include "BsVertexBuffer.h"
  8. #include "BsIndexBuffer.h"
  9. #include "BsVertexDeclaration.h"
  10. #include "BsGpuParamBlock.h"
  11. namespace BansheeEngine
  12. {
  13. /**
  14. * @brief Handles creation of various hardware buffers.
  15. *
  16. * @note Thread safe.
  17. */
  18. class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  19. {
  20. public:
  21. HardwareBufferManager();
  22. virtual ~HardwareBufferManager();
  23. /**
  24. * @brief Creates a new vertex buffer used for holding number of vertices and other
  25. * per-vertex data. Buffer can be bound to the pipeline and its data can
  26. * be passed to the active vertex GPU program.
  27. *
  28. * @param vertexSize Size of a single vertex in the buffer, in bytes.
  29. * @param numVerts Number of vertices the buffer can hold.
  30. * @param usage Usage that tells the hardware how will be buffer be used.
  31. * @param streamOut If true the buffer will be usable for streaming out data from the GPU.
  32. */
  33. virtual VertexBufferPtr createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  34. /**
  35. * @brief Creates a new index buffer that holds indices referencing vertices in a vertex buffer.
  36. * Indices are interpreted by the pipeline and vertices are drawn in the order specified in
  37. * the index buffer.
  38. *
  39. * @param itype Index type, determines size of an index.
  40. * @param numIndexes Number of indexes can buffer can hold.
  41. * @param usage Usage that tells the hardware how will be buffer be used.
  42. */
  43. virtual IndexBufferPtr createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  44. /**
  45. * @brief Creates an GPU parameter block that you can use for setting parameters for GPU programs.
  46. * Parameter blocks may be used for sharing parameter data between multiple GPU programs, requiring
  47. * you to update only one buffer for all of them, potentially improving performance.
  48. *
  49. * @param size Size of the parameter buffer in bytes.
  50. * @param usage Usage that tells the hardware how will be buffer be used.
  51. */
  52. virtual GpuParamBlockBufferPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  53. /**
  54. * @brief Creates a generic buffer that can be passed as a parameter to a GPU program. This type of buffer can hold
  55. * various type of data and can be used for various purposes. See "GpuBufferType" for explanation of
  56. * different buffer types.
  57. *
  58. * @param elementCount Number of elements in the buffer.
  59. * @param elementSize Size of each individual element in the buffer, in bytes.
  60. * @param type Type of the buffer.
  61. * @param usage Usage that tells the hardware how will be buffer be used.
  62. * @param randomGpuWrite (optional) Allows the GPU to write to the resource.
  63. * @param useCounter (optional) Binds a counter that can be used from a GPU program on the buffer.
  64. *
  65. * @note Be aware that due to some render API restrictions some of these settings cannot be used together,
  66. * and if so you will receive an assert in debug mode.
  67. */
  68. virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  69. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  70. /**
  71. * @brief Creates a new vertex declaration from a list of vertex elements.
  72. */
  73. virtual VertexDeclarationPtr createVertexDeclaration(const VertexDeclaration::VertexElementList& elements);
  74. protected:
  75. /**
  76. * @copydoc createVertexBuffer
  77. */
  78. virtual VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
  79. /**
  80. * @copydoc createIndexBuffer
  81. */
  82. virtual IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
  83. /**
  84. * @copydoc createGpuParamBlockBuffer
  85. */
  86. virtual GpuParamBlockBufferPtr createGpuParamBlockBufferImpl() = 0;
  87. /**
  88. * @copydoc createGpuBuffer
  89. */
  90. virtual GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage,
  91. bool randomGpuWrite = false, bool useCounter = false) = 0;
  92. /**
  93. * @copydoc createVertexDeclaration
  94. */
  95. virtual VertexDeclarationPtr createVertexDeclarationImpl(const VertexDeclaration::VertexElementList& elements);
  96. };
  97. }