2017-02-21 19:21:03 +00:00
|
|
|
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
2017-01-22 22:54:06 +00:00
|
|
|
{
|
2017-08-15 22:51:37 +00:00
|
|
|
if (src.renderMask !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
|
2017-02-23 03:54:54 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-13 23:57:32 +00:00
|
|
|
var list = src.getRenderList();
|
2017-02-21 19:21:03 +00:00
|
|
|
var blitterBatch = renderer.blitterBatch;
|
|
|
|
var cameraMatrix = camera.matrix.matrix;
|
|
|
|
var a = cameraMatrix[0];
|
|
|
|
var b = cameraMatrix[1];
|
|
|
|
var c = cameraMatrix[2];
|
|
|
|
var d = cameraMatrix[3];
|
|
|
|
var e = cameraMatrix[4];
|
|
|
|
var f = cameraMatrix[5];
|
2017-06-22 02:19:03 +00:00
|
|
|
var cameraScrollX = camera.scrollX * src.scrollFactorX;
|
|
|
|
var cameraScrollY = camera.scrollY * src.scrollFactorY;
|
2017-04-13 15:45:01 +00:00
|
|
|
var renderTarget = src.renderTarget;
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-01 00:43:38 +00:00
|
|
|
// Render bobs
|
2017-02-13 21:50:41 +00:00
|
|
|
|
2017-02-21 19:21:03 +00:00
|
|
|
for (var i = 0, l = list.length; i < l; i++)
|
2017-01-22 22:54:06 +00:00
|
|
|
{
|
2017-02-13 23:57:32 +00:00
|
|
|
var bob = list[i];
|
2017-02-21 19:21:03 +00:00
|
|
|
var frame = bob.frame;
|
|
|
|
var alpha = bob.alpha;
|
|
|
|
var vertexDataBuffer = blitterBatch.vertexDataBuffer;
|
|
|
|
var vertexBuffer = vertexDataBuffer.floatView;
|
|
|
|
var vertexOffset = 0;
|
|
|
|
var uvs = frame.uvs;
|
2017-03-20 23:37:17 +00:00
|
|
|
var width = frame.width * (bob.flipX ? -1 : 1);
|
|
|
|
var height = frame.height * (bob.flipY ? -1 : 1);
|
|
|
|
var x = bob.x + frame.x - cameraScrollX + ((frame.width) * (bob.flipX ? 1 : 0.0));
|
|
|
|
var y = bob.y + frame.y - cameraScrollY + ((frame.height) * (bob.flipY ? 1 : 0.0));
|
2017-02-21 19:21:03 +00:00
|
|
|
var xw = x + width;
|
|
|
|
var yh = y + height;
|
|
|
|
var tx = x * a + y * c + e;
|
|
|
|
var ty = x * b + y * d + f;
|
|
|
|
var txw = xw * a + yh * c + e;
|
|
|
|
var tyh = xw * b + yh * d + f;
|
|
|
|
|
|
|
|
if (blitterBatch.elementCount >= blitterBatch.maxParticles)
|
|
|
|
{
|
|
|
|
blitterBatch.flush();
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:45:01 +00:00
|
|
|
renderer.setRenderer(blitterBatch, frame.texture.source[frame.sourceIndex].glTexture, camera, renderTarget);
|
2017-02-21 19:21:03 +00:00
|
|
|
vertexOffset = vertexDataBuffer.allocate(20);
|
|
|
|
blitterBatch.elementCount += 6;
|
|
|
|
x += frame.x;
|
|
|
|
y += frame.y;
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-21 19:21:03 +00:00
|
|
|
vertexBuffer[vertexOffset++] = tx;
|
|
|
|
vertexBuffer[vertexOffset++] = ty;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.x0;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.y0;
|
|
|
|
vertexBuffer[vertexOffset++] = alpha;
|
2017-02-23 03:54:54 +00:00
|
|
|
|
2017-02-21 19:21:03 +00:00
|
|
|
vertexBuffer[vertexOffset++] = tx;
|
|
|
|
vertexBuffer[vertexOffset++] = tyh;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.x1;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.y1;
|
|
|
|
vertexBuffer[vertexOffset++] = alpha;
|
2017-02-23 03:54:54 +00:00
|
|
|
|
2017-02-21 19:21:03 +00:00
|
|
|
vertexBuffer[vertexOffset++] = txw;
|
|
|
|
vertexBuffer[vertexOffset++] = tyh;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.x2;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.y2;
|
|
|
|
vertexBuffer[vertexOffset++] = alpha;
|
2017-02-23 03:54:54 +00:00
|
|
|
|
2017-02-21 19:21:03 +00:00
|
|
|
vertexBuffer[vertexOffset++] = txw;
|
|
|
|
vertexBuffer[vertexOffset++] = ty;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.x3;
|
|
|
|
vertexBuffer[vertexOffset++] = uvs.y3;
|
|
|
|
vertexBuffer[vertexOffset++] = alpha;
|
2017-01-22 22:54:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BlitterWebGLRenderer;
|