BsD3D11IndexBuffer.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsD3D11IndexBuffer.h"
  5. #include "BsD3D11Device.h"
  6. #include "BsRenderStats.h"
  7. namespace BansheeEngine
  8. {
  9. D3D11IndexBuffer::D3D11IndexBuffer(D3D11Device& device, IndexType idxType, UINT32 numIndexes,
  10. GpuBufferUsage usage, bool useSystemMem)
  11. :IndexBuffer(idxType, numIndexes, usage, useSystemMem), mDevice(device), mBuffer(nullptr)
  12. {
  13. }
  14. D3D11IndexBuffer::~D3D11IndexBuffer()
  15. {
  16. }
  17. void D3D11IndexBuffer::initialize_internal()
  18. {
  19. mBuffer = bs_new<D3D11HardwareBuffer, PoolAlloc>(D3D11HardwareBuffer::BT_INDEX, mUsage, 1, mSizeInBytes, std::ref(mDevice), mSystemMemory);
  20. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
  21. IndexBuffer::initialize_internal();
  22. }
  23. void D3D11IndexBuffer::destroy_internal()
  24. {
  25. if(mBuffer != nullptr)
  26. bs_delete<PoolAlloc>(mBuffer) ;
  27. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
  28. IndexBuffer::destroy_internal();
  29. }
  30. void* D3D11IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
  31. {
  32. #if BS_PROFILING_ENABLED
  33. if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
  34. {
  35. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
  36. }
  37. if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
  38. {
  39. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
  40. }
  41. #endif
  42. return mBuffer->lock(offset, length, options);
  43. }
  44. void D3D11IndexBuffer::unlockImpl()
  45. {
  46. mBuffer->unlock();
  47. }
  48. void D3D11IndexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
  49. {
  50. mBuffer->readData(offset, length, pDest);
  51. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
  52. }
  53. void D3D11IndexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
  54. {
  55. mBuffer->writeData(offset, length, pSource, writeFlags);
  56. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
  57. }
  58. void D3D11IndexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset,
  59. UINT32 dstOffset, UINT32 length, bool discardWholeBuffer)
  60. {
  61. mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
  62. }
  63. }