Webgl / added time and resolution as default uniforms

Also added the `zoom` and `resolution` style operators
This commit is contained in:
Olivier Guyot
2019-10-25 13:40:26 +02:00
parent e843b2cfc0
commit acf973751b
6 changed files with 49 additions and 1 deletions

View File

@@ -122,6 +122,8 @@ describe('ol.style.expressions', function() {
expect(getValueType(['get', 'myAttr'])).to.eql(ValueTypes.ANY);
expect(getValueType(['var', 'myValue'])).to.eql(ValueTypes.ANY);
expect(getValueType(['time'])).to.eql(ValueTypes.NUMBER);
expect(getValueType(['zoom'])).to.eql(ValueTypes.NUMBER);
expect(getValueType(['resolution'])).to.eql(ValueTypes.NUMBER);
expect(getValueType(['+', ['get', 'size'], 12])).to.eql(ValueTypes.NUMBER);
expect(getValueType(['-', ['get', 'size'], 12])).to.eql(ValueTypes.NUMBER);
expect(getValueType(['/', ['get', 'size'], 12])).to.eql(ValueTypes.NUMBER);
@@ -156,6 +158,8 @@ describe('ol.style.expressions', function() {
expect(expressionToGlsl(context, ['get', 'myAttr'])).to.eql('a_myAttr');
expect(expressionToGlsl(context, ['var', 'myValue'])).to.eql('u_myValue');
expect(expressionToGlsl(context, ['time'])).to.eql('u_time');
expect(expressionToGlsl(context, ['zoom'])).to.eql('u_zoom');
expect(expressionToGlsl(context, ['resolution'])).to.eql('u_resolution');
expect(expressionToGlsl(context, ['+', ['*', ['get', 'size'], 0.001], 12])).to.eql('((a_size * 0.001) + 12.0)');
expect(expressionToGlsl(context, ['/', ['-', ['get', 'size'], 20], 100])).to.eql('((a_size - 20.0) / 100.0)');
expect(expressionToGlsl(context, ['clamp', ['get', 'attr2'], ['get', 'attr3'], 20])).to.eql('clamp(a_attr2, a_attr3, 20.0)');

View File

@@ -14,6 +14,8 @@ const VERTEX_SHADER = `
uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
attribute float a_test;
uniform float u_test;
@@ -28,6 +30,8 @@ const INVALID_VERTEX_SHADER = `
uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
bla
uniform float u_test;

View File

@@ -18,6 +18,8 @@ uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
attribute vec2 a_position;
attribute float a_index;
@@ -59,6 +61,8 @@ uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
uniform float u_myUniform;
attribute vec2 a_position;
attribute float a_index;
@@ -97,6 +101,8 @@ uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
attribute vec2 a_position;
attribute float a_index;
@@ -130,6 +136,8 @@ uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
attribute vec2 a_position;
attribute float a_index;
@@ -169,6 +177,8 @@ void main(void) {
expect(builder.getSymbolFragmentShader()).to.eql(`precision mediump float;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
varying vec2 v_texCoord;
varying vec2 v_quadCoord;
@@ -193,6 +203,8 @@ void main(void) {
expect(builder.getSymbolFragmentShader()).to.eql(`precision mediump float;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
uniform float u_myUniform;
uniform vec2 u_myUniform2;
varying vec2 v_texCoord;
@@ -210,6 +222,8 @@ void main(void) {
expect(builder.getSymbolFragmentShader(true)).to.eql(`precision mediump float;
uniform float u_time;
uniform float u_zoom;
uniform float u_resolution;
varying vec2 v_texCoord;
varying vec2 v_quadCoord;