Webgl points renderer / more optimizations

Simplify calls in the attributes callback, also less stress
on garbage collection.
This commit is contained in:
Olivier Guyot
2019-10-31 10:50:24 +01:00
parent e78c14c061
commit e5e03d46a0
2 changed files with 19 additions and 9 deletions

View File

@@ -203,6 +203,19 @@ export function colorToGlsl(color) {
);
}
/**
* Returns a stable equivalent number for the string literal.
* @param {ParsingContext} context Parsing context
* @param {string} string String literal value
* @returns {number} Number equivalent
*/
export function getStringNumberEquivalent(context, string) {
if (context.stringLiteralsMap[string] === undefined) {
context.stringLiteralsMap[string] = Object.keys(context.stringLiteralsMap).length;
}
return context.stringLiteralsMap[string];
}
/**
* Returns a stable equivalent number for the string literal, for use in shaders. This number is then
* converted to be a GLSL-compatible string.
@@ -211,10 +224,7 @@ export function colorToGlsl(color) {
* @returns {string} GLSL-compatible string containing a number
*/
export function stringToGlsl(context, string) {
if (context.stringLiteralsMap[string] === undefined) {
context.stringLiteralsMap[string] = Object.keys(context.stringLiteralsMap).length;
}
return numberToGlsl(context.stringLiteralsMap[string]);
return numberToGlsl(getStringNumberEquivalent(context, string));
}
/**