2017-03-01 21:08:10 +00:00
|
|
|
var Commands = require('./Commands');
|
|
|
|
var Earcut = require('./earcut');
|
|
|
|
var pathArray = [];
|
|
|
|
var cos = Math.cos;
|
|
|
|
var sin = Math.sin;
|
2017-03-02 00:40:03 +00:00
|
|
|
var sqrt = Math.sqrt;
|
2017-03-01 21:08:10 +00:00
|
|
|
|
2017-03-02 02:06:37 +00:00
|
|
|
var Point = function (x, y)
|
2017-03-01 21:08:10 +00:00
|
|
|
{
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
};
|
|
|
|
|
2017-03-02 02:06:37 +00:00
|
|
|
var Path = function (x, y)
|
2017-03-01 21:08:10 +00:00
|
|
|
{
|
|
|
|
this.points = [];
|
2017-03-01 23:23:46 +00:00
|
|
|
this.pointsLength = 1;
|
|
|
|
this.points[0] = new Point(x, y);
|
2017-03-01 21:08:10 +00:00
|
|
|
};
|
|
|
|
|
2017-03-02 02:06:37 +00:00
|
|
|
var lerp = function (norm, min, max)
|
2017-03-01 21:08:10 +00:00
|
|
|
{
|
|
|
|
return (max - min) * norm + min;
|
|
|
|
};
|
|
|
|
|
2017-03-02 00:40:03 +00:00
|
|
|
var renderLine = function (
|
|
|
|
/* start and end of line */
|
2017-03-02 02:06:37 +00:00
|
|
|
ax, ay, bx, by,
|
2017-03-02 00:40:03 +00:00
|
|
|
/* buffers */
|
|
|
|
vertexBufferF32, vertexBufferU32, vertexDataBuffer,
|
|
|
|
/* camera scroll */
|
|
|
|
cameraScrollX, cameraScrollY,
|
|
|
|
/* Camera transform */
|
|
|
|
a, b, c, d, e, f,
|
|
|
|
/* line properties */
|
|
|
|
lineColor, lineAlpha, lineWidth,
|
|
|
|
/* vertex count and limits */
|
|
|
|
vertexCount, maxVertices,
|
|
|
|
/* batch */
|
|
|
|
shapeBatch,
|
|
|
|
/* Game Object transform */
|
|
|
|
srcX, srcY, srcScaleX, srcScaleY, srcRotation
|
2017-03-02 02:06:37 +00:00
|
|
|
)
|
2017-03-02 00:40:03 +00:00
|
|
|
{
|
|
|
|
if (vertexCount + 6 > maxVertices)
|
|
|
|
{
|
|
|
|
shapeBatch.flush();
|
|
|
|
vertexCount = 0;
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-02 00:40:03 +00:00
|
|
|
shapeBatch.vertexCount = vertexCount + 6;
|
|
|
|
|
|
|
|
ax -= cameraScrollX;
|
|
|
|
bx -= cameraScrollX;
|
|
|
|
ay -= cameraScrollY;
|
|
|
|
by -= cameraScrollY;
|
|
|
|
|
|
|
|
var vertexOffset = vertexDataBuffer.allocate(9 * 6);
|
|
|
|
var dx = bx - ax;
|
|
|
|
var dy = by - ay;
|
|
|
|
var len = sqrt(dx * dx + dy * dy);
|
|
|
|
var l0 = lineWidth * (by - ay) / len;
|
|
|
|
var l1 = lineWidth * (ax - bx) / len;
|
|
|
|
var lx0 = bx - l0;
|
|
|
|
var ly0 = by - l1;
|
|
|
|
var lx1 = ax - l0;
|
|
|
|
var ly1 = ay - l1;
|
|
|
|
var lx2 = bx + l0;
|
|
|
|
var ly2 = by + l1;
|
|
|
|
var lx3 = ax + l0;
|
|
|
|
var ly3 = ay + l1;
|
|
|
|
var x0 = lx0 * a + ly0 * c + e;
|
|
|
|
var y0 = lx0 * b + ly0 * d + f;
|
|
|
|
var x1 = lx1 * a + ly1 * c + e;
|
|
|
|
var y1 = lx1 * b + ly1 * d + f;
|
|
|
|
var x2 = lx2 * a + ly2 * c + e;
|
|
|
|
var y2 = lx2 * b + ly2 * d + f;
|
|
|
|
var x3 = lx3 * a + ly3 * c + e;
|
|
|
|
var y3 = lx3 * b + ly3 * d + f;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x0;
|
|
|
|
vertexBufferF32[vertexOffset++] = y0;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x1;
|
|
|
|
vertexBufferF32[vertexOffset++] = y1;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x2;
|
|
|
|
vertexBufferF32[vertexOffset++] = y2;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x1;
|
|
|
|
vertexBufferF32[vertexOffset++] = y1;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x3;
|
|
|
|
vertexBufferF32[vertexOffset++] = y3;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x2;
|
|
|
|
vertexBufferF32[vertexOffset++] = y2;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
return [
|
|
|
|
x0, y0,
|
|
|
|
x1, y1,
|
|
|
|
x2, y2,
|
|
|
|
x3, y3
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2017-02-28 14:49:39 +00:00
|
|
|
var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
|
|
|
{
|
|
|
|
if (this.renderMask !== this.renderFlags)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
var shapeBatch = renderer.shapeBatch;
|
|
|
|
var vertexDataBuffer = shapeBatch.vertexDataBuffer;
|
|
|
|
var vertexBufferF32 = vertexDataBuffer.floatView;
|
|
|
|
var vertexBufferU32 = vertexDataBuffer.uintView;
|
|
|
|
var vertexOffset = 0;
|
|
|
|
var cameraScrollX = camera.scrollX;
|
|
|
|
var cameraScrollY = camera.scrollY;
|
2017-03-02 02:06:37 +00:00
|
|
|
var srcX = src.x;
|
2017-03-01 21:08:10 +00:00
|
|
|
var srcY = src.y;
|
|
|
|
var srcScaleX = src.scaleX;
|
|
|
|
var srcScaleY = src.scaleY;
|
|
|
|
var srcRotation = src.rotation;
|
|
|
|
var commandBuffer = src.commandBuffer;
|
|
|
|
var value;
|
|
|
|
var lineAlpha = 1.0;
|
|
|
|
var fillAlpha = 1.0;
|
|
|
|
var lineColor = 0;
|
|
|
|
var fillColor = 0;
|
|
|
|
var lineWidth = 1.0;
|
|
|
|
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];
|
|
|
|
var lastPath = null;
|
|
|
|
var iteration = 0;
|
|
|
|
var iterStep = 0.01;
|
|
|
|
var tx = 0;
|
|
|
|
var ty = 0;
|
|
|
|
var ta = 0;
|
|
|
|
var x, y, radius, startAngle, endAngle, anticlockwise;
|
|
|
|
var width, height, txw, tyh;
|
|
|
|
var vertexCount = shapeBatch.vertexCount;
|
|
|
|
var polygon = [];
|
|
|
|
var x0, y0, x1, y1, x2, y2;
|
|
|
|
var tx0, ty0, tx1, ty1, tx2, ty2;
|
|
|
|
var v0, v1, v2;
|
|
|
|
var polygonIndex;
|
|
|
|
var path;
|
|
|
|
var pathLength;
|
|
|
|
var point;
|
2017-03-01 23:23:46 +00:00
|
|
|
var maxVertices = shapeBatch.maxVertices;
|
2017-03-01 21:08:10 +00:00
|
|
|
|
|
|
|
renderer.setBatch(shapeBatch, null);
|
|
|
|
|
|
|
|
for (var cmdIndex = 0, cmdLength = commandBuffer.length; cmdIndex < cmdLength; ++cmdIndex)
|
|
|
|
{
|
|
|
|
var cmd = commandBuffer[cmdIndex];
|
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case Commands.ARC:
|
|
|
|
x = commandBuffer[cmdIndex + 1];
|
|
|
|
y = commandBuffer[cmdIndex + 2];
|
|
|
|
radius = commandBuffer[cmdIndex + 3];
|
|
|
|
startAngle = commandBuffer[cmdIndex + 4];
|
|
|
|
endAngle = commandBuffer[cmdIndex + 5];
|
|
|
|
anticlockwise = commandBuffer[cmdIndex + 6];
|
|
|
|
|
2017-03-02 02:06:37 +00:00
|
|
|
while (iteration < 1)
|
|
|
|
{
|
2017-03-01 21:08:10 +00:00
|
|
|
ta = lerp(iteration, startAngle, endAngle);
|
|
|
|
tx = x + cos(ta) * radius;
|
|
|
|
ty = y + sin(ta) * radius;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
if (iteration === 0)
|
|
|
|
{
|
2017-03-01 21:08:10 +00:00
|
|
|
lastPath = new Path(tx, ty);
|
|
|
|
pathArray.push(lastPath);
|
2017-03-02 02:06:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-01 21:08:10 +00:00
|
|
|
lastPath.points.push(new Point(tx, ty));
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
iteration += iterStep;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdIndex += 6;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.LINE_STYLE:
|
|
|
|
lineWidth = commandBuffer[cmdIndex + 1];
|
2017-03-02 02:06:37 +00:00
|
|
|
lineColor = commandBuffer[cmdIndex + 2];
|
2017-03-01 21:08:10 +00:00
|
|
|
lineAlpha = commandBuffer[cmdIndex + 3];
|
|
|
|
cmdIndex += 3;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.FILL_STYLE:
|
|
|
|
fillColor = commandBuffer[cmdIndex + 1];
|
|
|
|
fillAlpha = commandBuffer[cmdIndex + 2];
|
|
|
|
cmdIndex += 2;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.BEGIN_PATH:
|
|
|
|
pathArray.length = 0;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.CLOSE_PATH:
|
2017-03-02 02:06:37 +00:00
|
|
|
if (lastPath !== null && lastPath.points.length > 0)
|
|
|
|
{
|
2017-03-01 21:08:10 +00:00
|
|
|
var firstPoint = lastPath.points[0];
|
2017-03-02 02:06:37 +00:00
|
|
|
// var lastPoint = lastPath.points[lastPath.points.length - 1];
|
2017-03-01 21:08:10 +00:00
|
|
|
lastPath.points.push(firstPoint);
|
|
|
|
lastPath = new Path(x, y);
|
|
|
|
pathArray.push(lastPath);
|
|
|
|
}
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.FILL_PATH:
|
2017-03-02 02:06:37 +00:00
|
|
|
for (var pathArrayIndex = 0, pathArrayLength = pathArray.length;
|
|
|
|
pathArrayIndex < pathArrayLength;
|
|
|
|
++pathArrayIndex)
|
2017-03-01 21:08:10 +00:00
|
|
|
{
|
|
|
|
path = pathArray[pathArrayIndex].points;
|
|
|
|
pathLength = path.length;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
for (var pathIndex = 0;
|
|
|
|
pathIndex < pathLength;
|
2017-03-01 23:23:46 +00:00
|
|
|
++pathIndex)
|
2017-03-01 21:08:10 +00:00
|
|
|
{
|
|
|
|
point = path[pathIndex];
|
|
|
|
polygon.push(point.x, point.y);
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
polygonIndex = Earcut(polygon);
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
for (var index = 0, length = polygonIndex.length; index < length; index += 3)
|
2017-03-01 21:08:10 +00:00
|
|
|
{
|
|
|
|
v0 = polygonIndex[index + 0] * 2;
|
|
|
|
v1 = polygonIndex[index + 1] * 2;
|
|
|
|
v2 = polygonIndex[index + 2] * 2;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 23:23:46 +00:00
|
|
|
if (vertexCount + 3 > maxVertices)
|
|
|
|
{
|
|
|
|
shapeBatch.flush();
|
|
|
|
vertexCount = 0;
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
vertexOffset = vertexDataBuffer.allocate(9 * 3);
|
|
|
|
vertexCount += 3;
|
|
|
|
|
|
|
|
x0 = polygon[v0 + 0] - cameraScrollX;
|
|
|
|
y0 = polygon[v0 + 1] - cameraScrollY;
|
|
|
|
x1 = polygon[v1 + 0] - cameraScrollX;
|
|
|
|
y1 = polygon[v1 + 1] - cameraScrollY;
|
|
|
|
x2 = polygon[v2 + 0] - cameraScrollX;
|
|
|
|
y2 = polygon[v2 + 1] - cameraScrollY;
|
|
|
|
|
|
|
|
tx0 = x0 * a + y0 * c + e;
|
|
|
|
ty0 = x0 * b + y0 * d + f;
|
|
|
|
tx1 = x1 * a + y1 * c + e;
|
|
|
|
ty1 = x1 * b + y1 * d + f;
|
|
|
|
tx2 = x2 * a + y2 * c + e;
|
|
|
|
ty2 = x2 * b + y2 * d + f;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = tx0;
|
|
|
|
vertexBufferF32[vertexOffset++] = ty0;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = tx1;
|
|
|
|
vertexBufferF32[vertexOffset++] = ty1;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = tx2;
|
|
|
|
vertexBufferF32[vertexOffset++] = ty2;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
}
|
|
|
|
polygon.length = 0;
|
|
|
|
}
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.STROKE_PATH:
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
// All of these vars are already defined (except polylines, last, curr, point0 and point1)
|
2017-03-02 00:40:03 +00:00
|
|
|
var pathArrayLength = pathArray.length;
|
|
|
|
var lineWidth = lineWidth * 0.5;
|
|
|
|
var pathArrayIndex, path, pathLength, pathIndex, point0, point1;
|
|
|
|
var polylines = [];
|
|
|
|
var lineColor = lineColor;
|
|
|
|
var index, length, last, curr;
|
|
|
|
var x0, y0, x1, y1, x2, y2, offset, position, color;
|
|
|
|
|
2017-03-02 02:06:37 +00:00
|
|
|
for (pathArrayIndex = 0; pathArrayIndex < pathArrayLength; ++pathArrayIndex)
|
|
|
|
{
|
2017-03-02 00:40:03 +00:00
|
|
|
path = pathArray[pathArrayIndex].points;
|
|
|
|
pathLength = path.length;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
for (pathIndex = 0; pathIndex + 1 < pathLength; pathIndex += 1)
|
|
|
|
{
|
2017-03-02 00:40:03 +00:00
|
|
|
point0 = path[pathIndex];
|
|
|
|
point1 = path[pathIndex + 1];
|
|
|
|
polylines.push(renderLine(
|
|
|
|
point0.x, point0.y, point1.x, point1.y,
|
|
|
|
vertexBufferF32, vertexBufferU32, vertexDataBuffer,
|
|
|
|
cameraScrollX, cameraScrollY,
|
|
|
|
a, b, c, d, e, f,
|
|
|
|
lineColor, lineAlpha, lineWidth,
|
|
|
|
vertexCount, maxVertices,
|
|
|
|
shapeBatch,
|
|
|
|
srcX, srcY, srcScaleX, srcScaleY, srcRotation
|
|
|
|
));
|
|
|
|
vertexCount = shapeBatch.vertexCount;
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
if (pathArray[pathArrayIndex] === this._lastPath)
|
|
|
|
{
|
|
|
|
for (index = 1, length = polylines.length; index < length; ++index)
|
|
|
|
{
|
2017-03-02 00:40:03 +00:00
|
|
|
last = polylines[index - 1];
|
|
|
|
curr = polylines[index];
|
2017-03-02 02:06:37 +00:00
|
|
|
|
|
|
|
if (vertexCount + 6 > maxVertices)
|
|
|
|
{
|
2017-03-02 00:40:03 +00:00
|
|
|
shapeBatch.flush();
|
|
|
|
vertexCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vertexOffset = vertexDataBuffer.allocate(9 * 6);
|
|
|
|
vertexCount += 6;
|
|
|
|
|
|
|
|
x0 = last[2 * 2 + 0] - cameraScrollX;
|
|
|
|
y0 = last[2 * 2 + 1] - cameraScrollY;
|
|
|
|
x1 = last[2 * 0 + 0] - cameraScrollX;
|
|
|
|
y1 = last[2 * 0 + 1] - cameraScrollY;
|
|
|
|
x2 = curr[2 * 3 + 0] - cameraScrollX;
|
|
|
|
y2 = curr[2 * 3 + 1] - cameraScrollY;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x0;
|
|
|
|
vertexBufferF32[vertexOffset++] = y0;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x1;
|
|
|
|
vertexBufferF32[vertexOffset++] = y1;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x2;
|
|
|
|
vertexBufferF32[vertexOffset++] = y2;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
x0 = last[2 * 0 + 0] - cameraScrollX;
|
|
|
|
y0 = last[2 * 0 + 1] - cameraScrollY;
|
|
|
|
x1 = last[2 * 2 + 0] - cameraScrollX;
|
|
|
|
y1 = last[2 * 2 + 1] - cameraScrollY;
|
|
|
|
x2 = curr[2 * 1 + 0] - cameraScrollX;
|
|
|
|
y2 = curr[2 * 1 + 1] - cameraScrollY;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x0;
|
|
|
|
vertexBufferF32[vertexOffset++] = y0;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x1;
|
|
|
|
vertexBufferF32[vertexOffset++] = y1;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x2;
|
|
|
|
vertexBufferF32[vertexOffset++] = y2;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexCount += 6;
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (index = 0, length = polylines.length; index < length; ++index)
|
|
|
|
{
|
2017-03-02 00:40:03 +00:00
|
|
|
last = polylines[index - 1] || polylines[polylines.length - 1];
|
|
|
|
curr = polylines[index];
|
|
|
|
|
2017-03-02 02:06:37 +00:00
|
|
|
if (vertexCount + 6 > maxVertices)
|
|
|
|
{
|
2017-03-02 00:40:03 +00:00
|
|
|
shapeBatch.flush();
|
|
|
|
vertexCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vertexOffset = vertexDataBuffer.allocate(9 * 6);
|
|
|
|
vertexCount += 6;
|
|
|
|
|
|
|
|
x0 = last[2 * 2 + 0] - cameraScrollX;
|
|
|
|
y0 = last[2 * 2 + 1] - cameraScrollY;
|
|
|
|
x1 = last[2 * 0 + 0] - cameraScrollX;
|
|
|
|
y1 = last[2 * 0 + 1] - cameraScrollY;
|
|
|
|
x2 = curr[2 * 3 + 0] - cameraScrollX;
|
|
|
|
y2 = curr[2 * 3 + 1] - cameraScrollY;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x0;
|
|
|
|
vertexBufferF32[vertexOffset++] = y0;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x1;
|
|
|
|
vertexBufferF32[vertexOffset++] = y1;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x2;
|
|
|
|
vertexBufferF32[vertexOffset++] = y2;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
x0 = last[2 * 0 + 0] - cameraScrollX;
|
|
|
|
y0 = last[2 * 0 + 1] - cameraScrollY;
|
|
|
|
x1 = last[2 * 2 + 0] - cameraScrollX;
|
|
|
|
y1 = last[2 * 2 + 1] - cameraScrollY;
|
|
|
|
x2 = curr[2 * 1 + 0] - cameraScrollX;
|
|
|
|
y2 = curr[2 * 1 + 1] - cameraScrollY;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x0;
|
|
|
|
vertexBufferF32[vertexOffset++] = y0;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x1;
|
|
|
|
vertexBufferF32[vertexOffset++] = y1;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = x2;
|
|
|
|
vertexBufferF32[vertexOffset++] = y2;
|
|
|
|
vertexBufferU32[vertexOffset++] = lineColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = lineAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
|
|
|
|
vertexCount += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
polylines.length = 0;
|
|
|
|
}
|
2017-03-01 21:08:10 +00:00
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.FILL_RECT:
|
2017-03-01 23:23:46 +00:00
|
|
|
if (vertexCount + 6 > maxVertices)
|
|
|
|
{
|
|
|
|
shapeBatch.flush();
|
|
|
|
vertexCount = 0;
|
|
|
|
}
|
2017-03-01 21:08:10 +00:00
|
|
|
vertexOffset = vertexDataBuffer.allocate(9 * 6);
|
|
|
|
vertexCount += 6;
|
|
|
|
|
|
|
|
x = commandBuffer[cmdIndex + 1] - cameraScrollX;
|
|
|
|
y = commandBuffer[cmdIndex + 2] - cameraScrollY;
|
2017-03-02 02:06:37 +00:00
|
|
|
var xw = x + commandBuffer[cmdIndex + 3];
|
|
|
|
var yh = y + commandBuffer[cmdIndex + 4];
|
2017-03-01 21:08:10 +00:00
|
|
|
tx = x * a + y * c + e;
|
|
|
|
ty = x * b + y * d + f;
|
|
|
|
txw = xw * a + yh * c + e;
|
|
|
|
tyh = xw * b + yh * d + f;
|
|
|
|
|
|
|
|
vertexBufferF32[vertexOffset++] = tx;
|
|
|
|
vertexBufferF32[vertexOffset++] = ty;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
vertexBufferF32[vertexOffset++] = tx;
|
|
|
|
vertexBufferF32[vertexOffset++] = tyh;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
vertexBufferF32[vertexOffset++] = txw;
|
|
|
|
vertexBufferF32[vertexOffset++] = tyh;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
vertexBufferF32[vertexOffset++] = tx;
|
|
|
|
vertexBufferF32[vertexOffset++] = ty;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
vertexBufferF32[vertexOffset++] = txw;
|
|
|
|
vertexBufferF32[vertexOffset++] = tyh;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
vertexBufferF32[vertexOffset++] = txw;
|
|
|
|
vertexBufferF32[vertexOffset++] = ty;
|
|
|
|
vertexBufferU32[vertexOffset++] = fillColor;
|
|
|
|
vertexBufferF32[vertexOffset++] = fillAlpha;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleX;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcScaleY;
|
|
|
|
vertexBufferF32[vertexOffset++] = srcRotation;
|
|
|
|
cmdIndex += 4;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.LINE_TO:
|
2017-03-02 02:06:37 +00:00
|
|
|
if (lastPath !== null)
|
|
|
|
{
|
2017-03-01 21:08:10 +00:00
|
|
|
lastPath.points.push(new Point(commandBuffer[cmdIndex + 1], commandBuffer[cmdIndex + 2]));
|
2017-03-02 02:06:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-01 21:08:10 +00:00
|
|
|
lastPath = new Path(commandBuffer[cmdIndex + 1], commandBuffer[cmdIndex + 2]);
|
|
|
|
pathArray.push(lastPath);
|
|
|
|
}
|
|
|
|
cmdIndex += 2;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
case Commands.MOVE_TO:
|
|
|
|
lastPath = new Path(commandBuffer[cmdIndex + 1], commandBuffer[cmdIndex + 2]);
|
|
|
|
pathArray.push(lastPath);
|
|
|
|
cmdIndex += 2;
|
|
|
|
break;
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
default:
|
|
|
|
console.error('Phaser: Invalid Graphics Command ID ' + cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-02 02:06:37 +00:00
|
|
|
|
2017-03-01 21:08:10 +00:00
|
|
|
shapeBatch.vertexCount = vertexCount;
|
|
|
|
pathArray.length = 0;
|
2017-03-02 02:06:37 +00:00
|
|
|
};
|
2017-02-28 14:49:39 +00:00
|
|
|
|
|
|
|
module.exports = GraphicsWebGLRenderer;
|