ConstantBuffer.h 826 B

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