CmHardwareBufferManager.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "CmVertexBuffer.h"
  5. #include "CmIndexBuffer.h"
  6. #include "CmVertexDeclaration.h"
  7. #include "CmGpuParamBlock.h"
  8. namespace BansheeEngine
  9. {
  10. /** \addtogroup Core
  11. * @{
  12. */
  13. /** \addtogroup RenderSystem
  14. * @{
  15. */
  16. /** Base definition of a hardware buffer manager.
  17. */
  18. class CM_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  19. {
  20. public:
  21. HardwareBufferManager();
  22. virtual ~HardwareBufferManager();
  23. /** Create a hardware vertex buffer.
  24. @remarks
  25. This method creates a new vertex buffer; this will act as a source of geometry
  26. data for rendering objects. Note that because the meaning of the contents of
  27. the vertex buffer depends on the usage, this method does not specify a
  28. vertex format; the user of this buffer can actually insert whatever data
  29. they wish, in any format. However, in order to use this with a RenderOperation,
  30. the data in this vertex buffer will have to be associated with a semantic element
  31. of the rendering pipeline, e.g. a position, or texture coordinates. This is done
  32. using the VertexDeclaration class, which itself contains VertexElement structures
  33. referring to the source data.
  34. @remarks Note that because vertex buffers can be shared, they are reference
  35. counted so you do not need to worry about destroying themm this will be done
  36. automatically.
  37. @param vertexSize The size in bytes of each vertex in this buffer; you must calculate
  38. this based on the kind of data you expect to populate this buffer with.
  39. @param numVerts The number of vertices in this buffer.
  40. @param usage One or more members of the HardwareBuffer::Usage enumeration; you are
  41. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  42. update regularly, consider HBU_DYNAMIC_WRITE_ONLY and useShadowBuffer=true.
  43. @param streamOut Whether the vertex buffer will be used for steam out operations of the
  44. geometry shader.
  45. */
  46. virtual VertexBufferPtr
  47. createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  48. /** Create a hardware index buffer.
  49. @remarks Note that because buffers can be shared, they are reference
  50. counted so you do not need to worry about destroying them this will be done
  51. automatically.
  52. @param itype The type in index, either 16- or 32-bit, depending on how many vertices
  53. you need to be able to address
  54. @param numIndexes The number of indexes in the buffer
  55. @param usage One or more members of the HardwareBuffer::Usage enumeration.
  56. */
  57. virtual IndexBufferPtr
  58. createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  59. /**
  60. * @brief Creates an GPU parameter block that you can use for setting parameters
  61. * for GPU programs.
  62. *
  63. * @return The new GPU parameter block.
  64. */
  65. virtual GpuParamBlockBufferPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  66. /**
  67. * @brief Creates a generic buffer that can be passed as a parameter to a shader.
  68. *
  69. * @param elementCount Number of elements in the buffer.
  70. * @param elementSize Size of each individual element in the buffer, in bytes.
  71. * @param type Type of the buffer.
  72. * @param usage Determines how will the buffer be used.
  73. * @param randomGpuWrite (optional) Allows the GPU to write to the resource.
  74. * @param useCounter (optional) Binds a counter that can be used from a shader to the buffer.
  75. *
  76. * Be aware that some of these settings cannot be used together, and you will receive an assert if in debug mode.
  77. */
  78. virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  79. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  80. /** Creates a new vertex declaration. */
  81. virtual VertexDeclarationPtr createVertexDeclaration(const VertexDeclaration::VertexElementList& elements);
  82. protected:
  83. virtual VertexDeclarationPtr createVertexDeclarationImpl(const VertexDeclaration::VertexElementList& elements);
  84. virtual VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
  85. virtual IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
  86. virtual GpuParamBlockBufferPtr createGpuParamBlockBufferImpl() = 0;
  87. virtual GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage,
  88. bool randomGpuWrite = false, bool useCounter = false) = 0;
  89. };
  90. }