BsTransientMesh.cpp 1.9 KB

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