renderTextureQuad method Null safety

void renderTextureQuad(
  1. RenderState renderState,
  2. RenderTextureQuad renderTextureQuad
)

Implementation

void renderTextureQuad(
    RenderState renderState, RenderTextureQuad renderTextureQuad) {
  if (renderTextureQuad.hasCustomVertices) {
    final ixList = renderTextureQuad.ixList;
    final vxList = renderTextureQuad.vxList;
    renderTextureMesh(renderState, ixList, vxList);
    return;
  }

  final alpha = renderState.globalAlpha;
  final matrix = renderState.globalMatrix;
  final vxList = renderTextureQuad.vxListQuad;
  const ixListCount = 6;
  const vxListCount = 4;

  // check buffer sizes and flush if necessary

  final ixData = renderBufferIndex.data;
  final ixPosition = renderBufferIndex.position;
  if (ixPosition + ixListCount >= ixData.length) flush();

  final vxData = renderBufferVertex.data;
  final vxPosition = renderBufferVertex.position;
  if (vxPosition + vxListCount * 5 >= vxData.length) flush();

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

  // copy index list

  ixData[ixIndex + 0] = vxCount + 0;
  ixData[ixIndex + 1] = vxCount + 1;
  ixData[ixIndex + 2] = vxCount + 2;
  ixData[ixIndex + 3] = vxCount + 0;
  ixData[ixIndex + 4] = vxCount + 2;
  ixData[ixIndex + 5] = vxCount + 3;

  renderBufferIndex.position += ixListCount;
  renderBufferIndex.count += ixListCount;

  // copy vertex list

  final ma1 = vxList[0] * matrix.a + matrix.tx;
  final ma2 = vxList[8] * matrix.a + matrix.tx;
  final mb1 = vxList[0] * matrix.b + matrix.ty;
  final mb2 = vxList[8] * matrix.b + matrix.ty;
  final mc1 = vxList[1] * matrix.c;
  final mc2 = vxList[9] * matrix.c;
  final md1 = vxList[1] * matrix.d;
  final md2 = vxList[9] * matrix.d;

  vxData[vxIndex + 00] = ma1 + mc1;
  vxData[vxIndex + 01] = mb1 + md1;
  vxData[vxIndex + 02] = vxList[2];
  vxData[vxIndex + 03] = vxList[3];
  vxData[vxIndex + 04] = alpha;

  vxData[vxIndex + 05] = ma2 + mc1;
  vxData[vxIndex + 06] = mb2 + md1;
  vxData[vxIndex + 07] = vxList[6];
  vxData[vxIndex + 08] = vxList[7];
  vxData[vxIndex + 09] = alpha;

  vxData[vxIndex + 10] = ma2 + mc2;
  vxData[vxIndex + 11] = mb2 + md2;
  vxData[vxIndex + 12] = vxList[10];
  vxData[vxIndex + 13] = vxList[11];
  vxData[vxIndex + 14] = alpha;

  vxData[vxIndex + 15] = ma1 + mc2;
  vxData[vxIndex + 16] = mb1 + md2;
  vxData[vxIndex + 17] = vxList[14];
  vxData[vxIndex + 18] = vxList[15];
  vxData[vxIndex + 19] = alpha;

  renderBufferVertex.position += vxListCount * 5;
  renderBufferVertex.count += vxListCount;
}