Skip to content

Commit

Permalink
Use uniform bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Sep 24, 2018
1 parent bbb9384 commit 096d885
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/render/draw_fill_extrusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ function drawExtrusionTiles(painter, source, layer, coords, depthMode, stencilMo
const programConfiguration = bucket.programConfigurations.get(layer.id);
const program = painter.useProgram(image ? 'fillExtrusionPattern' : 'fillExtrusion', programConfiguration);

gl.uniform1f(program.uniforms.u_vertical_gradient, +layer.paint.get('fill-extrusion-vertical-gradient'));

if (image) {
painter.context.activeTexture.set(gl.TEXTURE0);
tile.imageAtlasTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
Expand All @@ -74,7 +72,7 @@ function drawExtrusionTiles(painter, source, layer, coords, depthMode, stencilMo

const uniformValues = image ?
fillExtrusionPatternUniformValues(matrix, painter, coord, crossfade, tile) :
fillExtrusionUniformValues(matrix, painter);
fillExtrusionUniformValues(matrix, painter, +layer.paint.get('fill-extrusion-vertical-gradient'));


program.draw(context, context.gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.backCCW,
Expand Down
14 changes: 10 additions & 4 deletions src/render/program/fill_extrusion_program.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export type FillExtrusionUniformsType = {|
'u_matrix': UniformMatrix4f,
'u_lightpos': Uniform3f,
'u_lightintensity': Uniform1f,
'u_lightcolor': Uniform3f
'u_lightcolor': Uniform3f,
'u_vertical_gradient': Uniform1f
|};

export type FillExtrusionPatternUniformsType = {|
Expand All @@ -33,6 +34,7 @@ export type FillExtrusionPatternUniformsType = {|
'u_lightintensity': Uniform1f,
'u_lightcolor': Uniform3f,
'u_height_factor': Uniform1f,
'u_vertical_gradient': Uniform1f,
// pattern uniforms:
'u_texsize': Uniform2f,
'u_image': Uniform1i,
Expand All @@ -53,14 +55,16 @@ const fillExtrusionUniforms = (context: Context, locations: UniformLocations): F
'u_matrix': new UniformMatrix4f(context, locations.u_matrix),
'u_lightpos': new Uniform3f(context, locations.u_lightpos),
'u_lightintensity': new Uniform1f(context, locations.u_lightintensity),
'u_lightcolor': new Uniform3f(context, locations.u_lightcolor)
'u_lightcolor': new Uniform3f(context, locations.u_lightcolor),
'u_vertical_gradient': new Uniform1f(context, locations.u_vertical_gradient)
});

const fillExtrusionPatternUniforms = (context: Context, locations: UniformLocations): FillExtrusionPatternUniformsType => ({
'u_matrix': new UniformMatrix4f(context, locations.u_matrix),
'u_lightpos': new Uniform3f(context, locations.u_lightpos),
'u_lightintensity': new Uniform1f(context, locations.u_lightintensity),
'u_lightcolor': new Uniform3f(context, locations.u_lightcolor),
'u_vertical_gradient': new Uniform1f(context, locations.u_vertical_gradient),
'u_height_factor': new Uniform1f(context, locations.u_height_factor),
// pattern uniforms
'u_image': new Uniform1i(context, locations.u_image),
Expand All @@ -80,7 +84,8 @@ const extrusionTextureUniforms = (context: Context, locations: UniformLocations)

const fillExtrusionUniformValues = (
matrix: Float32Array,
painter: Painter
painter: Painter,
verticalGradient: boolean,
): UniformValues<FillExtrusionUniformsType> => {
const light = painter.style.light;
const _lp = light.properties.get('position');
Expand All @@ -97,7 +102,8 @@ const fillExtrusionUniformValues = (
'u_matrix': matrix,
'u_lightpos': lightPos,
'u_lightintensity': light.properties.get('intensity'),
'u_lightcolor': [lightColor.r, lightColor.g, lightColor.b]
'u_lightcolor': [lightColor.r, lightColor.g, lightColor.b],
'u_vertical_gradient': verticalGradient
};
};

Expand Down
3 changes: 2 additions & 1 deletion src/style-spec/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ export type FillExtrusionLayerSpecification = {|
"fill-extrusion-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">,
"fill-extrusion-pattern"?: DataDrivenPropertyValueSpecification<string>,
"fill-extrusion-height"?: DataDrivenPropertyValueSpecification<number>,
"fill-extrusion-base"?: DataDrivenPropertyValueSpecification<number>
"fill-extrusion-base"?: DataDrivenPropertyValueSpecification<number>,
"fill-extrusion-vertical-gradient"?: PropertyValueSpecification<boolean>
|}
|}

Expand Down

0 comments on commit 096d885

Please sign in to comment.