BsD3D11VertexBuffer.cpp 2.5 KB

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