RenderInstances.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Renderer/Renderer.h>
  6. #include <Jolt/Core/Reference.h>
  7. class RenderPrimitive;
  8. /// Buffer that holds a list of instances (usually model transform etc.) for instance based rendering
  9. class RenderInstances : public RefTarget<RenderInstances>
  10. {
  11. public:
  12. /// Constructor
  13. RenderInstances(Renderer *inRenderer) : mRenderer(inRenderer) { }
  14. ~RenderInstances() { Clear(); }
  15. /// Erase all instance data
  16. void Clear();
  17. /// Instance buffer management functions
  18. void CreateBuffer(int inNumInstances, int inInstanceSize);
  19. void * Lock();
  20. void Unlock();
  21. /// Draw the instances when context has been set by Renderer::BindShader
  22. void Draw(RenderPrimitive *inPrimitive, int inStartInstance, int inNumInstances) const;
  23. private:
  24. Renderer * mRenderer;
  25. ComPtr<ID3D12Resource> mInstanceBuffer;
  26. int mInstanceBufferSize = 0;
  27. int mInstanceSize = 0;
  28. };