DXBuffer.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #include "OperatingSystem.h"
  3. #include "ReferenceCounter.h"
  4. #ifdef WIN32
  5. struct ID3D11Buffer;
  6. struct D3D11_BUFFER_DESC;
  7. struct ID3D11ShaderResourceView;
  8. struct ID3D11Device;
  9. struct ID3D11DeviceContext;
  10. #endif
  11. namespace Framework
  12. {
  13. class DX12CopyCommandQueue;
  14. class DX12DirectCommandQueue;
  15. //! An interface between main memory and graphics memory
  16. class DXBuffer : public virtual ReferenceCounter
  17. {
  18. protected:
  19. void* data;
  20. bool changed;
  21. int len;
  22. int elLen;
  23. public:
  24. //! Constructor
  25. //! \param bind The usage of the buffer. Example:
  26. //! D3D11_BIND_INDEX_BUFFER, D3D11_BIND_VERTEX_BUFFER. \param eLen
  27. //! Length of a single element in bytes
  28. DLLEXPORT DXBuffer(int eLen);
  29. //! Destructor
  30. DLLEXPORT virtual ~DXBuffer();
  31. //! Sets the changed flag so that the data is copied again on the
  32. //! next call of 'copy'
  33. DLLEXPORT void setChanged();
  34. //! Changes the length of the buffer on the next call of 'copy'
  35. //! \param len The length in bytes
  36. DLLEXPORT void setLength(int len);
  37. //! Sets what will be copied on the next call of 'copy'
  38. //! \param data A pointer to the data
  39. DLLEXPORT void setData(void* data);
  40. //! Copies the data into the buffer if it has changed
  41. DLLEXPORT virtual void copyData(int byteCount = -1) = 0;
  42. //! Returns the length of an element in bytes
  43. DLLEXPORT int getElementLength() const;
  44. //! Returns the number of elements in the buffer
  45. DLLEXPORT int getElementCount() const;
  46. };
  47. #ifdef WIN32
  48. //! A buffer with data in graphics memory
  49. class DX11Buffer : public DXBuffer
  50. {
  51. protected:
  52. D3D11_BUFFER_DESC* description;
  53. ID3D11Buffer* buffer;
  54. ID3D11Device* device;
  55. ID3D11DeviceContext* context;
  56. public:
  57. //! Constructor
  58. //! eSize: The length of an element in bytes
  59. DLLEXPORT DX11Buffer(int eSize,
  60. ID3D11Device* device,
  61. ID3D11DeviceContext* context,
  62. int bindFlags);
  63. //! Destructor
  64. DLLEXPORT virtual ~DX11Buffer();
  65. //! Copies the data into the buffer if it has changed
  66. DLLEXPORT virtual void copyData(int byteCount = -1) override;
  67. //! Returns the buffer
  68. DLLEXPORT ID3D11Buffer* zBuffer() const;
  69. };
  70. //! A buffer of indices from the vertex buffer, where every three
  71. //! form a triangle that is drawn
  72. class DX11StructuredBuffer : public DX11Buffer
  73. {
  74. private:
  75. ID3D11ShaderResourceView* view;
  76. public:
  77. //! Constructor
  78. //! eSize: The length of an element in bytes
  79. DLLEXPORT DX11StructuredBuffer(
  80. int eSize, ID3D11Device* device, ID3D11DeviceContext* context);
  81. //! Destructor
  82. DLLEXPORT virtual ~DX11StructuredBuffer();
  83. //! Copies the data into the buffer if it has changed
  84. DLLEXPORT void copyData(int byteCount = -1) override;
  85. //! Returns the used shader resource view
  86. DLLEXPORT operator ID3D11ShaderResourceView*() const;
  87. };
  88. #endif
  89. } // namespace Framework