From 06ba18decde18b75976966defd9f599cdd281853 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Mon, 24 Oct 2016 18:52:59 -0700 Subject: [PATCH] more rebasing, get tests to pass --- js/data/bucket/line_bucket.js | 45 ++++++++++++++++++++++++++++++++ js/data/program_configuration.js | 7 ++--- js/render/draw_line.js | 13 --------- js/util/browser.js | 13 +++++---- package.json | 2 +- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/js/data/bucket/line_bucket.js b/js/data/bucket/line_bucket.js index e8204ddc221..634617393f4 100644 --- a/js/data/bucket/line_bucket.js +++ b/js/data/bucket/line_bucket.js @@ -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() } diff --git a/js/data/program_configuration.js b/js/data/program_configuration.js index e6fa3d39423..747879a921f 100644 --- a/js/data/program_configuration.js +++ b/js/data/program_configuration.js @@ -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 @@ -167,7 +168,7 @@ 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`; } @@ -175,13 +176,13 @@ class ProgramConfiguration { 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); diff --git a/js/render/draw_line.js b/js/render/draw_line.js index cc64d202d2b..d6b5156b9bb 100644 --- a/js/render/draw_line.js +++ b/js/render/draw_line.js @@ -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) { @@ -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); diff --git a/js/util/browser.js b/js/util/browser.js index 7a621a36422..fc5782a8013 100755 --- a/js/util/browser.js +++ b/js/util/browser.js @@ -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; diff --git a/package.json b/package.json index 2c057c281db..6f7763b6307 100644 --- a/package.json +++ b/package.json @@ -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",