BsD3D11HardwareBuffer.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. D3D11HardwareBuffer(BufferType btype, GpuBufferUsage usage, UINT32 elementCount, UINT32 elementSize,
  36. D3D11Device& device, bool systemMemory = false, bool streamOut = false, bool randomGpuWrite = false,
  37. bool useCounter = false);
  38. ~D3D11HardwareBuffer();
  39. /** @copydoc HardwareBuffer::readData */
  40. void readData(UINT32 offset, UINT32 length, void* dest) override;
  41. /** @copydoc HardwareBuffer::writeData */
  42. void writeData(UINT32 offset, UINT32 length, const void* source,
  43. BufferWriteType writeFlags = BufferWriteType::Normal) override;
  44. /** @copydoc HardwareBuffer::copyData */
  45. void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset,
  46. UINT32 length, bool discardWholeBuffer = false) override;
  47. /** Returns the internal DX11 buffer object. */
  48. ID3D11Buffer* getD3DBuffer() const { return mD3DBuffer; }
  49. protected:
  50. /** @copydoc HardwareBuffer::lockImpl */
  51. void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options) override;
  52. /** @copydoc HardwareBuffer::unlockImpl */
  53. void unlockImpl() override;
  54. BufferType mBufferType;
  55. bool mRandomGpuWrite;
  56. bool mUseCounter;
  57. UINT32 mElementCount;
  58. UINT32 mElementSize;
  59. ID3D11Buffer* mD3DBuffer;
  60. bool mUseTempStagingBuffer;
  61. D3D11HardwareBuffer* mpTempStagingBuffer;
  62. bool mStagingUploadNeeded;
  63. D3D11Device& mDevice;
  64. D3D11_BUFFER_DESC mDesc;
  65. };
  66. /** @} */
  67. }