SpritesWebGL.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2011-2012 cocos2d-x.org
  4. Copyright (c) 2013-2014 Chukong Technologies Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of _t software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. cc._tmp.WebGLSprite = function () {
  23. var _p = cc.Sprite.prototype;
  24. _p._spriteFrameLoadedCallback = function(spriteFrame){
  25. this.setNodeDirty(true);
  26. this.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
  27. this._callLoadedEventCallbacks();
  28. };
  29. _p.setOpacityModifyRGB = function (modify) {
  30. if (this._opacityModifyRGB !== modify) {
  31. this._opacityModifyRGB = modify;
  32. this.updateColor();
  33. }
  34. };
  35. _p.updateDisplayedOpacity = function (parentOpacity) {
  36. cc.Node.prototype.updateDisplayedOpacity.call(this, parentOpacity);
  37. this.updateColor();
  38. };
  39. _p.ctor = function (fileName, rect, rotated) {
  40. var self = this;
  41. cc.Node.prototype.ctor.call(self);
  42. self._shouldBeHidden = false;
  43. self._offsetPosition = cc.p(0, 0);
  44. self._unflippedOffsetPositionFromCenter = cc.p(0, 0);
  45. self._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST};
  46. self._rect = cc.rect(0,0,0,0);
  47. self._quad = new cc.V3F_C4B_T2F_Quad();
  48. self._quadWebBuffer = cc._renderContext.createBuffer();
  49. self._quadDirty = true;
  50. self._textureLoaded = true;
  51. self._softInit(fileName, rect, rotated);
  52. };
  53. _p.setBlendFunc = function (src, dst) {
  54. var locBlendFunc = this._blendFunc;
  55. if (dst === undefined) {
  56. locBlendFunc.src = src.src;
  57. locBlendFunc.dst = src.dst;
  58. } else {
  59. locBlendFunc.src = src;
  60. locBlendFunc.dst = dst;
  61. }
  62. };
  63. _p.init = function () {
  64. var _t = this;
  65. if (arguments.length > 0)
  66. return _t.initWithFile(arguments[0], arguments[1]);
  67. cc.Node.prototype.init.call(_t);
  68. _t.dirty = _t._recursiveDirty = false;
  69. _t._opacityModifyRGB = true;
  70. _t._blendFunc.src = cc.BLEND_SRC;
  71. _t._blendFunc.dst = cc.BLEND_DST;
  72. // update texture (calls _updateBlendFunc)
  73. _t.texture = null;
  74. _t._textureLoaded = true;
  75. _t._flippedX = _t._flippedY = false;
  76. // default transform anchor: center
  77. _t.anchorX = 0.5;
  78. _t.anchorY = 0.5;
  79. // zwoptex default values
  80. _t._offsetPosition.x = 0;
  81. _t._offsetPosition.y = 0;
  82. _t._hasChildren = false;
  83. // Atlas: Color
  84. var tempColor = {r: 255, g: 255, b: 255, a: 255};
  85. _t._quad.bl.colors = tempColor;
  86. _t._quad.br.colors = tempColor;
  87. _t._quad.tl.colors = tempColor;
  88. _t._quad.tr.colors = tempColor;
  89. _t._quadDirty = true;
  90. // updated in "useSelfRender"
  91. // Atlas: TexCoords
  92. _t.setTextureRect(cc.rect(0, 0, 0, 0), false, cc.size(0, 0));
  93. return true;
  94. };
  95. _p.initWithTexture = function (texture, rect, rotated) {
  96. var _t = this;
  97. var argnum = arguments.length;
  98. cc.assert(argnum!=0, cc._LogInfos.Sprite_initWithTexture);
  99. rotated = rotated || false;
  100. if (!cc.Node.prototype.init.call(_t))
  101. return false;
  102. _t._batchNode = null;
  103. _t._recursiveDirty = false;
  104. _t.dirty = false;
  105. _t._opacityModifyRGB = true;
  106. _t._blendFunc.src = cc.BLEND_SRC;
  107. _t._blendFunc.dst = cc.BLEND_DST;
  108. _t._flippedX = _t._flippedY = false;
  109. // default transform anchor: center
  110. _t.anchorX = 0.5;
  111. _t.anchorY = 0.5;
  112. // zwoptex default values
  113. _t._offsetPosition.x = 0;
  114. _t._offsetPosition.y = 0;
  115. _t._hasChildren = false;
  116. // Atlas: Color
  117. var tmpColor = cc.color(255, 255, 255, 255);
  118. var locQuad = _t._quad;
  119. locQuad.bl.colors = tmpColor;
  120. locQuad.br.colors = tmpColor;
  121. locQuad.tl.colors = tmpColor;
  122. locQuad.tr.colors = tmpColor;
  123. var locTextureLoaded = texture.isLoaded();
  124. _t._textureLoaded = locTextureLoaded;
  125. if (!locTextureLoaded) {
  126. _t._rectRotated = rotated || false;
  127. if (rect) {
  128. var locRect = _t._rect;
  129. locRect.x = rect.x;
  130. locRect.y = rect.y;
  131. locRect.width = rect.width;
  132. locRect.height = rect.height;
  133. }
  134. texture.addLoadedEventListener(_t._textureLoadedCallback, _t);
  135. return true;
  136. }
  137. if (!rect) {
  138. rect = cc.rect(0, 0, texture.width, texture.height);
  139. }
  140. if(texture && texture.url) {
  141. var _x, _y;
  142. if(rotated){
  143. _x = rect.x + rect.height;
  144. _y = rect.y + rect.width;
  145. }else{
  146. _x = rect.x + rect.width;
  147. _y = rect.y + rect.height;
  148. }
  149. if(_x > texture.width){
  150. cc.error(cc._LogInfos.RectWidth, texture.url);
  151. }
  152. if(_y > texture.height){
  153. cc.error(cc._LogInfos.RectHeight, texture.url);
  154. }
  155. }
  156. _t.texture = texture;
  157. _t.setTextureRect(rect, rotated);
  158. // by default use "Self Render".
  159. // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
  160. _t.batchNode = null;
  161. _t._quadDirty = true;
  162. return true;
  163. };
  164. _p._textureLoadedCallback = function (sender) {
  165. var _t = this;
  166. if(_t._textureLoaded)
  167. return;
  168. _t._textureLoaded = true;
  169. var locRect = _t._rect;
  170. if (!locRect) {
  171. locRect = cc.rect(0, 0, sender.width, sender.height);
  172. } else if (cc._rectEqualToZero(locRect)) {
  173. locRect.width = sender.width;
  174. locRect.height = sender.height;
  175. }
  176. _t.texture = sender;
  177. _t.setTextureRect(locRect, _t._rectRotated);
  178. // by default use "Self Render".
  179. // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
  180. _t.batchNode = _t._batchNode;
  181. _t._quadDirty = true;
  182. _t._callLoadedEventCallbacks();
  183. };
  184. _p.setTextureRect = function (rect, rotated, untrimmedSize) {
  185. var _t = this;
  186. _t._rectRotated = rotated || false;
  187. _t.setContentSize(untrimmedSize || rect);
  188. _t.setVertexRect(rect);
  189. _t._setTextureCoords(rect);
  190. var relativeOffset = _t._unflippedOffsetPositionFromCenter;
  191. if (_t._flippedX)
  192. relativeOffset.x = -relativeOffset.x;
  193. if (_t._flippedY)
  194. relativeOffset.y = -relativeOffset.y;
  195. var locRect = _t._rect;
  196. _t._offsetPosition.x = relativeOffset.x + (_t._contentSize.width - locRect.width) / 2;
  197. _t._offsetPosition.y = relativeOffset.y + (_t._contentSize.height - locRect.height) / 2;
  198. // rendering using batch node
  199. if (_t._batchNode) {
  200. // update dirty, don't update _recursiveDirty
  201. _t.dirty = true;
  202. } else {
  203. // self rendering
  204. // Atlas: Vertex
  205. var x1 = 0 + _t._offsetPosition.x;
  206. var y1 = 0 + _t._offsetPosition.y;
  207. var x2 = x1 + locRect.width;
  208. var y2 = y1 + locRect.height;
  209. // Don't update Z.
  210. var locQuad = _t._quad;
  211. locQuad.bl.vertices = {x:x1, y:y1, z:0};
  212. locQuad.br.vertices = {x:x2, y:y1, z:0};
  213. locQuad.tl.vertices = {x:x1, y:y2, z:0};
  214. locQuad.tr.vertices = {x:x2, y:y2, z:0};
  215. _t._quadDirty = true;
  216. }
  217. };
  218. _p.updateTransform = function () {
  219. var _t = this;
  220. //cc.assert(_t._batchNode, "updateTransform is only valid when cc.Sprite is being rendered using an cc.SpriteBatchNode");
  221. // recaculate matrix only if it is dirty
  222. if (_t.dirty) {
  223. var locQuad = _t._quad, locParent = _t._parent;
  224. // If it is not visible, or one of its ancestors is not visible, then do nothing:
  225. if (!_t._visible || ( locParent && locParent != _t._batchNode && locParent._shouldBeHidden)) {
  226. locQuad.br.vertices = locQuad.tl.vertices = locQuad.tr.vertices = locQuad.bl.vertices = {x: 0, y: 0, z: 0};
  227. _t._shouldBeHidden = true;
  228. } else {
  229. _t._shouldBeHidden = false;
  230. if (!locParent || locParent == _t._batchNode) {
  231. _t._transformToBatch = _t.nodeToParentTransform();
  232. } else {
  233. //cc.assert(_t._parent instanceof cc.Sprite, "Logic error in CCSprite. Parent must be a CCSprite");
  234. _t._transformToBatch = cc.affineTransformConcat(_t.nodeToParentTransform(), locParent._transformToBatch);
  235. }
  236. //
  237. // calculate the Quad based on the Affine Matrix
  238. //
  239. var locTransformToBatch = _t._transformToBatch;
  240. var rect = _t._rect;
  241. var x1 = _t._offsetPosition.x;
  242. var y1 = _t._offsetPosition.y;
  243. var x2 = x1 + rect.width;
  244. var y2 = y1 + rect.height;
  245. var x = locTransformToBatch.tx;
  246. var y = locTransformToBatch.ty;
  247. var cr = locTransformToBatch.a;
  248. var sr = locTransformToBatch.b;
  249. var cr2 = locTransformToBatch.d;
  250. var sr2 = -locTransformToBatch.c;
  251. var ax = x1 * cr - y1 * sr2 + x;
  252. var ay = x1 * sr + y1 * cr2 + y;
  253. var bx = x2 * cr - y1 * sr2 + x;
  254. var by = x2 * sr + y1 * cr2 + y;
  255. var cx = x2 * cr - y2 * sr2 + x;
  256. var cy = x2 * sr + y2 * cr2 + y;
  257. var dx = x1 * cr - y2 * sr2 + x;
  258. var dy = x1 * sr + y2 * cr2 + y;
  259. var locVertexZ = _t._vertexZ;
  260. if(!cc.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
  261. ax = 0 | ax;
  262. ay = 0 | ay;
  263. bx = 0 | bx;
  264. by = 0 | by;
  265. cx = 0 | cx;
  266. cy = 0 | cy;
  267. dx = 0 | dx;
  268. dy = 0 | dy;
  269. }
  270. locQuad.bl.vertices = {x: ax, y: ay, z: locVertexZ};
  271. locQuad.br.vertices = {x: bx, y: by, z: locVertexZ};
  272. locQuad.tl.vertices = {x: dx, y: dy, z: locVertexZ};
  273. locQuad.tr.vertices = {x: cx, y: cy, z: locVertexZ};
  274. }
  275. _t.textureAtlas.updateQuad(locQuad, _t.atlasIndex);
  276. _t._recursiveDirty = false;
  277. _t.dirty = false;
  278. }
  279. // recursively iterate over children
  280. if (_t._hasChildren)
  281. _t._arrayMakeObjectsPerformSelector(_t._children, cc.Node._StateCallbackType.updateTransform);
  282. if (cc.SPRITE_DEBUG_DRAW) {
  283. // draw bounding box
  284. var vertices = [
  285. cc.p(_t._quad.bl.vertices.x, _t._quad.bl.vertices.y),
  286. cc.p(_t._quad.br.vertices.x, _t._quad.br.vertices.y),
  287. cc.p(_t._quad.tr.vertices.x, _t._quad.tr.vertices.y),
  288. cc.p(_t._quad.tl.vertices.x, _t._quad.tl.vertices.y)
  289. ];
  290. cc._drawingUtil.drawPoly(vertices, 4, true);
  291. }
  292. };
  293. _p.addChild = function (child, localZOrder, tag) {
  294. var _t = this;
  295. cc.assert(child, cc._LogInfos.Sprite_addChild_3);
  296. if (localZOrder == null)
  297. localZOrder = child._localZOrder;
  298. if (tag == null)
  299. tag = child.tag;
  300. if (_t._batchNode) {
  301. if(!(child instanceof cc.Sprite)){
  302. cc.log(cc._LogInfos.Sprite_addChild);
  303. return;
  304. }
  305. if(child.texture._webTextureObj !== _t.textureAtlas.texture._webTextureObj)
  306. cc.log(cc._LogInfos.Sprite_addChild_2);
  307. //put it in descendants array of batch node
  308. _t._batchNode.appendChild(child);
  309. if (!_t._reorderChildDirty)
  310. _t._setReorderChildDirtyRecursively();
  311. }
  312. //cc.Node already sets isReorderChildDirty_ so _t needs to be after batchNode check
  313. cc.Node.prototype.addChild.call(_t, child, localZOrder, tag);
  314. _t._hasChildren = true;
  315. };
  316. _p.setOpacity = function (opacity) {
  317. cc.Node.prototype.setOpacity.call(this, opacity);
  318. this.updateColor();
  319. };
  320. _p.setColor = function (color3) {
  321. cc.Node.prototype.setColor.call(this, color3);
  322. this.updateColor();
  323. };
  324. _p.updateDisplayedColor = function (parentColor) {
  325. cc.Node.prototype.updateDisplayedColor.call(this, parentColor);
  326. this.updateColor();
  327. };
  328. _p.setSpriteFrame = function (newFrame) {
  329. var _t = this;
  330. if(typeof(newFrame) == "string"){
  331. newFrame = cc.spriteFrameCache.getSpriteFrame(newFrame);
  332. cc.assert(newFrame, cc._LogInfos.Sprite_setSpriteFrame);
  333. }
  334. _t.setNodeDirty(true);
  335. var frameOffset = newFrame.getOffset();
  336. _t._unflippedOffsetPositionFromCenter.x = frameOffset.x;
  337. _t._unflippedOffsetPositionFromCenter.y = frameOffset.y;
  338. var pNewTexture = newFrame.getTexture();
  339. var locTextureLoaded = newFrame.textureLoaded();
  340. if (!locTextureLoaded) {
  341. _t._textureLoaded = false;
  342. newFrame.addLoadedEventListener(function (sender) {
  343. _t._textureLoaded = true;
  344. var locNewTexture = sender.getTexture();
  345. if (locNewTexture != _t._texture)
  346. _t.texture = locNewTexture;
  347. _t.setTextureRect(sender.getRect(), sender.isRotated(), sender.getOriginalSize());
  348. _t._callLoadedEventCallbacks();
  349. }, _t);
  350. }
  351. // update texture before updating texture rect
  352. if (pNewTexture != _t._texture)
  353. _t.texture = pNewTexture;
  354. // update rect
  355. _t._rectRotated = newFrame.isRotated();
  356. _t.setTextureRect(newFrame.getRect(), _t._rectRotated, newFrame.getOriginalSize());
  357. };
  358. _p.isFrameDisplayed = function (frame) {
  359. return (cc.rectEqualToRect(frame.getRect(), this._rect) && frame.getTexture().getName() == this._texture.getName()
  360. && cc.pointEqualToPoint(frame.getOffset(), this._unflippedOffsetPositionFromCenter));
  361. };
  362. _p.setBatchNode = function (spriteBatchNode) {
  363. var _t = this;
  364. _t._batchNode = spriteBatchNode; // weak reference
  365. // self render
  366. if (!_t._batchNode) {
  367. _t.atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED;
  368. _t.textureAtlas = null;
  369. _t._recursiveDirty = false;
  370. _t.dirty = false;
  371. var x1 = _t._offsetPosition.x;
  372. var y1 = _t._offsetPosition.y;
  373. var x2 = x1 + _t._rect.width;
  374. var y2 = y1 + _t._rect.height;
  375. var locQuad = _t._quad;
  376. locQuad.bl.vertices = {x:x1, y:y1, z:0};
  377. locQuad.br.vertices = {x:x2, y:y1, z:0};
  378. locQuad.tl.vertices = {x:x1, y:y2, z:0};
  379. locQuad.tr.vertices = {x:x2, y:y2, z:0};
  380. _t._quadDirty = true;
  381. } else {
  382. // using batch
  383. _t._transformToBatch = cc.affineTransformIdentity();
  384. _t.textureAtlas = _t._batchNode.textureAtlas; // weak ref
  385. }
  386. };
  387. _p.setTexture = function (texture) {
  388. var _t = this;
  389. if(texture && (typeof(texture) === "string")){
  390. texture = cc.textureCache.addImage(texture);
  391. _t.setTexture(texture);
  392. //TODO
  393. var size = texture.getContentSize();
  394. _t.setTextureRect(cc.rect(0,0, size.width, size.height));
  395. return;
  396. }
  397. // CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteSheet
  398. cc.assert(!texture || (texture instanceof cc.Texture2D), cc._LogInfos.Sprite_setTexture_2);
  399. // If batchnode, then texture id should be the same
  400. if(_t._batchNode && _t._batchNode.texture != texture) {
  401. cc.log(cc._LogInfos.Sprite_setTexture);
  402. return;
  403. }
  404. if (texture)
  405. _t.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR);
  406. else
  407. _t.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_COLOR);
  408. if (!_t._batchNode && _t._texture != texture) {
  409. _t._texture = texture;
  410. _t._updateBlendFunc();
  411. }
  412. };
  413. _p.draw = function () {
  414. var _t = this;
  415. if (!_t._textureLoaded)
  416. return;
  417. var gl = cc._renderContext, locTexture = _t._texture;
  418. //cc.assert(!_t._batchNode, "If cc.Sprite is being rendered by cc.SpriteBatchNode, cc.Sprite#draw SHOULD NOT be called");
  419. if (locTexture) {
  420. if (locTexture._isLoaded) {
  421. _t._shaderProgram.use();
  422. _t._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
  423. cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst);
  424. //optimize performance for javascript
  425. cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
  426. cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
  427. gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadWebBuffer);
  428. if (_t._quadDirty) {
  429. gl.bufferData(gl.ARRAY_BUFFER, _t._quad.arrayBuffer, gl.DYNAMIC_DRAW);
  430. _t._quadDirty = false;
  431. }
  432. gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.VERTEX_ATTRIB_POSITION
  433. gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.VERTEX_ATTRIB_COLOR
  434. gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.VERTEX_ATTRIB_TEX_COORDS
  435. gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  436. }
  437. } else {
  438. _t._shaderProgram.use();
  439. _t._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
  440. cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst);
  441. cc.glBindTexture2D(null);
  442. cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR);
  443. gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadWebBuffer);
  444. if (_t._quadDirty) {
  445. cc._renderContext.bufferData(cc._renderContext.ARRAY_BUFFER, _t._quad.arrayBuffer, cc._renderContext.STATIC_DRAW);
  446. _t._quadDirty = false;
  447. }
  448. gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0);
  449. gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12);
  450. gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  451. }
  452. cc.g_NumberOfDraws++;
  453. if (cc.SPRITE_DEBUG_DRAW === 0 && !_t._showNode)
  454. return;
  455. if (cc.SPRITE_DEBUG_DRAW === 1 || _t._showNode) {
  456. // draw bounding box
  457. var locQuad = _t._quad;
  458. var verticesG1 = [
  459. cc.p(locQuad.tl.vertices.x, locQuad.tl.vertices.y),
  460. cc.p(locQuad.bl.vertices.x, locQuad.bl.vertices.y),
  461. cc.p(locQuad.br.vertices.x, locQuad.br.vertices.y),
  462. cc.p(locQuad.tr.vertices.x, locQuad.tr.vertices.y)
  463. ];
  464. cc._drawingUtil.drawPoly(verticesG1, 4, true);
  465. } else if (cc.SPRITE_DEBUG_DRAW === 2) {
  466. // draw texture box
  467. var drawRectG2 = _t.getTextureRect();
  468. var offsetPixG2 = _t.getOffsetPosition();
  469. var verticesG2 = [cc.p(offsetPixG2.x, offsetPixG2.y), cc.p(offsetPixG2.x + drawRectG2.width, offsetPixG2.y),
  470. cc.p(offsetPixG2.x + drawRectG2.width, offsetPixG2.y + drawRectG2.height), cc.p(offsetPixG2.x, offsetPixG2.y + drawRectG2.height)];
  471. cc._drawingUtil.drawPoly(verticesG2, 4, true);
  472. } // CC_SPRITE_DEBUG_DRAW
  473. };
  474. delete _p;
  475. }