CCParticleSystemQuad.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2009 Leonardo Kasperavičius
  4. Copyright (c) 2010-2012 cocos2d-x.org
  5. Copyright (c) 2011 Zynga Inc.
  6. Copyright (c) 2013-2016 Chukong Technologies Inc.
  7. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  8. http://www.cocos2d-x.org
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. THE SOFTWARE.
  24. ****************************************************************************/
  25. #include "2d/CCParticleSystemQuad.h"
  26. #include <algorithm>
  27. #include <stddef.h> // offsetof
  28. #include "base/ccTypes.h"
  29. #include "2d/CCSpriteFrame.h"
  30. #include "2d/CCParticleBatchNode.h"
  31. #include "renderer/CCTextureAtlas.h"
  32. #include "renderer/CCRenderer.h"
  33. #include "base/CCDirector.h"
  34. #include "base/CCEventType.h"
  35. #include "base/CCConfiguration.h"
  36. #include "base/CCEventListenerCustom.h"
  37. #include "base/CCEventDispatcher.h"
  38. #include "base/ccUTF8.h"
  39. #include "renderer/ccShaders.h"
  40. #include "renderer/backend/ProgramState.h"
  41. NS_CC_BEGIN
  42. ParticleSystemQuad::ParticleSystemQuad()
  43. {
  44. auto& pipelieDescriptor = _quadCommand.getPipelineDescriptor();
  45. auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR);
  46. _programState = new (std::nothrow) backend::ProgramState(program);
  47. pipelieDescriptor.programState = _programState;
  48. _mvpMatrixLocaiton = pipelieDescriptor.programState->getUniformLocation("u_MVPMatrix");
  49. _textureLocation = pipelieDescriptor.programState->getUniformLocation("u_texture");
  50. auto vertexLayout = _programState->getVertexLayout();
  51. const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
  52. auto iter = attributeInfo.find("a_position");
  53. if(iter != attributeInfo.end())
  54. {
  55. vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
  56. }
  57. iter = attributeInfo.find("a_texCoord");
  58. if(iter != attributeInfo.end())
  59. {
  60. vertexLayout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
  61. }
  62. iter = attributeInfo.find("a_color");
  63. if(iter != attributeInfo.end())
  64. {
  65. vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
  66. }
  67. vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
  68. }
  69. ParticleSystemQuad::~ParticleSystemQuad()
  70. {
  71. if (nullptr == _batchNode)
  72. {
  73. CC_SAFE_FREE(_quads);
  74. CC_SAFE_FREE(_indices);
  75. }
  76. }
  77. // implementation ParticleSystemQuad
  78. ParticleSystemQuad * ParticleSystemQuad::create(const std::string& filename)
  79. {
  80. ParticleSystemQuad *ret = new (std::nothrow) ParticleSystemQuad();
  81. if (ret && ret->initWithFile(filename))
  82. {
  83. ret->autorelease();
  84. return ret;
  85. }
  86. CC_SAFE_DELETE(ret);
  87. return ret;
  88. }
  89. ParticleSystemQuad * ParticleSystemQuad::createWithTotalParticles(int numberOfParticles) {
  90. ParticleSystemQuad *ret = new (std::nothrow) ParticleSystemQuad();
  91. if (ret && ret->initWithTotalParticles(numberOfParticles))
  92. {
  93. ret->autorelease();
  94. return ret;
  95. }
  96. CC_SAFE_DELETE(ret);
  97. return ret;
  98. }
  99. ParticleSystemQuad * ParticleSystemQuad::create(ValueMap &dictionary)
  100. {
  101. ParticleSystemQuad *ret = new (std::nothrow) ParticleSystemQuad();
  102. if (ret && ret->initWithDictionary(dictionary))
  103. {
  104. ret->autorelease();
  105. return ret;
  106. }
  107. CC_SAFE_DELETE(ret);
  108. return ret;
  109. }
  110. //implementation ParticleSystemQuad
  111. // overriding the init method
  112. bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles)
  113. {
  114. // base initialization
  115. if( ParticleSystem::initWithTotalParticles(numberOfParticles) )
  116. {
  117. // allocating data space
  118. if( ! this->allocMemory() ) {
  119. this->release();
  120. return false;
  121. }
  122. initIndices();
  123. // setupVBO();
  124. #if CC_ENABLE_CACHE_TEXTURE_DATA
  125. // Need to listen the event only when not use batchnode, because it will use VBO
  126. auto listener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(ParticleSystemQuad::listenRendererRecreated, this));
  127. _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
  128. #endif
  129. return true;
  130. }
  131. return false;
  132. }
  133. // pointRect should be in Texture coordinates, not pixel coordinates
  134. void ParticleSystemQuad::initTexCoordsWithRect(const Rect& pointRect)
  135. {
  136. // convert to Tex coords
  137. Rect rect = Rect(
  138. pointRect.origin.x * CC_CONTENT_SCALE_FACTOR(),
  139. pointRect.origin.y * CC_CONTENT_SCALE_FACTOR(),
  140. pointRect.size.width * CC_CONTENT_SCALE_FACTOR(),
  141. pointRect.size.height * CC_CONTENT_SCALE_FACTOR());
  142. float wide = (float) pointRect.size.width;
  143. float high = (float) pointRect.size.height;
  144. if (_texture)
  145. {
  146. wide = (float)_texture->getPixelsWide();
  147. high = (float)_texture->getPixelsHigh();
  148. }
  149. #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
  150. float left = (rect.origin.x*2+1) / (wide*2);
  151. float bottom = (rect.origin.y*2+1) / (high*2);
  152. float right = left + (rect.size.width*2-2) / (wide*2);
  153. float top = bottom + (rect.size.height*2-2) / (high*2);
  154. #else
  155. float left = rect.origin.x / wide;
  156. float bottom = rect.origin.y / high;
  157. float right = left + rect.size.width / wide;
  158. float top = bottom + rect.size.height / high;
  159. #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
  160. // Important. Texture in cocos2d are inverted, so the Y component should be inverted
  161. std::swap(top, bottom);
  162. V3F_C4B_T2F_Quad *quads = nullptr;
  163. unsigned int start = 0, end = 0;
  164. if (_batchNode)
  165. {
  166. quads = _batchNode->getTextureAtlas()->getQuads();
  167. start = _atlasIndex;
  168. end = _atlasIndex + _totalParticles;
  169. }
  170. else
  171. {
  172. quads = _quads;
  173. start = 0;
  174. end = _totalParticles;
  175. }
  176. for(unsigned int i=start; i<end; i++)
  177. {
  178. // bottom-left vertex:
  179. quads[i].bl.texCoords.u = left;
  180. quads[i].bl.texCoords.v = bottom;
  181. // bottom-right vertex:
  182. quads[i].br.texCoords.u = right;
  183. quads[i].br.texCoords.v = bottom;
  184. // top-left vertex:
  185. quads[i].tl.texCoords.u = left;
  186. quads[i].tl.texCoords.v = top;
  187. // top-right vertex:
  188. quads[i].tr.texCoords.u = right;
  189. quads[i].tr.texCoords.v = top;
  190. }
  191. }
  192. void ParticleSystemQuad::updateTexCoords()
  193. {
  194. if (_texture)
  195. {
  196. const Size& s = _texture->getContentSize();
  197. initTexCoordsWithRect(Rect(0, 0, s.width, s.height));
  198. }
  199. }
  200. void ParticleSystemQuad::setTextureWithRect(Texture2D *texture, const Rect& rect)
  201. {
  202. // Only update the texture if is different from the current one
  203. if( !_texture || texture->getBackendTexture() != _texture->getBackendTexture() )
  204. {
  205. ParticleSystem::setTexture(texture);
  206. }
  207. this->initTexCoordsWithRect(rect);
  208. }
  209. void ParticleSystemQuad::setTexture(Texture2D* texture)
  210. {
  211. const Size& s = texture->getContentSize();
  212. this->setTextureWithRect(texture, Rect(0, 0, s.width, s.height));
  213. }
  214. void ParticleSystemQuad::setDisplayFrame(SpriteFrame *spriteFrame)
  215. {
  216. CCASSERT(spriteFrame->getOffsetInPixels().isZero(),
  217. "QuadParticle only supports SpriteFrames with no offsets");
  218. this->setTextureWithRect(spriteFrame->getTexture(), spriteFrame->getRect());
  219. }
  220. void ParticleSystemQuad::initIndices()
  221. {
  222. for(int i = 0; i < _totalParticles; ++i)
  223. {
  224. const unsigned int i6 = i*6;
  225. const unsigned int i4 = i*4;
  226. _indices[i6+0] = (unsigned short) i4+0;
  227. _indices[i6+1] = (unsigned short) i4+1;
  228. _indices[i6+2] = (unsigned short) i4+2;
  229. _indices[i6+5] = (unsigned short) i4+1;
  230. _indices[i6+4] = (unsigned short) i4+2;
  231. _indices[i6+3] = (unsigned short) i4+3;
  232. }
  233. }
  234. inline void updatePosWithParticle(V3F_C4B_T2F_Quad *quad, const Vec2& newPosition,float size,float rotation)
  235. {
  236. // vertices
  237. float size_2 = size/2;
  238. float x1 = -size_2;
  239. float y1 = -size_2;
  240. float x2 = size_2;
  241. float y2 = size_2;
  242. float x = newPosition.x;
  243. float y = newPosition.y;
  244. float r = (float)-CC_DEGREES_TO_RADIANS(rotation);
  245. float cr = cosf(r);
  246. float sr = sinf(r);
  247. float ax = x1 * cr - y1 * sr + x;
  248. float ay = x1 * sr + y1 * cr + y;
  249. float bx = x2 * cr - y1 * sr + x;
  250. float by = x2 * sr + y1 * cr + y;
  251. float cx = x2 * cr - y2 * sr + x;
  252. float cy = x2 * sr + y2 * cr + y;
  253. float dx = x1 * cr - y2 * sr + x;
  254. float dy = x1 * sr + y2 * cr + y;
  255. // bottom-left
  256. quad->bl.vertices.x = ax;
  257. quad->bl.vertices.y = ay;
  258. // bottom-right vertex:
  259. quad->br.vertices.x = bx;
  260. quad->br.vertices.y = by;
  261. // top-left vertex:
  262. quad->tl.vertices.x = dx;
  263. quad->tl.vertices.y = dy;
  264. // top-right vertex:
  265. quad->tr.vertices.x = cx;
  266. quad->tr.vertices.y = cy;
  267. }
  268. void ParticleSystemQuad::updateParticleQuads()
  269. {
  270. if (_particleCount <= 0) {
  271. return;
  272. }
  273. Vec2 currentPosition;
  274. if (_positionType == PositionType::FREE)
  275. {
  276. currentPosition = this->convertToWorldSpace(Vec2::ZERO);
  277. }
  278. else if (_positionType == PositionType::RELATIVE)
  279. {
  280. currentPosition = _position;
  281. }
  282. V3F_C4B_T2F_Quad *startQuad;
  283. Vec2 pos = Vec2::ZERO;
  284. if (_batchNode)
  285. {
  286. V3F_C4B_T2F_Quad *batchQuads = _batchNode->getTextureAtlas()->getQuads();
  287. startQuad = &(batchQuads[_atlasIndex]);
  288. pos = _position;
  289. }
  290. else
  291. {
  292. startQuad = &(_quads[0]);
  293. }
  294. if( _positionType == PositionType::FREE )
  295. {
  296. Vec3 p1(currentPosition.x, currentPosition.y, 0);
  297. Mat4 worldToNodeTM = getWorldToNodeTransform();
  298. worldToNodeTM.transformPoint(&p1);
  299. Vec3 p2;
  300. Vec2 newPos;
  301. float* startX = _particleData.startPosX;
  302. float* startY = _particleData.startPosY;
  303. float* x = _particleData.posx;
  304. float* y = _particleData.posy;
  305. float* s = _particleData.size;
  306. float* r = _particleData.rotation;
  307. V3F_C4B_T2F_Quad* quadStart = startQuad;
  308. for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
  309. {
  310. p2.set(*startX, *startY, 0);
  311. worldToNodeTM.transformPoint(&p2);
  312. newPos.set(*x,*y);
  313. p2 = p1 - p2;
  314. newPos.x -= p2.x - pos.x;
  315. newPos.y -= p2.y - pos.y;
  316. updatePosWithParticle(quadStart, newPos, *s, *r);
  317. }
  318. }
  319. else if( _positionType == PositionType::RELATIVE )
  320. {
  321. Vec2 newPos;
  322. float* startX = _particleData.startPosX;
  323. float* startY = _particleData.startPosY;
  324. float* x = _particleData.posx;
  325. float* y = _particleData.posy;
  326. float* s = _particleData.size;
  327. float* r = _particleData.rotation;
  328. V3F_C4B_T2F_Quad* quadStart = startQuad;
  329. for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
  330. {
  331. newPos.set(*x, *y);
  332. newPos.x = *x - (currentPosition.x - *startX);
  333. newPos.y = *y - (currentPosition.y - *startY);
  334. newPos += pos;
  335. updatePosWithParticle(quadStart, newPos, *s, *r);
  336. }
  337. }
  338. else
  339. {
  340. Vec2 newPos;
  341. float* startX = _particleData.startPosX;
  342. float* startY = _particleData.startPosY;
  343. float* x = _particleData.posx;
  344. float* y = _particleData.posy;
  345. float* s = _particleData.size;
  346. float* r = _particleData.rotation;
  347. V3F_C4B_T2F_Quad* quadStart = startQuad;
  348. for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
  349. {
  350. newPos.set(*x + pos.x, *y + pos.y);
  351. updatePosWithParticle(quadStart, newPos, *s, *r);
  352. }
  353. }
  354. //set color
  355. if(_opacityModifyRGB)
  356. {
  357. V3F_C4B_T2F_Quad* quad = startQuad;
  358. float* r = _particleData.colorR;
  359. float* g = _particleData.colorG;
  360. float* b = _particleData.colorB;
  361. float* a = _particleData.colorA;
  362. for (int i = 0; i < _particleCount; ++i,++quad,++r,++g,++b,++a)
  363. {
  364. uint8_t colorR = *r * *a * 255;
  365. uint8_t colorG = *g * *a * 255;
  366. uint8_t colorB = *b * *a * 255;
  367. uint8_t colorA = *a * 255;
  368. quad->bl.colors.set(colorR, colorG, colorB, colorA);
  369. quad->br.colors.set(colorR, colorG, colorB, colorA);
  370. quad->tl.colors.set(colorR, colorG, colorB, colorA);
  371. quad->tr.colors.set(colorR, colorG, colorB, colorA);
  372. }
  373. }
  374. else
  375. {
  376. V3F_C4B_T2F_Quad* quad = startQuad;
  377. float* r = _particleData.colorR;
  378. float* g = _particleData.colorG;
  379. float* b = _particleData.colorB;
  380. float* a = _particleData.colorA;
  381. for (int i = 0; i < _particleCount; ++i,++quad,++r,++g,++b,++a)
  382. {
  383. uint8_t colorR = *r * 255;
  384. uint8_t colorG = *g * 255;
  385. uint8_t colorB = *b * 255;
  386. uint8_t colorA = *a * 255;
  387. quad->bl.colors.set(colorR, colorG, colorB, colorA);
  388. quad->br.colors.set(colorR, colorG, colorB, colorA);
  389. quad->tl.colors.set(colorR, colorG, colorB, colorA);
  390. quad->tr.colors.set(colorR, colorG, colorB, colorA);
  391. }
  392. }
  393. }
  394. // overriding draw method
  395. void ParticleSystemQuad::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
  396. {
  397. //quad command
  398. if(_particleCount > 0)
  399. {
  400. auto programState = _quadCommand.getPipelineDescriptor().programState;
  401. programState->setTexture(_textureLocation, 0, _texture->getBackendTexture());
  402. cocos2d::Mat4 projectionMat = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
  403. programState->setUniform(_mvpMatrixLocaiton, projectionMat.m, sizeof(projectionMat.m));
  404. _quadCommand.init(_globalZOrder, _texture, _blendFunc, _quads, _particleCount, transform, flags);
  405. renderer->addCommand(&_quadCommand);
  406. }
  407. }
  408. void ParticleSystemQuad::setTotalParticles(int tp)
  409. {
  410. // If we are setting the total number of particles to a number higher
  411. // than what is allocated, we need to allocate new arrays
  412. if( tp > _allocatedParticles )
  413. {
  414. // Allocate new memory
  415. size_t quadsSize = sizeof(_quads[0]) * tp * 1;
  416. size_t indicesSize = sizeof(_indices[0]) * tp * 6 * 1;
  417. _particleData.release();
  418. if (!_particleData.init(tp))
  419. {
  420. CCLOG("Particle system: not enough memory");
  421. return;
  422. }
  423. V3F_C4B_T2F_Quad* quadsNew = (V3F_C4B_T2F_Quad*)realloc(_quads, quadsSize);
  424. unsigned short* indicesNew = (unsigned short*)realloc(_indices, indicesSize);
  425. if (quadsNew && indicesNew)
  426. {
  427. // Assign pointers
  428. _quads = quadsNew;
  429. _indices = indicesNew;
  430. // Clear the memory
  431. memset(_quads, 0, quadsSize);
  432. memset(_indices, 0, indicesSize);
  433. _allocatedParticles = tp;
  434. }
  435. else
  436. {
  437. // Out of memory, failed to resize some array
  438. if (quadsNew) _quads = quadsNew;
  439. if (indicesNew) _indices = indicesNew;
  440. CCLOG("Particle system: out of memory");
  441. return;
  442. }
  443. _totalParticles = tp;
  444. // Init particles
  445. if (_batchNode)
  446. {
  447. for (int i = 0; i < _totalParticles; i++)
  448. {
  449. _particleData.atlasIndex[i] = i;
  450. }
  451. }
  452. initIndices();
  453. // setupVBO();
  454. // fixed http://www.cocos2d-x.org/issues/3990
  455. // Updates texture coords.
  456. updateTexCoords();
  457. }
  458. else
  459. {
  460. _totalParticles = tp;
  461. }
  462. // fixed issue #5762
  463. // reset the emission rate
  464. setEmissionRate(_totalParticles / _life);
  465. resetSystem();
  466. }
  467. void ParticleSystemQuad::listenRendererRecreated(EventCustom* /*event*/)
  468. {
  469. //when comes to foreground in android, _buffersVBO and _VAOname is a wild handle
  470. //before recreating, we need to reset them to 0
  471. // memset(_buffersVBO, 0, sizeof(_buffersVBO));
  472. // if (Configuration::getInstance()->supportsShareableVAO())
  473. // {
  474. // _VAOname = 0;
  475. // setupVBOandVAO();
  476. // }
  477. // else
  478. // {
  479. // setupVBO();
  480. // }
  481. }
  482. bool ParticleSystemQuad::allocMemory()
  483. {
  484. CCASSERT( !_batchNode, "Memory should not be alloced when not using batchNode");
  485. CC_SAFE_FREE(_quads);
  486. CC_SAFE_FREE(_indices);
  487. _quads = (V3F_C4B_T2F_Quad*)malloc(_totalParticles * sizeof(V3F_C4B_T2F_Quad));
  488. _indices = (unsigned short*)malloc(_totalParticles * 6 * sizeof(unsigned short));
  489. if( !_quads || !_indices)
  490. {
  491. CCLOG("cocos2d: Particle system: not enough memory");
  492. CC_SAFE_FREE(_quads);
  493. CC_SAFE_FREE(_indices);
  494. return false;
  495. }
  496. memset(_quads, 0, _totalParticles * sizeof(V3F_C4B_T2F_Quad));
  497. memset(_indices, 0, _totalParticles * 6 * sizeof(unsigned short));
  498. return true;
  499. }
  500. void ParticleSystemQuad::setBatchNode(ParticleBatchNode * batchNode)
  501. {
  502. if( _batchNode != batchNode )
  503. {
  504. ParticleBatchNode* oldBatch = _batchNode;
  505. ParticleSystem::setBatchNode(batchNode);
  506. // NEW: is self render ?
  507. if( ! batchNode )
  508. {
  509. allocMemory();
  510. initIndices();
  511. setTexture(oldBatch->getTexture());
  512. // setupVBO();
  513. }
  514. // OLD: was it self render ? cleanup
  515. else if( !oldBatch )
  516. {
  517. // copy current state to batch
  518. V3F_C4B_T2F_Quad *batchQuads = _batchNode->getTextureAtlas()->getQuads();
  519. V3F_C4B_T2F_Quad *quad = &(batchQuads[_atlasIndex] );
  520. memcpy( quad, _quads, _totalParticles * sizeof(_quads[0]) );
  521. CC_SAFE_FREE(_quads);
  522. CC_SAFE_FREE(_indices);
  523. }
  524. }
  525. }
  526. ParticleSystemQuad * ParticleSystemQuad::create() {
  527. ParticleSystemQuad *particleSystemQuad = new (std::nothrow) ParticleSystemQuad();
  528. if (particleSystemQuad && particleSystemQuad->init())
  529. {
  530. particleSystemQuad->autorelease();
  531. return particleSystemQuad;
  532. }
  533. CC_SAFE_DELETE(particleSystemQuad);
  534. return nullptr;
  535. }
  536. std::string ParticleSystemQuad::getDescription() const
  537. {
  538. return StringUtils::format("<ParticleSystemQuad | Tag = %d, Total Particles = %d>", _tag, _totalParticles);
  539. }
  540. NS_CC_END