BsMesh.cpp 20 KB

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