BsD3D11HardwareBuffer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsHardwareBuffer.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Class containing common functionality for all DirectX 11 hardware buffers.
  8. */
  9. class BS_D3D11_EXPORT D3D11HardwareBuffer : public HardwareBuffer
  10. {
  11. public:
  12. /**
  13. * @brief Available types of DX11 buffers
  14. */
  15. enum BufferType
  16. {
  17. BT_VERTEX = 0x1, /**< Contains geometry vertices and their properties. */
  18. BT_INDEX = 0x2, /**< Contains triangle to vertex mapping. */
  19. BT_CONSTANT = 0x4, /**< Contains GPU program parameters. */
  20. BT_GROUP_GENERIC = 0x8, /**< Special value signifying a buffer is of generic type. Not an actual buffer. */
  21. BT_STRUCTURED = BT_GROUP_GENERIC | 0x10, /**< Generic buffer that holds one or more user-defined structures laid out sequentially. */
  22. BT_RAW = BT_GROUP_GENERIC | 0x20, /**< Generic buffer that holds raw block of bytes with no defined structure. */
  23. BT_INDIRECTARGUMENT = BT_GROUP_GENERIC | 0x40, /**< Generic buffer that is used for holding parameters used for indirect rendering. */
  24. BT_APPENDCONSUME = BT_GROUP_GENERIC | 0x80 /**< Generic buffer that allows the GPU program to use append/consume functionality. */
  25. };
  26. /**
  27. * @copydoc HardwareBuffer::HardwareBuffer
  28. */
  29. D3D11HardwareBuffer(BufferType btype, GpuBufferUsage usage, UINT32 elementCount, UINT32 elementSize,
  30. D3D11Device& device, bool useSystemMem = false, bool streamOut = false, bool randomGpuWrite = false, bool useCounter = false);
  31. ~D3D11HardwareBuffer();
  32. /**
  33. * @copydoc HardwareBuffer::readData
  34. */
  35. void readData(UINT32 offset, UINT32 length, void* pDest) override;
  36. /**
  37. * @copydoc HardwareBuffer::writeData
  38. */
  39. void writeData(UINT32 offset, UINT32 length, const void* pSource,
  40. BufferWriteType writeFlags = BufferWriteType::Normal) override;
  41. /**
  42. * @copydoc HardwareBuffer::copyData
  43. */
  44. void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset,
  45. UINT32 length, bool discardWholeBuffer = false) override;
  46. /**
  47. * @brief Returns the internal DX11 buffer object.
  48. */
  49. ID3D11Buffer* getD3DBuffer() { return mD3DBuffer; }
  50. protected:
  51. /**
  52. * @copydoc HardwareBuffer::lockImpl
  53. */
  54. void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options) override;
  55. /**
  56. * @copydoc HardwareBuffer::unlockImpl
  57. */
  58. void unlockImpl() override;
  59. BufferType mBufferType;
  60. bool mRandomGpuWrite;
  61. bool mUseCounter;
  62. UINT32 mElementCount;
  63. UINT32 mElementSize;
  64. ID3D11Buffer* mD3DBuffer;
  65. bool mUseTempStagingBuffer;
  66. D3D11HardwareBuffer* mpTempStagingBuffer;
  67. bool mStagingUploadNeeded;
  68. D3D11Device& mDevice;
  69. D3D11_BUFFER_DESC mDesc;
  70. };
  71. }