-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] Circles support #1241
Closed
Closed
[wip] Circles support #1241
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
263d57c
Stub circles support
scothis 65bf3e7
Merge branch 'master' into v8-circles
tmcw 77acaed
Add circle shaders
tmcw 1a8e6c1
Add two triangles in the vertex buffer for each circle
tmcw 5d68936
First steps toward drawing circles
tmcw 21940e7
Add circlevertexbuffer and bind more data
tmcw f33f46a
Bind element and vertex buffer
tmcw 66b70bc
Increment vertex and element counters
tmcw 39b68fb
Tweak shaders: still whitescreen
tmcw f1fdc08
Try pointing to a_extrude. #whitescreen
tmcw 6b9edfb
BLACK BROKEN TRIANGLE OF SUCCESS
tmcw 2182d9e
Circle: needs placement
tmcw 7298a89
Induce loud failure
tmcw cad4153
Prettier geometry access
tmcw 24d7e0c
Fix offset value
tmcw 6c44402
Getting closer: v_centerpoint is not being transferred
tmcw 2692288
Implement circle blurring, hitting style spec in a second.
tmcw 8a4670d
Pack more data into buffers, use axis-aligned boxes
tmcw 81a9ef5
Iterate through geometries
tmcw b2b74f0
fix circle size
ansis d333d4c
Simplify derivation of v_extrude
tmcw 498ac8e
Implement faux-antialiasing with blur
tmcw 6d9ddef
Simplify blur calculation
tmcw 8988dbc
Fix tile-edge clipping
tmcw 955b5c6
Add updated debug page
tmcw 1e202c2
Compensate for screen resolution differences when calculating min blur
tmcw 947496e
Revert debugs to master versions
tmcw 902427c
Update test to nan branch to get 0.12 compatibility
tmcw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,7 @@ | ||
{ | ||
"version": 8, | ||
"name": "rivers", | ||
"constants": { }, | ||
"sources": { }, | ||
"layers": [ ] | ||
} |
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,36 @@ | ||
'use strict'; | ||
|
||
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; | ||
|
||
gl.switchShader(painter.circleShader, tile.posMatrix, tile.exMatrix); | ||
|
||
// gl.uniform1f(shader.u_opacity, layer.paint['icon-opacity']); | ||
var vertex = tile.buffers.circleVertex; | ||
var shader = painter.circleShader; | ||
var elements = tile.buffers.circleElement; | ||
|
||
gl.uniform4fv(shader.u_color, layer.paint['circle-color']); | ||
gl.uniform1f(shader.u_blur, layer.paint['circle-blur']); | ||
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); | ||
} | ||
} |
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
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 / 2.0), 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,24 @@ | ||
// 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.x, 2.0) * 2.0 - 1.0, | ||
mod(a_pos.y, 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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most glsl operations can work with vectors, so this can be written as
v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);