3
0

DynamicBuffer.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RPI.Public/DynamicDraw/DynamicBufferAllocator.h>
  9. #include <Atom/RPI.Public/DynamicDraw/DynamicBuffer.h>
  10. namespace AZ
  11. {
  12. namespace RPI
  13. {
  14. bool DynamicBuffer::Write(const void* data, uint32_t size)
  15. {
  16. if (m_size >= size)
  17. {
  18. for(auto& [deviceIndex, address] : m_address)
  19. {
  20. memcpy(address, data, size);
  21. }
  22. return true;
  23. }
  24. AZ_Assert(false, "Can't write data out of range");
  25. return false;
  26. }
  27. uint32_t DynamicBuffer::GetSize()
  28. {
  29. return m_size;
  30. }
  31. const AZStd::unordered_map<int, void*>& DynamicBuffer::GetBufferAddress()
  32. {
  33. return m_address;
  34. }
  35. RHI::IndexBufferView DynamicBuffer::GetIndexBufferView(RHI::IndexFormat format)
  36. {
  37. return m_allocator->GetIndexBufferView(this, format);
  38. }
  39. RHI::StreamBufferView DynamicBuffer::GetStreamBufferView(uint32_t strideByteCount)
  40. {
  41. return m_allocator->GetStreamBufferView(this, strideByteCount);
  42. }
  43. void DynamicBuffer::Initialize(const AZStd::unordered_map<int, void*>& address, uint32_t size)
  44. {
  45. m_address = address;
  46. m_size = size;
  47. }
  48. }
  49. }