2
0

ConstantBuffer.h 762 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. class Renderer;
  5. /// A binary blob that can be used to pass constants to a shader
  6. class ConstantBuffer
  7. {
  8. public:
  9. /// Constructor
  10. ConstantBuffer(Renderer *inRenderer, uint64 inBufferSize);
  11. ~ConstantBuffer();
  12. /// Map / unmap buffer (get pointer to data). This will discard all data in the buffer.
  13. template <typename T> T * Map() { return reinterpret_cast<T *>(MapInternal()); }
  14. void Unmap();
  15. // Bind the constant buffer to a slot
  16. void Bind(int inSlot);
  17. private:
  18. friend class Renderer;
  19. void * MapInternal();
  20. Renderer * mRenderer;
  21. ComPtr<ID3D12Resource> mBuffer;
  22. uint64 mBufferSize;
  23. };