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));
}
/**

View File

@@ -3,7 +3,7 @@
* @module ol/webgl/ShaderBuilder
*/
import {expressionToGlsl, stringToGlsl, ValueTypes} from '../style/expressions.js';
import {expressionToGlsl, getStringNumberEquivalent, ValueTypes} from '../style/expressions.js';
/**
* @typedef {Object} VaryingDescription
@@ -450,7 +450,7 @@ export function parseLiteralStyle(style) {
}
let value = style.variables[varName];
if (typeof value === 'string') {
value = parseFloat(stringToGlsl(vertContext, value));
value = getStringNumberEquivalent(vertContext, value);
}
return value !== undefined ? value : -9999999; // to avoid matching with the first string literal
};
@@ -484,10 +484,10 @@ export function parseLiteralStyle(style) {
attributes: vertContext.attributes.map(function(attributeName) {
return {
name: attributeName,
callback: function(feature) {
let value = feature.get(attributeName);
callback: function(feature, props) {
let value = props[attributeName];
if (typeof value === 'string') {
value = parseFloat(stringToGlsl(vertContext, value));
value = getStringNumberEquivalent(vertContext, value);
}
return value !== undefined ? value : -9999999; // to avoid matching with the first string literal
}