BsD3D11IndexBuffer.cpp 2.1 KB

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