BsD3D11IndexBuffer.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "BsRenderStats.h"
  6. namespace BansheeEngine
  7. {
  8. D3D11IndexBufferCore::D3D11IndexBufferCore(D3D11Device& device, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
  9. :IndexBufferCore(idxType, numIndexes, usage), mDevice(device), mBuffer(nullptr)
  10. {
  11. }
  12. D3D11IndexBufferCore::~D3D11IndexBufferCore()
  13. {
  14. if (mBuffer != nullptr)
  15. bs_delete(mBuffer);
  16. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
  17. }
  18. void D3D11IndexBufferCore::initialize()
  19. {
  20. mBuffer = bs_new<D3D11HardwareBuffer>(D3D11HardwareBuffer::BT_INDEX, mUsage, 1, mSizeInBytes, std::ref(mDevice), mSystemMemory);
  21. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
  22. IndexBufferCore::initialize();
  23. }
  24. void* D3D11IndexBufferCore::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
  25. {
  26. #if BS_PROFILING_ENABLED
  27. if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
  28. {
  29. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
  30. }
  31. if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
  32. {
  33. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
  34. }
  35. #endif
  36. return mBuffer->lock(offset, length, options);
  37. }
  38. void D3D11IndexBufferCore::unlockImpl()
  39. {
  40. mBuffer->unlock();
  41. }
  42. void D3D11IndexBufferCore::readData(UINT32 offset, UINT32 length, void* pDest)
  43. {
  44. mBuffer->readData(offset, length, pDest);
  45. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
  46. }
  47. void D3D11IndexBufferCore::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
  48. {
  49. mBuffer->writeData(offset, length, pSource, writeFlags);
  50. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
  51. }
  52. void D3D11IndexBufferCore::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset,
  53. UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
  54. {
  55. mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
  56. }
  57. }