BsMesh.cpp 19 KB

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