BsD3D11HardwareBuffer.h 2.9 KB

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