phaser/v3/src/gameobjects/blitter/BlitterWebGLRenderer.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-02-21 19:21:03 +00:00
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
{
if (src.renderMask !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
{
return;
}
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;
var renderTarget = src.renderTarget;
// Render bobs
2017-02-21 19:21:03 +00:00
for (var i = 0, l = list.length; i < l; i++)
{
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;
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();
}
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-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-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-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-21 19:21:03 +00:00
vertexBuffer[vertexOffset++] = txw;
vertexBuffer[vertexOffset++] = ty;
vertexBuffer[vertexOffset++] = uvs.x3;
vertexBuffer[vertexOffset++] = uvs.y3;
vertexBuffer[vertexOffset++] = alpha;
}
};
module.exports = BlitterWebGLRenderer;