|
25 | 25 | //Sprite's WebGL render command
|
26 | 26 | (function() {
|
27 | 27 |
|
| 28 | + var _resetPointers = true; |
| 29 | + |
28 | 30 | cc.Sprite.WebGLRenderCmd = function (renderable) {
|
29 | 31 | cc.Node.WebGLRenderCmd.call(this, renderable);
|
30 | 32 | this._needDraw = true;
|
|
48 | 50 | // this._bufferOffset = 0;
|
49 | 51 | // this._quad = new cc.V3F_C4B_T2F_Quad(null, null, null, null, this._buffer, this._bufferOffset);
|
50 | 52 | // this._float32View = new Float32Array(this._buffer, this._bufferOffset, length / 4);
|
51 |
| - // Init buffer |
| 53 | + // this._uint32View = new Uint32Array(this._buffer, this._bufferOffset, length / 4); |
| 54 | + // // Init buffer |
52 | 55 | // var gl = cc._renderContext;
|
53 | 56 | // this._glBuffer = gl.createBuffer();
|
54 | 57 | // gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
|
|
534 | 537 |
|
535 | 538 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
536 | 539 | //optimize performance for javascript
|
537 |
| - cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture); |
538 |
| - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); |
| 540 | + cc.glBindTexture2DN(0, locTexture); |
539 | 541 |
|
540 |
| - gl.bindBuffer(gl.ARRAY_BUFFER, this._buffer.vertexBuffer); |
| 542 | + var _bufferchanged = !gl.bindBuffer(gl.ARRAY_BUFFER, this._buffer.vertexBuffer); |
541 | 543 | // if (this._bufferDirty) {
|
542 | 544 | // gl.bufferSubData(gl.ARRAY_BUFFER, this._bufferOffset, this._float32View);
|
543 | 545 | // this._bufferDirty = false;
|
544 | 546 | // }
|
545 |
| - gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, this._bufferOffset); //cc.VERTEX_ATTRIB_POSITION |
546 |
| - gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, this._bufferOffset + 12); //cc.VERTEX_ATTRIB_COLOR |
547 |
| - gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, this._bufferOffset + 16); //cc.VERTEX_ATTRIB_TEX_COORDS |
548 |
| - gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); |
| 547 | + if (_resetPointers || _bufferchanged) { |
| 548 | + cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); |
| 549 | + gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); |
| 550 | + gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); |
| 551 | + gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); |
| 552 | + } |
| 553 | + gl.drawArrays(gl.TRIANGLE_STRIP, this._bufferOffset / (this.vertexBytesPerUnit/4), 4); |
549 | 554 | }
|
550 | 555 | } else {
|
551 | 556 | program.use();
|
552 | 557 | program._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
553 | 558 |
|
554 | 559 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
555 |
| - cc.glBindTexture2D(null); |
556 |
| - |
557 |
| - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); |
558 | 560 |
|
559 | 561 | gl.bindBuffer(gl.ARRAY_BUFFER, this._buffer.vertexBuffer);
|
560 | 562 | // if (this._bufferDirty) {
|
561 | 563 | // gl.bufferSubData(gl.ARRAY_BUFFER, this._bufferOffset, this._float32View);
|
562 | 564 | // this._bufferDirty = false;
|
563 | 565 | // }
|
564 |
| - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, this._bufferOffset); |
565 |
| - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, this._bufferOffset + 12); |
566 |
| - gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); |
| 566 | + cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); |
| 567 | + gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); |
| 568 | + gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); |
| 569 | + gl.drawArrays(gl.TRIANGLE_STRIP, this._bufferOffset / (this.vertexBytesPerUnit/4), 4); |
| 570 | + _resetPointers = true; |
567 | 571 | }
|
568 | 572 | cc.g_NumberOfDraws++;
|
569 | 573 |
|
|
0 commit comments