BsD3D11IndexBuffer.cpp 2.1 KB

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