Skip to content

Commit 5fa9698

Browse files
committed
fix #2034, fix tile debug rendering
Switch lineWidth for debug rendering to `1` because the gl spec does not guarantee a width > 1.
1 parent 00ac673 commit 5fa9698

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

js/render/draw_debug.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,53 @@
22

33
var textVertices = require('../lib/debugtext');
44
var browser = require('../util/browser');
5+
var mat4 = require('gl-matrix').mat4;
6+
var EXTENT = require('../data/buffer').EXTENT;
57

68
module.exports = drawDebug;
79

8-
function drawDebug(painter, coords) {
10+
function drawDebug(painter, source, coords) {
911
if (painter.isOpaquePass) return;
1012
if (!painter.options.debug) return;
1113

1214
for (var i = 0; i < coords.length; i++) {
13-
drawDebugTile(painter, coords[i]);
15+
drawDebugTile(painter, source, coords[i]);
1416
}
1517
}
1618

17-
function drawDebugTile(painter, coord) {
19+
function drawDebugTile(painter, source, coord) {
1820
var gl = painter.gl;
1921

22+
gl.lineWidth(1 * browser.devicePixelRatio);
23+
24+
var posMatrix = painter.calculatePosMatrix(coord, source.maxzoom);
2025
var shader = painter.debugShader;
21-
gl.switchShader(shader, painter.calculatePosMatrix(coord));
26+
gl.switchShader(shader, posMatrix);
2227

2328
// draw bounding rectangle
2429
gl.bindBuffer(gl.ARRAY_BUFFER, painter.debugBuffer);
2530
gl.vertexAttribPointer(shader.a_pos, painter.debugBuffer.itemSize, gl.SHORT, false, 0, 0);
2631
gl.uniform4f(shader.u_color, 1, 0, 0, 1);
27-
gl.lineWidth(4);
2832
gl.drawArrays(gl.LINE_STRIP, 0, painter.debugBuffer.itemCount);
2933

3034
var vertices = textVertices(coord.toString(), 50, 200, 5);
31-
3235
gl.bindBuffer(gl.ARRAY_BUFFER, painter.debugTextBuffer);
3336
gl.bufferData(gl.ARRAY_BUFFER, new Int16Array(vertices), gl.STREAM_DRAW);
3437
gl.vertexAttribPointer(shader.a_pos, painter.debugTextBuffer.itemSize, gl.SHORT, false, 0, 0);
35-
gl.lineWidth(8 * browser.devicePixelRatio);
3638
gl.uniform4f(shader.u_color, 1, 1, 1, 1);
37-
gl.drawArrays(gl.LINES, 0, vertices.length / painter.debugTextBuffer.itemSize);
38-
gl.lineWidth(2 * browser.devicePixelRatio);
39+
40+
// Draw the halo with multiple 1px lines instead of one wider line because
41+
// the gl spec doesn't guarantee support for lines with width > 1.
42+
var tileSize = source.getTile(coord).tileSize;
43+
var onePixel = EXTENT / (Math.pow(2, painter.transform.zoom - coord.z) * tileSize);
44+
for (var x = -1; x <= 1; x += 2) {
45+
for (var y = -1; y <= 1; y += 2) {
46+
gl.setPosMatrix(mat4.translate([], posMatrix, [onePixel * x, onePixel * y, 0]));
47+
gl.drawArrays(gl.LINES, 0, vertices.length / painter.debugTextBuffer.itemSize);
48+
}
49+
}
50+
3951
gl.uniform4f(shader.u_color, 0, 0, 0, 1);
52+
gl.setPosMatrix(posMatrix);
4053
gl.drawArrays(gl.LINES, 0, vertices.length / painter.debugTextBuffer.itemSize);
4154
}

js/render/painter.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Painter.prototype.setup = function() {
152152
gl.bufferData(
153153
gl.ARRAY_BUFFER,
154154
new Int16Array([
155-
0, 0, EXTENT - 1, 0, EXTENT - 1, EXTENT - 1, 0, EXTENT - 1, 0, 0]),
155+
0, 0, EXTENT, 0, EXTENT, EXTENT, 0, EXTENT, 0, 0]),
156156
gl.STATIC_DRAW);
157157

158158
// The debugTextBuffer is used to draw tile IDs for debugging
@@ -299,7 +299,9 @@ Painter.prototype.renderPass = function(options) {
299299
this.renderLayer(this, source, layer, coords);
300300
}
301301

302-
draw.debug(this, coords);
302+
if (source) {
303+
draw.debug(this, source, coords);
304+
}
303305
}
304306
};
305307

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"eslint": "^1.5.0",
4040
"eslint-config-mourner": "^1.0.0",
4141
"istanbul": "^0.4.1",
42-
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#3fe57d5b2c885f758cc7667dbcce14a214b790e0",
42+
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#118cf6f20049b95658602c6cf59774f8b8c06704",
4343
"prova": "^2.1.2",
4444
"sinon": "^1.15.4",
4545
"st": "^1.0.0",

test/render.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ suite.run('js', {tests: tests}, function(style, options, callback) {
2828
attributionControl: false
2929
});
3030

31+
if (options.debug) map.debug = true;
32+
if (options.collisionDebug) map.collisionDebug = true;
33+
3134
var gl = map.painter.gl;
3235

3336
map.once('load', function() {

0 commit comments

Comments
 (0)