license import { env } from '@tensorflow/tfjs-core' ; export type GLSL = { version : string ; attribute : string ; varyingVs : string ; varyingFs : string ; texture2D : string ; output : string ; defineOutput : string ; defineSpecialNaN : string ; defineSpecialInf : string ; defineRound : string ; } ; export function getGlslDifferences ( ) { let version ; let attribute ; let varyingVs ; let varyingFs ; let texture2D ; let output ; let defineOutput ; let defineSpecialNaN ; let defineSpecialInf ; let defineRound ; if ( env ( ) . getNumber ( 'WEBGL_VERSION' ) === 2 ) { version = '#version 300 es' ; attribute = 'in' ; varyingVs = 'out' ; varyingFs = 'in' ; texture2D = 'texture' ; output = 'outputColor' ; defineOutput = 'out vec4 outputColor;' ; defineSpecialNaN = `
      bool isnan_custom(float val) {
        return (val > 0.0 || val < 0.0) ? false : val != 0.0;
      }

      bvec4 isnan_custom(vec4 val) {
        return bvec4(isnan_custom(val.x),
          isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
      }

      #define isnan(value) isnan_custom(value)
    ` ; defineSpecialInf = `` ; defineRound = `
      #define round(value) newRound(value)
      int newRound(float value) {
        return int(floor(value + 0.5));
      }

      ivec4 newRound(vec4 value) {
        return ivec4(floor(value + vec4(0.5)));
      }
    ` ; } else { version = '' ; attribute = 'attribute' ; varyingVs = 'varying' ; varyingFs = 'varying' ; texture2D = 'texture2D' ; output = 'gl_FragColor' ; defineOutput = '' ; defineSpecialNaN = `
      #define isnan(value) isnan_custom(value)
      bool isnan_custom(float val) {
        return (val > 0. || val < 1. || val == 0.) ? false : true;
      }
      bvec4 isnan_custom(vec4 val) {
        return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
      }
    ` ; defineSpecialInf = `
      uniform float INFINITY;

      bool isinf(float val) {
        return abs(val) == INFINITY;
      }
      bvec4 isinf(vec4 val) {
        return equal(abs(val), vec4(INFINITY));
      }
    ` ; defineRound = `
      int round(float value) {
        return int(floor(value + 0.5));
      }

      ivec4 round(vec4 value) {
        return ivec4(floor(value + vec4(0.5)));
      }
    ` ; } return { version , attribute , varyingVs , varyingFs , texture2D , output , defineOutput , defineSpecialNaN , defineSpecialInf , defineRound } ; }