{"version":3,"file":"logProgramError.mjs","sources":["../../../src/shader/utils/logProgramError.ts"],"sourcesContent":["/**\n * will log a shader error highlighting the lines with the error\n * also will add numbers along the side.\n * @param gl - the WebGLContext\n * @param shader - the shader to log errors for\n */\nfunction logPrettyShaderError(gl: WebGLRenderingContext, shader: WebGLShader): void\n{\n    const shaderSrc = gl.getShaderSource(shader)\n        .split('\\n')\n        .map((line, index) => `${index}: ${line}`);\n\n    const shaderLog = gl.getShaderInfoLog(shader);\n    const splitShader = shaderLog.split('\\n');\n\n    const dedupe: Record<number, boolean> = {};\n\n    const lineNumbers = splitShader.map((line) => parseFloat(line.replace(/^ERROR\\: 0\\:([\\d]+)\\:.*$/, '$1')))\n        .filter((n) =>\n        {\n            if (n && !dedupe[n])\n            {\n                dedupe[n] = true;\n\n                return true;\n            }\n\n            return false;\n        });\n\n    const logArgs = [''];\n\n    lineNumbers.forEach((number) =>\n    {\n        shaderSrc[number - 1] = `%c${shaderSrc[number - 1]}%c`;\n        logArgs.push('background: #FF0000; color:#FFFFFF; font-size: 10px', 'font-size: 10px');\n    });\n\n    const fragmentSourceToLog = shaderSrc\n        .join('\\n');\n\n    logArgs[0] = fragmentSourceToLog;\n\n    console.error(shaderLog);\n\n    // eslint-disable-next-line no-console\n    console.groupCollapsed('click to view full shader code');\n    console.warn(...logArgs);\n    // eslint-disable-next-line no-console\n    console.groupEnd();\n}\n\n/**\n *\n * logs out any program errors\n * @param gl - The current WebGL context\n * @param program - the WebGL program to display errors for\n * @param vertexShader  - the fragment WebGL shader program\n * @param fragmentShader - the vertex WebGL shader program\n */\nexport function logProgramError(\n    gl: WebGLRenderingContext,\n    program: WebGLProgram,\n    vertexShader: WebGLShader,\n    fragmentShader: WebGLShader\n): void\n{\n    // if linking fails, then log and cleanup\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS))\n    {\n        if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS))\n        {\n            logPrettyShaderError(gl, vertexShader);\n        }\n\n        if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS))\n        {\n            logPrettyShaderError(gl, fragmentShader);\n        }\n\n        console.error('PixiJS Error: Could not initialize shader.');\n\n        // if there is a program info log, log it\n        if (gl.getProgramInfoLog(program) !== '')\n        {\n            console.warn('PixiJS Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));\n        }\n    }\n}\n"],"names":[],"mappings":"AAMA,SAAS,qBAAqB,IAA2B,QACzD;AACI,QAAM,YAAY,GAAG,gBAAgB,MAAM,EACtC,MAAM;AAAA,CAAI,EACV,IAAI,CAAC,MAAM,UAAU,GAAG,KAAK,KAAK,IAAI,EAAE,GAEvC,YAAY,GAAG,iBAAiB,MAAM,GACtC,cAAc,UAAU,MAAM;AAAA,CAAI,GAElC,SAAkC,CAAC,GAEnC,cAAc,YAAY,IAAI,CAAC,SAAS,WAAW,KAAK,QAAQ,4BAA4B,IAAI,CAAC,CAAC,EACnG,OAAO,CAAC,MAED,KAAK,CAAC,OAAO,CAAC,KAEd,OAAO,CAAC,IAAI,IAEL,MAGJ,EACV,GAEC,UAAU,CAAC,EAAE;AAEP,cAAA,QAAQ,CAAC,WACrB;AACI,cAAU,SAAS,CAAC,IAAI,KAAK,UAAU,SAAS,CAAC,CAAC,MAClD,QAAQ,KAAK,uDAAuD,iBAAiB;AAAA,EAAA,CACxF;AAEK,QAAA,sBAAsB,UACvB,KAAK;AAAA,CAAI;AAEd,UAAQ,CAAC,IAAI,qBAEb,QAAQ,MAAM,SAAS,GAGvB,QAAQ,eAAe,gCAAgC,GACvD,QAAQ,KAAK,GAAG,OAAO,GAEvB,QAAQ;AACZ;AAUO,SAAS,gBACZ,IACA,SACA,cACA,gBAEJ;AAES,KAAG,oBAAoB,SAAS,GAAG,WAAW,MAE1C,GAAG,mBAAmB,cAAc,GAAG,cAAc,KAEtD,qBAAqB,IAAI,YAAY,GAGpC,GAAG,mBAAmB,gBAAgB,GAAG,cAAc,KAExD,qBAAqB,IAAI,cAAc,GAG3C,QAAQ,MAAM,4CAA4C,GAGtD,GAAG,kBAAkB,OAAO,MAAM,MAElC,QAAQ,KAAK,0CAA0C,GAAG,kBAAkB,OAAO,CAAC;AAGhG;"}