cpuTestDevice function

({TextureHandle albedo, CpuDevice device, TextureHandle normal}) cpuTestDevice({
  1. int width = 96,
  2. int height = 72,
})

A CpuDevice with the builtin shaders, and the fallbacks a renderer needs.

width and height default to something small enough that a software frame is cheap and large enough that a shape has an inside: every caller that had its own copy of this chose between 64×48 and 240×160.

Implementation

({CpuDevice device, TextureHandle albedo, TextureHandle normal}) cpuTestDevice({
  int width = 96,
  int height = 72,
}) {
  final device = CpuDevice(
    width: width,
    height: height,
    shaders: CpuShaderLibrary(builtinCpuShaders()),
  );
  return (
    device: device,
    // White, so a material's own colour is what reaches the target.
    albedo: texelOn(device, <int>[255, 255, 255, 255]),
    // Flat in tangent space: (0, 0, 1) encoded, which is the normal of a
    // surface with no bumps on it.
    normal: texelOn(device, <int>[128, 128, 255, 255]),
  );
}