RenderTextureQuad constructor

RenderTextureQuad(
  1. RenderTexture renderTexture,
  2. Rectangle<int> sourceRectangle,
  3. Rectangle<int> offsetRectangle,
  4. int rotation,
  5. num pixelRatio,
)

Implementation

RenderTextureQuad(this.renderTexture, this.sourceRectangle,
    this.offsetRectangle, this.rotation, this.pixelRatio) {
  final sr = sourceRectangle;
  final or = offsetRectangle;
  final rt = renderTexture;
  final pr = pixelRatio;

  // Vertex list [x/y]

  if (rotation == 0 || rotation == 2) {
    vxListQuad[00] = vxListQuad[12] = (0 - or.left) / pr;
    vxListQuad[01] = vxListQuad[05] = (0 - or.top) / pr;
    vxListQuad[08] = vxListQuad[04] = (0 - or.left + sr.width) / pr;
    vxListQuad[09] = vxListQuad[13] = (0 - or.top + sr.height) / pr;
  } else if (rotation == 1 || rotation == 3) {
    vxListQuad[00] = vxListQuad[12] = (0 - or.left) / pr;
    vxListQuad[01] = vxListQuad[05] = (0 - or.top) / pr;
    vxListQuad[08] = vxListQuad[04] = (0 - or.left + sr.height) / pr;
    vxListQuad[09] = vxListQuad[13] = (0 - or.top + sr.width) / pr;
  } else {
    throw Error();
  }

  // Vertex list [u/v]

  if (rotation == 0) {
    vxListQuad[02] = vxListQuad[14] = sr.left / rt.width;
    vxListQuad[03] = vxListQuad[07] = sr.top / rt.height;
    vxListQuad[10] = vxListQuad[06] = sr.right / rt.width;
    vxListQuad[11] = vxListQuad[15] = sr.bottom / rt.height;
  } else if (rotation == 1) {
    vxListQuad[02] = vxListQuad[06] = sr.right / rt.width;
    vxListQuad[03] = vxListQuad[15] = sr.top / rt.height;
    vxListQuad[10] = vxListQuad[14] = sr.left / rt.width;
    vxListQuad[11] = vxListQuad[07] = sr.bottom / rt.height;
  } else if (rotation == 2) {
    vxListQuad[02] = vxListQuad[14] = sr.right / rt.width;
    vxListQuad[03] = vxListQuad[07] = sr.bottom / rt.height;
    vxListQuad[10] = vxListQuad[06] = sr.left / rt.width;
    vxListQuad[11] = vxListQuad[15] = sr.top / rt.height;
  } else if (rotation == 3) {
    vxListQuad[02] = vxListQuad[06] = sr.left / rt.width;
    vxListQuad[03] = vxListQuad[15] = sr.bottom / rt.height;
    vxListQuad[10] = vxListQuad[14] = sr.right / rt.width;
    vxListQuad[11] = vxListQuad[07] = sr.top / rt.height;
  } else {
    throw Error();
  }

  // Index list

  ixListQuad[0] = 0;
  ixListQuad[1] = 1;
  ixListQuad[2] = 2;
  ixListQuad[3] = 0;
  ixListQuad[4] = 2;
  ixListQuad[5] = 3;

  // set default vertices to quad vertices

  _vxList = vxListQuad;
  _ixList = ixListQuad;
  _hasCustomVertices = false;
}