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,IAAI,GAAG,KAAK,UAAU,EAAE;oBACpE,2DAA2D;oBAC3D,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBAE5C,IAAI,KAAK,IAAI,KAAK,KAAK,EAAE,CAAC,QAAQ,EAAE;wBAClC,8EAA8E;wBAC9E,OAAO,CAAC,GAAG,CAAC,yBAAyB,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;qBAChE;iBACF;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;YACF,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,aAAa,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,aAAa,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import GLErrors from './GLErrors';\nimport { ExpoWebGLRenderingContext, GLLoggingOption } from './GLView.types';\n\n/**\n * Maximum length of the strings printed to the console.\n */\nconst MAX_STRING_LENGTH = 20;\n\n/**\n * Sets up `__expoSetLogging` method providing some logging options useful when debugging GL calls.\n */\nexport function configureLogging(gl: ExpoWebGLRenderingContext): void {\n // Enable/disable logging of all GL function calls\n let loggingOption = GLLoggingOption.DISABLED;\n\n gl.__expoSetLogging = (option: GLLoggingOption): void => {\n // If boolean values are the same, just change the internal value,\n // there is no need to wrap/unwrap functions in this case.\n if (!loggingOption === !option) {\n loggingOption = option;\n return;\n }\n\n // Turn off logging.\n if (!option || option === GLLoggingOption.DISABLED) {\n Object.entries(gl).forEach(([key, value]) => {\n if (typeof value === 'function' && value.original) {\n gl[key] = value.original;\n }\n });\n loggingOption = option;\n return;\n }\n\n // Turn on logging.\n Object.entries(gl).forEach(([key, originalValue]) => {\n if (typeof originalValue !== 'function' || key === '__expoSetLogging') {\n return;\n }\n\n gl[key] = (...args) => {\n if (loggingOption & GLLoggingOption.METHOD_CALLS) {\n const params = args.map(arg => {\n // If the type is `number`, then try to find name of the constant that has such value,\n // so it's easier to read these logs. In some cases it might be misleading\n // if the parameter is for example a width or height, so the number is still logged.\n if (loggingOption & GLLoggingOption.RESOLVE_CONSTANTS && typeof arg === 'number') {\n for (const prop in gl) {\n if (gl[prop] === arg) {\n return `${arg} (${prop})`;\n }\n }\n }\n\n // Truncate strings so they don't produce too much output and don't block the bridge.\n // It mostly applies to shaders which might be very long...\n if (loggingOption & GLLoggingOption.TRUNCATE_STRINGS && typeof arg === 'string') {\n if (arg.length > MAX_STRING_LENGTH) {\n const lastIndex = arg.lastIndexOf(' ', MAX_STRING_LENGTH);\n return arg.substr(0, lastIndex >= 0 ? lastIndex : MAX_STRING_LENGTH) + '...';\n }\n }\n\n // Just return the parameter as a string.\n return '' + arg;\n });\n console.log(`ExpoGL: ${key}(${params.join(', ')})`);\n }\n\n const result = originalValue.apply(gl, args);\n\n if (loggingOption & GLLoggingOption.METHOD_CALLS) {\n console.log(`ExpoGL: = ${result}`);\n }\n if (loggingOption & GLLoggingOption.GET_ERRORS && key !== 'getError') {\n // @ts-ignore We need to call into the original `getError`.\n const error = gl.getError.original.call(gl);\n\n if (error && error !== gl.NO_ERROR) {\n // `console.error` would cause a red screen, so let's just log with red color.\n console.log(`\\x1b[31mExpoGL: Error ${GLErrors[error]}\\x1b[0m`);\n }\n }\n return result;\n };\n gl[key].original = originalValue;\n });\n\n loggingOption = option;\n };\n}\n"]}
\No newline at end of file