Skip to content

Commit 07cb8d5

Browse files
committed
Website updates
1 parent f31a682 commit 07cb8d5

14 files changed

+89
-58
lines changed

dist/en/main/examples/common.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/common.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/webgl-vector-tiles.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/webgl-vector-tiles.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/dist/ol.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/dist/ol.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/layer/Heatmap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ class Heatmap extends BaseVector {
261261
if (typeof this.getBlur() === 'number') {
262262
blurCompiled = 'a_blur';
263263
blurRadiusUniforms['a_blur'] = () => this.getBlur();
264-
builder.addUniform('float a_blur');
264+
builder.addUniform('a_blur', 'float');
265265
}
266266
if (typeof this.getRadius() === 'number') {
267267
radiusCompiled = 'a_radius';
268268
blurRadiusUniforms['a_radius'] = () => this.getRadius();
269-
builder.addUniform('float a_radius');
269+
builder.addUniform('a_radius', 'float');
270270
}
271271

272272
/** @type {import('../render/webgl/VectorStyleRenderer.js').AttributeDefinitions} */

dist/en/main/ol/render/webgl/ShaderBuilder.d.ts

+34-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
export const COMMON_HEADER: "#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_screenToWorldMatrix;\nuniform vec2 u_viewportSizePx;\nuniform float u_pixelRatio;\nuniform float u_globalAlpha;\nuniform float u_time;\nuniform float u_zoom;\nuniform float u_resolution;\nuniform float u_rotation;\nuniform vec4 u_renderExtent;\nuniform vec2 u_patternOrigin;\nuniform float u_depth;\nuniform mediump int u_hitDetection;\n\nconst float PI = 3.141592653589793238;\nconst float TWO_PI = 2.0 * PI;\nfloat currentLineMetric = 0.; // an actual value will be used in the stroke shaders\n";
22
/**
33
* @typedef {Object} AttributeDescription
4-
* @property {string} name Attribute name, as will be declared in the headers (including a_)
5-
* @property {string} type Attribute type, either `float`, `vec2`, `vec4`...
6-
* @property {string} varyingName Varying name, as will be declared in the fragment shader (including v_)
4+
* @property {string} name Attribute name, as will be declared in the header of the vertex shader (including a_)
5+
* @property {string} type Attribute GLSL type, either `float`, `vec2`, `vec4`...
6+
* @property {string} varyingName Varying name, as will be declared in the header of both shaders (including v_)
77
* @property {string} varyingType Varying type, either `float`, `vec2`, `vec4`...
8-
* @property {string} varyingExpression GLSL expression to assign to the varying in the vertex shader
8+
* @property {string} varyingExpression GLSL expression to assign to the varying in the vertex shader (e.g. `unpackColor(a_myAttr)`)
9+
*/
10+
/**
11+
* @typedef {Object} UniformDescription
12+
* @property {string} name Uniform name, as will be declared in the header of the vertex shader (including u_)
13+
* @property {string} type Uniform GLSL type, either `float`, `vec2`, `vec4`...
914
*/
1015
/**
1116
* @classdesc
@@ -14,8 +19,8 @@ export const COMMON_HEADER: "#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp
1419
*
1520
* ```js
1621
* const shader = new ShaderBuilder()
17-
* .addVarying('v_width', 'float', 'a_width')
18-
* .addUniform('u_time')
22+
* .addAttribute('a_width', 'float')
23+
* .addUniform('u_time', 'float)
1924
* .setColorExpression('...')
2025
* .setSymbolSizeExpression('...')
2126
* .getSymbolFragmentShader();
@@ -28,7 +33,7 @@ export const COMMON_HEADER: "#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp
2833
export class ShaderBuilder {
2934
/**
3035
* Uniforms; these will be declared in the header (should include the type).
31-
* @type {Array<string>}
36+
* @type {Array<UniformDescription>}
3237
* @private
3338
*/
3439
private uniforms_;
@@ -136,23 +141,24 @@ export class ShaderBuilder {
136141
/**
137142
* Adds a uniform accessible in both fragment and vertex shaders.
138143
* The given name should include a type, such as `sampler2D u_texture`.
139-
* @param {string} name Uniform name
144+
* @param {string} name Uniform name, including the `u_` prefix
145+
* @param {'float'|'vec2'|'vec3'|'vec4'|'sampler2D'} type GLSL type
140146
* @return {ShaderBuilder} the builder object
141147
*/
142-
addUniform(name: string): ShaderBuilder;
148+
addUniform(name: string, type: "float" | "vec2" | "vec3" | "vec4" | "sampler2D"): ShaderBuilder;
143149
/**
144150
* Adds an attribute accessible in the vertex shader, read from the geometry buffer.
145151
* The given name should include a type, such as `vec2 a_position`.
146152
* Attributes will also be made available under the same name in fragment shaders.
147-
* @param {string} name Attribute name
148-
* @param {'float'|'vec2'|'vec3'|'vec4'} type Type
149-
* @param {string} [transform] Expression which will be assigned to the varying in the vertex shader, and
153+
* @param {string} name Attribute name, including the `a_` prefix
154+
* @param {'float'|'vec2'|'vec3'|'vec4'} type GLSL type
155+
* @param {string} [varyingExpression] Expression which will be assigned to the varying in the vertex shader, and
150156
* passed on to the fragment shader.
151-
* @param {'float'|'vec2'|'vec3'|'vec4'} [transformedType] Type of the attribute after transformation;
157+
* @param {'float'|'vec2'|'vec3'|'vec4'} [varyingType] Type of the attribute after transformation;
152158
* e.g. `vec4` after unpacking color components
153159
* @return {ShaderBuilder} the builder object
154160
*/
155-
addAttribute(name: string, type: "float" | "vec2" | "vec3" | "vec4", transform?: string, transformedType?: "float" | "vec2" | "vec3" | "vec4"): ShaderBuilder;
161+
addAttribute(name: string, type: "float" | "vec2" | "vec3" | "vec4", varyingExpression?: string, varyingType?: "float" | "vec2" | "vec3" | "vec4"): ShaderBuilder;
156162
/**
157163
* Sets an expression to compute the size of the shape.
158164
* This expression can use all the uniforms and attributes available
@@ -312,24 +318,34 @@ export class ShaderBuilder {
312318
}
313319
export type AttributeDescription = {
314320
/**
315-
* Attribute name, as will be declared in the headers (including a_)
321+
* Attribute name, as will be declared in the header of the vertex shader (including a_)
316322
*/
317323
name: string;
318324
/**
319-
* Attribute type, either `float`, `vec2`, `vec4`...
325+
* Attribute GLSL type, either `float`, `vec2`, `vec4`...
320326
*/
321327
type: string;
322328
/**
323-
* Varying name, as will be declared in the fragment shader (including v_)
329+
* Varying name, as will be declared in the header of both shaders (including v_)
324330
*/
325331
varyingName: string;
326332
/**
327333
* Varying type, either `float`, `vec2`, `vec4`...
328334
*/
329335
varyingType: string;
330336
/**
331-
* GLSL expression to assign to the varying in the vertex shader
337+
* GLSL expression to assign to the varying in the vertex shader (e.g. `unpackColor(a_myAttr)`)
332338
*/
333339
varyingExpression: string;
334340
};
341+
export type UniformDescription = {
342+
/**
343+
* Uniform name, as will be declared in the header of the vertex shader (including u_)
344+
*/
345+
name: string;
346+
/**
347+
* Uniform GLSL type, either `float`, `vec2`, `vec4`...
348+
*/
349+
type: string;
350+
};
335351
//# sourceMappingURL=ShaderBuilder.d.ts.map

dist/en/main/ol/render/webgl/ShaderBuilder.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

dist/en/main/ol/render/webgl/ShaderBuilder.js

+33-23
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ const DEFAULT_STYLE = createDefaultStyle();
3434

3535
/**
3636
* @typedef {Object} AttributeDescription
37-
* @property {string} name Attribute name, as will be declared in the headers (including a_)
38-
* @property {string} type Attribute type, either `float`, `vec2`, `vec4`...
39-
* @property {string} varyingName Varying name, as will be declared in the fragment shader (including v_)
37+
* @property {string} name Attribute name, as will be declared in the header of the vertex shader (including a_)
38+
* @property {string} type Attribute GLSL type, either `float`, `vec2`, `vec4`...
39+
* @property {string} varyingName Varying name, as will be declared in the header of both shaders (including v_)
4040
* @property {string} varyingType Varying type, either `float`, `vec2`, `vec4`...
41-
* @property {string} varyingExpression GLSL expression to assign to the varying in the vertex shader
41+
* @property {string} varyingExpression GLSL expression to assign to the varying in the vertex shader (e.g. `unpackColor(a_myAttr)`)
42+
*/
43+
44+
/**
45+
* @typedef {Object} UniformDescription
46+
* @property {string} name Uniform name, as will be declared in the header of the vertex shader (including u_)
47+
* @property {string} type Uniform GLSL type, either `float`, `vec2`, `vec4`...
4248
*/
4349

4450
/**
@@ -48,8 +54,8 @@ const DEFAULT_STYLE = createDefaultStyle();
4854
*
4955
* ```js
5056
* const shader = new ShaderBuilder()
51-
* .addVarying('v_width', 'float', 'a_width')
52-
* .addUniform('u_time')
57+
* .addAttribute('a_width', 'float')
58+
* .addUniform('u_time', 'float)
5359
* .setColorExpression('...')
5460
* .setSymbolSizeExpression('...')
5561
* .getSymbolFragmentShader();
@@ -63,7 +69,7 @@ export class ShaderBuilder {
6369
constructor() {
6470
/**
6571
* Uniforms; these will be declared in the header (should include the type).
66-
* @type {Array<string>}
72+
* @type {Array<UniformDescription>}
6773
* @private
6874
*/
6975
this.uniforms_ = [];
@@ -202,33 +208,37 @@ export class ShaderBuilder {
202208
/**
203209
* Adds a uniform accessible in both fragment and vertex shaders.
204210
* The given name should include a type, such as `sampler2D u_texture`.
205-
* @param {string} name Uniform name
211+
* @param {string} name Uniform name, including the `u_` prefix
212+
* @param {'float'|'vec2'|'vec3'|'vec4'|'sampler2D'} type GLSL type
206213
* @return {ShaderBuilder} the builder object
207214
*/
208-
addUniform(name) {
209-
this.uniforms_.push(name);
215+
addUniform(name, type) {
216+
this.uniforms_.push({
217+
name,
218+
type,
219+
});
210220
return this;
211221
}
212222

213223
/**
214224
* Adds an attribute accessible in the vertex shader, read from the geometry buffer.
215225
* The given name should include a type, such as `vec2 a_position`.
216226
* Attributes will also be made available under the same name in fragment shaders.
217-
* @param {string} name Attribute name
218-
* @param {'float'|'vec2'|'vec3'|'vec4'} type Type
219-
* @param {string} [transform] Expression which will be assigned to the varying in the vertex shader, and
227+
* @param {string} name Attribute name, including the `a_` prefix
228+
* @param {'float'|'vec2'|'vec3'|'vec4'} type GLSL type
229+
* @param {string} [varyingExpression] Expression which will be assigned to the varying in the vertex shader, and
220230
* passed on to the fragment shader.
221-
* @param {'float'|'vec2'|'vec3'|'vec4'} [transformedType] Type of the attribute after transformation;
231+
* @param {'float'|'vec2'|'vec3'|'vec4'} [varyingType] Type of the attribute after transformation;
222232
* e.g. `vec4` after unpacking color components
223233
* @return {ShaderBuilder} the builder object
224234
*/
225-
addAttribute(name, type, transform, transformedType) {
235+
addAttribute(name, type, varyingExpression, varyingType) {
226236
this.attributes_.push({
227237
name,
228238
type,
229239
varyingName: name.replace(/^a_/, 'v_'),
230-
varyingType: transformedType ?? type,
231-
varyingExpression: transform ?? name,
240+
varyingType: varyingType ?? type,
241+
varyingExpression: varyingExpression ?? name,
232242
});
233243
return this;
234244
}
@@ -463,7 +473,7 @@ export class ShaderBuilder {
463473
}
464474

465475
return `${COMMON_HEADER}
466-
${this.uniforms_.map((uniform) => `uniform ${uniform};`).join('\n')}
476+
${this.uniforms_.map((uniform) => `uniform ${uniform.type} ${uniform.name};`).join('\n')}
467477
attribute vec2 a_position;
468478
attribute float a_index;
469479
attribute vec4 a_hitColor;
@@ -540,7 +550,7 @@ ${this.attributes_
540550
}
541551

542552
return `${COMMON_HEADER}
543-
${this.uniforms_.map((uniform) => `uniform ${uniform};`).join('\n')}
553+
${this.uniforms_.map((uniform) => `uniform ${uniform.type} ${uniform.name};`).join('\n')}
544554
varying vec2 v_texCoord;
545555
varying vec4 v_hitColor;
546556
varying vec2 v_centerPx;
@@ -584,7 +594,7 @@ ${this.attributes_
584594
}
585595

586596
return `${COMMON_HEADER}
587-
${this.uniforms_.map((uniform) => `uniform ${uniform};`).join('\n')}
597+
${this.uniforms_.map((uniform) => `uniform ${uniform.type} ${uniform.name};`).join('\n')}
588598
attribute vec2 a_segmentStart;
589599
attribute vec2 a_segmentEnd;
590600
attribute float a_measureStart;
@@ -704,7 +714,7 @@ ${this.attributes_
704714
}
705715

706716
return `${COMMON_HEADER}
707-
${this.uniforms_.map((uniform) => `uniform ${uniform};`).join('\n')}
717+
${this.uniforms_.map((uniform) => `uniform ${uniform.type} ${uniform.name};`).join('\n')}
708718
varying vec2 v_segmentStart;
709719
varying vec2 v_segmentEnd;
710720
varying float v_angleStart;
@@ -884,7 +894,7 @@ ${this.attributes_
884894
}
885895

886896
return `${COMMON_HEADER}
887-
${this.uniforms_.map((uniform) => `uniform ${uniform};`).join('\n')}
897+
${this.uniforms_.map((uniform) => `uniform ${uniform.type} ${uniform.name};`).join('\n')}
888898
attribute vec2 a_position;
889899
attribute vec4 a_hitColor;
890900
@@ -919,7 +929,7 @@ ${this.attributes_
919929
}
920930

921931
return `${COMMON_HEADER}
922-
${this.uniforms_.map((uniform) => `uniform ${uniform};`).join('\n')}
932+
${this.uniforms_.map((uniform) => `uniform ${uniform.type} ${uniform.name};`).join('\n')}
923933
varying vec4 v_hitColor;
924934
${this.attributes_
925935
.map(

dist/en/main/ol/render/webgl/compileUtil.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

dist/en/main/ol/render/webgl/compileUtil.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function applyContextToBuilder(builder, context) {
9999
// we're not packing colors when they're passed as uniforms
100100
glslType = 'vec4';
101101
}
102-
builder.addUniform(`${glslType} ${uniformName}`);
102+
builder.addUniform(uniformName, glslType);
103103
}
104104

105105
// for each feature attribute used in the fragment shader, define a varying that will be used to pass data
@@ -153,7 +153,12 @@ export function generateUniformsFromContext(context, variables) {
153153
return value ? 1 : 0;
154154
}
155155
if (variable.type === ColorType) {
156-
return asArray(value || '#eee');
156+
const color = [...asArray(value || '#eee')];
157+
color[0] /= 255;
158+
color[1] /= 255;
159+
color[2] /= 255;
160+
color[3] ??= 1;
161+
return color;
157162
}
158163
if (typeof value === 'string') {
159164
return getStringNumberEquivalent(value);

dist/en/main/ol/render/webgl/style.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ function parseImageProperties(style, builder, uniforms, prefix, textureId) {
157157
uniforms[`u_texture${textureId}_size`] = () => {
158158
return image.complete ? [image.width, image.height] : [0, 0];
159159
};
160-
builder.addUniform(`vec2 u_texture${textureId}_size`);
160+
builder.addUniform(`u_texture${textureId}_size`, 'vec2');
161161
const size = `u_texture${textureId}_size`;
162162

163163
uniforms[`u_texture${textureId}`] = image;
164-
builder.addUniform(`sampler2D u_texture${textureId}`);
164+
builder.addUniform(`u_texture${textureId}`, 'sampler2D');
165165
return size;
166166
}
167167

0 commit comments

Comments
 (0)