BsTransientMesh.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsTransientMesh.h"
  5. #include "BsVertexData.h"
  6. #include "BsBounds.h"
  7. #include "BsMeshHeap.h"
  8. namespace BansheeEngine
  9. {
  10. TransientMesh::TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp)
  11. :MeshBase(numVertices, numIndices, drawOp), mParentHeap(parentHeap), mId(id), mIsDestroyed(false)
  12. {
  13. }
  14. TransientMesh::~TransientMesh()
  15. {
  16. if (!mIsDestroyed)
  17. {
  18. TransientMeshPtr meshPtr = std::static_pointer_cast<TransientMesh>(getThisPtr());
  19. mParentHeap->dealloc(meshPtr);
  20. }
  21. }
  22. void TransientMesh::writeSubresource(UINT32 subresourceIdx, const GpuResourceData& data, bool discardEntireBuffer)
  23. {
  24. BS_EXCEPT(InvalidStateException, "Updating is not supported on a transient mesh.");
  25. }
  26. void TransientMesh::readSubresource(UINT32 subresourceIdx, GpuResourceData& data)
  27. {
  28. BS_EXCEPT(InvalidStateException, "Reading is not supported on a transient mesh.");
  29. }
  30. std::shared_ptr<VertexData> TransientMesh::_getVertexData() const
  31. {
  32. return mParentHeap->_getVertexData();
  33. }
  34. IndexBufferPtr TransientMesh::_getIndexBuffer() const
  35. {
  36. return mParentHeap->_getIndexBuffer();
  37. }
  38. UINT32 TransientMesh::_getVertexOffset() const
  39. {
  40. return mParentHeap->getVertexOffset(mId);
  41. }
  42. UINT32 TransientMesh::_getIndexOffset() const
  43. {
  44. return mParentHeap->getIndexOffset(mId);
  45. }
  46. void TransientMesh::_notifyUsedOnGPU()
  47. {
  48. mParentHeap->notifyUsedOnGPU(mId);
  49. }
  50. MeshProxyPtr TransientMesh::_createProxy(UINT32 subMeshIdx)
  51. {
  52. MeshProxyPtr coreProxy = bs_shared_ptr<MeshProxy>();
  53. coreProxy->mesh = std::static_pointer_cast<MeshBase>(getThisPtr());
  54. coreProxy->subMesh = mSubMeshes[0];
  55. coreProxy->submeshIdx = subMeshIdx;
  56. // Note: Not calculating bounds for transient meshes yet
  57. // (No particular reason, I just didn't bother)
  58. coreProxy->bounds = Bounds();
  59. return coreProxy;
  60. }
  61. }