Webgl points renderer / more optimizations
Simplify calls in the attributes callback, also less stress on garbage collection.
This commit is contained in:
@@ -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
|
* Returns a stable equivalent number for the string literal, for use in shaders. This number is then
|
||||||
* converted to be a GLSL-compatible string.
|
* converted to be a GLSL-compatible string.
|
||||||
@@ -211,10 +224,7 @@ export function colorToGlsl(color) {
|
|||||||
* @returns {string} GLSL-compatible string containing a number
|
* @returns {string} GLSL-compatible string containing a number
|
||||||
*/
|
*/
|
||||||
export function stringToGlsl(context, string) {
|
export function stringToGlsl(context, string) {
|
||||||
if (context.stringLiteralsMap[string] === undefined) {
|
return numberToGlsl(getStringNumberEquivalent(context, string));
|
||||||
context.stringLiteralsMap[string] = Object.keys(context.stringLiteralsMap).length;
|
|
||||||
}
|
|
||||||
return numberToGlsl(context.stringLiteralsMap[string]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @module ol/webgl/ShaderBuilder
|
* @module ol/webgl/ShaderBuilder
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {expressionToGlsl, stringToGlsl, ValueTypes} from '../style/expressions.js';
|
import {expressionToGlsl, getStringNumberEquivalent, ValueTypes} from '../style/expressions.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} VaryingDescription
|
* @typedef {Object} VaryingDescription
|
||||||
@@ -450,7 +450,7 @@ export function parseLiteralStyle(style) {
|
|||||||
}
|
}
|
||||||
let value = style.variables[varName];
|
let value = style.variables[varName];
|
||||||
if (typeof value === 'string') {
|
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
|
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) {
|
attributes: vertContext.attributes.map(function(attributeName) {
|
||||||
return {
|
return {
|
||||||
name: attributeName,
|
name: attributeName,
|
||||||
callback: function(feature) {
|
callback: function(feature, props) {
|
||||||
let value = feature.get(attributeName);
|
let value = props[attributeName];
|
||||||
if (typeof value === 'string') {
|
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
|
return value !== undefined ? value : -9999999; // to avoid matching with the first string literal
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user