Add helper function and remove clutter
This commit is contained in:
parent
5ff15fa58f
commit
4629cfd469
2 changed files with 9 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { numberToGlslFloat } from '../../helper/number-to-glsl-float';
|
||||||
import { wait } from '../../helper/wait';
|
import { wait } from '../../helper/wait';
|
||||||
import { Insights } from '../rendering/insights';
|
import { Insights } from '../rendering/insights';
|
||||||
import { tryEnableExtension } from './helper/enable-extension';
|
import { tryEnableExtension } from './helper/enable-extension';
|
||||||
|
|
@ -33,7 +34,6 @@ export class ParallelCompiler {
|
||||||
let resolvePromise: ((program: WebGLProgram) => void) | null = null;
|
let resolvePromise: ((program: WebGLProgram) => void) | null = null;
|
||||||
const promise = new Promise<WebGLProgram>((r) => (resolvePromise = r));
|
const promise = new Promise<WebGLProgram>((r) => (resolvePromise = r));
|
||||||
|
|
||||||
// can only return null on lost context
|
|
||||||
const program = this.gl.createProgram()!;
|
const program = this.gl.createProgram()!;
|
||||||
|
|
||||||
const vertexShader = this.compileShader(
|
const vertexShader = this.compileShader(
|
||||||
|
|
@ -85,11 +85,10 @@ export class ParallelCompiler {
|
||||||
processedSource = processedSource.replace(/{(.+)}/gm, (_, name: string): string => {
|
processedSource = processedSource.replace(/{(.+)}/gm, (_, name: string): string => {
|
||||||
replaceHappened = true;
|
replaceHappened = true;
|
||||||
const value = substitutions[name];
|
const value = substitutions[name];
|
||||||
return Number.isInteger(value) ? `${value}.0` : value;
|
return numberToGlslFloat(value);
|
||||||
});
|
});
|
||||||
} while (replaceHappened);
|
} while (replaceHappened);
|
||||||
|
|
||||||
// can only return null on lost context
|
|
||||||
const shader = this.gl.createShader(type)!;
|
const shader = this.gl.createShader(type)!;
|
||||||
|
|
||||||
this.gl.shaderSource(shader, processedSource);
|
this.gl.shaderSource(shader, processedSource);
|
||||||
|
|
|
||||||
7
src/helper/number-to-glsl-float.ts
Normal file
7
src/helper/number-to-glsl-float.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* Returns non-numbers as is.
|
||||||
|
*/
|
||||||
|
export const numberToGlslFloat = (value: number | string): string =>
|
||||||
|
Number.isInteger(value) ? `${value}.0` : value.toString();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue