BsD3D11IndexBuffer.cpp 2.5 KB

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