samplerMatrix property

Matrix samplerMatrix

The matrix transformation for this RenderTextureQuad to transform target coordinates to sampler coordinates.

Sampler coordinate are in the range from (0, 0) to (1, 1). Target coordinates take the pixelRatio into account.

Implementation

Matrix get samplerMatrix {
  final pr = pixelRatio;
  final sx = 1.0 / renderTexture.width;
  final sy = 1.0 / renderTexture.height;

  if (rotation == 0) {
    final tx = sourceRectangle.left + offsetRectangle.left;
    final ty = sourceRectangle.top + offsetRectangle.top;
    return Matrix(sx * pr, 0.0, 0.0, sy * pr, sx * tx, sy * ty);
  } else if (rotation == 1) {
    final tx = sourceRectangle.right - offsetRectangle.top;
    final ty = sourceRectangle.top + offsetRectangle.left;
    return Matrix(0.0, sy * pr, 0.0 - sx * pr, 0.0, sx * tx, sy * ty);
  } else if (rotation == 2) {
    final tx = sourceRectangle.right - offsetRectangle.left;
    final ty = sourceRectangle.bottom - offsetRectangle.top;
    return Matrix(0.0 - sx * pr, 0.0, 0.0, 0.0 - sy * pr, sx * tx, sy * ty);
  } else if (rotation == 3) {
    final tx = sourceRectangle.left + offsetRectangle.top;
    final ty = sourceRectangle.bottom - offsetRectangle.left;
    return Matrix(0.0, 0.0 - sy * pr, sx * pr, 0.0, sx * tx, sy * ty);
  } else {
    throw Error();
  }
}