| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "Mesh/BsTransientMesh.h" |
| 4 | #include "RenderAPI/BsVertexData.h" |
| 5 | #include "Math/BsBounds.h" |
| 6 | #include "Mesh/BsMeshHeap.h" |
| 7 | |
| 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 | } |
| 15 | |
| 16 | TransientMesh::~TransientMesh() |
| 17 | { |
| 18 | if (!mIsDestroyed) |
| 19 | { |
| 20 | SPtr<TransientMesh> meshPtr = std::static_pointer_cast<TransientMesh>(getThisPtr()); |
| 21 | mParentHeap->dealloc(meshPtr); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | SPtr<ct::TransientMesh> TransientMesh::getCore() const |
| 26 | { |
| 27 | return std::static_pointer_cast<ct::TransientMesh>(mCoreSpecific); |
| 28 | } |
| 29 | |
| 30 | SPtr<ct::CoreObject> TransientMesh::createCore() const |
| 31 | { |
| 32 | ct::TransientMesh* core = new (bs_alloc<ct::TransientMesh>()) ct::TransientMesh( |
| 33 | mParentHeap->getCore(), mId, mProperties.mNumVertices, mProperties.mNumIndices, mProperties.mSubMeshes); |
| 34 | |
| 35 | SPtr<ct::CoreObject> meshCore = bs_shared_ptr<ct::TransientMesh>(core); |
| 36 | meshCore->_setThisPtr(meshCore); |
| 37 | |
| 38 | return meshCore; |
| 39 | } |
| 40 | |
| 41 | namespace ct |
| 42 | { |
| 43 | TransientMesh::TransientMesh(const SPtr<MeshHeap>& parentHeap, UINT32 id, |
| 44 | UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes) |
| 45 | :MeshBase(numVertices, numIndices, subMeshes), mParentHeap(parentHeap), mId(id) |
| 46 | { |
| 47 | |
| 48 | } |
| 49 | |
| 50 | SPtr<VertexData> TransientMesh::getVertexData() const |
| 51 | { |
| 52 | return mParentHeap->getVertexData(); |
| 53 | } |
| 54 | |
| 55 | SPtr<IndexBuffer> TransientMesh::getIndexBuffer() const |
| 56 | { |
| 57 | return mParentHeap->getIndexBuffer(); |
| 58 | } |
| 59 | |
| 60 | UINT32 TransientMesh::getVertexOffset() const |
| 61 | { |
| 62 | return mParentHeap->getVertexOffset(mId); |
| 63 | } |
| 64 | |
| 65 | UINT32 TransientMesh::getIndexOffset() const |
| 66 | { |
| 67 | return mParentHeap->getIndexOffset(mId); |
| 68 | } |
| 69 | |
| 70 | SPtr<VertexDataDesc> TransientMesh::getVertexDesc() const |
| 71 | { |
| 72 | return mParentHeap->getVertexDesc(); |
| 73 | } |
| 74 | |
| 75 | void TransientMesh::_notifyUsedOnGPU() |
| 76 | { |
| 77 | mParentHeap->notifyUsedOnGPU(mId); |
| 78 | } |
| 79 | } |
| 80 | } |