diff --git a/src/graphics/graphics-library/parallel-compiler.ts b/src/graphics/graphics-library/parallel-compiler.ts index 256778e..d33bac7 100644 --- a/src/graphics/graphics-library/parallel-compiler.ts +++ b/src/graphics/graphics-library/parallel-compiler.ts @@ -1,3 +1,4 @@ +import { numberToGlslFloat } from '../../helper/number-to-glsl-float'; import { wait } from '../../helper/wait'; import { Insights } from '../rendering/insights'; import { tryEnableExtension } from './helper/enable-extension'; @@ -33,7 +34,6 @@ export class ParallelCompiler { let resolvePromise: ((program: WebGLProgram) => void) | null = null; const promise = new Promise((r) => (resolvePromise = r)); - // can only return null on lost context const program = this.gl.createProgram()!; const vertexShader = this.compileShader( @@ -85,11 +85,10 @@ export class ParallelCompiler { processedSource = processedSource.replace(/{(.+)}/gm, (_, name: string): string => { replaceHappened = true; const value = substitutions[name]; - return Number.isInteger(value) ? `${value}.0` : value; + return numberToGlslFloat(value); }); } while (replaceHappened); - // can only return null on lost context const shader = this.gl.createShader(type)!; this.gl.shaderSource(shader, processedSource); diff --git a/src/helper/number-to-glsl-float.ts b/src/helper/number-to-glsl-float.ts new file mode 100644 index 0000000..8f2ec3d --- /dev/null +++ b/src/helper/number-to-glsl-float.ts @@ -0,0 +1,7 @@ +/** + * @internal + * + * Returns non-numbers as is. + */ +export const numberToGlslFloat = (value: number | string): string => + Number.isInteger(value) ? `${value}.0` : value.toString();