Skip to content

Commit

Permalink
more rebasing, get tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Oct 25, 2016
1 parent a446d6f commit 06ba18d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
45 changes: 45 additions & 0 deletions js/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,51 @@ const lineInterfaces = {
},
multiplier: 255,
paintProperty: 'line-color'
}, {
name: 'a_blur',
components: 1,
type: 'Uint8',
getValue: function(layer, globalProperties, featureProperties) {
return [layer.getPaintValue("line-blur", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'line-blur'
}, {
name: 'a_opacity',
components: 1,
type: 'Uint8',
getValue: function(layer, globalProperties, featureProperties) {
return [layer.getPaintValue("line-opacity", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'line-opacity'
}, {
name: 'a_width',
components: 1,
type: 'Uint8',
getValue: function(layer, globalProperties, featureProperties) {
return [layer.getPaintValue("line-width", globalProperties, featureProperties) / 2];
},
multiplier: 10,
paintProperty: 'line-width'
}, {
name: 'a_gapwidth',
components: 1,
type: 'Uint8',
getValue: function(layer, globalProperties, featureProperties) {
return [layer.getPaintValue("line-gap-width", globalProperties, featureProperties) / 2];
},
multiplier: 10,
paintProperty: 'line-gap-width'
}, {
name: 'a_offset',
components: 1,
type: 'Uint8',
getValue: function(layer, globalProperties, featureProperties) {
return [-1 * layer.getPaintValue("line-offset", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'line-offset'
}],
elementArrayType: new ElementArrayType()
}
Expand Down
7 changes: 4 additions & 3 deletions js/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const VertexArrayType = require('./vertex_array_type');
const util = require('../util/util');
const shaders = require('mapbox-gl-shaders');
const assert = require('assert');
const browser = require('../util/browser');

/**
* ProgramConfiguration contains the logic for binding style layer properties and tile
Expand Down Expand Up @@ -167,21 +168,21 @@ class ProgramConfiguration {

defines = this.defines.concat(defines);

let definesSource = '#define MAPBOX_GL_JS;\n';
let definesSource = `#define MAPBOX_GL_JS\n#define DEVICE_PIXEL_RATIO ${browser.devicePixelRatio.toFixed(1)}\n`;
for (let j = 0; j < defines.length; j++) {
definesSource += `#define ${defines[j]};\n`;
}

const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, applyPragmas(definesSource + definition.fragmentSource, this.fragmentPragmas));
gl.compileShader(fragmentShader);
assert(gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS), gl.getShaderInfoLog(fragmentShader));
assert(gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS), `${name}.fragment.glsl error:\n${gl.getShaderInfoLog(fragmentShader)}`);
gl.attachShader(program, fragmentShader);

const vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, applyPragmas(definesSource + shaders.util + definition.vertexSource, this.vertexPragmas));
gl.compileShader(vertexShader);
assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), gl.getShaderInfoLog(vertexShader));
assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), `${name}.vertex.glsl error:\n${gl.getShaderInfoLog(vertexShader)}`);
gl.attachShader(program, vertexShader);

gl.linkProgram(program);
Expand Down
13 changes: 0 additions & 13 deletions js/render/draw_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ function drawLineTile(painter, sourceCache, layer, coord) {
const program = painter.useProgram(dasharray ? 'lineSDF' : image ? 'linePattern' : 'line', programConfiguration);
programConfiguration.setUniforms(gl, program, layer, {zoom: painter.transform.zoom});

if (!image) {
gl.uniform4fv(program.u_color, layer.paint['line-color']);
}

let posA, posB, imagePosA, imagePosB;
if (dasharray) {
Expand Down Expand Up @@ -77,17 +74,7 @@ function drawLineTile(painter, sourceCache, layer, coord) {
gl.uniform1f(program.u_fade, image.t);
}

// the distance over which the line edge fades out.
// Retina devices need a smaller distance to avoid aliasing.
const antialiasing = 1 / browser.devicePixelRatio;

gl.uniform1f(program.u_linewidth, layer.paint['line-width'] / 2);
gl.uniform1f(program.u_gapwidth, layer.paint['line-gap-width'] / 2);
gl.uniform1f(program.u_antialiasing, antialiasing / 2);
gl.uniform1f(program.u_blur, layer.paint['line-blur'] + antialiasing);
gl.uniform1f(program.u_opacity, layer.paint['line-opacity']);
gl.uniformMatrix2fv(program.u_antialiasingmatrix, false, painter.transform.lineAntialiasingMatrix);
gl.uniform1f(program.u_offset, -layer.paint['line-offset']);
gl.uniform1f(program.u_extra, painter.transform.lineStretch);

painter.enableTileClippingMask(coord);
Expand Down
13 changes: 8 additions & 5 deletions js/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ Object.defineProperty(exports, 'devicePixelRatio', {

exports.supportsWebp = false;

const webpImgTest = window.document.createElement('img');
webpImgTest.onload = function() {
exports.supportsWebp = true;
};
webpImgTest.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
if (window.document) {
const webpImgTest = window.document.createElement('img');
webpImgTest.onload = function() {
exports.supportsWebp = true;
};
webpImgTest.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
}


exports.supportsGeolocation = !!window.navigator.geolocation;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"highlight.js": "9.3.0",
"jsdom": "^9.4.2",
"lodash.template": "^4.4.0",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#28c76c64e8cfcee8764c6c0f6d4fcc2d15a8d1e1",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#eb8b38a0df52361b5d4edeb8a31345d679b86718",
"minifyify": "^7.0.1",
"npm-run-all": "^3.0.0",
"nyc": "^8.3.0",
Expand Down

0 comments on commit 06ba18d

Please sign in to comment.