void renderTriangle(RenderState renderState, num x1, num y1, num x2, num y2, num x3, num y3, int color)

Source

void renderTriangle(
    RenderState renderState,
    num x1, num y1, num x2, num y2, num x3, num y3, int color) {

  var matrix = renderState.globalMatrix;
  var alpha = renderState.globalAlpha;
  var indexCount = 3;
  var vertexCount = 3;

  // check buffer sizes and flush if necessary

  var ixData = renderBufferIndex.data;
  var ixPosition = renderBufferIndex.position;
  if (ixPosition + indexCount >= ixData.length) flush();

  var vxData = renderBufferVertex.data;
  var vxPosition = renderBufferVertex.position;
  if (vxPosition + vertexCount * 6 >= vxData.length) flush();

  var ixIndex = renderBufferIndex.position;
  var vxIndex = renderBufferVertex.position;
  var vxCount = renderBufferVertex.count;

  // fill index buffer

  ixData[ixIndex + 0] = vxCount + 0;
  ixData[ixIndex + 1] = vxCount + 1;
  ixData[ixIndex + 2] = vxCount + 2;

  renderBufferIndex.position += indexCount;
  renderBufferIndex.count += indexCount;

  // fill vertex buffer

  var ma = matrix.a;
  var mb = matrix.b;
  var mc = matrix.c;
  var md = matrix.d;
  var mx = matrix.tx;
  var my = matrix.ty;

  var colorScale = 1 / 255.0;
  var colorA = colorScale * colorGetA(color) * alpha;
  var colorR = colorScale * colorGetR(color) * colorA;
  var colorG = colorScale * colorGetG(color) * colorA;
  var colorB = colorScale * colorGetB(color) * colorA;

  vxData[vxIndex + 00] = x1 * ma + y1 * mc + mx;
  vxData[vxIndex + 01] = x1 * mb + y1 * md + my;
  vxData[vxIndex + 02] = colorR;
  vxData[vxIndex + 03] = colorG;
  vxData[vxIndex + 04] = colorB;
  vxData[vxIndex + 05] = colorA;

  vxData[vxIndex + 06] = x2 * ma + y2 * mc + mx;
  vxData[vxIndex + 07] = x2 * mb + y2 * md + my;
  vxData[vxIndex + 08] = colorR;
  vxData[vxIndex + 09] = colorG;
  vxData[vxIndex + 10] = colorB;
  vxData[vxIndex + 11] = colorA;

  vxData[vxIndex + 12] = x3 * ma + y3 * mc + mx;
  vxData[vxIndex + 13] = x3 * mb + y3 * md + my;
  vxData[vxIndex + 14] = colorR;
  vxData[vxIndex + 15] = colorG;
  vxData[vxIndex + 16] = colorB;
  vxData[vxIndex + 17] = colorA;

  renderBufferVertex.position += vertexCount * 6;
  renderBufferVertex.count += vertexCount;
}