fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.3 kB
Source Map (JSON)
{"version":3,"file":"WebGLProbe.min.mjs","names":[],"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"],"mappings":"uGAOA,IAAa,EAAb,cAAgC,CAAA,CAS9B,cACE,EACA,EAAA,CAEA,IAAM,EAAiB,aAAa,EAAA,wBAC9B,EAAiB,EAAG,aAAa,EAAG,gBAAA,CAC1C,MAAA,CAAA,CAAK,IAGL,EAAG,aAAa,EAAgB,EAAA,CAChC,EAAG,cAAc,EAAA,CAAA,CAAA,CACR,EAAG,mBAAmB,EAAgB,EAAG,eAAA,EAMpD,WAAW,EAAA,CACT,IAAM,EAAK,EAAO,WAAW,QAAA,CACzB,IACF,KAAK,eAAiB,EAAG,aAAa,EAAG,iBAAA,CACzC,KAAK,YAAe,CAAC,QAAS,UAAW,OAAA,CAAkB,KACxD,GAAc,KAAK,cAAc,EAAI,EAAA,CAAA,CAExC,EAAG,aAAa,qBAAA,CAAuB,aAAA,CACvC,EAAI,MAAO,2BAA2B,KAAK,iBAAA,EAI/C,YAAY,EAAA,CACV,MAAA,CAAA,CAAS,KAAK,gBAAkB,KAAK,gBAAkB,IAAA,OAAA,KAAA"}