UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 2.66 kB
{"version":3,"file":"WebGLProbe.min.mjs","sources":["../../../../src/filters/GLProbes/WebGLProbe.ts"],"sourcesContent":["import { log } from '../../util/internals/console';\nimport { GLProbe } from './GLProbe';\nimport type { GLPrecision } from './GLProbe';\n\n/**\n * Lazy initialize WebGL constants\n */\nexport class WebGLProbe extends GLProbe {\n declare maxTextureSize?: number;\n\n /**\n * Tests if webgl supports certain precision\n * @param {WebGL} Canvas WebGL context to test on\n * @param {GLPrecision} Precision to test can be any of following\n * @returns {Boolean} Whether the user's browser WebGL supports given precision.\n */\n private testPrecision(\n gl: WebGLRenderingContext,\n precision: GLPrecision,\n ): boolean {\n const fragmentSource = `precision ${precision} float;\\nvoid main(){}`;\n const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);\n if (!fragmentShader) {\n return false;\n }\n gl.shaderSource(fragmentShader, fragmentSource);\n gl.compileShader(fragmentShader);\n return !!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS);\n }\n\n /**\n * query browser for WebGL\n */\n queryWebGL(canvas: HTMLCanvasElement) {\n const gl = canvas.getContext('webgl');\n if (gl) {\n this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);\n this.GLPrecision = (['highp', 'mediump', 'lowp'] as const).find(\n (precision) => this.testPrecision(gl, precision),\n );\n gl.getExtension('WEBGL_lose_context')!.loseContext();\n log('log', `WebGL: max texture size ${this.maxTextureSize}`);\n }\n }\n\n isSupported(textureSize: number) {\n return !!this.maxTextureSize && this.maxTextureSize >= textureSize;\n }\n}\n"],"names":["WebGLProbe","GLProbe","testPrecision","gl","precision","fragmentSource","concat","fragmentShader","createShader","FRAGMENT_SHADER","shaderSource","compileShader","getShaderParameter","COMPILE_STATUS","queryWebGL","canvas","getContext","this","maxTextureSize","getParameter","MAX_TEXTURE_SIZE","GLPrecision","find","getExtension","loseContext","log","isSupported","textureSize"],"mappings":"uGAOO,MAAMA,UAAmBC,EAStBC,aAAAA,CACNC,EACAC,GAEA,MAAMC,EAAc,aAAAC,OAAgBF,EAAiC,0BAC/DG,EAAiBJ,EAAGK,aAAaL,EAAGM,iBAC1C,QAAKF,IAGLJ,EAAGO,aAAaH,EAAgBF,GAChCF,EAAGQ,cAAcJ,KACRJ,EAAGS,mBAAmBL,EAAgBJ,EAAGU,gBACpD,CAKAC,UAAAA,CAAWC,GACT,MAAMZ,EAAKY,EAAOC,WAAW,SACzBb,IACFc,KAAKC,eAAiBf,EAAGgB,aAAahB,EAAGiB,kBACzCH,KAAKI,YAAe,CAAC,QAAS,UAAW,QAAkBC,MACxDlB,GAAca,KAAKf,cAAcC,EAAIC,KAExCD,EAAGoB,aAAa,sBAAuBC,cACvCC,EAAI,MAAKnB,2BAAAA,OAA6BW,KAAKC,iBAE/C,CAEAQ,WAAAA,CAAYC,GACV,QAASV,KAAKC,gBAAkBD,KAAKC,gBAAkBS,CACzD"}