BsTransientMesh.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Mesh/BsTransientMesh.h"
  4. #include "RenderAPI/BsVertexData.h"
  5. #include "Math/BsBounds.h"
  6. #include "Mesh/BsMeshHeap.h"
  7. #include "Allocators/BsFrameAlloc.h"
  8. namespace bs
  9. {
  10. TransientMesh::TransientMesh(const SPtr<MeshHeap>& parentHeap, UINT32 id, UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp)
  11. :MeshBase(numVertices, numIndices, drawOp), mIsDestroyed(false), mParentHeap(parentHeap), mId(id)
  12. {
  13. }
  14. TransientMesh::~TransientMesh()
  15. {
  16. if (!mIsDestroyed)
  17. {
  18. SPtr<TransientMesh> meshPtr = std::static_pointer_cast<TransientMesh>(getThisPtr());
  19. mParentHeap->dealloc(meshPtr);
  20. }
  21. }
  22. SPtr<ct::TransientMesh> TransientMesh::getCore() const
  23. {
  24. return std::static_pointer_cast<ct::TransientMesh>(mCoreSpecific);
  25. }
  26. SPtr<ct::CoreObject> TransientMesh::createCore() const
  27. {
  28. ct::TransientMesh* core = new (bs_alloc<ct::TransientMesh>()) ct::TransientMesh(
  29. mParentHeap->getCore(), mId, mProperties.mNumVertices, mProperties.mNumIndices, mProperties.mSubMeshes);
  30. SPtr<ct::CoreObject> meshCore = bs_shared_ptr<ct::TransientMesh>(core);
  31. meshCore->_setThisPtr(meshCore);
  32. return meshCore;
  33. }
  34. namespace ct
  35. {
  36. TransientMesh::TransientMesh(const SPtr<MeshHeap>& parentHeap, UINT32 id,
  37. UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes)
  38. :MeshBase(numVertices, numIndices, subMeshes), mParentHeap(parentHeap), mId(id)
  39. {
  40. }
  41. SPtr<VertexData> TransientMesh::getVertexData() const
  42. {
  43. return mParentHeap->getVertexData();
  44. }
  45. SPtr<IndexBuffer> TransientMesh::getIndexBuffer() const
  46. {
  47. return mParentHeap->getIndexBuffer();
  48. }
  49. UINT32 TransientMesh::getVertexOffset() const
  50. {
  51. return mParentHeap->getVertexOffset(mId);
  52. }
  53. UINT32 TransientMesh::getIndexOffset() const
  54. {
  55. return mParentHeap->getIndexOffset(mId);
  56. }
  57. SPtr<VertexDataDesc> TransientMesh::getVertexDesc() const
  58. {
  59. return mParentHeap->getVertexDesc();
  60. }
  61. void TransientMesh::_notifyUsedOnGPU()
  62. {
  63. mParentHeap->notifyUsedOnGPU(mId);
  64. }
  65. }
  66. }