BsD3D11HardwareBuffer.h 2.9 KB

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