Fix compiling edge-cases
This commit is contained in:
parent
bd2307f782
commit
4a6a25a081
2 changed files with 21 additions and 9 deletions
|
|
@ -79,11 +79,16 @@ export class ParallelCompiler {
|
|||
let replaceHappened: boolean;
|
||||
do {
|
||||
replaceHappened = false;
|
||||
processedSource = processedSource.replace(/{(.+)}/gm, (_, name: string): string => {
|
||||
replaceHappened = true;
|
||||
const value = substitutions[name];
|
||||
return numberToGlslFloat(value);
|
||||
});
|
||||
processedSource = processedSource.replace(
|
||||
/{(\w+)}/gm,
|
||||
(_, name: string): string => {
|
||||
replaceHappened = true;
|
||||
if (!(name in substitutions)) {
|
||||
throw new Error(`Unknown shader substitution: '{${name}}'`);
|
||||
}
|
||||
return numberToGlslFloat(substitutions[name]);
|
||||
}
|
||||
);
|
||||
} while (replaceHappened);
|
||||
|
||||
const shader = this.gl.createShader(type)!;
|
||||
|
|
@ -142,8 +147,7 @@ export class ParallelCompiler {
|
|||
console.error(
|
||||
formatLog(
|
||||
'parallel-compiler',
|
||||
`Error: ${error}\nSource (line ${line}):\n${
|
||||
shader.source.split('\n')[line - 1]
|
||||
`Error: ${error}\nSource (line ${line}):\n${shader.source.split('\n')[line - 1]
|
||||
}`
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,5 +3,13 @@
|
|||
*
|
||||
* Returns non-numbers as is.
|
||||
*/
|
||||
export const numberToGlslFloat = (value: number | string): string =>
|
||||
Number.isInteger(value) ? `${value}.0` : value.toString();
|
||||
export const numberToGlslFloat = (value: number | string): string => {
|
||||
if (typeof value !== 'number') {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
const asString = value.toString();
|
||||
|
||||
// Very large integers stringify in exponent notation (1e21)
|
||||
return Number.isInteger(value) && !asString.includes('e') ? `${asString}.0` : asString;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue