|
29 | 29 | cc.Node.WebGLRenderCmd.call(this, renderable); |
30 | 30 | this._needDraw = true; |
31 | 31 |
|
32 | | - this._uvs = [ |
33 | | - {u: 0, v: 0}, // tl |
34 | | - {u: 0, v: 0}, // bl |
35 | | - {u: 0, v: 0}, // tr |
36 | | - {u: 0, v: 0} // br |
| 32 | + this._vertices = [ |
| 33 | + {x: 0, y: 0, u: 0, v: 0}, // tl |
| 34 | + {x: 0, y: 0, u: 0, v: 0}, // bl |
| 35 | + {x: 0, y: 0, u: 0, v: 0}, // tr |
| 36 | + {x: 0, y: 0, u: 0, v: 0} // br |
37 | 37 | ]; |
38 | 38 | this._dirty = false; |
39 | 39 | this._recursiveDirty = false; |
|
44 | 44 | var proto = cc.Sprite.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype); |
45 | 45 | proto.constructor = cc.Sprite.WebGLRenderCmd; |
46 | 46 |
|
47 | | - // The following static properties must be provided for a auto batchable command |
48 | | - proto.vertexBytesPerUnit = cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT; |
49 | | - proto.bytesPerUnit = proto.vertexBytesPerUnit; |
50 | | - proto.indicesPerUnit = 6; |
51 | | - proto.verticesPerUnit = 4; |
52 | | - |
53 | 47 | proto.updateBlendFunc = function (blendFunc) {}; |
54 | 48 |
|
55 | 49 | proto.setDirtyFlag = function(dirtyFlag){ |
|
104 | 98 | }; |
105 | 99 |
|
106 | 100 | proto._textureLoadedCallback = function (sender) { |
107 | | - var renderCmd = this._renderCmd; |
108 | 101 | if (this._textureLoaded) |
109 | 102 | return; |
110 | 103 |
|
|
137 | 130 | var node = this._node; |
138 | 131 |
|
139 | 132 | var tex = node._batchNode ? node.textureAtlas.texture : node._texture; |
140 | | - var uvs = this._uvs; |
| 133 | + var uvs = this._vertices; |
141 | 134 | if (!tex) |
142 | 135 | return; |
143 | 136 |
|
|
280 | 273 | } |
281 | 274 | }; |
282 | 275 |
|
| 276 | + proto.transform = function (parentCmd, recursive) { |
| 277 | + this.originTransform(parentCmd, recursive); |
| 278 | + |
| 279 | + var node = this._node, |
| 280 | + lx = node._offsetPosition.x, rx = lx + node._rect.width, |
| 281 | + by = node._offsetPosition.y, ty = by + node._rect.height, |
| 282 | + wt = this._worldTransform; |
| 283 | + |
| 284 | + var vertices = this._vertices; |
| 285 | + vertices[0].x = lx * wt.a + ty * wt.c + wt.tx; // tl |
| 286 | + vertices[0].y = lx * wt.b + ty * wt.d + wt.ty; |
| 287 | + vertices[1].x = lx * wt.a + by * wt.c + wt.tx; // bl |
| 288 | + vertices[1].y = lx * wt.b + by * wt.d + wt.ty; |
| 289 | + vertices[2].x = rx * wt.a + ty * wt.c + wt.tx; // tr |
| 290 | + vertices[2].y = rx * wt.b + ty * wt.d + wt.ty; |
| 291 | + vertices[3].x = rx * wt.a + by * wt.c + wt.tx; // br |
| 292 | + vertices[3].y = rx * wt.b + by * wt.d + wt.ty; |
| 293 | + }; |
| 294 | + |
283 | 295 | proto.needDraw = function () { |
284 | 296 | var node = this._node, locTexture = node._texture; |
285 | 297 | return (this._needDraw && locTexture); |
|
290 | 302 | if (!(locTexture && locTexture._textureLoaded && node._rect.width && node._rect.height) || !this._displayedOpacity) |
291 | 303 | return false; |
292 | 304 |
|
293 | | - var lx = node._offsetPosition.x, rx = lx + node._rect.width, |
294 | | - by = node._offsetPosition.y, ty = by + node._rect.height, |
295 | | - wt = this._worldTransform; |
296 | | - |
297 | | - offset = vertexDataOffset; |
298 | | - |
299 | | - f32buffer[offset] = lx * wt.a + ty * wt.c + wt.tx; // tl |
300 | | - f32buffer[offset + 1] = lx * wt.b + ty * wt.d + wt.ty; |
301 | | - f32buffer[offset + 6] = lx * wt.a + by * wt.c + wt.tx; // bl |
302 | | - f32buffer[offset + 7] = lx * wt.b + by * wt.d + wt.ty; |
303 | | - f32buffer[offset + 12] = rx * wt.a + ty * wt.c + wt.tx; // tr |
304 | | - f32buffer[offset + 13] = rx * wt.b + ty * wt.d + wt.ty; |
305 | | - f32buffer[offset + 18] = rx * wt.a + by * wt.c + wt.tx; // br |
306 | | - f32buffer[offset + 19] = rx * wt.b + by * wt.d + wt.ty; |
| 305 | + var vertices = this._vertices; |
| 306 | + var visibleRect = cc.view._visibleRect; |
| 307 | + var tl = vertices[0], bl = vertices[1], tr = vertices[2], br = vertices[3]; |
| 308 | + if (Math.max(tl.x, bl.x, tr.x, br.x) < visibleRect.x || |
| 309 | + Math.max(tl.y, bl.y, tr.y, br.y) < visibleRect.y || |
| 310 | + Math.min(tl.x, bl.x, tr.x, br.x) > visibleRect.x + visibleRect.width || |
| 311 | + Math.min(tl.y, bl.y, tr.y, br.y) > visibleRect.y + visibleRect.height) { |
| 312 | + return false; |
| 313 | + } |
307 | 314 |
|
308 | 315 | // Fill in vertex data with quad information (4 vertices for sprite) |
309 | | - var uvs = this._uvs; |
310 | | - var opacity = Math.floor(this._displayedOpacity); |
| 316 | + var opacity = this._displayedOpacity; |
311 | 317 | var r = this._displayedColor.r, |
312 | 318 | g = this._displayedColor.g, |
313 | 319 | b = this._displayedColor.b; |
|
318 | 324 | b *= a; |
319 | 325 | } |
320 | 326 |
|
321 | | - var i, len = uvs.length, offset, uv, colorView; |
| 327 | + var i, len = vertices.length, vertex, offset = vertexDataOffset; |
322 | 328 | for (i = 0; i < len; ++i) { |
323 | 329 | offset = vertexDataOffset + i * 6; |
324 | | - uv = uvs[i]; |
| 330 | + vertex = vertices[i]; |
| 331 | + f32buffer[offset] = vertex.x; |
| 332 | + f32buffer[offset + 1] = vertex.y; |
325 | 333 | f32buffer[offset + 2] = node._vertexZ; |
326 | | - f32buffer[offset + 4] = uv.u; |
327 | | - f32buffer[offset + 5] = uv.v; |
328 | | - |
329 | 334 | ui32buffer[offset + 3] = ((opacity<<24) | (b<<16) | (g<<8) | r); |
| 335 | + f32buffer[offset + 4] = vertex.u; |
| 336 | + f32buffer[offset + 5] = vertex.v; |
330 | 337 | } |
331 | 338 |
|
332 | 339 | return true; |
|
0 commit comments