DXBuffer.h 3.2 KB

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