BsD3D11VertexBuffer.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsD3D11VertexBuffer.h"
  4. #include "BsD3D11Device.h"
  5. #include "Profiling/BsRenderStats.h"
  6. namespace bs { namespace ct
  7. {
  8. D3D11VertexBuffer::D3D11VertexBuffer(D3D11Device& device, const VERTEX_BUFFER_DESC& desc,
  9. GpuDeviceFlags deviceMask)
  10. : VertexBuffer(desc, deviceMask), mBuffer(nullptr), mDevice(device), mStreamOut(desc.streamOut)
  11. , mUsage(desc.usage)
  12. {
  13. assert((deviceMask == GDF_DEFAULT || deviceMask == GDF_PRIMARY) && "Multiple GPUs not supported natively on DirectX 11.");
  14. }
  15. D3D11VertexBuffer::~D3D11VertexBuffer()
  16. {
  17. if (mBuffer != nullptr)
  18. bs_delete(mBuffer);
  19. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_VertexBuffer);
  20. }
  21. void* D3D11VertexBuffer::map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 deviceIdx, UINT32 queueIdx)
  22. {
  23. #if BS_PROFILING_ENABLED
  24. if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
  25. {
  26. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_VertexBuffer);
  27. }
  28. if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
  29. {
  30. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_VertexBuffer);
  31. }
  32. #endif
  33. return mBuffer->lock(offset, length, options);
  34. }
  35. void D3D11VertexBuffer::unmap()
  36. {
  37. mBuffer->unlock();
  38. }
  39. void D3D11VertexBuffer::readData(UINT32 offset, UINT32 length, void* dest, UINT32 deviceIdx, UINT32 queueIdx)
  40. {
  41. mBuffer->readData(offset, length, dest);
  42. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_VertexBuffer);
  43. }
  44. void D3D11VertexBuffer::writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags,
  45. UINT32 queueIdx)
  46. {
  47. mBuffer->writeData(offset, length, source, writeFlags);
  48. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_VertexBuffer);
  49. }
  50. void D3D11VertexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset,
  51. UINT32 dstOffset, UINT32 length, bool discardWholeBuffer, const SPtr<CommandBuffer>& commandBuffer)
  52. {
  53. mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer, commandBuffer);
  54. }
  55. void D3D11VertexBuffer::initialize()
  56. {
  57. mBuffer = bs_new<D3D11HardwareBuffer>(D3D11HardwareBuffer::BT_VERTEX,
  58. mUsage, 1, mSize, std::ref(mDevice), false, mStreamOut);
  59. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_VertexBuffer);
  60. VertexBuffer::initialize();
  61. }
  62. }}