verifyColorSpace method

dynamic verifyColorSpace(
  1. Texture texture,
  2. dynamic image
)

Implementation

verifyColorSpace(Texture texture, image) {
  var encoding = texture.encoding;
  var format = texture.format;
  var type = texture.type;

  if (texture.isCompressedTexture == true || texture.isVideoTexture == true || texture.format == SRGBAFormat) {
    return image;
  }

  if (encoding != LinearEncoding) {
    // sRGB

    if (encoding == sRGBEncoding) {
      if (isWebGL2 == false) {
        // in WebGL 1, try to use EXT_sRGB extension and unsized formats

        if (extensions.has('EXT_sRGB') == true && format == RGBAFormat) {
          texture.format = SRGBAFormat;

          // it's not possible to generate mips in WebGL 1 with this extension

          texture.minFilter = LinearFilter;
          texture.generateMipmaps = false;
        } else {
          // slow fallback (CPU decode)

          image = ImageUtils.sRGBToLinear(image);
        }
      } else {
        // in WebGL 2 uncompressed textures can only be sRGB encoded if they have the RGBA8 format

        if (format != RGBAFormat || type != UnsignedByteType) {
          print('three.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.');
        }
      }
    } else {
      print('three.WebGLTextures: Unsupported texture encoding: $encoding');
    }
  }

  return image;
}