diff --git a/src/data/program_configuration.js b/src/data/program_configuration.js index 2cdaaccda20..7fd0f2281df 100644 --- a/src/data/program_configuration.js +++ b/src/data/program_configuration.js @@ -19,7 +19,7 @@ import type {StructArray, StructArrayMember} from '../util/struct_array'; import type VertexBuffer from '../gl/vertex_buffer'; import type {Feature, SourceExpression, CompositeExpression} from '../style-spec/expression'; import type {PossiblyEvaluated} from '../style/properties'; -import type {UniformValues} from '../render/uniform_binding'; +import type {BinderUniformTypes} from '../render/uniform_binding'; function packColor(color: Color): [number, number] { return [ @@ -333,7 +333,7 @@ class ProgramConfiguration { return this._buffers; } - getUniformBindings(context: Context): Uniforms { + getUniformBindings(context: Context): Uniforms { const uniformBindings = {}; for (const property in this.binders) { const binder = this.binders[property]; @@ -347,7 +347,7 @@ class ProgramConfiguration { return new Uniforms(uniformBindings); } - getUniforms(properties: PossiblyEvaluated, globals: GlobalProperties): UniformValues { + getUniforms(properties: PossiblyEvaluated, globals: GlobalProperties) { const uniformValues = {}; for (const property in this.binders) { const binder = this.binders[property]; diff --git a/src/gl/vertex_buffer.js b/src/gl/vertex_buffer.js index 917d4be6d6a..dafba66da41 100644 --- a/src/gl/vertex_buffer.js +++ b/src/gl/vertex_buffer.js @@ -68,7 +68,7 @@ class VertexBuffer { gl.bufferSubData(gl.ARRAY_BUFFER, 0, array.arrayBuffer); } - enableAttributes(gl: WebGLRenderingContext, program: Program) { + enableAttributes(gl: WebGLRenderingContext, program: Program<*>) { for (let j = 0; j < this.attributes.length; j++) { const member = this.attributes[j]; const attribIndex: number | void = program.attributes[member.name]; @@ -84,7 +84,7 @@ class VertexBuffer { * @param program The active WebGL program * @param vertexOffset Index of the starting vertex of the segment */ - setVertexAttribPointers(gl: WebGLRenderingContext, program: Program, vertexOffset: ?number) { + setVertexAttribPointers(gl: WebGLRenderingContext, program: Program<*>, vertexOffset: ?number) { for (let j = 0; j < this.attributes.length; j++) { const member = this.attributes[j]; const attribIndex: number | void = program.attributes[member.name]; diff --git a/src/render/painter.js b/src/render/painter.js index c608b828d8f..277136e9261 100644 --- a/src/render/painter.js +++ b/src/render/painter.js @@ -99,7 +99,7 @@ class Painter { currentLayer: number; id: string; _showOverdrawInspector: boolean; - cache: { [string]: Program }; + cache: { [string]: Program<*> }; crossTileSymbolIndex: CrossTileSymbolIndex; symbolFadeChange: number; @@ -481,7 +481,7 @@ class Painter { return !imagePosA || !imagePosB; } - _createProgramCached(name: string, programConfiguration: ProgramConfiguration): Program { + _createProgramCached(name: string, programConfiguration: ProgramConfiguration): Program { this.cache = this.cache || {}; const key = `${name}${programConfiguration.cacheKey || ''}${this._showOverdrawInspector ? '/overdraw' : ''}`; if (!this.cache[key]) { @@ -490,7 +490,7 @@ class Painter { return this.cache[key]; } - useProgram(name: string, programConfiguration?: ProgramConfiguration): Program { + useProgram(name: string, programConfiguration?: ProgramConfiguration): Program { const nextProgram = this._createProgramCached(name, programConfiguration || this.emptyProgramConfiguration); this.context.program.set(nextProgram.program); diff --git a/src/render/program.js b/src/render/program.js index a16d7c9b98c..1daca03b68a 100644 --- a/src/render/program.js +++ b/src/render/program.js @@ -13,26 +13,26 @@ import type IndexBuffer from '../gl/index_buffer'; import type DepthMode from '../gl/depth_mode'; import type StencilMode from '../gl/stencil_mode'; import type ColorMode from '../gl/color_mode'; -import type {Uniforms, UniformValues, UniformLocations} from './uniform_binding'; +import type {Uniforms, UniformBindings, UniformValues, UniformLocations, BinderUniformTypes} from './uniform_binding'; export type DrawMode = | $PropertyType | $PropertyType | $PropertyType; -class Program { +class Program { program: WebGLProgram; uniforms: UniformLocations; attributes: {[string]: number}; numAttributes: number; - fixedUniforms: Uniforms; - binderUniforms: Uniforms; + fixedUniforms: Uniforms; + binderUniforms: Uniforms; configuration: ProgramConfiguration; constructor(context: Context, source: {fragmentSource: string, vertexSource: string}, configuration: ProgramConfiguration, - fixedUniforms: (Context) => Uniforms, + fixedUniforms: (Context) => Uniforms, showOverdrawInspector: boolean) { const gl = context.gl; this.program = gl.createProgram(); @@ -99,7 +99,7 @@ class Program { depthMode: $ReadOnly, stencilMode: $ReadOnly, colorMode: $ReadOnly, - uniformValues: UniformValues, + uniformValues: UniformValues, layerID: string, layoutVertexBuffer: VertexBuffer, indexBuffer: IndexBuffer, diff --git a/src/render/program/background_program.js b/src/render/program/background_program.js index 3221548972d..604708cb9b5 100644 --- a/src/render/program/background_program.js +++ b/src/render/program/background_program.js @@ -1,8 +1,10 @@ // @flow -const {patternUniforms, patternUniformValues} = require('./pattern'); +const {patternUniformValues} = require('./pattern'); const { + Uniform1i, Uniform1f, + Uniform2fv, Uniform4fv, UniformMatrix4fv, Uniforms @@ -16,47 +18,80 @@ import type Color from '../../style-spec/util/color'; import type {CrossFaded} from '../../style/cross_faded'; import type {OverscaledTileID} from '../../source/tile_id'; -function backgroundUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_opacity': new Uniform1f(context), - 'u_color': new Uniform4fv(context) - }); -} +export type BackgroundUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_opacity': Uniform1f, + 'u_color': Uniform4fv +|}; -function backgroundPatternUniforms(context: Context): Uniforms { - return patternUniforms(context) - .concatenate(new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_opacity': new Uniform1f(context) - })); -} +export type BackgroundPatternUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_opacity': Uniform1f, + // pattern uniforms: + 'u_image': Uniform1i, + 'u_pattern_tl_a': Uniform2fv, + 'u_pattern_br_a': Uniform2fv, + 'u_pattern_tl_b': Uniform2fv, + 'u_pattern_br_b': Uniform2fv, + 'u_texsize': Uniform2fv, + 'u_mix': Uniform1f, + 'u_pattern_size_a': Uniform2fv, + 'u_pattern_size_b': Uniform2fv, + 'u_scale_a': Uniform1f, + 'u_scale_b': Uniform1f, + 'u_pixel_coord_upper': Uniform2fv, + 'u_pixel_coord_lower': Uniform2fv, + 'u_tile_units_to_pixels': Uniform1f +|}; -function backgroundUniformValues( +const backgroundUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_opacity': new Uniform1f(context), + 'u_color': new Uniform4fv(context) +}); + +const backgroundPatternUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_opacity': new Uniform1f(context), + 'u_image': new Uniform1i(context), + 'u_pattern_tl_a': new Uniform2fv(context), + 'u_pattern_br_a': new Uniform2fv(context), + 'u_pattern_tl_b': new Uniform2fv(context), + 'u_pattern_br_b': new Uniform2fv(context), + 'u_texsize': new Uniform2fv(context), + 'u_mix': new Uniform1f(context), + 'u_pattern_size_a': new Uniform2fv(context), + 'u_pattern_size_b': new Uniform2fv(context), + 'u_scale_a': new Uniform1f(context), + 'u_scale_b': new Uniform1f(context), + 'u_pixel_coord_upper': new Uniform2fv(context), + 'u_pixel_coord_lower': new Uniform2fv(context), + 'u_tile_units_to_pixels': new Uniform1f(context) +}); + +const backgroundUniformValues = ( matrix: Float32Array, opacity: number, color: Color -): UniformValues { - return { - 'u_matrix': matrix, - 'u_opacity': opacity, - 'u_color': [color.r, color.g, color.b, color.a] - }; -} +): UniformValues => ({ + 'u_matrix': matrix, + 'u_opacity': opacity, + 'u_color': [color.r, color.g, color.b, color.a] +}); -function backgroundPatternUniformValues( +const backgroundPatternUniformValues = ( matrix: Float32Array, opacity: number, painter: Painter, image: CrossFaded, tile: {tileID: OverscaledTileID, tileSize: number} -): UniformValues { - return util.extend(patternUniformValues(image, painter, tile), - { - 'u_matrix': matrix, - 'u_opacity': opacity - }); -} +): UniformValues => util.extend( + patternUniformValues(image, painter, tile), + { + 'u_matrix': matrix, + 'u_opacity': opacity + } +); module.exports = { backgroundUniforms, diff --git a/src/render/program/circle_program.js b/src/render/program/circle_program.js index 602db391ec0..141052cad17 100644 --- a/src/render/program/circle_program.js +++ b/src/render/program/circle_program.js @@ -16,22 +16,28 @@ import type Tile from '../../source/tile'; import type CircleStyleLayer from '../../style/style_layer/circle_style_layer'; import type Painter from '../painter'; -function circleUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_camera_to_center_distance': new Uniform1f(context), - 'u_scale_with_map': new Uniform1i(context), - 'u_pitch_with_map': new Uniform1i(context), - 'u_extrude_scale': new Uniform2fv(context), - 'u_matrix': new UniformMatrix4fv(context) - }); -} - -function circleUniformValues( +export type CircleUniformsType = {| + 'u_camera_to_center_distance': Uniform1f, + 'u_scale_with_map': Uniform1i, + 'u_pitch_with_map': Uniform1i, + 'u_extrude_scale': Uniform2fv, + 'u_matrix': UniformMatrix4fv +|}; + +const circleUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_camera_to_center_distance': new Uniform1f(context), + 'u_scale_with_map': new Uniform1i(context), + 'u_pitch_with_map': new Uniform1i(context), + 'u_extrude_scale': new Uniform2fv(context), + 'u_matrix': new UniformMatrix4fv(context) +}); + +const circleUniformValues = ( painter: Painter, coord: OverscaledTileID, tile: Tile, layer: CircleStyleLayer -): UniformValues { +): UniformValues => { const transform = painter.transform; let pitchWithMap, extrudeScale; @@ -55,6 +61,6 @@ function circleUniformValues( 'u_pitch_with_map': +(pitchWithMap), 'u_extrude_scale': extrudeScale }; -} +}; module.exports = { circleUniforms, circleUniformValues }; diff --git a/src/render/program/clipping_mask_program.js b/src/render/program/clipping_mask_program.js index ad9a2a0d32d..3acb370cad9 100644 --- a/src/render/program/clipping_mask_program.js +++ b/src/render/program/clipping_mask_program.js @@ -5,16 +5,16 @@ const {UniformMatrix4fv, Uniforms} = require('../uniform_binding'); import type Context from '../../gl/context'; import type {UniformValues} from '../uniform_binding'; -function clippingMaskUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context) - }); -} +export type ClippingMaskUniformsType = {| + 'u_matrix': UniformMatrix4fv +|}; -function clippingMaskUniformValues(matrix: Float32Array): UniformValues { - return { - 'u_matrix': matrix - }; -} +const clippingMaskUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context) +}); + +const clippingMaskUniformValues = (matrix: Float32Array): UniformValues => ({ + 'u_matrix': matrix +}); module.exports = { clippingMaskUniforms, clippingMaskUniformValues }; diff --git a/src/render/program/collision_program.js b/src/render/program/collision_program.js index dd49d5dbed5..0608f8bd447 100644 --- a/src/render/program/collision_program.js +++ b/src/render/program/collision_program.js @@ -13,21 +13,27 @@ import type {UniformValues} from '../uniform_binding'; import type Transform from '../../geo/transform'; import type Tile from '../../source/tile'; -function collisionUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_camera_to_center_distance': new Uniform1f(context), - 'u_pixels_to_tile_units': new Uniform1f(context), - 'u_extrude_scale': new Uniform2fv(context), - 'u_overscale_factor': new Uniform1f(context) - }); -} +export type CollisionUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_camera_to_center_distance': Uniform1f, + 'u_pixels_to_tile_units': Uniform1f, + 'u_extrude_scale': Uniform2fv, + 'u_overscale_factor': Uniform1f +|}; -function collisionUniformValues( +const collisionUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_camera_to_center_distance': new Uniform1f(context), + 'u_pixels_to_tile_units': new Uniform1f(context), + 'u_extrude_scale': new Uniform2fv(context), + 'u_overscale_factor': new Uniform1f(context) +}); + +const collisionUniformValues = ( matrix: Float32Array, transform: Transform, tile: Tile -): UniformValues { +): UniformValues => { const pixelRatio = pixelsToTileUnits(tile, 1, transform.zoom); const scale = Math.pow(2, transform.zoom - tile.tileID.overscaledZ); const overscaleFactor = tile.tileID.overscaleFactor(); @@ -39,6 +45,6 @@ function collisionUniformValues( transform.pixelsToGLUnits[1] / (pixelRatio * scale)], 'u_overscale_factor': overscaleFactor }; -} +}; module.exports = { collisionUniforms, collisionUniformValues }; diff --git a/src/render/program/debug_program.js b/src/render/program/debug_program.js index 4ba6457074e..13549f4e7a2 100644 --- a/src/render/program/debug_program.js +++ b/src/render/program/debug_program.js @@ -10,18 +10,19 @@ import type Context from '../../gl/context'; import type {UniformValues} from '../uniform_binding'; import type Color from '../../style-spec/util/color'; -function debugUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_color': new Uniform4fv(context), - 'u_matrix': new UniformMatrix4fv(context) - }); -} +export type DebugUniformsType = {| + 'u_color': Uniform4fv, + 'u_matrix': UniformMatrix4fv +|}; -function debugUniformValues(matrix: Float32Array, color: Color): UniformValues { - return { - 'u_matrix': matrix, - 'u_color': [color.r, color.g, color.b, color.a] - }; -} +const debugUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_color': new Uniform4fv(context), + 'u_matrix': new UniformMatrix4fv(context) +}); + +const debugUniformValues = (matrix: Float32Array, color: Color): UniformValues => ({ + 'u_matrix': matrix, + 'u_color': [color.r, color.g, color.b, color.a] +}); module.exports = { debugUniforms, debugUniformValues }; diff --git a/src/render/program/fill_extrusion_program.js b/src/render/program/fill_extrusion_program.js index 446c094e9e8..8524237ebda 100644 --- a/src/render/program/fill_extrusion_program.js +++ b/src/render/program/fill_extrusion_program.js @@ -1,6 +1,6 @@ // @flow -const {patternUniforms, patternUniformValues} = require('./pattern'); +const {patternUniformValues} = require('./pattern'); const { Uniform1i, Uniform1f, @@ -23,36 +23,83 @@ import type {CrossFaded} from '../../style/cross_faded'; import type {UniformValues} from '../uniform_binding'; import type FillExtrusionStyleLayer from '../../style/style_layer/fill_extrusion_style_layer'; -function fillExtrusionUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_lightpos': new Uniform3fv(context), - 'u_lightintensity': new Uniform1f(context), - 'u_lightcolor': new Uniform3fv(context) - }); -} - -function fillExtrusionPatternUniforms(context: Context): Uniforms { - return fillExtrusionUniforms(context) - .concatenate(patternUniforms(context)) - .concatenate(new Uniforms({ - 'u_height_factor': new Uniform1f(context) - })); -} - -function extrusionTextureUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_world': new Uniform2fv(context), - 'u_image': new Uniform1i(context), - 'u_opacity': new Uniform1f(context) - }); -} - -function fillExtrusionUniformValues( +export type FillExtrusionUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_lightpos': Uniform3fv, + 'u_lightintensity': Uniform1f, + 'u_lightcolor': Uniform3fv +|}; + +export type FillExtrusionPatternUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_lightpos': Uniform3fv, + 'u_lightintensity': Uniform1f, + 'u_lightcolor': Uniform3fv, + 'u_height_factor': Uniform1f, + // pattern uniforms: + 'u_image': Uniform1i, + 'u_pattern_tl_a': Uniform2fv, + 'u_pattern_br_a': Uniform2fv, + 'u_pattern_tl_b': Uniform2fv, + 'u_pattern_br_b': Uniform2fv, + 'u_texsize': Uniform2fv, + 'u_mix': Uniform1f, + 'u_pattern_size_a': Uniform2fv, + 'u_pattern_size_b': Uniform2fv, + 'u_scale_a': Uniform1f, + 'u_scale_b': Uniform1f, + 'u_pixel_coord_upper': Uniform2fv, + 'u_pixel_coord_lower': Uniform2fv, + 'u_tile_units_to_pixels': Uniform1f +|}; + +export type ExtrusionTextureUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_world': Uniform2fv, + 'u_image': Uniform1i, + 'u_opacity': Uniform1f +|}; + +const fillExtrusionUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_lightpos': new Uniform3fv(context), + 'u_lightintensity': new Uniform1f(context), + 'u_lightcolor': new Uniform3fv(context) +}); + +const fillExtrusionPatternUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_lightpos': new Uniform3fv(context), + 'u_lightintensity': new Uniform1f(context), + 'u_lightcolor': new Uniform3fv(context), + 'u_height_factor': new Uniform1f(context), + 'u_image': new Uniform1i(context), + 'u_pattern_tl_a': new Uniform2fv(context), + 'u_pattern_br_a': new Uniform2fv(context), + 'u_pattern_tl_b': new Uniform2fv(context), + 'u_pattern_br_b': new Uniform2fv(context), + 'u_texsize': new Uniform2fv(context), + 'u_mix': new Uniform1f(context), + 'u_pattern_size_a': new Uniform2fv(context), + 'u_pattern_size_b': new Uniform2fv(context), + 'u_scale_a': new Uniform1f(context), + 'u_scale_b': new Uniform1f(context), + 'u_pixel_coord_upper': new Uniform2fv(context), + 'u_pixel_coord_lower': new Uniform2fv(context), + 'u_tile_units_to_pixels': new Uniform1f(context) +}); + +const extrusionTextureUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_world': new Uniform2fv(context), + 'u_image': new Uniform1i(context), + 'u_opacity': new Uniform1f(context) +}); + +const fillExtrusionUniformValues = ( matrix: Float32Array, painter: Painter -): UniformValues { +): UniformValues => { const light = painter.style.light; const _lp = light.properties.get('position'); const lightPos = [_lp.x, _lp.y, _lp.z]; @@ -70,27 +117,27 @@ function fillExtrusionUniformValues( 'u_lightintensity': light.properties.get('intensity'), 'u_lightcolor': [lightColor.r, lightColor.g, lightColor.b] }; -} +}; -function fillExtrusionPatternUniformValues( +const fillExtrusionPatternUniformValues = ( matrix: Float32Array, painter: Painter, coord: OverscaledTileID, image: CrossFaded, tile: {tileID: OverscaledTileID, tileSize: number} -): UniformValues { +): UniformValues => { return util.extend(fillExtrusionUniformValues(matrix, painter), patternUniformValues(image, painter, tile), { 'u_height_factor': -Math.pow(2, coord.overscaledZ) / tile.tileSize / 8 }); -} +}; -function extrusionTextureUniformValues( +const extrusionTextureUniformValues = ( painter: Painter, layer: FillExtrusionStyleLayer, textureUnit: number -): UniformValues { +): UniformValues => { const matrix = mat4.create(); mat4.ortho(matrix, 0, painter.width, painter.height, 0, 0, 1); @@ -102,7 +149,7 @@ function extrusionTextureUniformValues( 'u_image': textureUnit, 'u_opacity': layer.paint.get('fill-extrusion-opacity') }; -} +}; module.exports = { fillExtrusionUniforms, diff --git a/src/render/program/fill_program.js b/src/render/program/fill_program.js index f1bb6b473ef..8fff3b6ffc1 100644 --- a/src/render/program/fill_program.js +++ b/src/render/program/fill_program.js @@ -1,7 +1,9 @@ // @flow -const {patternUniforms, patternUniformValues} = require('./pattern'); +const {patternUniformValues} = require('./pattern'); const { + Uniform1i, + Uniform1f, Uniform2fv, UniformMatrix4fv, Uniforms @@ -14,66 +16,135 @@ import type Context from '../../gl/context'; import type {CrossFaded} from '../../style/cross_faded'; import type {OverscaledTileID} from '../../source/tile_id'; -function fillUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - }); -} - -function fillPatternUniforms(context: Context): Uniforms { - return fillUniforms(context) - .concatenate(patternUniforms(context)); -} - -function fillOutlineUniforms(context: Context): Uniforms { - return fillUniforms(context) - .concatenate(new Uniforms({ - 'u_world': new Uniform2fv(context) - })); -} - -function fillOutlinePatternUniforms(context: Context): Uniforms { - return fillOutlineUniforms(context) - .concatenate(patternUniforms(context)); -} - -function fillUniformValues(matrix: Float32Array): UniformValues { - return { - 'u_matrix': matrix - }; -} - -function fillPatternUniformValues( + +export type FillUniformsType = {| + 'u_matrix': UniformMatrix4fv +|}; + +export type FillOutlineUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_world': Uniform2fv +|}; + +export type FillPatternUniformsType = {| + 'u_matrix': UniformMatrix4fv, + // pattern uniforms: + 'u_image': Uniform1i, + 'u_pattern_tl_a': Uniform2fv, + 'u_pattern_br_a': Uniform2fv, + 'u_pattern_tl_b': Uniform2fv, + 'u_pattern_br_b': Uniform2fv, + 'u_texsize': Uniform2fv, + 'u_mix': Uniform1f, + 'u_pattern_size_a': Uniform2fv, + 'u_pattern_size_b': Uniform2fv, + 'u_scale_a': Uniform1f, + 'u_scale_b': Uniform1f, + 'u_pixel_coord_upper': Uniform2fv, + 'u_pixel_coord_lower': Uniform2fv, + 'u_tile_units_to_pixels': Uniform1f +|}; + +export type FillOutlinePatternUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_world': Uniform2fv, + // pattern uniforms: + 'u_image': Uniform1i, + 'u_pattern_tl_a': Uniform2fv, + 'u_pattern_br_a': Uniform2fv, + 'u_pattern_tl_b': Uniform2fv, + 'u_pattern_br_b': Uniform2fv, + 'u_texsize': Uniform2fv, + 'u_mix': Uniform1f, + 'u_pattern_size_a': Uniform2fv, + 'u_pattern_size_b': Uniform2fv, + 'u_scale_a': Uniform1f, + 'u_scale_b': Uniform1f, + 'u_pixel_coord_upper': Uniform2fv, + 'u_pixel_coord_lower': Uniform2fv, + 'u_tile_units_to_pixels': Uniform1f +|}; + +const fillUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context) +}); + +const fillPatternUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_image': new Uniform1i(context), + 'u_pattern_tl_a': new Uniform2fv(context), + 'u_pattern_br_a': new Uniform2fv(context), + 'u_pattern_tl_b': new Uniform2fv(context), + 'u_pattern_br_b': new Uniform2fv(context), + 'u_texsize': new Uniform2fv(context), + 'u_mix': new Uniform1f(context), + 'u_pattern_size_a': new Uniform2fv(context), + 'u_pattern_size_b': new Uniform2fv(context), + 'u_scale_a': new Uniform1f(context), + 'u_scale_b': new Uniform1f(context), + 'u_pixel_coord_upper': new Uniform2fv(context), + 'u_pixel_coord_lower': new Uniform2fv(context), + 'u_tile_units_to_pixels': new Uniform1f(context) +}); + +const fillOutlineUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_world': new Uniform2fv(context) +}); + +const fillOutlinePatternUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_world': new Uniform2fv(context), + 'u_image': new Uniform1i(context), + 'u_pattern_tl_a': new Uniform2fv(context), + 'u_pattern_br_a': new Uniform2fv(context), + 'u_pattern_tl_b': new Uniform2fv(context), + 'u_pattern_br_b': new Uniform2fv(context), + 'u_texsize': new Uniform2fv(context), + 'u_mix': new Uniform1f(context), + 'u_pattern_size_a': new Uniform2fv(context), + 'u_pattern_size_b': new Uniform2fv(context), + 'u_scale_a': new Uniform1f(context), + 'u_scale_b': new Uniform1f(context), + 'u_pixel_coord_upper': new Uniform2fv(context), + 'u_pixel_coord_lower': new Uniform2fv(context), + 'u_tile_units_to_pixels': new Uniform1f(context) +}); + +const fillUniformValues = (matrix: Float32Array): UniformValues => ({ + 'u_matrix': matrix +}); + +const fillPatternUniformValues = ( matrix: Float32Array, painter: Painter, image: CrossFaded, tile: {tileID: OverscaledTileID, tileSize: number} -): UniformValues { - return util.extend(fillUniformValues(matrix), - patternUniformValues(image, painter, tile)); -} +): UniformValues => util.extend( + fillUniformValues(matrix), + patternUniformValues(image, painter, tile) +); -function fillOutlineUniformValues( +const fillOutlineUniformValues = ( matrix: Float32Array, drawingBufferSize: Array -): UniformValues { - return { - 'u_matrix': matrix, - 'u_world': drawingBufferSize - }; -} +): UniformValues => ({ + 'u_matrix': matrix, + 'u_world': drawingBufferSize +}); -function fillOutlinePatternUniformValues( +const fillOutlinePatternUniformValues = ( matrix: Float32Array, painter: Painter, image: CrossFaded, tile: {tileID: OverscaledTileID, tileSize: number}, drawingBufferSize: Array -): UniformValues { - return util.extend(fillPatternUniformValues(matrix, painter, image, tile), { +): UniformValues => util.extend( + fillPatternUniformValues(matrix, painter, image, tile), + { 'u_world': drawingBufferSize - }); -} + } +); module.exports = { fillUniforms, diff --git a/src/render/program/heatmap_program.js b/src/render/program/heatmap_program.js index 1fc12e7906b..666930f5845 100644 --- a/src/render/program/heatmap_program.js +++ b/src/render/program/heatmap_program.js @@ -16,43 +16,51 @@ import type {UniformValues} from '../uniform_binding'; import type Painter from '../painter'; import type HeatmapStyleLayer from '../../style/style_layer/heatmap_style_layer'; -function heatmapUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_extrude_scale': new Uniform1f(context), - 'u_intensity': new Uniform1f(context), - 'u_matrix': new UniformMatrix4fv(context) - }); -} +export type HeatmapUniformsType = {| + 'u_extrude_scale': Uniform1f, + 'u_intensity': Uniform1f, + 'u_matrix': UniformMatrix4fv +|}; -function heatmapTextureUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_world': new Uniform2fv(context), - 'u_image': new Uniform1i(context), - 'u_color_ramp': new Uniform1i(context), - 'u_opacity': new Uniform1f(context) - }); -} +export type HeatmapTextureUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_world': Uniform2fv, + 'u_image': Uniform1i, + 'u_color_ramp': Uniform1i, + 'u_opacity': Uniform1f +|}; -function heatmapUniformValues( +const heatmapUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_extrude_scale': new Uniform1f(context), + 'u_intensity': new Uniform1f(context), + 'u_matrix': new UniformMatrix4fv(context) +}); + +const heatmapTextureUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_world': new Uniform2fv(context), + 'u_image': new Uniform1i(context), + 'u_color_ramp': new Uniform1i(context), + 'u_opacity': new Uniform1f(context) +}); + +const heatmapUniformValues = ( matrix: Float32Array, tile: Tile, zoom: number, intensity: number -): UniformValues { - return { - 'u_matrix': matrix, - 'u_extrude_scale': pixelsToTileUnits(tile, 1, zoom), - 'u_intensity': intensity - }; -} +): UniformValues => ({ + 'u_matrix': matrix, + 'u_extrude_scale': pixelsToTileUnits(tile, 1, zoom), + 'u_intensity': intensity +}); -function heatmapTextureUniformValues( +const heatmapTextureUniformValues = ( painter: Painter, layer: HeatmapStyleLayer, textureUnit: number, colorRampUnit: number -): UniformValues { +): UniformValues => { const matrix = mat4.create(); mat4.ortho(matrix, 0, painter.width, painter.height, 0, 0, 1); @@ -65,7 +73,7 @@ function heatmapTextureUniformValues( 'u_color_ramp': colorRampUnit, 'u_opacity': layer.paint.get('heatmap-opacity') }; -} +}; module.exports = { heatmapUniforms, diff --git a/src/render/program/hillshade_program.js b/src/render/program/hillshade_program.js index 96ab3e2c03c..1ff88417930 100644 --- a/src/render/program/hillshade_program.js +++ b/src/render/program/hillshade_program.js @@ -19,33 +19,47 @@ import type Painter from '../painter'; import type HillshadeStyleLayer from '../../style/style_layer/hillshade_style_layer'; import type {OverscaledTileID} from '../../source/tile_id'; -function hillshadeUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_image': new Uniform1i(context), - 'u_latrange': new Uniform2fv(context), - 'u_light': new Uniform2fv(context), - 'u_shadow': new Uniform4fv(context), - 'u_highlight': new Uniform4fv(context), - 'u_accent': new Uniform4fv(context) - }); -} +export type HillshadeUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_image': Uniform1i, + 'u_latrange': Uniform2fv, + 'u_light': Uniform2fv, + 'u_shadow': Uniform4fv, + 'u_highlight': Uniform4fv, + 'u_accent': Uniform4fv +|}; -function hillshadePrepareUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_image': new Uniform1i(context), - 'u_dimension': new Uniform2fv(context), - 'u_zoom': new Uniform1f(context), - 'u_maxzoom': new Uniform1f(context) - }); -} +export type HillshadePrepareUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_image': Uniform1i, + 'u_dimension': Uniform2fv, + 'u_zoom': Uniform1f, + 'u_maxzoom': Uniform1f +|}; + +const hillshadeUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_image': new Uniform1i(context), + 'u_latrange': new Uniform2fv(context), + 'u_light': new Uniform2fv(context), + 'u_shadow': new Uniform4fv(context), + 'u_highlight': new Uniform4fv(context), + 'u_accent': new Uniform4fv(context) +}); + +const hillshadePrepareUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_image': new Uniform1i(context), + 'u_dimension': new Uniform2fv(context), + 'u_zoom': new Uniform1f(context), + 'u_maxzoom': new Uniform1f(context) +}); -function hillshadeUniformValues( +const hillshadeUniformValues = ( painter: Painter, tile: Tile, layer: HillshadeStyleLayer -): UniformValues { +): UniformValues => { const shadow = layer.paint.get("hillshade-shadow-color"); const highlight = layer.paint.get("hillshade-highlight-color"); const accent = layer.paint.get("hillshade-accent-color"); @@ -65,11 +79,11 @@ function hillshadeUniformValues( 'u_highlight': [highlight.r, highlight.g, highlight.b, highlight.a], 'u_accent': [accent.r, accent.g, accent.b, accent.a] }; -} +}; -function hillshadeUniformPrepareValues( +const hillshadeUniformPrepareValues = ( tile: {dem: any, tileID: OverscaledTileID}, maxzoom: number -): UniformValues { +): UniformValues => { const tileSize = tile.dem.level.dim; const matrix = mat4.create(); // Flip rendering at y axis. @@ -83,7 +97,7 @@ function hillshadeUniformPrepareValues( 'u_zoom': tile.tileID.overscaledZ, 'u_maxzoom': maxzoom }; -} +}; function getTileLatRange(painter: Painter, tileID: OverscaledTileID) { // for scaling the magnitude of a points slope by its latitude diff --git a/src/render/program/line_program.js b/src/render/program/line_program.js index a3c6d661f3a..bd603aa06e3 100644 --- a/src/render/program/line_program.js +++ b/src/render/program/line_program.js @@ -19,47 +19,79 @@ import type {CrossFaded} from '../../style/cross_faded'; import type LineStyleLayer from '../../style/style_layer/line_style_layer'; import type Painter from '../painter'; -function lineUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_ratio': new Uniform1f(context), - 'u_gl_units_to_pixels': new Uniform2fv(context) - }); -} - -function linePatternUniforms(context: Context): Uniforms { - return lineUniforms(context) - .concatenate(new Uniforms({ - 'u_pattern_size_a': new Uniform2fv(context), - 'u_pattern_size_b': new Uniform2fv(context), - 'u_texsize': new Uniform2fv(context), - 'u_image': new Uniform1i(context), - 'u_pattern_tl_a': new Uniform2fv(context), - 'u_pattern_br_a': new Uniform2fv(context), - 'u_pattern_tl_b': new Uniform2fv(context), - 'u_pattern_br_b': new Uniform2fv(context), - 'u_fade': new Uniform1f(context) - })); -} - -function lineSDFUniforms(context: Context): Uniforms { - return lineUniforms(context) - .concatenate(new Uniforms({ - 'u_patternscale_a': new Uniform2fv(context), - 'u_patternscale_b': new Uniform2fv(context), - 'u_sdfgamma': new Uniform1f(context), - 'u_image': new Uniform1i(context), - 'u_tex_y_a': new Uniform1f(context), - 'u_tex_y_b': new Uniform1f(context), - 'u_mix': new Uniform1f(context) - })); -} - -function lineUniformValues( +export type LineUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_ratio': Uniform1f, + 'u_gl_units_to_pixels': Uniform2fv +|}; + +export type LinePatternUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_ratio': Uniform1f, + 'u_gl_units_to_pixels': Uniform2fv, + 'u_pattern_size_a': Uniform2fv, + 'u_pattern_size_b': Uniform2fv, + 'u_texsize': Uniform2fv, + 'u_image': Uniform1i, + 'u_pattern_tl_a': Uniform2fv, + 'u_pattern_br_a': Uniform2fv, + 'u_pattern_tl_b': Uniform2fv, + 'u_pattern_br_b': Uniform2fv, + 'u_fade': Uniform1f +|}; + +export type LineSDFUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_ratio': Uniform1f, + 'u_gl_units_to_pixels': Uniform2fv, + 'u_patternscale_a': Uniform2fv, + 'u_patternscale_b': Uniform2fv, + 'u_sdfgamma': Uniform1f, + 'u_image': Uniform1i, + 'u_tex_y_a': Uniform1f, + 'u_tex_y_b': Uniform1f, + 'u_mix': Uniform1f +|}; + +const lineUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_ratio': new Uniform1f(context), + 'u_gl_units_to_pixels': new Uniform2fv(context) +}); + +const linePatternUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_ratio': new Uniform1f(context), + 'u_gl_units_to_pixels': new Uniform2fv(context), + 'u_pattern_size_a': new Uniform2fv(context), + 'u_pattern_size_b': new Uniform2fv(context), + 'u_texsize': new Uniform2fv(context), + 'u_image': new Uniform1i(context), + 'u_pattern_tl_a': new Uniform2fv(context), + 'u_pattern_br_a': new Uniform2fv(context), + 'u_pattern_tl_b': new Uniform2fv(context), + 'u_pattern_br_b': new Uniform2fv(context), + 'u_fade': new Uniform1f(context) +}); + +const lineSDFUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_ratio': new Uniform1f(context), + 'u_gl_units_to_pixels': new Uniform2fv(context), + 'u_patternscale_a': new Uniform2fv(context), + 'u_patternscale_b': new Uniform2fv(context), + 'u_sdfgamma': new Uniform1f(context), + 'u_image': new Uniform1i(context), + 'u_tex_y_a': new Uniform1f(context), + 'u_tex_y_b': new Uniform1f(context), + 'u_mix': new Uniform1f(context) +}); + +const lineUniformValues = ( painter: Painter, tile: Tile, layer: LineStyleLayer -): UniformValues { +): UniformValues => { const transform = painter.transform; return { @@ -70,14 +102,14 @@ function lineUniformValues( 1 / transform.pixelsToGLUnits[1] ] }; -} +}; -function linePatternUniformValues( +const linePatternUniformValues = ( painter: Painter, tile: Tile, layer: LineStyleLayer, image: CrossFaded -): UniformValues { +): UniformValues => { const pixelSize = painter.imageManager.getPixelSize(); const tileRatio = calculateTileRatio(tile, painter.transform); @@ -101,14 +133,14 @@ function linePatternUniformValues( 'u_pattern_br_b': imagePosB.br, 'u_fade': image.t }); -} +}; -function lineSDFUniformValues( +const lineSDFUniformValues = ( painter: Painter, tile: Tile, layer: LineStyleLayer, dasharray: CrossFaded> -): UniformValues { +): UniformValues => { const transform = painter.transform; const lineAtlas = painter.lineAtlas; const tileRatio = calculateTileRatio(tile, transform); @@ -130,7 +162,7 @@ function lineSDFUniformValues( 'u_tex_y_b': posB.y, 'u_mix': dasharray.t }); -} +}; function calculateTileRatio(tile: Tile, transform: Transform) { return 1 / pixelsToTileUnits(tile, 1, transform.tileZoom); diff --git a/src/render/program/pattern.js b/src/render/program/pattern.js index aeb6676d0b9..eace7e21841 100644 --- a/src/render/program/pattern.js +++ b/src/render/program/pattern.js @@ -4,7 +4,6 @@ const { Uniform1i, Uniform1f, Uniform2fv, - Uniforms } = require('../uniform_binding'); const assert = require('assert'); const pixelsToTileUnits = require('../../source/pixels_to_tile_units'); @@ -13,30 +12,27 @@ import type Painter from '../painter'; import type {OverscaledTileID} from '../../source/tile_id'; import type {CrossFaded} from '../../style/cross_faded'; import type {UniformValues} from '../uniform_binding'; -import type Context from '../../gl/context'; -function patternUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_image': new Uniform1i(context), - 'u_pattern_tl_a': new Uniform2fv(context), - 'u_pattern_br_a': new Uniform2fv(context), - 'u_pattern_tl_b': new Uniform2fv(context), - 'u_pattern_br_b': new Uniform2fv(context), - 'u_texsize': new Uniform2fv(context), - 'u_mix': new Uniform1f(context), - 'u_pattern_size_a': new Uniform2fv(context), - 'u_pattern_size_b': new Uniform2fv(context), - 'u_scale_a': new Uniform1f(context), - 'u_scale_b': new Uniform1f(context), - 'u_pixel_coord_upper': new Uniform2fv(context), - 'u_pixel_coord_lower': new Uniform2fv(context), - 'u_tile_units_to_pixels': new Uniform1f(context) - }); -} +type PatternUniformsType = {| + 'u_image': Uniform1i, + 'u_pattern_tl_a': Uniform2fv, + 'u_pattern_br_a': Uniform2fv, + 'u_pattern_tl_b': Uniform2fv, + 'u_pattern_br_b': Uniform2fv, + 'u_texsize': Uniform2fv, + 'u_mix': Uniform1f, + 'u_pattern_size_a': Uniform2fv, + 'u_pattern_size_b': Uniform2fv, + 'u_scale_a': Uniform1f, + 'u_scale_b': Uniform1f, + 'u_pixel_coord_upper': Uniform2fv, + 'u_pixel_coord_lower': Uniform2fv, + 'u_tile_units_to_pixels': Uniform1f +|}; function patternUniformValues(image: CrossFaded, painter: Painter, tile: {tileID: OverscaledTileID, tileSize: number} -): UniformValues { +): UniformValues { const imagePosA = painter.imageManager.getPattern(image.from); const imagePosB = painter.imageManager.getPattern(image.to); assert(imagePosA && imagePosB); @@ -67,4 +63,4 @@ function patternUniformValues(image: CrossFaded, painter: Painter, }; } -module.exports = { patternUniforms, patternUniformValues }; +module.exports = { patternUniformValues }; diff --git a/src/render/program/raster_program.js b/src/render/program/raster_program.js index b860963ef4b..2b44f51e0fa 100644 --- a/src/render/program/raster_program.js +++ b/src/render/program/raster_program.js @@ -13,47 +13,59 @@ import type Context from '../../gl/context'; import type {UniformValues} from '../uniform_binding'; import type RasterStyleLayer from '../../style/style_layer/raster_style_layer'; -function rasterUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_matrix': new UniformMatrix4fv(context), - 'u_tl_parent': new Uniform2fv(context), - 'u_scale_parent': new Uniform1f(context), - 'u_buffer_scale': new Uniform1f(context), - 'u_fade_t': new Uniform1f(context), - 'u_opacity': new Uniform1f(context), - 'u_image0': new Uniform1i(context), - 'u_image1': new Uniform1i(context), - 'u_brightness_low': new Uniform1f(context), - 'u_brightness_high': new Uniform1f(context), - 'u_saturation_factor': new Uniform1f(context), - 'u_contrast_factor': new Uniform1f(context), - 'u_spin_weights': new Uniform3fv(context) - }); -} +export type RasterUniformsType = {| + 'u_matrix': UniformMatrix4fv, + 'u_tl_parent': Uniform2fv, + 'u_scale_parent': Uniform1f, + 'u_buffer_scale': Uniform1f, + 'u_fade_t': Uniform1f, + 'u_opacity': Uniform1f, + 'u_image0': Uniform1i, + 'u_image1': Uniform1i, + 'u_brightness_low': Uniform1f, + 'u_brightness_high': Uniform1f, + 'u_saturation_factor': Uniform1f, + 'u_contrast_factor': Uniform1f, + 'u_spin_weights': Uniform3fv +|}; + +const rasterUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_matrix': new UniformMatrix4fv(context), + 'u_tl_parent': new Uniform2fv(context), + 'u_scale_parent': new Uniform1f(context), + 'u_buffer_scale': new Uniform1f(context), + 'u_fade_t': new Uniform1f(context), + 'u_opacity': new Uniform1f(context), + 'u_image0': new Uniform1i(context), + 'u_image1': new Uniform1i(context), + 'u_brightness_low': new Uniform1f(context), + 'u_brightness_high': new Uniform1f(context), + 'u_saturation_factor': new Uniform1f(context), + 'u_contrast_factor': new Uniform1f(context), + 'u_spin_weights': new Uniform3fv(context) +}); -function rasterUniformValues( +const rasterUniformValues = ( matrix: Float32Array, parentTL: Array, parentScaleBy: number, fade: {mix: number, opacity: number}, layer: RasterStyleLayer -): UniformValues { - return { - 'u_matrix': matrix, - 'u_tl_parent': parentTL, - 'u_scale_parent': parentScaleBy, - 'u_buffer_scale': 1, - 'u_fade_t': fade.mix, - 'u_opacity': fade.opacity * layer.paint.get('raster-opacity'), - 'u_image0': 0, - 'u_image1': 1, - 'u_brightness_low': layer.paint.get('raster-brightness-min'), - 'u_brightness_high': layer.paint.get('raster-brightness-max'), - 'u_saturation_factor': saturationFactor(layer.paint.get('raster-saturation')), - 'u_contrast_factor': contrastFactor(layer.paint.get('raster-contrast')), - 'u_spin_weights': spinWeights(layer.paint.get('raster-hue-rotate')) - }; -} +): UniformValues => ({ + 'u_matrix': matrix, + 'u_tl_parent': parentTL, + 'u_scale_parent': parentScaleBy, + 'u_buffer_scale': 1, + 'u_fade_t': fade.mix, + 'u_opacity': fade.opacity * layer.paint.get('raster-opacity'), + 'u_image0': 0, + 'u_image1': 1, + 'u_brightness_low': layer.paint.get('raster-brightness-min'), + 'u_brightness_high': layer.paint.get('raster-brightness-max'), + 'u_saturation_factor': saturationFactor(layer.paint.get('raster-saturation')), + 'u_contrast_factor': contrastFactor(layer.paint.get('raster-contrast')), + 'u_spin_weights': spinWeights(layer.paint.get('raster-hue-rotate')) +}); function spinWeights(angle) { angle *= Math.PI / 180; diff --git a/src/render/program/symbol_program.js b/src/render/program/symbol_program.js index 3be7cd75c83..277c44cdbb1 100644 --- a/src/render/program/symbol_program.js +++ b/src/render/program/symbol_program.js @@ -13,36 +13,88 @@ import type Context from '../../gl/context'; import type Painter from '../painter'; import type {UniformValues} from '../uniform_binding'; -function symbolIconUniforms(context: Context): Uniforms { - return new Uniforms({ - 'u_is_size_zoom_constant': new Uniform1i(context), - 'u_is_size_feature_constant': new Uniform1i(context), - 'u_size_t': new Uniform1f(context), - 'u_size': new Uniform1f(context), - 'u_camera_to_center_distance': new Uniform1f(context), - 'u_pitch': new Uniform1f(context), - 'u_rotate_symbol': new Uniform1i(context), - 'u_aspect_ratio': new Uniform1f(context), - 'u_fade_change': new Uniform1f(context), - 'u_matrix': new UniformMatrix4fv(context), - 'u_label_plane_matrix': new UniformMatrix4fv(context), - 'u_gl_coord_matrix': new UniformMatrix4fv(context), - 'u_is_text': new Uniform1f(context), - 'u_pitch_with_map': new Uniform1i(context), - 'u_texsize': new Uniform2fv(context), - 'u_texture': new Uniform1i(context) - }); -} -function symbolSDFUniforms(context: Context): Uniforms { - return symbolIconUniforms(context) - .concatenate(new Uniforms({ - 'u_gamma_scale': new Uniform1f(context), - 'u_is_halo': new Uniform1f(context) - })); -} +export type SymbolIconUniformsType = {| + 'u_is_size_zoom_constant': Uniform1i, + 'u_is_size_feature_constant': Uniform1i, + 'u_size_t': Uniform1f, + 'u_size': Uniform1f, + 'u_camera_to_center_distance': Uniform1f, + 'u_pitch': Uniform1f, + 'u_rotate_symbol': Uniform1i, + 'u_aspect_ratio': Uniform1f, + 'u_fade_change': Uniform1f, + 'u_matrix': UniformMatrix4fv, + 'u_label_plane_matrix': UniformMatrix4fv, + 'u_gl_coord_matrix': UniformMatrix4fv, + 'u_is_text': Uniform1f, + 'u_pitch_with_map': Uniform1i, + 'u_texsize': Uniform2fv, + 'u_texture': Uniform1i +|}; + +export type SymbolSDFUniformsType = {| + 'u_is_size_zoom_constant': Uniform1i, + 'u_is_size_feature_constant': Uniform1i, + 'u_size_t': Uniform1f, + 'u_size': Uniform1f, + 'u_camera_to_center_distance': Uniform1f, + 'u_pitch': Uniform1f, + 'u_rotate_symbol': Uniform1i, + 'u_aspect_ratio': Uniform1f, + 'u_fade_change': Uniform1f, + 'u_matrix': UniformMatrix4fv, + 'u_label_plane_matrix': UniformMatrix4fv, + 'u_gl_coord_matrix': UniformMatrix4fv, + 'u_is_text': Uniform1f, + 'u_pitch_with_map': Uniform1i, + 'u_texsize': Uniform2fv, + 'u_texture': Uniform1i, + 'u_gamma_scale': Uniform1f, + 'u_is_halo': Uniform1f +|}; + +const symbolIconUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_is_size_zoom_constant': new Uniform1i(context), + 'u_is_size_feature_constant': new Uniform1i(context), + 'u_size_t': new Uniform1f(context), + 'u_size': new Uniform1f(context), + 'u_camera_to_center_distance': new Uniform1f(context), + 'u_pitch': new Uniform1f(context), + 'u_rotate_symbol': new Uniform1i(context), + 'u_aspect_ratio': new Uniform1f(context), + 'u_fade_change': new Uniform1f(context), + 'u_matrix': new UniformMatrix4fv(context), + 'u_label_plane_matrix': new UniformMatrix4fv(context), + 'u_gl_coord_matrix': new UniformMatrix4fv(context), + 'u_is_text': new Uniform1f(context), + 'u_pitch_with_map': new Uniform1i(context), + 'u_texsize': new Uniform2fv(context), + 'u_texture': new Uniform1i(context) +}); + +const symbolSDFUniforms = (context: Context): Uniforms => new Uniforms({ + 'u_is_size_zoom_constant': new Uniform1i(context), + 'u_is_size_feature_constant': new Uniform1i(context), + 'u_size_t': new Uniform1f(context), + 'u_size': new Uniform1f(context), + 'u_camera_to_center_distance': new Uniform1f(context), + 'u_pitch': new Uniform1f(context), + 'u_rotate_symbol': new Uniform1i(context), + 'u_aspect_ratio': new Uniform1f(context), + 'u_fade_change': new Uniform1f(context), + 'u_matrix': new UniformMatrix4fv(context), + 'u_label_plane_matrix': new UniformMatrix4fv(context), + 'u_gl_coord_matrix': new UniformMatrix4fv(context), + 'u_is_text': new Uniform1f(context), + 'u_pitch_with_map': new Uniform1i(context), + 'u_texsize': new Uniform2fv(context), + 'u_texture': new Uniform1i(context), + 'u_gamma_scale': new Uniform1f(context), + 'u_is_halo': new Uniform1f(context) +}); -function symbolIconUniformValues( +const symbolIconUniformValues = ( functionType: string, size: ?{uSizeT: number, uSize: number}, rotateInShader: boolean, @@ -53,7 +105,7 @@ function symbolIconUniformValues( glCoordMatrix: Float32Array, isText: boolean, texSize: Array -): UniformValues { +): UniformValues => { const transform = painter.transform; return { @@ -74,9 +126,9 @@ function symbolIconUniformValues( 'u_texsize': texSize, 'u_texture': 0 }; -} +}; -function symbolSDFUniformValues( +const symbolSDFUniformValues = ( functionType: string, size: ?{uSizeT: number, uSize: number}, rotateInShader: boolean, @@ -88,7 +140,7 @@ function symbolSDFUniformValues( isText: boolean, texSize: Array, isHalo: boolean -): UniformValues { +): UniformValues => { const transform = painter.transform; return util.extend(symbolIconUniformValues(functionType, size, @@ -97,6 +149,6 @@ function symbolSDFUniformValues( 'u_gamma_scale': (pitchWithMap ? Math.cos(transform._pitch) * transform.cameraToCenterDistance : 1), 'u_is_halo': +isHalo }); -} +}; module.exports = { symbolIconUniforms, symbolSDFUniforms, symbolIconUniformValues, symbolSDFUniformValues }; diff --git a/src/render/uniform_binding.js b/src/render/uniform_binding.js index b598d2fa5ae..e1968adcdf1 100644 --- a/src/render/uniform_binding.js +++ b/src/render/uniform_binding.js @@ -1,7 +1,6 @@ // @flow const assert = require('assert'); -const util = require('../util/util'); import type Context from '../gl/context'; @@ -10,8 +9,13 @@ export interface UniformInterface { set(location: WebGLUniformLocation, value: T): void; } -export type UniformValues = {[string]: number | Array | Float32Array}; +export type UniformValue = number | Array | Float32Array; +export type UniformValues + = $Exact<$ObjMap(u: Uniform) => UniformValue>>; export type UniformLocations = {[string]: WebGLUniformLocation}; +export type UniformBindings = {[string]: any}; +// binder uniforms are dynamically created: +export type BinderUniformTypes = any; class Uniform { context: Context; @@ -81,24 +85,19 @@ class UniformMatrix4fv extends Uniform implements UniformInterface } } -class Uniforms { - bindings: Object; +class Uniforms { + bindings: Us; - constructor(bindings: Object) { + constructor(bindings: Us) { this.bindings = bindings; } - set(uniformLocations: UniformLocations, uniformValues: UniformValues) { + set(uniformLocations: UniformLocations, uniformValues: UniformValues) { for (const name in uniformValues) { assert(this.bindings[name], `No binding with name ${name}`); this.bindings[name].set(uniformLocations[name], uniformValues[name]); } } - - concatenate(otherUniforms: Uniforms) { // review: check copying overhead -- maybe not - this.bindings = util.extend(this.bindings, otherUniforms.bindings); - return this; - } } module.exports = { diff --git a/src/render/vertex_array_object.js b/src/render/vertex_array_object.js index 10fcf8bf7de..e24c3d735ab 100644 --- a/src/render/vertex_array_object.js +++ b/src/render/vertex_array_object.js @@ -9,7 +9,7 @@ import type Context from '../gl/context'; class VertexArrayObject { context: Context; - boundProgram: ?Program; + boundProgram: ?Program<*>; boundLayoutVertexBuffer: ?VertexBuffer; boundPaintVertexBuffers: Array; boundIndexBuffer: ?IndexBuffer; @@ -29,7 +29,7 @@ class VertexArrayObject { } bind(context: Context, - program: Program, + program: Program<*>, layoutVertexBuffer: VertexBuffer, paintVertexBuffers: Array, indexBuffer: ?IndexBuffer, @@ -77,7 +77,7 @@ class VertexArrayObject { } } - freshBind(program: Program, + freshBind(program: Program<*>, layoutVertexBuffer: VertexBuffer, paintVertexBuffers: Array, indexBuffer: ?IndexBuffer,