| 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/BsMeshBase.h" |
| 4 | #include "Private/RTTI/BsMeshBaseRTTI.h" |
| 5 | #include "CoreThread/BsCoreThread.h" |
| 6 | |
| 7 | namespace bs |
| 8 | { |
| 9 | MeshProperties::MeshProperties() |
| 10 | :mNumVertices(0), mNumIndices(0) |
| 11 | { |
| 12 | mSubMeshes.reserve(10); |
| 13 | } |
| 14 | |
| 15 | MeshProperties::MeshProperties(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp) |
| 16 | :mNumVertices(numVertices), mNumIndices(numIndices) |
| 17 | { |
| 18 | mSubMeshes.push_back(SubMesh(0, numIndices, drawOp)); |
| 19 | } |
| 20 | |
| 21 | MeshProperties::MeshProperties(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes) |
| 22 | :mNumVertices(numVertices), mNumIndices(numIndices) |
| 23 | { |
| 24 | mSubMeshes = subMeshes; |
| 25 | } |
| 26 | |
| 27 | const SubMesh& MeshProperties::getSubMesh(UINT32 subMeshIdx) const |
| 28 | { |
| 29 | if (subMeshIdx >= mSubMeshes.size()) |
| 30 | { |
| 31 | BS_EXCEPT(InvalidParametersException, "Invalid sub-mesh index (" |
| 32 | + toString(subMeshIdx) + "). Number of sub-meshes available: " + toString((int)mSubMeshes.size())); |
| 33 | } |
| 34 | |
| 35 | return mSubMeshes[subMeshIdx]; |
| 36 | } |
| 37 | |
| 38 | UINT32 MeshProperties::getNumSubMeshes() const |
| 39 | { |
| 40 | return (UINT32)mSubMeshes.size(); |
| 41 | } |
| 42 | |
| 43 | MeshBase::MeshBase(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp) |
| 44 | :mProperties(numVertices, numIndices, drawOp) |
| 45 | { } |
| 46 | |
| 47 | MeshBase::MeshBase(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes) |
| 48 | :mProperties(numVertices, numIndices, subMeshes) |
| 49 | { } |
| 50 | |
| 51 | MeshBase::~MeshBase() |
| 52 | { } |
| 53 | |
| 54 | CoreSyncData MeshBase::syncToCore(FrameAlloc* allocator) |
| 55 | { |
| 56 | UINT32 size = sizeof(Bounds); |
| 57 | UINT8* buffer = allocator->alloc(size); |
| 58 | |
| 59 | memcpy(buffer, &mProperties.mBounds, size); |
| 60 | return CoreSyncData(buffer, size); |
| 61 | } |
| 62 | |
| 63 | SPtr<ct::MeshBase> MeshBase::getCore() const |
| 64 | { |
| 65 | return std::static_pointer_cast<ct::MeshBase>(mCoreSpecific); |
| 66 | } |
| 67 | |
| 68 | /************************************************************************/ |
| 69 | /* SERIALIZATION */ |
| 70 | /************************************************************************/ |
| 71 | |
| 72 | RTTITypeBase* MeshBase::getRTTIStatic() |
| 73 | { |
| 74 | return MeshBaseRTTI::instance(); |
| 75 | } |
| 76 | |
| 77 | RTTITypeBase* MeshBase::getRTTI() const |
| 78 | { |
| 79 | return MeshBase::getRTTIStatic(); |
| 80 | } |
| 81 | |
| 82 | namespace ct |
| 83 | { |
| 84 | MeshBase::MeshBase(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes) |
| 85 | :mProperties(numVertices, numIndices, subMeshes) |
| 86 | { } |
| 87 | |
| 88 | void MeshBase::syncToCore(const CoreSyncData& data) |
| 89 | { |
| 90 | mProperties.mBounds = data.getData<Bounds>(); |
| 91 | } |
| 92 | } |
| 93 | } |