From 40d44db85e596c42d398e1b804bcaa64988ceb26 Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Tue, 3 Mar 2020 09:45:57 +0100 Subject: [PATCH] Shader Builder / use vertex context to parse the symbol rotation expression Previously the expression was parsed in the fragment shader context, which meant in case the expression used an attributes the resulting GLSL code would be wrong. Fragment shader context: `float angle = v_heading; // we're using the varying: not OK` Vertex shader context: `float angle = a_heading; // we're using the attribute: OK` --- src/ol/webgl/ShaderBuilder.js | 2 +- test/spec/ol/webgl/shaderbuilder.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ol/webgl/ShaderBuilder.js b/src/ol/webgl/ShaderBuilder.js index a2b21298c4..22b089f5e5 100644 --- a/src/ol/webgl/ShaderBuilder.js +++ b/src/ol/webgl/ShaderBuilder.js @@ -427,6 +427,7 @@ export function parseLiteralStyle(style) { const parsedSize = expressionToGlsl(vertContext, size, ValueTypes.NUMBER_ARRAY | ValueTypes.NUMBER); const parsedOffset = expressionToGlsl(vertContext, offset, ValueTypes.NUMBER_ARRAY); const parsedTexCoord = expressionToGlsl(vertContext, texCoord, ValueTypes.NUMBER_ARRAY); + const parsedRotation = expressionToGlsl(vertContext, rotation, ValueTypes.NUMBER); /** * @type {import("../style/expressions.js").ParsingContext} @@ -439,7 +440,6 @@ export function parseLiteralStyle(style) { }; const parsedColor = expressionToGlsl(fragContext, color, ValueTypes.COLOR); const parsedOpacity = expressionToGlsl(fragContext, opacity, ValueTypes.NUMBER); - const parsedRotation = expressionToGlsl(fragContext, rotation, ValueTypes.NUMBER); let opacityFilter = '1.0'; const visibleSize = `vec2(${expressionToGlsl(fragContext, size, ValueTypes.NUMBER_ARRAY | ValueTypes.NUMBER)}).x`; diff --git a/test/spec/ol/webgl/shaderbuilder.test.js b/test/spec/ol/webgl/shaderbuilder.test.js index 78ac4390e9..dfcf8e334f 100644 --- a/test/spec/ol/webgl/shaderbuilder.test.js +++ b/test/spec/ol/webgl/shaderbuilder.test.js @@ -511,6 +511,20 @@ void main(void) { expect(result.uniforms).to.have.property('u_ratio'); }); + it('parses a style with a rotation expression using an attribute', function() { + const result = parseLiteralStyle({ + symbol: { + symbolType: 'square', + size: 6, + rotation: ['get', 'heading'] + } + }); + + expect(result.builder.attributes).to.eql(['float a_heading']); + expect(result.builder.varyings).to.eql([]); + expect(result.builder.rotationExpression).to.eql('a_heading'); + }); + it('correctly adds string variables to the string literals mapping', function() { const result = parseLiteralStyle({ variables: {