-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a manual redo of #1241 on top of the v8 branch.
- Loading branch information
Showing
12 changed files
with
2,401 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var util = require('../../util/util'); | ||
var Buffer = require('./buffer'); | ||
|
||
module.exports = CircleVertexBuffer; | ||
|
||
/** | ||
* This contains the data that displays circle markers on the map, | ||
* including their centerpoint | ||
*/ | ||
function CircleVertexBuffer(buffer) { | ||
Buffer.call(this, buffer); | ||
} | ||
|
||
CircleVertexBuffer.prototype = util.inherit(Buffer, { | ||
defaultLength: 2048 * 16, | ||
|
||
itemSize: 4, // 2 bytes per short * 4 of them | ||
|
||
add: function(x, y, extrudeX, extrudeY) { | ||
var pos = this.pos, | ||
pos2 = pos / 2; | ||
|
||
this.resize(); | ||
|
||
// pack the extrusion of -1 or 1 into one short | ||
this.shorts[pos2 + 0] = (x * 2) + ((extrudeX + 1) / 2); | ||
this.shorts[pos2 + 1] = (y * 2) + ((extrudeY + 1) / 2); | ||
|
||
this.pos += this.itemSize; | ||
}, | ||
|
||
bind: function(gl, shader, offset) { | ||
Buffer.prototype.bind.call(this, gl); | ||
|
||
gl.vertexAttribPointer(shader.a_pos, 2, | ||
gl.SHORT, false, | ||
this.itemSize, offset + 0); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
var ElementGroups = require('./element_groups'); | ||
|
||
module.exports = CircleBucket; | ||
|
||
/** | ||
* A container for all circle data | ||
* | ||
* Circles are represented by two triangles. | ||
* | ||
* Each corner has a pos that is the center of the circle and an extrusion | ||
* vector that is where it points. | ||
*/ | ||
function CircleBucket(buffers) { | ||
this.buffers = buffers; | ||
this.elementGroups = new ElementGroups( | ||
buffers.circleVertex, | ||
buffers.circleElement); | ||
} | ||
|
||
CircleBucket.prototype.addFeatures = function() { | ||
for (var i = 0; i < this.features.length; i++) { | ||
var geometries = this.features[i].loadGeometry()[0]; | ||
for (var j = 0; j < geometries.length; j++) { | ||
this.elementGroups.makeRoomFor(6); | ||
var x = geometries[j].x, | ||
y = geometries[j].y; | ||
|
||
var idx = this.buffers.circleVertex.index - | ||
this.elementGroups.current.vertexStartIndex; | ||
|
||
// this geometry will be of the Point type, and we'll derive | ||
// two triangles from it. | ||
// | ||
// ┌─────────┐ | ||
// │ 4 3 │ | ||
// │ │ | ||
// │ 1 2 │ | ||
// └─────────┘ | ||
// | ||
this.buffers.circleVertex.add(x, y, -1, -1); // 1 | ||
this.buffers.circleVertex.add(x, y, 1, -1); // 2 | ||
this.buffers.circleVertex.add(x, y, 1, 1); // 3 | ||
this.buffers.circleVertex.add(x, y, -1, 1); // 4 | ||
|
||
// 1, 2, 3 | ||
// 1, 4, 3 | ||
this.elementGroups.elementBuffer.add(idx, idx + 1, idx + 2); | ||
this.elementGroups.elementBuffer.add(idx, idx + 3, idx + 2); | ||
|
||
this.elementGroups.current.vertexLength += 4; | ||
this.elementGroups.current.elementLength += 2; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
var browser = require('../util/browser.js'); | ||
|
||
module.exports = drawCircles; | ||
|
||
function drawCircles(painter, layer, posMatrix, tile) { | ||
// short-circuit if tile is empty | ||
if (!tile.buffers) return; | ||
|
||
var elementGroups = tile.elementGroups[layer.ref || layer.id]; | ||
if (!elementGroups) return; | ||
|
||
var gl = painter.gl; | ||
|
||
// Allow circles to be drawn across boundaries, so that | ||
// large circles are not clipped to tiles | ||
gl.disable(gl.STENCIL_TEST); | ||
|
||
gl.switchShader(painter.circleShader, tile.posMatrix, tile.exMatrix); | ||
|
||
var vertex = tile.buffers.circleVertex; | ||
var shader = painter.circleShader; | ||
var elements = tile.buffers.circleElement; | ||
|
||
// antialiasing factor: this is a minimum blur distance that serves as | ||
// a faux-antialiasing for the circle. since blur is a ratio of the circle's | ||
// size and the intent is to keep the blur at roughly 1px, the two | ||
// are inversely related. | ||
var antialias = 1 / browser.devicePixelRatio / layer.paint['circle-radius']; | ||
|
||
gl.uniform4fv(shader.u_color, layer.paint['circle-color']); | ||
gl.uniform1f(shader.u_blur, Math.max(layer.paint['circle-blur'], antialias)); | ||
gl.uniform1f(shader.u_size, layer.paint['circle-radius']); | ||
|
||
for (var k = 0; k < elementGroups.groups.length; k++) { | ||
var group = elementGroups.groups[k]; | ||
var offset = group.vertexStartIndex * vertex.itemSize; | ||
|
||
vertex.bind(gl, shader, offset); | ||
elements.bind(gl, shader, offset); | ||
|
||
var count = group.elementLength * 3; | ||
var elementOffset = group.elementStartIndex * elements.itemSize; | ||
gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_SHORT, elementOffset); | ||
} | ||
|
||
gl.enable(gl.STENCIL_TEST); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
uniform vec4 u_color; | ||
uniform float u_blur; | ||
uniform float u_size; | ||
|
||
varying vec2 v_extrude; | ||
|
||
void main() { | ||
float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude)); | ||
gl_FragColor = u_color * (1.0 - t); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// set by gl_util | ||
uniform float u_size; | ||
|
||
attribute vec2 a_pos; | ||
|
||
uniform mat4 u_matrix; | ||
uniform mat4 u_exmatrix; | ||
|
||
varying vec2 v_extrude; | ||
|
||
void main(void) { | ||
// unencode the extrusion vector that we snuck into the a_pos vector | ||
v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); | ||
|
||
vec4 extrude = u_exmatrix * vec4(v_extrude * u_size, 0, 0); | ||
// multiply a_pos by 0.5, since we had it * 2 in order to sneak | ||
// in extrusion data | ||
gl_Position = u_matrix * vec4(a_pos * 0.5, 0, 1); | ||
|
||
// gl_Position is divided by gl_Position.w after this shader runs. | ||
// Multiply the extrude by it so that it isn't affected by it. | ||
gl_Position += extrude * gl_Position.w; | ||
} |