BsMesh.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsMesh.h"
  4. #include "BsMeshRTTI.h"
  5. #include "BsMeshData.h"
  6. #include "BsDebug.h"
  7. #include "BsHardwareBufferManager.h"
  8. #include "BsMeshManager.h"
  9. #include "BsCoreThread.h"
  10. #include "BsAsyncOp.h"
  11. #include "BsVertexDataDesc.h"
  12. #include "BsResources.h"
  13. #include "BsRenderAPI.h"
  14. namespace BansheeEngine
  15. {
  16. MeshCore::MeshCore(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  17. const Vector<SubMesh>& subMeshes, int usage, IndexType indexType, const SPtr<Skeleton>& skeleton,
  18. const SPtr<MeshData>& initialMeshData)
  19. : MeshCoreBase(numVertices, numIndices, subMeshes), mVertexData(nullptr), mIndexBuffer(nullptr)
  20. , mVertexDesc(vertexDesc), mUsage(usage), mIndexType(indexType), mSkeleton(skeleton)
  21. , mTempInitialMeshData(initialMeshData)
  22. { }
  23. MeshCore::~MeshCore()
  24. {
  25. THROW_IF_NOT_CORE_THREAD;
  26. mVertexData = nullptr;
  27. mIndexBuffer = nullptr;
  28. mVertexDesc = nullptr;
  29. mTempInitialMeshData = nullptr;
  30. }
  31. void MeshCore::initialize()
  32. {
  33. THROW_IF_NOT_CORE_THREAD;
  34. bool isDynamic = (mUsage & MU_DYNAMIC) != 0;
  35. mIndexBuffer = HardwareBufferCoreManager::instance().createIndexBuffer(mIndexType,
  36. mProperties.mNumIndices, isDynamic ? GBU_DYNAMIC : GBU_STATIC);
  37. mVertexData = SPtr<VertexData>(bs_new<VertexData>());
  38. mVertexData->vertexCount = mProperties.mNumVertices;
  39. mVertexData->vertexDeclaration = HardwareBufferCoreManager::instance().createVertexDeclaration(mVertexDesc);
  40. for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
  41. {
  42. if (!mVertexDesc->hasStream(i))
  43. continue;
  44. SPtr<VertexBufferCore> vertexBuffer = HardwareBufferCoreManager::instance().createVertexBuffer(
  45. mVertexData->vertexDeclaration->getProperties().getVertexSize(i),
  46. mVertexData->vertexCount,
  47. isDynamic ? GBU_DYNAMIC : GBU_STATIC);
  48. mVertexData->setBuffer(i, vertexBuffer);
  49. }
  50. // TODO Low priority - DX11 (and maybe OpenGL)? allow an optimization that allows you to set
  51. // buffer data upon buffer construction, instead of setting it in a second step like I do here
  52. if (mTempInitialMeshData != nullptr)
  53. {
  54. writeSubresource(0, *mTempInitialMeshData, isDynamic);
  55. mTempInitialMeshData = nullptr;
  56. }
  57. MeshCoreBase::initialize();
  58. }
  59. SPtr<VertexData> MeshCore::getVertexData() const
  60. {
  61. THROW_IF_NOT_CORE_THREAD;
  62. return mVertexData;
  63. }
  64. SPtr<IndexBufferCore> MeshCore::getIndexBuffer() const
  65. {
  66. THROW_IF_NOT_CORE_THREAD;
  67. return mIndexBuffer;
  68. }
  69. SPtr<VertexDataDesc> MeshCore::getVertexDesc() const
  70. {
  71. THROW_IF_NOT_CORE_THREAD;
  72. return mVertexDesc;
  73. }
  74. void MeshCore::writeSubresource(UINT32 subresourceIdx, const MeshData& meshData, bool discardEntireBuffer, bool performUpdateBounds)
  75. {
  76. THROW_IF_NOT_CORE_THREAD;
  77. if (discardEntireBuffer)
  78. {
  79. if ((mUsage & MU_STATIC) != 0)
  80. {
  81. LOGWRN("Buffer discard is enabled but buffer was not created as dynamic. Disabling discard.");
  82. discardEntireBuffer = false;
  83. }
  84. }
  85. else
  86. {
  87. if ((mUsage & MU_DYNAMIC) != 0)
  88. {
  89. LOGWRN("Buffer discard is not enabled but buffer was created as dynamic. Enabling discard.");
  90. discardEntireBuffer = true;
  91. }
  92. }
  93. // Indices
  94. const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
  95. UINT32 indicesSize = meshData.getIndexBufferSize();
  96. UINT8* srcIdxData = meshData.getIndexData();
  97. if (meshData.getIndexElementSize() != ibProps.getIndexSize())
  98. {
  99. LOGERR("Provided index size doesn't match meshes index size. Needed: " +
  100. toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
  101. return;
  102. }
  103. if (indicesSize > mIndexBuffer->getSizeInBytes())
  104. {
  105. indicesSize = mIndexBuffer->getSizeInBytes();
  106. LOGERR("Index buffer values are being written out of valid range.");
  107. }
  108. mIndexBuffer->writeData(0, indicesSize, srcIdxData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
  109. // Vertices
  110. for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
  111. {
  112. if (!mVertexDesc->hasStream(i))
  113. continue;
  114. if (!meshData.getVertexDesc()->hasStream(i))
  115. continue;
  116. // Ensure both have the same sized vertices
  117. UINT32 myVertSize = mVertexDesc->getVertexStride(i);
  118. UINT32 otherVertSize = meshData.getVertexDesc()->getVertexStride(i);
  119. if (myVertSize != otherVertSize)
  120. {
  121. LOGERR("Provided vertex size for stream " + toString(i) + " doesn't match meshes vertex size. Needed: " +
  122. toString(myVertSize) + ". Got: " + toString(otherVertSize));
  123. continue;
  124. }
  125. SPtr<VertexBufferCore> vertexBuffer = mVertexData->getBuffer(i);
  126. UINT32 bufferSize = meshData.getStreamSize(i);
  127. UINT8* srcVertBufferData = meshData.getStreamData(i);
  128. if (bufferSize > vertexBuffer->getSizeInBytes())
  129. {
  130. bufferSize = vertexBuffer->getSizeInBytes();
  131. LOGERR("Vertex buffer values for stream \"" + toString(i) + "\" are being written out of valid range.");
  132. }
  133. if (RenderAPICore::instance().getAPIInfo().getVertexColorFlipRequired())
  134. {
  135. UINT8* bufferCopy = (UINT8*)bs_alloc(bufferSize);
  136. memcpy(bufferCopy, srcVertBufferData, bufferSize); // TODO Low priority - Attempt to avoid this copy
  137. UINT32 vertexStride = meshData.getVertexDesc()->getVertexStride(i);
  138. for (INT32 semanticIdx = 0; semanticIdx < VertexBuffer::MAX_SEMANTIC_IDX; semanticIdx++)
  139. {
  140. if (!meshData.getVertexDesc()->hasElement(VES_COLOR, semanticIdx, i))
  141. continue;
  142. UINT8* colorData = bufferCopy + mVertexDesc->getElementOffsetFromStream(VES_COLOR, semanticIdx, i);
  143. for (UINT32 j = 0; j < mVertexData->vertexCount; j++)
  144. {
  145. UINT32* curColor = (UINT32*)colorData;
  146. (*curColor) = ((*curColor) & 0xFF00FF00) | ((*curColor >> 16) & 0x000000FF) | ((*curColor << 16) & 0x00FF0000);
  147. colorData += vertexStride;
  148. }
  149. }
  150. vertexBuffer->writeData(0, bufferSize, bufferCopy, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
  151. bs_free(bufferCopy);
  152. }
  153. else
  154. {
  155. vertexBuffer->writeData(0, bufferSize, srcVertBufferData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
  156. }
  157. }
  158. if (performUpdateBounds)
  159. updateBounds(meshData);
  160. }
  161. void MeshCore::readSubresource(UINT32 subresourceIdx, MeshData& meshData)
  162. {
  163. THROW_IF_NOT_CORE_THREAD;
  164. IndexType indexType = IT_32BIT;
  165. if (mIndexBuffer)
  166. indexType = mIndexBuffer->getProperties().getType();
  167. if (mIndexBuffer)
  168. {
  169. const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
  170. if (meshData.getIndexElementSize() != ibProps.getIndexSize())
  171. {
  172. LOGERR("Provided index size doesn't match meshes index size. Needed: " +
  173. toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
  174. return;
  175. }
  176. UINT8* idxData = static_cast<UINT8*>(mIndexBuffer->lock(GBL_READ_ONLY));
  177. UINT32 idxElemSize = ibProps.getIndexSize();
  178. UINT8* indices = nullptr;
  179. if (indexType == IT_16BIT)
  180. indices = (UINT8*)meshData.getIndices16();
  181. else
  182. indices = (UINT8*)meshData.getIndices32();
  183. UINT32 numIndicesToCopy = std::min(mProperties.mNumIndices, meshData.getNumIndices());
  184. UINT32 indicesSize = numIndicesToCopy * idxElemSize;
  185. if (indicesSize > meshData.getIndexBufferSize())
  186. {
  187. LOGERR("Provided buffer doesn't have enough space to store mesh indices.");
  188. return;
  189. }
  190. memcpy(indices, idxData, numIndicesToCopy * idxElemSize);
  191. mIndexBuffer->unlock();
  192. }
  193. if (mVertexData)
  194. {
  195. auto vertexBuffers = mVertexData->getBuffers();
  196. UINT32 streamIdx = 0;
  197. for (auto iter = vertexBuffers.begin(); iter != vertexBuffers.end(); ++iter)
  198. {
  199. if (!meshData.getVertexDesc()->hasStream(streamIdx))
  200. continue;
  201. SPtr<VertexBufferCore> vertexBuffer = iter->second;
  202. const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
  203. // Ensure both have the same sized vertices
  204. UINT32 myVertSize = mVertexDesc->getVertexStride(streamIdx);
  205. UINT32 otherVertSize = meshData.getVertexDesc()->getVertexStride(streamIdx);
  206. if (myVertSize != otherVertSize)
  207. {
  208. LOGERR("Provided vertex size for stream " + toString(streamIdx) + " doesn't match meshes vertex size. Needed: " +
  209. toString(myVertSize) + ". Got: " + toString(otherVertSize));
  210. continue;
  211. }
  212. UINT32 numVerticesToCopy = meshData.getNumVertices();
  213. UINT32 bufferSize = vbProps.getVertexSize() * numVerticesToCopy;
  214. if (bufferSize > vertexBuffer->getSizeInBytes())
  215. {
  216. LOGERR("Vertex buffer values for stream \"" + toString(streamIdx) + "\" are being read out of valid range.");
  217. continue;
  218. }
  219. UINT8* vertDataPtr = static_cast<UINT8*>(vertexBuffer->lock(GBL_READ_ONLY));
  220. UINT8* dest = meshData.getStreamData(streamIdx);
  221. memcpy(dest, vertDataPtr, bufferSize);
  222. vertexBuffer->unlock();
  223. streamIdx++;
  224. }
  225. }
  226. }
  227. void MeshCore::updateBounds(const MeshData& meshData)
  228. {
  229. mProperties.mBounds = meshData.calculateBounds();
  230. // TODO - Sync this to sim-thread possibly?
  231. }
  232. SPtr<MeshCore> MeshCore::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  233. int usage, DrawOperationType drawOp, IndexType indexType, const SPtr<Skeleton>& skeleton)
  234. {
  235. SubMesh subMesh(0, numIndices, drawOp);
  236. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
  237. vertexDesc, { subMesh }, usage, indexType, skeleton, nullptr));
  238. mesh->_setThisPtr(mesh);
  239. mesh->initialize();
  240. return mesh;
  241. }
  242. SPtr<MeshCore> MeshCore::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  243. const Vector<SubMesh>& subMeshes, int usage, IndexType indexType, const SPtr<Skeleton>& skeleton)
  244. {
  245. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
  246. vertexDesc, subMeshes, usage, indexType, skeleton, nullptr));
  247. mesh->_setThisPtr(mesh);
  248. mesh->initialize();
  249. return mesh;
  250. }
  251. SPtr<MeshCore> MeshCore::create(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp,
  252. const SPtr<Skeleton>& skeleton)
  253. {
  254. UINT32 numVertices = initialMeshData->getNumVertices();
  255. UINT32 numIndices = initialMeshData->getNumIndices();
  256. SPtr<VertexDataDesc> vertexDesc = initialMeshData->getVertexDesc();
  257. SubMesh subMesh(0, numIndices, drawOp);
  258. IndexType indexType = initialMeshData->getIndexType();
  259. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
  260. vertexDesc, { subMesh }, usage, indexType, skeleton, initialMeshData));
  261. mesh->_setThisPtr(mesh);
  262. mesh->initialize();
  263. return mesh;
  264. }
  265. SPtr<MeshCore> MeshCore::create(const SPtr<MeshData>& initialMeshData, const Vector<SubMesh>& subMeshes, int usage,
  266. const SPtr<Skeleton>& skeleton)
  267. {
  268. UINT32 numVertices = initialMeshData->getNumVertices();
  269. UINT32 numIndices = initialMeshData->getNumIndices();
  270. SPtr<VertexDataDesc> vertexDesc = initialMeshData->getVertexDesc();
  271. IndexType indexType = initialMeshData->getIndexType();
  272. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
  273. vertexDesc, subMeshes, usage, indexType, skeleton, initialMeshData));
  274. mesh->_setThisPtr(mesh);
  275. mesh->initialize();
  276. return mesh;
  277. }
  278. Mesh::Mesh(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  279. int usage, DrawOperationType drawOp, IndexType indexType, const SPtr<Skeleton>& skeleton)
  280. :MeshBase(numVertices, numIndices, drawOp), mVertexDesc(vertexDesc), mUsage(usage),
  281. mIndexType(indexType), mSkeleton(skeleton)
  282. {
  283. }
  284. Mesh::Mesh(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  285. const Vector<SubMesh>& subMeshes, int usage, IndexType indexType, const SPtr<Skeleton>& skeleton)
  286. :MeshBase(numVertices, numIndices, subMeshes), mVertexDesc(vertexDesc), mUsage(usage),
  287. mIndexType(indexType), mSkeleton(skeleton)
  288. {
  289. }
  290. Mesh::Mesh(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp, const SPtr<Skeleton>& skeleton)
  291. :MeshBase(initialMeshData->getNumVertices(), initialMeshData->getNumIndices(), drawOp),
  292. mCPUData(initialMeshData), mVertexDesc(initialMeshData->getVertexDesc()),
  293. mUsage(usage), mIndexType(initialMeshData->getIndexType()), mSkeleton(skeleton)
  294. {
  295. }
  296. Mesh::Mesh(const SPtr<MeshData>& initialMeshData, const Vector<SubMesh>& subMeshes, int usage, const SPtr<Skeleton>& skeleton)
  297. :MeshBase(initialMeshData->getNumVertices(), initialMeshData->getNumIndices(), subMeshes),
  298. mCPUData(initialMeshData), mVertexDesc(initialMeshData->getVertexDesc()),
  299. mUsage(usage), mIndexType(initialMeshData->getIndexType()), mSkeleton(skeleton)
  300. {
  301. }
  302. Mesh::Mesh()
  303. :MeshBase(0, 0, DOT_TRIANGLE_LIST), mUsage(MU_STATIC), mIndexType(IT_32BIT)
  304. {
  305. }
  306. Mesh::~Mesh()
  307. {
  308. }
  309. AsyncOp Mesh::writeSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const SPtr<MeshData>& data, bool discardEntireBuffer)
  310. {
  311. updateBounds(*data);
  312. updateCPUBuffer(subresourceIdx, *data);
  313. data->_lock();
  314. std::function<void(const SPtr<MeshCore>&, UINT32, const SPtr<MeshData>&, bool, AsyncOp&)> func =
  315. [&](const SPtr<MeshCore>& mesh, UINT32 _subresourceIdx, const SPtr<MeshData>& _meshData, bool _discardEntireBuffer, AsyncOp& asyncOp)
  316. {
  317. mesh->writeSubresource(_subresourceIdx, *_meshData, _discardEntireBuffer, false);
  318. _meshData->_unlock();
  319. asyncOp._completeOperation();
  320. };
  321. return accessor.queueReturnCommand(std::bind(func, getCore(), subresourceIdx,
  322. data, discardEntireBuffer, std::placeholders::_1));
  323. }
  324. AsyncOp Mesh::readSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const SPtr<MeshData>& data)
  325. {
  326. data->_lock();
  327. std::function<void(const SPtr<MeshCore>&, UINT32, const SPtr<MeshData>&, AsyncOp&)> func =
  328. [&](const SPtr<MeshCore>& mesh, UINT32 _subresourceIdx, const SPtr<MeshData>& _meshData, AsyncOp& asyncOp)
  329. {
  330. mesh->readSubresource(_subresourceIdx, *_meshData);
  331. _meshData->_unlock();
  332. asyncOp._completeOperation();
  333. };
  334. return accessor.queueReturnCommand(std::bind(func, getCore(), subresourceIdx,
  335. data, std::placeholders::_1));
  336. }
  337. SPtr<MeshData> Mesh::allocateSubresourceBuffer(UINT32 subresourceIdx) const
  338. {
  339. SPtr<MeshData> meshData = bs_shared_ptr_new<MeshData>(mProperties.mNumVertices, mProperties.mNumIndices, mVertexDesc, mIndexType);
  340. return meshData;
  341. }
  342. void Mesh::initialize()
  343. {
  344. if (mCPUData != nullptr)
  345. updateBounds(*mCPUData);
  346. MeshBase::initialize();
  347. if ((mUsage & MU_CPUCACHED) != 0 && mCPUData == nullptr)
  348. createCPUBuffer();
  349. }
  350. void Mesh::updateBounds(const MeshData& meshData)
  351. {
  352. mProperties.mBounds = meshData.calculateBounds();
  353. markCoreDirty();
  354. }
  355. SPtr<MeshCore> Mesh::getCore() const
  356. {
  357. return std::static_pointer_cast<MeshCore>(mCoreSpecific);
  358. }
  359. SPtr<CoreObjectCore> Mesh::createCore() const
  360. {
  361. MeshCore* obj = new (bs_alloc<MeshCore>()) MeshCore(mProperties.mNumVertices, mProperties.mNumIndices,
  362. mVertexDesc, mProperties.mSubMeshes, mUsage, mIndexType, mSkeleton, mCPUData);
  363. SPtr<CoreObjectCore> meshCore = bs_shared_ptr<MeshCore>(obj);
  364. meshCore->_setThisPtr(meshCore);
  365. if ((mUsage & MU_CPUCACHED) == 0)
  366. mCPUData = nullptr;
  367. return meshCore;
  368. }
  369. void Mesh::updateCPUBuffer(UINT32 subresourceIdx, const MeshData& pixelData)
  370. {
  371. if ((mUsage & MU_CPUCACHED) == 0)
  372. return;
  373. if (subresourceIdx > 0)
  374. {
  375. LOGERR("Invalid subresource index: " + toString(subresourceIdx) + ". Supported range: 0 .. 1.");
  376. return;
  377. }
  378. if (pixelData.getNumIndices() != mProperties.getNumIndices() ||
  379. pixelData.getNumVertices() != mProperties.getNumVertices() ||
  380. pixelData.getIndexType() != mIndexType ||
  381. pixelData.getVertexDesc()->getVertexStride() != mVertexDesc->getVertexStride())
  382. {
  383. LOGERR("Provided buffer is not of valid dimensions or format in order to update this mesh.");
  384. return;
  385. }
  386. if (mCPUData->getSize() != pixelData.getSize())
  387. BS_EXCEPT(InternalErrorException, "Buffer sizes don't match.");
  388. UINT8* dest = mCPUData->getData();
  389. UINT8* src = pixelData.getData();
  390. memcpy(dest, src, pixelData.getSize());
  391. }
  392. void Mesh::readData(MeshData& dest)
  393. {
  394. if ((mUsage & MU_CPUCACHED) == 0)
  395. {
  396. LOGERR("Attempting to read CPU data from a mesh that is created without CPU caching.");
  397. return;
  398. }
  399. if (dest.getNumIndices() != mProperties.getNumIndices() ||
  400. dest.getNumVertices() != mProperties.getNumVertices() ||
  401. dest.getIndexType() != mIndexType ||
  402. dest.getVertexDesc()->getVertexStride() != mVertexDesc->getVertexStride())
  403. {
  404. LOGERR("Provided buffer is not of valid dimensions or format in order to read from this mesh.");
  405. return;
  406. }
  407. if (mCPUData->getSize() != dest.getSize())
  408. BS_EXCEPT(InternalErrorException, "Buffer sizes don't match.");
  409. UINT8* srcPtr = mCPUData->getData();
  410. UINT8* destPtr = dest.getData();
  411. memcpy(destPtr, srcPtr, dest.getSize());
  412. }
  413. void Mesh::createCPUBuffer()
  414. {
  415. mCPUData = allocateSubresourceBuffer(0);
  416. }
  417. HMesh Mesh::dummy()
  418. {
  419. return MeshManager::instance().getDummyMesh();
  420. }
  421. /************************************************************************/
  422. /* SERIALIZATION */
  423. /************************************************************************/
  424. RTTITypeBase* Mesh::getRTTIStatic()
  425. {
  426. return MeshRTTI::instance();
  427. }
  428. RTTITypeBase* Mesh::getRTTI() const
  429. {
  430. return Mesh::getRTTIStatic();
  431. }
  432. /************************************************************************/
  433. /* STATICS */
  434. /************************************************************************/
  435. HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  436. int usage, DrawOperationType drawOp, IndexType indexType, const SPtr<Skeleton>& skeleton)
  437. {
  438. SPtr<Mesh> meshPtr = _createPtr(numVertices, numIndices, vertexDesc, usage, drawOp, indexType, skeleton);
  439. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  440. }
  441. HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  442. const Vector<SubMesh>& subMeshes, int usage, IndexType indexType, const SPtr<Skeleton>& skeleton)
  443. {
  444. SPtr<Mesh> meshPtr = _createPtr(numVertices, numIndices, vertexDesc, subMeshes, usage, indexType, skeleton);
  445. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  446. }
  447. HMesh Mesh::create(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp, const SPtr<Skeleton>& skeleton)
  448. {
  449. SPtr<Mesh> meshPtr = _createPtr(initialMeshData, usage, drawOp, skeleton);
  450. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  451. }
  452. HMesh Mesh::create(const SPtr<MeshData>& initialMeshData, const Vector<SubMesh>& subMeshes, int usage, const SPtr<Skeleton>& skeleton)
  453. {
  454. SPtr<Mesh> meshPtr = _createPtr(initialMeshData, subMeshes, usage, skeleton);
  455. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  456. }
  457. SPtr<Mesh> Mesh::_createPtr(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  458. int usage, DrawOperationType drawOp, IndexType indexType, const SPtr<Skeleton>& skeleton)
  459. {
  460. return MeshManager::instance().create(numVertices, numIndices, vertexDesc, usage, drawOp, indexType, skeleton);
  461. }
  462. SPtr<Mesh> Mesh::_createPtr(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  463. const Vector<SubMesh>& subMeshes, int usage, IndexType indexType, const SPtr<Skeleton>& skeleton)
  464. {
  465. return MeshManager::instance().create(numVertices, numIndices, vertexDesc, subMeshes, usage, indexType, skeleton);
  466. }
  467. SPtr<Mesh> Mesh::_createPtr(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp, const SPtr<Skeleton>& skeleton)
  468. {
  469. return MeshManager::instance().create(initialMeshData, usage, drawOp, skeleton);
  470. }
  471. SPtr<Mesh> Mesh::_createPtr(const SPtr<MeshData>& initialMeshData, const Vector<SubMesh>& subMeshes, int usage, const SPtr<Skeleton>& skeleton)
  472. {
  473. return MeshManager::instance().create(initialMeshData, subMeshes, usage, skeleton);
  474. }
  475. }