From ba7f7ca3b87319fae0dc1e2b4a0d1350907bcbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 29 Oct 2013 21:55:48 +0100 Subject: [PATCH 001/259] move shaders to JS + separate files fixes #168 --- area.fragment.glsl | 8 ++++++ area.vertex.glsl | 12 ++++++++ composite.fragment.glsl | 10 +++++++ composite.vertex.glsl | 9 ++++++ debug.fragment.glsl | 7 +++++ debug.vertex.glsl | 11 +++++++ label.fragment.glsl | 10 +++++++ label.vertex.glsl | 17 +++++++++++ line.fragment.glsl | 35 +++++++++++++++++++++++ line.vertex.glsl | 63 +++++++++++++++++++++++++++++++++++++++++ point.fragment.glsl | 20 +++++++++++++ point.vertex.glsl | 25 ++++++++++++++++ raster.fragment.glsl | 42 +++++++++++++++++++++++++++ raster.vertex.glsl | 12 ++++++++ sdf.fragment.glsl | 15 ++++++++++ sdf.vertex.glsl | 34 ++++++++++++++++++++++ 16 files changed, 330 insertions(+) create mode 100644 area.fragment.glsl create mode 100644 area.vertex.glsl create mode 100644 composite.fragment.glsl create mode 100644 composite.vertex.glsl create mode 100644 debug.fragment.glsl create mode 100644 debug.vertex.glsl create mode 100644 label.fragment.glsl create mode 100644 label.vertex.glsl create mode 100644 line.fragment.glsl create mode 100644 line.vertex.glsl create mode 100644 point.fragment.glsl create mode 100644 point.vertex.glsl create mode 100644 raster.fragment.glsl create mode 100644 raster.vertex.glsl create mode 100644 sdf.fragment.glsl create mode 100644 sdf.vertex.glsl diff --git a/area.fragment.glsl b/area.fragment.glsl new file mode 100644 index 00000000000..3a86241cc93 --- /dev/null +++ b/area.fragment.glsl @@ -0,0 +1,8 @@ +precision mediump float; + +uniform vec4 u_color; + +void main() { + gl_FragColor = u_color; + +} diff --git a/area.vertex.glsl b/area.vertex.glsl new file mode 100644 index 00000000000..de67896cea1 --- /dev/null +++ b/area.vertex.glsl @@ -0,0 +1,12 @@ +// these are the shaders for rendering filled areas + +precision mediump float; + +attribute vec2 a_pos; + +uniform mat4 u_posmatrix; + +void main() { + gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0, 1); + gl_PointSize = 2.0; +} diff --git a/composite.fragment.glsl b/composite.fragment.glsl new file mode 100644 index 00000000000..d29cb978333 --- /dev/null +++ b/composite.fragment.glsl @@ -0,0 +1,10 @@ +precision mediump float; + +uniform sampler2D u_image; +uniform float u_opacity; + +varying vec2 v_pos; + +void main() { + gl_FragColor = texture2D(u_image, v_pos / 2.0 + 0.5) * u_opacity; +} diff --git a/composite.vertex.glsl b/composite.vertex.glsl new file mode 100644 index 00000000000..9ba6173f02d --- /dev/null +++ b/composite.vertex.glsl @@ -0,0 +1,9 @@ +attribute vec2 a_pos; + +uniform mat4 u_posmatrix; +varying vec2 v_pos; + +void main() { + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + v_pos = gl_Position.xy; +} diff --git a/debug.fragment.glsl b/debug.fragment.glsl new file mode 100644 index 00000000000..f21d7dd6ebb --- /dev/null +++ b/debug.fragment.glsl @@ -0,0 +1,7 @@ +precision mediump float; + +uniform vec4 u_color; + +void main() { + gl_FragColor = u_color; +} diff --git a/debug.vertex.glsl b/debug.vertex.glsl new file mode 100644 index 00000000000..e1440923333 --- /dev/null +++ b/debug.vertex.glsl @@ -0,0 +1,11 @@ +precision mediump float; + +attribute vec2 a_pos; + +uniform float u_pointsize; +uniform mat4 u_posmatrix; + +void main() { + gl_Position = u_posmatrix * vec4(a_pos, step(32767.0, a_pos.x), 1); + gl_PointSize = u_pointsize; +} diff --git a/label.fragment.glsl b/label.fragment.glsl new file mode 100644 index 00000000000..ceefcf207dc --- /dev/null +++ b/label.fragment.glsl @@ -0,0 +1,10 @@ +precision mediump float; + +uniform sampler2D u_sampler; +uniform vec4 u_color; +varying vec2 v_tex; + +void main() { + vec4 c = texture2D(u_sampler, v_tex); + gl_FragColor = vec4(u_color.r, u_color.g, u_color.b, u_color.a * c.a); +} diff --git a/label.vertex.glsl b/label.vertex.glsl new file mode 100644 index 00000000000..7beda4de3a6 --- /dev/null +++ b/label.vertex.glsl @@ -0,0 +1,17 @@ +precision mediump float; + +attribute vec2 a_pos; +attribute vec2 a_offset; +attribute vec2 a_tex; + +uniform vec2 u_texsize; +uniform mat4 u_posmatrix; +uniform mat4 u_resizematrix; + +varying vec2 v_tex; + +void main() { + vec2 a = a_offset; + gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_resizematrix * vec4(a_offset, 0, 1); + v_tex = a_tex / u_texsize; +} diff --git a/line.fragment.glsl b/line.fragment.glsl new file mode 100644 index 00000000000..c89eecac201 --- /dev/null +++ b/line.fragment.glsl @@ -0,0 +1,35 @@ +precision mediump float; + +// shared +uniform float u_debug; +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_point; + +uniform vec2 u_dasharray; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // Calculate the distance of the pixel from the line in pixels. + float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); + + dist *= u_linewidth.s; + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist), 0.0, 1.0); + + // Calculate the antialiasing fade factor based on distance to the dash. + // Only affects alpha when line is dashed + float pos = mod(v_linesofar, u_dasharray.x + u_dasharray.y); + alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0)); + + gl_FragColor = u_color * alpha; + + if (u_debug > 0.0) { + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); + } +} diff --git a/line.vertex.glsl b/line.vertex.glsl new file mode 100644 index 00000000000..bd76db8bdd5 --- /dev/null +++ b/line.vertex.glsl @@ -0,0 +1,63 @@ +// these are the shaders for rendering antialiased lines +precision mediump float; + +// floor(127 / 2) == 63.0 +// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is +// stored in a byte (-128..127). we scale regular normals up to length 63, but +// there are also "special" normals that have a bigger length (of up to 126 in +// this case). +#define scale 63.0 + +attribute vec2 a_pos; +attribute vec2 a_extrude; +attribute float a_linesofar; + +// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_posmatrix; +uniform mat4 u_exmatrix; + + +uniform float u_debug; + +// shared +uniform float u_ratio; +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_point; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // We store the texture normals in the most insignificant bit + // transform y so that 0 => -1 and 1 => 1 + // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap + // y is 1 if the normal points up, and -1 if it points down + vec2 normal = mod(a_pos, 2.0); + normal.y = sign(normal.y - 0.5); + v_normal = normal; + + // Scale the extrusion vector down to a normal and then up by the line width + // of this vertex. + vec2 extrude = a_extrude / scale; + vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); + + // If the x coordinate is the maximum integer, we move the z coordinates out + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + float z = step(32767.0, a_pos.x); + + // When drawing points, skip every other vertex + z += u_point * step(1.0, v_normal.y); + + // Remove the texture normal bit of the position before scaling it with the + // model/view matrix. Add the extrusion vector *after* the model/view matrix + // because we're extruding the line in pixel space, regardless of the current + // tile's zoom level. + gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + v_linesofar = a_linesofar * u_ratio; + + + gl_PointSize = 2.0 * u_linewidth.s - 1.0; +} diff --git a/point.fragment.glsl b/point.fragment.glsl new file mode 100644 index 00000000000..c48e121c507 --- /dev/null +++ b/point.fragment.glsl @@ -0,0 +1,20 @@ +#define root2 1.42 +precision mediump float; + +uniform sampler2D u_image; +uniform vec2 u_tl; +uniform vec2 u_br; + +varying mat2 v_rotationmatrix; + +void main(void) { + + vec2 pos = v_rotationmatrix * (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5; + + float inbounds = step(0.0, pos.x) * step(0.0, pos.y) * + (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y)); + + gl_FragColor = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds; + + gl_FragColor.rgb *= gl_FragColor.a; +} diff --git a/point.vertex.glsl b/point.vertex.glsl new file mode 100644 index 00000000000..fefb40bcc1f --- /dev/null +++ b/point.vertex.glsl @@ -0,0 +1,25 @@ +precision mediump float; + +#define scale 63.0 +#define root2 1.42 + +uniform mat4 u_posmatrix; +uniform vec2 u_size; +uniform mat2 u_rotationmatrix; + +attribute vec2 a_pos; +attribute vec2 a_slope; +varying mat2 v_rotationmatrix; + +void main(void) { + + gl_Position = u_posmatrix * vec4(floor(a_pos/2.0), 0, 1); + gl_PointSize = u_size.x * root2; + + float angle = atan(a_slope.y, a_slope.x); + + v_rotationmatrix = mat2( + cos(angle), -sin(angle), + sin(angle), cos(angle) + ) * u_rotationmatrix; +} diff --git a/raster.fragment.glsl b/raster.fragment.glsl new file mode 100644 index 00000000000..5f5c8e9a8f1 --- /dev/null +++ b/raster.fragment.glsl @@ -0,0 +1,42 @@ +precision mediump float; + +uniform float u_brightness_low; +uniform float u_brightness_high; +uniform float u_spin; +uniform float u_saturation; +uniform sampler2D u_image; +varying vec2 v_pos; + +vec3 u_high_vec; +vec3 u_low_vec; + +vec3 greyscale; +vec3 original; +vec3 saturated; + +float len; + +void main() { + + u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); + u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); + + // http://www.laurenscorijn.com/articles/colormath-basics + original = texture2D(u_image, v_pos).xyz; + len = length(original) / 2.0; + + greyscale = vec3(len, len, len); + + saturated = (u_saturation * original) + ((1.0 - u_saturation) * greyscale); + + gl_FragColor = vec4( + mix( + u_high_vec, + u_low_vec, + // texture2D(u_image, v_pos).xyz + saturated + ) * mat3( + 1, 0, 0, + 0, cos(u_spin), -sin(u_spin), + 0, sin(u_spin), cos(u_spin)), 1.0); +} diff --git a/raster.vertex.glsl b/raster.vertex.glsl new file mode 100644 index 00000000000..08fa4185891 --- /dev/null +++ b/raster.vertex.glsl @@ -0,0 +1,12 @@ +precision mediump float; +uniform mat4 u_posmatrix; +uniform float u_brightness_low; +uniform float u_brightness_high; +uniform float u_spin; +attribute vec2 a_pos; +varying vec2 v_pos; + +void main(void) { + gl_Position = u_posmatrix * vec4(a_pos, step(32767.0, a_pos.x), 1); + v_pos = a_pos / 4096.0; +} diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl new file mode 100644 index 00000000000..d4367323bec --- /dev/null +++ b/sdf.fragment.glsl @@ -0,0 +1,15 @@ +precision mediump float; + +uniform sampler2D u_texture; +uniform vec4 u_color; +uniform float u_buffer; +uniform float u_gamma; + +varying vec2 v_tex; + +void main() { + float dist = texture2D(u_texture, v_tex).a; + float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist); + gl_FragColor = u_color * alpha; + // gl_FragColor = vec4(0, 0, 0, 1); +} diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl new file mode 100644 index 00000000000..b3d41bb882e --- /dev/null +++ b/sdf.vertex.glsl @@ -0,0 +1,34 @@ +precision mediump float; + +attribute vec2 a_pos; +attribute vec2 a_offset; +attribute vec2 a_tex; +attribute float a_angle; +attribute float a_minzoom; + + +// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_posmatrix; +uniform mat4 u_exmatrix; +uniform float u_angle; +uniform float u_zoom; + +uniform vec2 u_texsize; + +varying vec2 v_tex; + +void main() { + + float rev = 1.0; + // We're using an int16 range for the angles. + if (abs(a_angle + u_angle) > 32767.0) rev = -1.0; + + // If the label should be invisible, we move the vertex outside + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + float z = 1.0 - step(a_minzoom, u_zoom); + + gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + rev * u_exmatrix * vec4(a_offset / 64.0, z, 0); + v_tex = a_tex * 4.0 / u_texsize; +} From 7284782c4e82e1623fd70fcf9645138998eb261d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 30 Oct 2013 16:02:49 +0100 Subject: [PATCH 002/259] take devicePixelRatio into account when drawing lines fixes #150 --- line.fragment.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index c89eecac201..079818f3d81 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -5,6 +5,7 @@ uniform float u_debug; uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_point; +uniform float u_gamma; uniform vec2 u_dasharray; @@ -20,7 +21,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist), 0.0, 1.0); + float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist) * u_gamma, 0.0, 1.0); // Calculate the antialiasing fade factor based on distance to the dash. // Only affects alpha when line is dashed From 16795dfcc55316a94348852130ead0bb77dc743d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 5 Nov 2013 11:54:21 -0500 Subject: [PATCH 003/259] add rotation range attribute to sdf shader --- sdf.vertex.glsl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index b3d41bb882e..92ef9b2400b 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -5,6 +5,8 @@ attribute vec2 a_offset; attribute vec2 a_tex; attribute float a_angle; attribute float a_minzoom; +attribute float a_rangeend; +attribute float a_rangestart; // posmatrix is for the vertex position, exmatrix is for rotating and projecting @@ -29,6 +31,9 @@ void main() { // for us to create degenerate triangle strips. float z = 1.0 - step(a_minzoom, u_zoom); + float angle = mod(u_angle + 65536.0, 65536.0); + z += step(a_rangeend, angle) * step(angle, a_rangestart); + gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + rev * u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex * 4.0 / u_texsize; } From 8d835581680e700e6b03a171acd6f8296bb184d6 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 5 Nov 2013 13:59:02 -0500 Subject: [PATCH 004/259] don't rotate horizontal labels, avoid collisions - fixes bugs in rotation collision calculation - integrates it into label placement --- sdf.fragment.glsl | 1 - 1 file changed, 1 deletion(-) diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index d4367323bec..ce1324dd3a2 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -11,5 +11,4 @@ void main() { float dist = texture2D(u_texture, v_tex).a; float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist); gl_FragColor = u_color * alpha; - // gl_FragColor = vec4(0, 0, 0, 1); } From c53023502fd853f8776812773ef683e499ddde62 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 6 Nov 2013 11:36:50 -0500 Subject: [PATCH 005/259] don't flip horizontal labels when rotating --- sdf.vertex.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 92ef9b2400b..3384a289ecd 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -15,6 +15,7 @@ uniform mat4 u_posmatrix; uniform mat4 u_exmatrix; uniform float u_angle; uniform float u_zoom; +uniform float u_flip; uniform vec2 u_texsize; @@ -24,7 +25,7 @@ void main() { float rev = 1.0; // We're using an int16 range for the angles. - if (abs(a_angle + u_angle) > 32767.0) rev = -1.0; + if (abs(a_angle + u_angle) > 32767.0 && u_flip > 0.0) rev = -1.0; // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier From a79addfaaa075451b9cfb2af4c90e35e9ddc1808 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 8 Nov 2013 16:35:41 -0500 Subject: [PATCH 006/259] fix rotation range bug in shader/buffer --- sdf.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 3384a289ecd..ff4e8dd08db 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -32,7 +32,7 @@ void main() { // for us to create degenerate triangle strips. float z = 1.0 - step(a_minzoom, u_zoom); - float angle = mod(u_angle + 65536.0, 65536.0); + float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + rev * u_exmatrix * vec4(a_offset / 64.0, z, 0); From c314311d8094ac5d6f0d1cff518b409587683037 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 11 Nov 2013 18:13:56 -0500 Subject: [PATCH 007/259] add maxzoom to glyphs --- sdf.vertex.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index ff4e8dd08db..10be24ac36b 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -5,6 +5,7 @@ attribute vec2 a_offset; attribute vec2 a_tex; attribute float a_angle; attribute float a_minzoom; +attribute float a_maxzoom; attribute float a_rangeend; attribute float a_rangestart; @@ -30,7 +31,7 @@ void main() { // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. - float z = 1.0 - step(a_minzoom, u_zoom); + float z = 2.0 - step(a_minzoom, u_zoom) - step(u_zoom, a_maxzoom); float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From 083ad5db1b07f942b470178063dc505d7e36ecfc Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 13 Nov 2013 12:17:14 -0500 Subject: [PATCH 008/259] intial sliding labels --- sdf.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 10be24ac36b..2767d2ee04b 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -31,7 +31,7 @@ void main() { // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. - float z = 2.0 - step(a_minzoom, u_zoom) - step(u_zoom, a_maxzoom); + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From d13e9f97570d38b45b6fa5d9727a7b8bc59aaff7 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 13 Nov 2013 17:04:49 -0500 Subject: [PATCH 009/259] curved labels. messy, slow, but working. --- sdf.vertex.glsl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 2767d2ee04b..6ecc82c9988 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -24,18 +24,20 @@ varying vec2 v_tex; void main() { - float rev = 1.0; + float rev = 0.0; // We're using an int16 range for the angles. - if (abs(a_angle + u_angle) > 32767.0 && u_flip > 0.0) rev = -1.0; + //if (abs(a_angle + u_angle) > 32767.0 && u_flip > 0.0) rev = -1.0; + if (abs(mod(a_angle + u_angle/2.0, 65536.0) - 32767.0) < 16384.0 && u_flip > 0.0) rev = -1.0; + //rev = 1.0; // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); - gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + rev * u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex * 4.0 / u_texsize; } From eb6b2515c402989c315b476976f404b1c0fba6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 15 Nov 2013 14:54:37 +0100 Subject: [PATCH 010/259] show poi icons --- point.fragment.glsl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/point.fragment.glsl b/point.fragment.glsl index c48e121c507..51d2de9e992 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -4,17 +4,21 @@ precision mediump float; uniform sampler2D u_image; uniform vec2 u_tl; uniform vec2 u_br; +uniform vec4 u_color; varying mat2 v_rotationmatrix; void main(void) { - vec2 pos = v_rotationmatrix * (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5; float inbounds = step(0.0, pos.x) * step(0.0, pos.y) * (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y)); - gl_FragColor = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds; + vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds; - gl_FragColor.rgb *= gl_FragColor.a; + if (u_color.a > 0.0) { + gl_FragColor = u_color * color.a; + } else { + gl_FragColor = vec4(color.rgb * color.a, color.a); + } } From e4584b6a40fe8d40770546f068452d0708f2c247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Nov 2013 16:47:02 +0100 Subject: [PATCH 011/259] allow inverting icons --- point.fragment.glsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/point.fragment.glsl b/point.fragment.glsl index 51d2de9e992..45da978c941 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -5,6 +5,7 @@ uniform sampler2D u_image; uniform vec2 u_tl; uniform vec2 u_br; uniform vec4 u_color; +uniform bool u_invert; varying mat2 v_rotationmatrix; @@ -15,6 +16,9 @@ void main(void) { (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y)); vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds; + if (u_invert) { + color.rgb = 1.0 - color.rgb; + } if (u_color.a > 0.0) { gl_FragColor = u_color * color.a; From 45bcdb36110b0f0998a190525ee7fb0bc35e1ca9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 22 Nov 2013 11:56:25 -0500 Subject: [PATCH 012/259] fade labels based on zoom level --- sdf.fragment.glsl | 3 ++- sdf.vertex.glsl | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index ce1324dd3a2..595437a2136 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -6,9 +6,10 @@ uniform float u_buffer; uniform float u_gamma; varying vec2 v_tex; +varying float v_alpha; void main() { float dist = texture2D(u_texture, v_tex).a; - float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist); + float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist) * v_alpha; gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 6ecc82c9988..e569379ce69 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -8,6 +8,7 @@ attribute float a_minzoom; attribute float a_maxzoom; attribute float a_rangeend; attribute float a_rangestart; +attribute float a_labelminzoom; // posmatrix is for the vertex position, exmatrix is for rotating and projecting @@ -17,13 +18,16 @@ uniform mat4 u_exmatrix; uniform float u_angle; uniform float u_zoom; uniform float u_flip; +uniform float u_fadefactor; uniform vec2 u_texsize; varying vec2 v_tex; +varying float v_alpha; void main() { + float a_fadedist = 10.0; float rev = 0.0; // We're using an int16 range for the angles. //if (abs(a_angle + u_angle) > 32767.0 && u_flip > 0.0) rev = -1.0; @@ -35,6 +39,8 @@ void main() { // for us to create degenerate triangle strips. float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; + v_alpha = smoothstep(a_labelminzoom, a_labelminzoom + a_fadedist * u_fadefactor, u_zoom); + float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From 0d0cdc1b1618a7b8e802ed05fa8e21a2f01d3089 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 28 Nov 2013 18:29:25 -0500 Subject: [PATCH 013/259] first attempt at fading out labels after zoomend --- sdf.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index e569379ce69..7ccb2d2b6f1 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -39,7 +39,7 @@ void main() { // for us to create degenerate triangle strips. float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; - v_alpha = smoothstep(a_labelminzoom, a_labelminzoom + a_fadedist * u_fadefactor, u_zoom); + v_alpha = clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 0.0, 1.0); float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From c2347d07f67202c708cf0d8c744395095bc2e5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 4 Dec 2013 16:06:42 +0100 Subject: [PATCH 014/259] new polygon drawing code instead of using GL_INVERT, we increment/decrement the pixels so that we can detect nonzero areas. this means we can now handle overlapping polygons. optionally, you can switch back to even-odd filling if desired (needs to be exposed to the stylesheet). in the same turn, it switches the clipping from the depth to the stencil buffer so that we don't need to request a depth buffer at all. prior to rendering, it masks the 0x80 bit to indicate the current tile extent. it also switches to front-to-back compositing, meaning that things drawn later in a frame will appear *behind* what is already visible. this allows us to use the stencil buffer to mask areas that are fully opaque so that we can cull fragments in those areas early on. fixes #55 fixes #77 fixes #177 --- fill.fragment.glsl | 7 +++++++ fill.vertex.glsl | 8 ++++++++ outline.fragment.glsl | 11 +++++++++++ outline.vertex.glsl | 16 ++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 fill.fragment.glsl create mode 100644 fill.vertex.glsl create mode 100644 outline.fragment.glsl create mode 100644 outline.vertex.glsl diff --git a/fill.fragment.glsl b/fill.fragment.glsl new file mode 100644 index 00000000000..f21d7dd6ebb --- /dev/null +++ b/fill.fragment.glsl @@ -0,0 +1,7 @@ +precision mediump float; + +uniform vec4 u_color; + +void main() { + gl_FragColor = u_color; +} diff --git a/fill.vertex.glsl b/fill.vertex.glsl new file mode 100644 index 00000000000..cf6e81a2f9e --- /dev/null +++ b/fill.vertex.glsl @@ -0,0 +1,8 @@ +precision mediump float; + +attribute vec2 a_pos; +uniform mat4 u_posmatrix; + +void main() { + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); +} diff --git a/outline.fragment.glsl b/outline.fragment.glsl new file mode 100644 index 00000000000..f7e5fda9a38 --- /dev/null +++ b/outline.fragment.glsl @@ -0,0 +1,11 @@ +precision mediump float; + +uniform vec4 u_color; + +varying vec2 v_pos; + +void main() { + float dist = length(v_pos - gl_FragCoord.xy); + float alpha = smoothstep(1.0, 0.0, dist); + gl_FragColor = u_color * alpha; +} diff --git a/outline.vertex.glsl b/outline.vertex.glsl new file mode 100644 index 00000000000..43194b92326 --- /dev/null +++ b/outline.vertex.glsl @@ -0,0 +1,16 @@ +precision mediump float; + +attribute vec2 a_pos; +uniform mat4 u_posmatrix; +uniform vec2 u_world; + +varying vec2 v_pos; + +void main() { + // If the x coordinate is the maximum integer, we move the z coordinates out + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + float z = step(32767.0, a_pos.x); + gl_Position = u_posmatrix * vec4(a_pos, z, 1); + v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world; +} From ffe8fa7b4e52eb4f8385e43538ae110eabf68e0d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Dec 2013 14:15:42 -0500 Subject: [PATCH 015/259] add demo first attempt --- sdf.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 7ccb2d2b6f1..52cecbe66fd 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -39,7 +39,7 @@ void main() { // for us to create degenerate triangle strips. float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; - v_alpha = clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 0.0, 1.0); + v_alpha = 1.0 ;//clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 0.0, 1.0); float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From 0a2f1e00bc5e18fdb8fd4c4cb7d93eec7c136c14 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Dec 2013 16:13:48 -0500 Subject: [PATCH 016/259] demo tweaks --- sdf.vertex.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 52cecbe66fd..bb6ccf35491 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -39,7 +39,9 @@ void main() { // for us to create degenerate triangle strips. float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; - v_alpha = 1.0 ;//clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 0.0, 1.0); + // Fade out labels (disabled) + //v_alpha = clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 0.0, 1.0); + v_alpha = clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 1.0, 1.0); float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From 814c80713be0aee1843c3869e5f07cfc27178393 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 16 Dec 2013 11:51:42 -0500 Subject: [PATCH 017/259] add support for patterns --- pattern.fragment.glsl | 29 +++++++++++++++++++++++++++++ pattern.vertex.glsl | 12 ++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 pattern.fragment.glsl create mode 100644 pattern.vertex.glsl diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl new file mode 100644 index 00000000000..8baf5547a8b --- /dev/null +++ b/pattern.fragment.glsl @@ -0,0 +1,29 @@ +precision mediump float; + +uniform vec4 u_color; + +uniform vec2 u_rotate; +uniform vec2 u_offset; +uniform vec2 u_pattern_size; +uniform vec2 u_pattern_tl; +uniform vec2 u_pattern_br; +uniform float u_mix; + + +uniform sampler2D u_image; + +varying vec2 v_pos; + +void main() { + + vec2 imagecoord = mod((v_pos + u_offset) / u_pattern_size, 1.0) * u_rotate; + vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); + vec4 color1 = texture2D(u_image, pos); + + vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); + vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); + vec4 color2 = texture2D(u_image, pos2); + + vec4 color = mix(color1, color2, u_mix); + gl_FragColor = color + u_color * (1.0 - color.a); +} diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl new file mode 100644 index 00000000000..4c4c7cffdbb --- /dev/null +++ b/pattern.vertex.glsl @@ -0,0 +1,12 @@ +precision mediump float; + +uniform mat4 u_posmatrix; + +attribute vec2 a_pos; + +varying vec2 v_pos; + +void main() { + v_pos = a_pos; + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); +} From 0d5e3b3e10c7c312e67dc098ed6786af6fde6a6e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 17 Dec 2013 16:24:20 -0500 Subject: [PATCH 018/259] initial line patterns attempt --- linepattern.fragment.glsl | 44 +++++++++++++++++++++++++++ linepattern.vertex.glsl | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 linepattern.fragment.glsl create mode 100644 linepattern.vertex.glsl diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl new file mode 100644 index 00000000000..47f7153a884 --- /dev/null +++ b/linepattern.fragment.glsl @@ -0,0 +1,44 @@ +precision mediump float; + +// shared +uniform float u_debug; +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_point; +uniform float u_gamma; + +uniform vec2 u_pattern_size; +uniform vec2 u_pattern_tl; +uniform vec2 u_pattern_br; +uniform float u_fade; + +uniform sampler2D u_image; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // Calculate the distance of the pixel from the line in pixels. + float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); + + dist *= u_linewidth.s; + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist) * u_gamma, 0.0, 1.0); + + float x = mod(v_linesofar / u_pattern_size.x, 1.0); + float y = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size.y); + vec2 pos = mix(u_pattern_tl, u_pattern_br, vec2(x, y)); + float x2 = mod(x * 2.0, 1.0); + vec2 pos2 = mix(u_pattern_tl, u_pattern_br, vec2(x2, y)); + + vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); + + gl_FragColor = color * u_color.a * alpha; + + if (u_debug > 0.0) { + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); + } +} diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl new file mode 100644 index 00000000000..8f99b5ac1bd --- /dev/null +++ b/linepattern.vertex.glsl @@ -0,0 +1,63 @@ +// these are the shaders for rendering antialiased lines +precision mediump float; + +// floor(127 / 2) == 63.0 +// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is +// stored in a byte (-128..127). we scale regular normals up to length 63, but +// there are also "special" normals that have a bigger length (of up to 126 in +// this case). +#define scale 63.0 + +attribute vec2 a_pos; +attribute vec2 a_extrude; +attribute float a_linesofar; + +// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_posmatrix; +uniform mat4 u_exmatrix; + + +uniform float u_debug; + +// shared +uniform float u_ratio; +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_point; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // We store the texture normals in the most insignificant bit + // transform y so that 0 => -1 and 1 => 1 + // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap + // y is 1 if the normal points up, and -1 if it points down + vec2 normal = mod(a_pos, 2.0); + normal.y = sign(normal.y - 0.5); + v_normal = normal; + + // Scale the extrusion vector down to a normal and then up by the line width + // of this vertex. + vec2 extrude = a_extrude / scale; + vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); + + // If the x coordinate is the maximum integer, we move the z coordinates out + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + float z = step(32767.0, a_pos.x); + + // When drawing points, skip every other vertex + z += u_point * step(1.0, v_normal.y); + + // Remove the texture normal bit of the position before scaling it with the + // model/view matrix. Add the extrusion vector *after* the model/view matrix + // because we're extruding the line in pixel space, regardless of the current + // tile's zoom level. + gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + v_linesofar = a_linesofar;// * u_ratio; + + + gl_PointSize = 2.0 * u_linewidth.s - 1.0; +} From b0bcc4d630dcc7f2b6a4125dc68bfcd1ad78a198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 3 Jan 2014 16:47:06 +0100 Subject: [PATCH 019/259] fix debug vertex display --- debug_point.fragment.glsl | 7 +++++++ debug_point.vertex.glsl | 12 ++++++++++++ fill.vertex.glsl | 1 + 3 files changed, 20 insertions(+) create mode 100644 debug_point.fragment.glsl create mode 100644 debug_point.vertex.glsl diff --git a/debug_point.fragment.glsl b/debug_point.fragment.glsl new file mode 100644 index 00000000000..f21d7dd6ebb --- /dev/null +++ b/debug_point.fragment.glsl @@ -0,0 +1,7 @@ +precision mediump float; + +uniform vec4 u_color; + +void main() { + gl_FragColor = u_color; +} diff --git a/debug_point.vertex.glsl b/debug_point.vertex.glsl new file mode 100644 index 00000000000..b313ce8455c --- /dev/null +++ b/debug_point.vertex.glsl @@ -0,0 +1,12 @@ +precision mediump float; + +attribute vec2 a_pos; + +uniform mat4 u_posmatrix; +uniform float u_pointsize; +uniform float u_scale; + +void main() { + gl_Position = u_posmatrix * vec4(floor(a_pos / u_scale), 0, 1); + gl_PointSize = u_pointsize; +} diff --git a/fill.vertex.glsl b/fill.vertex.glsl index cf6e81a2f9e..ee737f69ba6 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -5,4 +5,5 @@ uniform mat4 u_posmatrix; void main() { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + gl_PointSize = 2.0; } From 5e03af11e502224ff7742853c5ad616256eeae83 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sun, 2 Feb 2014 13:24:43 -0500 Subject: [PATCH 020/259] new approach to fading labels in and out The general idea is to take the current speed of zooming, pass it to the shader, and let each vertex estimate how long since it was visble and what its opacity should be. --- sdf.vertex.glsl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index bb6ccf35491..afe492ff036 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -18,7 +18,7 @@ uniform mat4 u_exmatrix; uniform float u_angle; uniform float u_zoom; uniform float u_flip; -uniform float u_fadefactor; +uniform float u_fadedist; uniform vec2 u_texsize; @@ -39,9 +39,18 @@ void main() { // for us to create degenerate triangle strips. float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; - // Fade out labels (disabled) - //v_alpha = clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 0.0, 1.0); - v_alpha = clamp((u_zoom - a_labelminzoom) / (u_fadefactor * 10.0), 1.0, 1.0); + // fade out labels + float alpha = smoothstep(0.0, 1.0, clamp((u_zoom - a_labelminzoom + 0.01) / u_fadedist, 0.0, 1.0)); + + // todo remove branching + if (u_fadedist >= 0.0) { + v_alpha = alpha; + } else { + v_alpha = 1.0 - alpha; + } + + // if label has been faded out, clip it + z += step(v_alpha, 0.0); float angle = mod(u_angle/2.0 + 65536.0, 65536.0); z += step(a_rangeend, angle) * step(angle, a_rangestart); From ebd2b526092ebb4e590ce50670d57f461e7f5e03 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sun, 2 Feb 2014 14:00:22 -0500 Subject: [PATCH 021/259] remove unused u_rotate from pattern shader --- pattern.fragment.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index 8baf5547a8b..4ae6ce443f8 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -2,7 +2,6 @@ precision mediump float; uniform vec4 u_color; -uniform vec2 u_rotate; uniform vec2 u_offset; uniform vec2 u_pattern_size; uniform vec2 u_pattern_tl; @@ -16,7 +15,7 @@ varying vec2 v_pos; void main() { - vec2 imagecoord = mod((v_pos + u_offset) / u_pattern_size, 1.0) * u_rotate; + vec2 imagecoord = mod((v_pos + u_offset) / u_pattern_size, 1.0); vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); vec4 color1 = texture2D(u_image, pos); From 8be5184ea327b8358069f11adf3270cd6bf75566 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 6 Feb 2014 20:29:26 -0500 Subject: [PATCH 022/259] fix label fading Actually work out the math to properly estimate fades based on current zooming speed. --- sdf.vertex.glsl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index afe492ff036..767c1d93d84 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -19,6 +19,9 @@ uniform float u_angle; uniform float u_zoom; uniform float u_flip; uniform float u_fadedist; +uniform float u_minfadezoom; +uniform float u_maxfadezoom; +uniform float u_fadezoombump; uniform vec2 u_texsize; @@ -40,7 +43,7 @@ void main() { float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; // fade out labels - float alpha = smoothstep(0.0, 1.0, clamp((u_zoom - a_labelminzoom + 0.01) / u_fadedist, 0.0, 1.0)); + float alpha = clamp((u_zoom + u_fadezoombump - a_labelminzoom) / u_fadedist, 0.0, 1.0); // todo remove branching if (u_fadedist >= 0.0) { @@ -48,6 +51,12 @@ void main() { } else { v_alpha = 1.0 - alpha; } + if (u_maxfadezoom < a_labelminzoom) { + v_alpha = 0.0; + } + if (u_minfadezoom >= a_labelminzoom) { + v_alpha = 1.0; + } // if label has been faded out, clip it z += step(v_alpha, 0.0); From d594f77ddf07fc837f260393075b818da7f50e8b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 7 Feb 2014 18:36:41 -0500 Subject: [PATCH 023/259] switch glyph angles and zoom levels to bytes ... and fix a bunch of rotation problems that were hidden by the high precision. --- sdf.vertex.glsl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 767c1d93d84..6649edbf6cb 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -32,10 +32,9 @@ void main() { float a_fadedist = 10.0; float rev = 0.0; - // We're using an int16 range for the angles. - //if (abs(a_angle + u_angle) > 32767.0 && u_flip > 0.0) rev = -1.0; - if (abs(mod(a_angle + u_angle/2.0, 65536.0) - 32767.0) < 16384.0 && u_flip > 0.0) rev = -1.0; - //rev = 1.0; + // We're using an int18 range for the angles. + float rotated = mod(a_angle + u_angle/2.0, 256.0) - 128.0; + if (rotated >= -64.0 && rotated < 64.0 && u_flip > 0.0) rev = -1.0; // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier @@ -61,8 +60,8 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - float angle = mod(u_angle/2.0 + 65536.0, 65536.0); - z += step(a_rangeend, angle) * step(angle, a_rangestart); + float angle = mod(u_angle/2.0 + 256.0, 256.0); + z += step(a_rangeend, angle) * (1.0 - step(a_rangestart, angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex * 4.0 / u_texsize; From 3b89c491a764af0147c4029fb44bbb9e58eb0790 Mon Sep 17 00:00:00 2001 From: Eden Halperin Date: Fri, 7 Feb 2014 15:38:54 -0800 Subject: [PATCH 024/259] add dot shader if no image specified in point bucket, closes #249 --- dot.fragment.glsl | 11 +++++++++++ dot.vertex.glsl | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 dot.fragment.glsl create mode 100644 dot.vertex.glsl diff --git a/dot.fragment.glsl b/dot.fragment.glsl new file mode 100644 index 00000000000..694a5c517b4 --- /dev/null +++ b/dot.fragment.glsl @@ -0,0 +1,11 @@ +precision mediump float; + +uniform vec4 u_color; +uniform float u_fade; + +void main() { + float dist = length(gl_PointCoord - vec2(0.5, 0.5)); + float t = smoothstep(0.5-(u_fade/2.0), 0.5, dist); + + gl_FragColor = mix(u_color, vec4(0.0, 0.0, 0.0, 0.0), t); +} diff --git a/dot.vertex.glsl b/dot.vertex.glsl new file mode 100644 index 00000000000..4243918f035 --- /dev/null +++ b/dot.vertex.glsl @@ -0,0 +1,11 @@ +precision mediump float; + +uniform mat4 u_posmatrix; +uniform float u_size; + +attribute vec2 a_pos; + +void main(void) { + gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0, 1); + gl_PointSize = u_size; +} From 9f5f95a41ea5e37e79527f5744fdc24d74d707b7 Mon Sep 17 00:00:00 2001 From: Eden Halperin Date: Fri, 7 Feb 2014 16:11:08 -0800 Subject: [PATCH 025/259] cleanup drawpoint.js, dotFade -> blur --- dot.fragment.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dot.fragment.glsl b/dot.fragment.glsl index 694a5c517b4..52b903a17cf 100644 --- a/dot.fragment.glsl +++ b/dot.fragment.glsl @@ -1,11 +1,11 @@ precision mediump float; uniform vec4 u_color; -uniform float u_fade; +uniform float u_blur; void main() { float dist = length(gl_PointCoord - vec2(0.5, 0.5)); - float t = smoothstep(0.5-(u_fade/2.0), 0.5, dist); + float t = smoothstep(0.5-(u_blur/2.0), 0.5, dist); gl_FragColor = mix(u_color, vec4(0.0, 0.0, 0.0, 0.0), t); } From 1a41f75ea3c4c5e55ba1da14e847b776947cf985 Mon Sep 17 00:00:00 2001 From: Eden Halperin Date: Mon, 10 Feb 2014 11:13:58 -0800 Subject: [PATCH 026/259] pixel-based blur for dot shader --- dot.fragment.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dot.fragment.glsl b/dot.fragment.glsl index 52b903a17cf..7d3477d8eda 100644 --- a/dot.fragment.glsl +++ b/dot.fragment.glsl @@ -5,7 +5,7 @@ uniform float u_blur; void main() { float dist = length(gl_PointCoord - vec2(0.5, 0.5)); - float t = smoothstep(0.5-(u_blur/2.0), 0.5, dist); + float t = smoothstep(0.5 - u_blur, 0.5, dist); - gl_FragColor = mix(u_color, vec4(0.0, 0.0, 0.0, 0.0), t); + gl_FragColor = u_color * (1.0 - t); } From f9abf949ec14da2a3da4fa797cb9e52c90f0f6f5 Mon Sep 17 00:00:00 2001 From: Eden Halperin Date: Mon, 10 Feb 2014 11:30:50 -0800 Subject: [PATCH 027/259] dot fragment cleanup, closes #249 --- dot.fragment.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dot.fragment.glsl b/dot.fragment.glsl index 7d3477d8eda..1feefca75b3 100644 --- a/dot.fragment.glsl +++ b/dot.fragment.glsl @@ -4,8 +4,8 @@ uniform vec4 u_color; uniform float u_blur; void main() { - float dist = length(gl_PointCoord - vec2(0.5, 0.5)); - float t = smoothstep(0.5 - u_blur, 0.5, dist); + float dist = length(gl_PointCoord - 0.5); + float t = smoothstep(0.5, 0.5 - u_blur, dist); - gl_FragColor = u_color * (1.0 - t); + gl_FragColor = u_color * t; } From 591f0fcb9ee97b426fcf550dfe719265095b1031 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 12 Feb 2014 12:42:44 -0500 Subject: [PATCH 028/259] replace debugPointShader with dotShader --- debug_point.fragment.glsl | 7 ------- debug_point.vertex.glsl | 12 ------------ 2 files changed, 19 deletions(-) delete mode 100644 debug_point.fragment.glsl delete mode 100644 debug_point.vertex.glsl diff --git a/debug_point.fragment.glsl b/debug_point.fragment.glsl deleted file mode 100644 index f21d7dd6ebb..00000000000 --- a/debug_point.fragment.glsl +++ /dev/null @@ -1,7 +0,0 @@ -precision mediump float; - -uniform vec4 u_color; - -void main() { - gl_FragColor = u_color; -} diff --git a/debug_point.vertex.glsl b/debug_point.vertex.glsl deleted file mode 100644 index b313ce8455c..00000000000 --- a/debug_point.vertex.glsl +++ /dev/null @@ -1,12 +0,0 @@ -precision mediump float; - -attribute vec2 a_pos; - -uniform mat4 u_posmatrix; -uniform float u_pointsize; -uniform float u_scale; - -void main() { - gl_Position = u_posmatrix * vec4(floor(a_pos / u_scale), 0, 1); - gl_PointSize = u_pointsize; -} From 9ece154799fdd2a9d99ef9ddc8d728525791a72b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 12 Feb 2014 13:07:48 -0500 Subject: [PATCH 029/259] store point angle in one byte --- point.vertex.glsl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/point.vertex.glsl b/point.vertex.glsl index fefb40bcc1f..922beacf7b6 100644 --- a/point.vertex.glsl +++ b/point.vertex.glsl @@ -8,7 +8,8 @@ uniform vec2 u_size; uniform mat2 u_rotationmatrix; attribute vec2 a_pos; -attribute vec2 a_slope; +attribute float a_angle; + varying mat2 v_rotationmatrix; void main(void) { @@ -16,10 +17,8 @@ void main(void) { gl_Position = u_posmatrix * vec4(floor(a_pos/2.0), 0, 1); gl_PointSize = u_size.x * root2; - float angle = atan(a_slope.y, a_slope.x); - v_rotationmatrix = mat2( - cos(angle), -sin(angle), - sin(angle), cos(angle) + cos(a_angle), -sin(a_angle), + sin(a_angle), cos(a_angle) ) * u_rotationmatrix; } From 6c68229e88cf81cfe8ae584e6133a397dd8339f2 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 12 Feb 2014 14:09:03 -0500 Subject: [PATCH 030/259] use separate buffer for points, add a_minzoom A step in the direction of drawing different icons with one draw call, and being able to place/fade points just like text. --- dot.vertex.glsl | 2 +- point.vertex.glsl | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dot.vertex.glsl b/dot.vertex.glsl index 4243918f035..d71dae5e5a2 100644 --- a/dot.vertex.glsl +++ b/dot.vertex.glsl @@ -6,6 +6,6 @@ uniform float u_size; attribute vec2 a_pos; void main(void) { - gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0, 1); + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); gl_PointSize = u_size; } diff --git a/point.vertex.glsl b/point.vertex.glsl index 922beacf7b6..3252515e4c5 100644 --- a/point.vertex.glsl +++ b/point.vertex.glsl @@ -2,23 +2,31 @@ precision mediump float; #define scale 63.0 #define root2 1.42 +#define PI 3.1415926535897932384626 uniform mat4 u_posmatrix; uniform vec2 u_size; uniform mat2 u_rotationmatrix; +uniform float u_zoom; attribute vec2 a_pos; attribute float a_angle; +attribute float a_minzoom; varying mat2 v_rotationmatrix; void main(void) { - gl_Position = u_posmatrix * vec4(floor(a_pos/2.0), 0, 1); + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); gl_PointSize = u_size.x * root2; + // if u_zoom < a_minzoom hide this point + gl_Position.z += 1.0 - step(a_minzoom, u_zoom); + + float angle = a_angle * 2.0 * PI / 256.0; + v_rotationmatrix = mat2( - cos(a_angle), -sin(a_angle), - sin(a_angle), cos(a_angle) + cos(angle), -sin(angle), + sin(angle), cos(angle) ) * u_rotationmatrix; } From a16258ec46456c71ce309ebc8732fceba91f710e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 19 Feb 2014 06:08:12 -0500 Subject: [PATCH 031/259] fix label rotation collisions fixes #295 --- sdf.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 6649edbf6cb..2018b78db57 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -60,7 +60,7 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - float angle = mod(u_angle/2.0 + 256.0, 256.0); + float angle = mod(u_angle, 256.0); z += step(a_rangeend, angle) * (1.0 - step(a_rangestart, angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); From bd96187d4fe8a4f621630ef17c9705b4a6acb78e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 19 Feb 2014 06:42:05 -0500 Subject: [PATCH 032/259] simplify and comment sdf shader --- sdf.vertex.glsl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 2018b78db57..060474a2d53 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -32,14 +32,17 @@ void main() { float a_fadedist = 10.0; float rev = 0.0; - // We're using an int18 range for the angles. - float rotated = mod(a_angle + u_angle/2.0, 256.0) - 128.0; - if (rotated >= -64.0 && rotated < 64.0 && u_flip > 0.0) rev = -1.0; + + // u_angle is angle of the map, -128..128 representing 0..2PI + // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text + float rotated = mod(a_angle + u_angle, 256.0); + // if the label rotates with the map, and if the rotated label is upside down, hide it + if (u_flip > 0.0 && rotated > 64.0 && rotated <= 192.0) rev = 1.0; // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) - rev; + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; // fade out labels float alpha = clamp((u_zoom + u_fadezoombump - a_labelminzoom) / u_fadedist, 0.0, 1.0); @@ -61,6 +64,9 @@ void main() { z += step(v_alpha, 0.0); float angle = mod(u_angle, 256.0); + + // all the angles are 0..256 representing 0..2PI + // hide if (angle >= a_rangeend && angle < rangestart) z += step(a_rangeend, angle) * (1.0 - step(a_rangestart, angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); From 156446b8da9c49364f4065594cf4b8fefa8e5c9f Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 19 Feb 2014 09:14:54 -0500 Subject: [PATCH 033/259] convert -pi..pi angle to 0..2pi in js not shader --- sdf.vertex.glsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 060474a2d53..be52d32e6b8 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -37,7 +37,7 @@ void main() { // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text float rotated = mod(a_angle + u_angle, 256.0); // if the label rotates with the map, and if the rotated label is upside down, hide it - if (u_flip > 0.0 && rotated > 64.0 && rotated <= 192.0) rev = 1.0; + if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier @@ -63,11 +63,9 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - float angle = mod(u_angle, 256.0); - // all the angles are 0..256 representing 0..2PI // hide if (angle >= a_rangeend && angle < rangestart) - z += step(a_rangeend, angle) * (1.0 - step(a_rangestart, angle)); + z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex * 4.0 / u_texsize; From bc596aa06a152b9dda8477cbd4f9745aeecd0687 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 20 Feb 2014 08:09:35 -0500 Subject: [PATCH 034/259] fix font sizes as functions for curved labels Each glyph has a `a_minzoom` and `a_maxzoom` which set the range of zoom levels it is safe to show the glyph if the glyph is rendered at the fontSize which was used for placement (the one set in the bucket). `u_zoom` is compared against the min and max values to see if the glyph can be shown. When the font size in the style is different than that at which the glyphs were placed, then the min and max zooms the glyph can be shown at change. Instead of changing the min and max zooms, this adjusts `u_zoom` so that less work needs to be done in the shader. --- sdf.vertex.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index be52d32e6b8..99385f6c9af 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -21,7 +21,7 @@ uniform float u_flip; uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; -uniform float u_fadezoombump; +uniform float u_fadezoom; uniform vec2 u_texsize; @@ -42,10 +42,11 @@ void main() { // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. + // u_zoom is the current zoom level adjusted for the change in font size float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; // fade out labels - float alpha = clamp((u_zoom + u_fadezoombump - a_labelminzoom) / u_fadedist, 0.0, 1.0); + float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); // todo remove branching if (u_fadedist >= 0.0) { From fd838604b369d0c7284e22b8a58307f73285c148 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 14 Mar 2014 12:51:01 -0400 Subject: [PATCH 035/259] remove areaShader, just use fillShader --- area.fragment.glsl | 8 -------- area.vertex.glsl | 12 ------------ 2 files changed, 20 deletions(-) delete mode 100644 area.fragment.glsl delete mode 100644 area.vertex.glsl diff --git a/area.fragment.glsl b/area.fragment.glsl deleted file mode 100644 index 3a86241cc93..00000000000 --- a/area.fragment.glsl +++ /dev/null @@ -1,8 +0,0 @@ -precision mediump float; - -uniform vec4 u_color; - -void main() { - gl_FragColor = u_color; - -} diff --git a/area.vertex.glsl b/area.vertex.glsl deleted file mode 100644 index de67896cea1..00000000000 --- a/area.vertex.glsl +++ /dev/null @@ -1,12 +0,0 @@ -// these are the shaders for rendering filled areas - -precision mediump float; - -attribute vec2 a_pos; - -uniform mat4 u_posmatrix; - -void main() { - gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0, 1); - gl_PointSize = 2.0; -} From 620337046a66e6a2bf4fcc6e470cc1e767b0288b Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 14 Mar 2014 13:57:59 -0700 Subject: [PATCH 036/259] Blur road outlines as well --- line.fragment.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 079818f3d81..bcaa4b7c1f9 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -6,6 +6,7 @@ uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_point; uniform float u_gamma; +uniform float u_blur; uniform vec2 u_dasharray; @@ -13,6 +14,7 @@ varying vec2 v_normal; varying float v_linesofar; void main() { + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); @@ -21,7 +23,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist) * u_gamma, 0.0, 1.0); + float alpha = clamp((min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur) * u_gamma, 0.0, 1.0); // Calculate the antialiasing fade factor based on distance to the dash. // Only affects alpha when line is dashed From a8d8c591fa3b18632b6669538db8c2aee3f7559b Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 17 Mar 2014 11:44:34 -0700 Subject: [PATCH 037/259] Fix saturation and spin controls. Fixes #333 --- raster.fragment.glsl | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 5f5c8e9a8f1..75f0b4cecda 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -21,22 +21,30 @@ void main() { u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); - // http://www.laurenscorijn.com/articles/colormath-basics - original = texture2D(u_image, v_pos).xyz; - len = length(original) / 2.0; + vec4 color = texture2D(u_image, v_pos); - greyscale = vec3(len, len, len); + float angle = u_spin * 3.14159265; + float s = sin(angle), c = cos(angle); + vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0; + float len = length(color.rgb); - saturated = (u_saturation * original) + ((1.0 - u_saturation) * greyscale); + color.rgb = vec3( + dot(color.rgb, weights.xyz), + dot(color.rgb, weights.zxy), + dot(color.rgb, weights.yzx)); + + float average = (color.r + color.g + color.b) / 3.0; + + if (u_saturation > 0.0) { + color.rgb += (average - color.rgb) * (1.0 - 1.0 / (1.001 - u_saturation)); + } else { + color.rgb += (average - color.rgb) * (-u_saturation); + } gl_FragColor = vec4( mix( u_high_vec, u_low_vec, - // texture2D(u_image, v_pos).xyz - saturated - ) * mat3( - 1, 0, 0, - 0, cos(u_spin), -sin(u_spin), - 0, sin(u_spin), cos(u_spin)), 1.0); + color.rgb + ), color.a); } From 8692b9f8cccdb483ed863f386bc2f96fb16e37ec Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 17 Mar 2014 11:57:59 -0700 Subject: [PATCH 038/259] Add contrast control for satellite imagery --- raster.fragment.glsl | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 75f0b4cecda..867b16523b5 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -4,22 +4,14 @@ uniform float u_brightness_low; uniform float u_brightness_high; uniform float u_spin; uniform float u_saturation; +uniform float u_contrast; uniform sampler2D u_image; varying vec2 v_pos; -vec3 u_high_vec; -vec3 u_low_vec; - -vec3 greyscale; -vec3 original; -vec3 saturated; - -float len; - void main() { - u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); - u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); + vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); + vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); vec4 color = texture2D(u_image, v_pos); @@ -41,6 +33,12 @@ void main() { color.rgb += (average - color.rgb) * (-u_saturation); } + if (u_contrast > 0.0) { + color.rgb = (color.rgb - 0.5) / (1.0 - u_contrast) + 0.5; + } else { + color.rgb = (color.rgb - 0.5) * (1.0 + u_contrast) + 0.5; + } + gl_FragColor = vec4( mix( u_high_vec, From 38a370fb52bff28cfc015f0784e66f74863bc775 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 18 Mar 2014 16:15:11 -0400 Subject: [PATCH 039/259] remove misleading todo --- sdf.vertex.glsl | 1 - 1 file changed, 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 99385f6c9af..647b17226b5 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -48,7 +48,6 @@ void main() { // fade out labels float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); - // todo remove branching if (u_fadedist >= 0.0) { v_alpha = alpha; } else { From 7be6a4ad2c6d403a2d290ead82b20db199e3f832 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sat, 22 Mar 2014 22:08:05 -0400 Subject: [PATCH 040/259] remove code for drawing round joins with points Switching back to the old way of doing it. ref #120 --- line.fragment.glsl | 3 +-- line.vertex.glsl | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index bcaa4b7c1f9..31c2c23a1ba 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -4,7 +4,6 @@ precision mediump float; uniform float u_debug; uniform vec2 u_linewidth; uniform vec4 u_color; -uniform float u_point; uniform float u_gamma; uniform float u_blur; @@ -16,7 +15,7 @@ varying float v_linesofar; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); + float dist = length(v_normal); dist *= u_linewidth.s; diff --git a/line.vertex.glsl b/line.vertex.glsl index bd76db8bdd5..bf35ba79dd6 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -24,7 +24,6 @@ uniform float u_debug; uniform float u_ratio; uniform vec2 u_linewidth; uniform vec4 u_color; -uniform float u_point; varying vec2 v_normal; varying float v_linesofar; @@ -41,23 +40,17 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. vec2 extrude = a_extrude / scale; - vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); + vec2 dist = u_linewidth.s * extrude; // If the x coordinate is the maximum integer, we move the z coordinates out // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. float z = step(32767.0, a_pos.x); - // When drawing points, skip every other vertex - z += u_point * step(1.0, v_normal.y); - // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); v_linesofar = a_linesofar * u_ratio; - - - gl_PointSize = 2.0 * u_linewidth.s - 1.0; } From 0c280c5162ebc071fde456f426e10acf1296781f Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sat, 22 Mar 2014 22:33:41 -0400 Subject: [PATCH 041/259] lines now never have degenerate triangles --- line.vertex.glsl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index bf35ba79dd6..fc6e15d6676 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -42,15 +42,10 @@ void main() { vec2 extrude = a_extrude / scale; vec2 dist = u_linewidth.s * extrude; - // If the x coordinate is the maximum integer, we move the z coordinates out - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. - float z = step(32767.0, a_pos.x); - // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, 0.0, 0.0); v_linesofar = a_linesofar * u_ratio; } From 4ce26ac17d65fa6cf70019260f291ac3d2e782de Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 8 May 2014 23:57:40 -0400 Subject: [PATCH 042/259] crossfade raster tiles --- raster.fragment.glsl | 11 ++++++++--- raster.vertex.glsl | 11 +++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 867b16523b5..a3648fef2c2 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -5,15 +5,20 @@ uniform float u_brightness_high; uniform float u_spin; uniform float u_saturation; uniform float u_contrast; -uniform sampler2D u_image; -varying vec2 v_pos; +uniform float u_mix; +uniform sampler2D u_image0; +uniform sampler2D u_image1; +varying vec2 v_pos0; +varying vec2 v_pos1; void main() { vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); - vec4 color = texture2D(u_image, v_pos); + vec4 color0 = texture2D(u_image0, v_pos0); + vec4 color1 = texture2D(u_image1, v_pos1); + vec4 color = mix(color1, color0, u_mix); float angle = u_spin * 3.14159265; float s = sin(angle), c = cos(angle); diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 08fa4185891..d719d34d0e4 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,12 +1,19 @@ precision mediump float; + uniform mat4 u_posmatrix; uniform float u_brightness_low; uniform float u_brightness_high; uniform float u_spin; +uniform vec2 u_tl_parent; +uniform float u_scale_parent; + attribute vec2 a_pos; -varying vec2 v_pos; + +varying vec2 v_pos0; +varying vec2 v_pos1; void main(void) { gl_Position = u_posmatrix * vec4(a_pos, step(32767.0, a_pos.x), 1); - v_pos = a_pos / 4096.0; + v_pos0 = a_pos / 4096.0; + v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } From 46805c40bbd8c1f4df69a54e5663c366081ca3c3 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 9 May 2014 00:44:57 -0400 Subject: [PATCH 043/259] clean up raster shader - move calculation outside the shaders as much as possible - remove effectless code --- raster.fragment.glsl | 58 ++++++++++++++++++-------------------------- raster.vertex.glsl | 5 +--- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/raster.fragment.glsl b/raster.fragment.glsl index a3648fef2c2..563b7c7e029 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -1,53 +1,41 @@ precision mediump float; -uniform float u_brightness_low; -uniform float u_brightness_high; -uniform float u_spin; -uniform float u_saturation; -uniform float u_contrast; uniform float u_mix; uniform sampler2D u_image0; uniform sampler2D u_image1; varying vec2 v_pos0; varying vec2 v_pos1; -void main() { +uniform float u_brightness_low; +uniform float u_brightness_high; - vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); - vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); +uniform float u_saturation_factor; +uniform float u_contrast_factor; +uniform vec3 u_spin_weights; +void main() { + + // read and cross-fade colors from the main and parent tiles vec4 color0 = texture2D(u_image0, v_pos0); vec4 color1 = texture2D(u_image1, v_pos1); vec4 color = mix(color1, color0, u_mix); + vec3 rgb = color.rgb; - float angle = u_spin * 3.14159265; - float s = sin(angle), c = cos(angle); - vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0; - float len = length(color.rgb); - - color.rgb = vec3( - dot(color.rgb, weights.xyz), - dot(color.rgb, weights.zxy), - dot(color.rgb, weights.yzx)); + // spin + rgb = vec3( + dot(rgb, u_spin_weights.xyz), + dot(rgb, u_spin_weights.zxy), + dot(rgb, u_spin_weights.yzx)); + // saturation float average = (color.r + color.g + color.b) / 3.0; + rgb += (average - rgb) * u_saturation_factor; - if (u_saturation > 0.0) { - color.rgb += (average - color.rgb) * (1.0 - 1.0 / (1.001 - u_saturation)); - } else { - color.rgb += (average - color.rgb) * (-u_saturation); - } - - if (u_contrast > 0.0) { - color.rgb = (color.rgb - 0.5) / (1.0 - u_contrast) + 0.5; - } else { - color.rgb = (color.rgb - 0.5) * (1.0 + u_contrast) + 0.5; - } - - gl_FragColor = vec4( - mix( - u_high_vec, - u_low_vec, - color.rgb - ), color.a); + // contrast + rgb = (rgb - 0.5) * u_contrast_factor + 0.5; + + // brightness + vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); + vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); + gl_FragColor = vec4(mix(u_high_vec, u_low_vec, rgb), color.a); } diff --git a/raster.vertex.glsl b/raster.vertex.glsl index d719d34d0e4..3fa8da697c7 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,9 +1,6 @@ precision mediump float; uniform mat4 u_posmatrix; -uniform float u_brightness_low; -uniform float u_brightness_high; -uniform float u_spin; uniform vec2 u_tl_parent; uniform float u_scale_parent; @@ -13,7 +10,7 @@ varying vec2 v_pos0; varying vec2 v_pos1; void main(void) { - gl_Position = u_posmatrix * vec4(a_pos, step(32767.0, a_pos.x), 1); + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); v_pos0 = a_pos / 4096.0; v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } From 1b75abb18b8525d61f78a5eff6952bcf7a488a34 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 9 May 2014 01:04:19 -0400 Subject: [PATCH 044/259] let raster tiles fade in over background --- raster.fragment.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 563b7c7e029..1c8c98243ac 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -1,6 +1,7 @@ precision mediump float; -uniform float u_mix; +uniform float u_opacity0; +uniform float u_opacity1; uniform sampler2D u_image0; uniform sampler2D u_image1; varying vec2 v_pos0; @@ -18,7 +19,7 @@ void main() { // read and cross-fade colors from the main and parent tiles vec4 color0 = texture2D(u_image0, v_pos0); vec4 color1 = texture2D(u_image1, v_pos1); - vec4 color = mix(color1, color0, u_mix); + vec4 color = color0 * u_opacity0 + color1 * u_opacity1; vec3 rgb = color.rgb; // spin From a888306e6f4481bff9d21a440ab3a415b2430b48 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 9 May 2014 14:28:04 -0400 Subject: [PATCH 045/259] move calculation from frag to vertex shader --- composite.fragment.glsl | 2 +- composite.vertex.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composite.fragment.glsl b/composite.fragment.glsl index d29cb978333..f341687206f 100644 --- a/composite.fragment.glsl +++ b/composite.fragment.glsl @@ -6,5 +6,5 @@ uniform float u_opacity; varying vec2 v_pos; void main() { - gl_FragColor = texture2D(u_image, v_pos / 2.0 + 0.5) * u_opacity; + gl_FragColor = texture2D(u_image, v_pos) * u_opacity; } diff --git a/composite.vertex.glsl b/composite.vertex.glsl index 9ba6173f02d..63641ebd42e 100644 --- a/composite.vertex.glsl +++ b/composite.vertex.glsl @@ -5,5 +5,5 @@ varying vec2 v_pos; void main() { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - v_pos = gl_Position.xy; + v_pos = gl_Position.xy / 2.0 + 0.5; } From f8038f6e1d3e281edf45004b994171212ef29ad2 Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Tue, 3 Jun 2014 16:29:30 -0400 Subject: [PATCH 046/259] Refactoring to get sprite json accessible from workertile and icon positions passed through as varying per feature. --- point.fragment.glsl | 6 +++--- point.vertex.glsl | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/point.fragment.glsl b/point.fragment.glsl index 45da978c941..eac9811c0bf 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -2,12 +2,12 @@ precision mediump float; uniform sampler2D u_image; -uniform vec2 u_tl; -uniform vec2 u_br; uniform vec4 u_color; uniform bool u_invert; varying mat2 v_rotationmatrix; +varying vec2 v_tl; +varying vec2 v_br; void main(void) { vec2 pos = v_rotationmatrix * (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5; @@ -15,7 +15,7 @@ void main(void) { float inbounds = step(0.0, pos.x) * step(0.0, pos.y) * (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y)); - vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds; + vec4 color = texture2D(u_image, mix(v_tl, v_br, pos)) * inbounds; if (u_invert) { color.rgb = 1.0 - color.rgb; } diff --git a/point.vertex.glsl b/point.vertex.glsl index 3252515e4c5..b97146d117e 100644 --- a/point.vertex.glsl +++ b/point.vertex.glsl @@ -5,20 +5,24 @@ precision mediump float; #define PI 3.1415926535897932384626 uniform mat4 u_posmatrix; -uniform vec2 u_size; uniform mat2 u_rotationmatrix; uniform float u_zoom; attribute vec2 a_pos; +attribute vec2 a_size; +attribute vec2 a_tl; +attribute vec2 a_br; attribute float a_angle; attribute float a_minzoom; varying mat2 v_rotationmatrix; +varying vec2 v_tl; +varying vec2 v_br; void main(void) { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - gl_PointSize = u_size.x * root2; + gl_PointSize = a_size.x * root2; // if u_zoom < a_minzoom hide this point gl_Position.z += 1.0 - step(a_minzoom, u_zoom); @@ -29,4 +33,7 @@ void main(void) { cos(angle), -sin(angle), sin(angle), cos(angle) ) * u_rotationmatrix; + + v_tl = a_tl; + v_br = a_br; } From 46fafbecfae063815468205a24288c80b154c198 Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Tue, 3 Jun 2014 19:13:33 -0400 Subject: [PATCH 047/259] Get fixed icons back to working. --- point.vertex.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/point.vertex.glsl b/point.vertex.glsl index b97146d117e..3c272416d90 100644 --- a/point.vertex.glsl +++ b/point.vertex.glsl @@ -7,6 +7,7 @@ precision mediump float; uniform mat4 u_posmatrix; uniform mat2 u_rotationmatrix; uniform float u_zoom; +uniform vec2 u_texsize; attribute vec2 a_pos; attribute vec2 a_size; @@ -34,6 +35,6 @@ void main(void) { sin(angle), cos(angle) ) * u_rotationmatrix; - v_tl = a_tl; - v_br = a_br; + v_tl = a_tl/u_texsize; + v_br = a_br/u_texsize; } From 3390d0af5f2def48f31b132e570deb3984e21a0e Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Wed, 4 Jun 2014 11:19:16 -0400 Subject: [PATCH 048/259] Revert size from varying to uniform and use bucket info for point-image and point-size. --- point.vertex.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point.vertex.glsl b/point.vertex.glsl index 3c272416d90..431cea46b08 100644 --- a/point.vertex.glsl +++ b/point.vertex.glsl @@ -5,12 +5,12 @@ precision mediump float; #define PI 3.1415926535897932384626 uniform mat4 u_posmatrix; +uniform vec2 u_size; uniform mat2 u_rotationmatrix; uniform float u_zoom; uniform vec2 u_texsize; attribute vec2 a_pos; -attribute vec2 a_size; attribute vec2 a_tl; attribute vec2 a_br; attribute float a_angle; @@ -23,7 +23,7 @@ varying vec2 v_br; void main(void) { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - gl_PointSize = a_size.x * root2; + gl_PointSize = u_size.x * root2; // if u_zoom < a_minzoom hide this point gl_Position.z += 1.0 - step(a_minzoom, u_zoom); From 8372642990b89296853000815f02833aedb131d8 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 4 Jun 2014 23:56:10 +0300 Subject: [PATCH 049/259] make point-opacity work for icons --- point.fragment.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/point.fragment.glsl b/point.fragment.glsl index eac9811c0bf..9fbde01ea25 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -21,7 +21,7 @@ void main(void) { } if (u_color.a > 0.0) { - gl_FragColor = u_color * color.a; + gl_FragColor = u_color * color; } else { gl_FragColor = vec4(color.rgb * color.a, color.a); } From 29fd67f8960e88f2aa48b40cf50e0b1d7992a581 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 5 Jun 2014 00:06:29 +0300 Subject: [PATCH 050/259] simplify point shader --- point.fragment.glsl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/point.fragment.glsl b/point.fragment.glsl index 9fbde01ea25..d127194f8b4 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -20,9 +20,5 @@ void main(void) { color.rgb = 1.0 - color.rgb; } - if (u_color.a > 0.0) { - gl_FragColor = u_color * color; - } else { - gl_FragColor = vec4(color.rgb * color.a, color.a); - } + gl_FragColor = u_color * color; } From 8b73747c0c047bae9b923d5bdd116d671b1c49cd Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 5 Jun 2014 00:16:39 +0300 Subject: [PATCH 051/259] premultiply icon colors --- point.fragment.glsl | 1 + 1 file changed, 1 insertion(+) diff --git a/point.fragment.glsl b/point.fragment.glsl index d127194f8b4..05916478156 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -20,5 +20,6 @@ void main(void) { color.rgb = 1.0 - color.rgb; } + color.rgb *= color.a; gl_FragColor = u_color * color; } From 2869787959c0ff667fb4a0ffde8ab5ed03dad45d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Jun 2014 16:53:49 -0400 Subject: [PATCH 052/259] add video source Example options used to create a video source: { type: 'video', url: 'http://mapbox.s3.amazonaws.com/llmr-demo/aleppo.mp4', coordinates: [ [37.17021346092223, 36.20638184589834], [37.18670368194580, 36.20444264512721], [37.18577027320862, 36.19716155628325], [37.16894745826721, 36.19928275195264] ] } Create a video bucket with { filter: { type: video } } --- raster.vertex.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 3fa8da697c7..d2fabeddcf0 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -5,12 +5,13 @@ uniform vec2 u_tl_parent; uniform float u_scale_parent; attribute vec2 a_pos; +attribute vec2 a_texture_pos; varying vec2 v_pos0; varying vec2 v_pos1; void main(void) { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - v_pos0 = a_pos / 4096.0; + v_pos0 = a_texture_pos / 32767.0; v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } From aa8d40457375e524c05e55459195d376d48bfa43 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 20 Jun 2014 14:14:02 -0700 Subject: [PATCH 053/259] fix line patterns --- linepattern.fragment.glsl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 47f7153a884..ad2fec7c65a 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -3,7 +3,6 @@ precision mediump float; // shared uniform float u_debug; uniform vec2 u_linewidth; -uniform vec4 u_color; uniform float u_point; uniform float u_gamma; @@ -36,9 +35,7 @@ void main() { vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); - gl_FragColor = color * u_color.a * alpha; + color.rgb *= color.a; // premultiply - if (u_debug > 0.0) { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - } + gl_FragColor = color * alpha; } From ae5f9cbc9f094b66100b647fbf99ab9b0f531c79 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sun, 22 Jun 2014 16:17:33 -0700 Subject: [PATCH 054/259] fix drawing patterned backgrounds --- pattern.fragment.glsl | 4 +--- pattern.vertex.glsl | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index 4ae6ce443f8..ea0f253b9aa 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -2,8 +2,6 @@ precision mediump float; uniform vec4 u_color; -uniform vec2 u_offset; -uniform vec2 u_pattern_size; uniform vec2 u_pattern_tl; uniform vec2 u_pattern_br; uniform float u_mix; @@ -15,7 +13,7 @@ varying vec2 v_pos; void main() { - vec2 imagecoord = mod((v_pos + u_offset) / u_pattern_size, 1.0); + vec2 imagecoord = mod(v_pos, 1.0); vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); vec4 color1 = texture2D(u_image, pos); diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 4c4c7cffdbb..bf863a68e99 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,12 +1,13 @@ precision mediump float; uniform mat4 u_posmatrix; +uniform mat3 u_patternmatrix; attribute vec2 a_pos; varying vec2 v_pos; void main() { - v_pos = a_pos; gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + v_pos = (u_patternmatrix * vec3(a_pos, 1)).xy; } From bac25d2259a9b4303e78892a0f295249891310f5 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 24 Jun 2014 19:22:10 -0700 Subject: [PATCH 055/259] prepare for drawing text and icons similarly --- icon.fragment.glsl | 11 +++++++ icon.vertex.glsl | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 icon.fragment.glsl create mode 100644 icon.vertex.glsl diff --git a/icon.fragment.glsl b/icon.fragment.glsl new file mode 100644 index 00000000000..72d639a0040 --- /dev/null +++ b/icon.fragment.glsl @@ -0,0 +1,11 @@ +precision mediump float; + +uniform sampler2D u_texture; + +varying vec2 v_tex; +varying float v_alpha; + +void main() { + gl_FragColor = texture2D(u_texture, v_tex); + gl_FragColor.rgb *= gl_FragColor.a; +} diff --git a/icon.vertex.glsl b/icon.vertex.glsl new file mode 100644 index 00000000000..647b17226b5 --- /dev/null +++ b/icon.vertex.glsl @@ -0,0 +1,72 @@ +precision mediump float; + +attribute vec2 a_pos; +attribute vec2 a_offset; +attribute vec2 a_tex; +attribute float a_angle; +attribute float a_minzoom; +attribute float a_maxzoom; +attribute float a_rangeend; +attribute float a_rangestart; +attribute float a_labelminzoom; + + +// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_posmatrix; +uniform mat4 u_exmatrix; +uniform float u_angle; +uniform float u_zoom; +uniform float u_flip; +uniform float u_fadedist; +uniform float u_minfadezoom; +uniform float u_maxfadezoom; +uniform float u_fadezoom; + +uniform vec2 u_texsize; + +varying vec2 v_tex; +varying float v_alpha; + +void main() { + + float a_fadedist = 10.0; + float rev = 0.0; + + // u_angle is angle of the map, -128..128 representing 0..2PI + // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text + float rotated = mod(a_angle + u_angle, 256.0); + // if the label rotates with the map, and if the rotated label is upside down, hide it + if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; + + // If the label should be invisible, we move the vertex outside + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + // u_zoom is the current zoom level adjusted for the change in font size + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + + // fade out labels + float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); + + if (u_fadedist >= 0.0) { + v_alpha = alpha; + } else { + v_alpha = 1.0 - alpha; + } + if (u_maxfadezoom < a_labelminzoom) { + v_alpha = 0.0; + } + if (u_minfadezoom >= a_labelminzoom) { + v_alpha = 1.0; + } + + // if label has been faded out, clip it + z += step(v_alpha, 0.0); + + // all the angles are 0..256 representing 0..2PI + // hide if (angle >= a_rangeend && angle < rangestart) + z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); + + gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + v_tex = a_tex * 4.0 / u_texsize; +} From 035097450fe430dd7ed9fc1258d55404c094ed4b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 25 Jun 2014 17:03:12 -0700 Subject: [PATCH 056/259] draw icons the way glyphs are drawn --- icon.fragment.glsl | 1 + icon.vertex.glsl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/icon.fragment.glsl b/icon.fragment.glsl index 72d639a0040..22b9f08bf0e 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -7,5 +7,6 @@ varying float v_alpha; void main() { gl_FragColor = texture2D(u_texture, v_tex); + gl_FragColor.a *= v_alpha; gl_FragColor.rgb *= gl_FragColor.a; } diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 647b17226b5..9347114245e 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -68,5 +68,5 @@ void main() { z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); - v_tex = a_tex * 4.0 / u_texsize; + v_tex = a_tex * 1.0 / u_texsize; } From 522bd1fe3fce3e91c9ff4951a756aa08b331fdc2 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 9 Jul 2014 15:33:47 -0700 Subject: [PATCH 057/259] implement sdf icons --- icon.vertex.glsl | 2 +- sdf.vertex.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 9347114245e..5a21c507281 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -68,5 +68,5 @@ void main() { z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); - v_tex = a_tex * 1.0 / u_texsize; + v_tex = a_tex / u_texsize; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 647b17226b5..5a21c507281 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -68,5 +68,5 @@ void main() { z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); - v_tex = a_tex * 4.0 / u_texsize; + v_tex = a_tex / u_texsize; } From f88584a24edeb121c68ef274dbafd36379737e8c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 10 Jul 2014 11:13:03 -0700 Subject: [PATCH 058/259] fix pattern premultiplication and scaling --- pattern.fragment.glsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index ea0f253b9aa..ecfdb7867d8 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -1,12 +1,9 @@ precision mediump float; -uniform vec4 u_color; - uniform vec2 u_pattern_tl; uniform vec2 u_pattern_br; uniform float u_mix; - uniform sampler2D u_image; varying vec2 v_pos; @@ -22,5 +19,6 @@ void main() { vec4 color2 = texture2D(u_image, pos2); vec4 color = mix(color1, color2, u_mix); - gl_FragColor = color + u_color * (1.0 - color.a); + color.rgb *= color.a; + gl_FragColor = color; } From 4c0169150f715ff58f426261cbd2ca41307cb1e4 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 10 Jul 2014 11:31:47 -0700 Subject: [PATCH 059/259] implement opacity for fill patterns, fix #528 --- pattern.fragment.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index ecfdb7867d8..db49688115a 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -1,5 +1,6 @@ precision mediump float; +uniform float u_opacity; uniform vec2 u_pattern_tl; uniform vec2 u_pattern_br; uniform float u_mix; @@ -18,7 +19,7 @@ void main() { vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); vec4 color2 = texture2D(u_image, pos2); - vec4 color = mix(color1, color2, u_mix); + vec4 color = mix(color1, color2, u_mix) * u_opacity; color.rgb *= color.a; gl_FragColor = color; } From eff1594d0e8925717884aa5e7584dc8098da0df2 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 10 Jul 2014 16:14:58 -0700 Subject: [PATCH 060/259] fix opacity in pattern shader --- pattern.fragment.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index db49688115a..4cb45263872 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -19,7 +19,8 @@ void main() { vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); vec4 color2 = texture2D(u_image, pos2); - vec4 color = mix(color1, color2, u_mix) * u_opacity; + vec4 color = mix(color1, color2, u_mix); + color.a *= u_opacity; color.rgb *= color.a; gl_FragColor = color; } From ded34b583eb59fb44e1fc566637c0908793ba6bd Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 10 Jul 2014 15:23:48 -0700 Subject: [PATCH 061/259] Reboot headless rendering --- composite.fragment.glsl | 2 -- debug.fragment.glsl | 2 -- debug.vertex.glsl | 2 -- dot.fragment.glsl | 6 ++---- dot.vertex.glsl | 2 -- fill.fragment.glsl | 2 -- fill.vertex.glsl | 2 -- icon.fragment.glsl | 2 -- icon.vertex.glsl | 2 -- label.fragment.glsl | 2 -- label.vertex.glsl | 2 -- line.fragment.glsl | 2 -- line.vertex.glsl | 1 - linepattern.fragment.glsl | 2 -- linepattern.vertex.glsl | 1 - outline.fragment.glsl | 2 -- outline.vertex.glsl | 2 -- pattern.fragment.glsl | 2 -- pattern.vertex.glsl | 2 -- point.fragment.glsl | 1 - point.vertex.glsl | 2 -- raster.fragment.glsl | 2 -- raster.vertex.glsl | 2 -- sdf.fragment.glsl | 2 -- sdf.vertex.glsl | 2 -- 25 files changed, 2 insertions(+), 49 deletions(-) diff --git a/composite.fragment.glsl b/composite.fragment.glsl index f341687206f..feb0a58f075 100644 --- a/composite.fragment.glsl +++ b/composite.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform sampler2D u_image; uniform float u_opacity; diff --git a/debug.fragment.glsl b/debug.fragment.glsl index f21d7dd6ebb..8df552c1718 100644 --- a/debug.fragment.glsl +++ b/debug.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform vec4 u_color; void main() { diff --git a/debug.vertex.glsl b/debug.vertex.glsl index e1440923333..674e5e5d2b3 100644 --- a/debug.vertex.glsl +++ b/debug.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - attribute vec2 a_pos; uniform float u_pointsize; diff --git a/dot.fragment.glsl b/dot.fragment.glsl index 1feefca75b3..6d998b5611f 100644 --- a/dot.fragment.glsl +++ b/dot.fragment.glsl @@ -1,11 +1,9 @@ -precision mediump float; - uniform vec4 u_color; uniform float u_blur; void main() { - float dist = length(gl_PointCoord - 0.5); - float t = smoothstep(0.5, 0.5 - u_blur, dist); + float dist = length(gl_PointCoord - 0.5); + float t = smoothstep(0.5, 0.5 - u_blur, dist); gl_FragColor = u_color * t; } diff --git a/dot.vertex.glsl b/dot.vertex.glsl index d71dae5e5a2..0d686dc6d3a 100644 --- a/dot.vertex.glsl +++ b/dot.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform mat4 u_posmatrix; uniform float u_size; diff --git a/fill.fragment.glsl b/fill.fragment.glsl index f21d7dd6ebb..8df552c1718 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform vec4 u_color; void main() { diff --git a/fill.vertex.glsl b/fill.vertex.glsl index ee737f69ba6..ca7570254e7 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - attribute vec2 a_pos; uniform mat4 u_posmatrix; diff --git a/icon.fragment.glsl b/icon.fragment.glsl index 22b9f08bf0e..beaee7654ec 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform sampler2D u_texture; varying vec2 v_tex; diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 5a21c507281..30a15a566f2 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - attribute vec2 a_pos; attribute vec2 a_offset; attribute vec2 a_tex; diff --git a/label.fragment.glsl b/label.fragment.glsl index ceefcf207dc..385189c4b31 100644 --- a/label.fragment.glsl +++ b/label.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform sampler2D u_sampler; uniform vec4 u_color; varying vec2 v_tex; diff --git a/label.vertex.glsl b/label.vertex.glsl index 7beda4de3a6..06059ac127d 100644 --- a/label.vertex.glsl +++ b/label.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - attribute vec2 a_pos; attribute vec2 a_offset; attribute vec2 a_tex; diff --git a/line.fragment.glsl b/line.fragment.glsl index 31c2c23a1ba..41421981340 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - // shared uniform float u_debug; uniform vec2 u_linewidth; diff --git a/line.vertex.glsl b/line.vertex.glsl index fc6e15d6676..cb3888452b9 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -1,5 +1,4 @@ // these are the shaders for rendering antialiased lines -precision mediump float; // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index ad2fec7c65a..df9428b5209 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - // shared uniform float u_debug; uniform vec2 u_linewidth; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 8f99b5ac1bd..476916b1cab 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -1,5 +1,4 @@ // these are the shaders for rendering antialiased lines -precision mediump float; // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is diff --git a/outline.fragment.glsl b/outline.fragment.glsl index f7e5fda9a38..eccda714e52 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform vec4 u_color; varying vec2 v_pos; diff --git a/outline.vertex.glsl b/outline.vertex.glsl index 43194b92326..e5948768049 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - attribute vec2 a_pos; uniform mat4 u_posmatrix; uniform vec2 u_world; diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index 4cb45263872..3dc625b0475 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform float u_opacity; uniform vec2 u_pattern_tl; uniform vec2 u_pattern_br; diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index bf863a68e99..2f9e9018c7d 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform mat4 u_posmatrix; uniform mat3 u_patternmatrix; diff --git a/point.fragment.glsl b/point.fragment.glsl index 05916478156..ff79dfe0191 100644 --- a/point.fragment.glsl +++ b/point.fragment.glsl @@ -1,5 +1,4 @@ #define root2 1.42 -precision mediump float; uniform sampler2D u_image; uniform vec4 u_color; diff --git a/point.vertex.glsl b/point.vertex.glsl index 431cea46b08..5e4373319ae 100644 --- a/point.vertex.glsl +++ b/point.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - #define scale 63.0 #define root2 1.42 #define PI 3.1415926535897932384626 diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 1c8c98243ac..2e4750b3e14 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform float u_opacity0; uniform float u_opacity1; uniform sampler2D u_image0; diff --git a/raster.vertex.glsl b/raster.vertex.glsl index d2fabeddcf0..d2d89ec77c5 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform mat4 u_posmatrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index 595437a2136..d72d61dab19 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,5 +1,3 @@ -precision mediump float; - uniform sampler2D u_texture; uniform vec4 u_color; uniform float u_buffer; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 5a21c507281..30a15a566f2 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -1,5 +1,3 @@ -precision mediump float; - attribute vec2 a_pos; attribute vec2 a_offset; attribute vec2 a_tex; From 407065171c4253e451f03bcacf12d2572550415b Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Wed, 16 Jul 2014 18:38:55 -0700 Subject: [PATCH 062/259] recreate texturerender branch --- gaussian.fragment.glsl | 13 +++++++++++++ gaussian.vertex.glsl | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gaussian.fragment.glsl create mode 100644 gaussian.vertex.glsl diff --git a/gaussian.fragment.glsl b/gaussian.fragment.glsl new file mode 100644 index 00000000000..9f839581916 --- /dev/null +++ b/gaussian.fragment.glsl @@ -0,0 +1,13 @@ +uniform sampler2D u_image; +uniform float u_opacity; + +varying vec2 v_pos; +varying vec2 v_coords[3]; + +void main() { + vec4 sum = vec4(0.0); + sum += texture2D(u_image, v_coords[0]) * 0.40261994689424746; + sum += texture2D(u_image, v_coords[1]) * 0.2986900265528763; + sum += texture2D(u_image, v_coords[2]) * 0.2986900265528763; + gl_FragColor = sum; +} diff --git a/gaussian.vertex.glsl b/gaussian.vertex.glsl new file mode 100644 index 00000000000..c833249316d --- /dev/null +++ b/gaussian.vertex.glsl @@ -0,0 +1,15 @@ +attribute vec2 a_pos; + +uniform mat4 u_posmatrix; +uniform vec2 u_offset; +varying vec2 v_pos; +varying vec2 v_coords[3]; + +void main() { + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + vec2 tex = gl_Position.xy / 2.0 + 0.5; + + v_coords[0] = tex; + v_coords[1] = tex + u_offset * 1.1824255238063563; + v_coords[2] = tex - u_offset * 1.1824255238063563; +} From 17ff9a1f47ee2c6d0a49a0b8de53049961ebb5c1 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 17 Jul 2014 14:57:17 -0700 Subject: [PATCH 063/259] fix pattern premultiplication fixes #69 --- pattern.fragment.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index 3dc625b0475..a3dc9edfccd 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -12,13 +12,14 @@ void main() { vec2 imagecoord = mod(v_pos, 1.0); vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); vec4 color1 = texture2D(u_image, pos); + color1.rgb *= color1.a; vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); vec4 color2 = texture2D(u_image, pos2); + color2.rgb *= color2.a; vec4 color = mix(color1, color2, u_mix); - color.a *= u_opacity; - color.rgb *= color.a; + color *= u_opacity; gl_FragColor = color; } From 08fe66f2be3f335412bda4fbd9b99b26e830e808 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 18 Jul 2014 16:13:59 -0700 Subject: [PATCH 064/259] introduced u_buffer_scale but prerendered raster tiles still not seamless --- raster.vertex.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/raster.vertex.glsl b/raster.vertex.glsl index d2d89ec77c5..55476cc0e0e 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,6 +1,7 @@ uniform mat4 u_posmatrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; +uniform float u_buffer_scale; attribute vec2 a_pos; attribute vec2 a_texture_pos; @@ -10,6 +11,6 @@ varying vec2 v_pos1; void main(void) { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - v_pos0 = a_texture_pos / 32767.0; + v_pos0 = (((a_texture_pos / 32767.0) - 0.5) * u_buffer_scale ) + 0.5; v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } From 80e402efc2779e7dcfce8d18f1f3dd0e2c4f9c95 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sat, 19 Jul 2014 13:16:57 -0700 Subject: [PATCH 065/259] remove unused shader --- label.fragment.glsl | 8 -------- label.vertex.glsl | 15 --------------- 2 files changed, 23 deletions(-) delete mode 100644 label.fragment.glsl delete mode 100644 label.vertex.glsl diff --git a/label.fragment.glsl b/label.fragment.glsl deleted file mode 100644 index 385189c4b31..00000000000 --- a/label.fragment.glsl +++ /dev/null @@ -1,8 +0,0 @@ -uniform sampler2D u_sampler; -uniform vec4 u_color; -varying vec2 v_tex; - -void main() { - vec4 c = texture2D(u_sampler, v_tex); - gl_FragColor = vec4(u_color.r, u_color.g, u_color.b, u_color.a * c.a); -} diff --git a/label.vertex.glsl b/label.vertex.glsl deleted file mode 100644 index 06059ac127d..00000000000 --- a/label.vertex.glsl +++ /dev/null @@ -1,15 +0,0 @@ -attribute vec2 a_pos; -attribute vec2 a_offset; -attribute vec2 a_tex; - -uniform vec2 u_texsize; -uniform mat4 u_posmatrix; -uniform mat4 u_resizematrix; - -varying vec2 v_tex; - -void main() { - vec2 a = a_offset; - gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_resizematrix * vec4(a_offset, 0, 1); - v_tex = a_tex / u_texsize; -} From 504fcf2becf1e94df851e4d71f31027e92c1500d Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Mon, 21 Jul 2014 13:14:51 -0700 Subject: [PATCH 066/259] omg this works --- raster.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 55476cc0e0e..9726f7360c1 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -11,6 +11,6 @@ varying vec2 v_pos1; void main(void) { gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - v_pos0 = (((a_texture_pos / 32767.0) - 0.5) * u_buffer_scale ) + 0.5; + v_pos0 = (((a_texture_pos / 32767.0) - 0.5) / u_buffer_scale ) + 0.5; v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } From 625380cfcc1eb754b6f532537abe1808f29f0fed Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 22 Jul 2014 18:56:17 -0700 Subject: [PATCH 067/259] add support for icon-opacity, fixes #599 --- icon.vertex.glsl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 30a15a566f2..d273b733d76 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -20,6 +20,7 @@ uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; +uniform float u_opacity; uniform vec2 u_texsize; @@ -67,4 +68,6 @@ void main() { gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; + + v_alpha *= u_opacity; } From 715e99df1cf53fedf91e8da222cbb346f0491b8b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 25 Jul 2014 12:17:42 -0700 Subject: [PATCH 068/259] `line-blur` isn't affected by devicePixelRatio now fixes #615 --- line.fragment.glsl | 3 +-- linepattern.fragment.glsl | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 41421981340..3cdbb6ca86a 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -2,7 +2,6 @@ uniform float u_debug; uniform vec2 u_linewidth; uniform vec4 u_color; -uniform float u_gamma; uniform float u_blur; uniform vec2 u_dasharray; @@ -20,7 +19,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp((min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur) * u_gamma, 0.0, 1.0); + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); // Calculate the antialiasing fade factor based on distance to the dash. // Only affects alpha when line is dashed diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index df9428b5209..68d016b21f8 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -2,7 +2,7 @@ uniform float u_debug; uniform vec2 u_linewidth; uniform float u_point; -uniform float u_gamma; +uniform float u_blur; uniform vec2 u_pattern_size; uniform vec2 u_pattern_tl; @@ -23,7 +23,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist) * u_gamma, 0.0, 1.0); + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); float x = mod(v_linesofar / u_pattern_size.x, 1.0); float y = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size.y); From 8909898f6a80f876e648aaee9f652b5b2ad11dc9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 4 Aug 2014 13:49:56 -0700 Subject: [PATCH 069/259] premultiply sprite Fixes #624 Previously colors were premultiplied in the shader. Texture reads would interpolate the color before the premultiplication. Since completely transparent pixels could have any rgb values (often 0, 0, 0), the interpolation would bleed this value into pixels. For example if rgba(255, 0, 0, 1) was next to rgba(0, 0, 0, 0) then the interpolated value would be (127, 0, 0, 0.5) instead of (255, 0, 0, 0.5). Premultiplying before the interpolation solves this. Premultiplying the sprite also means a bit less work needs to be done in the fragment shader. --- icon.fragment.glsl | 4 +--- pattern.fragment.glsl | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/icon.fragment.glsl b/icon.fragment.glsl index beaee7654ec..45b56793eba 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -4,7 +4,5 @@ varying vec2 v_tex; varying float v_alpha; void main() { - gl_FragColor = texture2D(u_texture, v_tex); - gl_FragColor.a *= v_alpha; - gl_FragColor.rgb *= gl_FragColor.a; + gl_FragColor = texture2D(u_texture, v_tex) * v_alpha; } diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index a3dc9edfccd..ba6aed30239 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -12,14 +12,10 @@ void main() { vec2 imagecoord = mod(v_pos, 1.0); vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); vec4 color1 = texture2D(u_image, pos); - color1.rgb *= color1.a; vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); vec4 color2 = texture2D(u_image, pos2); - color2.rgb *= color2.a; - vec4 color = mix(color1, color2, u_mix); - color *= u_opacity; - gl_FragColor = color; + gl_FragColor = mix(color1, color2, u_mix) * u_opacity; } From 8e154d1e66657d18128d63052c9bb0271c437b07 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 7 Aug 2014 11:18:17 -0700 Subject: [PATCH 070/259] remove unused pointShader --- point.fragment.glsl | 24 ------------------------ point.vertex.glsl | 38 -------------------------------------- 2 files changed, 62 deletions(-) delete mode 100644 point.fragment.glsl delete mode 100644 point.vertex.glsl diff --git a/point.fragment.glsl b/point.fragment.glsl deleted file mode 100644 index ff79dfe0191..00000000000 --- a/point.fragment.glsl +++ /dev/null @@ -1,24 +0,0 @@ -#define root2 1.42 - -uniform sampler2D u_image; -uniform vec4 u_color; -uniform bool u_invert; - -varying mat2 v_rotationmatrix; -varying vec2 v_tl; -varying vec2 v_br; - -void main(void) { - vec2 pos = v_rotationmatrix * (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5; - - float inbounds = step(0.0, pos.x) * step(0.0, pos.y) * - (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y)); - - vec4 color = texture2D(u_image, mix(v_tl, v_br, pos)) * inbounds; - if (u_invert) { - color.rgb = 1.0 - color.rgb; - } - - color.rgb *= color.a; - gl_FragColor = u_color * color; -} diff --git a/point.vertex.glsl b/point.vertex.glsl deleted file mode 100644 index 5e4373319ae..00000000000 --- a/point.vertex.glsl +++ /dev/null @@ -1,38 +0,0 @@ -#define scale 63.0 -#define root2 1.42 -#define PI 3.1415926535897932384626 - -uniform mat4 u_posmatrix; -uniform vec2 u_size; -uniform mat2 u_rotationmatrix; -uniform float u_zoom; -uniform vec2 u_texsize; - -attribute vec2 a_pos; -attribute vec2 a_tl; -attribute vec2 a_br; -attribute float a_angle; -attribute float a_minzoom; - -varying mat2 v_rotationmatrix; -varying vec2 v_tl; -varying vec2 v_br; - -void main(void) { - - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - gl_PointSize = u_size.x * root2; - - // if u_zoom < a_minzoom hide this point - gl_Position.z += 1.0 - step(a_minzoom, u_zoom); - - float angle = a_angle * 2.0 * PI / 256.0; - - v_rotationmatrix = mat2( - cos(angle), -sin(angle), - sin(angle), cos(angle) - ) * u_rotationmatrix; - - v_tl = a_tl/u_texsize; - v_br = a_br/u_texsize; -} From 89eebe4e173a9abc7e4c88dcb49030af4be1cc9a Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 8 Aug 2014 17:11:54 -0700 Subject: [PATCH 071/259] draw fill antialiasing with indexed lines fixes #668 --- outline.vertex.glsl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/outline.vertex.glsl b/outline.vertex.glsl index e5948768049..c4e4bb630ee 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -5,10 +5,6 @@ uniform vec2 u_world; varying vec2 v_pos; void main() { - // If the x coordinate is the maximum integer, we move the z coordinates out - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. - float z = step(32767.0, a_pos.x); - gl_Position = u_posmatrix * vec4(a_pos, z, 1); + gl_Position = u_posmatrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world; } From e53dd6099f383d74c2d243e637f60ac855857b03 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 29 Aug 2014 15:22:30 -0700 Subject: [PATCH 072/259] Remove u_debug from shaders --- line.fragment.glsl | 6 ------ line.vertex.glsl | 3 --- linepattern.fragment.glsl | 2 -- linepattern.vertex.glsl | 3 --- 4 files changed, 14 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 3cdbb6ca86a..74dca327ae4 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,5 +1,3 @@ -// shared -uniform float u_debug; uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_blur; @@ -27,8 +25,4 @@ void main() { alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0)); gl_FragColor = u_color * alpha; - - if (u_debug > 0.0) { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - } } diff --git a/line.vertex.glsl b/line.vertex.glsl index cb3888452b9..205aa759fe2 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -16,9 +16,6 @@ attribute float a_linesofar; uniform mat4 u_posmatrix; uniform mat4 u_exmatrix; - -uniform float u_debug; - // shared uniform float u_ratio; uniform vec2 u_linewidth; diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 68d016b21f8..52ca823a3b6 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,5 +1,3 @@ -// shared -uniform float u_debug; uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 476916b1cab..ecfdfaf5849 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -16,9 +16,6 @@ attribute float a_linesofar; uniform mat4 u_posmatrix; uniform mat4 u_exmatrix; - -uniform float u_debug; - // shared uniform float u_ratio; uniform vec2 u_linewidth; From 1f012579e99d2a02fb649963a970bfd701e29155 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 29 Aug 2014 15:31:18 -0700 Subject: [PATCH 073/259] Remove inaccurate comment --- linepattern.vertex.glsl | 2 -- 1 file changed, 2 deletions(-) diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index ecfdfaf5849..ec48b2f6d9b 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -1,5 +1,3 @@ -// these are the shaders for rendering antialiased lines - // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but From 3536b438168e11bd6b3cb0f1190da71cd425f0dd Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Sep 2014 11:19:58 -0700 Subject: [PATCH 074/259] Remove composite shader --- composite.fragment.glsl | 8 -------- composite.vertex.glsl | 9 --------- 2 files changed, 17 deletions(-) delete mode 100644 composite.fragment.glsl delete mode 100644 composite.vertex.glsl diff --git a/composite.fragment.glsl b/composite.fragment.glsl deleted file mode 100644 index feb0a58f075..00000000000 --- a/composite.fragment.glsl +++ /dev/null @@ -1,8 +0,0 @@ -uniform sampler2D u_image; -uniform float u_opacity; - -varying vec2 v_pos; - -void main() { - gl_FragColor = texture2D(u_image, v_pos) * u_opacity; -} diff --git a/composite.vertex.glsl b/composite.vertex.glsl deleted file mode 100644 index 63641ebd42e..00000000000 --- a/composite.vertex.glsl +++ /dev/null @@ -1,9 +0,0 @@ -attribute vec2 a_pos; - -uniform mat4 u_posmatrix; -varying vec2 v_pos; - -void main() { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - v_pos = gl_Position.xy / 2.0 + 0.5; -} From bfdaa494844bfd28bbcc7ffc0f874f1e2449209f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Sep 2014 11:54:05 -0700 Subject: [PATCH 075/259] Match native shaders --- debug.vertex.glsl | 4 ++-- dot.vertex.glsl | 4 ++-- fill.vertex.glsl | 4 ++-- gaussian.fragment.glsl | 2 -- gaussian.vertex.glsl | 8 ++++---- icon.vertex.glsl | 6 +++--- line.fragment.glsl | 5 +---- line.vertex.glsl | 14 ++++++-------- linepattern.vertex.glsl | 6 +++--- outline.vertex.glsl | 4 ++-- pattern.vertex.glsl | 4 ++-- raster.fragment.glsl | 1 + raster.vertex.glsl | 6 +++--- sdf.vertex.glsl | 6 +++--- 14 files changed, 34 insertions(+), 40 deletions(-) diff --git a/debug.vertex.glsl b/debug.vertex.glsl index 674e5e5d2b3..869bcefc75c 100644 --- a/debug.vertex.glsl +++ b/debug.vertex.glsl @@ -1,9 +1,9 @@ attribute vec2 a_pos; uniform float u_pointsize; -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; void main() { - gl_Position = u_posmatrix * vec4(a_pos, step(32767.0, a_pos.x), 1); + gl_Position = u_matrix * vec4(a_pos, step(32767.0, a_pos.x), 1); gl_PointSize = u_pointsize; } diff --git a/dot.vertex.glsl b/dot.vertex.glsl index 0d686dc6d3a..5310ae745e0 100644 --- a/dot.vertex.glsl +++ b/dot.vertex.glsl @@ -1,9 +1,9 @@ -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform float u_size; attribute vec2 a_pos; void main(void) { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + gl_Position = u_matrix * vec4(a_pos, 0, 1); gl_PointSize = u_size; } diff --git a/fill.vertex.glsl b/fill.vertex.glsl index ca7570254e7..08c99981877 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,7 +1,7 @@ attribute vec2 a_pos; -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; void main() { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + gl_Position = u_matrix * vec4(a_pos, 0, 1); gl_PointSize = 2.0; } diff --git a/gaussian.fragment.glsl b/gaussian.fragment.glsl index 9f839581916..ee8406e9e11 100644 --- a/gaussian.fragment.glsl +++ b/gaussian.fragment.glsl @@ -1,7 +1,5 @@ uniform sampler2D u_image; -uniform float u_opacity; -varying vec2 v_pos; varying vec2 v_coords[3]; void main() { diff --git a/gaussian.vertex.glsl b/gaussian.vertex.glsl index c833249316d..26a83942046 100644 --- a/gaussian.vertex.glsl +++ b/gaussian.vertex.glsl @@ -1,14 +1,14 @@ attribute vec2 a_pos; -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform vec2 u_offset; -varying vec2 v_pos; + varying vec2 v_coords[3]; void main() { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); - vec2 tex = gl_Position.xy / 2.0 + 0.5; + gl_Position = u_matrix * vec4(a_pos, 0, 1); + vec2 tex = gl_Position.xy / 2.0 + 0.5; v_coords[0] = tex; v_coords[1] = tex + u_offset * 1.1824255238063563; v_coords[2] = tex - u_offset * 1.1824255238063563; diff --git a/icon.vertex.glsl b/icon.vertex.glsl index d273b733d76..8c69c404100 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -9,9 +9,9 @@ attribute float a_rangestart; attribute float a_labelminzoom; -// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_angle; uniform float u_zoom; @@ -66,7 +66,7 @@ void main() { // hide if (angle >= a_rangeend && angle < rangestart) z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; v_alpha *= u_opacity; diff --git a/line.fragment.glsl b/line.fragment.glsl index 74dca327ae4..f4ac1458b33 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -8,11 +8,8 @@ varying vec2 v_normal; varying float v_linesofar; void main() { - // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal); - - dist *= u_linewidth.s; + float dist = length(v_normal) * u_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out diff --git a/line.vertex.glsl b/line.vertex.glsl index 205aa759fe2..1d8e687c957 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -1,19 +1,18 @@ -// these are the shaders for rendering antialiased lines - // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but // there are also "special" normals that have a bigger length (of up to 126 in // this case). -#define scale 63.0 +// #define scale 63.0 +#define scale 0.015873016 attribute vec2 a_pos; attribute vec2 a_extrude; attribute float a_linesofar; -// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; // shared @@ -35,13 +34,12 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec2 extrude = a_extrude / scale; - vec2 dist = u_linewidth.s * extrude; + vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, 0.0, 0.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; v_linesofar = a_linesofar * u_ratio; } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index ec48b2f6d9b..4600ebf65b4 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -9,9 +9,9 @@ attribute vec2 a_pos; attribute vec2 a_extrude; attribute float a_linesofar; -// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; // shared @@ -49,7 +49,7 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); v_linesofar = a_linesofar;// * u_ratio; diff --git a/outline.vertex.glsl b/outline.vertex.glsl index c4e4bb630ee..29c16e3ded2 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,10 +1,10 @@ attribute vec2 a_pos; -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform vec2 u_world; varying vec2 v_pos; void main() { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world; } diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 2f9e9018c7d..f2de884eadb 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,4 +1,4 @@ -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform mat3 u_patternmatrix; attribute vec2 a_pos; @@ -6,6 +6,6 @@ attribute vec2 a_pos; varying vec2 v_pos; void main() { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (u_patternmatrix * vec3(a_pos, 1)).xy; } diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 2e4750b3e14..7a6c49acec2 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -36,5 +36,6 @@ void main() { // brightness vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); + gl_FragColor = vec4(mix(u_high_vec, u_low_vec, rgb), color.a); } diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 9726f7360c1..987212d88ff 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,4 +1,4 @@ -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; uniform float u_buffer_scale; @@ -9,8 +9,8 @@ attribute vec2 a_texture_pos; varying vec2 v_pos0; varying vec2 v_pos1; -void main(void) { - gl_Position = u_posmatrix * vec4(a_pos, 0, 1); +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos0 = (((a_texture_pos / 32767.0) - 0.5) / u_buffer_scale ) + 0.5; v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 30a15a566f2..a90cab1b83c 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -9,9 +9,9 @@ attribute float a_rangestart; attribute float a_labelminzoom; -// posmatrix is for the vertex position, exmatrix is for rotating and projecting +// matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_posmatrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_angle; uniform float u_zoom; @@ -65,6 +65,6 @@ void main() { // hide if (angle >= a_rangeend && angle < rangestart) z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_posmatrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; } From 8cc02df475f9ccf2f29601337c4d78e728c8dfea Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Sep 2014 13:25:46 -0700 Subject: [PATCH 076/259] Remove unused --- sdf.vertex.glsl | 1 - 1 file changed, 1 deletion(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index a90cab1b83c..c5166ae46f8 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -28,7 +28,6 @@ varying float v_alpha; void main() { - float a_fadedist = 10.0; float rev = 0.0; // u_angle is angle of the map, -128..128 representing 0..2PI From 44884984d45a1fee5a32e6674dc29744ecde9d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 4 Dec 2014 18:29:42 +0100 Subject: [PATCH 077/259] make most headers private --- dot.fragment.glsl | 9 +++ dot.vertex.glsl | 9 +++ dot_shader.cpp | 26 ++++++++ dot_shader.hpp | 26 ++++++++ gaussian.fragment.glsl | 11 ++++ gaussian.vertex.glsl | 15 +++++ gaussian_shader.cpp | 28 ++++++++ gaussian_shader.hpp | 25 +++++++ icon.fragment.glsl | 8 +++ icon.vertex.glsl | 73 +++++++++++++++++++++ icon_shader.cpp | 60 +++++++++++++++++ icon_shader.hpp | 41 ++++++++++++ line.fragment.glsl | 25 +++++++ line.vertex.glsl | 45 +++++++++++++ line_shader.cpp | 34 ++++++++++ line_shader.hpp | 32 +++++++++ linejoin.fragment.glsl | 14 ++++ linejoin.vertex.glsl | 13 ++++ linejoin_shader.cpp | 27 ++++++++ linejoin_shader.hpp | 27 ++++++++ linepattern.fragment.glsl | 37 +++++++++++ linepattern.vertex.glsl | 57 ++++++++++++++++ linepattern_shader.cpp | 35 ++++++++++ linepattern_shader.hpp | 33 ++++++++++ outline.fragment.glsl | 9 +++ outline.vertex.glsl | 10 +++ outline_shader.cpp | 26 ++++++++ outline_shader.hpp | 25 +++++++ pattern.fragment.glsl | 21 ++++++ pattern.vertex.glsl | 11 ++++ pattern_shader.cpp | 26 ++++++++ pattern_shader.hpp | 29 +++++++++ plain.fragment.glsl | 5 ++ plain.vertex.glsl | 7 ++ plain_shader.cpp | 26 ++++++++ plain_shader.hpp | 24 +++++++ raster.fragment.glsl | 36 +++++++++++ raster.vertex.glsl | 13 ++++ raster_shader.cpp | 28 ++++++++ raster_shader.hpp | 31 +++++++++ sdf.fragment.glsl | 13 ++++ sdf.vertex.glsl | 69 ++++++++++++++++++++ sdf_shader.cpp | 91 ++++++++++++++++++++++++++ sdf_shader.hpp | 53 +++++++++++++++ shader.cpp | 133 ++++++++++++++++++++++++++++++++++++++ shader.hpp | 28 ++++++++ uniform.cpp | 47 ++++++++++++++ uniform.hpp | 53 +++++++++++++++ 48 files changed, 1524 insertions(+) create mode 100644 dot.fragment.glsl create mode 100644 dot.vertex.glsl create mode 100644 dot_shader.cpp create mode 100644 dot_shader.hpp create mode 100644 gaussian.fragment.glsl create mode 100644 gaussian.vertex.glsl create mode 100644 gaussian_shader.cpp create mode 100644 gaussian_shader.hpp create mode 100644 icon.fragment.glsl create mode 100644 icon.vertex.glsl create mode 100644 icon_shader.cpp create mode 100644 icon_shader.hpp create mode 100644 line.fragment.glsl create mode 100644 line.vertex.glsl create mode 100644 line_shader.cpp create mode 100644 line_shader.hpp create mode 100644 linejoin.fragment.glsl create mode 100644 linejoin.vertex.glsl create mode 100644 linejoin_shader.cpp create mode 100644 linejoin_shader.hpp create mode 100644 linepattern.fragment.glsl create mode 100644 linepattern.vertex.glsl create mode 100644 linepattern_shader.cpp create mode 100644 linepattern_shader.hpp create mode 100644 outline.fragment.glsl create mode 100644 outline.vertex.glsl create mode 100644 outline_shader.cpp create mode 100644 outline_shader.hpp create mode 100644 pattern.fragment.glsl create mode 100644 pattern.vertex.glsl create mode 100644 pattern_shader.cpp create mode 100644 pattern_shader.hpp create mode 100644 plain.fragment.glsl create mode 100644 plain.vertex.glsl create mode 100644 plain_shader.cpp create mode 100644 plain_shader.hpp create mode 100644 raster.fragment.glsl create mode 100644 raster.vertex.glsl create mode 100644 raster_shader.cpp create mode 100644 raster_shader.hpp create mode 100644 sdf.fragment.glsl create mode 100644 sdf.vertex.glsl create mode 100644 sdf_shader.cpp create mode 100644 sdf_shader.hpp create mode 100644 shader.cpp create mode 100644 shader.hpp create mode 100644 uniform.cpp create mode 100644 uniform.hpp diff --git a/dot.fragment.glsl b/dot.fragment.glsl new file mode 100644 index 00000000000..6d998b5611f --- /dev/null +++ b/dot.fragment.glsl @@ -0,0 +1,9 @@ +uniform vec4 u_color; +uniform float u_blur; + +void main() { + float dist = length(gl_PointCoord - 0.5); + float t = smoothstep(0.5, 0.5 - u_blur, dist); + + gl_FragColor = u_color * t; +} diff --git a/dot.vertex.glsl b/dot.vertex.glsl new file mode 100644 index 00000000000..5310ae745e0 --- /dev/null +++ b/dot.vertex.glsl @@ -0,0 +1,9 @@ +uniform mat4 u_matrix; +uniform float u_size; + +attribute vec2 a_pos; + +void main(void) { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + gl_PointSize = u_size; +} diff --git a/dot_shader.cpp b/dot_shader.cpp new file mode 100644 index 00000000000..a897f410a71 --- /dev/null +++ b/dot_shader.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +DotShader::DotShader() +: Shader( + "dot", + shaders[DOT_SHADER].vertex, + shaders[DOT_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid dot shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void DotShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset); +} diff --git a/dot_shader.hpp b/dot_shader.hpp new file mode 100644 index 00000000000..2c4176f364e --- /dev/null +++ b/dot_shader.hpp @@ -0,0 +1,26 @@ +#ifndef MBGL_SHADER_SHADER_DOT +#define MBGL_SHADER_SHADER_DOT + +#include +#include + +namespace mbgl { + +class DotShader : public Shader { +public: + DotShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform u_size = {"u_size", *this}; + Uniform u_blur = {"u_blur", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/gaussian.fragment.glsl b/gaussian.fragment.glsl new file mode 100644 index 00000000000..ee8406e9e11 --- /dev/null +++ b/gaussian.fragment.glsl @@ -0,0 +1,11 @@ +uniform sampler2D u_image; + +varying vec2 v_coords[3]; + +void main() { + vec4 sum = vec4(0.0); + sum += texture2D(u_image, v_coords[0]) * 0.40261994689424746; + sum += texture2D(u_image, v_coords[1]) * 0.2986900265528763; + sum += texture2D(u_image, v_coords[2]) * 0.2986900265528763; + gl_FragColor = sum; +} diff --git a/gaussian.vertex.glsl b/gaussian.vertex.glsl new file mode 100644 index 00000000000..26a83942046 --- /dev/null +++ b/gaussian.vertex.glsl @@ -0,0 +1,15 @@ +attribute vec2 a_pos; + +uniform mat4 u_matrix; +uniform vec2 u_offset; + +varying vec2 v_coords[3]; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + + vec2 tex = gl_Position.xy / 2.0 + 0.5; + v_coords[0] = tex; + v_coords[1] = tex + u_offset * 1.1824255238063563; + v_coords[2] = tex - u_offset * 1.1824255238063563; +} diff --git a/gaussian_shader.cpp b/gaussian_shader.cpp new file mode 100644 index 00000000000..9060f0ee714 --- /dev/null +++ b/gaussian_shader.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +GaussianShader::GaussianShader() + : Shader( + "gaussian", + shaders[GAUSSIAN_SHADER].vertex, + shaders[GAUSSIAN_SHADER].fragment + ) { + if (!valid) { +#if defined(DEBUG) + fprintf(stderr, "invalid raster shader\n"); +#endif + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void GaussianShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); +} diff --git a/gaussian_shader.hpp b/gaussian_shader.hpp new file mode 100644 index 00000000000..0f494f5c7eb --- /dev/null +++ b/gaussian_shader.hpp @@ -0,0 +1,25 @@ +#ifndef MBGL_RENDERER_SHADER_GAUSSIAN +#define MBGL_RENDERER_SHADER_GAUSSIAN + +#include +#include + +namespace mbgl { + +class GaussianShader : public Shader { +public: + GaussianShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_offset = {"u_offset", *this}; + Uniform u_image = {"u_image", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/icon.fragment.glsl b/icon.fragment.glsl new file mode 100644 index 00000000000..45b56793eba --- /dev/null +++ b/icon.fragment.glsl @@ -0,0 +1,8 @@ +uniform sampler2D u_texture; + +varying vec2 v_tex; +varying float v_alpha; + +void main() { + gl_FragColor = texture2D(u_texture, v_tex) * v_alpha; +} diff --git a/icon.vertex.glsl b/icon.vertex.glsl new file mode 100644 index 00000000000..8c69c404100 --- /dev/null +++ b/icon.vertex.glsl @@ -0,0 +1,73 @@ +attribute vec2 a_pos; +attribute vec2 a_offset; +attribute vec2 a_tex; +attribute float a_angle; +attribute float a_minzoom; +attribute float a_maxzoom; +attribute float a_rangeend; +attribute float a_rangestart; +attribute float a_labelminzoom; + + +// matrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_matrix; +uniform mat4 u_exmatrix; +uniform float u_angle; +uniform float u_zoom; +uniform float u_flip; +uniform float u_fadedist; +uniform float u_minfadezoom; +uniform float u_maxfadezoom; +uniform float u_fadezoom; +uniform float u_opacity; + +uniform vec2 u_texsize; + +varying vec2 v_tex; +varying float v_alpha; + +void main() { + + float a_fadedist = 10.0; + float rev = 0.0; + + // u_angle is angle of the map, -128..128 representing 0..2PI + // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text + float rotated = mod(a_angle + u_angle, 256.0); + // if the label rotates with the map, and if the rotated label is upside down, hide it + if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; + + // If the label should be invisible, we move the vertex outside + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + // u_zoom is the current zoom level adjusted for the change in font size + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + + // fade out labels + float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); + + if (u_fadedist >= 0.0) { + v_alpha = alpha; + } else { + v_alpha = 1.0 - alpha; + } + if (u_maxfadezoom < a_labelminzoom) { + v_alpha = 0.0; + } + if (u_minfadezoom >= a_labelminzoom) { + v_alpha = 1.0; + } + + // if label has been faded out, clip it + z += step(v_alpha, 0.0); + + // all the angles are 0..256 representing 0..2PI + // hide if (angle >= a_rangeend && angle < rangestart) + z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); + + gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + v_tex = a_tex / u_texsize; + + v_alpha *= u_opacity; +} diff --git a/icon_shader.cpp b/icon_shader.cpp new file mode 100644 index 00000000000..5c54177eb6c --- /dev/null +++ b/icon_shader.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +IconShader::IconShader() + : Shader( + "icon", + shaders[ICON_SHADER].vertex, + shaders[ICON_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid icon shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); + a_offset = glGetAttribLocation(program, "a_offset"); + a_tex = glGetAttribLocation(program, "a_tex"); + a_angle = glGetAttribLocation(program, "a_angle"); + a_minzoom = glGetAttribLocation(program, "a_minzoom"); + a_maxzoom = glGetAttribLocation(program, "a_maxzoom"); + a_rangeend = glGetAttribLocation(program, "a_rangeend"); + a_rangestart = glGetAttribLocation(program, "a_rangestart"); + a_labelminzoom = glGetAttribLocation(program, "a_labelminzoom"); +} + +void IconShader::bind(char *offset) { + const int stride = 20; + + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0); + + glEnableVertexAttribArray(a_offset); + glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4); + + glEnableVertexAttribArray(a_labelminzoom); + glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8); + + glEnableVertexAttribArray(a_minzoom); + glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9); + + glEnableVertexAttribArray(a_maxzoom); + glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10); + + glEnableVertexAttribArray(a_angle); + glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11); + + glEnableVertexAttribArray(a_rangeend); + glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12); + + glEnableVertexAttribArray(a_rangestart); + glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13); + + glEnableVertexAttribArray(a_tex); + glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16); +} diff --git a/icon_shader.hpp b/icon_shader.hpp new file mode 100644 index 00000000000..645d7e21b63 --- /dev/null +++ b/icon_shader.hpp @@ -0,0 +1,41 @@ +#ifndef MBGL_SHADER_SHADER_ICON +#define MBGL_SHADER_SHADER_ICON + +#include +#include + +namespace mbgl { + +class IconShader : public Shader { +public: + IconShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform u_angle = {"u_angle", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_flip = {"u_flip", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform> u_texsize = {"u_texsize", *this}; + +private: + int32_t a_pos = -1; + int32_t a_offset = -1; + int32_t a_tex = -1; + int32_t a_angle = -1; + int32_t a_minzoom = -1; + int32_t a_maxzoom = -1; + int32_t a_rangeend = -1; + int32_t a_rangestart = -1; + int32_t a_labelminzoom = -1; +}; + +} + +#endif diff --git a/line.fragment.glsl b/line.fragment.glsl new file mode 100644 index 00000000000..f4ac1458b33 --- /dev/null +++ b/line.fragment.glsl @@ -0,0 +1,25 @@ +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_blur; + +uniform vec2 u_dasharray; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // Calculate the distance of the pixel from the line in pixels. + float dist = length(v_normal) * u_linewidth.s; + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + + // Calculate the antialiasing fade factor based on distance to the dash. + // Only affects alpha when line is dashed + float pos = mod(v_linesofar, u_dasharray.x + u_dasharray.y); + alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0)); + + gl_FragColor = u_color * alpha; +} diff --git a/line.vertex.glsl b/line.vertex.glsl new file mode 100644 index 00000000000..1d8e687c957 --- /dev/null +++ b/line.vertex.glsl @@ -0,0 +1,45 @@ +// floor(127 / 2) == 63.0 +// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is +// stored in a byte (-128..127). we scale regular normals up to length 63, but +// there are also "special" normals that have a bigger length (of up to 126 in +// this case). +// #define scale 63.0 +#define scale 0.015873016 + +attribute vec2 a_pos; +attribute vec2 a_extrude; +attribute float a_linesofar; + +// matrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_matrix; +uniform mat4 u_exmatrix; + +// shared +uniform float u_ratio; +uniform vec2 u_linewidth; +uniform vec4 u_color; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // We store the texture normals in the most insignificant bit + // transform y so that 0 => -1 and 1 => 1 + // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap + // y is 1 if the normal points up, and -1 if it points down + vec2 normal = mod(a_pos, 2.0); + normal.y = sign(normal.y - 0.5); + v_normal = normal; + + // Scale the extrusion vector down to a normal and then up by the line width + // of this vertex. + vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + + // Remove the texture normal bit of the position before scaling it with the + // model/view matrix. Add the extrusion vector *after* the model/view matrix + // because we're extruding the line in pixel space, regardless of the current + // tile's zoom level. + gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + v_linesofar = a_linesofar * u_ratio; +} diff --git a/line_shader.cpp b/line_shader.cpp new file mode 100644 index 00000000000..8353f4c6cae --- /dev/null +++ b/line_shader.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +LineShader::LineShader() + : Shader( + "line", + shaders[LINE_SHADER].vertex, + shaders[LINE_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid line shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); + a_extrude = glGetAttribLocation(program, "a_extrude"); + a_linesofar = glGetAttribLocation(program, "a_linesofar"); +} + +void LineShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0); + + glEnableVertexAttribArray(a_extrude); + glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4); + + glEnableVertexAttribArray(a_linesofar); + glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6); +} diff --git a/line_shader.hpp b/line_shader.hpp new file mode 100644 index 00000000000..b789330882c --- /dev/null +++ b/line_shader.hpp @@ -0,0 +1,32 @@ +#ifndef MBGL_SHADER_SHADER_LINE +#define MBGL_SHADER_SHADER_LINE + +#include +#include + +namespace mbgl { + +class LineShader : public Shader { +public: + LineShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform> u_dasharray = {"u_dasharray", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_blur = {"u_blur", *this}; + +private: + int32_t a_pos = -1; + int32_t a_extrude = -1; + int32_t a_linesofar = -1; +}; + + +} + +#endif diff --git a/linejoin.fragment.glsl b/linejoin.fragment.glsl new file mode 100644 index 00000000000..705a57766e4 --- /dev/null +++ b/linejoin.fragment.glsl @@ -0,0 +1,14 @@ +uniform vec4 u_color; +uniform vec2 u_linewidth; + +varying vec2 v_pos; + +void main() { + float dist = length(v_pos - gl_FragCoord.xy); + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist), 0.0, 1.0); + gl_FragColor = u_color * alpha; +} diff --git a/linejoin.vertex.glsl b/linejoin.vertex.glsl new file mode 100644 index 00000000000..2e03561e5b4 --- /dev/null +++ b/linejoin.vertex.glsl @@ -0,0 +1,13 @@ +attribute vec2 a_pos; + +uniform mat4 u_matrix; +uniform vec2 u_world; +uniform float u_size; + +varying vec2 v_pos; + +void main() { + gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0); + v_pos = (gl_Position.xy + 1.0) * u_world; + gl_PointSize = u_size; +} diff --git a/linejoin_shader.cpp b/linejoin_shader.cpp new file mode 100644 index 00000000000..050e180e00e --- /dev/null +++ b/linejoin_shader.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +LinejoinShader::LinejoinShader() + : Shader( + "linejoin", + shaders[LINEJOIN_SHADER].vertex, + shaders[LINEJOIN_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid line shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void LinejoinShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + // Note: We're referring to the vertices in a line array, which are 8 bytes long! + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset); +} diff --git a/linejoin_shader.hpp b/linejoin_shader.hpp new file mode 100644 index 00000000000..61406fd45ca --- /dev/null +++ b/linejoin_shader.hpp @@ -0,0 +1,27 @@ +#ifndef MBGL_SHADER_SHADER_LINEJOIN +#define MBGL_SHADER_SHADER_LINEJOIN + +#include +#include + +namespace mbgl { + +class LinejoinShader : public Shader { +public: + LinejoinShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_world = {"u_world", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform u_size = {"u_size", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl new file mode 100644 index 00000000000..52ca823a3b6 --- /dev/null +++ b/linepattern.fragment.glsl @@ -0,0 +1,37 @@ +uniform vec2 u_linewidth; +uniform float u_point; +uniform float u_blur; + +uniform vec2 u_pattern_size; +uniform vec2 u_pattern_tl; +uniform vec2 u_pattern_br; +uniform float u_fade; + +uniform sampler2D u_image; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // Calculate the distance of the pixel from the line in pixels. + float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); + + dist *= u_linewidth.s; + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + + float x = mod(v_linesofar / u_pattern_size.x, 1.0); + float y = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size.y); + vec2 pos = mix(u_pattern_tl, u_pattern_br, vec2(x, y)); + float x2 = mod(x * 2.0, 1.0); + vec2 pos2 = mix(u_pattern_tl, u_pattern_br, vec2(x2, y)); + + vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); + + color.rgb *= color.a; // premultiply + + gl_FragColor = color * alpha; +} diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl new file mode 100644 index 00000000000..4600ebf65b4 --- /dev/null +++ b/linepattern.vertex.glsl @@ -0,0 +1,57 @@ +// floor(127 / 2) == 63.0 +// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is +// stored in a byte (-128..127). we scale regular normals up to length 63, but +// there are also "special" normals that have a bigger length (of up to 126 in +// this case). +#define scale 63.0 + +attribute vec2 a_pos; +attribute vec2 a_extrude; +attribute float a_linesofar; + +// matrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_matrix; +uniform mat4 u_exmatrix; + +// shared +uniform float u_ratio; +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_point; + +varying vec2 v_normal; +varying float v_linesofar; + +void main() { + // We store the texture normals in the most insignificant bit + // transform y so that 0 => -1 and 1 => 1 + // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap + // y is 1 if the normal points up, and -1 if it points down + vec2 normal = mod(a_pos, 2.0); + normal.y = sign(normal.y - 0.5); + v_normal = normal; + + // Scale the extrusion vector down to a normal and then up by the line width + // of this vertex. + vec2 extrude = a_extrude / scale; + vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); + + // If the x coordinate is the maximum integer, we move the z coordinates out + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + float z = step(32767.0, a_pos.x); + + // When drawing points, skip every other vertex + z += u_point * step(1.0, v_normal.y); + + // Remove the texture normal bit of the position before scaling it with the + // model/view matrix. Add the extrusion vector *after* the model/view matrix + // because we're extruding the line in pixel space, regardless of the current + // tile's zoom level. + gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + v_linesofar = a_linesofar;// * u_ratio; + + + gl_PointSize = 2.0 * u_linewidth.s - 1.0; +} diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp new file mode 100644 index 00000000000..954dbd2b3ff --- /dev/null +++ b/linepattern_shader.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include + +using namespace mbgl; + +LinepatternShader::LinepatternShader() + : Shader( + "linepattern", + shaders[LINEPATTERN_SHADER].vertex, + shaders[LINEPATTERN_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid line pattern shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); + a_extrude = glGetAttribLocation(program, "a_extrude"); + a_linesofar = glGetAttribLocation(program, "a_linesofar"); +} + +void LinepatternShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0); + + glEnableVertexAttribArray(a_extrude); + glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4); + + glEnableVertexAttribArray(a_linesofar); + glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6); +} diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp new file mode 100644 index 00000000000..bf85940b8a7 --- /dev/null +++ b/linepattern_shader.hpp @@ -0,0 +1,33 @@ +#ifndef MBGL_SHADER_SHADER_LINEPATTERN +#define MBGL_SHADER_SHADER_LINEPATTERN + +#include +#include + +namespace mbgl { + +class LinepatternShader : public Shader { +public: + LinepatternShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform> u_pattern_size = {"u_pattern_size", *this}; + Uniform> u_pattern_tl = {"u_pattern_tl", *this}; + Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_point = {"u_point", *this}; + Uniform u_blur = {"u_blur", *this}; + Uniform u_fade = {"u_fade", *this}; + +private: + int32_t a_pos = -1; + int32_t a_extrude = -1; + int32_t a_linesofar = -1; +}; +} + +#endif diff --git a/outline.fragment.glsl b/outline.fragment.glsl new file mode 100644 index 00000000000..eccda714e52 --- /dev/null +++ b/outline.fragment.glsl @@ -0,0 +1,9 @@ +uniform vec4 u_color; + +varying vec2 v_pos; + +void main() { + float dist = length(v_pos - gl_FragCoord.xy); + float alpha = smoothstep(1.0, 0.0, dist); + gl_FragColor = u_color * alpha; +} diff --git a/outline.vertex.glsl b/outline.vertex.glsl new file mode 100644 index 00000000000..29c16e3ded2 --- /dev/null +++ b/outline.vertex.glsl @@ -0,0 +1,10 @@ +attribute vec2 a_pos; +uniform mat4 u_matrix; +uniform vec2 u_world; + +varying vec2 v_pos; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world; +} diff --git a/outline_shader.cpp b/outline_shader.cpp new file mode 100644 index 00000000000..ddabfa5d0d4 --- /dev/null +++ b/outline_shader.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +OutlineShader::OutlineShader() + : Shader( + "outline", + shaders[OUTLINE_SHADER].vertex, + shaders[OUTLINE_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid outline shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void OutlineShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); +} diff --git a/outline_shader.hpp b/outline_shader.hpp new file mode 100644 index 00000000000..f3e8175fd78 --- /dev/null +++ b/outline_shader.hpp @@ -0,0 +1,25 @@ +#ifndef MBGL_SHADER_SHADER_OUTLINE +#define MBGL_SHADER_SHADER_OUTLINE + +#include +#include + +namespace mbgl { + +class OutlineShader : public Shader { +public: + OutlineShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_world = {"u_world", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl new file mode 100644 index 00000000000..ba6aed30239 --- /dev/null +++ b/pattern.fragment.glsl @@ -0,0 +1,21 @@ +uniform float u_opacity; +uniform vec2 u_pattern_tl; +uniform vec2 u_pattern_br; +uniform float u_mix; + +uniform sampler2D u_image; + +varying vec2 v_pos; + +void main() { + + vec2 imagecoord = mod(v_pos, 1.0); + vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); + vec4 color1 = texture2D(u_image, pos); + + vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); + vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); + vec4 color2 = texture2D(u_image, pos2); + + gl_FragColor = mix(color1, color2, u_mix) * u_opacity; +} diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl new file mode 100644 index 00000000000..f2de884eadb --- /dev/null +++ b/pattern.vertex.glsl @@ -0,0 +1,11 @@ +uniform mat4 u_matrix; +uniform mat3 u_patternmatrix; + +attribute vec2 a_pos; + +varying vec2 v_pos; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + v_pos = (u_patternmatrix * vec3(a_pos, 1)).xy; +} diff --git a/pattern_shader.cpp b/pattern_shader.cpp new file mode 100644 index 00000000000..31374bc3e8e --- /dev/null +++ b/pattern_shader.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +PatternShader::PatternShader() + : Shader( + "pattern", + shaders[PATTERN_SHADER].vertex, + shaders[PATTERN_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid pattern shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void PatternShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); +} diff --git a/pattern_shader.hpp b/pattern_shader.hpp new file mode 100644 index 00000000000..9fabd8e18ac --- /dev/null +++ b/pattern_shader.hpp @@ -0,0 +1,29 @@ +#ifndef MBGL_SHADER_SHADER_PATTERN +#define MBGL_SHADER_SHADER_PATTERN + +#include +#include + +namespace mbgl { + +class PatternShader : public Shader { +public: + PatternShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_pattern_tl = {"u_pattern_tl", *this}; + Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_mix = {"u_mix", *this}; + Uniform u_image = {"u_image", *this}; + UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/plain.fragment.glsl b/plain.fragment.glsl new file mode 100644 index 00000000000..8df552c1718 --- /dev/null +++ b/plain.fragment.glsl @@ -0,0 +1,5 @@ +uniform vec4 u_color; + +void main() { + gl_FragColor = u_color; +} diff --git a/plain.vertex.glsl b/plain.vertex.glsl new file mode 100644 index 00000000000..866c3cd2f39 --- /dev/null +++ b/plain.vertex.glsl @@ -0,0 +1,7 @@ +attribute vec2 a_pos; + +uniform mat4 u_matrix; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); +} diff --git a/plain_shader.cpp b/plain_shader.cpp new file mode 100644 index 00000000000..8a37837b309 --- /dev/null +++ b/plain_shader.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +PlainShader::PlainShader() + : Shader( + "plain", + shaders[PLAIN_SHADER].vertex, + shaders[PLAIN_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid plain shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void PlainShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); +} diff --git a/plain_shader.hpp b/plain_shader.hpp new file mode 100644 index 00000000000..051501c3c94 --- /dev/null +++ b/plain_shader.hpp @@ -0,0 +1,24 @@ +#ifndef MBGL_SHADER_SHADER_PLAIN +#define MBGL_SHADER_SHADER_PLAIN + +#include +#include + +namespace mbgl { + +class PlainShader : public Shader { +public: + PlainShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/raster.fragment.glsl b/raster.fragment.glsl new file mode 100644 index 00000000000..333de76dc14 --- /dev/null +++ b/raster.fragment.glsl @@ -0,0 +1,36 @@ +uniform sampler2D u_image; +uniform float u_opacity; + +varying vec2 v_pos; + +uniform float u_brightness_low; +uniform float u_brightness_high; + +uniform float u_saturation_factor; +uniform float u_contrast_factor; +uniform vec3 u_spin_weights; + +void main() { + + vec4 color = texture2D(u_image, v_pos) * u_opacity; + vec3 rgb = color.rgb; + + // spin + rgb = vec3( + dot(rgb, u_spin_weights.xyz), + dot(rgb, u_spin_weights.zxy), + dot(rgb, u_spin_weights.yzx)); + + // saturation + float average = (color.r + color.g + color.b) / 3.0; + rgb += (average - rgb) * u_saturation_factor; + + // contrast + rgb = (rgb - 0.5) * u_contrast_factor + 0.5; + + // brightness + vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low); + vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); + + gl_FragColor = vec4(mix(u_high_vec, u_low_vec, rgb), color.a); +} diff --git a/raster.vertex.glsl b/raster.vertex.glsl new file mode 100644 index 00000000000..97e563f585f --- /dev/null +++ b/raster.vertex.glsl @@ -0,0 +1,13 @@ +uniform mat4 u_matrix; +uniform float u_buffer; + +attribute vec2 a_pos; + +varying vec2 v_pos; + + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + float dimension = (4096.0 + 2.0 * u_buffer); + v_pos = (a_pos / dimension) + (u_buffer / dimension); +} diff --git a/raster_shader.cpp b/raster_shader.cpp new file mode 100644 index 00000000000..7351f7d0c44 --- /dev/null +++ b/raster_shader.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +RasterShader::RasterShader() + : Shader( + "raster", + shaders[RASTER_SHADER].vertex, + shaders[RASTER_SHADER].fragment + ) { + if (!valid) { +#if defined(DEBUG) + fprintf(stderr, "invalid raster shader\n"); +#endif + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); +} + +void RasterShader::bind(char *offset) { + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); +} diff --git a/raster_shader.hpp b/raster_shader.hpp new file mode 100644 index 00000000000..8cf97055a2a --- /dev/null +++ b/raster_shader.hpp @@ -0,0 +1,31 @@ +#ifndef MBGL_RENDERER_SHADER_RASTER +#define MBGL_RENDERER_SHADER_RASTER + +#include +#include + +namespace mbgl { + +class RasterShader : public Shader { +public: + RasterShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform u_image = {"u_image", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_brightness_low = {"u_brightness_low", *this}; + Uniform u_brightness_high = {"u_brightness_high", *this}; + Uniform u_saturation_factor = {"u_saturation_factor", *this}; + Uniform u_contrast_factor = {"u_contrast_factor", *this}; + Uniform> u_spin_weights = {"u_spin_weights", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl new file mode 100644 index 00000000000..d72d61dab19 --- /dev/null +++ b/sdf.fragment.glsl @@ -0,0 +1,13 @@ +uniform sampler2D u_texture; +uniform vec4 u_color; +uniform float u_buffer; +uniform float u_gamma; + +varying vec2 v_tex; +varying float v_alpha; + +void main() { + float dist = texture2D(u_texture, v_tex).a; + float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist) * v_alpha; + gl_FragColor = u_color * alpha; +} diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl new file mode 100644 index 00000000000..c5166ae46f8 --- /dev/null +++ b/sdf.vertex.glsl @@ -0,0 +1,69 @@ +attribute vec2 a_pos; +attribute vec2 a_offset; +attribute vec2 a_tex; +attribute float a_angle; +attribute float a_minzoom; +attribute float a_maxzoom; +attribute float a_rangeend; +attribute float a_rangestart; +attribute float a_labelminzoom; + + +// matrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_matrix; +uniform mat4 u_exmatrix; +uniform float u_angle; +uniform float u_zoom; +uniform float u_flip; +uniform float u_fadedist; +uniform float u_minfadezoom; +uniform float u_maxfadezoom; +uniform float u_fadezoom; + +uniform vec2 u_texsize; + +varying vec2 v_tex; +varying float v_alpha; + +void main() { + + float rev = 0.0; + + // u_angle is angle of the map, -128..128 representing 0..2PI + // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text + float rotated = mod(a_angle + u_angle, 256.0); + // if the label rotates with the map, and if the rotated label is upside down, hide it + if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; + + // If the label should be invisible, we move the vertex outside + // of the view plane so that the triangle gets clipped. This makes it easier + // for us to create degenerate triangle strips. + // u_zoom is the current zoom level adjusted for the change in font size + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + + // fade out labels + float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); + + if (u_fadedist >= 0.0) { + v_alpha = alpha; + } else { + v_alpha = 1.0 - alpha; + } + if (u_maxfadezoom < a_labelminzoom) { + v_alpha = 0.0; + } + if (u_minfadezoom >= a_labelminzoom) { + v_alpha = 1.0; + } + + // if label has been faded out, clip it + z += step(v_alpha, 0.0); + + // all the angles are 0..256 representing 0..2PI + // hide if (angle >= a_rangeend && angle < rangestart) + z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); + + gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + v_tex = a_tex / u_texsize; +} diff --git a/sdf_shader.cpp b/sdf_shader.cpp new file mode 100644 index 00000000000..b86733c0e4c --- /dev/null +++ b/sdf_shader.cpp @@ -0,0 +1,91 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +SDFShader::SDFShader() + : Shader( + "sdf", + shaders[SDF_SHADER].vertex, + shaders[SDF_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid sdf shader\n"); + return; + } + + a_pos = glGetAttribLocation(program, "a_pos"); + a_offset = glGetAttribLocation(program, "a_offset"); + a_tex = glGetAttribLocation(program, "a_tex"); + a_angle = glGetAttribLocation(program, "a_angle"); + a_minzoom = glGetAttribLocation(program, "a_minzoom"); + a_maxzoom = glGetAttribLocation(program, "a_maxzoom"); + a_rangeend = glGetAttribLocation(program, "a_rangeend"); + a_rangestart = glGetAttribLocation(program, "a_rangestart"); + a_labelminzoom = glGetAttribLocation(program, "a_labelminzoom"); +} + +void SDFGlyphShader::bind(char *offset) { + const int stride = 16; + + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0); + + glEnableVertexAttribArray(a_offset); + glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4); + + glEnableVertexAttribArray(a_labelminzoom); + glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8); + + glEnableVertexAttribArray(a_minzoom); + glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9); + + glEnableVertexAttribArray(a_maxzoom); + glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10); + + glEnableVertexAttribArray(a_angle); + glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11); + + glEnableVertexAttribArray(a_rangeend); + glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12); + + glEnableVertexAttribArray(a_rangestart); + glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13); + + glEnableVertexAttribArray(a_tex); + glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14); +} + +void SDFIconShader::bind(char *offset) { + const int stride = 20; + + glEnableVertexAttribArray(a_pos); + glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0); + + glEnableVertexAttribArray(a_offset); + glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4); + + glEnableVertexAttribArray(a_labelminzoom); + glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8); + + glEnableVertexAttribArray(a_minzoom); + glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9); + + glEnableVertexAttribArray(a_maxzoom); + glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10); + + glEnableVertexAttribArray(a_angle); + glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11); + + glEnableVertexAttribArray(a_rangeend); + glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12); + + glEnableVertexAttribArray(a_rangestart); + glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13); + + glEnableVertexAttribArray(a_tex); + glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16); +} diff --git a/sdf_shader.hpp b/sdf_shader.hpp new file mode 100644 index 00000000000..0737c25ee10 --- /dev/null +++ b/sdf_shader.hpp @@ -0,0 +1,53 @@ +#ifndef MBGL_SHADER_SDF_SHADER +#define MBGL_SHADER_SDF_SHADER + +#include +#include + +namespace mbgl { + +class SDFShader : public Shader { +public: + SDFShader(); + + virtual void bind(char *offset) = 0; + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_texsize = {"u_texsize", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_gamma = {"u_gamma", *this}; + Uniform u_angle = {"u_angle", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_flip = {"u_flip", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; + +protected: + int32_t a_pos = -1; + int32_t a_offset = -1; + int32_t a_tex = -1; + int32_t a_angle = -1; + int32_t a_minzoom = -1; + int32_t a_maxzoom = -1; + int32_t a_rangeend = -1; + int32_t a_rangestart = -1; + int32_t a_labelminzoom = -1; +}; + +class SDFGlyphShader : public SDFShader { +public: + void bind(char *offset); +}; + +class SDFIconShader : public SDFShader { +public: + void bind(char *offset); +}; + +} + +#endif diff --git a/shader.cpp b/shader.cpp new file mode 100644 index 00000000000..84cb55eac4a --- /dev/null +++ b/shader.cpp @@ -0,0 +1,133 @@ +#include +#include +#include +#include + +#include +#include + +using namespace mbgl; + +Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource) + : name(name_), + valid(false), + program(0) { + util::stopwatch stopwatch("shader compilation", Event::Shader); + + GLuint vertShader; + if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { + Log::Error(Event::Shader, "Vertex shader failed to compile: %s", vertSource); + return; + } + + GLuint fragShader; + if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { + Log::Error(Event::Shader, "Fragment shader failed to compile: %s", fragSource); + return; + } + + program = glCreateProgram(); + + // Attach shaders + glAttachShader(program, vertShader); + glAttachShader(program, fragShader); + + + { + // Link program + GLint status; + glLinkProgram(program); + + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (status == 0) { + GLint logLength; + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(program, logLength, &logLength, log); + Log::Error(Event::Shader, "Program failed to link: %s", log); + free(log); + } + + glDeleteShader(vertShader); + vertShader = 0; + glDeleteShader(fragShader); + fragShader = 0; + glDeleteProgram(program); + program = 0; + return; + } + } + + { + // Validate program + GLint status; + glValidateProgram(program); + + glGetProgramiv(program, GL_VALIDATE_STATUS, &status); + if (status == 0) { + GLint logLength; + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(program, logLength, &logLength, log); + Log::Error(Event::Shader, "Program failed to validate: %s", log); + free(log); + } + + glDeleteShader(vertShader); + vertShader = 0; + glDeleteShader(fragShader); + fragShader = 0; + glDeleteProgram(program); + program = 0; + } + + } + + // Remove the compiled shaders; they are now part of the program. + glDetachShader(program, vertShader); + glDeleteShader(vertShader); + glDetachShader(program, fragShader); + glDeleteShader(fragShader); + + valid = true; +} + + +bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { + GLint status; + + *shader = glCreateShader(type); + const GLchar *strings[] = { source }; + const GLint lengths[] = { (GLint)strlen(source) }; + glShaderSource(*shader, 1, strings, lengths); + + glCompileShader(*shader); + + glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + if (status == 0) { + GLint logLength; + glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetShaderInfoLog(*shader, logLength, &logLength, log); + Log::Error(Event::Shader, "Shader failed to compile: %s", log); + free(log); + } + + glDeleteShader(*shader); + *shader = 0; + return false; + } + + return true; +} + +Shader::~Shader() { + if (program) { + glDeleteProgram(program); + program = 0; + valid = false; + } +} diff --git a/shader.hpp b/shader.hpp new file mode 100644 index 00000000000..27e831a5103 --- /dev/null +++ b/shader.hpp @@ -0,0 +1,28 @@ +#ifndef MBGL_RENDERER_SHADER +#define MBGL_RENDERER_SHADER + +#include +#include +#include + +namespace mbgl { + +class Shader : private util::noncopyable { +public: + Shader(const char *name, const char *vertex, const char *fragment); + ~Shader(); + const char *name; + bool valid; + uint32_t program; + + inline uint32_t getID() const { + return program; + } + +private: + bool compileShader(uint32_t *shader, uint32_t type, const char *source); +}; + +} + +#endif diff --git a/uniform.cpp b/uniform.cpp new file mode 100644 index 00000000000..24f179baf17 --- /dev/null +++ b/uniform.cpp @@ -0,0 +1,47 @@ +#include + +namespace mbgl { + +template <> +void Uniform::bind(const float& t) { + glUniform1f(location, t); +} + +template <> +void Uniform::bind(const int32_t& t) { + glUniform1i(location, t); +} + +template <> +void Uniform>::bind(const std::array& t) { + glUniform2fv(location, 1, t.data()); +} + +template <> +void Uniform>::bind(const std::array& t) { + glUniform3fv(location, 1, t.data()); +} + +template <> +void Uniform>::bind(const std::array& t) { + glUniform4fv(location, 1, t.data()); +} + +template <> +void UniformMatrix<2>::bind(const std::array& t) { + glUniformMatrix2fv(location, 1, GL_FALSE, t.data()); +} + +template <> +void UniformMatrix<3>::bind(const std::array& t) { + glUniformMatrix3fv(location, 1, GL_FALSE, t.data()); +} + +template <> +void UniformMatrix<4>::bind(const std::array& t) { + glUniformMatrix4fv(location, 1, GL_FALSE, t.data()); +} + +// Add more as needed. + +} diff --git a/uniform.hpp b/uniform.hpp new file mode 100644 index 00000000000..8579ae22c74 --- /dev/null +++ b/uniform.hpp @@ -0,0 +1,53 @@ +#ifndef MBGL_SHADER_UNIFORM +#define MBGL_SHADER_UNIFORM + +#include +#include + +namespace mbgl { + +template +class Uniform { +public: + Uniform(const GLchar* name, const Shader& shader) + : location(glGetUniformLocation(shader.program, name)) {} + + void operator=(const T& t) { + if (current != t) { + current = t; + bind(t); + } + } + +private: + void bind(const T&); + + T current; + GLint location; +}; + +template +class UniformMatrix { +public: + typedef std::array T; + + UniformMatrix(const GLchar* name, const Shader& shader) + : location(glGetUniformLocation(shader.program, name)) {} + + void operator=(const T& t) { + if (current != t) { + current = t; + bind(t); + } + } + +private: + void bind(const T&); + + T current; + GLint location; +}; + +} + +#endif From e27793121c1878a9fb723ad1fd41baf1bce0f7de Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Sun, 23 Nov 2014 10:18:13 +1100 Subject: [PATCH 078/259] Load program binary extension on Linux --- shader.cpp | 172 +++++++++++++++++++++++++++++++++++++++-------------- shader.hpp | 3 + 2 files changed, 129 insertions(+), 46 deletions(-) diff --git a/shader.cpp b/shader.cpp index 84cb55eac4a..af6ba627e11 100644 --- a/shader.cpp +++ b/shader.cpp @@ -2,9 +2,11 @@ #include #include #include +#include #include #include +#include using namespace mbgl; @@ -14,49 +16,97 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo program(0) { util::stopwatch stopwatch("shader compilation", Event::Shader); - GLuint vertShader; - if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { - Log::Error(Event::Shader, "Vertex shader failed to compile: %s", vertSource); - return; - } - - GLuint fragShader; - if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { - Log::Error(Event::Shader, "Fragment shader failed to compile: %s", fragSource); - return; - } - program = glCreateProgram(); - // Attach shaders - glAttachShader(program, vertShader); - glAttachShader(program, fragShader); + if (!mbgl::platform::defaultShaderCache().empty()) { + binaryFileName = mbgl::platform::defaultShaderCache() + name + ".bin"; + } + // Load binary shader if it exists + bool skipCompile = false; + if (!binaryFileName.empty() && (gl::ProgramBinary != nullptr)) { + FILE *binaryFile = fopen(binaryFileName.c_str(), "rb"); + if (binaryFile != nullptr) { + GLsizei binaryLength; + GLenum binaryFormat; + bool lengthOk = fread(&binaryLength, sizeof(binaryLength), 1, binaryFile) == 1; + bool formatOk = fread(&binaryFormat, sizeof(binaryFormat), 1, binaryFile) == 1; + + if (lengthOk && formatOk && binaryLength > 0) { + std::unique_ptr binary = mbgl::util::make_unique(binaryLength); + + if (binary != nullptr) { + bool binaryOk = fread(binary.get(), binaryLength, 1, binaryFile) == 1; + + if (binaryOk) { + gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength); + + // Check if the binary was valid + GLint status; + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (status == GL_TRUE) { + skipCompile = true; + } + } + } + } - { - // Link program - GLint status; - glLinkProgram(program); + fclose(binaryFile); + binaryFile = nullptr; + } + } - glGetProgramiv(program, GL_LINK_STATUS, &status); - if (status == 0) { - GLint logLength; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); - if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); - glGetProgramInfoLog(program, logLength, &logLength, log); - Log::Error(Event::Shader, "Program failed to link: %s", log); - free(log); - } + GLuint vertShader = 0; + GLuint fragShader = 0; + if (!skipCompile) { + if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { + Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); + glDeleteProgram(program); + program = 0; + return; + } + if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { + Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); glDeleteShader(vertShader); vertShader = 0; - glDeleteShader(fragShader); - fragShader = 0; glDeleteProgram(program); program = 0; return; } + + // Attach shaders + glAttachShader(program, vertShader); + glAttachShader(program, fragShader); + + { + if (!binaryFileName.empty() && (gl::ProgramParameteri != nullptr)) { + gl::ProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE); + } + + // Link program + GLint status; + glLinkProgram(program); + + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (status == 0) { + GLint logLength; + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + std::unique_ptr log = mbgl::util::make_unique(logLength); + glGetProgramInfoLog(program, logLength, &logLength, log.get()); + Log::Error(Event::Shader, "Program failed to link: %s", log.get()); + } + + glDeleteShader(vertShader); + vertShader = 0; + glDeleteShader(fragShader); + fragShader = 0; + glDeleteProgram(program); + program = 0; + return; + } + } } { @@ -69,10 +119,9 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo GLint logLength; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); - glGetProgramInfoLog(program, logLength, &logLength, log); - Log::Error(Event::Shader, "Program failed to validate: %s", log); - free(log); + std::unique_ptr log = mbgl::util::make_unique(logLength); + glGetProgramInfoLog(program, logLength, &logLength, log.get()); + Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); } glDeleteShader(vertShader); @@ -82,14 +131,15 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo glDeleteProgram(program); program = 0; } - } - // Remove the compiled shaders; they are now part of the program. - glDetachShader(program, vertShader); - glDeleteShader(vertShader); - glDetachShader(program, fragShader); - glDeleteShader(fragShader); + if (!skipCompile) { + // Remove the compiled shaders; they are now part of the program. + glDetachShader(program, vertShader); + glDeleteShader(vertShader); + glDetachShader(program, fragShader); + glDeleteShader(fragShader); + } valid = true; } @@ -100,7 +150,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { *shader = glCreateShader(type); const GLchar *strings[] = { source }; - const GLint lengths[] = { (GLint)strlen(source) }; + const GLsizei lengths[] = { (GLsizei)strlen(source) }; glShaderSource(*shader, 1, strings, lengths); glCompileShader(*shader); @@ -110,10 +160,9 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { GLint logLength; glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); - glGetShaderInfoLog(*shader, logLength, &logLength, log); - Log::Error(Event::Shader, "Shader failed to compile: %s", log); - free(log); + std::unique_ptr log = mbgl::util::make_unique(logLength); + glGetShaderInfoLog(*shader, logLength, &logLength, log.get()); + Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); } glDeleteShader(*shader); @@ -121,10 +170,41 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { return false; } + glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + if (status == GL_FALSE) { + Log::Error(Event::Shader, "Shader %s failed to compile.", name, type); + glDeleteShader(*shader); + *shader = 0; + return false; + } + return true; } Shader::~Shader() { + if (!binaryFileName.empty() && (gl::GetProgramBinary != nullptr)) { + // Retrieve the program binary + GLsizei binaryLength; + GLenum binaryFormat; + glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength); + if (binaryLength > 0) { + std::unique_ptr binary = mbgl::util::make_unique(binaryLength); + if (binary != nullptr) { + gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get()); + + // Write the binary to a file + FILE *binaryFile = fopen(binaryFileName.c_str(), "wb"); + if (binaryFile != nullptr) { + fwrite(&binaryLength, sizeof(binaryLength), 1, binaryFile); + fwrite(&binaryFormat, sizeof(binaryFormat), 1, binaryFile); + fwrite(binary.get(), binaryLength, 1, binaryFile); + fclose(binaryFile); + binaryFile = nullptr; + } + } + } + } + if (program) { glDeleteProgram(program); program = 0; diff --git a/shader.hpp b/shader.hpp index 27e831a5103..beaaa8b756e 100644 --- a/shader.hpp +++ b/shader.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace mbgl { @@ -21,6 +22,8 @@ class Shader : private util::noncopyable { private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); + + std::string binaryFileName; }; } From e66af041588f04cd833d91466ada8ead84f59821 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 10 Dec 2014 21:32:11 +1100 Subject: [PATCH 079/259] Use CHECK_ERROR on every GL call --- dot_shader.cpp | 6 +-- gaussian_shader.cpp | 6 +-- icon_shader.cpp | 54 ++++++++++++------------- line_shader.cpp | 18 ++++----- linejoin_shader.cpp | 6 +-- linepattern_shader.cpp | 18 ++++----- outline_shader.cpp | 6 +-- pattern_shader.cpp | 6 +-- plain_shader.cpp | 6 +-- raster_shader.cpp | 6 +-- sdf_shader.cpp | 90 +++++++++++++++++++++--------------------- shader.cpp | 78 ++++++++++++++++++------------------ uniform.cpp | 16 ++++---- uniform.hpp | 10 +++-- 14 files changed, 164 insertions(+), 162 deletions(-) diff --git a/dot_shader.cpp b/dot_shader.cpp index a897f410a71..9874f15efa4 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -17,10 +17,10 @@ DotShader::DotShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void DotShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); } diff --git a/gaussian_shader.cpp b/gaussian_shader.cpp index 9060f0ee714..9569d4047f6 100644 --- a/gaussian_shader.cpp +++ b/gaussian_shader.cpp @@ -19,10 +19,10 @@ GaussianShader::GaussianShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void GaussianShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/icon_shader.cpp b/icon_shader.cpp index 5c54177eb6c..a50c525b6ed 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -17,44 +17,44 @@ IconShader::IconShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); - a_offset = glGetAttribLocation(program, "a_offset"); - a_tex = glGetAttribLocation(program, "a_tex"); - a_angle = glGetAttribLocation(program, "a_angle"); - a_minzoom = glGetAttribLocation(program, "a_minzoom"); - a_maxzoom = glGetAttribLocation(program, "a_maxzoom"); - a_rangeend = glGetAttribLocation(program, "a_rangeend"); - a_rangestart = glGetAttribLocation(program, "a_rangestart"); - a_labelminzoom = glGetAttribLocation(program, "a_labelminzoom"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_offset = CHECK_ERROR(glGetAttribLocation(program, "a_offset")); + a_tex = CHECK_ERROR(glGetAttribLocation(program, "a_tex")); + a_angle = CHECK_ERROR(glGetAttribLocation(program, "a_angle")); + a_minzoom = CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); + a_maxzoom = CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); + a_rangeend = CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); + a_rangestart = CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); + a_labelminzoom = CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); } void IconShader::bind(char *offset) { const int stride = 20; - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - glEnableVertexAttribArray(a_offset); - glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4); + CHECK_ERROR(glEnableVertexAttribArray(a_offset)); + CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - glEnableVertexAttribArray(a_labelminzoom); - glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8); + CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); + CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - glEnableVertexAttribArray(a_minzoom); - glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9); + CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); + CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - glEnableVertexAttribArray(a_maxzoom); - glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10); + CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); + CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - glEnableVertexAttribArray(a_angle); - glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11); + CHECK_ERROR(glEnableVertexAttribArray(a_angle)); + CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - glEnableVertexAttribArray(a_rangeend); - glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12); + CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); + CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - glEnableVertexAttribArray(a_rangestart); - glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13); + CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); + CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - glEnableVertexAttribArray(a_tex); - glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16); + CHECK_ERROR(glEnableVertexAttribArray(a_tex)); + CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); } diff --git a/line_shader.cpp b/line_shader.cpp index 8353f4c6cae..3d8af9fd016 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -17,18 +17,18 @@ LineShader::LineShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); - a_extrude = glGetAttribLocation(program, "a_extrude"); - a_linesofar = glGetAttribLocation(program, "a_linesofar"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_extrude = CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); + a_linesofar = CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); } void LineShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - glEnableVertexAttribArray(a_extrude); - glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4); + CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); + CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); - glEnableVertexAttribArray(a_linesofar); - glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6); + CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); + CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); } diff --git a/linejoin_shader.cpp b/linejoin_shader.cpp index 050e180e00e..94c00fd0db8 100644 --- a/linejoin_shader.cpp +++ b/linejoin_shader.cpp @@ -17,11 +17,11 @@ LinejoinShader::LinejoinShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void LinejoinShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); // Note: We're referring to the vertices in a line array, which are 8 bytes long! - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); } diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 954dbd2b3ff..0a4503dd128 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -18,18 +18,18 @@ LinepatternShader::LinepatternShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); - a_extrude = glGetAttribLocation(program, "a_extrude"); - a_linesofar = glGetAttribLocation(program, "a_linesofar"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_extrude = CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); + a_linesofar = CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); } void LinepatternShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - glEnableVertexAttribArray(a_extrude); - glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4); + CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); + CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); - glEnableVertexAttribArray(a_linesofar); - glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6); + CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); + CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); } diff --git a/outline_shader.cpp b/outline_shader.cpp index ddabfa5d0d4..ef2f7dccf67 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -17,10 +17,10 @@ OutlineShader::OutlineShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void OutlineShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/pattern_shader.cpp b/pattern_shader.cpp index 31374bc3e8e..660c90c20a1 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -17,10 +17,10 @@ PatternShader::PatternShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void PatternShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/plain_shader.cpp b/plain_shader.cpp index 8a37837b309..4e636309b5a 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -17,10 +17,10 @@ PlainShader::PlainShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void PlainShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/raster_shader.cpp b/raster_shader.cpp index 7351f7d0c44..b9cdaed6b96 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -19,10 +19,10 @@ RasterShader::RasterShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void RasterShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/sdf_shader.cpp b/sdf_shader.cpp index b86733c0e4c..05541ce4e90 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -17,75 +17,75 @@ SDFShader::SDFShader() return; } - a_pos = glGetAttribLocation(program, "a_pos"); - a_offset = glGetAttribLocation(program, "a_offset"); - a_tex = glGetAttribLocation(program, "a_tex"); - a_angle = glGetAttribLocation(program, "a_angle"); - a_minzoom = glGetAttribLocation(program, "a_minzoom"); - a_maxzoom = glGetAttribLocation(program, "a_maxzoom"); - a_rangeend = glGetAttribLocation(program, "a_rangeend"); - a_rangestart = glGetAttribLocation(program, "a_rangestart"); - a_labelminzoom = glGetAttribLocation(program, "a_labelminzoom"); + a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_offset = CHECK_ERROR(glGetAttribLocation(program, "a_offset")); + a_tex = CHECK_ERROR(glGetAttribLocation(program, "a_tex")); + a_angle = CHECK_ERROR(glGetAttribLocation(program, "a_angle")); + a_minzoom = CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); + a_maxzoom = CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); + a_rangeend = CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); + a_rangestart = CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); + a_labelminzoom = CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); } void SDFGlyphShader::bind(char *offset) { const int stride = 16; - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - glEnableVertexAttribArray(a_offset); - glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4); + CHECK_ERROR(glEnableVertexAttribArray(a_offset)); + CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - glEnableVertexAttribArray(a_labelminzoom); - glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8); + CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); + CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - glEnableVertexAttribArray(a_minzoom); - glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9); + CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); + CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - glEnableVertexAttribArray(a_maxzoom); - glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10); + CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); + CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - glEnableVertexAttribArray(a_angle); - glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11); + CHECK_ERROR(glEnableVertexAttribArray(a_angle)); + CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - glEnableVertexAttribArray(a_rangeend); - glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12); + CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); + CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - glEnableVertexAttribArray(a_rangestart); - glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13); + CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); + CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - glEnableVertexAttribArray(a_tex); - glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14); + CHECK_ERROR(glEnableVertexAttribArray(a_tex)); + CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14)); } void SDFIconShader::bind(char *offset) { const int stride = 20; - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0); + CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - glEnableVertexAttribArray(a_offset); - glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4); + CHECK_ERROR(glEnableVertexAttribArray(a_offset)); + CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - glEnableVertexAttribArray(a_labelminzoom); - glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8); + CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); + CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - glEnableVertexAttribArray(a_minzoom); - glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9); + CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); + CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - glEnableVertexAttribArray(a_maxzoom); - glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10); + CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); + CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - glEnableVertexAttribArray(a_angle); - glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11); + CHECK_ERROR(glEnableVertexAttribArray(a_angle)); + CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - glEnableVertexAttribArray(a_rangeend); - glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12); + CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); + CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - glEnableVertexAttribArray(a_rangestart); - glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13); + CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); + CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - glEnableVertexAttribArray(a_tex); - glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16); + CHECK_ERROR(glEnableVertexAttribArray(a_tex)); + CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); } diff --git a/shader.cpp b/shader.cpp index af6ba627e11..73270dbddeb 100644 --- a/shader.cpp +++ b/shader.cpp @@ -16,7 +16,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo program(0) { util::stopwatch stopwatch("shader compilation", Event::Shader); - program = glCreateProgram(); + program = CHECK_ERROR(glCreateProgram()); if (!mbgl::platform::defaultShaderCache().empty()) { binaryFileName = mbgl::platform::defaultShaderCache() + name + ".bin"; @@ -39,11 +39,11 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo bool binaryOk = fread(binary.get(), binaryLength, 1, binaryFile) == 1; if (binaryOk) { - gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength); + CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); // Check if the binary was valid GLint status; - glGetProgramiv(program, GL_LINK_STATUS, &status); + CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); if (status == GL_TRUE) { skipCompile = true; } @@ -61,48 +61,48 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (!skipCompile) { if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); - glDeleteProgram(program); + CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); - glDeleteShader(vertShader); + CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - glDeleteProgram(program); + CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } // Attach shaders - glAttachShader(program, vertShader); - glAttachShader(program, fragShader); + CHECK_ERROR(glAttachShader(program, vertShader)); + CHECK_ERROR(glAttachShader(program, fragShader)); { if (!binaryFileName.empty() && (gl::ProgramParameteri != nullptr)) { - gl::ProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE); + CHECK_ERROR(gl::ProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE)); } // Link program GLint status; - glLinkProgram(program); + CHECK_ERROR(glLinkProgram(program)); - glGetProgramiv(program, GL_LINK_STATUS, &status); + CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); if (status == 0) { GLint logLength; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { std::unique_ptr log = mbgl::util::make_unique(logLength); - glGetProgramInfoLog(program, logLength, &logLength, log.get()); + CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } - glDeleteShader(vertShader); + CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - glDeleteShader(fragShader); + CHECK_ERROR(glDeleteShader(fragShader)); fragShader = 0; - glDeleteProgram(program); + CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } @@ -112,33 +112,33 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo { // Validate program GLint status; - glValidateProgram(program); + CHECK_ERROR(glValidateProgram(program)); - glGetProgramiv(program, GL_VALIDATE_STATUS, &status); + CHECK_ERROR(glGetProgramiv(program, GL_VALIDATE_STATUS, &status)); if (status == 0) { GLint logLength; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { std::unique_ptr log = mbgl::util::make_unique(logLength); - glGetProgramInfoLog(program, logLength, &logLength, log.get()); + CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); } - glDeleteShader(vertShader); + CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - glDeleteShader(fragShader); + CHECK_ERROR(glDeleteShader(fragShader)); fragShader = 0; - glDeleteProgram(program); + CHECK_ERROR(glDeleteProgram(program)); program = 0; } } if (!skipCompile) { // Remove the compiled shaders; they are now part of the program. - glDetachShader(program, vertShader); - glDeleteShader(vertShader); - glDetachShader(program, fragShader); - glDeleteShader(fragShader); + CHECK_ERROR(glDetachShader(program, vertShader)); + CHECK_ERROR(glDeleteShader(vertShader)); + CHECK_ERROR(glDetachShader(program, fragShader)); + CHECK_ERROR(glDeleteShader(fragShader)); } valid = true; @@ -148,32 +148,32 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { GLint status; - *shader = glCreateShader(type); + *shader = CHECK_ERROR(glCreateShader(type)); const GLchar *strings[] = { source }; const GLsizei lengths[] = { (GLsizei)strlen(source) }; - glShaderSource(*shader, 1, strings, lengths); + CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths)); - glCompileShader(*shader); + CHECK_ERROR(glCompileShader(*shader)); - glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); if (status == 0) { GLint logLength; - glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); + CHECK_ERROR(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { std::unique_ptr log = mbgl::util::make_unique(logLength); - glGetShaderInfoLog(*shader, logLength, &logLength, log.get()); + CHECK_ERROR(glGetShaderInfoLog(*shader, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); } - glDeleteShader(*shader); + CHECK_ERROR(glDeleteShader(*shader)); *shader = 0; return false; } - glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); if (status == GL_FALSE) { Log::Error(Event::Shader, "Shader %s failed to compile.", name, type); - glDeleteShader(*shader); + CHECK_ERROR(glDeleteShader(*shader)); *shader = 0; return false; } @@ -186,11 +186,11 @@ Shader::~Shader() { // Retrieve the program binary GLsizei binaryLength; GLenum binaryFormat; - glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength); + CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength)); if (binaryLength > 0) { std::unique_ptr binary = mbgl::util::make_unique(binaryLength); if (binary != nullptr) { - gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get()); + CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); // Write the binary to a file FILE *binaryFile = fopen(binaryFileName.c_str(), "wb"); @@ -206,7 +206,7 @@ Shader::~Shader() { } if (program) { - glDeleteProgram(program); + CHECK_ERROR(glDeleteProgram(program)); program = 0; valid = false; } diff --git a/uniform.cpp b/uniform.cpp index 24f179baf17..f2b03ac0b10 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -4,42 +4,42 @@ namespace mbgl { template <> void Uniform::bind(const float& t) { - glUniform1f(location, t); + CHECK_ERROR(glUniform1f(location, t)); } template <> void Uniform::bind(const int32_t& t) { - glUniform1i(location, t); + CHECK_ERROR(glUniform1i(location, t)); } template <> void Uniform>::bind(const std::array& t) { - glUniform2fv(location, 1, t.data()); + CHECK_ERROR(glUniform2fv(location, 1, t.data())); } template <> void Uniform>::bind(const std::array& t) { - glUniform3fv(location, 1, t.data()); + CHECK_ERROR(glUniform3fv(location, 1, t.data())); } template <> void Uniform>::bind(const std::array& t) { - glUniform4fv(location, 1, t.data()); + CHECK_ERROR(glUniform4fv(location, 1, t.data())); } template <> void UniformMatrix<2>::bind(const std::array& t) { - glUniformMatrix2fv(location, 1, GL_FALSE, t.data()); + CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data())); } template <> void UniformMatrix<3>::bind(const std::array& t) { - glUniformMatrix3fv(location, 1, GL_FALSE, t.data()); + CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, t.data())); } template <> void UniformMatrix<4>::bind(const std::array& t) { - glUniformMatrix4fv(location, 1, GL_FALSE, t.data()); + CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, t.data())); } // Add more as needed. diff --git a/uniform.hpp b/uniform.hpp index 8579ae22c74..9d0b9e24b9d 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -9,8 +9,9 @@ namespace mbgl { template class Uniform { public: - Uniform(const GLchar* name, const Shader& shader) - : location(glGetUniformLocation(shader.program, name)) {} + Uniform(const GLchar* name, const Shader& shader) { + location = CHECK_ERROR(glGetUniformLocation(shader.program, name)); + } void operator=(const T& t) { if (current != t) { @@ -31,8 +32,9 @@ class UniformMatrix { public: typedef std::array T; - UniformMatrix(const GLchar* name, const Shader& shader) - : location(glGetUniformLocation(shader.program, name)) {} + UniformMatrix(const GLchar* name, const Shader& shader) { + location = CHECK_ERROR(glGetUniformLocation(shader.program, name)); + } void operator=(const T& t) { if (current != t) { From 4bf07d526603ecc4305eba6276fa937ba1327965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 10 Dec 2014 13:21:08 +0100 Subject: [PATCH 080/259] update error reporting function --- dot_shader.cpp | 6 +-- gaussian_shader.cpp | 6 +-- icon_shader.cpp | 54 ++++++++++++------------- line_shader.cpp | 18 ++++----- linejoin_shader.cpp | 6 +-- linepattern_shader.cpp | 18 ++++----- outline_shader.cpp | 6 +-- pattern_shader.cpp | 6 +-- plain_shader.cpp | 6 +-- raster_shader.cpp | 6 +-- sdf_shader.cpp | 90 +++++++++++++++++++++--------------------- shader.cpp | 78 ++++++++++++++++++------------------ uniform.cpp | 16 ++++---- uniform.hpp | 4 +- 14 files changed, 160 insertions(+), 160 deletions(-) diff --git a/dot_shader.cpp b/dot_shader.cpp index 9874f15efa4..08b55a566b7 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -17,10 +17,10 @@ DotShader::DotShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void DotShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); } diff --git a/gaussian_shader.cpp b/gaussian_shader.cpp index 9569d4047f6..483de4867e1 100644 --- a/gaussian_shader.cpp +++ b/gaussian_shader.cpp @@ -19,10 +19,10 @@ GaussianShader::GaussianShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void GaussianShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/icon_shader.cpp b/icon_shader.cpp index a50c525b6ed..fa397fb2740 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -17,44 +17,44 @@ IconShader::IconShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); - a_offset = CHECK_ERROR(glGetAttribLocation(program, "a_offset")); - a_tex = CHECK_ERROR(glGetAttribLocation(program, "a_tex")); - a_angle = CHECK_ERROR(glGetAttribLocation(program, "a_angle")); - a_minzoom = CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); - a_maxzoom = CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); - a_rangeend = CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); - a_rangestart = CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); - a_labelminzoom = CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); + a_tex = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_tex")); + a_angle = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_angle")); + a_minzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); + a_maxzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); + a_rangeend = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); + a_rangestart = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); + a_labelminzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); } void IconShader::bind(char *offset) { const int stride = 20; - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - CHECK_ERROR(glEnableVertexAttribArray(a_offset)); - CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); - CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); - CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); - CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - CHECK_ERROR(glEnableVertexAttribArray(a_angle)); - CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); - CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); - CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - CHECK_ERROR(glEnableVertexAttribArray(a_tex)); - CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); } diff --git a/line_shader.cpp b/line_shader.cpp index 3d8af9fd016..5ad257eabde 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -17,18 +17,18 @@ LineShader::LineShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); - a_extrude = CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); - a_linesofar = CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); + a_linesofar = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); } void LineShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); - CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); - CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); - CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); } diff --git a/linejoin_shader.cpp b/linejoin_shader.cpp index 94c00fd0db8..5b9e7ba20a5 100644 --- a/linejoin_shader.cpp +++ b/linejoin_shader.cpp @@ -17,11 +17,11 @@ LinejoinShader::LinejoinShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void LinejoinShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); // Note: We're referring to the vertices in a line array, which are 8 bytes long! - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); } diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 0a4503dd128..492a8f2a850 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -18,18 +18,18 @@ LinepatternShader::LinepatternShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); - a_extrude = CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); - a_linesofar = CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); + a_linesofar = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); } void LinepatternShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); - CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); - CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); - CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); } diff --git a/outline_shader.cpp b/outline_shader.cpp index ef2f7dccf67..98d208297cb 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -17,10 +17,10 @@ OutlineShader::OutlineShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void OutlineShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/pattern_shader.cpp b/pattern_shader.cpp index 660c90c20a1..0a6013b17db 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -17,10 +17,10 @@ PatternShader::PatternShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void PatternShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/plain_shader.cpp b/plain_shader.cpp index 4e636309b5a..ce7ddae918a 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -17,10 +17,10 @@ PlainShader::PlainShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void PlainShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/raster_shader.cpp b/raster_shader.cpp index b9cdaed6b96..14c6ddc7c4b 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -19,10 +19,10 @@ RasterShader::RasterShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void RasterShader::bind(char *offset) { - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 05541ce4e90..25b226ee230 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -17,75 +17,75 @@ SDFShader::SDFShader() return; } - a_pos = CHECK_ERROR(glGetAttribLocation(program, "a_pos")); - a_offset = CHECK_ERROR(glGetAttribLocation(program, "a_offset")); - a_tex = CHECK_ERROR(glGetAttribLocation(program, "a_tex")); - a_angle = CHECK_ERROR(glGetAttribLocation(program, "a_angle")); - a_minzoom = CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); - a_maxzoom = CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); - a_rangeend = CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); - a_rangestart = CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); - a_labelminzoom = CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); + a_tex = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_tex")); + a_angle = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_angle")); + a_minzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); + a_maxzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); + a_rangeend = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); + a_rangestart = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); + a_labelminzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); } void SDFGlyphShader::bind(char *offset) { const int stride = 16; - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - CHECK_ERROR(glEnableVertexAttribArray(a_offset)); - CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); - CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); - CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); - CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - CHECK_ERROR(glEnableVertexAttribArray(a_angle)); - CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); - CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); - CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - CHECK_ERROR(glEnableVertexAttribArray(a_tex)); - CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14)); } void SDFIconShader::bind(char *offset) { const int stride = 20; - CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - CHECK_ERROR(glEnableVertexAttribArray(a_offset)); - CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); - CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); - CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); - CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - CHECK_ERROR(glEnableVertexAttribArray(a_angle)); - CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); - CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); - CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - CHECK_ERROR(glEnableVertexAttribArray(a_tex)); - CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); } diff --git a/shader.cpp b/shader.cpp index 73270dbddeb..c43863b52cd 100644 --- a/shader.cpp +++ b/shader.cpp @@ -16,7 +16,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo program(0) { util::stopwatch stopwatch("shader compilation", Event::Shader); - program = CHECK_ERROR(glCreateProgram()); + program = MBGL_CHECK_ERROR(glCreateProgram()); if (!mbgl::platform::defaultShaderCache().empty()) { binaryFileName = mbgl::platform::defaultShaderCache() + name + ".bin"; @@ -39,11 +39,11 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo bool binaryOk = fread(binary.get(), binaryLength, 1, binaryFile) == 1; if (binaryOk) { - CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); // Check if the binary was valid GLint status; - CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); if (status == GL_TRUE) { skipCompile = true; } @@ -61,48 +61,48 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (!skipCompile) { if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); - CHECK_ERROR(glDeleteProgram(program)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); - CHECK_ERROR(glDeleteShader(vertShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - CHECK_ERROR(glDeleteProgram(program)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } // Attach shaders - CHECK_ERROR(glAttachShader(program, vertShader)); - CHECK_ERROR(glAttachShader(program, fragShader)); + MBGL_CHECK_ERROR(glAttachShader(program, vertShader)); + MBGL_CHECK_ERROR(glAttachShader(program, fragShader)); { if (!binaryFileName.empty() && (gl::ProgramParameteri != nullptr)) { - CHECK_ERROR(gl::ProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE)); + MBGL_CHECK_ERROR(gl::ProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE)); } // Link program GLint status; - CHECK_ERROR(glLinkProgram(program)); + MBGL_CHECK_ERROR(glLinkProgram(program)); - CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); if (status == 0) { GLint logLength; - CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { std::unique_ptr log = mbgl::util::make_unique(logLength); - CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); + MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } - CHECK_ERROR(glDeleteShader(vertShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - CHECK_ERROR(glDeleteShader(fragShader)); + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); fragShader = 0; - CHECK_ERROR(glDeleteProgram(program)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } @@ -112,33 +112,33 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo { // Validate program GLint status; - CHECK_ERROR(glValidateProgram(program)); + MBGL_CHECK_ERROR(glValidateProgram(program)); - CHECK_ERROR(glGetProgramiv(program, GL_VALIDATE_STATUS, &status)); + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_VALIDATE_STATUS, &status)); if (status == 0) { GLint logLength; - CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { std::unique_ptr log = mbgl::util::make_unique(logLength); - CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); + MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); } - CHECK_ERROR(glDeleteShader(vertShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - CHECK_ERROR(glDeleteShader(fragShader)); + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); fragShader = 0; - CHECK_ERROR(glDeleteProgram(program)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; } } if (!skipCompile) { // Remove the compiled shaders; they are now part of the program. - CHECK_ERROR(glDetachShader(program, vertShader)); - CHECK_ERROR(glDeleteShader(vertShader)); - CHECK_ERROR(glDetachShader(program, fragShader)); - CHECK_ERROR(glDeleteShader(fragShader)); + MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); + MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); } valid = true; @@ -148,32 +148,32 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { GLint status; - *shader = CHECK_ERROR(glCreateShader(type)); + *shader = MBGL_CHECK_ERROR(glCreateShader(type)); const GLchar *strings[] = { source }; const GLsizei lengths[] = { (GLsizei)strlen(source) }; - CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths)); + MBGL_CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths)); - CHECK_ERROR(glCompileShader(*shader)); + MBGL_CHECK_ERROR(glCompileShader(*shader)); - CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); + MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); if (status == 0) { GLint logLength; - CHECK_ERROR(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength)); + MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { std::unique_ptr log = mbgl::util::make_unique(logLength); - CHECK_ERROR(glGetShaderInfoLog(*shader, logLength, &logLength, log.get())); + MBGL_CHECK_ERROR(glGetShaderInfoLog(*shader, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); } - CHECK_ERROR(glDeleteShader(*shader)); + MBGL_CHECK_ERROR(glDeleteShader(*shader)); *shader = 0; return false; } - CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); + MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); if (status == GL_FALSE) { Log::Error(Event::Shader, "Shader %s failed to compile.", name, type); - CHECK_ERROR(glDeleteShader(*shader)); + MBGL_CHECK_ERROR(glDeleteShader(*shader)); *shader = 0; return false; } @@ -186,11 +186,11 @@ Shader::~Shader() { // Retrieve the program binary GLsizei binaryLength; GLenum binaryFormat; - CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength)); + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength)); if (binaryLength > 0) { std::unique_ptr binary = mbgl::util::make_unique(binaryLength); if (binary != nullptr) { - CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); + MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); // Write the binary to a file FILE *binaryFile = fopen(binaryFileName.c_str(), "wb"); @@ -206,7 +206,7 @@ Shader::~Shader() { } if (program) { - CHECK_ERROR(glDeleteProgram(program)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; valid = false; } diff --git a/uniform.cpp b/uniform.cpp index f2b03ac0b10..c013699bfd8 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -4,42 +4,42 @@ namespace mbgl { template <> void Uniform::bind(const float& t) { - CHECK_ERROR(glUniform1f(location, t)); + MBGL_CHECK_ERROR(glUniform1f(location, t)); } template <> void Uniform::bind(const int32_t& t) { - CHECK_ERROR(glUniform1i(location, t)); + MBGL_CHECK_ERROR(glUniform1i(location, t)); } template <> void Uniform>::bind(const std::array& t) { - CHECK_ERROR(glUniform2fv(location, 1, t.data())); + MBGL_CHECK_ERROR(glUniform2fv(location, 1, t.data())); } template <> void Uniform>::bind(const std::array& t) { - CHECK_ERROR(glUniform3fv(location, 1, t.data())); + MBGL_CHECK_ERROR(glUniform3fv(location, 1, t.data())); } template <> void Uniform>::bind(const std::array& t) { - CHECK_ERROR(glUniform4fv(location, 1, t.data())); + MBGL_CHECK_ERROR(glUniform4fv(location, 1, t.data())); } template <> void UniformMatrix<2>::bind(const std::array& t) { - CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data())); + MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data())); } template <> void UniformMatrix<3>::bind(const std::array& t) { - CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, t.data())); + MBGL_CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, t.data())); } template <> void UniformMatrix<4>::bind(const std::array& t) { - CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, t.data())); + MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, t.data())); } // Add more as needed. diff --git a/uniform.hpp b/uniform.hpp index 9d0b9e24b9d..9a25d105cfa 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -10,7 +10,7 @@ template class Uniform { public: Uniform(const GLchar* name, const Shader& shader) { - location = CHECK_ERROR(glGetUniformLocation(shader.program, name)); + location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); } void operator=(const T& t) { @@ -33,7 +33,7 @@ class UniformMatrix { typedef std::array T; UniformMatrix(const GLchar* name, const Shader& shader) { - location = CHECK_ERROR(glGetUniformLocation(shader.program, name)); + location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); } void operator=(const T& t) { From 9689401995a843289faa6ac9919fcee397f47e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 25 Nov 2014 17:42:05 +0100 Subject: [PATCH 081/259] Align vertex attributes at 4 byte boundaries - Introduces a sprite atlas - Moves icon rendering to use the sprite atlas - Unifies icon and glyph buffer structures and vertex shaders --- icon.vertex.glsl | 18 +++++++++++------- sdf.vertex.glsl | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 8c69c404100..fd7afd5b7d9 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -1,12 +1,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; -attribute vec2 a_tex; -attribute float a_angle; -attribute float a_minzoom; -attribute float a_maxzoom; -attribute float a_rangeend; -attribute float a_rangestart; -attribute float a_labelminzoom; +attribute vec4 a_data1; +attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting @@ -28,6 +23,15 @@ varying vec2 v_tex; varying float v_alpha; void main() { + vec2 a_tex = a_data1.xy; + float a_labelminzoom = a_data1[2]; + float a_angle = a_data1[3]; + vec2 a_zoom = a_data2.st; + float a_minzoom = a_zoom[0]; + float a_maxzoom = a_zoom[1]; + vec2 a_range = a_data2.pq; + float a_rangeend = a_range[0]; + float a_rangestart = a_range[1]; float a_fadedist = 10.0; float rev = 0.0; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index c5166ae46f8..bbfc44919e3 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -1,12 +1,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; -attribute vec2 a_tex; -attribute float a_angle; -attribute float a_minzoom; -attribute float a_maxzoom; -attribute float a_rangeend; -attribute float a_rangestart; -attribute float a_labelminzoom; +attribute vec4 a_data1; +attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting @@ -27,6 +22,15 @@ varying vec2 v_tex; varying float v_alpha; void main() { + vec2 a_tex = a_data1.xy; + float a_labelminzoom = a_data1[2]; + float a_angle = a_data1[3]; + vec2 a_zoom = a_data2.st; + float a_minzoom = a_zoom[0]; + float a_maxzoom = a_zoom[1]; + vec2 a_range = a_data2.pq; + float a_rangeend = a_range[0]; + float a_rangestart = a_range[1]; float rev = 0.0; From d96df9418129a4b8e34b94dd73a3d28ec2a1ff47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 12 Dec 2014 11:59:27 +0100 Subject: [PATCH 082/259] fix remaining rendering issues --- line.vertex.glsl | 6 ++++-- linepattern.vertex.glsl | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index 1d8e687c957..bf0b537e83f 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -7,8 +7,7 @@ #define scale 0.015873016 attribute vec2 a_pos; -attribute vec2 a_extrude; -attribute float a_linesofar; +attribute vec4 a_data; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -24,6 +23,9 @@ varying vec2 v_normal; varying float v_linesofar; void main() { + vec2 a_extrude = a_data.xy; + float a_linesofar = a_data.z * 128.0 + a_data.w; + // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 4600ebf65b4..ada384a3d10 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -3,11 +3,11 @@ // stored in a byte (-128..127). we scale regular normals up to length 63, but // there are also "special" normals that have a bigger length (of up to 126 in // this case). -#define scale 63.0 +// #define scale 63.0 +#define scale 0.015873016 attribute vec2 a_pos; -attribute vec2 a_extrude; -attribute float a_linesofar; +attribute vec4 a_data; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -24,6 +24,9 @@ varying vec2 v_normal; varying float v_linesofar; void main() { + vec2 a_extrude = a_data.xy; + float a_linesofar = a_data.z * 128.0 + a_data.w; + // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap @@ -34,7 +37,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec2 extrude = a_extrude / scale; + vec2 extrude = a_extrude * scale; vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); // If the x coordinate is the maximum integer, we move the z coordinates out From a4634d696966b9dbb52a84e48ff65746fd6add91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 11 Nov 2014 16:56:20 +0100 Subject: [PATCH 083/259] use 4-byte aligned vertex attributes for performance reason reverts 9d5f02ccaa051a0f3459f6fc94df807338fa2552 and 4c0b4a79017bc7c7ae864e6f961f186605be617f --- icon.vertex.glsl | 18 +++++++++------ icon_shader.cpp | 34 ++++++----------------------- icon_shader.hpp | 9 ++------ line.vertex.glsl | 6 +++-- line_shader.cpp | 10 +++------ line_shader.hpp | 3 +-- sdf.vertex.glsl | 18 +++++++++------ sdf_shader.cpp | 57 ++++++++++-------------------------------------- sdf_shader.hpp | 9 ++------ 9 files changed, 52 insertions(+), 112 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 8c69c404100..fd7afd5b7d9 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -1,12 +1,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; -attribute vec2 a_tex; -attribute float a_angle; -attribute float a_minzoom; -attribute float a_maxzoom; -attribute float a_rangeend; -attribute float a_rangestart; -attribute float a_labelminzoom; +attribute vec4 a_data1; +attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting @@ -28,6 +23,15 @@ varying vec2 v_tex; varying float v_alpha; void main() { + vec2 a_tex = a_data1.xy; + float a_labelminzoom = a_data1[2]; + float a_angle = a_data1[3]; + vec2 a_zoom = a_data2.st; + float a_minzoom = a_zoom[0]; + float a_maxzoom = a_zoom[1]; + vec2 a_range = a_data2.pq; + float a_rangeend = a_range[0]; + float a_rangestart = a_range[1]; float a_fadedist = 10.0; float rev = 0.0; diff --git a/icon_shader.cpp b/icon_shader.cpp index fa397fb2740..0dfd67e25b0 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -19,17 +19,12 @@ IconShader::IconShader() a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); - a_tex = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_tex")); - a_angle = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_angle")); - a_minzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); - a_maxzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); - a_rangeend = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); - a_rangestart = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); - a_labelminzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); + a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); + a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); } void IconShader::bind(char *offset) { - const int stride = 20; + const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); @@ -37,24 +32,9 @@ void IconShader::bind(char *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); } diff --git a/icon_shader.hpp b/icon_shader.hpp index 645d7e21b63..155b9addca6 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -27,13 +27,8 @@ class IconShader : public Shader { private: int32_t a_pos = -1; int32_t a_offset = -1; - int32_t a_tex = -1; - int32_t a_angle = -1; - int32_t a_minzoom = -1; - int32_t a_maxzoom = -1; - int32_t a_rangeend = -1; - int32_t a_rangestart = -1; - int32_t a_labelminzoom = -1; + int32_t a_data1 = -1; + int32_t a_data2 = -1; }; } diff --git a/line.vertex.glsl b/line.vertex.glsl index 1d8e687c957..bf0b537e83f 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -7,8 +7,7 @@ #define scale 0.015873016 attribute vec2 a_pos; -attribute vec2 a_extrude; -attribute float a_linesofar; +attribute vec4 a_data; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -24,6 +23,9 @@ varying vec2 v_normal; varying float v_linesofar; void main() { + vec2 a_extrude = a_data.xy; + float a_linesofar = a_data.z * 128.0 + a_data.w; + // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap diff --git a/line_shader.cpp b/line_shader.cpp index 5ad257eabde..432a64f6950 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -18,17 +18,13 @@ LineShader::LineShader() } a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); - a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); - a_linesofar = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } void LineShader::bind(char *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); } diff --git a/line_shader.hpp b/line_shader.hpp index b789330882c..c6adc0ff8db 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -22,8 +22,7 @@ class LineShader : public Shader { private: int32_t a_pos = -1; - int32_t a_extrude = -1; - int32_t a_linesofar = -1; + int32_t a_data = -1; }; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index c5166ae46f8..bbfc44919e3 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -1,12 +1,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; -attribute vec2 a_tex; -attribute float a_angle; -attribute float a_minzoom; -attribute float a_maxzoom; -attribute float a_rangeend; -attribute float a_rangestart; -attribute float a_labelminzoom; +attribute vec4 a_data1; +attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting @@ -27,6 +22,15 @@ varying vec2 v_tex; varying float v_alpha; void main() { + vec2 a_tex = a_data1.xy; + float a_labelminzoom = a_data1[2]; + float a_angle = a_data1[3]; + vec2 a_zoom = a_data2.st; + float a_minzoom = a_zoom[0]; + float a_maxzoom = a_zoom[1]; + vec2 a_range = a_data2.pq; + float a_rangeend = a_range[0]; + float a_rangestart = a_range[1]; float rev = 0.0; diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 25b226ee230..757884f39c7 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -19,13 +19,8 @@ SDFShader::SDFShader() a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); - a_tex = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_tex")); - a_angle = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_angle")); - a_minzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_minzoom")); - a_maxzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom")); - a_rangeend = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangeend")); - a_rangestart = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangestart")); - a_labelminzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom")); + a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); + a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); } void SDFGlyphShader::bind(char *offset) { @@ -37,30 +32,15 @@ void SDFGlyphShader::bind(char *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); } void SDFIconShader::bind(char *offset) { - const int stride = 20; + const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); @@ -68,24 +48,9 @@ void SDFIconShader::bind(char *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); } diff --git a/sdf_shader.hpp b/sdf_shader.hpp index 0737c25ee10..08f3053b7d4 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -29,13 +29,8 @@ class SDFShader : public Shader { protected: int32_t a_pos = -1; int32_t a_offset = -1; - int32_t a_tex = -1; - int32_t a_angle = -1; - int32_t a_minzoom = -1; - int32_t a_maxzoom = -1; - int32_t a_rangeend = -1; - int32_t a_rangestart = -1; - int32_t a_labelminzoom = -1; + int32_t a_data1 = -1; + int32_t a_data2 = -1; }; class SDFGlyphShader : public SDFShader { From 4934940256d08856c3affcd02fbc66ffa9878a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 11 Dec 2014 11:58:46 +0100 Subject: [PATCH 084/259] fix rendering errors --- linepattern.vertex.glsl | 11 +++++++---- linepattern_shader.cpp | 11 +++-------- linepattern_shader.hpp | 3 +-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 4600ebf65b4..ada384a3d10 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -3,11 +3,11 @@ // stored in a byte (-128..127). we scale regular normals up to length 63, but // there are also "special" normals that have a bigger length (of up to 126 in // this case). -#define scale 63.0 +// #define scale 63.0 +#define scale 0.015873016 attribute vec2 a_pos; -attribute vec2 a_extrude; -attribute float a_linesofar; +attribute vec4 a_data; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -24,6 +24,9 @@ varying vec2 v_normal; varying float v_linesofar; void main() { + vec2 a_extrude = a_data.xy; + float a_linesofar = a_data.z * 128.0 + a_data.w; + // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap @@ -34,7 +37,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec2 extrude = a_extrude / scale; + vec2 extrude = a_extrude * scale; vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); // If the x coordinate is the maximum integer, we move the z coordinates out diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 492a8f2a850..c45378378d6 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include @@ -19,17 +18,13 @@ LinepatternShader::LinepatternShader() } a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); - a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); - a_linesofar = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_linesofar")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } void LinepatternShader::bind(char *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_linesofar)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); } diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index bf85940b8a7..ace8198aedc 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -25,8 +25,7 @@ class LinepatternShader : public Shader { private: int32_t a_pos = -1; - int32_t a_extrude = -1; - int32_t a_linesofar = -1; + int32_t a_data = -1; }; } From dd868e0b4cffa6d42fb3d8bb0c14067693f69b85 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Sat, 20 Dec 2014 14:15:33 +1300 Subject: [PATCH 085/259] Use iostream for saving GL program binary. Also check for GL_NUM_PROGRAM_BINARY_FORMATS > 0. --- shader.cpp | 71 ++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/shader.cpp b/shader.cpp index c43863b52cd..62edf1d3826 100644 --- a/shader.cpp +++ b/shader.cpp @@ -5,8 +5,9 @@ #include #include -#include #include +#include +#include using namespace mbgl; @@ -25,35 +26,26 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo // Load binary shader if it exists bool skipCompile = false; if (!binaryFileName.empty() && (gl::ProgramBinary != nullptr)) { - FILE *binaryFile = fopen(binaryFileName.c_str(), "rb"); - if (binaryFile != nullptr) { - GLsizei binaryLength; - GLenum binaryFormat; - bool lengthOk = fread(&binaryLength, sizeof(binaryLength), 1, binaryFile) == 1; - bool formatOk = fread(&binaryFormat, sizeof(binaryFormat), 1, binaryFile) == 1; - - if (lengthOk && formatOk && binaryLength > 0) { - std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - - if (binary != nullptr) { - bool binaryOk = fread(binary.get(), binaryLength, 1, binaryFile) == 1; - - if (binaryOk) { - MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); - - // Check if the binary was valid - GLint status; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); - if (status == GL_TRUE) { - skipCompile = true; - } - } - } - } + std::ifstream binaryFile(binaryFileName, std::ios::in | std::ios::binary); + + GLsizei binaryLength; + GLenum binaryFormat; + binaryFile.read(reinterpret_cast(&binaryLength), sizeof(binaryLength)); + binaryFile.read(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); + + std::unique_ptr binary = mbgl::util::make_unique(binaryLength); + binaryFile.read(binary.get(), binaryLength); - fclose(binaryFile); - binaryFile = nullptr; + MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + + // Check if the binary was valid + GLint status; + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + if (status == GL_TRUE) { + skipCompile = true; } + + binaryFile.close(); } GLuint vertShader = 0; @@ -150,7 +142,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { *shader = MBGL_CHECK_ERROR(glCreateShader(type)); const GLchar *strings[] = { source }; - const GLsizei lengths[] = { (GLsizei)strlen(source) }; + const GLsizei lengths[] = { (GLsizei)std::strlen(source) }; MBGL_CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths)); MBGL_CHECK_ERROR(glCompileShader(*shader)); @@ -189,19 +181,14 @@ Shader::~Shader() { MBGL_CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength)); if (binaryLength > 0) { std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - if (binary != nullptr) { - MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); - - // Write the binary to a file - FILE *binaryFile = fopen(binaryFileName.c_str(), "wb"); - if (binaryFile != nullptr) { - fwrite(&binaryLength, sizeof(binaryLength), 1, binaryFile); - fwrite(&binaryFormat, sizeof(binaryFormat), 1, binaryFile); - fwrite(binary.get(), binaryLength, 1, binaryFile); - fclose(binaryFile); - binaryFile = nullptr; - } - } + MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); + + // Write the binary to a file + std::ofstream binaryFile(binaryFileName, std::ios::out | std::ios::trunc | std::ios::binary); + binaryFile.write(reinterpret_cast(&binaryLength), sizeof(binaryLength)); + binaryFile.write(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); + binaryFile.write(binary.get(), binaryLength); + binaryFile.close(); } } From 87a59884baef1eaa2665a8bf0497209337cfe42e Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 24 Dec 2014 08:12:20 +1300 Subject: [PATCH 086/259] Tidy up a few missed things in shader.cpp --- shader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shader.cpp b/shader.cpp index 62edf1d3826..87e841f420e 100644 --- a/shader.cpp +++ b/shader.cpp @@ -35,6 +35,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo std::unique_ptr binary = mbgl::util::make_unique(binaryLength); binaryFile.read(binary.get(), binaryLength); + binaryFile.close(); MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); @@ -44,8 +45,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (status == GL_TRUE) { skipCompile = true; } - - binaryFile.close(); } GLuint vertShader = 0; @@ -142,7 +141,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { *shader = MBGL_CHECK_ERROR(glCreateShader(type)); const GLchar *strings[] = { source }; - const GLsizei lengths[] = { (GLsizei)std::strlen(source) }; + const GLsizei lengths[] = { static_cast(std::strlen(source)) }; MBGL_CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths)); MBGL_CHECK_ERROR(glCompileShader(*shader)); From 61c24b90b5cedb8bac6c6b19033f014817840d10 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Mon, 5 Jan 2015 12:28:32 +1300 Subject: [PATCH 087/259] Add failsafe to program binary loading --- shader.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/shader.cpp b/shader.cpp index 87e841f420e..d39e1f62e95 100644 --- a/shader.cpp +++ b/shader.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using namespace mbgl; @@ -33,17 +34,47 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo binaryFile.read(reinterpret_cast(&binaryLength), sizeof(binaryLength)); binaryFile.read(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); - std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - binaryFile.read(binary.get(), binaryLength); - binaryFile.close(); - MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + GLint numBinaryFormats; + MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats)); - // Check if the binary was valid - GLint status; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); - if (status == GL_TRUE) { - skipCompile = true; + std::unique_ptr validBinaryFormats = mbgl::util::make_unique(numBinaryFormats); + MBGL_CHECK_ERROR(glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, reinterpret_cast(validBinaryFormats.get()))); + + bool validBinaryFormat = false; + for (GLint i = 0; i < numBinaryFormats; i++) { + if (validBinaryFormats[i] == binaryFormat) { + validBinaryFormat = true; + } + } + if (!validBinaryFormat) { + Log::Error(Event::OpenGL, "Trying load program binary with an invalid binaryFormat!"); + } + + if (binaryLength == 0) { + Log::Error(Event::OpenGL, "Trying load program binary with a zero length binary!"); + } + + if (validBinaryFormat && (binaryLength != 0)) { + + std::unique_ptr binary = mbgl::util::make_unique(binaryLength); + binaryFile.read(binary.get(), binaryLength); + binaryFile.close(); + + Log::Error(Event::OpenGL, "glProgramBinary(%u, %u, %u, %u)", program, binaryFormat, binary.get(), binaryLength); + MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + + // Check if the binary was valid + GLint status; + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + if (status == GL_TRUE) { + skipCompile = true; + } + } else { + binaryFile.close(); + + // Delete the bad file + std::remove(binaryFileName.c_str()); } } @@ -180,7 +211,9 @@ Shader::~Shader() { MBGL_CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength)); if (binaryLength > 0) { std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); + MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, nullptr, &binaryFormat, binary.get())); + + Log::Error(Event::OpenGL, "glGetProgramBinary(%u, %u, nullptr, %u, %u)", program, binaryLength, binaryFormat, binary.get()); // Write the binary to a file std::ofstream binaryFile(binaryFileName, std::ios::out | std::ios::trunc | std::ios::binary); From 186140bdf4c87bb1e9d06109b5aee67390dda80a Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 6 Jan 2015 12:37:23 -0500 Subject: [PATCH 088/259] fix extrudes, rotation, and unskew labels --- line.vertex.glsl | 3 +-- sdf.vertex.glsl | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index 1d8e687c957..abb23cc4868 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -13,7 +13,6 @@ attribute float a_linesofar; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. uniform mat4 u_matrix; -uniform mat4 u_exmatrix; // shared uniform float u_ratio; @@ -40,6 +39,6 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar * u_ratio; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index c5166ae46f8..4ff194186ea 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -64,6 +64,13 @@ void main() { // hide if (angle >= a_rangeend && angle < rangestart) z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1); + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); + + //if (u_flip == 0.0) { + //extrude *= gl_Position.w; + //} + + gl_Position += extrude; v_tex = a_tex / u_texsize; } From 2b8bf3998b9a1cf6fe0292da7e05c99385c36342 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 13 Jan 2015 19:48:00 +1100 Subject: [PATCH 089/259] remove extra line --- shader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/shader.cpp b/shader.cpp index d39e1f62e95..6e52126aa9d 100644 --- a/shader.cpp +++ b/shader.cpp @@ -34,7 +34,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo binaryFile.read(reinterpret_cast(&binaryLength), sizeof(binaryLength)); binaryFile.read(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); - GLint numBinaryFormats; MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats)); From e6c8be83979fee9f926c3e4d62d2ccde274791cd Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Mon, 12 Jan 2015 12:35:09 +1100 Subject: [PATCH 090/259] Check for IO errors when loading binary shader. Fixes #740 --- shader.cpp | 78 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/shader.cpp b/shader.cpp index 62edf1d3826..32e10a64007 100644 --- a/shader.cpp +++ b/shader.cpp @@ -26,26 +26,53 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo // Load binary shader if it exists bool skipCompile = false; if (!binaryFileName.empty() && (gl::ProgramBinary != nullptr)) { - std::ifstream binaryFile(binaryFileName, std::ios::in | std::ios::binary); + try { + std::ifstream binaryFile(binaryFileName, std::ios::in | std::ios::binary); + binaryFile.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); - GLsizei binaryLength; - GLenum binaryFormat; - binaryFile.read(reinterpret_cast(&binaryLength), sizeof(binaryLength)); - binaryFile.read(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); + GLsizei binaryLength; + GLenum binaryFormat; + binaryFile.read(reinterpret_cast(&binaryLength), sizeof(binaryLength)); + binaryFile.read(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); - std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - binaryFile.read(binary.get(), binaryLength); + GLint numBinaryFormats; + MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats)); - MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + std::unique_ptr validBinaryFormats = mbgl::util::make_unique(numBinaryFormats); + MBGL_CHECK_ERROR(glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, reinterpret_cast(validBinaryFormats.get()))); - // Check if the binary was valid - GLint status; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); - if (status == GL_TRUE) { - skipCompile = true; - } + bool validBinaryFormat = false; + for (GLint i = 0; i < numBinaryFormats; i++) { + if (validBinaryFormats[i] == binaryFormat) { + validBinaryFormat = true; + } + } + if (!validBinaryFormat) { + throw std::runtime_error("Trying load program binary with an invalid binaryFormat!"); + } + + if (binaryLength == 0) { + throw std::runtime_error("Trying load program binary with a zero length binary!"); + } + + std::unique_ptr binary = mbgl::util::make_unique(binaryLength); + binaryFile.read(binary.get(), binaryLength); - binaryFile.close(); + MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + + // Check if the binary was valid + GLint status; + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + if (status == GL_TRUE) { + skipCompile = true; + } + + } catch(std::exception& e) { + Log::Error(Event::Shader, "Loading binary shader failed!"); + + // Delete the bad file + std::remove(binaryFileName.c_str()); + } } GLuint vertShader = 0; @@ -183,12 +210,21 @@ Shader::~Shader() { std::unique_ptr binary = mbgl::util::make_unique(binaryLength); MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get())); - // Write the binary to a file - std::ofstream binaryFile(binaryFileName, std::ios::out | std::ios::trunc | std::ios::binary); - binaryFile.write(reinterpret_cast(&binaryLength), sizeof(binaryLength)); - binaryFile.write(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); - binaryFile.write(binary.get(), binaryLength); - binaryFile.close(); + try { + // Write the binary to a file + std::ofstream binaryFile(binaryFileName, std::ios::out | std::ios::trunc | std::ios::binary); + binaryFile.exceptions(std::ofstream::failbit | std::ofstream::badbit | std::ofstream::eofbit); + + binaryFile.write(reinterpret_cast(&binaryLength), sizeof(binaryLength)); + binaryFile.write(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); + binaryFile.write(binary.get(), binaryLength); + + } catch(std::exception& e) { + Log::Error(Event::Shader, "Saving binary shader failed!"); + + // Delete the bad file + std::remove(binaryFileName.c_str()); + } } } From 7d06ccc074bce791520837cde50d0b7ffc449456 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 13 Jan 2015 17:16:00 -0500 Subject: [PATCH 091/259] dashes: no spinning, any length, round caps Instead of spinning, dashes stretch before reseting at every round zoom. Dash and space length units are now in terms of the line width, not pixels. Dasharrays can be any length, not just 2. Lines with "line-cap": "round" will have round dashes. --- linesdfpattern.fragment.glsl | 25 +++++++++++++++++ linesdfpattern.vertex.glsl | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 linesdfpattern.fragment.glsl create mode 100644 linesdfpattern.vertex.glsl diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl new file mode 100644 index 00000000000..3cc8a63748f --- /dev/null +++ b/linesdfpattern.fragment.glsl @@ -0,0 +1,25 @@ +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_blur; +uniform sampler2D u_image; +uniform float u_sdfgamma; + + +varying vec2 v_normal; +varying float v_linesofar; +varying vec2 v_tex; + +void main() { + // Calculate the distance of the pixel from the line in pixels. + float dist = length(v_normal) * u_linewidth.s; + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + + float sdfdist = texture2D(u_image, v_tex).a; + alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); + + gl_FragColor = u_color * alpha; +} diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl new file mode 100644 index 00000000000..7c779855145 --- /dev/null +++ b/linesdfpattern.vertex.glsl @@ -0,0 +1,52 @@ +// floor(127 / 2) == 63.0 +// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is +// stored in a byte (-128..127). we scale regular normals up to length 63, but +// there are also "special" normals that have a bigger length (of up to 126 in +// this case). +// #define scale 63.0 +#define scale 0.015873016 + +attribute vec2 a_pos; +attribute vec4 a_data; + +// matrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_matrix; +uniform mat4 u_exmatrix; + +uniform vec2 u_linewidth; +uniform float u_ratio; +uniform vec2 u_patternscale; +uniform float u_tex_y; + +varying vec2 v_normal; +varying float v_linesofar; +varying vec2 v_tex; + +void main() { + vec2 a_extrude = a_data.xy; + float a_linesofar = a_data.z * 128.0 + a_data.w; + + // We store the texture normals in the most insignificant bit + // transform y so that 0 => -1 and 1 => 1 + // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap + // y is 1 if the normal points up, and -1 if it points down + vec2 normal = mod(a_pos, 2.0); + normal.y = sign(normal.y - 0.5); + v_normal = normal; + + // Scale the extrusion vector down to a normal and then up by the line width + // of this vertex. + vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + + // Remove the texture normal bit of the position before scaling it with the + // model/view matrix. Add the extrusion vector *after* the model/view matrix + // because we're extruding the line in pixel space, regardless of the current + // tile's zoom level. + gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + v_linesofar = a_linesofar * u_ratio; + + v_tex = vec2(a_linesofar * u_patternscale.x, normal.y * u_patternscale.y + u_tex_y); + //v_tex = vec2(a_linesofar, 1.0); + //v_tex = vec2(1.0, 1.0); +} From d95531b64810e3bd151c780b9f901204fc428308 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 13 Jan 2015 17:25:12 -0500 Subject: [PATCH 092/259] remove old dash support from line shader --- line.fragment.glsl | 6 ------ line.vertex.glsl | 3 --- 2 files changed, 9 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index f4ac1458b33..fd3f964f0dd 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -5,7 +5,6 @@ uniform float u_blur; uniform vec2 u_dasharray; varying vec2 v_normal; -varying float v_linesofar; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -16,10 +15,5 @@ void main() { // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - // Calculate the antialiasing fade factor based on distance to the dash. - // Only affects alpha when line is dashed - float pos = mod(v_linesofar, u_dasharray.x + u_dasharray.y); - alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0)); - gl_FragColor = u_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index bf0b537e83f..1f5432991ce 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -20,11 +20,9 @@ uniform vec2 u_linewidth; uniform vec4 u_color; varying vec2 v_normal; -varying float v_linesofar; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -43,5 +41,4 @@ void main() { // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; - v_linesofar = a_linesofar * u_ratio; } From ce564fe5f84b7059646d8c6c0539e2c9ad46c750 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 14 Jan 2015 20:56:18 -0500 Subject: [PATCH 093/259] start porting dash lines from js - switches to dash units that are scaled by line width - adds a lineatlas to store patterns line dashed lines - adds linesdf shader which renders line fill from the lineatlas js: 8e83d76af3bd877eb9639c02e296363e2c0186f8 --- linesdf.fragment.glsl | 23 ++++++++++++++++++++ linesdf.vertex.glsl | 49 +++++++++++++++++++++++++++++++++++++++++++ linesdf_shader.cpp | 30 ++++++++++++++++++++++++++ linesdf_shader.hpp | 34 ++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 linesdf.fragment.glsl create mode 100644 linesdf.vertex.glsl create mode 100644 linesdf_shader.cpp create mode 100644 linesdf_shader.hpp diff --git a/linesdf.fragment.glsl b/linesdf.fragment.glsl new file mode 100644 index 00000000000..90a5eac3e23 --- /dev/null +++ b/linesdf.fragment.glsl @@ -0,0 +1,23 @@ +uniform vec2 u_linewidth; +uniform vec4 u_color; +uniform float u_blur; +uniform sampler2D u_image; +uniform float u_sdfgamma; + +varying vec2 v_normal; +varying vec2 v_tex; + +void main() { + // Calculate the distance of the pixel from the line in pixels. + float dist = length(v_normal) * u_linewidth.s; + + // Calculate the antialiasing fade factor. This is either when fading in + // the line in case of an offset line (v_linewidth.t) or when fading out + // (v_linewidth.s) + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + + float sdfdist = texture2D(u_image, v_tex).a; + alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); + + gl_FragColor = u_color * alpha; +} diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl new file mode 100644 index 00000000000..0ab6804ab5a --- /dev/null +++ b/linesdf.vertex.glsl @@ -0,0 +1,49 @@ +// floor(127 / 2) == 63.0 +// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is +// stored in a byte (-128..127). we scale regular normals up to length 63, but +// there are also "special" normals that have a bigger length (of up to 126 in +// this case). +// #define scale 63.0 +#define scale 0.015873016 + +attribute vec2 a_pos; +attribute vec4 a_data; + +// matrix is for the vertex position, exmatrix is for rotating and projecting +// the extrusion vector. +uniform mat4 u_matrix; +uniform mat4 u_exmatrix; + +// shared +uniform float u_ratio; +uniform vec2 u_linewidth; +uniform vec2 u_patternscale; +uniform float u_tex_y; + +varying vec2 v_normal; +varying vec2 v_tex; + +void main() { + vec2 a_extrude = a_data.xy; + float a_linesofar = a_data.z * 128.0 + a_data.w; + + // We store the texture normals in the most insignificant bit + // transform y so that 0 => -1 and 1 => 1 + // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap + // y is 1 if the normal points up, and -1 if it points down + vec2 normal = mod(a_pos, 2.0); + normal.y = sign(normal.y - 0.5); + v_normal = normal; + + // Scale the extrusion vector down to a normal and then up by the line width + // of this vertex. + vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + + // Remove the texture normal bit of the position before scaling it with the + // model/view matrix. Add the extrusion vector *after* the model/view matrix + // because we're extruding the line in pixel space, regardless of the current + // tile's zoom level. + gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + + v_tex = vec2(a_linesofar * u_patternscale.x, normal.y * u_patternscale.y + u_tex_y); +} diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp new file mode 100644 index 00000000000..9802afb532b --- /dev/null +++ b/linesdf_shader.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +LineSDFShader::LineSDFShader() + : Shader( + "line", + shaders[LINESDF_SHADER].vertex, + shaders[LINESDF_SHADER].fragment + ) { + if (!valid) { + fprintf(stderr, "invalid line shader\n"); + return; + } + + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); +} + +void LineSDFShader::bind(char *offset) { + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); + + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); +} diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp new file mode 100644 index 00000000000..918ed5cbab2 --- /dev/null +++ b/linesdf_shader.hpp @@ -0,0 +1,34 @@ +#ifndef MBGL_SHADER_SHADER_LINESDF +#define MBGL_SHADER_SHADER_LINESDF + +#include +#include + +namespace mbgl { + +class LineSDFShader : public Shader { +public: + LineSDFShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_blur = {"u_blur", *this}; + Uniform> u_patternscale = { "u_patternscale", *this }; + Uniform u_tex_y = {"u_tex_y", *this}; + Uniform u_image = {"u_image", *this}; + Uniform u_sdfgamma = {"u_sdfgamma", *this}; + +private: + int32_t a_pos = -1; + int32_t a_data = -1; +}; + + +} + +#endif From bd2b591189b29a04ce3ee181f45b234a8600eb76 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 14 Jan 2015 21:11:19 -0500 Subject: [PATCH 094/259] remove old dash support from line shader --- line.fragment.glsl | 8 -------- line.vertex.glsl | 3 --- line_shader.hpp | 1 - 3 files changed, 12 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index f4ac1458b33..717c46e10d6 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -2,10 +2,7 @@ uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_blur; -uniform vec2 u_dasharray; - varying vec2 v_normal; -varying float v_linesofar; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -16,10 +13,5 @@ void main() { // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - // Calculate the antialiasing fade factor based on distance to the dash. - // Only affects alpha when line is dashed - float pos = mod(v_linesofar, u_dasharray.x + u_dasharray.y); - alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0)); - gl_FragColor = u_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index bf0b537e83f..1f5432991ce 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -20,11 +20,9 @@ uniform vec2 u_linewidth; uniform vec4 u_color; varying vec2 v_normal; -varying float v_linesofar; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -43,5 +41,4 @@ void main() { // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; - v_linesofar = a_linesofar * u_ratio; } diff --git a/line_shader.hpp b/line_shader.hpp index c6adc0ff8db..85152d6e0c1 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -16,7 +16,6 @@ class LineShader : public Shader { UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; Uniform> u_color = {"u_color", *this}; Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform> u_dasharray = {"u_dasharray", *this}; Uniform u_ratio = {"u_ratio", *this}; Uniform u_blur = {"u_blur", *this}; From 89d6b97be5f5d081bbd12ccc27919bfffaa1d1c1 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 14 Jan 2015 23:17:00 -0500 Subject: [PATCH 095/259] remove unused varying from line shader --- linesdfpattern.fragment.glsl | 1 - linesdfpattern.vertex.glsl | 4 ---- 2 files changed, 5 deletions(-) diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index 3cc8a63748f..eec5e34ca54 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -6,7 +6,6 @@ uniform float u_sdfgamma; varying vec2 v_normal; -varying float v_linesofar; varying vec2 v_tex; void main() { diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 7c779855145..53080c736da 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -20,7 +20,6 @@ uniform vec2 u_patternscale; uniform float u_tex_y; varying vec2 v_normal; -varying float v_linesofar; varying vec2 v_tex; void main() { @@ -44,9 +43,6 @@ void main() { // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; - v_linesofar = a_linesofar * u_ratio; v_tex = vec2(a_linesofar * u_patternscale.x, normal.y * u_patternscale.y + u_tex_y); - //v_tex = vec2(a_linesofar, 1.0); - //v_tex = vec2(1.0, 1.0); } From 7b46df9ecb755faf4842871b1d468eb1c07321e0 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Thu, 15 Jan 2015 21:07:53 +1100 Subject: [PATCH 096/259] Update to Android NDK r10d in new AMI --- shader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shader.cpp b/shader.cpp index 5eb354f8520..d47723db494 100644 --- a/shader.cpp +++ b/shader.cpp @@ -67,7 +67,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (status == GL_TRUE) { skipCompile = true; } - } catch(std::exception& e) { + } catch(const std::exception& e) { Log::Error(Event::Shader, "Loading binary shader failed!"); // Delete the bad file @@ -221,7 +221,7 @@ Shader::~Shader() { binaryFile.write(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); binaryFile.write(binary.get(), binaryLength); - } catch(std::exception& e) { + } catch(const std::exception& e) { Log::Error(Event::Shader, "Saving binary shader failed!"); // Delete the bad file From be4c21664e164a70db6f9cf54ba738d88be61087 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 23 Jan 2015 13:51:54 -0500 Subject: [PATCH 097/259] transition dashes when resetting their stretch Dash patterns stretch from one integer zoom until the next integer zoom where they reset. This transitions those resets. --- linesdfpattern.fragment.glsl | 8 ++++++-- linesdfpattern.vertex.glsl | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index eec5e34ca54..c3384ebf88d 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -3,10 +3,12 @@ uniform vec4 u_color; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; +uniform float u_mix; varying vec2 v_normal; -varying vec2 v_tex; +varying vec2 v_tex_a; +varying vec2 v_tex_b; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -17,7 +19,9 @@ void main() { // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - float sdfdist = texture2D(u_image, v_tex).a; + float sdfdist_a = texture2D(u_image, v_tex_a).a; + float sdfdist_b = texture2D(u_image, v_tex_b).a; + float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); gl_FragColor = u_color * alpha; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 53080c736da..3c1155f61d8 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -16,11 +16,14 @@ uniform mat4 u_exmatrix; uniform vec2 u_linewidth; uniform float u_ratio; -uniform vec2 u_patternscale; -uniform float u_tex_y; +uniform vec2 u_patternscale_a; +uniform float u_tex_y_a; +uniform vec2 u_patternscale_b; +uniform float u_tex_y_b; varying vec2 v_normal; -varying vec2 v_tex; +varying vec2 v_tex_a; +varying vec2 v_tex_b; void main() { vec2 a_extrude = a_data.xy; @@ -44,5 +47,6 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; - v_tex = vec2(a_linesofar * u_patternscale.x, normal.y * u_patternscale.y + u_tex_y); + v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); + v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); } From dd5730c946717027bced88e698b31c7ada1103fc Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 23 Jan 2015 17:25:31 -0500 Subject: [PATCH 098/259] transition dashes when resetting their stretch Dash patterns stretch from one integer zoom until the next integer zoom where they reset. This transitions those resets. js: be5c7184bfd8cc9d47299041eb7fadbd41f6f6f0 --- linesdf.fragment.glsl | 8 ++++++-- linesdf.vertex.glsl | 12 ++++++++---- linesdf_shader.hpp | 7 +++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/linesdf.fragment.glsl b/linesdf.fragment.glsl index 90a5eac3e23..5d53dbe8833 100644 --- a/linesdf.fragment.glsl +++ b/linesdf.fragment.glsl @@ -3,9 +3,11 @@ uniform vec4 u_color; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; +uniform float u_mix; varying vec2 v_normal; -varying vec2 v_tex; +varying vec2 v_tex_a; +varying vec2 v_tex_b; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -16,7 +18,9 @@ void main() { // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - float sdfdist = texture2D(u_image, v_tex).a; + float sdfdist_a = texture2D(u_image, v_tex_a).a; + float sdfdist_b = texture2D(u_image, v_tex_b).a; + float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); gl_FragColor = u_color * alpha; diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl index 0ab6804ab5a..7f246ced67c 100644 --- a/linesdf.vertex.glsl +++ b/linesdf.vertex.glsl @@ -17,11 +17,14 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; -uniform vec2 u_patternscale; -uniform float u_tex_y; +uniform vec2 u_patternscale_a; +uniform float u_tex_y_a; +uniform vec2 u_patternscale_b; +uniform float u_tex_y_b; varying vec2 v_normal; -varying vec2 v_tex; +varying vec2 v_tex_a; +varying vec2 v_tex_b; void main() { vec2 a_extrude = a_data.xy; @@ -45,5 +48,6 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; - v_tex = vec2(a_linesofar * u_patternscale.x, normal.y * u_patternscale.y + u_tex_y); + v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); + v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); } diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 918ed5cbab2..16b7f3cb1ba 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -18,10 +18,13 @@ class LineSDFShader : public Shader { Uniform> u_linewidth = {"u_linewidth", *this}; Uniform u_ratio = {"u_ratio", *this}; Uniform u_blur = {"u_blur", *this}; - Uniform> u_patternscale = { "u_patternscale", *this }; - Uniform u_tex_y = {"u_tex_y", *this}; + Uniform> u_patternscale_a = { "u_patternscale_a", *this }; + Uniform u_tex_y_a = {"u_tex_y_a", *this}; + Uniform> u_patternscale_b = { "u_patternscale_b", *this }; + Uniform u_tex_y_b = {"u_tex_y_b", *this}; Uniform u_image = {"u_image", *this}; Uniform u_sdfgamma = {"u_sdfgamma", *this}; + Uniform u_mix = {"u_mix", *this}; private: int32_t a_pos = -1; From 3f719f9ef7b5c5750a3cfcfde058badb70a44c07 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 27 Jan 2015 12:34:55 +1100 Subject: [PATCH 099/259] Remove program binary caching --- shader.cpp | 166 ++++++++++++----------------------------------------- shader.hpp | 2 - 2 files changed, 37 insertions(+), 131 deletions(-) diff --git a/shader.cpp b/shader.cpp index d47723db494..550c159665b 100644 --- a/shader.cpp +++ b/shader.cpp @@ -20,112 +20,51 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo program = MBGL_CHECK_ERROR(glCreateProgram()); - if (!mbgl::platform::defaultShaderCache().empty()) { - binaryFileName = mbgl::platform::defaultShaderCache() + name + ".bin"; + GLuint vertShader = 0; + GLuint fragShader = 0; + if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { + Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); + MBGL_CHECK_ERROR(glDeleteProgram(program)); + program = 0; + return; } - // Load binary shader if it exists - bool skipCompile = false; - if (!binaryFileName.empty() && (gl::ProgramBinary != nullptr)) { - try { - std::ifstream binaryFile(binaryFileName, std::ios::in | std::ios::binary); - binaryFile.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); - - GLsizei binaryLength; - GLenum binaryFormat; - binaryFile.read(reinterpret_cast(&binaryLength), sizeof(binaryLength)); - binaryFile.read(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); - - GLint numBinaryFormats; - MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats)); - - std::unique_ptr validBinaryFormats = mbgl::util::make_unique(numBinaryFormats); - MBGL_CHECK_ERROR(glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, reinterpret_cast(validBinaryFormats.get()))); - - bool validBinaryFormat = false; - for (GLint i = 0; i < numBinaryFormats; i++) { - if (validBinaryFormats[i] == binaryFormat) { - validBinaryFormat = true; - } - } - if (!validBinaryFormat) { - throw std::runtime_error("Trying load program binary with an invalid binaryFormat!"); - } - - if (binaryLength == 0) { - throw std::runtime_error("Trying load program binary with a zero length binary!"); - } + if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { + Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); + vertShader = 0; + MBGL_CHECK_ERROR(glDeleteProgram(program)); + program = 0; + return; + } - std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - binaryFile.read(binary.get(), binaryLength); + // Attach shaders + MBGL_CHECK_ERROR(glAttachShader(program, vertShader)); + MBGL_CHECK_ERROR(glAttachShader(program, fragShader)); - MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength)); + { + // Link program + GLint status; + MBGL_CHECK_ERROR(glLinkProgram(program)); - // Check if the binary was valid - GLint status; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); - if (status == GL_TRUE) { - skipCompile = true; + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + if (status == 0) { + GLint logLength; + MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); + if (logLength > 0) { + std::unique_ptr log = mbgl::util::make_unique(logLength); + MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); + Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } - } catch(const std::exception& e) { - Log::Error(Event::Shader, "Loading binary shader failed!"); - - // Delete the bad file - std::remove(binaryFileName.c_str()); - } - } - GLuint vertShader = 0; - GLuint fragShader = 0; - if (!skipCompile) { - if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { - Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; - return; - } - - if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { - Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); + fragShader = 0; MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; return; } - - // Attach shaders - MBGL_CHECK_ERROR(glAttachShader(program, vertShader)); - MBGL_CHECK_ERROR(glAttachShader(program, fragShader)); - - { - if (!binaryFileName.empty() && (gl::ProgramParameteri != nullptr)) { - MBGL_CHECK_ERROR(gl::ProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE)); - } - - // Link program - GLint status; - MBGL_CHECK_ERROR(glLinkProgram(program)); - - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); - if (status == 0) { - GLint logLength; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); - if (logLength > 0) { - std::unique_ptr log = mbgl::util::make_unique(logLength); - MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Program failed to link: %s", log.get()); - } - - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - vertShader = 0; - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - fragShader = 0; - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; - return; - } - } } { @@ -152,13 +91,11 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo } } - if (!skipCompile) { - // Remove the compiled shaders; they are now part of the program. - MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - } + // Remove the compiled shaders; they are now part of the program. + MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); + MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); valid = true; } @@ -201,35 +138,6 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { } Shader::~Shader() { - if (!binaryFileName.empty() && (gl::GetProgramBinary != nullptr)) { - // Retrieve the program binary - GLsizei binaryLength; - GLenum binaryFormat; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength)); - if (binaryLength > 0) { - std::unique_ptr binary = mbgl::util::make_unique(binaryLength); - MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, nullptr, &binaryFormat, binary.get())); - - Log::Error(Event::OpenGL, "glGetProgramBinary(%u, %u, nullptr, %u, %u)", program, binaryLength, binaryFormat, binary.get()); - - try { - // Write the binary to a file - std::ofstream binaryFile(binaryFileName, std::ios::out | std::ios::trunc | std::ios::binary); - binaryFile.exceptions(std::ofstream::failbit | std::ofstream::badbit | std::ofstream::eofbit); - - binaryFile.write(reinterpret_cast(&binaryLength), sizeof(binaryLength)); - binaryFile.write(reinterpret_cast(&binaryFormat), sizeof(binaryFormat)); - binaryFile.write(binary.get(), binaryLength); - - } catch(const std::exception& e) { - Log::Error(Event::Shader, "Saving binary shader failed!"); - - // Delete the bad file - std::remove(binaryFileName.c_str()); - } - } - } - if (program) { MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; diff --git a/shader.hpp b/shader.hpp index beaaa8b756e..965180ff968 100644 --- a/shader.hpp +++ b/shader.hpp @@ -22,8 +22,6 @@ class Shader : private util::noncopyable { private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); - - std::string binaryFileName; }; } From 182e4210ed18ca714938cff1f05bc4d0e933509e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 30 Jan 2015 10:46:31 -0800 Subject: [PATCH 100/259] don't premultiply line patterns twice --- linepattern.fragment.glsl | 2 -- 1 file changed, 2 deletions(-) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 52ca823a3b6..0a2f4846c34 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -31,7 +31,5 @@ void main() { vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); - color.rgb *= color.a; // premultiply - gl_FragColor = color * alpha; } From 062bb6c61f6a8493a0bac2be00801b466807183c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 30 Jan 2015 10:51:28 -0800 Subject: [PATCH 101/259] make line-opacity work with line-image, fixes #970 --- linepattern.fragment.glsl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 0a2f4846c34..45be7c8c2fd 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -6,6 +6,7 @@ uniform vec2 u_pattern_size; uniform vec2 u_pattern_tl; uniform vec2 u_pattern_br; uniform float u_fade; +uniform float u_opacity; uniform sampler2D u_image; @@ -31,5 +32,7 @@ void main() { vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); + alpha *= u_opacity; + gl_FragColor = color * alpha; } From a661bc3c194c2c93b3b52084b39f9b46553b9ba5 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 30 Jan 2015 11:02:26 -0800 Subject: [PATCH 102/259] make line-opacity work with line-image js: 0e9a86e3553913abb8ebb3d8926e2b99db8d4008 --- linepattern.fragment.glsl | 3 ++- linepattern_shader.hpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 52ca823a3b6..45be7c8c2fd 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -6,6 +6,7 @@ uniform vec2 u_pattern_size; uniform vec2 u_pattern_tl; uniform vec2 u_pattern_br; uniform float u_fade; +uniform float u_opacity; uniform sampler2D u_image; @@ -31,7 +32,7 @@ void main() { vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); - color.rgb *= color.a; // premultiply + alpha *= u_opacity; gl_FragColor = color * alpha; } diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index ace8198aedc..388cff17d26 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -22,6 +22,7 @@ class LinepatternShader : public Shader { Uniform u_point = {"u_point", *this}; Uniform u_blur = {"u_blur", *this}; Uniform u_fade = {"u_fade", *this}; + Uniform u_opacity = {"u_opacity", *this}; private: int32_t a_pos = -1; From 641c77c59a6aa709da03a878dc5056663aed15e3 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 14:46:48 -0800 Subject: [PATCH 103/259] implement functions for patterns It introduces a new function type, FadedStopsFunction, that transitions between the stops values instead of interpolating between them. --- pattern.fragment.glsl | 17 ++++++++++------- pattern.vertex.glsl | 9 ++++++--- pattern_shader.hpp | 9 ++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index ba6aed30239..a28a52ce36a 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -1,20 +1,23 @@ uniform float u_opacity; -uniform vec2 u_pattern_tl; -uniform vec2 u_pattern_br; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; uniform float u_mix; uniform sampler2D u_image; -varying vec2 v_pos; +varying vec2 v_pos_a; +varying vec2 v_pos_b; void main() { - vec2 imagecoord = mod(v_pos, 1.0); - vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); vec4 color1 = texture2D(u_image, pos); - vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); - vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); vec4 color2 = texture2D(u_image, pos2); gl_FragColor = mix(color1, color2, u_mix) * u_opacity; diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index f2de884eadb..dff4469d2b6 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,11 +1,14 @@ uniform mat4 u_matrix; -uniform mat3 u_patternmatrix; +uniform mat3 u_patternmatrix_a; +uniform mat3 u_patternmatrix_b; attribute vec2 a_pos; -varying vec2 v_pos; +varying vec2 v_pos_a; +varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (u_patternmatrix * vec3(a_pos, 1)).xy; + v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy; + v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy; } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 9fabd8e18ac..9fc8dcfa01e 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -13,12 +13,15 @@ class PatternShader : public Shader { void bind(char *offset); UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_pattern_tl = {"u_pattern_tl", *this}; - Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; Uniform u_opacity = {"u_opacity", *this}; Uniform u_mix = {"u_mix", *this}; Uniform u_image = {"u_image", *this}; - UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this}; + UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; + UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; private: int32_t a_pos = -1; From 44cf525dbbd561978534895d69415a5eb2159632 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 17:08:26 -0800 Subject: [PATCH 104/259] implement functions for line-image --- linepattern.fragment.glsl | 22 +++++++++++++--------- linepattern_shader.hpp | 9 ++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 45be7c8c2fd..08feff4396e 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -2,9 +2,12 @@ uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; -uniform vec2 u_pattern_size; -uniform vec2 u_pattern_tl; -uniform vec2 u_pattern_br; +uniform vec2 u_pattern_size_a; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_size_b; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; uniform float u_fade; uniform float u_opacity; @@ -24,13 +27,14 @@ void main() { // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - float x = mod(v_linesofar / u_pattern_size.x, 1.0); - float y = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size.y); - vec2 pos = mix(u_pattern_tl, u_pattern_br, vec2(x, y)); - float x2 = mod(x * 2.0, 1.0); - vec2 pos2 = mix(u_pattern_tl, u_pattern_br, vec2(x2, y)); + float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); + float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); + vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); + float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); + float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); + vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); - vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); + vec4 color = mix(texture2D(u_image, pos_a), texture2D(u_image, pos_b), u_fade); alpha *= u_opacity; diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index 388cff17d26..16d9ff8be73 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -15,9 +15,12 @@ class LinepatternShader : public Shader { UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform> u_pattern_size = {"u_pattern_size", *this}; - Uniform> u_pattern_tl = {"u_pattern_tl", *this}; - Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform> u_pattern_size_a = {"u_pattern_size_a", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_size_b = {"u_pattern_size_b", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; Uniform u_ratio = {"u_ratio", *this}; Uniform u_point = {"u_point", *this}; Uniform u_blur = {"u_blur", *this}; From d31b1a59ffa095ceb98c50bef17cf36ce33a9ce6 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 29 Jan 2015 11:03:48 -0800 Subject: [PATCH 105/259] Function support for all properties https://github.com/mapbox/mapbox-gl-style-spec/issues/237 --- linepattern.fragment.glsl | 26 ++++++++++++++------------ linepattern.vertex.glsl | 15 ++------------- pattern.fragment.glsl | 17 ++++++++++------- pattern.vertex.glsl | 9 ++++++--- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 45be7c8c2fd..50c3f98e4ea 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -2,9 +2,12 @@ uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; -uniform vec2 u_pattern_size; -uniform vec2 u_pattern_tl; -uniform vec2 u_pattern_br; +uniform vec2 u_pattern_size_a; +uniform vec2 u_pattern_size_b; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; uniform float u_fade; uniform float u_opacity; @@ -15,22 +18,21 @@ varying float v_linesofar; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); - - dist *= u_linewidth.s; + float dist = length(v_normal) * u_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - float x = mod(v_linesofar / u_pattern_size.x, 1.0); - float y = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size.y); - vec2 pos = mix(u_pattern_tl, u_pattern_br, vec2(x, y)); - float x2 = mod(x * 2.0, 1.0); - vec2 pos2 = mix(u_pattern_tl, u_pattern_br, vec2(x2, y)); + float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); + float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); + float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); + float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); - vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); + vec4 color = mix(texture2D(u_image, pos), texture2D(u_image, pos2), u_fade); alpha *= u_opacity; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index ada384a3d10..987f2e8ce6c 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -18,7 +18,6 @@ uniform mat4 u_exmatrix; uniform float u_ratio; uniform vec2 u_linewidth; uniform vec4 u_color; -uniform float u_point; varying vec2 v_normal; varying float v_linesofar; @@ -38,23 +37,13 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. vec2 extrude = a_extrude * scale; - vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); - - // If the x coordinate is the maximum integer, we move the z coordinates out - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. - float z = step(32767.0, a_pos.x); - - // When drawing points, skip every other vertex - z += u_point * step(1.0, v_normal.y); + vec2 dist = u_linewidth.s * extrude; // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, 0.0, 0.0); v_linesofar = a_linesofar;// * u_ratio; - - gl_PointSize = 2.0 * u_linewidth.s - 1.0; } diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index ba6aed30239..a28a52ce36a 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -1,20 +1,23 @@ uniform float u_opacity; -uniform vec2 u_pattern_tl; -uniform vec2 u_pattern_br; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; uniform float u_mix; uniform sampler2D u_image; -varying vec2 v_pos; +varying vec2 v_pos_a; +varying vec2 v_pos_b; void main() { - vec2 imagecoord = mod(v_pos, 1.0); - vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); vec4 color1 = texture2D(u_image, pos); - vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); - vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); vec4 color2 = texture2D(u_image, pos2); gl_FragColor = mix(color1, color2, u_mix) * u_opacity; diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index f2de884eadb..dff4469d2b6 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,11 +1,14 @@ uniform mat4 u_matrix; -uniform mat3 u_patternmatrix; +uniform mat3 u_patternmatrix_a; +uniform mat3 u_patternmatrix_b; attribute vec2 a_pos; -varying vec2 v_pos; +varying vec2 v_pos_a; +varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (u_patternmatrix * vec3(a_pos, 1)).xy; + v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy; + v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy; } From 52496e69740df76def38385ba4bd149429b76a42 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 6 Feb 2015 19:50:21 -0800 Subject: [PATCH 106/259] fix fill antialiasing for tilt --- outline.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outline.vertex.glsl b/outline.vertex.glsl index 29c16e3ded2..535063b5964 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -6,5 +6,5 @@ varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world; + v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; } From f5d49000a9440a374e76addd0f546825673dd385 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 6 Feb 2015 20:40:13 -0800 Subject: [PATCH 107/259] fix line antialiasing in perspective view --- line.fragment.glsl | 4 +++- line.vertex.glsl | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index f4ac1458b33..27e9ea5072e 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -6,6 +6,7 @@ uniform vec2 u_dasharray; varying vec2 v_normal; varying float v_linesofar; +varying float gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -14,7 +15,8 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float blur = u_blur * gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); // Calculate the antialiasing fade factor based on distance to the dash. // Only affects alpha when line is dashed diff --git a/line.vertex.glsl b/line.vertex.glsl index abb23cc4868..ca6004eb2f5 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -19,8 +19,12 @@ uniform float u_ratio; uniform vec2 u_linewidth; uniform vec4 u_color; +uniform float u_extra; +uniform mat2 u_antialiasingmatrix; + varying vec2 v_normal; varying float v_linesofar; +varying float gamma_scale; void main() { // We store the texture normals in the most insignificant bit @@ -41,4 +45,16 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar * u_ratio; + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + + // how much features are squished in the y direction by the tilt + float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); + + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - y * u_extra); + + // the 0.9 adds a tiny bit of extra blurriness to account for the inexactness of these calculations + gamma_scale = perspective_scale * squish_scale * 0.9; } From 6f0c0b7f6f9782511cd1e3a7abcede749fa01be6 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 17 Feb 2015 11:16:05 -0800 Subject: [PATCH 108/259] start of new labelling work The general idea is to generate fewer, separate boxes used for placement and only generate glyphs for rendering after features have been placed. This commit breaks lots of things. --- placementbox.fragment.glsl | 19 +++++++++++++++++++ placementbox.vertex.glsl | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 placementbox.fragment.glsl create mode 100644 placementbox.vertex.glsl diff --git a/placementbox.fragment.glsl b/placementbox.fragment.glsl new file mode 100644 index 00000000000..f99077a74e7 --- /dev/null +++ b/placementbox.fragment.glsl @@ -0,0 +1,19 @@ +uniform float u_zoom; + +varying float v_max_zoom; +varying float v_placement_zoom; + +void main() { + + float alpha = 0.5; + + gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0) * alpha; + + if (v_placement_zoom > u_zoom) { + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * alpha; + } + + if (u_zoom >= v_max_zoom) { + gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) * alpha * 0.25; + } +} diff --git a/placementbox.vertex.glsl b/placementbox.vertex.glsl new file mode 100644 index 00000000000..b085ab91475 --- /dev/null +++ b/placementbox.vertex.glsl @@ -0,0 +1,16 @@ +attribute vec2 a_pos; +attribute vec2 a_extrude; +attribute vec2 a_data; + +uniform mat4 u_matrix; +uniform float u_scale; + +varying float v_max_zoom; +varying float v_placement_zoom; + +void main() { + gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0); + + v_max_zoom = a_data.x + 128.0; + v_placement_zoom = a_data.y + 128.0; +} From 9b588eaf57ec2309a1699f8143c76c0684d7e5e9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 19 Feb 2015 20:54:49 -0800 Subject: [PATCH 109/259] draw labels that couldn't be placed blue --- placementbox.fragment.glsl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/placementbox.fragment.glsl b/placementbox.fragment.glsl index f99077a74e7..030f1219f8e 100644 --- a/placementbox.fragment.glsl +++ b/placementbox.fragment.glsl @@ -1,4 +1,5 @@ uniform float u_zoom; +uniform float u_maxzoom; varying float v_max_zoom; varying float v_placement_zoom; @@ -16,4 +17,8 @@ void main() { if (u_zoom >= v_max_zoom) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) * alpha * 0.25; } + + if (v_placement_zoom >= u_maxzoom) { + gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0) * alpha * 0.2; + } } From 8cdc4b49c423e81996d2e0b97dc0282b1b1dd74a Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 19 Feb 2015 21:06:50 -0800 Subject: [PATCH 110/259] remove more old placement code --- icon.vertex.glsl | 7 ------- sdf.vertex.glsl | 7 ------- 2 files changed, 14 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index fd7afd5b7d9..dd5faf415fe 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -29,9 +29,6 @@ void main() { vec2 a_zoom = a_data2.st; float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - vec2 a_range = a_data2.pq; - float a_rangeend = a_range[0]; - float a_rangestart = a_range[1]; float a_fadedist = 10.0; float rev = 0.0; @@ -66,10 +63,6 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - // all the angles are 0..256 representing 0..2PI - // hide if (angle >= a_rangeend && angle < rangestart) - z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index bbfc44919e3..13e5ba03f72 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -28,9 +28,6 @@ void main() { vec2 a_zoom = a_data2.st; float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - vec2 a_range = a_data2.pq; - float a_rangeend = a_range[0]; - float a_rangestart = a_range[1]; float rev = 0.0; @@ -64,10 +61,6 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - // all the angles are 0..256 representing 0..2PI - // hide if (angle >= a_rangeend && angle < rangestart) - z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; } From 4dcee98be3042b94c6557553e78e3b20a976f9bb Mon Sep 17 00:00:00 2001 From: Amit Kapadia Date: Mon, 23 Feb 2015 18:14:24 -0800 Subject: [PATCH 111/259] remove symbol angle from shader --- sdf.vertex.glsl | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 13e5ba03f72..71bfca17b0f 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -8,7 +8,7 @@ attribute vec4 a_data2; // the extrusion vector. uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform float u_angle; + uniform float u_zoom; uniform float u_flip; uniform float u_fadedist; @@ -24,24 +24,15 @@ varying float v_alpha; void main() { vec2 a_tex = a_data1.xy; float a_labelminzoom = a_data1[2]; - float a_angle = a_data1[3]; vec2 a_zoom = a_data2.st; float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - float rev = 0.0; - - // u_angle is angle of the map, -128..128 representing 0..2PI - // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text - float rotated = mod(a_angle + u_angle, 256.0); - // if the label rotates with the map, and if the rotated label is upside down, hide it - if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; - // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); // fade out labels float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); From cb3d77fca04494cd4c376a5612b9aa0c68734eb0 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 3 Mar 2015 15:15:18 -0800 Subject: [PATCH 112/259] support line labels in perspective view --- sdf.fragment.glsl | 4 +++- sdf.vertex.glsl | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index d72d61dab19..a7ae7f821f6 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -5,9 +5,11 @@ uniform float u_gamma; varying vec2 v_tex; varying float v_alpha; +varying float v_gamma_scale; void main() { + float gamma = u_gamma * v_gamma_scale; float dist = texture2D(u_texture, v_tex).a; - float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist) * v_alpha; + float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 4ff194186ea..69148c92225 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -20,11 +20,14 @@ uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; +uniform bool u_skewed; +uniform float u_extra; uniform vec2 u_texsize; varying vec2 v_tex; varying float v_alpha; +varying float v_gamma_scale; void main() { @@ -64,13 +67,20 @@ void main() { // hide if (angle >= a_rangeend && angle < rangestart) z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1); - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); + if (u_skewed) { + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); + gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); + gl_Position.z += z * gl_Position.w; + } else { + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; + } - //if (u_flip == 0.0) { - //extrude *= gl_Position.w; - //} + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - y * u_extra); + v_gamma_scale = perspective_scale; - gl_Position += extrude; v_tex = a_tex / u_texsize; } From 2bbb828b4b817450d07e28ae0b531f371c4314b8 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 3 Mar 2015 15:16:35 -0800 Subject: [PATCH 113/259] fix line antialiasing adjustment --- line.vertex.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index ca6004eb2f5..4ab568e2e86 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -55,6 +55,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - y * u_extra); - // the 0.9 adds a tiny bit of extra blurriness to account for the inexactness of these calculations - gamma_scale = perspective_scale * squish_scale * 0.9; + // the 1.1 adds a tiny bit of extra blurriness to account for the inexactness of these calculations + gamma_scale = perspective_scale * squish_scale * 1.1; } From 01d7b5b66f2b2563713427963859a78990a2b63d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 3 Mar 2015 16:00:11 -0800 Subject: [PATCH 114/259] fix line icons aligned with map --- icon.vertex.glsl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 8c69c404100..6c0350371bc 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -21,6 +21,8 @@ uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; uniform float u_opacity; +uniform bool u_skewed; +uniform float u_extra; uniform vec2 u_texsize; @@ -66,7 +68,15 @@ void main() { // hide if (angle >= a_rangeend && angle < rangestart) z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + if (u_skewed) { + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); + gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); + gl_Position.z += z * gl_Position.w; + } else { + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; + } + v_tex = a_tex / u_texsize; v_alpha *= u_opacity; From c17a4f1b248d5bd0ae5b632ff06e997640e86c84 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Mar 2015 12:27:29 -0800 Subject: [PATCH 115/259] fix dashed and pattern line rendering --- line.vertex.glsl | 3 +-- linepattern.vertex.glsl | 2 +- linesdfpattern.vertex.glsl | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index d4369c478cb..fc7fc7f771e 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -55,6 +55,5 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - y * u_extra); - // the 1.1 adds a tiny bit of extra blurriness to account for the inexactness of these calculations - gamma_scale = perspective_scale * squish_scale * 1.1; + gamma_scale = perspective_scale * squish_scale; } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 987f2e8ce6c..65aed9f26c2 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -43,7 +43,7 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, 0.0, 0.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar;// * u_ratio; } diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 3c1155f61d8..9da42801b4e 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -45,7 +45,7 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); From 55f79df0bac6e38481eec5e3f8d52e499fee4717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 13 Feb 2015 14:51:01 -0800 Subject: [PATCH 116/259] throw exception when shader compilation fails --- dot_shader.cpp | 5 ----- gaussian_shader.cpp | 7 ------- icon_shader.cpp | 5 ----- line_shader.cpp | 5 ----- linejoin_shader.cpp | 5 ----- linepattern_shader.cpp | 5 ----- linesdf_shader.cpp | 5 ----- outline_shader.cpp | 5 ----- pattern_shader.cpp | 5 ----- plain_shader.cpp | 5 ----- raster_shader.cpp | 7 ------- sdf_shader.cpp | 5 ----- shader.cpp | 16 +++++++--------- shader.hpp | 1 - 14 files changed, 7 insertions(+), 74 deletions(-) diff --git a/dot_shader.cpp b/dot_shader.cpp index 08b55a566b7..57a60cc5194 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -12,11 +12,6 @@ DotShader::DotShader() shaders[DOT_SHADER].vertex, shaders[DOT_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid dot shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/gaussian_shader.cpp b/gaussian_shader.cpp index 483de4867e1..b7d593f2e40 100644 --- a/gaussian_shader.cpp +++ b/gaussian_shader.cpp @@ -12,13 +12,6 @@ GaussianShader::GaussianShader() shaders[GAUSSIAN_SHADER].vertex, shaders[GAUSSIAN_SHADER].fragment ) { - if (!valid) { -#if defined(DEBUG) - fprintf(stderr, "invalid raster shader\n"); -#endif - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/icon_shader.cpp b/icon_shader.cpp index 0dfd67e25b0..0f626ec9e7a 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -12,11 +12,6 @@ IconShader::IconShader() shaders[ICON_SHADER].vertex, shaders[ICON_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid icon shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); diff --git a/line_shader.cpp b/line_shader.cpp index 432a64f6950..c2364c9beac 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -12,11 +12,6 @@ LineShader::LineShader() shaders[LINE_SHADER].vertex, shaders[LINE_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid line shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/linejoin_shader.cpp b/linejoin_shader.cpp index 5b9e7ba20a5..b3c5638b5d8 100644 --- a/linejoin_shader.cpp +++ b/linejoin_shader.cpp @@ -12,11 +12,6 @@ LinejoinShader::LinejoinShader() shaders[LINEJOIN_SHADER].vertex, shaders[LINEJOIN_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid line shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index c45378378d6..7bfd1412dbf 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -12,11 +12,6 @@ LinepatternShader::LinepatternShader() shaders[LINEPATTERN_SHADER].vertex, shaders[LINEPATTERN_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid line pattern shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index 9802afb532b..bd2137de307 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -12,11 +12,6 @@ LineSDFShader::LineSDFShader() shaders[LINESDF_SHADER].vertex, shaders[LINESDF_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid line shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/outline_shader.cpp b/outline_shader.cpp index 98d208297cb..ee2a6bcd407 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -12,11 +12,6 @@ OutlineShader::OutlineShader() shaders[OUTLINE_SHADER].vertex, shaders[OUTLINE_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid outline shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/pattern_shader.cpp b/pattern_shader.cpp index 0a6013b17db..66369d528ab 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -12,11 +12,6 @@ PatternShader::PatternShader() shaders[PATTERN_SHADER].vertex, shaders[PATTERN_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid pattern shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/plain_shader.cpp b/plain_shader.cpp index ce7ddae918a..93dbb42a573 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -12,11 +12,6 @@ PlainShader::PlainShader() shaders[PLAIN_SHADER].vertex, shaders[PLAIN_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid plain shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/raster_shader.cpp b/raster_shader.cpp index 14c6ddc7c4b..2d69549209a 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -12,13 +12,6 @@ RasterShader::RasterShader() shaders[RASTER_SHADER].vertex, shaders[RASTER_SHADER].fragment ) { - if (!valid) { -#if defined(DEBUG) - fprintf(stderr, "invalid raster shader\n"); -#endif - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 757884f39c7..ca1dab58dd7 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -12,11 +12,6 @@ SDFShader::SDFShader() shaders[SDF_SHADER].vertex, shaders[SDF_SHADER].fragment ) { - if (!valid) { - fprintf(stderr, "invalid sdf shader\n"); - return; - } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); diff --git a/shader.cpp b/shader.cpp index 550c159665b..00b928b4459 100644 --- a/shader.cpp +++ b/shader.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -14,7 +15,6 @@ using namespace mbgl; Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource) : name(name_), - valid(false), program(0) { util::stopwatch stopwatch("shader compilation", Event::Shader); @@ -26,7 +26,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; - return; + throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile"); } if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { @@ -35,7 +35,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo vertShader = 0; MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; - return; + throw util::ShaderException(std::string { "Fragment shader " } + name + " failed to compile"); } // Attach shaders @@ -51,8 +51,8 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (status == 0) { GLint logLength; MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); + std::unique_ptr log = mbgl::util::make_unique(logLength); if (logLength > 0) { - std::unique_ptr log = mbgl::util::make_unique(logLength); MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } @@ -63,7 +63,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo fragShader = 0; MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; - return; + throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); } } @@ -76,8 +76,8 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (status == 0) { GLint logLength; MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); + std::unique_ptr log = mbgl::util::make_unique(logLength); if (logLength > 0) { - std::unique_ptr log = mbgl::util::make_unique(logLength); MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); } @@ -88,6 +88,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo fragShader = 0; MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; + throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); } } @@ -96,8 +97,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo MBGL_CHECK_ERROR(glDeleteShader(vertShader)); MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - - valid = true; } @@ -141,6 +140,5 @@ Shader::~Shader() { if (program) { MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; - valid = false; } } diff --git a/shader.hpp b/shader.hpp index 965180ff968..b3d9b4e46cc 100644 --- a/shader.hpp +++ b/shader.hpp @@ -13,7 +13,6 @@ class Shader : private util::noncopyable { Shader(const char *name, const char *vertex, const char *fragment); ~Shader(); const char *name; - bool valid; uint32_t program; inline uint32_t getID() const { From e2686ad7ee44de371e7ec51d6e235efc9eb6f735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 12 Feb 2015 13:03:40 -0800 Subject: [PATCH 117/259] use a reinterpret_cast to return the correct type --- shader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shader.cpp b/shader.cpp index 00b928b4459..a079409aa0d 100644 --- a/shader.cpp +++ b/shader.cpp @@ -127,7 +127,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); if (status == GL_FALSE) { - Log::Error(Event::Shader, "Shader %s failed to compile.", name, type); + Log::Error(Event::Shader, "Shader %s failed to compile.", name); MBGL_CHECK_ERROR(glDeleteShader(*shader)); *shader = 0; return false; From e2cbcc3cf54d591f7cd3de4c5282263332a3622d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 6 Mar 2015 09:40:41 -0800 Subject: [PATCH 118/259] don't pass fonstacks to getGlyphQuads and other cleaup --- icon.vertex.glsl | 12 +----------- sdf.vertex.glsl | 1 - 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index dd5faf415fe..49af0a24f41 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -8,9 +8,7 @@ attribute vec4 a_data2; // the extrusion vector. uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform float u_angle; uniform float u_zoom; -uniform float u_flip; uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; @@ -25,25 +23,17 @@ varying float v_alpha; void main() { vec2 a_tex = a_data1.xy; float a_labelminzoom = a_data1[2]; - float a_angle = a_data1[3]; vec2 a_zoom = a_data2.st; float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; float a_fadedist = 10.0; - float rev = 0.0; - - // u_angle is angle of the map, -128..128 representing 0..2PI - // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text - float rotated = mod(a_angle + u_angle, 256.0); - // if the label rotates with the map, and if the rotated label is upside down, hide it - if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; // If the label should be invisible, we move the vertex outside // of the view plane so that the triangle gets clipped. This makes it easier // for us to create degenerate triangle strips. // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); // fade out labels float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 71bfca17b0f..93842f6657a 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -10,7 +10,6 @@ uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; -uniform float u_flip; uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; From b59ef15c82a8800de19760feb169d53af51ff481 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Mar 2015 12:00:08 -0700 Subject: [PATCH 119/259] more placement cleanup --- icon.vertex.glsl | 3 --- sdf.vertex.glsl | 3 --- 2 files changed, 6 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 49af0a24f41..019b40f612e 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -29,9 +29,6 @@ void main() { float a_fadedist = 10.0; - // If the label should be invisible, we move the vertex outside - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. // u_zoom is the current zoom level adjusted for the change in font size float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 93842f6657a..741334f2277 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -27,9 +27,6 @@ void main() { float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - // If the label should be invisible, we move the vertex outside - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. // u_zoom is the current zoom level adjusted for the change in font size float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); From 3a985ae5fa0f37bde994f3456a4f8bec51dcf210 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Mar 2015 13:22:35 -0700 Subject: [PATCH 120/259] rename Placement* to Collision* where appropriate --- placementbox.fragment.glsl => collisionbox.fragment.glsl | 0 placementbox.vertex.glsl => collisionbox.vertex.glsl | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename placementbox.fragment.glsl => collisionbox.fragment.glsl (100%) rename placementbox.vertex.glsl => collisionbox.vertex.glsl (100%) diff --git a/placementbox.fragment.glsl b/collisionbox.fragment.glsl similarity index 100% rename from placementbox.fragment.glsl rename to collisionbox.fragment.glsl diff --git a/placementbox.vertex.glsl b/collisionbox.vertex.glsl similarity index 100% rename from placementbox.vertex.glsl rename to collisionbox.vertex.glsl From bc3ef4c4021884e8b94551378cee0d18e712b9cd Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 30 Mar 2015 17:48:52 -0700 Subject: [PATCH 121/259] remove in-shader label flipping --- icon.vertex.glsl | 21 +-------------------- icon_shader.hpp | 2 -- sdf.vertex.glsl | 22 +--------------------- sdf_shader.hpp | 2 -- 4 files changed, 2 insertions(+), 45 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index fd7afd5b7d9..549570021de 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -8,9 +8,7 @@ attribute vec4 a_data2; // the extrusion vector. uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform float u_angle; uniform float u_zoom; -uniform float u_flip; uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; @@ -29,24 +27,11 @@ void main() { vec2 a_zoom = a_data2.st; float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - vec2 a_range = a_data2.pq; - float a_rangeend = a_range[0]; - float a_rangestart = a_range[1]; float a_fadedist = 10.0; - float rev = 0.0; - // u_angle is angle of the map, -128..128 representing 0..2PI - // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text - float rotated = mod(a_angle + u_angle, 256.0); - // if the label rotates with the map, and if the rotated label is upside down, hide it - if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; - - // If the label should be invisible, we move the vertex outside - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); // fade out labels float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); @@ -66,10 +51,6 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - // all the angles are 0..256 representing 0..2PI - // hide if (angle >= a_rangeend && angle < rangestart) - z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; diff --git a/icon_shader.hpp b/icon_shader.hpp index 155b9addca6..b6156ae9a0f 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -14,9 +14,7 @@ class IconShader : public Shader { UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform u_angle = {"u_angle", *this}; Uniform u_zoom = {"u_zoom", *this}; - Uniform u_flip = {"u_flip", *this}; Uniform u_fadedist = {"u_fadedist", *this}; Uniform u_minfadezoom = {"u_minfadezoom", *this}; Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index bbfc44919e3..416a9bca586 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -8,9 +8,7 @@ attribute vec4 a_data2; // the extrusion vector. uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform float u_angle; uniform float u_zoom; -uniform float u_flip; uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; @@ -28,23 +26,9 @@ void main() { vec2 a_zoom = a_data2.st; float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - vec2 a_range = a_data2.pq; - float a_rangeend = a_range[0]; - float a_rangestart = a_range[1]; - float rev = 0.0; - - // u_angle is angle of the map, -128..128 representing 0..2PI - // a_angle is angle of the label, 0..256 representing 0..2PI, where 0 is horizontal text - float rotated = mod(a_angle + u_angle, 256.0); - // if the label rotates with the map, and if the rotated label is upside down, hide it - if (u_flip > 0.0 && rotated >= 64.0 && rotated < 192.0) rev = 1.0; - - // If the label should be invisible, we move the vertex outside - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev; + float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); // fade out labels float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); @@ -64,10 +48,6 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - // all the angles are 0..256 representing 0..2PI - // hide if (angle >= a_rangeend && angle < rangestart) - z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); v_tex = a_tex / u_texsize; } diff --git a/sdf_shader.hpp b/sdf_shader.hpp index 08f3053b7d4..36dfa30d3ec 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -18,9 +18,7 @@ class SDFShader : public Shader { Uniform> u_texsize = {"u_texsize", *this}; Uniform u_buffer = {"u_buffer", *this}; Uniform u_gamma = {"u_gamma", *this}; - Uniform u_angle = {"u_angle", *this}; Uniform u_zoom = {"u_zoom", *this}; - Uniform u_flip = {"u_flip", *this}; Uniform u_fadedist = {"u_fadedist", *this}; Uniform u_minfadezoom = {"u_minfadezoom", *this}; Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; From 7e7a2dc0c1f7d4f93f3fe9244f8db1c916d35edf Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 1 Apr 2015 13:22:16 -0700 Subject: [PATCH 122/259] port collision box debug rendering --- box.fragment.glsl | 24 ++++++++++++++++++++++++ box.vertex.glsl | 16 ++++++++++++++++ box_shader.cpp | 32 ++++++++++++++++++++++++++++++++ box_shader.hpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 box.fragment.glsl create mode 100644 box.vertex.glsl create mode 100644 box_shader.cpp create mode 100644 box_shader.hpp diff --git a/box.fragment.glsl b/box.fragment.glsl new file mode 100644 index 00000000000..030f1219f8e --- /dev/null +++ b/box.fragment.glsl @@ -0,0 +1,24 @@ +uniform float u_zoom; +uniform float u_maxzoom; + +varying float v_max_zoom; +varying float v_placement_zoom; + +void main() { + + float alpha = 0.5; + + gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0) * alpha; + + if (v_placement_zoom > u_zoom) { + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * alpha; + } + + if (u_zoom >= v_max_zoom) { + gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) * alpha * 0.25; + } + + if (v_placement_zoom >= u_maxzoom) { + gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0) * alpha * 0.2; + } +} diff --git a/box.vertex.glsl b/box.vertex.glsl new file mode 100644 index 00000000000..d141b13873a --- /dev/null +++ b/box.vertex.glsl @@ -0,0 +1,16 @@ +attribute vec2 a_pos; +attribute vec2 a_extrude; +attribute vec2 a_data; + +uniform mat4 u_matrix; +uniform float u_scale; + +varying float v_max_zoom; +varying float v_placement_zoom; + +void main() { + gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0); + + v_max_zoom = a_data.x; + v_placement_zoom = a_data.y; +} diff --git a/box_shader.cpp b/box_shader.cpp new file mode 100644 index 00000000000..2676223a9da --- /dev/null +++ b/box_shader.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +CollisionBoxShader::CollisionBoxShader() + : Shader( + "collisionbox", + shaders[BOX_SHADER].vertex, + shaders[BOX_SHADER].fragment + ) { + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); +} + +void CollisionBoxShader::bind(char *offset) { + const int stride = 12; + + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); + + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_SHORT, false, stride, offset + 4)); + + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 2, GL_UNSIGNED_BYTE, false, stride, offset + 8)); + +} diff --git a/box_shader.hpp b/box_shader.hpp new file mode 100644 index 00000000000..5c84d8906c1 --- /dev/null +++ b/box_shader.hpp @@ -0,0 +1,28 @@ +#ifndef MBGL_SHADER_SHADER_BOX +#define MBGL_SHADER_SHADER_BOX + +#include +#include + +namespace mbgl { + +class CollisionBoxShader : public Shader { +public: + CollisionBoxShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform u_scale = {"u_scale", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_maxzoom = {"u_maxzoom", *this}; + +protected: + int32_t a_pos = -1; + int32_t a_extrude = -1; + int32_t a_data = -1; +}; + +} + +#endif From 3b69f4e10dfafced3c1117b606009375d1ab5777 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 6 Apr 2015 11:22:05 -0700 Subject: [PATCH 123/259] misc small changes made while porting to native --- collisionbox.vertex.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collisionbox.vertex.glsl b/collisionbox.vertex.glsl index b085ab91475..ecd4a7e1c96 100644 --- a/collisionbox.vertex.glsl +++ b/collisionbox.vertex.glsl @@ -11,6 +11,6 @@ varying float v_placement_zoom; void main() { gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0); - v_max_zoom = a_data.x + 128.0; - v_placement_zoom = a_data.y + 128.0; + v_max_zoom = a_data.x; + v_placement_zoom = a_data.y; } From d06627220b8b69749e613bf42476c14eccadf30c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 24 Apr 2015 13:06:01 -0700 Subject: [PATCH 124/259] remove linejoin shader The previous commit switched to using triangles for drawing round joins. --- linejoin.fragment.glsl | 14 -------------- linejoin.vertex.glsl | 13 ------------- linejoin_shader.cpp | 22 ---------------------- linejoin_shader.hpp | 27 --------------------------- 4 files changed, 76 deletions(-) delete mode 100644 linejoin.fragment.glsl delete mode 100644 linejoin.vertex.glsl delete mode 100644 linejoin_shader.cpp delete mode 100644 linejoin_shader.hpp diff --git a/linejoin.fragment.glsl b/linejoin.fragment.glsl deleted file mode 100644 index 705a57766e4..00000000000 --- a/linejoin.fragment.glsl +++ /dev/null @@ -1,14 +0,0 @@ -uniform vec4 u_color; -uniform vec2 u_linewidth; - -varying vec2 v_pos; - -void main() { - float dist = length(v_pos - gl_FragCoord.xy); - - // Calculate the antialiasing fade factor. This is either when fading in - // the line in case of an offset line (v_linewidth.t) or when fading out - // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist), 0.0, 1.0); - gl_FragColor = u_color * alpha; -} diff --git a/linejoin.vertex.glsl b/linejoin.vertex.glsl deleted file mode 100644 index 2e03561e5b4..00000000000 --- a/linejoin.vertex.glsl +++ /dev/null @@ -1,13 +0,0 @@ -attribute vec2 a_pos; - -uniform mat4 u_matrix; -uniform vec2 u_world; -uniform float u_size; - -varying vec2 v_pos; - -void main() { - gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0); - v_pos = (gl_Position.xy + 1.0) * u_world; - gl_PointSize = u_size; -} diff --git a/linejoin_shader.cpp b/linejoin_shader.cpp deleted file mode 100644 index b3c5638b5d8..00000000000 --- a/linejoin_shader.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -#include - -using namespace mbgl; - -LinejoinShader::LinejoinShader() - : Shader( - "linejoin", - shaders[LINEJOIN_SHADER].vertex, - shaders[LINEJOIN_SHADER].fragment - ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); -} - -void LinejoinShader::bind(char *offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - // Note: We're referring to the vertices in a line array, which are 8 bytes long! - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); -} diff --git a/linejoin_shader.hpp b/linejoin_shader.hpp deleted file mode 100644 index 61406fd45ca..00000000000 --- a/linejoin_shader.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINEJOIN -#define MBGL_SHADER_SHADER_LINEJOIN - -#include -#include - -namespace mbgl { - -class LinejoinShader : public Shader { -public: - LinejoinShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_world = {"u_world", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform u_size = {"u_size", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif From 5ba58eab7342124f2487c532f869476fa9c9f1f0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 1 May 2015 09:44:15 -0400 Subject: [PATCH 125/259] Fix uninitialized variable --- uniform.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uniform.hpp b/uniform.hpp index 9a25d105cfa..d2a248c609d 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -9,7 +9,7 @@ namespace mbgl { template class Uniform { public: - Uniform(const GLchar* name, const Shader& shader) { + Uniform(const GLchar* name, const Shader& shader) : current() { location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); } @@ -32,7 +32,7 @@ class UniformMatrix { public: typedef std::array T; - UniformMatrix(const GLchar* name, const Shader& shader) { + UniformMatrix(const GLchar* name, const Shader& shader) : current() { location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); } From 522fa4a8cb31d91da58ae19dff53c5f1890ff60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 26 May 2015 15:18:27 +0200 Subject: [PATCH 126/259] Replace mbgl::util::make_unique<> with std::make_unique<> --- shader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shader.cpp b/shader.cpp index a079409aa0d..6210c1c32e5 100644 --- a/shader.cpp +++ b/shader.cpp @@ -51,7 +51,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (status == 0) { GLint logLength; MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); - std::unique_ptr log = mbgl::util::make_unique(logLength); + const auto log = std::make_unique(logLength); if (logLength > 0) { MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); @@ -76,7 +76,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo if (status == 0) { GLint logLength; MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); - std::unique_ptr log = mbgl::util::make_unique(logLength); + const auto log = std::make_unique(logLength); if (logLength > 0) { MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); @@ -115,7 +115,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { GLint logLength; MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { - std::unique_ptr log = mbgl::util::make_unique(logLength); + const auto log = std::make_unique(logLength); MBGL_CHECK_ERROR(glGetShaderInfoLog(*shader, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); } From 5c70a45a1bb30019028192c3181778d4c9daa3c9 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 9 Jun 2015 11:19:58 -0400 Subject: [PATCH 127/259] Made line color a attribute / varying pair --- line.fragment.glsl | 4 ++-- line.vertex.glsl | 5 ++++- linepattern.vertex.glsl | 2 -- linesdfpattern.fragment.glsl | 5 ++--- linesdfpattern.vertex.glsl | 4 ++++ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 7e7d5d1b0e3..bd465c9ab78 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,9 +1,9 @@ uniform vec2 u_linewidth; -uniform vec4 u_color; uniform float u_blur; uniform vec2 u_dasharray; +varying vec4 v_color; varying vec2 v_normal; varying float v_linesofar; varying float gamma_scale; @@ -18,5 +18,5 @@ void main() { float blur = u_blur * gamma_scale; float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); - gl_FragColor = u_color * alpha; + gl_FragColor = v_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index fc7fc7f771e..3dfec46c1e1 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -8,6 +8,7 @@ attribute vec2 a_pos; attribute vec4 a_data; +attribute vec4 a_color; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -16,13 +17,13 @@ uniform mat4 u_matrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; -uniform vec4 u_color; uniform float u_extra; uniform mat2 u_antialiasingmatrix; varying vec2 v_normal; varying float v_linesofar; +varying vec4 v_color; varying float gamma_scale; void main() { @@ -56,4 +57,6 @@ void main() { float perspective_scale = 1.0 / (1.0 - y * u_extra); gamma_scale = perspective_scale * squish_scale; + + v_color = a_color; } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 65aed9f26c2..f924fc063e0 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -17,7 +17,6 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; -uniform vec4 u_color; varying vec2 v_normal; varying float v_linesofar; @@ -45,5 +44,4 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar;// * u_ratio; - } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index c3384ebf88d..9052d61d35c 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,14 +1,13 @@ uniform vec2 u_linewidth; -uniform vec4 u_color; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; - varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; +varying vec4 v_color; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -24,5 +23,5 @@ void main() { float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); - gl_FragColor = u_color * alpha; + gl_FragColor = v_color * alpha; } diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 9da42801b4e..237e4a300ec 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -8,6 +8,7 @@ attribute vec2 a_pos; attribute vec4 a_data; +attribute vec4 a_color; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -24,6 +25,7 @@ uniform float u_tex_y_b; varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; +varying vec4 v_color; void main() { vec2 a_extrude = a_data.xy; @@ -49,4 +51,6 @@ void main() { v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); + + v_color = a_color; } From bf8ce3e5663a674b769764d6f5aa32f7f5eead6e Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 9 Jun 2015 14:48:25 -0400 Subject: [PATCH 128/259] Made linewidth an attribute / varying pair --- line.fragment.glsl | 6 +++--- line.vertex.glsl | 6 ++++-- linepattern.fragment.glsl | 10 +++++----- linepattern.vertex.glsl | 7 +++++-- linesdfpattern.fragment.glsl | 6 +++--- linesdfpattern.vertex.glsl | 6 ++++-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index bd465c9ab78..23ff0516a01 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,4 +1,3 @@ -uniform vec2 u_linewidth; uniform float u_blur; uniform vec2 u_dasharray; @@ -7,16 +6,17 @@ varying vec4 v_color; varying vec2 v_normal; varying float v_linesofar; varying float gamma_scale; +varying vec2 v_linewidth; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * u_linewidth.s; + float dist = length(v_normal) * v_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * gamma_scale; - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = v_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index 3dfec46c1e1..3c7abc55136 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -9,6 +9,7 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec4 a_color; +attribute vec2 a_linewidth; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -16,7 +17,6 @@ uniform mat4 u_matrix; // shared uniform float u_ratio; -uniform vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; @@ -25,6 +25,7 @@ varying vec2 v_normal; varying float v_linesofar; varying vec4 v_color; varying float gamma_scale; +varying vec2 v_linewidth; void main() { vec2 a_extrude = a_data.xy; @@ -39,7 +40,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + vec4 dist = vec4(a_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix @@ -59,4 +60,5 @@ void main() { gamma_scale = perspective_scale * squish_scale; v_color = a_color; + v_linewidth = a_linewidth; } diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 50c3f98e4ea..87ad93ddc95 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,4 +1,3 @@ -uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; @@ -15,20 +14,21 @@ uniform sampler2D u_image; varying vec2 v_normal; varying float v_linesofar; +varying vec2 v_linewidth; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * u_linewidth.s; + float dist = length(v_normal) * v_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - u_blur), v_linewidth.s - dist) / u_blur, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); - float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); - float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); + float y_a = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_a.y); + float y_b = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_b.y); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index f924fc063e0..4d829162c54 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -8,6 +8,7 @@ attribute vec2 a_pos; attribute vec4 a_data; +attribute vec2 a_linewidth; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -16,10 +17,10 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; -uniform vec2 u_linewidth; varying vec2 v_normal; varying float v_linesofar; +varying vec2 v_linewidth; void main() { vec2 a_extrude = a_data.xy; @@ -36,7 +37,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. vec2 extrude = a_extrude * scale; - vec2 dist = u_linewidth.s * extrude; + vec2 dist = a_linewidth.s * extrude; // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix @@ -44,4 +45,6 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar;// * u_ratio; + + v_linewidth = a_linewidth; } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index 9052d61d35c..a399ddf18dd 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,4 +1,3 @@ -uniform vec2 u_linewidth; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; @@ -8,15 +7,16 @@ varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; +varying vec2 v_linewidth; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * u_linewidth.s; + float dist = length(v_normal) * v_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - u_blur), v_linewidth.s - dist) / u_blur, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 237e4a300ec..d84629558c9 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -9,13 +9,13 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec4 a_color; +attribute vec2 a_linewidth; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform vec2 u_linewidth; uniform float u_ratio; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; @@ -26,6 +26,7 @@ varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; +varying vec2 v_linewidth; void main() { vec2 a_extrude = a_data.xy; @@ -41,7 +42,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + vec4 dist = vec4(a_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix @@ -53,4 +54,5 @@ void main() { v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); v_color = a_color; + v_linewidth = a_linewidth; } From 941903e312187b88cb4789575eccba545ca5424d Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 10 Jun 2015 11:47:17 -0400 Subject: [PATCH 129/259] Made fillShader color an attribute / varying pair --- fill.fragment.glsl | 4 ++-- fill.vertex.glsl | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fill.fragment.glsl b/fill.fragment.glsl index 8df552c1718..7c31f83aacb 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -1,5 +1,5 @@ -uniform vec4 u_color; +varying vec4 v_color; void main() { - gl_FragColor = u_color; + gl_FragColor = v_color; } diff --git a/fill.vertex.glsl b/fill.vertex.glsl index 08c99981877..dcfe9f4e68d 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,7 +1,13 @@ -attribute vec2 a_pos; uniform mat4 u_matrix; +attribute vec2 a_pos; +attribute vec4 a_color; + +varying vec4 v_color; + void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); gl_PointSize = 2.0; + + v_color = a_color; } From 058bf651cee3ee45f0a6316e8e728ced907f8a66 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 10 Jun 2015 14:25:21 -0400 Subject: [PATCH 130/259] Made line blur an attribute / varying pair --- line.fragment.glsl | 4 ++-- line.vertex.glsl | 3 +++ linepattern.fragment.glsl | 4 ++-- linepattern.vertex.glsl | 3 +++ linesdfpattern.fragment.glsl | 4 ++-- linesdfpattern.vertex.glsl | 3 +++ 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 23ff0516a01..4a87a593aca 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,4 +1,3 @@ -uniform float u_blur; uniform vec2 u_dasharray; @@ -7,6 +6,7 @@ varying vec2 v_normal; varying float v_linesofar; varying float gamma_scale; varying vec2 v_linewidth; +varying float v_blur; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -15,7 +15,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float blur = u_blur * gamma_scale; + float blur = v_blur * gamma_scale; float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = v_color * alpha; diff --git a/line.vertex.glsl b/line.vertex.glsl index 3c7abc55136..d58ce277069 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -10,6 +10,7 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec4 a_color; attribute vec2 a_linewidth; +attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -26,6 +27,7 @@ varying float v_linesofar; varying vec4 v_color; varying float gamma_scale; varying vec2 v_linewidth; +varying float v_blur; void main() { vec2 a_extrude = a_data.xy; @@ -61,4 +63,5 @@ void main() { v_color = a_color; v_linewidth = a_linewidth; + v_blur = a_blur; } diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 87ad93ddc95..426dd68dbf8 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,5 +1,4 @@ uniform float u_point; -uniform float u_blur; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; @@ -15,6 +14,7 @@ uniform sampler2D u_image; varying vec2 v_normal; varying float v_linesofar; varying vec2 v_linewidth; +varying float v_blur; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -23,7 +23,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (v_linewidth.t - u_blur), v_linewidth.s - dist) / u_blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - v_blur), v_linewidth.s - dist) / v_blur, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 4d829162c54..b6ee31f07c6 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -9,6 +9,7 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec2 a_linewidth; +attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -21,6 +22,7 @@ uniform float u_ratio; varying vec2 v_normal; varying float v_linesofar; varying vec2 v_linewidth; +varying float v_blur; void main() { vec2 a_extrude = a_data.xy; @@ -47,4 +49,5 @@ void main() { v_linesofar = a_linesofar;// * u_ratio; v_linewidth = a_linewidth; + v_blur = a_blur; } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index a399ddf18dd..9034c7d94dc 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,4 +1,3 @@ -uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; @@ -8,6 +7,7 @@ varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; varying vec2 v_linewidth; +varying float v_blur; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -16,7 +16,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (v_linewidth.t - u_blur), v_linewidth.s - dist) / u_blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - v_blur), v_linewidth.s - dist) / v_blur, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index d84629558c9..87a87986d2c 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -10,6 +10,7 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec4 a_color; attribute vec2 a_linewidth; +attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -27,6 +28,7 @@ varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; varying vec2 v_linewidth; +varying float v_blur; void main() { vec2 a_extrude = a_data.xy; @@ -55,4 +57,5 @@ void main() { v_color = a_color; v_linewidth = a_linewidth; + v_blur = a_blur; } From 524c1d487f89632314335e507be0e2d37d497dc2 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 10 Jun 2015 14:36:19 -0400 Subject: [PATCH 131/259] Made outline color an attribute / varying pair --- outline.fragment.glsl | 5 ++--- outline.vertex.glsl | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/outline.fragment.glsl b/outline.fragment.glsl index eccda714e52..99f1595307e 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -1,9 +1,8 @@ -uniform vec4 u_color; - +varying vec4 v_color; varying vec2 v_pos; void main() { float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); - gl_FragColor = u_color * alpha; + gl_FragColor = v_color * alpha; } diff --git a/outline.vertex.glsl b/outline.vertex.glsl index 535063b5964..1cd8e46fe36 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,10 +1,13 @@ attribute vec2 a_pos; +attribute vec4 a_color; + uniform mat4 u_matrix; uniform vec2 u_world; - +varying vec4 v_color; varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; + v_color = a_color; } From 95b7129041d01141ddd3c2181e102dc72e5d8db7 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 10 Jun 2015 14:48:18 -0400 Subject: [PATCH 132/259] Made sdf color an attribute / varying pair --- sdf.fragment.glsl | 4 ++-- sdf.vertex.glsl | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index a7ae7f821f6..edba04f99a3 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,15 +1,15 @@ uniform sampler2D u_texture; -uniform vec4 u_color; uniform float u_buffer; uniform float u_gamma; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; +varying vec4 v_color; void main() { float gamma = u_gamma * v_gamma_scale; float dist = texture2D(u_texture, v_tex).a; float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; - gl_FragColor = u_color * alpha; + gl_FragColor = v_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 10aa5e3b497..1e2fa22a95e 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -2,7 +2,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; attribute vec4 a_data2; - +attribute vec4 a_color; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -22,6 +22,7 @@ uniform vec2 u_texsize; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; +varying vec4 v_color; void main() { vec2 a_tex = a_data1.xy; @@ -67,4 +68,5 @@ void main() { v_gamma_scale = perspective_scale; v_tex = a_tex / u_texsize; + v_color = a_color; } From b549be41a65d456bea8a48ef4588f0f33a20d700 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 10 Jun 2015 15:36:00 -0400 Subject: [PATCH 133/259] Made sf buffer an attribute / varying pair, always enable vertex attribs after disabling --- sdf.fragment.glsl | 4 ++-- sdf.vertex.glsl | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index edba04f99a3..68c612820e0 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,15 +1,15 @@ uniform sampler2D u_texture; -uniform float u_buffer; uniform float u_gamma; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; varying vec4 v_color; +varying float v_buffer; void main() { float gamma = u_gamma * v_gamma_scale; float dist = texture2D(u_texture, v_tex).a; - float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; + float alpha = smoothstep(v_buffer - gamma, v_buffer + gamma, dist) * v_alpha; gl_FragColor = v_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 1e2fa22a95e..139d2fb8d71 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -3,6 +3,7 @@ attribute vec2 a_offset; attribute vec4 a_data1; attribute vec4 a_data2; attribute vec4 a_color; +attribute float a_buffer; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -23,6 +24,7 @@ varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; varying vec4 v_color; +varying float v_buffer; void main() { vec2 a_tex = a_data1.xy; @@ -69,4 +71,5 @@ void main() { v_tex = a_tex / u_texsize; v_color = a_color; + v_buffer = a_buffer; } From b3a09aef743fca2e07b394c7b98a3f853390817f Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 11 Jun 2015 14:48:15 -0400 Subject: [PATCH 134/259] Made line pattern opacity an attribute / varying pair --- linepattern.fragment.glsl | 4 ++-- linepattern.vertex.glsl | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 426dd68dbf8..9396968edc0 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -7,7 +7,6 @@ uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; uniform vec2 u_pattern_br_b; uniform float u_fade; -uniform float u_opacity; uniform sampler2D u_image; @@ -15,6 +14,7 @@ varying vec2 v_normal; varying float v_linesofar; varying vec2 v_linewidth; varying float v_blur; +varying float v_opacity; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -34,7 +34,7 @@ void main() { vec4 color = mix(texture2D(u_image, pos), texture2D(u_image, pos2), u_fade); - alpha *= u_opacity; + alpha *= v_opacity; gl_FragColor = color * alpha; } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index b6ee31f07c6..fc77f6fc600 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -10,6 +10,7 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec2 a_linewidth; attribute float a_blur; +attribute float a_opacity; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -23,6 +24,7 @@ varying vec2 v_normal; varying float v_linesofar; varying vec2 v_linewidth; varying float v_blur; +varying float v_opacity; void main() { vec2 a_extrude = a_data.xy; @@ -50,4 +52,5 @@ void main() { v_linewidth = a_linewidth; v_blur = a_blur; + v_opacity = a_opacity; } From 351f2e6202f24e56a46c121b8439268e25180c16 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 11 Jun 2015 15:00:05 -0400 Subject: [PATCH 135/259] Made icon opacity an attribute / varying pair --- icon.vertex.glsl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 16759a1f3db..dc43253e6b5 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -2,7 +2,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; attribute vec4 a_data2; - +attribute float a_opacity; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -13,7 +13,6 @@ uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; -uniform float u_opacity; uniform bool u_skewed; uniform float u_extra; @@ -63,5 +62,5 @@ void main() { v_tex = a_tex / u_texsize; - v_alpha *= u_opacity; + v_alpha *= a_opacity; } From b7cf1fb9a109527dcf2d5a05db68ea3630f6dbdf Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 11 Jun 2015 15:06:47 -0400 Subject: [PATCH 136/259] Made symbol gamma an attribute / varying pair --- outline.vertex.glsl | 1 + sdf.fragment.glsl | 4 ++-- sdf.vertex.glsl | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/outline.vertex.glsl b/outline.vertex.glsl index 1cd8e46fe36..bf876b0333d 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -3,6 +3,7 @@ attribute vec4 a_color; uniform mat4 u_matrix; uniform vec2 u_world; + varying vec4 v_color; varying vec2 v_pos; diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index 68c612820e0..4c17d38da8a 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,14 +1,14 @@ uniform sampler2D u_texture; -uniform float u_gamma; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; varying vec4 v_color; varying float v_buffer; +varying float v_gamma; void main() { - float gamma = u_gamma * v_gamma_scale; + float gamma = v_gamma * v_gamma_scale; float dist = texture2D(u_texture, v_tex).a; float alpha = smoothstep(v_buffer - gamma, v_buffer + gamma, dist) * v_alpha; gl_FragColor = v_color * alpha; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 139d2fb8d71..b881ef747e9 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -4,6 +4,7 @@ attribute vec4 a_data1; attribute vec4 a_data2; attribute vec4 a_color; attribute float a_buffer; +attribute float a_gamma; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -25,6 +26,7 @@ varying float v_alpha; varying float v_gamma_scale; varying vec4 v_color; varying float v_buffer; +varying float v_gamma; void main() { vec2 a_tex = a_data1.xy; @@ -72,4 +74,5 @@ void main() { v_tex = a_tex / u_texsize; v_color = a_color; v_buffer = a_buffer; + v_gamma = a_gamma; } From 293c80c6916a37cae6fc5e00d5c0d626747451d3 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 11 Jun 2015 13:23:07 -0400 Subject: [PATCH 137/259] fix precision issues on iOS, close #750 --- icon.vertex.glsl | 2 +- line.vertex.glsl | 2 +- linepattern.vertex.glsl | 2 +- linesdfpattern.vertex.glsl | 2 +- outline.vertex.glsl | 2 +- sdf.vertex.glsl | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index dc43253e6b5..1b45ded2675 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -6,7 +6,7 @@ attribute float a_opacity; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; uniform float u_fadedist; diff --git a/line.vertex.glsl b/line.vertex.glsl index d58ce277069..82513769f6f 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -14,7 +14,7 @@ attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; // shared uniform float u_ratio; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index fc77f6fc600..f120a76aa09 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -14,7 +14,7 @@ attribute float a_opacity; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform mat4 u_exmatrix; // shared diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 87a87986d2c..526dcae9579 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -14,7 +14,7 @@ attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_ratio; diff --git a/outline.vertex.glsl b/outline.vertex.glsl index bf876b0333d..ca69ee3002d 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,7 +1,7 @@ attribute vec2 a_pos; attribute vec4 a_color; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform vec2 u_world; varying vec4 v_color; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index b881ef747e9..abb2bf2c9cf 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -8,7 +8,7 @@ attribute float a_gamma; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; From a4eb3b09cf3ffe6547cb2cbab902ab12b770ef88 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 17 Jun 2015 18:19:47 -0400 Subject: [PATCH 138/259] Circles: meet v8. This is a manual redo of #1241 on top of the v8 branch. --- circle.fragment.glsl | 10 ++++++++++ circle.vertex.glsl | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 circle.fragment.glsl create mode 100644 circle.vertex.glsl diff --git a/circle.fragment.glsl b/circle.fragment.glsl new file mode 100644 index 00000000000..7267bf81e3b --- /dev/null +++ b/circle.fragment.glsl @@ -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); +} diff --git a/circle.vertex.glsl b/circle.vertex.glsl new file mode 100644 index 00000000000..eeeb30abc5b --- /dev/null +++ b/circle.vertex.glsl @@ -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; +} From c0fcce02f2f3abda5163965c45557d1c23c0645c Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 10 Aug 2015 12:00:11 -0700 Subject: [PATCH 139/259] Revert shader "uniform" to "attribute" refactorings --- fill.fragment.glsl | 4 ++-- fill.vertex.glsl | 8 +------- icon.vertex.glsl | 5 +++-- line.fragment.glsl | 10 +++++----- line.vertex.glsl | 9 ++------- linepattern.fragment.glsl | 16 ++++++++-------- linepattern.vertex.glsl | 13 ++----------- linesdfpattern.fragment.glsl | 8 ++++---- linesdfpattern.vertex.glsl | 9 ++------- outline.fragment.glsl | 5 +++-- outline.vertex.glsl | 3 --- sdf.fragment.glsl | 12 ++++++------ sdf.vertex.glsl | 10 +--------- 13 files changed, 39 insertions(+), 73 deletions(-) diff --git a/fill.fragment.glsl b/fill.fragment.glsl index 7c31f83aacb..8df552c1718 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -1,5 +1,5 @@ -varying vec4 v_color; +uniform vec4 u_color; void main() { - gl_FragColor = v_color; + gl_FragColor = u_color; } diff --git a/fill.vertex.glsl b/fill.vertex.glsl index dcfe9f4e68d..08c99981877 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,13 +1,7 @@ -uniform mat4 u_matrix; - attribute vec2 a_pos; -attribute vec4 a_color; - -varying vec4 v_color; +uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); gl_PointSize = 2.0; - - v_color = a_color; } diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 1b45ded2675..498c769f5a9 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -2,7 +2,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; attribute vec4 a_data2; -attribute float a_opacity; + // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -13,6 +13,7 @@ uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; +uniform float u_opacity; uniform bool u_skewed; uniform float u_extra; @@ -62,5 +63,5 @@ void main() { v_tex = a_tex / u_texsize; - v_alpha *= a_opacity; + v_alpha *= u_opacity; } diff --git a/line.fragment.glsl b/line.fragment.glsl index 4a87a593aca..bd465c9ab78 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,3 +1,5 @@ +uniform vec2 u_linewidth; +uniform float u_blur; uniform vec2 u_dasharray; @@ -5,18 +7,16 @@ varying vec4 v_color; varying vec2 v_normal; varying float v_linesofar; varying float gamma_scale; -varying vec2 v_linewidth; -varying float v_blur; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * v_linewidth.s; + float dist = length(v_normal) * u_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float blur = v_blur * gamma_scale; - float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); + float blur = u_blur * gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = v_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index 82513769f6f..7103b65fa41 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -9,8 +9,6 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec4 a_color; -attribute vec2 a_linewidth; -attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -18,6 +16,7 @@ uniform highp mat4 u_matrix; // shared uniform float u_ratio; +uniform vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; @@ -26,8 +25,6 @@ varying vec2 v_normal; varying float v_linesofar; varying vec4 v_color; varying float gamma_scale; -varying vec2 v_linewidth; -varying float v_blur; void main() { vec2 a_extrude = a_data.xy; @@ -42,7 +39,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(a_linewidth.s * a_extrude * scale, 0.0, 0.0); + vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix @@ -62,6 +59,4 @@ void main() { gamma_scale = perspective_scale * squish_scale; v_color = a_color; - v_linewidth = a_linewidth; - v_blur = a_blur; } diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 9396968edc0..50c3f98e4ea 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,4 +1,6 @@ +uniform vec2 u_linewidth; uniform float u_point; +uniform float u_blur; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; @@ -7,34 +9,32 @@ uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; uniform vec2 u_pattern_br_b; uniform float u_fade; +uniform float u_opacity; uniform sampler2D u_image; varying vec2 v_normal; varying float v_linesofar; -varying vec2 v_linewidth; -varying float v_blur; -varying float v_opacity; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * v_linewidth.s; + float dist = length(v_normal) * u_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (v_linewidth.t - v_blur), v_linewidth.s - dist) / v_blur, 0.0, 1.0); + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); - float y_a = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_a.y); - float y_b = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_b.y); + float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); + float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); vec4 color = mix(texture2D(u_image, pos), texture2D(u_image, pos2), u_fade); - alpha *= v_opacity; + alpha *= u_opacity; gl_FragColor = color * alpha; } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index f120a76aa09..0b8faee043a 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -8,9 +8,6 @@ attribute vec2 a_pos; attribute vec4 a_data; -attribute vec2 a_linewidth; -attribute float a_blur; -attribute float a_opacity; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -19,12 +16,10 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; +uniform vec2 u_linewidth; varying vec2 v_normal; varying float v_linesofar; -varying vec2 v_linewidth; -varying float v_blur; -varying float v_opacity; void main() { vec2 a_extrude = a_data.xy; @@ -41,7 +36,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. vec2 extrude = a_extrude * scale; - vec2 dist = a_linewidth.s * extrude; + vec2 dist = u_linewidth.s * extrude; // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix @@ -49,8 +44,4 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar;// * u_ratio; - - v_linewidth = a_linewidth; - v_blur = a_blur; - v_opacity = a_opacity; } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index 9034c7d94dc..9052d61d35c 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,3 +1,5 @@ +uniform vec2 u_linewidth; +uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; @@ -6,17 +8,15 @@ varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; -varying vec2 v_linewidth; -varying float v_blur; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * v_linewidth.s; + float dist = length(v_normal) * u_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (v_linewidth.t - v_blur), v_linewidth.s - dist) / v_blur, 0.0, 1.0); + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 526dcae9579..e7191dc1d8f 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -9,14 +9,13 @@ attribute vec2 a_pos; attribute vec4 a_data; attribute vec4 a_color; -attribute vec2 a_linewidth; -attribute float a_blur; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. uniform highp mat4 u_matrix; uniform mat4 u_exmatrix; +uniform vec2 u_linewidth; uniform float u_ratio; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; @@ -27,8 +26,6 @@ varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; -varying vec2 v_linewidth; -varying float v_blur; void main() { vec2 a_extrude = a_data.xy; @@ -44,7 +41,7 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(a_linewidth.s * a_extrude * scale, 0.0, 0.0); + vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix @@ -56,6 +53,4 @@ void main() { v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); v_color = a_color; - v_linewidth = a_linewidth; - v_blur = a_blur; } diff --git a/outline.fragment.glsl b/outline.fragment.glsl index 99f1595307e..eccda714e52 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -1,8 +1,9 @@ -varying vec4 v_color; +uniform vec4 u_color; + varying vec2 v_pos; void main() { float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); - gl_FragColor = v_color * alpha; + gl_FragColor = u_color * alpha; } diff --git a/outline.vertex.glsl b/outline.vertex.glsl index ca69ee3002d..b8658e60482 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,14 +1,11 @@ attribute vec2 a_pos; -attribute vec4 a_color; uniform highp mat4 u_matrix; uniform vec2 u_world; -varying vec4 v_color; varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; - v_color = a_color; } diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index 4c17d38da8a..a7ae7f821f6 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,15 +1,15 @@ uniform sampler2D u_texture; +uniform vec4 u_color; +uniform float u_buffer; +uniform float u_gamma; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; -varying vec4 v_color; -varying float v_buffer; -varying float v_gamma; void main() { - float gamma = v_gamma * v_gamma_scale; + float gamma = u_gamma * v_gamma_scale; float dist = texture2D(u_texture, v_tex).a; - float alpha = smoothstep(v_buffer - gamma, v_buffer + gamma, dist) * v_alpha; - gl_FragColor = v_color * alpha; + float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; + gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index abb2bf2c9cf..287e2631888 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -2,9 +2,7 @@ attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; attribute vec4 a_data2; -attribute vec4 a_color; -attribute float a_buffer; -attribute float a_gamma; + // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -24,9 +22,6 @@ uniform vec2 u_texsize; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; -varying vec4 v_color; -varying float v_buffer; -varying float v_gamma; void main() { vec2 a_tex = a_data1.xy; @@ -72,7 +67,4 @@ void main() { v_gamma_scale = perspective_scale; v_tex = a_tex / u_texsize; - v_color = a_color; - v_buffer = a_buffer; - v_gamma = a_gamma; } From c864d88cfe2ef702199efc315f85ff070c623e5f Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 20 Aug 2015 11:23:26 -0400 Subject: [PATCH 140/259] remove unused gaussian blur shader --- gaussian.fragment.glsl | 11 ----------- gaussian.vertex.glsl | 15 --------------- 2 files changed, 26 deletions(-) delete mode 100644 gaussian.fragment.glsl delete mode 100644 gaussian.vertex.glsl diff --git a/gaussian.fragment.glsl b/gaussian.fragment.glsl deleted file mode 100644 index ee8406e9e11..00000000000 --- a/gaussian.fragment.glsl +++ /dev/null @@ -1,11 +0,0 @@ -uniform sampler2D u_image; - -varying vec2 v_coords[3]; - -void main() { - vec4 sum = vec4(0.0); - sum += texture2D(u_image, v_coords[0]) * 0.40261994689424746; - sum += texture2D(u_image, v_coords[1]) * 0.2986900265528763; - sum += texture2D(u_image, v_coords[2]) * 0.2986900265528763; - gl_FragColor = sum; -} diff --git a/gaussian.vertex.glsl b/gaussian.vertex.glsl deleted file mode 100644 index 26a83942046..00000000000 --- a/gaussian.vertex.glsl +++ /dev/null @@ -1,15 +0,0 @@ -attribute vec2 a_pos; - -uniform mat4 u_matrix; -uniform vec2 u_offset; - -varying vec2 v_coords[3]; - -void main() { - gl_Position = u_matrix * vec4(a_pos, 0, 1); - - vec2 tex = gl_Position.xy / 2.0 + 0.5; - v_coords[0] = tex; - v_coords[1] = tex + u_offset * 1.1824255238063563; - v_coords[2] = tex - u_offset * 1.1824255238063563; -} From 8d5df593126d3d647c9f3da262724d96a7ef03ee Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 20 Aug 2015 11:38:56 -0400 Subject: [PATCH 141/259] remove unused gaussian shader --- gaussian.fragment.glsl | 11 ----------- gaussian.vertex.glsl | 15 --------------- gaussian_shader.cpp | 21 --------------------- gaussian_shader.hpp | 25 ------------------------- 4 files changed, 72 deletions(-) delete mode 100644 gaussian.fragment.glsl delete mode 100644 gaussian.vertex.glsl delete mode 100644 gaussian_shader.cpp delete mode 100644 gaussian_shader.hpp diff --git a/gaussian.fragment.glsl b/gaussian.fragment.glsl deleted file mode 100644 index ee8406e9e11..00000000000 --- a/gaussian.fragment.glsl +++ /dev/null @@ -1,11 +0,0 @@ -uniform sampler2D u_image; - -varying vec2 v_coords[3]; - -void main() { - vec4 sum = vec4(0.0); - sum += texture2D(u_image, v_coords[0]) * 0.40261994689424746; - sum += texture2D(u_image, v_coords[1]) * 0.2986900265528763; - sum += texture2D(u_image, v_coords[2]) * 0.2986900265528763; - gl_FragColor = sum; -} diff --git a/gaussian.vertex.glsl b/gaussian.vertex.glsl deleted file mode 100644 index 26a83942046..00000000000 --- a/gaussian.vertex.glsl +++ /dev/null @@ -1,15 +0,0 @@ -attribute vec2 a_pos; - -uniform mat4 u_matrix; -uniform vec2 u_offset; - -varying vec2 v_coords[3]; - -void main() { - gl_Position = u_matrix * vec4(a_pos, 0, 1); - - vec2 tex = gl_Position.xy / 2.0 + 0.5; - v_coords[0] = tex; - v_coords[1] = tex + u_offset * 1.1824255238063563; - v_coords[2] = tex - u_offset * 1.1824255238063563; -} diff --git a/gaussian_shader.cpp b/gaussian_shader.cpp deleted file mode 100644 index b7d593f2e40..00000000000 --- a/gaussian_shader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -#include - -using namespace mbgl; - -GaussianShader::GaussianShader() - : Shader( - "gaussian", - shaders[GAUSSIAN_SHADER].vertex, - shaders[GAUSSIAN_SHADER].fragment - ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); -} - -void GaussianShader::bind(char *offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); -} diff --git a/gaussian_shader.hpp b/gaussian_shader.hpp deleted file mode 100644 index 0f494f5c7eb..00000000000 --- a/gaussian_shader.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_RENDERER_SHADER_GAUSSIAN -#define MBGL_RENDERER_SHADER_GAUSSIAN - -#include -#include - -namespace mbgl { - -class GaussianShader : public Shader { -public: - GaussianShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_offset = {"u_offset", *this}; - Uniform u_image = {"u_image", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif From a72b313d2b281fed849ba395c2f198c62ea441d8 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 17 Jun 2015 10:56:18 +0300 Subject: [PATCH 142/259] Add circle render type As specified in: https://github.com/mapbox/mapbox-gl-style-spec/blob/v8-circle/reference/v8.json Part of #1740. --- circle.fragment.glsl | 10 ++++++++++ circle.vertex.glsl | 23 +++++++++++++++++++++++ circle_shader.cpp | 21 +++++++++++++++++++++ circle_shader.hpp | 27 +++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 circle.fragment.glsl create mode 100644 circle.vertex.glsl create mode 100644 circle_shader.cpp create mode 100644 circle_shader.hpp diff --git a/circle.fragment.glsl b/circle.fragment.glsl new file mode 100644 index 00000000000..7267bf81e3b --- /dev/null +++ b/circle.fragment.glsl @@ -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); +} diff --git a/circle.vertex.glsl b/circle.vertex.glsl new file mode 100644 index 00000000000..eeeb30abc5b --- /dev/null +++ b/circle.vertex.glsl @@ -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; +} diff --git a/circle_shader.cpp b/circle_shader.cpp new file mode 100644 index 00000000000..074f92d68b2 --- /dev/null +++ b/circle_shader.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +#include + +using namespace mbgl; + +CircleShader::CircleShader() + : Shader( + "circle", + shaders[CIRCLE_SHADER].vertex, + shaders[CIRCLE_SHADER].fragment + ) { + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); +} + +void CircleShader::bind(char *offset) { + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 4, offset)); +} diff --git a/circle_shader.hpp b/circle_shader.hpp new file mode 100644 index 00000000000..545a0baad5c --- /dev/null +++ b/circle_shader.hpp @@ -0,0 +1,27 @@ +#ifndef MBGL_SHADER_CIRCLE_SHADER +#define MBGL_SHADER_CIRCLE_SHADER + +#include +#include + +namespace mbgl { + +class CircleShader : public Shader { +public: + CircleShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform u_size = {"u_size", *this}; + Uniform u_blur = {"u_blur", *this}; + +private: + int32_t a_pos = -1; +}; + +} + +#endif // MBGL_SHADER_CIRCLE_SHADER From c4093b52054b72d56fa97da9b3ad3fb2e261ab11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 11 Aug 2015 16:34:51 +0300 Subject: [PATCH 143/259] don't clip glyphs with the frustum --- sdf.vertex.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 416a9bca586..192459f9da0 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -28,7 +28,7 @@ void main() { float a_maxzoom = a_zoom[1]; // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); + float show = step(a_minzoom, u_zoom) * (1.0 - step(a_maxzoom, u_zoom)); // fade out labels float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); @@ -46,8 +46,8 @@ void main() { } // if label has been faded out, clip it - z += step(v_alpha, 0.0); + show *= (1.0 - step(v_alpha, 0.0)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); v_tex = a_tex / u_texsize; } From 36c47b276f347807a0824c7984f2958acd1e0714 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 14 Aug 2015 13:27:59 +0300 Subject: [PATCH 144/259] hacks to see stuff --- plain.vertex.glsl | 1 + 1 file changed, 1 insertion(+) diff --git a/plain.vertex.glsl b/plain.vertex.glsl index 866c3cd2f39..7ccbed12b99 100644 --- a/plain.vertex.glsl +++ b/plain.vertex.glsl @@ -4,4 +4,5 @@ uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); + gl_Position.z = 1.0; } From 05fedc2448f00dab58956c01915b53744dc17b15 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 14 Aug 2015 16:53:31 +0300 Subject: [PATCH 145/259] port line rendering fixes for perspective views --- line.fragment.glsl | 4 +++- line.vertex.glsl | 21 ++++++++++++++++----- line_shader.hpp | 2 ++ linepattern.vertex.glsl | 2 +- linesdf.vertex.glsl | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 717c46e10d6..e0ef6499653 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -3,6 +3,7 @@ uniform vec4 u_color; uniform float u_blur; varying vec2 v_normal; +varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -11,7 +12,8 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float blur = u_blur * v_gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = u_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index 1f5432991ce..f818565ccdd 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -9,17 +9,17 @@ attribute vec2 a_pos; attribute vec4 a_data; -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. uniform mat4 u_matrix; -uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; -uniform vec4 u_color; + +uniform float u_extra; +uniform mat2 u_antialiasingmatrix; varying vec2 v_normal; +varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; @@ -40,5 +40,16 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + + // how much features are squished in the y direction by the tilt + float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); + + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - y * u_extra); + + v_gamma_scale = perspective_scale * squish_scale; } diff --git a/line_shader.hpp b/line_shader.hpp index 85152d6e0c1..0572cac88d9 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -18,6 +18,8 @@ class LineShader : public Shader { Uniform> u_linewidth = {"u_linewidth", *this}; Uniform u_ratio = {"u_ratio", *this}; Uniform u_blur = {"u_blur", *this}; + Uniform u_extra = {"u_extra", *this}; + UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: int32_t a_pos = -1; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index ada384a3d10..47d551e2eb6 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -52,7 +52,7 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0); + gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar;// * u_ratio; diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl index 7f246ced67c..6529fb45c50 100644 --- a/linesdf.vertex.glsl +++ b/linesdf.vertex.glsl @@ -46,7 +46,7 @@ void main() { // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist; + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); From 8fa159ef02142f3b58e84b3c7c4dcfc2ba5a2ad0 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 14 Aug 2015 17:14:51 +0300 Subject: [PATCH 146/259] fix fill antialiasing for perspective views --- outline.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outline.vertex.glsl b/outline.vertex.glsl index 29c16e3ded2..f720b8d629c 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -6,5 +6,5 @@ varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world; + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } From 2970ca9366a9f81ae24846a8ed5b8ba44c16a10c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 14 Aug 2015 18:06:14 +0300 Subject: [PATCH 147/259] fix symbol rendering in perspective view --- icon.vertex.glsl | 12 +++++++++++- icon_shader.hpp | 2 ++ sdf.fragment.glsl | 4 +++- sdf.vertex.glsl | 18 +++++++++++++++++- sdf_shader.hpp | 2 ++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 549570021de..3850e01ab79 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -14,6 +14,8 @@ uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; uniform float u_opacity; +uniform bool u_skewed; +uniform float u_extra; uniform vec2 u_texsize; @@ -51,7 +53,15 @@ void main() { // if label has been faded out, clip it z += step(v_alpha, 0.0); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0); + if (u_skewed) { + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); + gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); + gl_Position.z += z * gl_Position.w; + } else { + vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; + } + v_tex = a_tex / u_texsize; v_alpha *= u_opacity; diff --git a/icon_shader.hpp b/icon_shader.hpp index b6156ae9a0f..18b0fce37ba 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -21,6 +21,8 @@ class IconShader : public Shader { Uniform u_fadezoom = {"u_fadezoom", *this}; Uniform u_opacity = {"u_opacity", *this}; Uniform> u_texsize = {"u_texsize", *this}; + Uniform u_skewed = {"u_skewed", *this}; + Uniform u_extra = {"u_extra", *this}; private: int32_t a_pos = -1; diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index d72d61dab19..a77e959e53b 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -5,9 +5,11 @@ uniform float u_gamma; varying vec2 v_tex; varying float v_alpha; +varying float v_gamma_scale; void main() { float dist = texture2D(u_texture, v_tex).a; - float alpha = smoothstep(u_buffer - u_gamma, u_buffer + u_gamma, dist) * v_alpha; + float gamma = u_gamma * v_gamma_scale; + float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 192459f9da0..5d2e1ce249e 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -13,11 +13,14 @@ uniform float u_fadedist; uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; +uniform bool u_skewed; +uniform float u_extra; uniform vec2 u_texsize; varying vec2 v_tex; varying float v_alpha; +varying float v_gamma_scale; void main() { vec2 a_tex = a_data1.xy; @@ -48,6 +51,19 @@ void main() { // if label has been faded out, clip it show *= (1.0 - step(v_alpha, 0.0)); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); + if (u_skewed) { + vec4 extrude = u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); + gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); + } else { + vec4 extrude = u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; + } + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - y * u_extra); + v_gamma_scale = perspective_scale; + v_tex = a_tex / u_texsize; } diff --git a/sdf_shader.hpp b/sdf_shader.hpp index 36dfa30d3ec..181788ab16a 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -23,6 +23,8 @@ class SDFShader : public Shader { Uniform u_minfadezoom = {"u_minfadezoom", *this}; Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; Uniform u_fadezoom = {"u_fadezoom", *this}; + Uniform u_skewed = {"u_skewed", *this}; + Uniform u_extra = {"u_extra", *this}; protected: int32_t a_pos = -1; From 08cd87397f170f2aeebd8b69c7c8221b8c82ae65 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 14 Aug 2015 19:34:13 +0300 Subject: [PATCH 148/259] fix earthquakes in perspective view Use higher precision for matrix calculations so that the map does not jump around while zooming. --- uniform.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/uniform.hpp b/uniform.hpp index d2a248c609d..55646f7d87a 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -36,10 +36,16 @@ class UniformMatrix { location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); } - void operator=(const T& t) { - if (current != t) { - current = t; - bind(t); + void operator=(const std::array& t) { + bool dirty = false; + for (unsigned int i = 0; i < C*R; i++) { + if (current[i] != t[i]) { + current[i] = t[i]; + dirty = true; + } + } + if (dirty) { + bind(current); } } From 92b03f6582f57426c74fb4353f54962ef5b01f25 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 17 Aug 2015 19:02:30 -0400 Subject: [PATCH 149/259] fix depth clipping in perspective view The depth range is now set slightly differently. Both ends of the range are shifted for each layer to solve some precision issues. Some layers draw multiple things at different depths. For example, fill layers draw fills and antialiasing separately. To handle this case, I added setDepthSublayer(n) which a --- plain.vertex.glsl | 1 - 1 file changed, 1 deletion(-) diff --git a/plain.vertex.glsl b/plain.vertex.glsl index 7ccbed12b99..866c3cd2f39 100644 --- a/plain.vertex.glsl +++ b/plain.vertex.glsl @@ -4,5 +4,4 @@ uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - gl_Position.z = 1.0; } From 039830c2e0ad84e915306b76c9f8705ae114e7ea Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 27 Aug 2015 16:49:35 -0400 Subject: [PATCH 150/259] fix line antialiasing adjustment bug fix #2189 This puts an upper limit on how much lines can be blurred because of their y position. It's a hacky fix but the entire way lines are antialiased in perspective view is hacky. --- line.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index f818565ccdd..3b3caaab15c 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -49,7 +49,7 @@ void main() { float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); // how much features are squished in all directions by the perspectiveness - float perspective_scale = 1.0 / (1.0 - y * u_extra); + float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.90)); v_gamma_scale = perspective_scale * squish_scale; } From b6928cabeb5fe2ed7a5142893bc21d2cfe0ea783 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 27 Aug 2015 17:33:56 -0400 Subject: [PATCH 151/259] improve dashed and patterned line antialiasing in perspective view. This is exactly the same approach used for regular lines. I just forgot to implement it for these types of lines. --- line.vertex.glsl | 4 ++-- linepattern.fragment.glsl | 9 ++++----- linepattern.vertex.glsl | 28 +++++++++++++++------------- linepattern_shader.hpp | 2 ++ linesdf.fragment.glsl | 4 +++- linesdf.vertex.glsl | 19 +++++++++++++++++-- linesdf_shader.hpp | 2 ++ 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index 3b3caaab15c..980212384bb 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -34,13 +34,13 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + vec2 dist = u_linewidth.s * a_extrude * scale; // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist / u_ratio, 0.0, 1.0); // position of y on the screen float y = gl_Position.y / gl_Position.w; diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 08feff4396e..4110a99ead6 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,5 +1,4 @@ uniform vec2 u_linewidth; -uniform float u_point; uniform float u_blur; uniform vec2 u_pattern_size_a; @@ -15,17 +14,17 @@ uniform sampler2D u_image; varying vec2 v_normal; varying float v_linesofar; +varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0); - - dist *= u_linewidth.s; + float dist = length(v_normal) * u_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float blur = u_blur * v_gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 47d551e2eb6..541c9fc3a7c 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -18,10 +18,13 @@ uniform mat4 u_exmatrix; uniform float u_ratio; uniform vec2 u_linewidth; uniform vec4 u_color; -uniform float u_point; + +uniform float u_extra; +uniform mat2 u_antialiasingmatrix; varying vec2 v_normal; varying float v_linesofar; +varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; @@ -37,24 +40,23 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec2 extrude = a_extrude * scale; - vec2 dist = u_linewidth.s * extrude * (1.0 - u_point); - - // If the x coordinate is the maximum integer, we move the z coordinates out - // of the view plane so that the triangle gets clipped. This makes it easier - // for us to create degenerate triangle strips. - float z = step(32767.0, a_pos.x); - - // When drawing points, skip every other vertex - z += u_point * step(1.0, v_normal.y); + vec2 dist = u_linewidth.s * a_extrude * scale; // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + dist.xy / u_ratio, 0.0, 1.0); - v_linesofar = a_linesofar;// * u_ratio; + v_linesofar = a_linesofar; + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + + // how much features are squished in the y direction by the tilt + float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - y * u_extra); - gl_PointSize = 2.0 * u_linewidth.s - 1.0; + v_gamma_scale = perspective_scale * squish_scale; } diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index 16d9ff8be73..dce065a0d5c 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -26,6 +26,8 @@ class LinepatternShader : public Shader { Uniform u_blur = {"u_blur", *this}; Uniform u_fade = {"u_fade", *this}; Uniform u_opacity = {"u_opacity", *this}; + Uniform u_extra = {"u_extra", *this}; + UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: int32_t a_pos = -1; diff --git a/linesdf.fragment.glsl b/linesdf.fragment.glsl index 5d53dbe8833..f8962fa570a 100644 --- a/linesdf.fragment.glsl +++ b/linesdf.fragment.glsl @@ -8,6 +8,7 @@ uniform float u_mix; varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; +varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -16,7 +17,8 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float blur = u_blur * v_gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl index 6529fb45c50..03851ed533d 100644 --- a/linesdf.vertex.glsl +++ b/linesdf.vertex.glsl @@ -22,9 +22,13 @@ uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; +uniform float u_extra; +uniform mat2 u_antialiasingmatrix; + varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; +varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; @@ -40,14 +44,25 @@ void main() { // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + vec2 dist = u_linewidth.s * a_extrude * scale; // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + + // how much features are squished in the y direction by the tilt + float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); + + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); + + v_gamma_scale = perspective_scale * squish_scale; } diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 16b7f3cb1ba..9928d5b3044 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -25,6 +25,8 @@ class LineSDFShader : public Shader { Uniform u_image = {"u_image", *this}; Uniform u_sdfgamma = {"u_sdfgamma", *this}; Uniform u_mix = {"u_mix", *this}; + Uniform u_extra = {"u_extra", *this}; + UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: int32_t a_pos = -1; From f34df798554421c5d5f30b74a5b9b5b666652e03 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 28 Aug 2015 10:32:48 -0400 Subject: [PATCH 152/259] fix line antialiasing adjustment bug https://github.com/mapbox/mapbox-gl-native/commit/294b307cb3f470b1cf5fb94633c9082dc0bfd719 https://github.com/mapbox/mapbox-gl-native/issues/2189 This puts an upper limit on how much lines can be blurred because of their y position. It's a hacky fix but the entire way lines are antialiased in perspective view is hacky. --- line.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index 7103b65fa41..9a3d43e4deb 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -54,7 +54,7 @@ void main() { float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); // how much features are squished in all directions by the perspectiveness - float perspective_scale = 1.0 / (1.0 - y * u_extra); + float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); gamma_scale = perspective_scale * squish_scale; From 224b16f4d41fbfacbd813a0efa8fd6ca0dc425ba Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 28 Aug 2015 11:40:52 -0400 Subject: [PATCH 153/259] improve dashed and patterned line antialiasing in perspective view. This is exactly the same approach used for regular lines. I just forgot to implement it for these types of lines. -native commit: d50ade7aa47a4460b0d6bc4e89f83288070b8d9f --- line.fragment.glsl | 4 ++-- line.vertex.glsl | 4 ++-- linepattern.fragment.glsl | 4 +++- linepattern.vertex.glsl | 15 +++++++++++++++ linesdfpattern.fragment.glsl | 4 +++- linesdfpattern.vertex.glsl | 15 +++++++++++++++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index bd465c9ab78..b8be094e7e6 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -6,7 +6,7 @@ uniform vec2 u_dasharray; varying vec4 v_color; varying vec2 v_normal; varying float v_linesofar; -varying float gamma_scale; +varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -15,7 +15,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float blur = u_blur * gamma_scale; + float blur = u_blur * v_gamma_scale; float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = v_color * alpha; diff --git a/line.vertex.glsl b/line.vertex.glsl index 9a3d43e4deb..25741ce788f 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -24,7 +24,7 @@ uniform mat2 u_antialiasingmatrix; varying vec2 v_normal; varying float v_linesofar; varying vec4 v_color; -varying float gamma_scale; +varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; @@ -56,7 +56,7 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); - gamma_scale = perspective_scale * squish_scale; + v_gamma_scale = perspective_scale * squish_scale; v_color = a_color; } diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 50c3f98e4ea..792d970c9a7 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -15,6 +15,7 @@ uniform sampler2D u_image; varying vec2 v_normal; varying float v_linesofar; +varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -23,7 +24,8 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float blur = u_blur * v_gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 0b8faee043a..644eb957e6a 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -18,8 +18,12 @@ uniform mat4 u_exmatrix; uniform float u_ratio; uniform vec2 u_linewidth; +uniform float u_extra; +uniform mat2 u_antialiasingmatrix; + varying vec2 v_normal; varying float v_linesofar; +varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; @@ -44,4 +48,15 @@ void main() { // tile's zoom level. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar;// * u_ratio; + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + + // how much features are squished in the y direction by the tilt + float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); + + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); + + v_gamma_scale = perspective_scale * squish_scale; } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index 9052d61d35c..db18afc117b 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -8,6 +8,7 @@ varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; +varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. @@ -16,7 +17,8 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); + float blur = u_blur * v_gamma_scale; + float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index e7191dc1d8f..0e86d23d7a4 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -22,10 +22,14 @@ uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; +uniform float u_extra; +uniform mat2 u_antialiasingmatrix; + varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying vec4 v_color; +varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; @@ -53,4 +57,15 @@ void main() { v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); v_color = a_color; + + // position of y on the screen + float y = gl_Position.y / gl_Position.w; + + // how much features are squished in the y direction by the tilt + float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); + + // how much features are squished in all directions by the perspectiveness + float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); + + v_gamma_scale = perspective_scale * squish_scale; } From 309253c74d7f961a52a0d56f3679e540e36200b5 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 31 Aug 2015 17:35:47 -0400 Subject: [PATCH 154/259] revert 354179e8609e4968278206d4745a2467c8d57563 --- line.fragment.glsl | 4 ++-- line.vertex.glsl | 4 ---- linepattern.vertex.glsl | 1 + linesdfpattern.fragment.glsl | 5 +++-- linesdfpattern.vertex.glsl | 4 ---- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index b8be094e7e6..40ac93667bd 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,9 +1,9 @@ uniform vec2 u_linewidth; +uniform vec4 u_color; uniform float u_blur; uniform vec2 u_dasharray; -varying vec4 v_color; varying vec2 v_normal; varying float v_linesofar; varying float v_gamma_scale; @@ -18,5 +18,5 @@ void main() { float blur = u_blur * v_gamma_scale; float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); - gl_FragColor = v_color * alpha; + gl_FragColor = u_color * alpha; } diff --git a/line.vertex.glsl b/line.vertex.glsl index 25741ce788f..b40a1a5f8da 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -8,7 +8,6 @@ attribute vec2 a_pos; attribute vec4 a_data; -attribute vec4 a_color; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -23,7 +22,6 @@ uniform mat2 u_antialiasingmatrix; varying vec2 v_normal; varying float v_linesofar; -varying vec4 v_color; varying float v_gamma_scale; void main() { @@ -57,6 +55,4 @@ void main() { float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); v_gamma_scale = perspective_scale * squish_scale; - - v_color = a_color; } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 644eb957e6a..15bf624322c 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -17,6 +17,7 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; +uniform vec4 u_color; uniform float u_extra; uniform mat2 u_antialiasingmatrix; diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index db18afc117b..f60364500b2 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,13 +1,14 @@ uniform vec2 u_linewidth; +uniform vec4 u_color; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; + varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; -varying vec4 v_color; varying float v_gamma_scale; void main() { @@ -25,5 +26,5 @@ void main() { float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); - gl_FragColor = v_color * alpha; + gl_FragColor = u_color * alpha; } diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 0e86d23d7a4..2dc98aff43f 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -8,7 +8,6 @@ attribute vec2 a_pos; attribute vec4 a_data; -attribute vec4 a_color; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. @@ -28,7 +27,6 @@ uniform mat2 u_antialiasingmatrix; varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; -varying vec4 v_color; varying float v_gamma_scale; void main() { @@ -56,8 +54,6 @@ void main() { v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); - v_color = a_color; - // position of y on the screen float y = gl_Position.y / gl_Position.w; From a5bb41109b4dce5a28914fe7a3dfe1324f97bc15 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 1 Sep 2015 18:26:41 -0400 Subject: [PATCH 155/259] cleanup shaders remove unused uniforms and outdated comments --- debug.vertex.glsl | 2 -- fill.vertex.glsl | 1 - line.fragment.glsl | 2 -- line.vertex.glsl | 9 +-------- linepattern.vertex.glsl | 12 ++---------- linesdfpattern.fragment.glsl | 1 - linesdfpattern.vertex.glsl | 9 +-------- 7 files changed, 4 insertions(+), 32 deletions(-) diff --git a/debug.vertex.glsl b/debug.vertex.glsl index 869bcefc75c..71f42b9935f 100644 --- a/debug.vertex.glsl +++ b/debug.vertex.glsl @@ -1,9 +1,7 @@ attribute vec2 a_pos; -uniform float u_pointsize; uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, step(32767.0, a_pos.x), 1); - gl_PointSize = u_pointsize; } diff --git a/fill.vertex.glsl b/fill.vertex.glsl index 08c99981877..4810e910a5a 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -3,5 +3,4 @@ uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - gl_PointSize = 2.0; } diff --git a/line.fragment.glsl b/line.fragment.glsl index 40ac93667bd..43a28ffcfcc 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -2,8 +2,6 @@ uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_blur; -uniform vec2 u_dasharray; - varying vec2 v_normal; varying float v_linesofar; varying float v_gamma_scale; diff --git a/line.vertex.glsl b/line.vertex.glsl index b40a1a5f8da..f63d8a69efe 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -9,14 +9,9 @@ attribute vec2 a_pos; attribute vec4 a_data; -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. uniform highp mat4 u_matrix; - -// shared uniform float u_ratio; uniform vec2 u_linewidth; - uniform float u_extra; uniform mat2 u_antialiasingmatrix; @@ -40,9 +35,7 @@ void main() { vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the - // model/view matrix. Add the extrusion vector *after* the model/view matrix - // because we're extruding the line in pixel space, regardless of the current - // tile's zoom level. + // model/view matrix. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); // position of y on the screen diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 15bf624322c..1abaf61fc26 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -9,16 +9,10 @@ attribute vec2 a_pos; attribute vec4 a_data; -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. uniform highp mat4 u_matrix; -uniform mat4 u_exmatrix; - -// shared uniform float u_ratio; uniform vec2 u_linewidth; uniform vec4 u_color; - uniform float u_extra; uniform mat2 u_antialiasingmatrix; @@ -44,11 +38,9 @@ void main() { vec2 dist = u_linewidth.s * extrude; // Remove the texture normal bit of the position before scaling it with the - // model/view matrix. Add the extrusion vector *after* the model/view matrix - // because we're extruding the line in pixel space, regardless of the current - // tile's zoom level. + // model/view matrix. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); - v_linesofar = a_linesofar;// * u_ratio; + v_linesofar = a_linesofar; // position of y on the screen float y = gl_Position.y / gl_Position.w; diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index f60364500b2..f8962fa570a 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -5,7 +5,6 @@ uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; - varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 2dc98aff43f..409a9ed210e 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -9,18 +9,13 @@ attribute vec2 a_pos; attribute vec4 a_data; -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. uniform highp mat4 u_matrix; -uniform mat4 u_exmatrix; - uniform vec2 u_linewidth; uniform float u_ratio; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; - uniform float u_extra; uniform mat2 u_antialiasingmatrix; @@ -46,9 +41,7 @@ void main() { vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Remove the texture normal bit of the position before scaling it with the - // model/view matrix. Add the extrusion vector *after* the model/view matrix - // because we're extruding the line in pixel space, regardless of the current - // tile's zoom level. + // model/view matrix. gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); From f8ee9ced72940fa565502535fa7134177c5c9ce7 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 2 Sep 2015 15:05:31 -0400 Subject: [PATCH 156/259] fix #1446 The pos coordinates still included part of the extrude. The positions for drawing the vertices on the right side were offset to the right by 0.5. This is a really tiny difference, but if you zoom in far enough it makes the circle bigger than it should be. --- circle.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index eeeb30abc5b..387c377a60c 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -15,7 +15,7 @@ void main(void) { 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 = u_matrix * vec4(floor(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. From 0ef6fe4758335472bcdcffea9cf9466824d11862 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 2 Sep 2015 15:14:14 -0400 Subject: [PATCH 157/259] fix circles at very high zoom levels https://github.com/mapbox/mapbox-gl-js/commit/5c8be4b8487a230a32684737a1e81c8a0b2a4396 --- circle.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index eeeb30abc5b..387c377a60c 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -15,7 +15,7 @@ void main(void) { 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 = u_matrix * vec4(floor(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. From cbbe7262a5ffc3f4c6ae247355b7addca4484538 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 10 Sep 2015 14:05:16 +0300 Subject: [PATCH 158/259] [shader] Moved 'a_pos' GL attribute to Shader Avoids duplicated code in all derived classes. --- box_shader.cpp | 1 - box_shader.hpp | 1 - circle_shader.cpp | 1 - circle_shader.hpp | 3 --- dot_shader.cpp | 1 - dot_shader.hpp | 3 --- icon_shader.cpp | 1 - icon_shader.hpp | 1 - line_shader.cpp | 1 - line_shader.hpp | 1 - linepattern_shader.cpp | 1 - linepattern_shader.hpp | 1 - linesdf_shader.cpp | 1 - linesdf_shader.hpp | 1 - outline_shader.cpp | 1 - outline_shader.hpp | 3 --- pattern_shader.cpp | 1 - pattern_shader.hpp | 3 --- plain_shader.cpp | 1 - plain_shader.hpp | 3 --- raster_shader.cpp | 1 - raster_shader.hpp | 3 --- sdf_shader.cpp | 1 - sdf_shader.hpp | 1 - shader.cpp | 2 ++ shader.hpp | 7 ++++++- 26 files changed, 8 insertions(+), 37 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index 2676223a9da..5c290718e48 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -12,7 +12,6 @@ CollisionBoxShader::CollisionBoxShader() shaders[BOX_SHADER].vertex, shaders[BOX_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/box_shader.hpp b/box_shader.hpp index 5c84d8906c1..832d3e1c03b 100644 --- a/box_shader.hpp +++ b/box_shader.hpp @@ -18,7 +18,6 @@ class CollisionBoxShader : public Shader { Uniform u_maxzoom = {"u_maxzoom", *this}; protected: - int32_t a_pos = -1; int32_t a_extrude = -1; int32_t a_data = -1; }; diff --git a/circle_shader.cpp b/circle_shader.cpp index 074f92d68b2..dc8558d1084 100644 --- a/circle_shader.cpp +++ b/circle_shader.cpp @@ -12,7 +12,6 @@ CircleShader::CircleShader() shaders[CIRCLE_SHADER].vertex, shaders[CIRCLE_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void CircleShader::bind(char *offset) { diff --git a/circle_shader.hpp b/circle_shader.hpp index 545a0baad5c..ce7bb2d20f1 100644 --- a/circle_shader.hpp +++ b/circle_shader.hpp @@ -17,9 +17,6 @@ class CircleShader : public Shader { Uniform> u_color = {"u_color", *this}; Uniform u_size = {"u_size", *this}; Uniform u_blur = {"u_blur", *this}; - -private: - int32_t a_pos = -1; }; } diff --git a/dot_shader.cpp b/dot_shader.cpp index 57a60cc5194..67c4639447d 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -12,7 +12,6 @@ DotShader::DotShader() shaders[DOT_SHADER].vertex, shaders[DOT_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void DotShader::bind(char *offset) { diff --git a/dot_shader.hpp b/dot_shader.hpp index 2c4176f364e..51263a7311f 100644 --- a/dot_shader.hpp +++ b/dot_shader.hpp @@ -16,9 +16,6 @@ class DotShader : public Shader { Uniform> u_color = {"u_color", *this}; Uniform u_size = {"u_size", *this}; Uniform u_blur = {"u_blur", *this}; - -private: - int32_t a_pos = -1; }; } diff --git a/icon_shader.cpp b/icon_shader.cpp index 0f626ec9e7a..1084ab3083f 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -12,7 +12,6 @@ IconShader::IconShader() shaders[ICON_SHADER].vertex, shaders[ICON_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); diff --git a/icon_shader.hpp b/icon_shader.hpp index 18b0fce37ba..20d3ebf5c52 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -25,7 +25,6 @@ class IconShader : public Shader { Uniform u_extra = {"u_extra", *this}; private: - int32_t a_pos = -1; int32_t a_offset = -1; int32_t a_data1 = -1; int32_t a_data2 = -1; diff --git a/line_shader.cpp b/line_shader.cpp index c2364c9beac..66dff81c99c 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -12,7 +12,6 @@ LineShader::LineShader() shaders[LINE_SHADER].vertex, shaders[LINE_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/line_shader.hpp b/line_shader.hpp index 0572cac88d9..1a4289ded9c 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -22,7 +22,6 @@ class LineShader : public Shader { UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: - int32_t a_pos = -1; int32_t a_data = -1; }; diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 7bfd1412dbf..65404cb1177 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -12,7 +12,6 @@ LinepatternShader::LinepatternShader() shaders[LINEPATTERN_SHADER].vertex, shaders[LINEPATTERN_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index dce065a0d5c..a06135180d0 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -30,7 +30,6 @@ class LinepatternShader : public Shader { UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: - int32_t a_pos = -1; int32_t a_data = -1; }; } diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index bd2137de307..a08c99c7474 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -12,7 +12,6 @@ LineSDFShader::LineSDFShader() shaders[LINESDF_SHADER].vertex, shaders[LINESDF_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 9928d5b3044..4d08916cd50 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -29,7 +29,6 @@ class LineSDFShader : public Shader { UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: - int32_t a_pos = -1; int32_t a_data = -1; }; diff --git a/outline_shader.cpp b/outline_shader.cpp index ee2a6bcd407..1d2c3667f69 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -12,7 +12,6 @@ OutlineShader::OutlineShader() shaders[OUTLINE_SHADER].vertex, shaders[OUTLINE_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void OutlineShader::bind(char *offset) { diff --git a/outline_shader.hpp b/outline_shader.hpp index f3e8175fd78..9b086594bb5 100644 --- a/outline_shader.hpp +++ b/outline_shader.hpp @@ -15,9 +15,6 @@ class OutlineShader : public Shader { UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_color = {"u_color", *this}; Uniform> u_world = {"u_world", *this}; - -private: - int32_t a_pos = -1; }; } diff --git a/pattern_shader.cpp b/pattern_shader.cpp index 66369d528ab..b5883b95659 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -12,7 +12,6 @@ PatternShader::PatternShader() shaders[PATTERN_SHADER].vertex, shaders[PATTERN_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void PatternShader::bind(char *offset) { diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 9fc8dcfa01e..5090a453e8f 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -22,9 +22,6 @@ class PatternShader : public Shader { Uniform u_image = {"u_image", *this}; UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; - -private: - int32_t a_pos = -1; }; } diff --git a/plain_shader.cpp b/plain_shader.cpp index 93dbb42a573..bb719f47dfa 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -12,7 +12,6 @@ PlainShader::PlainShader() shaders[PLAIN_SHADER].vertex, shaders[PLAIN_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void PlainShader::bind(char *offset) { diff --git a/plain_shader.hpp b/plain_shader.hpp index 051501c3c94..266600024f2 100644 --- a/plain_shader.hpp +++ b/plain_shader.hpp @@ -14,9 +14,6 @@ class PlainShader : public Shader { UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_color = {"u_color", *this}; - -private: - int32_t a_pos = -1; }; } diff --git a/raster_shader.cpp b/raster_shader.cpp index 2d69549209a..ce03488ac4b 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -12,7 +12,6 @@ RasterShader::RasterShader() shaders[RASTER_SHADER].vertex, shaders[RASTER_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } void RasterShader::bind(char *offset) { diff --git a/raster_shader.hpp b/raster_shader.hpp index 8cf97055a2a..e869fb74115 100644 --- a/raster_shader.hpp +++ b/raster_shader.hpp @@ -21,9 +21,6 @@ class RasterShader : public Shader { Uniform u_saturation_factor = {"u_saturation_factor", *this}; Uniform u_contrast_factor = {"u_contrast_factor", *this}; Uniform> u_spin_weights = {"u_spin_weights", *this}; - -private: - int32_t a_pos = -1; }; } diff --git a/sdf_shader.cpp b/sdf_shader.cpp index ca1dab58dd7..7b729a4588c 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -12,7 +12,6 @@ SDFShader::SDFShader() shaders[SDF_SHADER].vertex, shaders[SDF_SHADER].fragment ) { - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); diff --git a/sdf_shader.hpp b/sdf_shader.hpp index 181788ab16a..f8e0aef2b61 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -27,7 +27,6 @@ class SDFShader : public Shader { Uniform u_extra = {"u_extra", *this}; protected: - int32_t a_pos = -1; int32_t a_offset = -1; int32_t a_data1 = -1; int32_t a_data2 = -1; diff --git a/shader.cpp b/shader.cpp index 6210c1c32e5..1e3df1bbc22 100644 --- a/shader.cpp +++ b/shader.cpp @@ -97,6 +97,8 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo MBGL_CHECK_ERROR(glDeleteShader(vertShader)); MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); MBGL_CHECK_ERROR(glDeleteShader(fragShader)); + + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } diff --git a/shader.hpp b/shader.hpp index b3d9b4e46cc..2a1cf39fe20 100644 --- a/shader.hpp +++ b/shader.hpp @@ -1,10 +1,12 @@ #ifndef MBGL_RENDERER_SHADER #define MBGL_RENDERER_SHADER +#include +#include + #include #include #include -#include namespace mbgl { @@ -19,6 +21,9 @@ class Shader : private util::noncopyable { return program; } +protected: + GLint a_pos = -1; + private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); }; From 941583c7e0f160b87a2b35849d80e9f4c120c618 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 10 Sep 2015 14:46:38 +0300 Subject: [PATCH 159/259] [shader] bind() is now a pure virtual - Shader::bind() now receives a GLbyte* - BUFFER_OFFSET now uses GLbyte --- box_shader.cpp | 2 +- box_shader.hpp | 3 ++- circle_shader.cpp | 2 +- circle_shader.hpp | 2 +- dot_shader.cpp | 2 +- dot_shader.hpp | 2 +- icon_shader.cpp | 2 +- icon_shader.hpp | 2 +- line_shader.cpp | 2 +- line_shader.hpp | 2 +- linepattern_shader.cpp | 2 +- linepattern_shader.hpp | 2 +- linesdf_shader.cpp | 2 +- linesdf_shader.hpp | 2 +- outline_shader.cpp | 2 +- outline_shader.hpp | 2 +- pattern_shader.cpp | 2 +- pattern_shader.hpp | 2 +- plain_shader.cpp | 2 +- plain_shader.hpp | 2 +- raster_shader.cpp | 2 +- raster_shader.hpp | 2 +- sdf_shader.cpp | 4 ++-- sdf_shader.hpp | 6 ++---- shader.hpp | 2 ++ 25 files changed, 29 insertions(+), 28 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index 5c290718e48..ffcce815f0f 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -16,7 +16,7 @@ CollisionBoxShader::CollisionBoxShader() a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void CollisionBoxShader::bind(char *offset) { +void CollisionBoxShader::bind(GLbyte *offset) { const int stride = 12; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); diff --git a/box_shader.hpp b/box_shader.hpp index 832d3e1c03b..20d1deec62b 100644 --- a/box_shader.hpp +++ b/box_shader.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace mbgl { @@ -10,7 +11,7 @@ class CollisionBoxShader : public Shader { public: CollisionBoxShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform u_scale = {"u_scale", *this}; diff --git a/circle_shader.cpp b/circle_shader.cpp index dc8558d1084..8fa10191b99 100644 --- a/circle_shader.cpp +++ b/circle_shader.cpp @@ -14,7 +14,7 @@ CircleShader::CircleShader() ) { } -void CircleShader::bind(char *offset) { +void CircleShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 4, offset)); } diff --git a/circle_shader.hpp b/circle_shader.hpp index ce7bb2d20f1..58314e837d7 100644 --- a/circle_shader.hpp +++ b/circle_shader.hpp @@ -10,7 +10,7 @@ class CircleShader : public Shader { public: CircleShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; diff --git a/dot_shader.cpp b/dot_shader.cpp index 67c4639447d..baec3678b44 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -14,7 +14,7 @@ DotShader::DotShader() ) { } -void DotShader::bind(char *offset) { +void DotShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); } diff --git a/dot_shader.hpp b/dot_shader.hpp index 51263a7311f..45ac1c26cd2 100644 --- a/dot_shader.hpp +++ b/dot_shader.hpp @@ -10,7 +10,7 @@ class DotShader : public Shader { public: DotShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_color = {"u_color", *this}; diff --git a/icon_shader.cpp b/icon_shader.cpp index 1084ab3083f..736bb47e72c 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -17,7 +17,7 @@ IconShader::IconShader() a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); } -void IconShader::bind(char *offset) { +void IconShader::bind(GLbyte *offset) { const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); diff --git a/icon_shader.hpp b/icon_shader.hpp index 20d3ebf5c52..a0e9397f09b 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -10,7 +10,7 @@ class IconShader : public Shader { public: IconShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; diff --git a/line_shader.cpp b/line_shader.cpp index 66dff81c99c..1e2306939d9 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -15,7 +15,7 @@ LineShader::LineShader() a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void LineShader::bind(char *offset) { +void LineShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); diff --git a/line_shader.hpp b/line_shader.hpp index 1a4289ded9c..77866e89dc2 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -10,7 +10,7 @@ class LineShader : public Shader { public: LineShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 65404cb1177..4d416d506e0 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -15,7 +15,7 @@ LinepatternShader::LinepatternShader() a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void LinepatternShader::bind(char *offset) { +void LinepatternShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index a06135180d0..335281c1962 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -10,7 +10,7 @@ class LinepatternShader : public Shader { public: LinepatternShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index a08c99c7474..1a56bb106e6 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -15,7 +15,7 @@ LineSDFShader::LineSDFShader() a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void LineSDFShader::bind(char *offset) { +void LineSDFShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 4d08916cd50..1996d16f13c 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -10,7 +10,7 @@ class LineSDFShader : public Shader { public: LineSDFShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; diff --git a/outline_shader.cpp b/outline_shader.cpp index 1d2c3667f69..74453468bf0 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -14,7 +14,7 @@ OutlineShader::OutlineShader() ) { } -void OutlineShader::bind(char *offset) { +void OutlineShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/outline_shader.hpp b/outline_shader.hpp index 9b086594bb5..9de01e21439 100644 --- a/outline_shader.hpp +++ b/outline_shader.hpp @@ -10,7 +10,7 @@ class OutlineShader : public Shader { public: OutlineShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_color = {"u_color", *this}; diff --git a/pattern_shader.cpp b/pattern_shader.cpp index b5883b95659..d6ddab8e2eb 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -14,7 +14,7 @@ PatternShader::PatternShader() ) { } -void PatternShader::bind(char *offset) { +void PatternShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 5090a453e8f..28cd341d861 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -10,7 +10,7 @@ class PatternShader : public Shader { public: PatternShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; diff --git a/plain_shader.cpp b/plain_shader.cpp index bb719f47dfa..52fef07c051 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -14,7 +14,7 @@ PlainShader::PlainShader() ) { } -void PlainShader::bind(char *offset) { +void PlainShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/plain_shader.hpp b/plain_shader.hpp index 266600024f2..cf2bcc38c12 100644 --- a/plain_shader.hpp +++ b/plain_shader.hpp @@ -10,7 +10,7 @@ class PlainShader : public Shader { public: PlainShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_color = {"u_color", *this}; diff --git a/raster_shader.cpp b/raster_shader.cpp index ce03488ac4b..b8496230b97 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -14,7 +14,7 @@ RasterShader::RasterShader() ) { } -void RasterShader::bind(char *offset) { +void RasterShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/raster_shader.hpp b/raster_shader.hpp index e869fb74115..705efec9964 100644 --- a/raster_shader.hpp +++ b/raster_shader.hpp @@ -10,7 +10,7 @@ class RasterShader : public Shader { public: RasterShader(); - void bind(char *offset); + void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform u_image = {"u_image", *this}; diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 7b729a4588c..144ba6c475f 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -17,7 +17,7 @@ SDFShader::SDFShader() a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); } -void SDFGlyphShader::bind(char *offset) { +void SDFGlyphShader::bind(GLbyte *offset) { const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); @@ -33,7 +33,7 @@ void SDFGlyphShader::bind(char *offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); } -void SDFIconShader::bind(char *offset) { +void SDFIconShader::bind(GLbyte *offset) { const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); diff --git a/sdf_shader.hpp b/sdf_shader.hpp index f8e0aef2b61..a56f3b2eb4b 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -10,8 +10,6 @@ class SDFShader : public Shader { public: SDFShader(); - virtual void bind(char *offset) = 0; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; Uniform> u_color = {"u_color", *this}; @@ -34,12 +32,12 @@ class SDFShader : public Shader { class SDFGlyphShader : public SDFShader { public: - void bind(char *offset); + void bind(GLbyte *offset) final; }; class SDFIconShader : public SDFShader { public: - void bind(char *offset); + void bind(GLbyte *offset) final; }; } diff --git a/shader.hpp b/shader.hpp index 2a1cf39fe20..9b150c37edf 100644 --- a/shader.hpp +++ b/shader.hpp @@ -21,6 +21,8 @@ class Shader : private util::noncopyable { return program; } + virtual void bind(GLbyte *offset) = 0; + protected: GLint a_pos = -1; From 60dc85938a69716ed564610b14d987b2dba78c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 21 Aug 2015 14:33:17 -0400 Subject: [PATCH 160/259] don't validate the program it's not in a state where validation always succeeds with all drivers, e.g. because textures might not be attached yet --- shader.cpp | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/shader.cpp b/shader.cpp index 1e3df1bbc22..ed4cb729b3f 100644 --- a/shader.cpp +++ b/shader.cpp @@ -67,31 +67,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo } } - { - // Validate program - GLint status; - MBGL_CHECK_ERROR(glValidateProgram(program)); - - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_VALIDATE_STATUS, &status)); - if (status == 0) { - GLint logLength; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); - const auto log = std::make_unique(logLength); - if (logLength > 0) { - MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Program failed to validate: %s", log.get()); - } - - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - vertShader = 0; - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - fragShader = 0; - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; - throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); - } - } - // Remove the compiled shaders; they are now part of the program. MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); MBGL_CHECK_ERROR(glDeleteShader(vertShader)); From b702ad0904b7cc3dbc8eabc87a1ec0bda7a60c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 21 Aug 2015 14:34:06 -0400 Subject: [PATCH 161/259] don't delete the shaders before the program some GPU drivers have issues with deleting shader objects that are attached to programs. while this is allowed by the spec, it seems that some drivers are crashing nonetheless. --- shader.cpp | 14 ++++++-------- shader.hpp | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/shader.cpp b/shader.cpp index ed4cb729b3f..c69518c8c8f 100644 --- a/shader.cpp +++ b/shader.cpp @@ -20,8 +20,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo program = MBGL_CHECK_ERROR(glCreateProgram()); - GLuint vertShader = 0; - GLuint fragShader = 0; if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); MBGL_CHECK_ERROR(glDeleteProgram(program)); @@ -67,12 +65,6 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo } } - // Remove the compiled shaders; they are now part of the program. - MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); } @@ -115,7 +107,13 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { Shader::~Shader() { if (program) { + MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); + MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; + MBGL_CHECK_ERROR(glDeleteShader(vertShader)); + vertShader = 0; + MBGL_CHECK_ERROR(glDeleteShader(fragShader)); + fragShader = 0; } } diff --git a/shader.hpp b/shader.hpp index 9b150c37edf..32902247963 100644 --- a/shader.hpp +++ b/shader.hpp @@ -28,6 +28,9 @@ class Shader : private util::noncopyable { private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); + + uint32_t vertShader = 0; + uint32_t fragShader = 0; }; } From 3f86a2b9dabf499cdf55b63105aa48d6abc86c71 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 10 Sep 2015 15:16:19 +0300 Subject: [PATCH 162/259] [shader] Shaders vertex and fragments are now GLchar* --- shader.cpp | 16 ++++++++-------- shader.hpp | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/shader.cpp b/shader.cpp index c69518c8c8f..e8deefc8ff5 100644 --- a/shader.cpp +++ b/shader.cpp @@ -14,20 +14,21 @@ using namespace mbgl; Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource) - : name(name_), - program(0) { + : name(name_) + , program(0) +{ util::stopwatch stopwatch("shader compilation", Event::Shader); program = MBGL_CHECK_ERROR(glCreateProgram()); - if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { + if (!compileShader(&vertShader, GL_VERTEX_SHADER, &vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); MBGL_CHECK_ERROR(glDeleteProgram(program)); program = 0; throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile"); } - if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { + if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, &fragSource)) { Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; @@ -69,13 +70,12 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo } -bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) { +bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source[]) { GLint status; *shader = MBGL_CHECK_ERROR(glCreateShader(type)); - const GLchar *strings[] = { source }; - const GLsizei lengths[] = { static_cast(std::strlen(source)) }; - MBGL_CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths)); + const GLsizei lengths = static_cast(std::strlen(*source)); + MBGL_CHECK_ERROR(glShaderSource(*shader, 1, source, &lengths)); MBGL_CHECK_ERROR(glCompileShader(*shader)); diff --git a/shader.hpp b/shader.hpp index 32902247963..dab7cd8522b 100644 --- a/shader.hpp +++ b/shader.hpp @@ -12,9 +12,10 @@ namespace mbgl { class Shader : private util::noncopyable { public: - Shader(const char *name, const char *vertex, const char *fragment); + Shader(const GLchar *name, const GLchar *vertex, const GLchar *fragment); + ~Shader(); - const char *name; + const GLchar *name; uint32_t program; inline uint32_t getID() const { @@ -27,10 +28,10 @@ class Shader : private util::noncopyable { GLint a_pos = -1; private: - bool compileShader(uint32_t *shader, uint32_t type, const char *source); + bool compileShader(GLuint *shader, GLenum type, const GLchar *source[]); - uint32_t vertShader = 0; - uint32_t fragShader = 0; + GLuint vertShader = 0; + GLuint fragShader = 0; }; } From 9365942aad81c6ee0ba58e936d92e05a7166d86f Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 10 Sep 2015 17:45:02 +0300 Subject: [PATCH 163/259] [shader] GL types for all Shader attributes --- box_shader.cpp | 2 +- box_shader.hpp | 14 +++++++------- circle_shader.hpp | 10 +++++----- dot_shader.hpp | 8 ++++---- icon_shader.cpp | 2 +- icon_shader.hpp | 32 ++++++++++++++++---------------- line_shader.hpp | 18 +++++++++--------- linepattern_shader.hpp | 34 +++++++++++++++++----------------- linesdf_shader.hpp | 32 ++++++++++++++++---------------- outline_shader.hpp | 6 +++--- pattern_shader.hpp | 20 ++++++++++---------- plain_shader.hpp | 4 ++-- raster_shader.hpp | 18 +++++++++--------- sdf_shader.hpp | 32 ++++++++++++++++---------------- shader.hpp | 4 ++-- uniform.cpp | 16 ++++++++-------- 16 files changed, 126 insertions(+), 126 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index ffcce815f0f..beb5e15f9ec 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -17,7 +17,7 @@ CollisionBoxShader::CollisionBoxShader() } void CollisionBoxShader::bind(GLbyte *offset) { - const int stride = 12; + const GLint stride = 12; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); diff --git a/box_shader.hpp b/box_shader.hpp index 20d1deec62b..19df2ca8250 100644 --- a/box_shader.hpp +++ b/box_shader.hpp @@ -14,15 +14,15 @@ class CollisionBoxShader : public Shader { void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform u_scale = {"u_scale", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_maxzoom = {"u_maxzoom", *this}; + Uniform u_scale = {"u_scale", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_maxzoom = {"u_maxzoom", *this}; protected: - int32_t a_extrude = -1; - int32_t a_data = -1; + GLint a_extrude = -1; + GLint a_data = -1; }; -} +} // namespace mbgl -#endif +#endif // MBGL_SHADER_BOX_SHADER diff --git a/circle_shader.hpp b/circle_shader.hpp index 58314e837d7..84f4ef99a1e 100644 --- a/circle_shader.hpp +++ b/circle_shader.hpp @@ -12,11 +12,11 @@ class CircleShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform u_size = {"u_size", *this}; - Uniform u_blur = {"u_blur", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform u_size = {"u_size", *this}; + Uniform u_blur = {"u_blur", *this}; }; } diff --git a/dot_shader.hpp b/dot_shader.hpp index 45ac1c26cd2..fe1541cf753 100644 --- a/dot_shader.hpp +++ b/dot_shader.hpp @@ -12,10 +12,10 @@ class DotShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform u_size = {"u_size", *this}; - Uniform u_blur = {"u_blur", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform u_size = {"u_size", *this}; + Uniform u_blur = {"u_blur", *this}; }; } diff --git a/icon_shader.cpp b/icon_shader.cpp index 736bb47e72c..a9b4be23e80 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -18,7 +18,7 @@ IconShader::IconShader() } void IconShader::bind(GLbyte *offset) { - const int stride = 16; + const GLsizei stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); diff --git a/icon_shader.hpp b/icon_shader.hpp index a0e9397f09b..437fd859bcb 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -12,22 +12,22 @@ class IconShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_fadedist = {"u_fadedist", *this}; - Uniform u_minfadezoom = {"u_minfadezoom", *this}; - Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform u_fadezoom = {"u_fadezoom", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform> u_texsize = {"u_texsize", *this}; - Uniform u_skewed = {"u_skewed", *this}; - Uniform u_extra = {"u_extra", *this}; - -private: - int32_t a_offset = -1; - int32_t a_data1 = -1; - int32_t a_data2 = -1; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform> u_texsize = {"u_texsize", *this}; + Uniform u_skewed = {"u_skewed", *this}; + Uniform u_extra = {"u_extra", *this}; + +protected: + GLint a_offset = -1; + GLint a_data1 = -1; + GLint a_data2 = -1; }; } diff --git a/line_shader.hpp b/line_shader.hpp index 77866e89dc2..580035a07a3 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -12,17 +12,17 @@ class LineShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform u_ratio = {"u_ratio", *this}; - Uniform u_blur = {"u_blur", *this}; - Uniform u_extra = {"u_extra", *this}; - UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_blur = {"u_blur", *this}; + Uniform u_extra = {"u_extra", *this}; + UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: - int32_t a_data = -1; + GLint a_data = -1; }; diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index 335281c1962..f2189d4710a 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -12,25 +12,25 @@ class LinepatternShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform> u_pattern_size_a = {"u_pattern_size_a", *this}; - Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; - Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; - Uniform> u_pattern_size_b = {"u_pattern_size_b", *this}; - Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; - Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; - Uniform u_ratio = {"u_ratio", *this}; - Uniform u_point = {"u_point", *this}; - Uniform u_blur = {"u_blur", *this}; - Uniform u_fade = {"u_fade", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_extra = {"u_extra", *this}; - UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform> u_pattern_size_a = {"u_pattern_size_a", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_size_b = {"u_pattern_size_b", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_point = {"u_point", *this}; + Uniform u_blur = {"u_blur", *this}; + Uniform u_fade = {"u_fade", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_extra = {"u_extra", *this}; + UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: - int32_t a_data = -1; + GLint a_data = -1; }; } diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 1996d16f13c..839494f79bc 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -12,24 +12,24 @@ class LineSDFShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform u_ratio = {"u_ratio", *this}; - Uniform u_blur = {"u_blur", *this}; - Uniform> u_patternscale_a = { "u_patternscale_a", *this }; - Uniform u_tex_y_a = {"u_tex_y_a", *this}; - Uniform> u_patternscale_b = { "u_patternscale_b", *this }; - Uniform u_tex_y_b = {"u_tex_y_b", *this}; - Uniform u_image = {"u_image", *this}; - Uniform u_sdfgamma = {"u_sdfgamma", *this}; - Uniform u_mix = {"u_mix", *this}; - Uniform u_extra = {"u_extra", *this}; - UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_blur = {"u_blur", *this}; + Uniform> u_patternscale_a = { "u_patternscale_a", *this}; + Uniform u_tex_y_a = {"u_tex_y_a", *this}; + Uniform> u_patternscale_b = { "u_patternscale_b", *this}; + Uniform u_tex_y_b = {"u_tex_y_b", *this}; + Uniform u_image = {"u_image", *this}; + Uniform u_sdfgamma = {"u_sdfgamma", *this}; + Uniform u_mix = {"u_mix", *this}; + Uniform u_extra = {"u_extra", *this}; + UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: - int32_t a_data = -1; + GLint a_data = -1; }; diff --git a/outline_shader.hpp b/outline_shader.hpp index 9de01e21439..2cd4b1dc31e 100644 --- a/outline_shader.hpp +++ b/outline_shader.hpp @@ -12,9 +12,9 @@ class OutlineShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_world = {"u_world", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_world = {"u_world", *this}; }; } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 28cd341d861..3dd3daa4618 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -12,16 +12,16 @@ class PatternShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; - Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; - Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; - Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_mix = {"u_mix", *this}; - Uniform u_image = {"u_image", *this}; - UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; - UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_mix = {"u_mix", *this}; + Uniform u_image = {"u_image", *this}; + UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; + UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; }; } diff --git a/plain_shader.hpp b/plain_shader.hpp index cf2bcc38c12..ee0528e9e3c 100644 --- a/plain_shader.hpp +++ b/plain_shader.hpp @@ -12,8 +12,8 @@ class PlainShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; }; } diff --git a/raster_shader.hpp b/raster_shader.hpp index 705efec9964..af51b4ba464 100644 --- a/raster_shader.hpp +++ b/raster_shader.hpp @@ -12,15 +12,15 @@ class RasterShader : public Shader { void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform u_image = {"u_image", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_buffer = {"u_buffer", *this}; - Uniform u_brightness_low = {"u_brightness_low", *this}; - Uniform u_brightness_high = {"u_brightness_high", *this}; - Uniform u_saturation_factor = {"u_saturation_factor", *this}; - Uniform u_contrast_factor = {"u_contrast_factor", *this}; - Uniform> u_spin_weights = {"u_spin_weights", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform u_image = {"u_image", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_brightness_low = {"u_brightness_low", *this}; + Uniform u_brightness_high = {"u_brightness_high", *this}; + Uniform u_saturation_factor = {"u_saturation_factor", *this}; + Uniform u_contrast_factor = {"u_contrast_factor", *this}; + Uniform> u_spin_weights = {"u_spin_weights", *this}; }; } diff --git a/sdf_shader.hpp b/sdf_shader.hpp index a56f3b2eb4b..fcb2e15d112 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -10,24 +10,24 @@ class SDFShader : public Shader { public: SDFShader(); - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_texsize = {"u_texsize", *this}; - Uniform u_buffer = {"u_buffer", *this}; - Uniform u_gamma = {"u_gamma", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_fadedist = {"u_fadedist", *this}; - Uniform u_minfadezoom = {"u_minfadezoom", *this}; - Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform u_fadezoom = {"u_fadezoom", *this}; - Uniform u_skewed = {"u_skewed", *this}; - Uniform u_extra = {"u_extra", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_texsize = {"u_texsize", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_gamma = {"u_gamma", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; + Uniform u_skewed = {"u_skewed", *this}; + Uniform u_extra = {"u_extra", *this}; protected: - int32_t a_offset = -1; - int32_t a_data1 = -1; - int32_t a_data2 = -1; + GLint a_offset = -1; + GLint a_data1 = -1; + GLint a_data2 = -1; }; class SDFGlyphShader : public SDFShader { diff --git a/shader.hpp b/shader.hpp index dab7cd8522b..1de56da87ae 100644 --- a/shader.hpp +++ b/shader.hpp @@ -16,9 +16,9 @@ class Shader : private util::noncopyable { ~Shader(); const GLchar *name; - uint32_t program; + GLuint program; - inline uint32_t getID() const { + inline GLuint getID() const { return program; } diff --git a/uniform.cpp b/uniform.cpp index c013699bfd8..eca1a99d176 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -3,42 +3,42 @@ namespace mbgl { template <> -void Uniform::bind(const float& t) { +void Uniform::bind(const GLfloat& t) { MBGL_CHECK_ERROR(glUniform1f(location, t)); } template <> -void Uniform::bind(const int32_t& t) { +void Uniform::bind(const GLint& t) { MBGL_CHECK_ERROR(glUniform1i(location, t)); } template <> -void Uniform>::bind(const std::array& t) { +void Uniform>::bind(const std::array& t) { MBGL_CHECK_ERROR(glUniform2fv(location, 1, t.data())); } template <> -void Uniform>::bind(const std::array& t) { +void Uniform>::bind(const std::array& t) { MBGL_CHECK_ERROR(glUniform3fv(location, 1, t.data())); } template <> -void Uniform>::bind(const std::array& t) { +void Uniform>::bind(const std::array& t) { MBGL_CHECK_ERROR(glUniform4fv(location, 1, t.data())); } template <> -void UniformMatrix<2>::bind(const std::array& t) { +void UniformMatrix<2>::bind(const std::array& t) { MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data())); } template <> -void UniformMatrix<3>::bind(const std::array& t) { +void UniformMatrix<3>::bind(const std::array& t) { MBGL_CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, t.data())); } template <> -void UniformMatrix<4>::bind(const std::array& t) { +void UniformMatrix<4>::bind(const std::array& t) { MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, t.data())); } From 49568da06897c305cf37053315e3b69cd3b978a7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 11 Nov 2015 15:58:58 -0800 Subject: [PATCH 164/259] Replace use of glify with brfs (fixes #1701) This increases the bundle size by 3%. --- circle.fragment.glsl | 2 ++ circle.vertex.glsl | 2 ++ collisionbox.fragment.glsl | 2 ++ collisionbox.vertex.glsl | 2 ++ debug.fragment.glsl | 2 ++ debug.vertex.glsl | 2 ++ dot.fragment.glsl | 2 ++ dot.vertex.glsl | 2 ++ fill.fragment.glsl | 2 ++ fill.vertex.glsl | 2 ++ icon.fragment.glsl | 2 ++ icon.vertex.glsl | 2 ++ line.fragment.glsl | 2 ++ line.vertex.glsl | 2 ++ linepattern.fragment.glsl | 2 ++ linepattern.vertex.glsl | 2 ++ linesdfpattern.fragment.glsl | 2 ++ linesdfpattern.vertex.glsl | 2 ++ outline.fragment.glsl | 2 ++ outline.vertex.glsl | 2 ++ pattern.fragment.glsl | 2 ++ pattern.vertex.glsl | 2 ++ raster.fragment.glsl | 2 ++ raster.vertex.glsl | 2 ++ sdf.fragment.glsl | 2 ++ sdf.vertex.glsl | 2 ++ 26 files changed, 52 insertions(+) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 7267bf81e3b..8f997eee22b 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec4 u_color; uniform float u_blur; uniform float u_size; diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 387c377a60c..6672c9d472f 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + // set by gl_util uniform float u_size; diff --git a/collisionbox.fragment.glsl b/collisionbox.fragment.glsl index 030f1219f8e..ca911993302 100644 --- a/collisionbox.fragment.glsl +++ b/collisionbox.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform float u_zoom; uniform float u_maxzoom; diff --git a/collisionbox.vertex.glsl b/collisionbox.vertex.glsl index ecd4a7e1c96..e887a975e83 100644 --- a/collisionbox.vertex.glsl +++ b/collisionbox.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + attribute vec2 a_pos; attribute vec2 a_extrude; attribute vec2 a_data; diff --git a/debug.fragment.glsl b/debug.fragment.glsl index 8df552c1718..f21d7dd6ebb 100644 --- a/debug.fragment.glsl +++ b/debug.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec4 u_color; void main() { diff --git a/debug.vertex.glsl b/debug.vertex.glsl index 71f42b9935f..f375d99a22c 100644 --- a/debug.vertex.glsl +++ b/debug.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + attribute vec2 a_pos; uniform mat4 u_matrix; diff --git a/dot.fragment.glsl b/dot.fragment.glsl index 6d998b5611f..4639f697361 100644 --- a/dot.fragment.glsl +++ b/dot.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec4 u_color; uniform float u_blur; diff --git a/dot.vertex.glsl b/dot.vertex.glsl index 5310ae745e0..b58862645a1 100644 --- a/dot.vertex.glsl +++ b/dot.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform mat4 u_matrix; uniform float u_size; diff --git a/fill.fragment.glsl b/fill.fragment.glsl index 8df552c1718..f21d7dd6ebb 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec4 u_color; void main() { diff --git a/fill.vertex.glsl b/fill.vertex.glsl index 4810e910a5a..d37f25a160c 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + attribute vec2 a_pos; uniform mat4 u_matrix; diff --git a/icon.fragment.glsl b/icon.fragment.glsl index 45b56793eba..509695dccb1 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform sampler2D u_texture; varying vec2 v_tex; diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 498c769f5a9..1ecaf076087 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; diff --git a/line.fragment.glsl b/line.fragment.glsl index 43a28ffcfcc..999834cd4bd 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_blur; diff --git a/line.vertex.glsl b/line.vertex.glsl index f63d8a69efe..c6240737a81 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 792d970c9a7..37a3504cc2b 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 1abaf61fc26..91529396edb 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index f8962fa570a..4fc1b949774 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_blur; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 409a9ed210e..92de52bce5b 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/outline.fragment.glsl b/outline.fragment.glsl index eccda714e52..f7e5fda9a38 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform vec4 u_color; varying vec2 v_pos; diff --git a/outline.vertex.glsl b/outline.vertex.glsl index b8658e60482..6c00cd9bb9a 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + attribute vec2 a_pos; uniform highp mat4 u_matrix; diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index a28a52ce36a..1bb1d5bb342 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index dff4469d2b6..560dc737227 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform mat4 u_matrix; uniform mat3 u_patternmatrix_a; uniform mat3 u_patternmatrix_b; diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 7a6c49acec2..48948bac7df 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform float u_opacity0; uniform float u_opacity1; uniform sampler2D u_image0; diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 987212d88ff..1e658c7f1fd 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index a7ae7f821f6..30b5a2272a7 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,3 +1,5 @@ +precision mediump float; + uniform sampler2D u_texture; uniform vec4 u_color; uniform float u_buffer; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 287e2631888..486d063a1e8 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -1,3 +1,5 @@ +precision mediump float; + attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; From 89c4b6c10f9faf8b8a4bacc31ae65023462ba445 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 1 Dec 2015 14:48:49 -0800 Subject: [PATCH 165/259] Add rudimentary support for line-offset --- line.vertex.glsl | 12 +++++++++++- linepattern.vertex.glsl | 14 ++++++++++++-- linesdfpattern.vertex.glsl | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index c6240737a81..ba0ffe05a61 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -16,6 +16,7 @@ uniform float u_ratio; uniform vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; +uniform float u_offset; varying vec2 v_normal; varying float v_linesofar; @@ -23,6 +24,7 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -36,9 +38,17 @@ void main() { // of this vertex. vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist.xy) / u_ratio, 0.0, 1.0); // position of y on the screen float y = gl_Position.y / gl_Position.w; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 91529396edb..e39baad2eb0 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -17,6 +17,7 @@ uniform vec2 u_linewidth; uniform vec4 u_color; uniform float u_extra; uniform mat2 u_antialiasingmatrix; +uniform float u_offset; varying vec2 v_normal; varying float v_linesofar; @@ -24,7 +25,8 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -39,9 +41,17 @@ void main() { vec2 extrude = a_extrude * scale; vec2 dist = u_linewidth.s * extrude; + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist.xy) / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar; // position of y on the screen diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 92de52bce5b..3af6d0cf7cc 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -20,6 +20,7 @@ uniform vec2 u_patternscale_b; uniform float u_tex_y_b; uniform float u_extra; uniform mat2 u_antialiasingmatrix; +uniform float u_offset; varying vec2 v_normal; varying vec2 v_tex_a; @@ -28,7 +29,8 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -42,9 +44,17 @@ void main() { // of this vertex. vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist.xy) / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); From 4981d18d43b467bf987333215f4f98bb68500b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 1 Dec 2015 17:30:44 +0100 Subject: [PATCH 166/259] [core] add namespace comment to closing brace --- circle_shader.hpp | 2 +- dot_shader.hpp | 2 +- icon_shader.hpp | 2 +- line_shader.hpp | 2 +- linepattern_shader.hpp | 2 +- linesdf_shader.hpp | 2 +- outline_shader.hpp | 2 +- pattern_shader.hpp | 2 +- plain_shader.hpp | 2 +- raster_shader.hpp | 2 +- sdf_shader.hpp | 2 +- shader.hpp | 2 +- uniform.cpp | 2 +- uniform.hpp | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/circle_shader.hpp b/circle_shader.hpp index 84f4ef99a1e..7c1212c2752 100644 --- a/circle_shader.hpp +++ b/circle_shader.hpp @@ -19,6 +19,6 @@ class CircleShader : public Shader { Uniform u_blur = {"u_blur", *this}; }; -} +} // namespace mbgl #endif // MBGL_SHADER_CIRCLE_SHADER diff --git a/dot_shader.hpp b/dot_shader.hpp index fe1541cf753..606764c2d65 100644 --- a/dot_shader.hpp +++ b/dot_shader.hpp @@ -18,6 +18,6 @@ class DotShader : public Shader { Uniform u_blur = {"u_blur", *this}; }; -} +} // namespace mbgl #endif diff --git a/icon_shader.hpp b/icon_shader.hpp index 437fd859bcb..df6232cdcc2 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -30,6 +30,6 @@ class IconShader : public Shader { GLint a_data2 = -1; }; -} +} // namespace mbgl #endif diff --git a/line_shader.hpp b/line_shader.hpp index 580035a07a3..50c209ef242 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -26,6 +26,6 @@ class LineShader : public Shader { }; -} +} // namespace mbgl #endif diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index f2189d4710a..aae550665c3 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -32,6 +32,6 @@ class LinepatternShader : public Shader { private: GLint a_data = -1; }; -} +} // namespace mbgl #endif diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 839494f79bc..1fdae140698 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -33,6 +33,6 @@ class LineSDFShader : public Shader { }; -} +} // namespace mbgl #endif diff --git a/outline_shader.hpp b/outline_shader.hpp index 2cd4b1dc31e..3af9b8349ff 100644 --- a/outline_shader.hpp +++ b/outline_shader.hpp @@ -17,6 +17,6 @@ class OutlineShader : public Shader { Uniform> u_world = {"u_world", *this}; }; -} +} // namespace mbgl #endif diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 3dd3daa4618..d47cbfb182e 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -24,6 +24,6 @@ class PatternShader : public Shader { UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; }; -} +} // namespace mbgl #endif diff --git a/plain_shader.hpp b/plain_shader.hpp index ee0528e9e3c..f9b8c41a630 100644 --- a/plain_shader.hpp +++ b/plain_shader.hpp @@ -16,6 +16,6 @@ class PlainShader : public Shader { Uniform> u_color = {"u_color", *this}; }; -} +} // namespace mbgl #endif diff --git a/raster_shader.hpp b/raster_shader.hpp index af51b4ba464..60b283fc2a7 100644 --- a/raster_shader.hpp +++ b/raster_shader.hpp @@ -23,6 +23,6 @@ class RasterShader : public Shader { Uniform> u_spin_weights = {"u_spin_weights", *this}; }; -} +} // namespace mbgl #endif diff --git a/sdf_shader.hpp b/sdf_shader.hpp index fcb2e15d112..aa888d7d4b7 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -40,6 +40,6 @@ class SDFIconShader : public SDFShader { void bind(GLbyte *offset) final; }; -} +} // namespace mbgl #endif diff --git a/shader.hpp b/shader.hpp index 1de56da87ae..927fdf0b0b0 100644 --- a/shader.hpp +++ b/shader.hpp @@ -34,6 +34,6 @@ class Shader : private util::noncopyable { GLuint fragShader = 0; }; -} +} // namespace mbgl #endif diff --git a/uniform.cpp b/uniform.cpp index eca1a99d176..d43dd20016f 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -44,4 +44,4 @@ void UniformMatrix<4>::bind(const std::array& t) { // Add more as needed. -} +} // namespace mbgl diff --git a/uniform.hpp b/uniform.hpp index 55646f7d87a..0b6d574d09b 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -56,6 +56,6 @@ class UniformMatrix { GLint location; }; -} +} // namespace mbgl #endif From cf8ce922114ef38d8a2c50719d39229693158ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 25 Nov 2015 12:42:34 +0100 Subject: [PATCH 167/259] [core] rudimentary support for offsetting lines --- line.vertex.glsl | 12 +++++++++++- line_shader.hpp | 1 + linepattern.vertex.glsl | 14 ++++++++++++-- linepattern_shader.hpp | 1 + linesdf.vertex.glsl | 14 ++++++++++++-- linesdf_shader.hpp | 1 + 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index 980212384bb..1bd7f5ef5f4 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -14,6 +14,7 @@ uniform mat4 u_matrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; +uniform float u_offset; uniform float u_extra; uniform mat2 u_antialiasingmatrix; @@ -23,6 +24,7 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -36,11 +38,19 @@ void main() { // of this vertex. vec2 dist = u_linewidth.s * a_extrude * scale; + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); // position of y on the screen float y = gl_Position.y / gl_Position.w; diff --git a/line_shader.hpp b/line_shader.hpp index 50c209ef242..14e03c2eafb 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -19,6 +19,7 @@ class LineShader : public Shader { Uniform u_ratio = {"u_ratio", *this}; Uniform u_blur = {"u_blur", *this}; Uniform u_extra = {"u_extra", *this}; + Uniform u_offset = {"u_offset", *this}; UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 541c9fc3a7c..5b3c468be0c 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -17,6 +17,7 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; +uniform float u_offset; uniform vec4 u_color; uniform float u_extra; @@ -28,7 +29,8 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -42,11 +44,19 @@ void main() { // of this vertex. vec2 dist = u_linewidth.s * a_extrude * scale; + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + (offset + dist) / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar; // position of y on the screen diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index aae550665c3..6c83cb0cc3f 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -27,6 +27,7 @@ class LinepatternShader : public Shader { Uniform u_fade = {"u_fade", *this}; Uniform u_opacity = {"u_opacity", *this}; Uniform u_extra = {"u_extra", *this}; + Uniform u_offset = {"u_offset", *this}; UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl index 03851ed533d..80516f97c00 100644 --- a/linesdf.vertex.glsl +++ b/linesdf.vertex.glsl @@ -17,6 +17,7 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; +uniform float u_offset; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; @@ -32,7 +33,8 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -46,11 +48,19 @@ void main() { // of this vertex. vec2 dist = u_linewidth.s * a_extrude * scale; + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + dist / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 1fdae140698..2a8bdc6629d 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -26,6 +26,7 @@ class LineSDFShader : public Shader { Uniform u_sdfgamma = {"u_sdfgamma", *this}; Uniform u_mix = {"u_mix", *this}; Uniform u_extra = {"u_extra", *this}; + Uniform u_offset = {"u_offset", *this}; UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: From 378697ee8219a3f543e6f57633f4f69efe044079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 10 Dec 2015 11:59:30 -0800 Subject: [PATCH 168/259] [core] don't rebuild shaders unless they change --- box_shader.cpp | 9 +++------ circle_shader.cpp | 11 ++++------- dot_shader.cpp | 12 ++++-------- icon_shader.cpp | 12 ++++-------- line_shader.cpp | 12 ++++-------- linepattern_shader.cpp | 11 ++++------- linesdf_shader.cpp | 11 ++++------- outline_shader.cpp | 11 ++++------- pattern_shader.cpp | 6 +++--- plain_shader.cpp | 12 ++++-------- raster_shader.cpp | 11 ++++------- sdf_shader.cpp | 14 +++++--------- 12 files changed, 47 insertions(+), 85 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index beb5e15f9ec..d9845ec36f6 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -7,11 +8,7 @@ using namespace mbgl; CollisionBoxShader::CollisionBoxShader() - : Shader( - "collisionbox", - shaders[BOX_SHADER].vertex, - shaders[BOX_SHADER].fragment - ) { + : Shader("collisionbox", shaders::box::vertex, shaders::box::fragment) { a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } diff --git a/circle_shader.cpp b/circle_shader.cpp index 8fa10191b99..0af5bcf6049 100644 --- a/circle_shader.cpp +++ b/circle_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -7,14 +8,10 @@ using namespace mbgl; CircleShader::CircleShader() - : Shader( - "circle", - shaders[CIRCLE_SHADER].vertex, - shaders[CIRCLE_SHADER].fragment - ) { + : Shader("circle", shaders::circle::vertex, shaders::circle::fragment) { } -void CircleShader::bind(GLbyte *offset) { +void CircleShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 4, offset)); } diff --git a/dot_shader.cpp b/dot_shader.cpp index baec3678b44..2eba489b668 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -1,20 +1,16 @@ #include -#include +#include +#include #include #include using namespace mbgl; -DotShader::DotShader() -: Shader( - "dot", - shaders[DOT_SHADER].vertex, - shaders[DOT_SHADER].fragment - ) { +DotShader::DotShader() : Shader("dot", shaders::dot::vertex, shaders::dot::fragment) { } -void DotShader::bind(GLbyte *offset) { +void DotShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); } diff --git a/icon_shader.cpp b/icon_shader.cpp index a9b4be23e80..bb43cb3e4a2 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -1,23 +1,19 @@ #include -#include +#include +#include #include #include using namespace mbgl; -IconShader::IconShader() - : Shader( - "icon", - shaders[ICON_SHADER].vertex, - shaders[ICON_SHADER].fragment - ) { +IconShader::IconShader() : Shader("icon", shaders::icon::vertex, shaders::icon::fragment) { a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); } -void IconShader::bind(GLbyte *offset) { +void IconShader::bind(GLbyte* offset) { const GLsizei stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); diff --git a/line_shader.cpp b/line_shader.cpp index 1e2306939d9..54bc6c11487 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -1,21 +1,17 @@ #include -#include +#include +#include #include #include using namespace mbgl; -LineShader::LineShader() - : Shader( - "line", - shaders[LINE_SHADER].vertex, - shaders[LINE_SHADER].fragment - ) { +LineShader::LineShader() : Shader("line", shaders::line::vertex, shaders::line::fragment) { a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void LineShader::bind(GLbyte *offset) { +void LineShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 4d416d506e0..9e71d0a9d9b 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -7,15 +8,11 @@ using namespace mbgl; LinepatternShader::LinepatternShader() - : Shader( - "linepattern", - shaders[LINEPATTERN_SHADER].vertex, - shaders[LINEPATTERN_SHADER].fragment - ) { + : Shader("linepattern", shaders::linepattern::vertex, shaders::linepattern::fragment) { a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void LinepatternShader::bind(GLbyte *offset) { +void LinepatternShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index 1a56bb106e6..df988bb3373 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -7,15 +8,11 @@ using namespace mbgl; LineSDFShader::LineSDFShader() - : Shader( - "line", - shaders[LINESDF_SHADER].vertex, - shaders[LINESDF_SHADER].fragment - ) { + : Shader("line", shaders::linesdf::vertex, shaders::linesdf::fragment) { a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); } -void LineSDFShader::bind(GLbyte *offset) { +void LineSDFShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); diff --git a/outline_shader.cpp b/outline_shader.cpp index 74453468bf0..9cda1a11081 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -7,14 +8,10 @@ using namespace mbgl; OutlineShader::OutlineShader() - : Shader( - "outline", - shaders[OUTLINE_SHADER].vertex, - shaders[OUTLINE_SHADER].fragment - ) { + : Shader("outline", shaders::outline::vertex, shaders::outline::fragment) { } -void OutlineShader::bind(GLbyte *offset) { +void OutlineShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/pattern_shader.cpp b/pattern_shader.cpp index d6ddab8e2eb..ef3f35c3560 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -9,8 +10,7 @@ using namespace mbgl; PatternShader::PatternShader() : Shader( "pattern", - shaders[PATTERN_SHADER].vertex, - shaders[PATTERN_SHADER].fragment + shaders::pattern::vertex, shaders::pattern::fragment ) { } diff --git a/plain_shader.cpp b/plain_shader.cpp index 52fef07c051..1817ffbc3de 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -1,20 +1,16 @@ #include -#include +#include +#include #include #include using namespace mbgl; -PlainShader::PlainShader() - : Shader( - "plain", - shaders[PLAIN_SHADER].vertex, - shaders[PLAIN_SHADER].fragment - ) { +PlainShader::PlainShader() : Shader("plain", shaders::plain::vertex, shaders::plain::fragment) { } -void PlainShader::bind(GLbyte *offset) { +void PlainShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/raster_shader.cpp b/raster_shader.cpp index b8496230b97..aaf0bfd2a57 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -7,14 +8,10 @@ using namespace mbgl; RasterShader::RasterShader() - : Shader( - "raster", - shaders[RASTER_SHADER].vertex, - shaders[RASTER_SHADER].fragment - ) { + : Shader("raster", shaders::raster::vertex, shaders::raster::fragment) { } -void RasterShader::bind(GLbyte *offset) { +void RasterShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); } diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 144ba6c475f..97297a7bafb 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -1,23 +1,19 @@ #include -#include +#include +#include #include #include using namespace mbgl; -SDFShader::SDFShader() - : Shader( - "sdf", - shaders[SDF_SHADER].vertex, - shaders[SDF_SHADER].fragment - ) { +SDFShader::SDFShader() : Shader("sdf", shaders::sdf::vertex, shaders::sdf::fragment) { a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); } -void SDFGlyphShader::bind(GLbyte *offset) { +void SDFGlyphShader::bind(GLbyte* offset) { const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); @@ -33,7 +29,7 @@ void SDFGlyphShader::bind(GLbyte *offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); } -void SDFIconShader::bind(GLbyte *offset) { +void SDFIconShader::bind(GLbyte* offset) { const int stride = 16; MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); From abc14cf106e12517c6c177be9560a2c1991bbeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 17 Nov 2015 18:09:36 +0100 Subject: [PATCH 169/259] [core] fix font rendering at the top edge of the viewport --- sdf.vertex.glsl | 7 +------ sdf_shader.hpp | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 5d2e1ce249e..0d538b24fdb 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -14,7 +14,6 @@ uniform float u_minfadezoom; uniform float u_maxfadezoom; uniform float u_fadezoom; uniform bool u_skewed; -uniform float u_extra; uniform vec2 u_texsize; @@ -59,11 +58,7 @@ void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; } - // position of y on the screen - float y = gl_Position.y / gl_Position.w; - // how much features are squished in all directions by the perspectiveness - float perspective_scale = 1.0 / (1.0 - y * u_extra); - v_gamma_scale = perspective_scale; + v_gamma_scale = (gl_Position.w - 0.5); v_tex = a_tex / u_texsize; } diff --git a/sdf_shader.hpp b/sdf_shader.hpp index aa888d7d4b7..a6f9ce105f0 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -22,7 +22,6 @@ class SDFShader : public Shader { Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; Uniform u_fadezoom = {"u_fadezoom", *this}; Uniform u_skewed = {"u_skewed", *this}; - Uniform u_extra = {"u_extra", *this}; protected: GLint a_offset = -1; From eb2657e96e8bdb4ca73c7647acfc7571be2be774 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 18 Dec 2015 11:05:59 -0800 Subject: [PATCH 170/259] Fix warping when rotating / zooming really fast --- circle.vertex.glsl | 2 +- collisionbox.vertex.glsl | 2 +- debug.vertex.glsl | 2 +- dot.vertex.glsl | 2 +- fill.vertex.glsl | 2 +- pattern.vertex.glsl | 2 +- raster.vertex.glsl | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 6672c9d472f..145ebc61a56 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -5,7 +5,7 @@ uniform float u_size; attribute vec2 a_pos; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform mat4 u_exmatrix; varying vec2 v_extrude; diff --git a/collisionbox.vertex.glsl b/collisionbox.vertex.glsl index e887a975e83..cf45740f553 100644 --- a/collisionbox.vertex.glsl +++ b/collisionbox.vertex.glsl @@ -4,7 +4,7 @@ attribute vec2 a_pos; attribute vec2 a_extrude; attribute vec2 a_data; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform float u_scale; varying float v_max_zoom; diff --git a/debug.vertex.glsl b/debug.vertex.glsl index f375d99a22c..46f4d13ff43 100644 --- a/debug.vertex.glsl +++ b/debug.vertex.glsl @@ -2,7 +2,7 @@ precision mediump float; attribute vec2 a_pos; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, step(32767.0, a_pos.x), 1); diff --git a/dot.vertex.glsl b/dot.vertex.glsl index b58862645a1..86554810a9e 100644 --- a/dot.vertex.glsl +++ b/dot.vertex.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform float u_size; attribute vec2 a_pos; diff --git a/fill.vertex.glsl b/fill.vertex.glsl index d37f25a160c..e5d78c0911f 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,7 +1,7 @@ precision mediump float; attribute vec2 a_pos; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 560dc737227..ad7c085e25f 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform mat3 u_patternmatrix_a; uniform mat3 u_patternmatrix_b; diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 1e658c7f1fd..3da31aef3dd 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform mat4 u_matrix; +uniform highp mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; uniform float u_buffer_scale; From 7167111db6d3d13276b38a16ac4d211dc95c7d2b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 21 Apr 2015 16:11:52 -0700 Subject: [PATCH 171/259] implement layer-by-layer rendering This makes rendering more similar to -native. All layers are drawn in two passes: opaque and then transparent. Tile clip ids are drawn to the stencil at the same time to allow for fast switching between tiles. The depth buffer is used to drop fragments below opaque fills. fixes #757 Unlike -native, only the last 5 bits of the stencil buffer are used for storing clip ids. The first 3 bits are still used for rendering polygons. --- pattern.vertex.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index ad7c085e25f..0b067ed65f0 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,8 +1,8 @@ precision mediump float; uniform highp mat4 u_matrix; -uniform mat3 u_patternmatrix_a; -uniform mat3 u_patternmatrix_b; +uniform vec2 u_patternscale_a; +uniform vec2 u_patternscale_b; attribute vec2 a_pos; @@ -11,6 +11,6 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy; - v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy; + v_pos_a = u_patternscale_a * a_pos; + v_pos_b = u_patternscale_b * a_pos; } From e1d5981c88316f018a9bfbfda9c44b275686b3e3 Mon Sep 17 00:00:00 2001 From: kelvinabrokwa Date: Thu, 7 Jan 2016 17:02:35 -0800 Subject: [PATCH 172/259] match patterns at tile boundaries offsets fill-patterns to match at tile boundaries update test suite to include uneven pattern test seamless over dateline b -> a --- pattern.vertex.glsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 0b067ed65f0..7af9976c9d6 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -3,6 +3,8 @@ precision mediump float; uniform highp mat4 u_matrix; uniform vec2 u_patternscale_a; uniform vec2 u_patternscale_b; +uniform vec2 u_offset_a; +uniform vec2 u_offset_b; attribute vec2 a_pos; @@ -11,6 +13,6 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = u_patternscale_a * a_pos; - v_pos_b = u_patternscale_b * a_pos; + v_pos_a = u_patternscale_a * a_pos + u_offset_a; + v_pos_b = u_patternscale_b * a_pos + u_offset_b; } From ec2176863ed8d3739f8990ee66c26eb7efa06bed Mon Sep 17 00:00:00 2001 From: kelvinabrokwa Date: Mon, 11 Jan 2016 10:33:49 -0800 Subject: [PATCH 173/259] [core] seamless fill-pattern seamless across dateline upgrade test-suite version --- pattern.vertex.glsl | 7 +++++-- pattern_shader.hpp | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index dff4469d2b6..4ff51cad647 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -2,6 +2,9 @@ uniform mat4 u_matrix; uniform mat3 u_patternmatrix_a; uniform mat3 u_patternmatrix_b; +uniform vec2 u_offset_a; +uniform vec2 u_offset_b; + attribute vec2 a_pos; varying vec2 v_pos_a; @@ -9,6 +12,6 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy; - v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy; + v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy + u_offset_a; + v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy + u_offset_b; } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index d47cbfb182e..db7901c578f 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -22,6 +22,8 @@ class PatternShader : public Shader { Uniform u_image = {"u_image", *this}; UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; + Uniform> u_offset_a = {"u_offset_a", *this}; + Uniform> u_offset_b = {"u_offset_b", *this}; }; } // namespace mbgl From aeedf644344be152109f22097894e3014eaffc5b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 12 Jan 2016 17:13:11 -0800 Subject: [PATCH 174/259] [core] set u_texture uniform value fix #1685 --- icon_shader.hpp | 1 + sdf_shader.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/icon_shader.hpp b/icon_shader.hpp index df6232cdcc2..8a25b635fe1 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -23,6 +23,7 @@ class IconShader : public Shader { Uniform> u_texsize = {"u_texsize", *this}; Uniform u_skewed = {"u_skewed", *this}; Uniform u_extra = {"u_extra", *this}; + Uniform u_texture = {"u_texture", *this}; protected: GLint a_offset = -1; diff --git a/sdf_shader.hpp b/sdf_shader.hpp index a6f9ce105f0..29dbfea0474 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -22,6 +22,7 @@ class SDFShader : public Shader { Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; Uniform u_fadezoom = {"u_fadezoom", *this}; Uniform u_skewed = {"u_skewed", *this}; + Uniform u_texture = {"u_texture", *this}; protected: GLint a_offset = -1; From cf92516e63ecb88fc13c9e27a3883cb3d95043f1 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 28 Jan 2016 21:41:20 -0800 Subject: [PATCH 175/259] [core] support tiles with non-4096 extents Convert all geometries to the maximum extent supported by our buffers and then use that constant extent everywhere else. --- raster.vertex.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 97e563f585f..107b82a0ef2 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -8,6 +8,6 @@ varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - float dimension = (4096.0 + 2.0 * u_buffer); + float dimension = (8192.0 + 2.0 * u_buffer); v_pos = (a_pos / dimension) + (u_buffer / dimension); } From a777985f41be868ce5c3fa862aca315b0ef66e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 4 Feb 2016 16:18:35 +0100 Subject: [PATCH 176/259] [core] move platform/gl.hpp to gl/gl.hpp --- box_shader.cpp | 2 +- box_shader.hpp | 2 +- circle_shader.cpp | 2 +- dot_shader.cpp | 2 +- icon_shader.cpp | 2 +- line_shader.cpp | 2 +- linepattern_shader.cpp | 2 +- linesdf_shader.cpp | 2 +- outline_shader.cpp | 2 +- pattern_shader.cpp | 2 +- plain_shader.cpp | 2 +- raster_shader.cpp | 2 +- sdf_shader.cpp | 2 +- shader.cpp | 2 +- shader.hpp | 2 +- uniform.hpp | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index d9845ec36f6..c9cd9bf0913 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/box_shader.hpp b/box_shader.hpp index 19df2ca8250..bc781dbc153 100644 --- a/box_shader.hpp +++ b/box_shader.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace mbgl { diff --git a/circle_shader.cpp b/circle_shader.cpp index 0af5bcf6049..d128f8b699c 100644 --- a/circle_shader.cpp +++ b/circle_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/dot_shader.cpp b/dot_shader.cpp index 2eba489b668..12e2ee78450 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/icon_shader.cpp b/icon_shader.cpp index bb43cb3e4a2..28d84853dea 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/line_shader.cpp b/line_shader.cpp index 54bc6c11487..12790de00a4 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 9e71d0a9d9b..18ec2c23f50 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index df988bb3373..48622cb7635 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/outline_shader.cpp b/outline_shader.cpp index 9cda1a11081..df42e09e010 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/pattern_shader.cpp b/pattern_shader.cpp index ef3f35c3560..d872e8d9761 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/plain_shader.cpp b/plain_shader.cpp index 1817ffbc3de..1408a42c62f 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/raster_shader.cpp b/raster_shader.cpp index aaf0bfd2a57..4b7c0077b35 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 97297a7bafb..7ca3bf84dec 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include diff --git a/shader.cpp b/shader.cpp index e8deefc8ff5..fbf758d3bfb 100644 --- a/shader.cpp +++ b/shader.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/shader.hpp b/shader.hpp index 927fdf0b0b0..0570b1c642c 100644 --- a/shader.hpp +++ b/shader.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_RENDERER_SHADER #define MBGL_RENDERER_SHADER -#include +#include #include #include diff --git a/uniform.hpp b/uniform.hpp index 0b6d574d09b..ceeb22bd99d 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -2,7 +2,7 @@ #define MBGL_SHADER_UNIFORM #include -#include +#include namespace mbgl { From ddb630b084f89382a1d4852be1cfe1fedecd1e83 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 11 Feb 2016 15:15:41 -0800 Subject: [PATCH 177/259] remove unused dot shader --- dot.fragment.glsl | 11 ----------- dot.vertex.glsl | 11 ----------- 2 files changed, 22 deletions(-) delete mode 100644 dot.fragment.glsl delete mode 100644 dot.vertex.glsl diff --git a/dot.fragment.glsl b/dot.fragment.glsl deleted file mode 100644 index 4639f697361..00000000000 --- a/dot.fragment.glsl +++ /dev/null @@ -1,11 +0,0 @@ -precision mediump float; - -uniform vec4 u_color; -uniform float u_blur; - -void main() { - float dist = length(gl_PointCoord - 0.5); - float t = smoothstep(0.5, 0.5 - u_blur, dist); - - gl_FragColor = u_color * t; -} diff --git a/dot.vertex.glsl b/dot.vertex.glsl deleted file mode 100644 index 86554810a9e..00000000000 --- a/dot.vertex.glsl +++ /dev/null @@ -1,11 +0,0 @@ -precision mediump float; - -uniform highp mat4 u_matrix; -uniform float u_size; - -attribute vec2 a_pos; - -void main(void) { - gl_Position = u_matrix * vec4(a_pos, 0, 1); - gl_PointSize = u_size; -} From 0aa370a7d85f9a1a73389ea4c4bfcaddb31c3d65 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Sun, 14 Feb 2016 13:17:59 +0200 Subject: [PATCH 178/259] [gl] Use Shader::getID() whenever possible --- box_shader.cpp | 4 ++-- icon_shader.cpp | 6 +++--- line_shader.cpp | 2 +- linepattern_shader.cpp | 2 +- linesdf_shader.cpp | 2 +- sdf_shader.cpp | 6 +++--- uniform.hpp | 6 ++++-- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index c9cd9bf0913..59fd104f838 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -9,8 +9,8 @@ using namespace mbgl; CollisionBoxShader::CollisionBoxShader() : Shader("collisionbox", shaders::box::vertex, shaders::box::fragment) { - a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude")); - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); + a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_extrude")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } void CollisionBoxShader::bind(GLbyte *offset) { diff --git a/icon_shader.cpp b/icon_shader.cpp index 28d84853dea..609f2bb293e 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -8,9 +8,9 @@ using namespace mbgl; IconShader::IconShader() : Shader("icon", shaders::icon::vertex, shaders::icon::fragment) { - a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); - a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); - a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); + a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")); + a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")); + a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2")); } void IconShader::bind(GLbyte* offset) { diff --git a/line_shader.cpp b/line_shader.cpp index 12790de00a4..e0dc5384b56 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -8,7 +8,7 @@ using namespace mbgl; LineShader::LineShader() : Shader("line", shaders::line::vertex, shaders::line::fragment) { - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } void LineShader::bind(GLbyte* offset) { diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 18ec2c23f50..4c15d8b075b 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -9,7 +9,7 @@ using namespace mbgl; LinepatternShader::LinepatternShader() : Shader("linepattern", shaders::linepattern::vertex, shaders::linepattern::fragment) { - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } void LinepatternShader::bind(GLbyte* offset) { diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index 48622cb7635..f5eba0a0469 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -9,7 +9,7 @@ using namespace mbgl; LineSDFShader::LineSDFShader() : Shader("line", shaders::linesdf::vertex, shaders::linesdf::fragment) { - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data")); + a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } void LineSDFShader::bind(GLbyte* offset) { diff --git a/sdf_shader.cpp b/sdf_shader.cpp index 7ca3bf84dec..e613863041e 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -8,9 +8,9 @@ using namespace mbgl; SDFShader::SDFShader() : Shader("sdf", shaders::sdf::vertex, shaders::sdf::fragment) { - a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset")); - a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1")); - a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2")); + a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")); + a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")); + a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2")); } void SDFGlyphShader::bind(GLbyte* offset) { diff --git a/uniform.hpp b/uniform.hpp index ceeb22bd99d..5c4a2b14c4f 100644 --- a/uniform.hpp +++ b/uniform.hpp @@ -4,13 +4,15 @@ #include #include +#include + namespace mbgl { template class Uniform { public: Uniform(const GLchar* name, const Shader& shader) : current() { - location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); + location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name)); } void operator=(const T& t) { @@ -33,7 +35,7 @@ class UniformMatrix { typedef std::array T; UniformMatrix(const GLchar* name, const Shader& shader) : current() { - location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name)); + location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name)); } void operator=(const std::array& t) { From 098743f7faebf85b6a05c565d3c0f8ae3c70a470 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Sun, 14 Feb 2016 17:55:39 +0200 Subject: [PATCH 179/259] [gl] Added mbgl::gl::ProgramHolder --- shader.cpp | 34 ++++++++++++++-------------------- shader.hpp | 11 ++++------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/shader.cpp b/shader.cpp index fbf758d3bfb..c0757b749a3 100644 --- a/shader.cpp +++ b/shader.cpp @@ -15,16 +15,14 @@ using namespace mbgl; Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource) : name(name_) - , program(0) { util::stopwatch stopwatch("shader compilation", Event::Shader); - program = MBGL_CHECK_ERROR(glCreateProgram()); + program.create(); if (!compileShader(&vertShader, GL_VERTEX_SHADER, &vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; + program.reset(); throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile"); } @@ -32,27 +30,26 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; + program.reset(); throw util::ShaderException(std::string { "Fragment shader " } + name + " failed to compile"); } // Attach shaders - MBGL_CHECK_ERROR(glAttachShader(program, vertShader)); - MBGL_CHECK_ERROR(glAttachShader(program, fragShader)); + MBGL_CHECK_ERROR(glAttachShader(program.getID(), vertexShader)); + MBGL_CHECK_ERROR(glAttachShader(program.getID(), fragmentShader)); { // Link program GLint status; - MBGL_CHECK_ERROR(glLinkProgram(program)); + MBGL_CHECK_ERROR(glLinkProgram(program.getID())); - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status)); + MBGL_CHECK_ERROR(glGetProgramiv(program.getID(), GL_LINK_STATUS, &status)); if (status == 0) { GLint logLength; - MBGL_CHECK_ERROR(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength)); + MBGL_CHECK_ERROR(glGetProgramiv(program.getID(), GL_INFO_LOG_LENGTH, &logLength)); const auto log = std::make_unique(logLength); if (logLength > 0) { - MBGL_CHECK_ERROR(glGetProgramInfoLog(program, logLength, &logLength, log.get())); + MBGL_CHECK_ERROR(glGetProgramInfoLog(program.getID(), logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } @@ -60,13 +57,12 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo vertShader = 0; MBGL_CHECK_ERROR(glDeleteShader(fragShader)); fragShader = 0; - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; - throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); + program.reset(); + throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); } } - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program.getID(), "a_pos")); } @@ -107,10 +103,8 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source[]) Shader::~Shader() { if (program) { - MBGL_CHECK_ERROR(glDetachShader(program, vertShader)); - MBGL_CHECK_ERROR(glDetachShader(program, fragShader)); - MBGL_CHECK_ERROR(glDeleteProgram(program)); - program = 0; + MBGL_CHECK_ERROR(glDetachShader(program.getID(), vertexShader)); + MBGL_CHECK_ERROR(glDetachShader(program.getID(), fragmentShader)); MBGL_CHECK_ERROR(glDeleteShader(vertShader)); vertShader = 0; MBGL_CHECK_ERROR(glDeleteShader(fragShader)); diff --git a/shader.hpp b/shader.hpp index 0570b1c642c..b3d694a04fe 100644 --- a/shader.hpp +++ b/shader.hpp @@ -2,12 +2,9 @@ #define MBGL_RENDERER_SHADER #include +#include #include -#include -#include -#include - namespace mbgl { class Shader : private util::noncopyable { @@ -16,10 +13,9 @@ class Shader : private util::noncopyable { ~Shader(); const GLchar *name; - GLuint program; - inline GLuint getID() const { - return program; + inline const GLuint& getID() const { + return program.getID(); } virtual void bind(GLbyte *offset) = 0; @@ -30,6 +26,7 @@ class Shader : private util::noncopyable { private: bool compileShader(GLuint *shader, GLenum type, const GLchar *source[]); + gl::ProgramHolder program; GLuint vertShader = 0; GLuint fragShader = 0; }; From ca86707e4811322f692bf62dd0a775e5a52b96ca Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Sun, 14 Feb 2016 18:18:24 +0200 Subject: [PATCH 180/259] [gl] Added mbgl::gl::ShaderHolder --- shader.cpp | 58 +++++++++++++++++++----------------------------------- shader.hpp | 8 ++++---- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/shader.cpp b/shader.cpp index c0757b749a3..998edfb9704 100644 --- a/shader.cpp +++ b/shader.cpp @@ -11,7 +11,7 @@ #include #include -using namespace mbgl; +namespace mbgl { Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource) : name(name_) @@ -19,24 +19,21 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo util::stopwatch stopwatch("shader compilation", Event::Shader); program.create(); - - if (!compileShader(&vertShader, GL_VERTEX_SHADER, &vertSource)) { + vertexShader.create(); + if (!compileShader(vertexShader, &vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); - program.reset(); throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile"); } - if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, &fragSource)) { + fragmentShader.create(); + if (!compileShader(fragmentShader, &fragSource)) { Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - vertShader = 0; - program.reset(); throw util::ShaderException(std::string { "Fragment shader " } + name + " failed to compile"); } // Attach shaders - MBGL_CHECK_ERROR(glAttachShader(program.getID(), vertexShader)); - MBGL_CHECK_ERROR(glAttachShader(program.getID(), fragmentShader)); + MBGL_CHECK_ERROR(glAttachShader(program.getID(), vertexShader.getID())); + MBGL_CHECK_ERROR(glAttachShader(program.getID(), fragmentShader.getID())); { // Link program @@ -52,49 +49,36 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo MBGL_CHECK_ERROR(glGetProgramInfoLog(program.getID(), logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } - - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - vertShader = 0; - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - fragShader = 0; - program.reset(); - throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); + throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); } } a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program.getID(), "a_pos")); } +bool Shader::compileShader(gl::ShaderHolder& shader, const GLchar *source[]) { + GLint status = 0; -bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source[]) { - GLint status; - - *shader = MBGL_CHECK_ERROR(glCreateShader(type)); const GLsizei lengths = static_cast(std::strlen(*source)); - MBGL_CHECK_ERROR(glShaderSource(*shader, 1, source, &lengths)); + MBGL_CHECK_ERROR(glShaderSource(shader.getID(), 1, source, &lengths)); - MBGL_CHECK_ERROR(glCompileShader(*shader)); + MBGL_CHECK_ERROR(glCompileShader(shader.getID())); - MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); + MBGL_CHECK_ERROR(glGetShaderiv(shader.getID(), GL_COMPILE_STATUS, &status)); if (status == 0) { GLint logLength; - MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength)); + MBGL_CHECK_ERROR(glGetShaderiv(shader.getID(), GL_INFO_LOG_LENGTH, &logLength)); if (logLength > 0) { const auto log = std::make_unique(logLength); - MBGL_CHECK_ERROR(glGetShaderInfoLog(*shader, logLength, &logLength, log.get())); + MBGL_CHECK_ERROR(glGetShaderInfoLog(shader.getID(), logLength, &logLength, log.get())); Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); } - - MBGL_CHECK_ERROR(glDeleteShader(*shader)); - *shader = 0; return false; } - MBGL_CHECK_ERROR(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); + MBGL_CHECK_ERROR(glGetShaderiv(shader.getID(), GL_COMPILE_STATUS, &status)); if (status == GL_FALSE) { Log::Error(Event::Shader, "Shader %s failed to compile.", name); - MBGL_CHECK_ERROR(glDeleteShader(*shader)); - *shader = 0; return false; } @@ -103,11 +87,9 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source[]) Shader::~Shader() { if (program) { - MBGL_CHECK_ERROR(glDetachShader(program.getID(), vertexShader)); - MBGL_CHECK_ERROR(glDetachShader(program.getID(), fragmentShader)); - MBGL_CHECK_ERROR(glDeleteShader(vertShader)); - vertShader = 0; - MBGL_CHECK_ERROR(glDeleteShader(fragShader)); - fragShader = 0; + MBGL_CHECK_ERROR(glDetachShader(program.getID(), vertexShader.getID())); + MBGL_CHECK_ERROR(glDetachShader(program.getID(), fragmentShader.getID())); } } + +} // namespace mbgl diff --git a/shader.hpp b/shader.hpp index b3d694a04fe..c63aa6714cb 100644 --- a/shader.hpp +++ b/shader.hpp @@ -14,7 +14,7 @@ class Shader : private util::noncopyable { ~Shader(); const GLchar *name; - inline const GLuint& getID() const { + GLuint getID() const { return program.getID(); } @@ -24,11 +24,11 @@ class Shader : private util::noncopyable { GLint a_pos = -1; private: - bool compileShader(GLuint *shader, GLenum type, const GLchar *source[]); + bool compileShader(gl::ShaderHolder&, const GLchar *source[]); gl::ProgramHolder program; - GLuint vertShader = 0; - GLuint fragShader = 0; + gl::ShaderHolder vertexShader = { GL_VERTEX_SHADER }; + gl::ShaderHolder fragmentShader = { GL_FRAGMENT_SHADER }; }; } // namespace mbgl From 8ab28437c5b6b1810f718c0ddb7980cf1fe8d515 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 18 Feb 2016 11:19:24 -0800 Subject: [PATCH 181/259] [core] Thread GLObjectStore through to Holder objects This eliminates the reliance on ThreadContext to provide GLObjectStore, and statically enforces that GL cleanup functions happen only when GLObjectStore::performCleanup is called. With the elimination of the Map thread, this becomes important because there may be multiple GLObjectStore's per-thread, and Map will need to ensure that the correct context is active when calling GLObjectStore::performCleanup. --- box_shader.cpp | 4 ++-- box_shader.hpp | 2 +- circle_shader.cpp | 4 ++-- circle_shader.hpp | 2 +- dot_shader.cpp | 3 ++- dot_shader.hpp | 2 +- icon_shader.cpp | 3 ++- icon_shader.hpp | 2 +- line_shader.cpp | 3 ++- line_shader.hpp | 2 +- linepattern_shader.cpp | 4 ++-- linepattern_shader.hpp | 2 +- linesdf_shader.cpp | 4 ++-- linesdf_shader.hpp | 2 +- outline_shader.cpp | 4 ++-- outline_shader.hpp | 2 +- pattern_shader.cpp | 5 +++-- pattern_shader.hpp | 2 +- plain_shader.cpp | 3 ++- plain_shader.hpp | 2 +- raster_shader.cpp | 4 ++-- raster_shader.hpp | 2 +- sdf_shader.cpp | 3 ++- sdf_shader.hpp | 4 +++- shader.cpp | 8 ++++---- shader.hpp | 2 +- 26 files changed, 44 insertions(+), 36 deletions(-) diff --git a/box_shader.cpp b/box_shader.cpp index 59fd104f838..63f800ea698 100644 --- a/box_shader.cpp +++ b/box_shader.cpp @@ -7,8 +7,8 @@ using namespace mbgl; -CollisionBoxShader::CollisionBoxShader() - : Shader("collisionbox", shaders::box::vertex, shaders::box::fragment) { +CollisionBoxShader::CollisionBoxShader(gl::GLObjectStore& glObjectStore) + : Shader("collisionbox", shaders::box::vertex, shaders::box::fragment, glObjectStore) { a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_extrude")); a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } diff --git a/box_shader.hpp b/box_shader.hpp index bc781dbc153..f3015b73a7b 100644 --- a/box_shader.hpp +++ b/box_shader.hpp @@ -9,7 +9,7 @@ namespace mbgl { class CollisionBoxShader : public Shader { public: - CollisionBoxShader(); + CollisionBoxShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/circle_shader.cpp b/circle_shader.cpp index d128f8b699c..3ec822747fe 100644 --- a/circle_shader.cpp +++ b/circle_shader.cpp @@ -7,8 +7,8 @@ using namespace mbgl; -CircleShader::CircleShader() - : Shader("circle", shaders::circle::vertex, shaders::circle::fragment) { +CircleShader::CircleShader(gl::GLObjectStore& glObjectStore) + : Shader("circle", shaders::circle::vertex, shaders::circle::fragment, glObjectStore) { } void CircleShader::bind(GLbyte* offset) { diff --git a/circle_shader.hpp b/circle_shader.hpp index 7c1212c2752..a28bf3c6ae0 100644 --- a/circle_shader.hpp +++ b/circle_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class CircleShader : public Shader { public: - CircleShader(); + CircleShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/dot_shader.cpp b/dot_shader.cpp index 12e2ee78450..9d60306da2c 100644 --- a/dot_shader.cpp +++ b/dot_shader.cpp @@ -7,7 +7,8 @@ using namespace mbgl; -DotShader::DotShader() : Shader("dot", shaders::dot::vertex, shaders::dot::fragment) { +DotShader::DotShader(gl::GLObjectStore& glObjectStore) + : Shader("dot", shaders::dot::vertex, shaders::dot::fragment, glObjectStore) { } void DotShader::bind(GLbyte* offset) { diff --git a/dot_shader.hpp b/dot_shader.hpp index 606764c2d65..a015310a626 100644 --- a/dot_shader.hpp +++ b/dot_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class DotShader : public Shader { public: - DotShader(); + DotShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/icon_shader.cpp b/icon_shader.cpp index 609f2bb293e..2ff653a87c3 100644 --- a/icon_shader.cpp +++ b/icon_shader.cpp @@ -7,7 +7,8 @@ using namespace mbgl; -IconShader::IconShader() : Shader("icon", shaders::icon::vertex, shaders::icon::fragment) { +IconShader::IconShader(gl::GLObjectStore& glObjectStore) + : Shader("icon", shaders::icon::vertex, shaders::icon::fragment, glObjectStore) { a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")); a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2")); diff --git a/icon_shader.hpp b/icon_shader.hpp index 8a25b635fe1..ec6311ea807 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class IconShader : public Shader { public: - IconShader(); + IconShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/line_shader.cpp b/line_shader.cpp index e0dc5384b56..e4df0531d8b 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -7,7 +7,8 @@ using namespace mbgl; -LineShader::LineShader() : Shader("line", shaders::line::vertex, shaders::line::fragment) { +LineShader::LineShader(gl::GLObjectStore& glObjectStore) + : Shader("line", shaders::line::vertex, shaders::line::fragment, glObjectStore) { a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } diff --git a/line_shader.hpp b/line_shader.hpp index 14e03c2eafb..1a9598f9251 100644 --- a/line_shader.hpp +++ b/line_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class LineShader : public Shader { public: - LineShader(); + LineShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 4c15d8b075b..7acd42f727a 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -7,8 +7,8 @@ using namespace mbgl; -LinepatternShader::LinepatternShader() - : Shader("linepattern", shaders::linepattern::vertex, shaders::linepattern::fragment) { +LinepatternShader::LinepatternShader(gl::GLObjectStore& glObjectStore) + : Shader("linepattern", shaders::linepattern::vertex, shaders::linepattern::fragment, glObjectStore) { a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index 6c83cb0cc3f..0d3e98c8341 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class LinepatternShader : public Shader { public: - LinepatternShader(); + LinepatternShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index f5eba0a0469..00adaf0c867 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -7,8 +7,8 @@ using namespace mbgl; -LineSDFShader::LineSDFShader() - : Shader("line", shaders::linesdf::vertex, shaders::linesdf::fragment) { +LineSDFShader::LineSDFShader(gl::GLObjectStore& glObjectStore) + : Shader("line", shaders::linesdf::vertex, shaders::linesdf::fragment, glObjectStore) { a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); } diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp index 2a8bdc6629d..8ac0aa57934 100644 --- a/linesdf_shader.hpp +++ b/linesdf_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class LineSDFShader : public Shader { public: - LineSDFShader(); + LineSDFShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/outline_shader.cpp b/outline_shader.cpp index df42e09e010..8c7458327fd 100644 --- a/outline_shader.cpp +++ b/outline_shader.cpp @@ -7,8 +7,8 @@ using namespace mbgl; -OutlineShader::OutlineShader() - : Shader("outline", shaders::outline::vertex, shaders::outline::fragment) { +OutlineShader::OutlineShader(gl::GLObjectStore& glObjectStore) + : Shader("outline", shaders::outline::vertex, shaders::outline::fragment, glObjectStore) { } void OutlineShader::bind(GLbyte* offset) { diff --git a/outline_shader.hpp b/outline_shader.hpp index 3af9b8349ff..800461bf066 100644 --- a/outline_shader.hpp +++ b/outline_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class OutlineShader : public Shader { public: - OutlineShader(); + OutlineShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/pattern_shader.cpp b/pattern_shader.cpp index d872e8d9761..4f52df59fb1 100644 --- a/pattern_shader.cpp +++ b/pattern_shader.cpp @@ -7,10 +7,11 @@ using namespace mbgl; -PatternShader::PatternShader() +PatternShader::PatternShader(gl::GLObjectStore& glObjectStore) : Shader( "pattern", - shaders::pattern::vertex, shaders::pattern::fragment + shaders::pattern::vertex, shaders::pattern::fragment, + glObjectStore ) { } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index db7901c578f..8692f6ed399 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class PatternShader : public Shader { public: - PatternShader(); + PatternShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/plain_shader.cpp b/plain_shader.cpp index 1408a42c62f..1b5a7819b36 100644 --- a/plain_shader.cpp +++ b/plain_shader.cpp @@ -7,7 +7,8 @@ using namespace mbgl; -PlainShader::PlainShader() : Shader("plain", shaders::plain::vertex, shaders::plain::fragment) { +PlainShader::PlainShader(gl::GLObjectStore& glObjectStore) + : Shader("plain", shaders::plain::vertex, shaders::plain::fragment, glObjectStore) { } void PlainShader::bind(GLbyte* offset) { diff --git a/plain_shader.hpp b/plain_shader.hpp index f9b8c41a630..34ee4dcdf78 100644 --- a/plain_shader.hpp +++ b/plain_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class PlainShader : public Shader { public: - PlainShader(); + PlainShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/raster_shader.cpp b/raster_shader.cpp index 4b7c0077b35..77bcf400087 100644 --- a/raster_shader.cpp +++ b/raster_shader.cpp @@ -7,8 +7,8 @@ using namespace mbgl; -RasterShader::RasterShader() - : Shader("raster", shaders::raster::vertex, shaders::raster::fragment) { +RasterShader::RasterShader(gl::GLObjectStore& glObjectStore) + : Shader("raster", shaders::raster::vertex, shaders::raster::fragment, glObjectStore) { } void RasterShader::bind(GLbyte* offset) { diff --git a/raster_shader.hpp b/raster_shader.hpp index 60b283fc2a7..6a2e2ecf3ed 100644 --- a/raster_shader.hpp +++ b/raster_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class RasterShader : public Shader { public: - RasterShader(); + RasterShader(gl::GLObjectStore&); void bind(GLbyte *offset) final; diff --git a/sdf_shader.cpp b/sdf_shader.cpp index e613863041e..a972849d3d9 100644 --- a/sdf_shader.cpp +++ b/sdf_shader.cpp @@ -7,7 +7,8 @@ using namespace mbgl; -SDFShader::SDFShader() : Shader("sdf", shaders::sdf::vertex, shaders::sdf::fragment) { +SDFShader::SDFShader(gl::GLObjectStore& glObjectStore) + : Shader("sdf", shaders::sdf::vertex, shaders::sdf::fragment, glObjectStore) { a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")); a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")); a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2")); diff --git a/sdf_shader.hpp b/sdf_shader.hpp index 29dbfea0474..402168de0c1 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class SDFShader : public Shader { public: - SDFShader(); + SDFShader(gl::GLObjectStore&); UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; @@ -32,11 +32,13 @@ class SDFShader : public Shader { class SDFGlyphShader : public SDFShader { public: + SDFGlyphShader(gl::GLObjectStore& glObjectStore) : SDFShader(glObjectStore) {} void bind(GLbyte *offset) final; }; class SDFIconShader : public SDFShader { public: + SDFIconShader(gl::GLObjectStore& glObjectStore) : SDFShader(glObjectStore) {} void bind(GLbyte *offset) final; }; diff --git a/shader.cpp b/shader.cpp index 998edfb9704..8216de5b4d9 100644 --- a/shader.cpp +++ b/shader.cpp @@ -13,19 +13,19 @@ namespace mbgl { -Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource) +Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource, gl::GLObjectStore& glObjectStore) : name(name_) { util::stopwatch stopwatch("shader compilation", Event::Shader); - program.create(); - vertexShader.create(); + program.create(glObjectStore); + vertexShader.create(glObjectStore); if (!compileShader(vertexShader, &vertSource)) { Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile"); } - fragmentShader.create(); + fragmentShader.create(glObjectStore); if (!compileShader(fragmentShader, &fragSource)) { Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); throw util::ShaderException(std::string { "Fragment shader " } + name + " failed to compile"); diff --git a/shader.hpp b/shader.hpp index c63aa6714cb..b543f73a6f7 100644 --- a/shader.hpp +++ b/shader.hpp @@ -9,7 +9,7 @@ namespace mbgl { class Shader : private util::noncopyable { public: - Shader(const GLchar *name, const GLchar *vertex, const GLchar *fragment); + Shader(const GLchar *name, const GLchar *vertex, const GLchar *fragment, gl::GLObjectStore&); ~Shader(); const GLchar *name; From 341429c28bc68259dfa5ef28eddb766aa2500a8d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 9 Feb 2016 16:22:51 -0800 Subject: [PATCH 182/259] fix #2099, reset line distance when it is near max --- linepattern.vertex.glsl | 6 +++++- linesdfpattern.vertex.glsl | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index e39baad2eb0..426e4d5fb05 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -8,6 +8,10 @@ precision mediump float; // #define scale 63.0 #define scale 0.015873016 +// We scale the distance before adding it to the buffers so that we can store +// long distances for long segments. Use this value to unscale the distance. +#define LINE_DISTANCE_SCALE 2.0 + attribute vec2 a_pos; attribute vec4 a_data; @@ -26,7 +30,7 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; + float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 3af6d0cf7cc..cec35abac2a 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -8,6 +8,10 @@ precision mediump float; // #define scale 63.0 #define scale 0.015873016 +// We scale the distance before adding it to the buffers so that we can store +// long distances for long segments. Use this value to unscale the distance. +#define LINE_DISTANCE_SCALE 2.0 + attribute vec2 a_pos; attribute vec4 a_data; @@ -30,7 +34,7 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; + float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 From 53f6bd73b2b5a0270d94eeeed045948845485c27 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 19 Feb 2016 16:07:57 -0800 Subject: [PATCH 183/259] pack extrude and line distance into unsigned byte instead of a signed byte. It's a bit easier to understand. --- line.vertex.glsl | 4 ++-- linepattern.vertex.glsl | 6 +++--- linesdfpattern.vertex.glsl | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index ba0ffe05a61..4c36e0c13bb 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -23,8 +23,8 @@ varying float v_linesofar; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 426e4d5fb05..0e00dc12d40 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -28,9 +28,9 @@ varying float v_linesofar; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; + float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index cec35abac2a..b7fc6f76a0b 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -32,9 +32,9 @@ varying vec2 v_tex_b; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; + float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 From cead98a640d79d46e24a25e716e61d3a0a370a98 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 11 Feb 2016 12:55:21 -0800 Subject: [PATCH 184/259] Set all colors to lowp --- circle.fragment.glsl | 2 +- debug.fragment.glsl | 2 +- fill.fragment.glsl | 2 +- line.fragment.glsl | 2 +- linepattern.vertex.glsl | 2 +- linesdfpattern.fragment.glsl | 2 +- outline.fragment.glsl | 2 +- sdf.fragment.glsl | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 8f997eee22b..4427d64c65c 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform vec4 u_color; +uniform lowp vec4 u_color; uniform float u_blur; uniform float u_size; diff --git a/debug.fragment.glsl b/debug.fragment.glsl index f21d7dd6ebb..e8cc2e202aa 100644 --- a/debug.fragment.glsl +++ b/debug.fragment.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform vec4 u_color; +uniform lowp vec4 u_color; void main() { gl_FragColor = u_color; diff --git a/fill.fragment.glsl b/fill.fragment.glsl index f21d7dd6ebb..e8cc2e202aa 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform vec4 u_color; +uniform lowp vec4 u_color; void main() { gl_FragColor = u_color; diff --git a/line.fragment.glsl b/line.fragment.glsl index 999834cd4bd..3578f9bfadd 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,7 +1,7 @@ precision mediump float; uniform vec2 u_linewidth; -uniform vec4 u_color; +uniform lowp vec4 u_color; uniform float u_blur; varying vec2 v_normal; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 0e00dc12d40..c3186be4c53 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -18,7 +18,7 @@ attribute vec4 a_data; uniform highp mat4 u_matrix; uniform float u_ratio; uniform vec2 u_linewidth; -uniform vec4 u_color; +uniform lowp vec4 u_color; uniform float u_extra; uniform mat2 u_antialiasingmatrix; uniform float u_offset; diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index 4fc1b949774..c79cd02a946 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,7 +1,7 @@ precision mediump float; uniform vec2 u_linewidth; -uniform vec4 u_color; +uniform lowp vec4 u_color; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; diff --git a/outline.fragment.glsl b/outline.fragment.glsl index f7e5fda9a38..f4dec896174 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -1,6 +1,6 @@ precision mediump float; -uniform vec4 u_color; +uniform lowp vec4 u_color; varying vec2 v_pos; diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index 30b5a2272a7..fb108725d74 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,7 +1,7 @@ precision mediump float; uniform sampler2D u_texture; -uniform vec4 u_color; +uniform lowp vec4 u_color; uniform float u_buffer; uniform float u_gamma; From 93c8afaa95074af117d717c174e3bcec42e31511 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 11 Feb 2016 13:04:54 -0800 Subject: [PATCH 185/259] Change default vertex shader precision to highp --- circle.vertex.glsl | 4 ++-- collisionbox.vertex.glsl | 4 ++-- debug.vertex.glsl | 4 ++-- fill.vertex.glsl | 4 ++-- icon.vertex.glsl | 4 ++-- line.vertex.glsl | 4 ++-- linepattern.vertex.glsl | 4 ++-- linesdfpattern.vertex.glsl | 4 ++-- outline.vertex.glsl | 4 ++-- pattern.vertex.glsl | 4 ++-- raster.vertex.glsl | 4 ++-- sdf.vertex.glsl | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 145ebc61a56..002bd97bd2c 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -1,11 +1,11 @@ -precision mediump float; +precision highp float; // set by gl_util uniform float u_size; attribute vec2 a_pos; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; varying vec2 v_extrude; diff --git a/collisionbox.vertex.glsl b/collisionbox.vertex.glsl index cf45740f553..dba9fe320b1 100644 --- a/collisionbox.vertex.glsl +++ b/collisionbox.vertex.glsl @@ -1,10 +1,10 @@ -precision mediump float; +precision highp float; attribute vec2 a_pos; attribute vec2 a_extrude; attribute vec2 a_data; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform float u_scale; varying float v_max_zoom; diff --git a/debug.vertex.glsl b/debug.vertex.glsl index 46f4d13ff43..4f3dbf2f01f 100644 --- a/debug.vertex.glsl +++ b/debug.vertex.glsl @@ -1,8 +1,8 @@ -precision mediump float; +precision highp float; attribute vec2 a_pos; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, step(32767.0, a_pos.x), 1); diff --git a/fill.vertex.glsl b/fill.vertex.glsl index e5d78c0911f..c393d2f30ea 100644 --- a/fill.vertex.glsl +++ b/fill.vertex.glsl @@ -1,7 +1,7 @@ -precision mediump float; +precision highp float; attribute vec2 a_pos; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 1ecaf076087..bae8dd252b2 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -1,4 +1,4 @@ -precision mediump float; +precision highp float; attribute vec2 a_pos; attribute vec2 a_offset; @@ -8,7 +8,7 @@ attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; uniform float u_fadedist; diff --git a/line.vertex.glsl b/line.vertex.glsl index 4c36e0c13bb..3936cfc98a9 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -1,4 +1,4 @@ -precision mediump float; +precision highp float; // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is @@ -11,7 +11,7 @@ precision mediump float; attribute vec2 a_pos; attribute vec4 a_data; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform float u_ratio; uniform vec2 u_linewidth; uniform float u_extra; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index c3186be4c53..ab5ee31aca8 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -1,4 +1,4 @@ -precision mediump float; +precision highp float; // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is @@ -15,7 +15,7 @@ precision mediump float; attribute vec2 a_pos; attribute vec4 a_data; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform float u_ratio; uniform vec2 u_linewidth; uniform lowp vec4 u_color; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index b7fc6f76a0b..7d6943bacbf 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -1,4 +1,4 @@ -precision mediump float; +precision highp float; // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is @@ -15,7 +15,7 @@ precision mediump float; attribute vec2 a_pos; attribute vec4 a_data; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform vec2 u_linewidth; uniform float u_ratio; uniform vec2 u_patternscale_a; diff --git a/outline.vertex.glsl b/outline.vertex.glsl index 6c00cd9bb9a..57e1282f28f 100644 --- a/outline.vertex.glsl +++ b/outline.vertex.glsl @@ -1,8 +1,8 @@ -precision mediump float; +precision highp float; attribute vec2 a_pos; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform vec2 u_world; varying vec2 v_pos; diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 7af9976c9d6..fe048f6d840 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,6 +1,6 @@ -precision mediump float; +precision highp float; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform vec2 u_patternscale_a; uniform vec2 u_patternscale_b; uniform vec2 u_offset_a; diff --git a/raster.vertex.glsl b/raster.vertex.glsl index 3da31aef3dd..ce0fcd449a8 100644 --- a/raster.vertex.glsl +++ b/raster.vertex.glsl @@ -1,6 +1,6 @@ -precision mediump float; +precision highp float; -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; uniform float u_buffer_scale; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 486d063a1e8..7c0603f88cb 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -1,4 +1,4 @@ -precision mediump float; +precision highp float; attribute vec2 a_pos; attribute vec2 a_offset; @@ -8,7 +8,7 @@ attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. -uniform highp mat4 u_matrix; +uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; From fe4ec7ff44c28553c3017bd61baff9b8c7b1feb9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 22 Feb 2016 15:25:55 -0800 Subject: [PATCH 186/259] fix uniforms with same name but different precision --- circle.vertex.glsl | 8 +++----- line.vertex.glsl | 2 +- linepattern.vertex.glsl | 3 +-- linesdfpattern.vertex.glsl | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 002bd97bd2c..59f4bb24adf 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -1,12 +1,10 @@ precision highp float; -// set by gl_util -uniform float u_size; - -attribute vec2 a_pos; - uniform mat4 u_matrix; uniform mat4 u_exmatrix; +uniform mediump float u_size; + +attribute vec2 a_pos; varying vec2 v_extrude; diff --git a/line.vertex.glsl b/line.vertex.glsl index 3936cfc98a9..8176a995576 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -13,7 +13,7 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform float u_ratio; -uniform vec2 u_linewidth; +uniform mediump vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; uniform float u_offset; diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index ab5ee31aca8..2c2e7a5c2a9 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -17,8 +17,7 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform float u_ratio; -uniform vec2 u_linewidth; -uniform lowp vec4 u_color; +uniform mediump vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; uniform float u_offset; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 7d6943bacbf..1b32c6e0263 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -16,7 +16,7 @@ attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; -uniform vec2 u_linewidth; +uniform mediump vec2 u_linewidth; uniform float u_ratio; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; From b89680d457985430cb48b99de550d72b91c34d1a Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 22 Feb 2016 16:55:09 -0800 Subject: [PATCH 187/259] add more precision qualifiers --- circle.fragment.glsl | 3 +-- icon.vertex.glsl | 24 ++++++++++++------------ line.vertex.glsl | 12 ++++++------ linepattern.vertex.glsl | 16 ++++++++-------- linesdfpattern.vertex.glsl | 14 +++++++------- sdf.fragment.glsl | 10 +++++----- sdf.vertex.glsl | 22 +++++++++++----------- 7 files changed, 50 insertions(+), 51 deletions(-) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 4427d64c65c..97e0348c43d 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -1,8 +1,7 @@ precision mediump float; uniform lowp vec4 u_color; -uniform float u_blur; -uniform float u_size; +uniform lowp float u_blur; varying vec2 v_extrude; diff --git a/icon.vertex.glsl b/icon.vertex.glsl index bae8dd252b2..948c6babf11 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -10,12 +10,12 @@ attribute vec4 a_data2; // the extrusion vector. uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform float u_zoom; -uniform float u_fadedist; -uniform float u_minfadezoom; -uniform float u_maxfadezoom; -uniform float u_fadezoom; -uniform float u_opacity; +uniform mediump float u_zoom; +uniform mediump float u_fadedist; +uniform mediump float u_minfadezoom; +uniform mediump float u_maxfadezoom; +uniform mediump float u_fadezoom; +uniform lowp float u_opacity; uniform bool u_skewed; uniform float u_extra; @@ -26,18 +26,18 @@ varying float v_alpha; void main() { vec2 a_tex = a_data1.xy; - float a_labelminzoom = a_data1[2]; - vec2 a_zoom = a_data2.st; - float a_minzoom = a_zoom[0]; - float a_maxzoom = a_zoom[1]; + mediump float a_labelminzoom = a_data1[2]; + mediump vec2 a_zoom = a_data2.st; + mediump float a_minzoom = a_zoom[0]; + mediump float a_maxzoom = a_zoom[1]; float a_fadedist = 10.0; // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); + mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); // fade out labels - float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); + mediump float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); if (u_fadedist >= 0.0) { v_alpha = alpha; diff --git a/line.vertex.glsl b/line.vertex.glsl index 8176a995576..d4b7697610e 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -16,7 +16,7 @@ uniform float u_ratio; uniform mediump vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; -uniform float u_offset; +uniform mediump float u_offset; varying vec2 v_normal; varying float v_linesofar; @@ -30,21 +30,21 @@ void main() { // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = mod(a_pos, 2.0); normal.y = sign(normal.y - 0.5); v_normal = normal; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + mediump vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate // it when we're drawing round end points (a_direction = -1 or 1) since their // extrude vector points in another direction. - float u = 0.5 * a_direction; - float t = 1.0 - abs(u); - vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + mediump float u = 0.5 * a_direction; + mediump float t = 1.0 - abs(u); + mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 2c2e7a5c2a9..907049a5672 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -16,11 +16,11 @@ attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; -uniform float u_ratio; +uniform mediump float u_ratio; uniform mediump vec2 u_linewidth; uniform float u_extra; uniform mat2 u_antialiasingmatrix; -uniform float u_offset; +uniform mediump float u_offset; varying vec2 v_normal; varying float v_linesofar; @@ -35,22 +35,22 @@ void main() { // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = mod(a_pos, 2.0); normal.y = sign(normal.y - 0.5); v_normal = normal; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec2 extrude = a_extrude * scale; - vec2 dist = u_linewidth.s * extrude; + mediump vec2 extrude = a_extrude * scale; + mediump vec2 dist = u_linewidth.s * extrude; // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate // it when we're drawing round end points (a_direction = -1 or 1) since their // extrude vector points in another direction. - float u = 0.5 * a_direction; - float t = 1.0 - abs(u); - vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + mediump float u = 0.5 * a_direction; + mediump float t = 1.0 - abs(u); + mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index 1b32c6e0263..f5650aacda7 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -17,14 +17,14 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump vec2 u_linewidth; -uniform float u_ratio; +uniform mediump float u_ratio; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; uniform float u_extra; uniform mat2 u_antialiasingmatrix; -uniform float u_offset; +uniform mediump float u_offset; varying vec2 v_normal; varying vec2 v_tex_a; @@ -40,21 +40,21 @@ void main() { // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = mod(a_pos, 2.0); normal.y = sign(normal.y - 0.5); v_normal = normal; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + mediump vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate // it when we're drawing round end points (a_direction = -1 or 1) since their // extrude vector points in another direction. - float u = 0.5 * a_direction; - float t = 1.0 - abs(u); - vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + mediump float u = 0.5 * a_direction; + mediump float t = 1.0 - abs(u); + mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index fb108725d74..c3b3061d747 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -2,16 +2,16 @@ precision mediump float; uniform sampler2D u_texture; uniform lowp vec4 u_color; -uniform float u_buffer; -uniform float u_gamma; +uniform lowp float u_buffer; +uniform lowp float u_gamma; varying vec2 v_tex; varying float v_alpha; varying float v_gamma_scale; void main() { - float gamma = u_gamma * v_gamma_scale; - float dist = texture2D(u_texture, v_tex).a; - float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; + lowp float gamma = u_gamma * v_gamma_scale; + lowp float dist = texture2D(u_texture, v_tex).a; + lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 7c0603f88cb..cad5d3b4e84 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -11,11 +11,11 @@ attribute vec4 a_data2; uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform float u_zoom; -uniform float u_fadedist; -uniform float u_minfadezoom; -uniform float u_maxfadezoom; -uniform float u_fadezoom; +uniform mediump float u_zoom; +uniform mediump float u_fadedist; +uniform mediump float u_minfadezoom; +uniform mediump float u_maxfadezoom; +uniform mediump float u_fadezoom; uniform bool u_skewed; uniform float u_extra; @@ -27,16 +27,16 @@ varying float v_gamma_scale; void main() { vec2 a_tex = a_data1.xy; - float a_labelminzoom = a_data1[2]; - vec2 a_zoom = a_data2.st; - float a_minzoom = a_zoom[0]; - float a_maxzoom = a_zoom[1]; + mediump float a_labelminzoom = a_data1[2]; + mediump vec2 a_zoom = a_data2.st; + mediump float a_minzoom = a_zoom[0]; + mediump float a_maxzoom = a_zoom[1]; // u_zoom is the current zoom level adjusted for the change in font size - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); + mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); // fade out labels - float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); + mediump float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); if (u_fadedist >= 0.0) { v_alpha = alpha; From 3028218a8fd486701172170b2c38823eb81f9d87 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 28 Mar 2016 11:57:45 -0700 Subject: [PATCH 188/259] [core] fix background-pattern rendering in perspective view fix #3801 --- pattern.vertex.glsl | 8 ++++---- pattern_shader.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 4ff51cad647..1363f173002 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,6 +1,6 @@ uniform mat4 u_matrix; -uniform mat3 u_patternmatrix_a; -uniform mat3 u_patternmatrix_b; +uniform vec2 u_patternscale_a; +uniform vec2 u_patternscale_b; uniform vec2 u_offset_a; uniform vec2 u_offset_b; @@ -12,6 +12,6 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy + u_offset_a; - v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy + u_offset_b; + v_pos_a = u_patternscale_a * a_pos + u_offset_a; + v_pos_b = u_patternscale_b * a_pos + u_offset_b; } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 8692f6ed399..0898dc0b8cd 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -20,8 +20,8 @@ class PatternShader : public Shader { Uniform u_opacity = {"u_opacity", *this}; Uniform u_mix = {"u_mix", *this}; Uniform u_image = {"u_image", *this}; - UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; - UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; + Uniform> u_patternscale_a = {"u_patternscale_a", *this}; + Uniform> u_patternscale_b = {"u_patternscale_b", *this}; Uniform> u_offset_a = {"u_offset_a", *this}; Uniform> u_offset_b = {"u_offset_b", *this}; }; From b4f12c0b10b9c5413f38cfed63e0b1f7186c7c40 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 28 Mar 2016 16:35:49 -0700 Subject: [PATCH 189/259] [core] reset line distance when it is near max port https://github.com/mapbox/mapbox-gl-js/commit/77ce4b45b24e8a0ed1bb739da436d19415c7e5e4 fix #4492 --- linepattern.vertex.glsl | 6 +++++- linesdf.vertex.glsl | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 5b3c468be0c..6fa499106c8 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -6,6 +6,10 @@ // #define scale 63.0 #define scale 0.015873016 +// We scale the distance before adding it to the buffers so that we can store +// long distances for long segments. Use this value to unscale the distance. +#define LINE_DISTANCE_SCALE 2.0 + attribute vec2 a_pos; attribute vec4 a_data; @@ -30,7 +34,7 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; + float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl index 80516f97c00..f24d8399b82 100644 --- a/linesdf.vertex.glsl +++ b/linesdf.vertex.glsl @@ -6,6 +6,10 @@ // #define scale 63.0 #define scale 0.015873016 +// We scale the distance before adding it to the buffers so that we can store +// long distances for long segments. Use this value to unscale the distance. +#define LINE_DISTANCE_SCALE 2.0 + attribute vec2 a_pos; attribute vec4 a_data; @@ -34,7 +38,7 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; + float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 From bd14719b432d0861c157b7bcbaaa37e0a1ded7d0 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 28 Mar 2016 16:58:54 -0700 Subject: [PATCH 190/259] [core] pack extrude and line distance into unsigned byte instead of a signed byte. It's a bit easier to understand. https://github.com/mapbox/mapbox-gl-js/commit/6c29251b3572ce9f2afae8182b56da6c1b9838b4 --- line.vertex.glsl | 4 ++-- line_shader.cpp | 2 +- linepattern.vertex.glsl | 6 +++--- linepattern_shader.cpp | 2 +- linesdf.vertex.glsl | 6 +++--- linesdf_shader.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/line.vertex.glsl b/line.vertex.glsl index 1bd7f5ef5f4..973e92a17d7 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -23,8 +23,8 @@ varying vec2 v_normal; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/line_shader.cpp b/line_shader.cpp index e4df0531d8b..c54b3312d82 100644 --- a/line_shader.cpp +++ b/line_shader.cpp @@ -17,5 +17,5 @@ void LineShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); } diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 6fa499106c8..5cceb64038b 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -32,9 +32,9 @@ varying float v_linesofar; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; + float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp index 7acd42f727a..40f64ed139c 100644 --- a/linepattern_shader.cpp +++ b/linepattern_shader.cpp @@ -17,5 +17,5 @@ void LinepatternShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); } diff --git a/linesdf.vertex.glsl b/linesdf.vertex.glsl index f24d8399b82..9174e4d9876 100644 --- a/linesdf.vertex.glsl +++ b/linesdf.vertex.glsl @@ -36,9 +36,9 @@ varying vec2 v_tex_b; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; + float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp index 00adaf0c867..13581279251 100644 --- a/linesdf_shader.cpp +++ b/linesdf_shader.cpp @@ -17,5 +17,5 @@ void LineSDFShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); } From 5cf05434dce8e7f957ffaa734ef00a521138a191 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 28 Mar 2016 11:57:45 -0700 Subject: [PATCH 191/259] [core] fix background-pattern rendering in perspective view fix #3801 --- pattern.vertex.glsl | 8 ++++---- pattern_shader.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index 4ff51cad647..1363f173002 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,6 +1,6 @@ uniform mat4 u_matrix; -uniform mat3 u_patternmatrix_a; -uniform mat3 u_patternmatrix_b; +uniform vec2 u_patternscale_a; +uniform vec2 u_patternscale_b; uniform vec2 u_offset_a; uniform vec2 u_offset_b; @@ -12,6 +12,6 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy + u_offset_a; - v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy + u_offset_b; + v_pos_a = u_patternscale_a * a_pos + u_offset_a; + v_pos_b = u_patternscale_b * a_pos + u_offset_b; } diff --git a/pattern_shader.hpp b/pattern_shader.hpp index 8692f6ed399..0898dc0b8cd 100644 --- a/pattern_shader.hpp +++ b/pattern_shader.hpp @@ -20,8 +20,8 @@ class PatternShader : public Shader { Uniform u_opacity = {"u_opacity", *this}; Uniform u_mix = {"u_mix", *this}; Uniform u_image = {"u_image", *this}; - UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; - UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; + Uniform> u_patternscale_a = {"u_patternscale_a", *this}; + Uniform> u_patternscale_b = {"u_patternscale_b", *this}; Uniform> u_offset_a = {"u_offset_a", *this}; Uniform> u_offset_b = {"u_offset_b", *this}; }; From be4700279de8472f643667534708e4309c4a8604 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 31 Mar 2016 14:33:37 -0700 Subject: [PATCH 192/259] better symbol fading with texture lookups - this is simpler than prediction opacity based on current zooming speed - this is smoother: Symbols don't flicker when changing zoom speed or zooming in and out rapidly. fix #590 --- icon.fragment.glsl | 7 +++++-- icon.vertex.glsl | 28 ++-------------------------- sdf.fragment.glsl | 8 +++++--- sdf.vertex.glsl | 25 ++----------------------- 4 files changed, 14 insertions(+), 54 deletions(-) diff --git a/icon.fragment.glsl b/icon.fragment.glsl index 509695dccb1..f1ae5e078ad 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -1,10 +1,13 @@ precision mediump float; uniform sampler2D u_texture; +uniform sampler2D u_fadetexture; +uniform lowp float u_opacity; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; void main() { - gl_FragColor = texture2D(u_texture, v_tex) * v_alpha; + lowp float alpha = texture2D(u_fadetexture, v_fade_tex).a * u_opacity; + gl_FragColor = texture2D(u_texture, v_tex) * alpha; } diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 948c6babf11..ffc40f7115d 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -11,18 +11,13 @@ attribute vec4 a_data2; uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform mediump float u_zoom; -uniform mediump float u_fadedist; -uniform mediump float u_minfadezoom; -uniform mediump float u_maxfadezoom; -uniform mediump float u_fadezoom; -uniform lowp float u_opacity; uniform bool u_skewed; uniform float u_extra; uniform vec2 u_texsize; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; void main() { vec2 a_tex = a_data1.xy; @@ -36,24 +31,6 @@ void main() { // u_zoom is the current zoom level adjusted for the change in font size mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); - // fade out labels - mediump float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); - - if (u_fadedist >= 0.0) { - v_alpha = alpha; - } else { - v_alpha = 1.0 - alpha; - } - if (u_maxfadezoom < a_labelminzoom) { - v_alpha = 0.0; - } - if (u_minfadezoom >= a_labelminzoom) { - v_alpha = 1.0; - } - - // if label has been faded out, clip it - z += step(v_alpha, 0.0); - if (u_skewed) { vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); @@ -64,6 +41,5 @@ void main() { } v_tex = a_tex / u_texsize; - - v_alpha *= u_opacity; + v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0); } diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index c3b3061d747..43c406dcda0 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,17 +1,19 @@ precision mediump float; uniform sampler2D u_texture; +uniform sampler2D u_fadetexture; uniform lowp vec4 u_color; uniform lowp float u_buffer; uniform lowp float u_gamma; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; varying float v_gamma_scale; void main() { - lowp float gamma = u_gamma * v_gamma_scale; lowp float dist = texture2D(u_texture, v_tex).a; - lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; + lowp float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a; + lowp float gamma = u_gamma * v_gamma_scale; + lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index cad5d3b4e84..4e5ddcd59f0 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -12,17 +12,13 @@ uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform mediump float u_zoom; -uniform mediump float u_fadedist; -uniform mediump float u_minfadezoom; -uniform mediump float u_maxfadezoom; -uniform mediump float u_fadezoom; uniform bool u_skewed; uniform float u_extra; uniform vec2 u_texsize; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; varying float v_gamma_scale; void main() { @@ -35,24 +31,6 @@ void main() { // u_zoom is the current zoom level adjusted for the change in font size mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); - // fade out labels - mediump float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); - - if (u_fadedist >= 0.0) { - v_alpha = alpha; - } else { - v_alpha = 1.0 - alpha; - } - if (u_maxfadezoom < a_labelminzoom) { - v_alpha = 0.0; - } - if (u_minfadezoom >= a_labelminzoom) { - v_alpha = 1.0; - } - - // if label has been faded out, clip it - z += step(v_alpha, 0.0); - if (u_skewed) { vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); @@ -69,4 +47,5 @@ void main() { v_gamma_scale = perspective_scale; v_tex = a_tex / u_texsize; + v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0); } From 001bf07de13a26d77e69f64c566d4e88038a7bcc Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Wed, 30 Mar 2016 18:49:57 -0700 Subject: [PATCH 193/259] fix anti-aliasing for fill-patterns update package.json with new test-suite sha, rename imageOffset -> setPattern include distance interpolation for opacity fix linting tests refactor image offset calculations use distance from line to calculate alpha, change to multiplication for combining u_opacity and alpha add u_world to use_program for outline pattern, refactor using new imageOffset function refactor draw_fill, fix conditionals --- outlinepattern.fragment.glsl | 32 ++++++++++++++++++++++++++++++++ outlinepattern.vertex.glsl | 23 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 outlinepattern.fragment.glsl create mode 100644 outlinepattern.vertex.glsl diff --git a/outlinepattern.fragment.glsl b/outlinepattern.fragment.glsl new file mode 100644 index 00000000000..70c174f237e --- /dev/null +++ b/outlinepattern.fragment.glsl @@ -0,0 +1,32 @@ +precision mediump float; + +uniform float u_opacity; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; +uniform float u_mix; + +uniform sampler2D u_image; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec2 v_pos; + +void main() { + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); + vec4 color1 = texture2D(u_image, pos); + + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); + vec4 color2 = texture2D(u_image, pos2); + + // find distance to outline for alpha interpolation + + float dist = length(v_pos - gl_FragCoord.xy); + float alpha = smoothstep(1.0, 0.0, dist); + + + gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; +} diff --git a/outlinepattern.vertex.glsl b/outlinepattern.vertex.glsl new file mode 100644 index 00000000000..1a3973cfc5e --- /dev/null +++ b/outlinepattern.vertex.glsl @@ -0,0 +1,23 @@ +precision highp float; + +uniform vec2 u_patternscale_a; +uniform vec2 u_patternscale_b; +uniform vec2 u_offset_a; +uniform vec2 u_offset_b; + +attribute vec2 a_pos; + +uniform mat4 u_matrix; +uniform vec2 u_world; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec2 v_pos; + + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + v_pos_a = u_patternscale_a * a_pos + u_offset_a; + v_pos_b = u_patternscale_b * a_pos + u_offset_b; + v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; +} From ab15c1eced0ad961c88e8c01ddc950066e003709 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 6 Jan 2016 10:24:30 -0800 Subject: [PATCH 194/259] Attribute-ify circle shaders --- circle.fragment.glsl | 4 ++-- circle.vertex.glsl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 97e0348c43d..4874a024abc 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -1,11 +1,11 @@ precision mediump float; -uniform lowp vec4 u_color; uniform lowp float u_blur; +varying lowp vec4 v_color; 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); + gl_FragColor = v_color * (1.0 - t); } diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 59f4bb24adf..8ae53c97de3 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -5,8 +5,10 @@ uniform mat4 u_exmatrix; uniform mediump float u_size; attribute vec2 a_pos; +attribute lowp vec4 a_color; varying vec2 v_extrude; +varying lowp vec4 v_color; void main(void) { // unencode the extrusion vector that we snuck into the a_pos vector @@ -20,4 +22,6 @@ void main(void) { // 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; + + v_color = a_color / 255.0; } From fd5169364c51f41fb5680c567cb629b57a711cc0 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 30 Mar 2016 16:11:19 -0700 Subject: [PATCH 195/259] Allow token replacement in shaders --- circle.vertex.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 8ae53c97de3..d47bb493d62 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -5,7 +5,8 @@ uniform mat4 u_exmatrix; uniform mediump float u_size; attribute vec2 a_pos; -attribute lowp vec4 a_color; + +{{colorType}} lowp vec4 a_color; varying vec2 v_extrude; varying lowp vec4 v_color; From 714881ab247be3eefc8b67557d52da878aa18778 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Sat, 9 Apr 2016 12:46:14 -0700 Subject: [PATCH 196/259] use glsl macros instead of custom templating Using macros and preprocessor directives is the glsl way of doing this. After this the .glsl files are now valid glsl. I think it's clearer to have both variations explicitly written in glsl than having string replacement. --- circle.vertex.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index d47bb493d62..906cd8cb219 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -6,7 +6,11 @@ uniform mediump float u_size; attribute vec2 a_pos; -{{colorType}} lowp vec4 a_color; +#ifdef ATTRIBUTE_COLOR +attribute lowp vec4 a_color; +#else +uniform lowp vec4 a_color; +#endif varying vec2 v_extrude; varying lowp vec4 v_color; From 4356e41fa657837904d189e604468617ee601ddb Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 11 Apr 2016 14:58:18 -0700 Subject: [PATCH 197/259] Enabled data-driven styling for circle-radius --- circle.fragment.glsl | 3 ++- circle.vertex.glsl | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 4874a024abc..1d9936199e3 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -4,8 +4,9 @@ uniform lowp float u_blur; varying lowp vec4 v_color; varying vec2 v_extrude; +varying lowp float v_antialiasblur; void main() { - float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude)); + float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = v_color * (1.0 - t); } diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 906cd8cb219..a0457fc293a 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -2,7 +2,7 @@ precision highp float; uniform mat4 u_matrix; uniform mat4 u_exmatrix; -uniform mediump float u_size; +uniform float u_devicepixelratio; attribute vec2 a_pos; @@ -12,14 +12,21 @@ attribute lowp vec4 a_color; uniform lowp vec4 a_color; #endif +#ifdef ATTRIBUTE_RADIUS +attribute mediump float a_radius; +#else +uniform mediump float a_radius; +#endif + varying vec2 v_extrude; varying lowp vec4 v_color; +varying lowp float v_antialiasblur; 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); + vec4 extrude = u_exmatrix * vec4(v_extrude * a_radius / 10.0, 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(floor(a_pos * 0.5), 0, 1); @@ -29,4 +36,9 @@ void main(void) { gl_Position += extrude * gl_Position.w; v_color = a_color / 255.0; + + // 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. + v_antialiasblur = 1.0 / u_devicepixelratio / (a_radius / 10.0); } From a09dee9e1c95545468f3fc92b1fd5ec6c1fafeaa Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 8 Apr 2016 20:51:04 -0700 Subject: [PATCH 198/259] disable attributes based on their paint property This replaces a per-attribute `isDisabled` function with paint property key. All data-driven attributes must now depend on only a single paint property. The `a_color` attribute used to depend on both the `circle-color` and `circle-opacity` paint properties. This splits them up into two attributes/uniforms, each of which only depends on one paint property. I think it will be simpler to have all attributes be based on a single style property. We will need to split up: - a_color, which depends on -color and -opacity - u_linewidth, which depends on line-width and line-width-gap --- circle.fragment.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 1d9936199e3..581f2e716f0 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -1,6 +1,7 @@ precision mediump float; uniform lowp float u_blur; +uniform lowp float u_opacity; varying lowp vec4 v_color; varying vec2 v_extrude; @@ -8,5 +9,5 @@ varying lowp float v_antialiasblur; void main() { float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); - gl_FragColor = v_color * (1.0 - t); + gl_FragColor = v_color * (1.0 - t) * u_opacity; } From 0d3412519618a3a1672db9fa21f96f90070cf84c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 11 Apr 2016 14:31:48 -0700 Subject: [PATCH 199/259] separate u_opacity from u_color This prepares the shaders for the switch to data driven styling where opacity and color need to be passed to the shader independent of eachotehr. remove the `additionalOpacity` parameter from `util.premultiply` --- fill.fragment.glsl | 3 ++- line.fragment.glsl | 3 ++- linesdfpattern.fragment.glsl | 3 ++- outline.fragment.glsl | 3 ++- sdf.fragment.glsl | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fill.fragment.glsl b/fill.fragment.glsl index e8cc2e202aa..87101ecedd4 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -1,7 +1,8 @@ precision mediump float; uniform lowp vec4 u_color; +uniform lowp float u_opacity; void main() { - gl_FragColor = u_color; + gl_FragColor = u_color * u_opacity; } diff --git a/line.fragment.glsl b/line.fragment.glsl index 3578f9bfadd..f0ff35b247f 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -2,6 +2,7 @@ precision mediump float; uniform vec2 u_linewidth; uniform lowp vec4 u_color; +uniform lowp float u_opacity; uniform float u_blur; varying vec2 v_normal; @@ -18,5 +19,5 @@ void main() { float blur = u_blur * v_gamma_scale; float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); - gl_FragColor = u_color * alpha; + gl_FragColor = u_color * (alpha * u_opacity); } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index c79cd02a946..5548d21fba1 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -2,6 +2,7 @@ precision mediump float; uniform vec2 u_linewidth; uniform lowp vec4 u_color; +uniform lowp float u_opacity; uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; @@ -27,5 +28,5 @@ void main() { float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); - gl_FragColor = u_color * alpha; + gl_FragColor = u_color * (alpha * u_opacity); } diff --git a/outline.fragment.glsl b/outline.fragment.glsl index f4dec896174..344014dcaa3 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -1,11 +1,12 @@ precision mediump float; uniform lowp vec4 u_color; +uniform lowp float u_opacity; varying vec2 v_pos; void main() { float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); - gl_FragColor = u_color * alpha; + gl_FragColor = u_color * (alpha * u_opacity); } diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index 43c406dcda0..a9e7e1234a1 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -3,6 +3,7 @@ precision mediump float; uniform sampler2D u_texture; uniform sampler2D u_fadetexture; uniform lowp vec4 u_color; +uniform lowp float u_opacity; uniform lowp float u_buffer; uniform lowp float u_gamma; @@ -15,5 +16,5 @@ void main() { lowp float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a; lowp float gamma = u_gamma * v_gamma_scale; lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; - gl_FragColor = u_color * alpha; + gl_FragColor = u_color * (alpha * u_opacity); } From 396b9c3874f0e134b17c8c7fac241af84016f253 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 11 Apr 2016 16:44:23 -0700 Subject: [PATCH 200/259] use function instead of string of code for getValue A function of the layer, globalProperties, featureProperties is simpler than a string of code that gets joined into a function. This separates the vertex push method for core attributes from the push methods for data-driven attributes. This will let us: - use a regular function for adding core attributes to buffers - and either: - generate a separate method for data driven attributes - or optimize adding attributes without code generation Data driven properties need to be evaluated once per feature, not once per vertex. This means we can evaluate them outside the main vertex loop and then add the same value for every vertex. The hot loop for lines, fills and symbols will be: for (var i = startIndex; i < endIndex; i++) { ... } If it's too slow in the current implementation we could add new StructArray methods for setting a single value for a range of elements. If we need to generate code it would be nice to contain that to StructArray. --- circle.vertex.glsl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index a0457fc293a..99b2c885f44 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -23,10 +23,17 @@ varying lowp vec4 v_color; varying lowp float v_antialiasblur; void main(void) { + +#ifdef ATTRIBUTE_RADIUS + mediump float radius = a_radius / 10.0; +#else + mediump float radius = a_radius; +#endif + // 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 * a_radius / 10.0, 0, 0); + vec4 extrude = u_exmatrix * vec4(v_extrude * radius, 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(floor(a_pos * 0.5), 0, 1); @@ -35,10 +42,14 @@ void main(void) { // Multiply the extrude by it so that it isn't affected by it. gl_Position += extrude * gl_Position.w; +#ifdef ATTRIBUTE_COLOR v_color = a_color / 255.0; +#else + v_color = a_color; +#endif // 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. - v_antialiasblur = 1.0 / u_devicepixelratio / (a_radius / 10.0); + v_antialiasblur = 1.0 / u_devicepixelratio / radius; } From 3ccca643ddd1365a1343e47e13161c0c215853bf Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 11 Apr 2016 23:00:39 -0700 Subject: [PATCH 201/259] split paint attributes into a separate buffer - avoids the need to namespace attribute names with string concatenation - this let's us use attribute.name as the shader attribute name - this will let us use instanced rendering (#1898) with a shorter buffer when that extension is available. --- circle.vertex.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 99b2c885f44..f607f3a6940 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -6,13 +6,13 @@ uniform float u_devicepixelratio; attribute vec2 a_pos; -#ifdef ATTRIBUTE_COLOR +#ifdef ATTRIBUTE_A_COLOR attribute lowp vec4 a_color; #else uniform lowp vec4 a_color; #endif -#ifdef ATTRIBUTE_RADIUS +#ifdef ATTRIBUTE_A_RADIUS attribute mediump float a_radius; #else uniform mediump float a_radius; @@ -24,7 +24,7 @@ varying lowp float v_antialiasblur; void main(void) { -#ifdef ATTRIBUTE_RADIUS +#ifdef ATTRIBUTE_A_RADIUS mediump float radius = a_radius / 10.0; #else mediump float radius = a_radius; @@ -42,7 +42,7 @@ void main(void) { // Multiply the extrude by it so that it isn't affected by it. gl_Position += extrude * gl_Position.w; -#ifdef ATTRIBUTE_COLOR +#ifdef ATTRIBUTE_A_COLOR v_color = a_color / 255.0; #else v_color = a_color; From b620bc2f0a01daef8ebe6dcef276133993498f68 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 1 Apr 2016 17:23:46 -0700 Subject: [PATCH 202/259] [core] always set activeTexture before binding a texture --- linepattern_shader.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp index 0d3e98c8341..cbab2f9c4c5 100644 --- a/linepattern_shader.hpp +++ b/linepattern_shader.hpp @@ -28,6 +28,7 @@ class LinepatternShader : public Shader { Uniform u_opacity = {"u_opacity", *this}; Uniform u_extra = {"u_extra", *this}; Uniform u_offset = {"u_offset", *this}; + Uniform u_image = {"u_image", *this}; UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; private: From 80614f9b2a1a1650cc9ffa470af49a5dcaa51a33 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 13 Apr 2016 18:14:34 -0700 Subject: [PATCH 203/259] implement zoom and data driven functions --- circle.vertex.glsl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index f607f3a6940..e05b5c4ef7d 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -8,12 +8,21 @@ attribute vec2 a_pos; #ifdef ATTRIBUTE_A_COLOR attribute lowp vec4 a_color; +#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_COLOR0 +uniform lowp float u_color_t; +attribute lowp vec4 a_color0; +attribute lowp vec4 a_color1; +attribute lowp vec4 a_color2; +attribute lowp vec4 a_color3; #else uniform lowp vec4 a_color; #endif #ifdef ATTRIBUTE_A_RADIUS attribute mediump float a_radius; +#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_RADIUS +uniform lowp float u_radius_t; +attribute mediump vec4 a_radius; #else uniform mediump float a_radius; #endif @@ -22,10 +31,32 @@ varying vec2 v_extrude; varying lowp vec4 v_color; varying lowp float v_antialiasblur; +float evaluate_zoom_function_1(const vec4 values, const float t) { + if (t < 1.0) { + return mix(values[0], values[1], t); + } else if (t < 2.0) { + return mix(values[1], values[2], t - 1.0); + } else { + return mix(values[2], values[3], t - 2.0); + } +} + +vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { + if (t < 1.0) { + return mix(value0, value1, t); + } else if (t < 2.0) { + return mix(value1, value2, t - 1.0); + } else { + return mix(value2, value3, t - 2.0); + } +} + void main(void) { #ifdef ATTRIBUTE_A_RADIUS mediump float radius = a_radius / 10.0; +#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_RADIUS + mediump float radius = evaluate_zoom_function_1(a_radius, u_radius_t) / 10.0; #else mediump float radius = a_radius; #endif @@ -44,6 +75,8 @@ void main(void) { #ifdef ATTRIBUTE_A_COLOR v_color = a_color / 255.0; +#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_COLOR0 + v_color = evaluate_zoom_function_4(a_color0, a_color1, a_color2, a_color3, u_color_t) / 255.0; #else v_color = a_color; #endif From 847b437779ce3f2108afa24247f48b2885bbd866 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 22 Apr 2016 16:11:13 -0700 Subject: [PATCH 204/259] add an overdraw inspector The overdraw inspector shows how many time each fragment has been shaded. White fragments were shaded 8 or more times. Black fragments were shaded 0 times. Lower is better. `map.showOverdrawInspector = true` turns it on. --- circle.fragment.glsl | 4 ++++ fill.fragment.glsl | 4 ++++ icon.fragment.glsl | 4 ++++ line.fragment.glsl | 4 ++++ linepattern.fragment.glsl | 4 ++++ linesdfpattern.fragment.glsl | 4 ++++ outline.fragment.glsl | 4 ++++ outlinepattern.fragment.glsl | 4 ++++ pattern.fragment.glsl | 4 ++++ raster.fragment.glsl | 4 ++++ sdf.fragment.glsl | 4 ++++ 11 files changed, 44 insertions(+) diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 581f2e716f0..204ce85f52f 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -10,4 +10,8 @@ varying lowp float v_antialiasblur; void main() { float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = v_color * (1.0 - t) * u_opacity; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/fill.fragment.glsl b/fill.fragment.glsl index 87101ecedd4..4a5c9282f75 100644 --- a/fill.fragment.glsl +++ b/fill.fragment.glsl @@ -5,4 +5,8 @@ uniform lowp float u_opacity; void main() { gl_FragColor = u_color * u_opacity; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/icon.fragment.glsl b/icon.fragment.glsl index f1ae5e078ad..76966a00155 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -10,4 +10,8 @@ varying vec2 v_fade_tex; void main() { lowp float alpha = texture2D(u_fadetexture, v_fade_tex).a * u_opacity; gl_FragColor = texture2D(u_texture, v_tex) * alpha; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/line.fragment.glsl b/line.fragment.glsl index f0ff35b247f..44220e35fa8 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -20,4 +20,8 @@ void main() { float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = u_color * (alpha * u_opacity); + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 37a3504cc2b..2ec81174371 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -41,4 +41,8 @@ void main() { alpha *= u_opacity; gl_FragColor = color * alpha; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index 5548d21fba1..b07f08dcdd2 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -29,4 +29,8 @@ void main() { alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); gl_FragColor = u_color * (alpha * u_opacity); + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/outline.fragment.glsl b/outline.fragment.glsl index 344014dcaa3..0108221297f 100644 --- a/outline.fragment.glsl +++ b/outline.fragment.glsl @@ -9,4 +9,8 @@ void main() { float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); gl_FragColor = u_color * (alpha * u_opacity); + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/outlinepattern.fragment.glsl b/outlinepattern.fragment.glsl index 70c174f237e..36ceaacd4ea 100644 --- a/outlinepattern.fragment.glsl +++ b/outlinepattern.fragment.glsl @@ -29,4 +29,8 @@ void main() { gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/pattern.fragment.glsl b/pattern.fragment.glsl index 1bb1d5bb342..441f4eaa7dc 100644 --- a/pattern.fragment.glsl +++ b/pattern.fragment.glsl @@ -23,4 +23,8 @@ void main() { vec4 color2 = texture2D(u_image, pos2); gl_FragColor = mix(color1, color2, u_mix) * u_opacity; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/raster.fragment.glsl b/raster.fragment.glsl index 48948bac7df..0404dfb0a0d 100644 --- a/raster.fragment.glsl +++ b/raster.fragment.glsl @@ -40,4 +40,8 @@ void main() { vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); gl_FragColor = vec4(mix(u_high_vec, u_low_vec, rgb), color.a); + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index a9e7e1234a1..cac9608f319 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -17,4 +17,8 @@ void main() { lowp float gamma = u_gamma * v_gamma_scale; lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; gl_FragColor = u_color * (alpha * u_opacity); + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif } From a8d549b7a41540d3a99767975ff1b7b18a6010e9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 21 Apr 2016 17:04:20 -0700 Subject: [PATCH 205/259] convert mat4 exMatrix to a vec2 extrudeScale The matrix was only be used to scale vec2s. We don't need a mat4 to do that. This should be slightly faster --- circle.vertex.glsl | 6 +++--- icon.vertex.glsl | 12 +++++------- sdf.vertex.glsl | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index e05b5c4ef7d..5574aa28ccb 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -1,7 +1,7 @@ precision highp float; uniform mat4 u_matrix; -uniform mat4 u_exmatrix; +uniform vec2 u_extrude_scale; uniform float u_devicepixelratio; attribute vec2 a_pos; @@ -64,14 +64,14 @@ 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 * radius, 0, 0); + vec2 extrude = v_extrude * radius * u_extrude_scale; // multiply a_pos by 0.5, since we had it * 2 in order to sneak // in extrusion data gl_Position = u_matrix * vec4(floor(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; + gl_Position.xy += extrude * gl_Position.w; #ifdef ATTRIBUTE_A_COLOR v_color = a_color / 255.0; diff --git a/icon.vertex.glsl b/icon.vertex.glsl index ffc40f7115d..d324c6a37f9 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -9,10 +9,11 @@ attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. uniform mat4 u_matrix; -uniform mat4 u_exmatrix; + uniform mediump float u_zoom; uniform bool u_skewed; uniform float u_extra; +uniform vec2 u_extrude_scale; uniform vec2 u_texsize; @@ -26,18 +27,15 @@ void main() { mediump float a_minzoom = a_zoom[0]; mediump float a_maxzoom = a_zoom[1]; - float a_fadedist = 10.0; - // u_zoom is the current zoom level adjusted for the change in font size mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); + vec2 extrude = u_extrude_scale * (a_offset / 64.0); if (u_skewed) { - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); - gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); + gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1); gl_Position.z += z * gl_Position.w; } else { - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; + gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); } v_tex = a_tex / u_texsize; diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 4e5ddcd59f0..58f26ccf22d 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -9,11 +9,11 @@ attribute vec4 a_data2; // matrix is for the vertex position, exmatrix is for rotating and projecting // the extrusion vector. uniform mat4 u_matrix; -uniform mat4 u_exmatrix; uniform mediump float u_zoom; uniform bool u_skewed; uniform float u_extra; +uniform vec2 u_extrude_scale; uniform vec2 u_texsize; @@ -31,13 +31,12 @@ void main() { // u_zoom is the current zoom level adjusted for the change in font size mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); + vec2 extrude = u_extrude_scale * (a_offset / 64.0); if (u_skewed) { - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); - gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); + gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1); gl_Position.z += z * gl_Position.w; } else { - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; + gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); } // position of y on the screen From e39ba17c74a5725eb6c28ec0dd394d3fc91d72d5 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Wed, 20 Apr 2016 15:21:44 -0700 Subject: [PATCH 206/259] [core] port outlinepattern for fill-pattern anti-aliasing from gl-js to native add outlinepattern shader class to relevant files add outlinepattern code to painter_fill.cpp add outlinepattern code to fill_bucket refactor painter_fill, fix tests fix merge conflicts and setDepthSublayer update render test to no antialiasing so travis will be happy --- outlinepattern.fragment.glsl | 30 ++++++++++++++++++++++++++++++ outlinepattern.vertex.glsl | 21 +++++++++++++++++++++ outlinepattern_shader.cpp | 21 +++++++++++++++++++++ outlinepattern_shader.hpp | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 outlinepattern.fragment.glsl create mode 100644 outlinepattern.vertex.glsl create mode 100644 outlinepattern_shader.cpp create mode 100644 outlinepattern_shader.hpp diff --git a/outlinepattern.fragment.glsl b/outlinepattern.fragment.glsl new file mode 100644 index 00000000000..dd1efd63e67 --- /dev/null +++ b/outlinepattern.fragment.glsl @@ -0,0 +1,30 @@ +uniform float u_opacity; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; +uniform float u_mix; + +uniform sampler2D u_image; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec2 v_pos; + +void main() { + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); + vec4 color1 = texture2D(u_image, pos); + + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); + vec4 color2 = texture2D(u_image, pos2); + + // find distance to outline for alpha interpolation + + float dist = length(v_pos - gl_FragCoord.xy); + float alpha = smoothstep(1.0, 0.0, dist); + + + gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; +} \ No newline at end of file diff --git a/outlinepattern.vertex.glsl b/outlinepattern.vertex.glsl new file mode 100644 index 00000000000..e31b77b560f --- /dev/null +++ b/outlinepattern.vertex.glsl @@ -0,0 +1,21 @@ +uniform vec2 u_patternscale_a; +uniform vec2 u_patternscale_b; +uniform vec2 u_offset_a; +uniform vec2 u_offset_b; + +attribute vec2 a_pos; + +uniform mat4 u_matrix; +uniform vec2 u_world; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec2 v_pos; + + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + v_pos_a = u_patternscale_a * a_pos + u_offset_a; + v_pos_b = u_patternscale_b * a_pos + u_offset_b; + v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; +} diff --git a/outlinepattern_shader.cpp b/outlinepattern_shader.cpp new file mode 100644 index 00000000000..44b76b74c0b --- /dev/null +++ b/outlinepattern_shader.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +#include + +using namespace mbgl; + +OutlinePatternShader::OutlinePatternShader(gl::GLObjectStore& glObjectStore) + : Shader( + "outlinepattern", + shaders::outlinepattern::vertex, shaders::outlinepattern::fragment, + glObjectStore + ) { +} + +void OutlinePatternShader::bind(GLbyte *offset) { + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); +} diff --git a/outlinepattern_shader.hpp b/outlinepattern_shader.hpp new file mode 100644 index 00000000000..eed3839fd37 --- /dev/null +++ b/outlinepattern_shader.hpp @@ -0,0 +1,32 @@ +#ifndef MBGL_SHADER_SHADER_OUTLINEPATTERN +#define MBGL_SHADER_SHADER_OUTLINEPATTERN + +#include +#include + +namespace mbgl { + +class OutlinePatternShader : public Shader { +public: + OutlinePatternShader(gl::GLObjectStore&); + + void bind(GLbyte *offset) final; + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_mix = {"u_mix", *this}; + Uniform u_image = {"u_image", *this}; + Uniform> u_patternscale_a = {"u_patternscale_a", *this}; + Uniform> u_patternscale_b = {"u_patternscale_b", *this}; + Uniform> u_offset_a = {"u_offset_a", *this}; + Uniform> u_offset_b = {"u_offset_b", *this}; + Uniform> u_world = {"u_world", *this}; +}; + +} // namespace mbgl + +#endif \ No newline at end of file From a9559e911b11a155135888f733a96e5110f8cef6 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Apr 2016 15:47:07 -0700 Subject: [PATCH 207/259] combine line-width and line-gap-width in shader This makes the values for u_linewidth and u_gapwidth independent of eachother, which clears the way for making these properties data-driven. --- line.fragment.glsl | 7 +++---- line.vertex.glsl | 17 ++++++++++++----- linepattern.fragment.glsl | 10 +++++----- linepattern.vertex.glsl | 13 ++++++++++--- linesdfpattern.fragment.glsl | 6 +++--- linesdfpattern.vertex.glsl | 11 +++++++++-- 6 files changed, 42 insertions(+), 22 deletions(-) diff --git a/line.fragment.glsl b/line.fragment.glsl index 44220e35fa8..15d093afb44 100644 --- a/line.fragment.glsl +++ b/line.fragment.glsl @@ -1,23 +1,22 @@ precision mediump float; -uniform vec2 u_linewidth; uniform lowp vec4 u_color; uniform lowp float u_opacity; uniform float u_blur; varying vec2 v_normal; -varying float v_linesofar; +varying vec2 v_linewidth; varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * u_linewidth.s; + float dist = length(v_normal) * v_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * v_gamma_scale; - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); gl_FragColor = u_color * (alpha * u_opacity); diff --git a/line.vertex.glsl b/line.vertex.glsl index d4b7697610e..d82c9d39fb5 100644 --- a/line.vertex.glsl +++ b/line.vertex.glsl @@ -12,14 +12,17 @@ attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; -uniform float u_ratio; -uniform mediump vec2 u_linewidth; -uniform float u_extra; +uniform mediump float u_ratio; +uniform mediump float u_linewidth; +uniform mediump float u_gapwidth; +uniform mediump float u_antialiasing; +uniform mediump float u_extra; uniform mat2 u_antialiasingmatrix; uniform mediump float u_offset; +uniform mediump float u_blur; varying vec2 v_normal; -varying float v_linesofar; +varying vec2 v_linewidth; varying float v_gamma_scale; void main() { @@ -34,9 +37,12 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; + float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); + float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; + // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - mediump vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + mediump vec4 dist = vec4(outset * a_extrude * scale, 0.0, 0.0); // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -59,5 +65,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); + v_linewidth = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; } diff --git a/linepattern.fragment.glsl b/linepattern.fragment.glsl index 2ec81174371..b66ded700a1 100644 --- a/linepattern.fragment.glsl +++ b/linepattern.fragment.glsl @@ -1,6 +1,5 @@ precision mediump float; -uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; @@ -16,23 +15,24 @@ uniform float u_opacity; uniform sampler2D u_image; varying vec2 v_normal; +varying vec2 v_linewidth; varying float v_linesofar; varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * u_linewidth.s; + float dist = length(v_normal) * v_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * v_gamma_scale; - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); - float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); - float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); + float y_a = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_a.y); + float y_b = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_b.y); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); diff --git a/linepattern.vertex.glsl b/linepattern.vertex.glsl index 907049a5672..12f72938820 100644 --- a/linepattern.vertex.glsl +++ b/linepattern.vertex.glsl @@ -17,12 +17,15 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; -uniform mediump vec2 u_linewidth; -uniform float u_extra; +uniform mediump float u_linewidth; +uniform mediump float u_gapwidth; +uniform mediump float u_antialiasing; +uniform mediump float u_extra; uniform mat2 u_antialiasingmatrix; uniform mediump float u_offset; varying vec2 v_normal; +varying vec2 v_linewidth; varying float v_linesofar; varying float v_gamma_scale; @@ -39,10 +42,13 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; + float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); + float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; + // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. mediump vec2 extrude = a_extrude * scale; - mediump vec2 dist = u_linewidth.s * extrude; + mediump vec2 dist = outset * extrude; // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -66,5 +72,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); + v_linewidth = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; } diff --git a/linesdfpattern.fragment.glsl b/linesdfpattern.fragment.glsl index b07f08dcdd2..b71be3911e1 100644 --- a/linesdfpattern.fragment.glsl +++ b/linesdfpattern.fragment.glsl @@ -1,6 +1,5 @@ precision mediump float; -uniform vec2 u_linewidth; uniform lowp vec4 u_color; uniform lowp float u_opacity; uniform float u_blur; @@ -9,19 +8,20 @@ uniform float u_sdfgamma; uniform float u_mix; varying vec2 v_normal; +varying vec2 v_linewidth; varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * u_linewidth.s; + float dist = length(v_normal) * v_linewidth.s; // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * v_gamma_scale; - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); + float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/linesdfpattern.vertex.glsl b/linesdfpattern.vertex.glsl index f5650aacda7..78bf6a43cca 100644 --- a/linesdfpattern.vertex.glsl +++ b/linesdfpattern.vertex.glsl @@ -16,8 +16,10 @@ attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; -uniform mediump vec2 u_linewidth; uniform mediump float u_ratio; +uniform mediump float u_linewidth; +uniform mediump float u_gapwidth; +uniform mediump float u_antialiasing; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; @@ -27,6 +29,7 @@ uniform mat2 u_antialiasingmatrix; uniform mediump float u_offset; varying vec2 v_normal; +varying vec2 v_linewidth; varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; @@ -44,9 +47,12 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; + float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); + float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; + // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - mediump vec4 dist = vec4(u_linewidth.s * a_extrude * scale, 0.0, 0.0); + mediump vec4 dist = vec4(outset * a_extrude * scale, 0.0, 0.0); // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -72,5 +78,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); + v_linewidth = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; } From 48d7f2dc06a2be1e95f800db6d00acffb1a0fd47 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Apr 2016 18:00:54 -0700 Subject: [PATCH 208/259] separate pattern size from draw-time variables This is a step towards implementing data driven fill styles. --- outlinepattern.vertex.glsl | 39 +++++++++++++++++++++++++++++++------- pattern.vertex.glsl | 36 +++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/outlinepattern.vertex.glsl b/outlinepattern.vertex.glsl index 1a3973cfc5e..cae922e4e72 100644 --- a/outlinepattern.vertex.glsl +++ b/outlinepattern.vertex.glsl @@ -1,9 +1,12 @@ precision highp float; -uniform vec2 u_patternscale_a; -uniform vec2 u_patternscale_b; -uniform vec2 u_offset_a; -uniform vec2 u_offset_b; +uniform vec2 u_pattern_size_a; +uniform vec2 u_pattern_size_b; +uniform vec2 u_pixel_coord_upper; +uniform vec2 u_pixel_coord_lower; +uniform float u_scale_a; +uniform float u_scale_b; +uniform float u_tile_units_to_pixels; attribute vec2 a_pos; @@ -17,7 +20,29 @@ varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = u_patternscale_a * a_pos + u_offset_a; - v_pos_b = u_patternscale_b * a_pos + u_offset_b; - v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; + vec2 scaled_size_a = u_scale_a * u_pattern_size_a; + vec2 scaled_size_b = u_scale_b * u_pattern_size_b; + + // the correct offset needs to be calculated. + // + // The offset depends on how many pixels are between the world origin and + // the edge of the tile: + // vec2 offset = mod(pixel_coord, size) + // + // At high zoom levels there are a ton of pixels between the world origin + // and the edge of the tile. The glsl spec only guarantees 16 bits of + // precision for highp floats. We need more than that. + // + // The pixel_coord is passed in as two 16 bit values: + // pixel_coord_upper = floor(pixel_coord / 2^16) + // pixel_coord_lower = mod(pixel_coord, 2^16) + // + // The offset is calculated in a series of steps that should preserve this precision: + vec2 offset_a = mod(mod(mod(u_pixel_coord_upper, scaled_size_a) * 256.0, scaled_size_a) * 256.0 + u_pixel_coord_lower, scaled_size_a); + vec2 offset_b = mod(mod(mod(u_pixel_coord_upper, scaled_size_b) * 256.0, scaled_size_b) * 256.0 + u_pixel_coord_lower, scaled_size_b); + + v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; + v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; + + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } diff --git a/pattern.vertex.glsl b/pattern.vertex.glsl index fe048f6d840..1ecc90f91dd 100644 --- a/pattern.vertex.glsl +++ b/pattern.vertex.glsl @@ -1,10 +1,13 @@ precision highp float; uniform mat4 u_matrix; -uniform vec2 u_patternscale_a; -uniform vec2 u_patternscale_b; -uniform vec2 u_offset_a; -uniform vec2 u_offset_b; +uniform vec2 u_pattern_size_a; +uniform vec2 u_pattern_size_b; +uniform vec2 u_pixel_coord_upper; +uniform vec2 u_pixel_coord_lower; +uniform float u_scale_a; +uniform float u_scale_b; +uniform float u_tile_units_to_pixels; attribute vec2 a_pos; @@ -13,6 +16,27 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos_a = u_patternscale_a * a_pos + u_offset_a; - v_pos_b = u_patternscale_b * a_pos + u_offset_b; + vec2 scaled_size_a = u_scale_a * u_pattern_size_a; + vec2 scaled_size_b = u_scale_b * u_pattern_size_b; + + // the correct offset needs to be calculated. + // + // The offset depends on how many pixels are between the world origin and + // the edge of the tile: + // vec2 offset = mod(pixel_coord, size) + // + // At high zoom levels there are a ton of pixels between the world origin + // and the edge of the tile. The glsl spec only guarantees 16 bits of + // precision for highp floats. We need more than that. + // + // The pixel_coord is passed in as two 16 bit values: + // pixel_coord_upper = floor(pixel_coord / 2^16) + // pixel_coord_lower = mod(pixel_coord, 2^16) + // + // The offset is calculated in a series of steps that should preserve this precision: + vec2 offset_a = mod(mod(mod(u_pixel_coord_upper, scaled_size_a) * 256.0, scaled_size_a) * 256.0 + u_pixel_coord_lower, scaled_size_a); + vec2 offset_b = mod(mod(mod(u_pixel_coord_upper, scaled_size_b) * 256.0, scaled_size_b) * 256.0 + u_pixel_coord_lower, scaled_size_b); + + v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; + v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; } From 256c233b2c5a9760804faae4d6c26689be243425 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 May 2016 13:54:02 -0400 Subject: [PATCH 209/259] fix #2541, scale circles in pitch views (#2544) --- circle.vertex.glsl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/circle.vertex.glsl b/circle.vertex.glsl index 5574aa28ccb..eda02b993aa 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -69,9 +69,7 @@ void main(void) { // in extrusion data gl_Position = u_matrix * vec4(floor(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.xy += extrude * gl_Position.w; + gl_Position.xy += extrude; #ifdef ATTRIBUTE_A_COLOR v_color = a_color / 255.0; From 71eb17447752f377a4634d2ff979648ec43b2051 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 20 May 2016 15:19:56 -0400 Subject: [PATCH 210/259] [core] better symbol fading with texture lookups (#4579) - this is simpler than predicting opacity based on current zooming speed - this is smoother: symbols don't flicker when changing zoom speed or when zooming in and out rapidly. https://github.com/mapbox/mapbox-gl-js/commit/1df146627092b58c8db64d45530c74cd12a3fa02 fix #4562 --- icon.fragment.glsl | 7 +++++-- icon.vertex.glsl | 30 ++---------------------------- icon_shader.hpp | 5 +---- sdf.fragment.glsl | 6 ++++-- sdf.vertex.glsl | 25 ++----------------------- sdf_shader.hpp | 5 +---- 6 files changed, 15 insertions(+), 63 deletions(-) diff --git a/icon.fragment.glsl b/icon.fragment.glsl index 45b56793eba..f9ed6e75ed1 100644 --- a/icon.fragment.glsl +++ b/icon.fragment.glsl @@ -1,8 +1,11 @@ uniform sampler2D u_texture; +uniform sampler2D u_fadetexture; +uniform float u_opacity; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; void main() { - gl_FragColor = texture2D(u_texture, v_tex) * v_alpha; + float alpha = texture2D(u_fadetexture, v_fade_tex).a * u_opacity; + gl_FragColor = texture2D(u_texture, v_tex) * alpha; } diff --git a/icon.vertex.glsl b/icon.vertex.glsl index 3850e01ab79..a6a423127ab 100644 --- a/icon.vertex.glsl +++ b/icon.vertex.glsl @@ -9,18 +9,13 @@ attribute vec4 a_data2; uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; -uniform float u_fadedist; -uniform float u_minfadezoom; -uniform float u_maxfadezoom; -uniform float u_fadezoom; -uniform float u_opacity; uniform bool u_skewed; uniform float u_extra; uniform vec2 u_texsize; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; void main() { vec2 a_tex = a_data1.xy; @@ -30,29 +25,9 @@ void main() { float a_minzoom = a_zoom[0]; float a_maxzoom = a_zoom[1]; - float a_fadedist = 10.0; - // u_zoom is the current zoom level adjusted for the change in font size float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); - // fade out labels - float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); - - if (u_fadedist >= 0.0) { - v_alpha = alpha; - } else { - v_alpha = 1.0 - alpha; - } - if (u_maxfadezoom < a_labelminzoom) { - v_alpha = 0.0; - } - if (u_minfadezoom >= a_labelminzoom) { - v_alpha = 1.0; - } - - // if label has been faded out, clip it - z += step(v_alpha, 0.0); - if (u_skewed) { vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); @@ -63,6 +38,5 @@ void main() { } v_tex = a_tex / u_texsize; - - v_alpha *= u_opacity; + v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0); } diff --git a/icon_shader.hpp b/icon_shader.hpp index ec6311ea807..a7dcfe7a7e6 100644 --- a/icon_shader.hpp +++ b/icon_shader.hpp @@ -15,15 +15,12 @@ class IconShader : public Shader { UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; Uniform u_zoom = {"u_zoom", *this}; - Uniform u_fadedist = {"u_fadedist", *this}; - Uniform u_minfadezoom = {"u_minfadezoom", *this}; - Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform u_fadezoom = {"u_fadezoom", *this}; Uniform u_opacity = {"u_opacity", *this}; Uniform> u_texsize = {"u_texsize", *this}; Uniform u_skewed = {"u_skewed", *this}; Uniform u_extra = {"u_extra", *this}; Uniform u_texture = {"u_texture", *this}; + Uniform u_fadetexture = {"u_fadetexture", *this}; protected: GLint a_offset = -1; diff --git a/sdf.fragment.glsl b/sdf.fragment.glsl index a77e959e53b..3a6a4a8c37e 100644 --- a/sdf.fragment.glsl +++ b/sdf.fragment.glsl @@ -1,15 +1,17 @@ uniform sampler2D u_texture; +uniform sampler2D u_fadetexture; uniform vec4 u_color; uniform float u_buffer; uniform float u_gamma; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; varying float v_gamma_scale; void main() { float dist = texture2D(u_texture, v_tex).a; + float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a; float gamma = u_gamma * v_gamma_scale; - float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * v_alpha; + float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; gl_FragColor = u_color * alpha; } diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 0d538b24fdb..818378475e9 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -9,16 +9,12 @@ attribute vec4 a_data2; uniform mat4 u_matrix; uniform mat4 u_exmatrix; uniform float u_zoom; -uniform float u_fadedist; -uniform float u_minfadezoom; -uniform float u_maxfadezoom; -uniform float u_fadezoom; uniform bool u_skewed; uniform vec2 u_texsize; varying vec2 v_tex; -varying float v_alpha; +varying vec2 v_fade_tex; varying float v_gamma_scale; void main() { @@ -32,24 +28,6 @@ void main() { // u_zoom is the current zoom level adjusted for the change in font size float show = step(a_minzoom, u_zoom) * (1.0 - step(a_maxzoom, u_zoom)); - // fade out labels - float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0); - - if (u_fadedist >= 0.0) { - v_alpha = alpha; - } else { - v_alpha = 1.0 - alpha; - } - if (u_maxfadezoom < a_labelminzoom) { - v_alpha = 0.0; - } - if (u_minfadezoom >= a_labelminzoom) { - v_alpha = 1.0; - } - - // if label has been faded out, clip it - show *= (1.0 - step(v_alpha, 0.0)); - if (u_skewed) { vec4 extrude = u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); @@ -61,4 +39,5 @@ void main() { v_gamma_scale = (gl_Position.w - 0.5); v_tex = a_tex / u_texsize; + v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0); } diff --git a/sdf_shader.hpp b/sdf_shader.hpp index 402168de0c1..5fe6a443709 100644 --- a/sdf_shader.hpp +++ b/sdf_shader.hpp @@ -17,12 +17,9 @@ class SDFShader : public Shader { Uniform u_buffer = {"u_buffer", *this}; Uniform u_gamma = {"u_gamma", *this}; Uniform u_zoom = {"u_zoom", *this}; - Uniform u_fadedist = {"u_fadedist", *this}; - Uniform u_minfadezoom = {"u_minfadezoom", *this}; - Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform u_fadezoom = {"u_fadezoom", *this}; Uniform u_skewed = {"u_skewed", *this}; Uniform u_texture = {"u_texture", *this}; + Uniform u_fadetexture = {"u_fadetexture", *this}; protected: GLint a_offset = -1; From dbc0cb3910e6d808311e243ef8cc05aab7b15167 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 May 2016 11:20:06 -0700 Subject: [PATCH 211/259] Prepare for merge --- box_shader.cpp | 28 ------ box_shader.hpp | 28 ------ circle_shader.cpp | 17 ---- circle_shader.hpp | 24 ----- dot_shader.cpp | 17 ---- dot_shader.hpp | 23 ----- icon_shader.cpp | 31 ------ icon_shader.hpp | 33 ------- line_shader.cpp | 21 ---- line_shader.hpp | 32 ------- linepattern_shader.cpp | 21 ---- linepattern_shader.hpp | 39 -------- linesdf_shader.cpp | 21 ---- linesdf_shader.hpp | 39 -------- outline_shader.cpp | 17 ---- outline_shader.hpp | 22 ----- outlinepattern_shader.cpp | 21 ---- outlinepattern_shader.hpp | 32 ------- pattern_shader.cpp | 21 ---- pattern_shader.hpp | 31 ------ plain_shader.cpp | 17 ---- plain_shader.hpp | 21 ---- raster_shader.cpp | 17 ---- raster_shader.hpp | 28 ------ sdf_shader.cpp | 47 --------- sdf_shader.hpp | 44 --------- shader.cpp | 95 ------------------- shader.hpp | 36 ------- .../circle.fragment.glsl | 0 circle.vertex.glsl => src/circle.vertex.glsl | 0 .../collisionbox.fragment.glsl | 0 .../collisionbox.vertex.glsl | 0 dot.fragment.glsl => src/debug.fragment.glsl | 0 dot.vertex.glsl => src/debug.vertex.glsl | 0 plain.fragment.glsl => src/fill.fragment.glsl | 0 plain.vertex.glsl => src/fill.vertex.glsl | 0 icon.fragment.glsl => src/icon.fragment.glsl | 0 icon.vertex.glsl => src/icon.vertex.glsl | 0 line.fragment.glsl => src/line.fragment.glsl | 0 line.vertex.glsl => src/line.vertex.glsl | 0 .../linepattern.fragment.glsl | 0 .../linepattern.vertex.glsl | 0 .../linesdfpattern.fragment.glsl | 0 .../linesdfpattern.vertex.glsl | 0 .../outline.fragment.glsl | 0 .../outline.vertex.glsl | 0 .../outlinepattern.fragment.glsl | 0 .../outlinepattern.vertex.glsl | 0 .../pattern.fragment.glsl | 0 .../pattern.vertex.glsl | 0 .../raster.fragment.glsl | 0 raster.vertex.glsl => src/raster.vertex.glsl | 0 sdf.fragment.glsl => src/sdf.fragment.glsl | 0 sdf.vertex.glsl => src/sdf.vertex.glsl | 0 uniform.cpp | 47 --------- uniform.hpp | 63 ------------ 56 files changed, 933 deletions(-) delete mode 100644 box_shader.cpp delete mode 100644 box_shader.hpp delete mode 100644 circle_shader.cpp delete mode 100644 circle_shader.hpp delete mode 100644 dot_shader.cpp delete mode 100644 dot_shader.hpp delete mode 100644 icon_shader.cpp delete mode 100644 icon_shader.hpp delete mode 100644 line_shader.cpp delete mode 100644 line_shader.hpp delete mode 100644 linepattern_shader.cpp delete mode 100644 linepattern_shader.hpp delete mode 100644 linesdf_shader.cpp delete mode 100644 linesdf_shader.hpp delete mode 100644 outline_shader.cpp delete mode 100644 outline_shader.hpp delete mode 100644 outlinepattern_shader.cpp delete mode 100644 outlinepattern_shader.hpp delete mode 100644 pattern_shader.cpp delete mode 100644 pattern_shader.hpp delete mode 100644 plain_shader.cpp delete mode 100644 plain_shader.hpp delete mode 100644 raster_shader.cpp delete mode 100644 raster_shader.hpp delete mode 100644 sdf_shader.cpp delete mode 100644 sdf_shader.hpp delete mode 100644 shader.cpp delete mode 100644 shader.hpp rename circle.fragment.glsl => src/circle.fragment.glsl (100%) rename circle.vertex.glsl => src/circle.vertex.glsl (100%) rename box.fragment.glsl => src/collisionbox.fragment.glsl (100%) rename box.vertex.glsl => src/collisionbox.vertex.glsl (100%) rename dot.fragment.glsl => src/debug.fragment.glsl (100%) rename dot.vertex.glsl => src/debug.vertex.glsl (100%) rename plain.fragment.glsl => src/fill.fragment.glsl (100%) rename plain.vertex.glsl => src/fill.vertex.glsl (100%) rename icon.fragment.glsl => src/icon.fragment.glsl (100%) rename icon.vertex.glsl => src/icon.vertex.glsl (100%) rename line.fragment.glsl => src/line.fragment.glsl (100%) rename line.vertex.glsl => src/line.vertex.glsl (100%) rename linepattern.fragment.glsl => src/linepattern.fragment.glsl (100%) rename linepattern.vertex.glsl => src/linepattern.vertex.glsl (100%) rename linesdf.fragment.glsl => src/linesdfpattern.fragment.glsl (100%) rename linesdf.vertex.glsl => src/linesdfpattern.vertex.glsl (100%) rename outline.fragment.glsl => src/outline.fragment.glsl (100%) rename outline.vertex.glsl => src/outline.vertex.glsl (100%) rename outlinepattern.fragment.glsl => src/outlinepattern.fragment.glsl (100%) rename outlinepattern.vertex.glsl => src/outlinepattern.vertex.glsl (100%) rename pattern.fragment.glsl => src/pattern.fragment.glsl (100%) rename pattern.vertex.glsl => src/pattern.vertex.glsl (100%) rename raster.fragment.glsl => src/raster.fragment.glsl (100%) rename raster.vertex.glsl => src/raster.vertex.glsl (100%) rename sdf.fragment.glsl => src/sdf.fragment.glsl (100%) rename sdf.vertex.glsl => src/sdf.vertex.glsl (100%) delete mode 100644 uniform.cpp delete mode 100644 uniform.hpp diff --git a/box_shader.cpp b/box_shader.cpp deleted file mode 100644 index 63f800ea698..00000000000 --- a/box_shader.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -CollisionBoxShader::CollisionBoxShader(gl::GLObjectStore& glObjectStore) - : Shader("collisionbox", shaders::box::vertex, shaders::box::fragment, glObjectStore) { - a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_extrude")); - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); -} - -void CollisionBoxShader::bind(GLbyte *offset) { - const GLint stride = 12; - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_SHORT, false, stride, offset + 4)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 2, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - -} diff --git a/box_shader.hpp b/box_shader.hpp deleted file mode 100644 index f3015b73a7b..00000000000 --- a/box_shader.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_BOX -#define MBGL_SHADER_SHADER_BOX - -#include -#include -#include - -namespace mbgl { - -class CollisionBoxShader : public Shader { -public: - CollisionBoxShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform u_scale = {"u_scale", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_maxzoom = {"u_maxzoom", *this}; - -protected: - GLint a_extrude = -1; - GLint a_data = -1; -}; - -} // namespace mbgl - -#endif // MBGL_SHADER_BOX_SHADER diff --git a/circle_shader.cpp b/circle_shader.cpp deleted file mode 100644 index 3ec822747fe..00000000000 --- a/circle_shader.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -CircleShader::CircleShader(gl::GLObjectStore& glObjectStore) - : Shader("circle", shaders::circle::vertex, shaders::circle::fragment, glObjectStore) { -} - -void CircleShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 4, offset)); -} diff --git a/circle_shader.hpp b/circle_shader.hpp deleted file mode 100644 index a28bf3c6ae0..00000000000 --- a/circle_shader.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef MBGL_SHADER_CIRCLE_SHADER -#define MBGL_SHADER_CIRCLE_SHADER - -#include -#include - -namespace mbgl { - -class CircleShader : public Shader { -public: - CircleShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform u_size = {"u_size", *this}; - Uniform u_blur = {"u_blur", *this}; -}; - -} // namespace mbgl - -#endif // MBGL_SHADER_CIRCLE_SHADER diff --git a/dot_shader.cpp b/dot_shader.cpp deleted file mode 100644 index 9d60306da2c..00000000000 --- a/dot_shader.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -DotShader::DotShader(gl::GLObjectStore& glObjectStore) - : Shader("dot", shaders::dot::vertex, shaders::dot::fragment, glObjectStore) { -} - -void DotShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset)); -} diff --git a/dot_shader.hpp b/dot_shader.hpp deleted file mode 100644 index a015310a626..00000000000 --- a/dot_shader.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_DOT -#define MBGL_SHADER_SHADER_DOT - -#include -#include - -namespace mbgl { - -class DotShader : public Shader { -public: - DotShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform u_size = {"u_size", *this}; - Uniform u_blur = {"u_blur", *this}; -}; - -} // namespace mbgl - -#endif diff --git a/icon_shader.cpp b/icon_shader.cpp deleted file mode 100644 index 2ff653a87c3..00000000000 --- a/icon_shader.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -IconShader::IconShader(gl::GLObjectStore& glObjectStore) - : Shader("icon", shaders::icon::vertex, shaders::icon::fragment, glObjectStore) { - a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")); - a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")); - a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2")); -} - -void IconShader::bind(GLbyte* offset) { - const GLsizei stride = 16; - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); -} diff --git a/icon_shader.hpp b/icon_shader.hpp deleted file mode 100644 index a7dcfe7a7e6..00000000000 --- a/icon_shader.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_ICON -#define MBGL_SHADER_SHADER_ICON - -#include -#include - -namespace mbgl { - -class IconShader : public Shader { -public: - IconShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform> u_texsize = {"u_texsize", *this}; - Uniform u_skewed = {"u_skewed", *this}; - Uniform u_extra = {"u_extra", *this}; - Uniform u_texture = {"u_texture", *this}; - Uniform u_fadetexture = {"u_fadetexture", *this}; - -protected: - GLint a_offset = -1; - GLint a_data1 = -1; - GLint a_data2 = -1; -}; - -} // namespace mbgl - -#endif diff --git a/line_shader.cpp b/line_shader.cpp deleted file mode 100644 index c54b3312d82..00000000000 --- a/line_shader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -LineShader::LineShader(gl::GLObjectStore& glObjectStore) - : Shader("line", shaders::line::vertex, shaders::line::fragment, glObjectStore) { - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); -} - -void LineShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); -} diff --git a/line_shader.hpp b/line_shader.hpp deleted file mode 100644 index 1a9598f9251..00000000000 --- a/line_shader.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINE -#define MBGL_SHADER_SHADER_LINE - -#include -#include - -namespace mbgl { - -class LineShader : public Shader { -public: - LineShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform u_ratio = {"u_ratio", *this}; - Uniform u_blur = {"u_blur", *this}; - Uniform u_extra = {"u_extra", *this}; - Uniform u_offset = {"u_offset", *this}; - UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; - -private: - GLint a_data = -1; -}; - - -} // namespace mbgl - -#endif diff --git a/linepattern_shader.cpp b/linepattern_shader.cpp deleted file mode 100644 index 40f64ed139c..00000000000 --- a/linepattern_shader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -LinepatternShader::LinepatternShader(gl::GLObjectStore& glObjectStore) - : Shader("linepattern", shaders::linepattern::vertex, shaders::linepattern::fragment, glObjectStore) { - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); -} - -void LinepatternShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); -} diff --git a/linepattern_shader.hpp b/linepattern_shader.hpp deleted file mode 100644 index cbab2f9c4c5..00000000000 --- a/linepattern_shader.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINEPATTERN -#define MBGL_SHADER_SHADER_LINEPATTERN - -#include -#include - -namespace mbgl { - -class LinepatternShader : public Shader { -public: - LinepatternShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform> u_pattern_size_a = {"u_pattern_size_a", *this}; - Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; - Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; - Uniform> u_pattern_size_b = {"u_pattern_size_b", *this}; - Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; - Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; - Uniform u_ratio = {"u_ratio", *this}; - Uniform u_point = {"u_point", *this}; - Uniform u_blur = {"u_blur", *this}; - Uniform u_fade = {"u_fade", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_extra = {"u_extra", *this}; - Uniform u_offset = {"u_offset", *this}; - Uniform u_image = {"u_image", *this}; - UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; - -private: - GLint a_data = -1; -}; -} // namespace mbgl - -#endif diff --git a/linesdf_shader.cpp b/linesdf_shader.cpp deleted file mode 100644 index 13581279251..00000000000 --- a/linesdf_shader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -LineSDFShader::LineSDFShader(gl::GLObjectStore& glObjectStore) - : Shader("line", shaders::linesdf::vertex, shaders::linesdf::fragment, glObjectStore) { - a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data")); -} - -void LineSDFShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); -} diff --git a/linesdf_shader.hpp b/linesdf_shader.hpp deleted file mode 100644 index 8ac0aa57934..00000000000 --- a/linesdf_shader.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINESDF -#define MBGL_SHADER_SHADER_LINESDF - -#include -#include - -namespace mbgl { - -class LineSDFShader : public Shader { -public: - LineSDFShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform u_ratio = {"u_ratio", *this}; - Uniform u_blur = {"u_blur", *this}; - Uniform> u_patternscale_a = { "u_patternscale_a", *this}; - Uniform u_tex_y_a = {"u_tex_y_a", *this}; - Uniform> u_patternscale_b = { "u_patternscale_b", *this}; - Uniform u_tex_y_b = {"u_tex_y_b", *this}; - Uniform u_image = {"u_image", *this}; - Uniform u_sdfgamma = {"u_sdfgamma", *this}; - Uniform u_mix = {"u_mix", *this}; - Uniform u_extra = {"u_extra", *this}; - Uniform u_offset = {"u_offset", *this}; - UniformMatrix<2> u_antialiasingmatrix = {"u_antialiasingmatrix", *this}; - -private: - GLint a_data = -1; -}; - - -} // namespace mbgl - -#endif diff --git a/outline_shader.cpp b/outline_shader.cpp deleted file mode 100644 index 8c7458327fd..00000000000 --- a/outline_shader.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -OutlineShader::OutlineShader(gl::GLObjectStore& glObjectStore) - : Shader("outline", shaders::outline::vertex, shaders::outline::fragment, glObjectStore) { -} - -void OutlineShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); -} diff --git a/outline_shader.hpp b/outline_shader.hpp deleted file mode 100644 index 800461bf066..00000000000 --- a/outline_shader.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_OUTLINE -#define MBGL_SHADER_SHADER_OUTLINE - -#include -#include - -namespace mbgl { - -class OutlineShader : public Shader { -public: - OutlineShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_world = {"u_world", *this}; -}; - -} // namespace mbgl - -#endif diff --git a/outlinepattern_shader.cpp b/outlinepattern_shader.cpp deleted file mode 100644 index 44b76b74c0b..00000000000 --- a/outlinepattern_shader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -OutlinePatternShader::OutlinePatternShader(gl::GLObjectStore& glObjectStore) - : Shader( - "outlinepattern", - shaders::outlinepattern::vertex, shaders::outlinepattern::fragment, - glObjectStore - ) { -} - -void OutlinePatternShader::bind(GLbyte *offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); -} diff --git a/outlinepattern_shader.hpp b/outlinepattern_shader.hpp deleted file mode 100644 index eed3839fd37..00000000000 --- a/outlinepattern_shader.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_OUTLINEPATTERN -#define MBGL_SHADER_SHADER_OUTLINEPATTERN - -#include -#include - -namespace mbgl { - -class OutlinePatternShader : public Shader { -public: - OutlinePatternShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; - Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; - Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; - Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_mix = {"u_mix", *this}; - Uniform u_image = {"u_image", *this}; - Uniform> u_patternscale_a = {"u_patternscale_a", *this}; - Uniform> u_patternscale_b = {"u_patternscale_b", *this}; - Uniform> u_offset_a = {"u_offset_a", *this}; - Uniform> u_offset_b = {"u_offset_b", *this}; - Uniform> u_world = {"u_world", *this}; -}; - -} // namespace mbgl - -#endif \ No newline at end of file diff --git a/pattern_shader.cpp b/pattern_shader.cpp deleted file mode 100644 index 4f52df59fb1..00000000000 --- a/pattern_shader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -PatternShader::PatternShader(gl::GLObjectStore& glObjectStore) - : Shader( - "pattern", - shaders::pattern::vertex, shaders::pattern::fragment, - glObjectStore - ) { -} - -void PatternShader::bind(GLbyte *offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); -} diff --git a/pattern_shader.hpp b/pattern_shader.hpp deleted file mode 100644 index 0898dc0b8cd..00000000000 --- a/pattern_shader.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_PATTERN -#define MBGL_SHADER_SHADER_PATTERN - -#include -#include - -namespace mbgl { - -class PatternShader : public Shader { -public: - PatternShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; - Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; - Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; - Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_mix = {"u_mix", *this}; - Uniform u_image = {"u_image", *this}; - Uniform> u_patternscale_a = {"u_patternscale_a", *this}; - Uniform> u_patternscale_b = {"u_patternscale_b", *this}; - Uniform> u_offset_a = {"u_offset_a", *this}; - Uniform> u_offset_b = {"u_offset_b", *this}; -}; - -} // namespace mbgl - -#endif diff --git a/plain_shader.cpp b/plain_shader.cpp deleted file mode 100644 index 1b5a7819b36..00000000000 --- a/plain_shader.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -PlainShader::PlainShader(gl::GLObjectStore& glObjectStore) - : Shader("plain", shaders::plain::vertex, shaders::plain::fragment, glObjectStore) { -} - -void PlainShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); -} diff --git a/plain_shader.hpp b/plain_shader.hpp deleted file mode 100644 index 34ee4dcdf78..00000000000 --- a/plain_shader.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_PLAIN -#define MBGL_SHADER_SHADER_PLAIN - -#include -#include - -namespace mbgl { - -class PlainShader : public Shader { -public: - PlainShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_color = {"u_color", *this}; -}; - -} // namespace mbgl - -#endif diff --git a/raster_shader.cpp b/raster_shader.cpp deleted file mode 100644 index 77bcf400087..00000000000 --- a/raster_shader.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -RasterShader::RasterShader(gl::GLObjectStore& glObjectStore) - : Shader("raster", shaders::raster::vertex, shaders::raster::fragment, glObjectStore) { -} - -void RasterShader::bind(GLbyte* offset) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); -} diff --git a/raster_shader.hpp b/raster_shader.hpp deleted file mode 100644 index 6a2e2ecf3ed..00000000000 --- a/raster_shader.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MBGL_RENDERER_SHADER_RASTER -#define MBGL_RENDERER_SHADER_RASTER - -#include -#include - -namespace mbgl { - -class RasterShader : public Shader { -public: - RasterShader(gl::GLObjectStore&); - - void bind(GLbyte *offset) final; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform u_image = {"u_image", *this}; - Uniform u_opacity = {"u_opacity", *this}; - Uniform u_buffer = {"u_buffer", *this}; - Uniform u_brightness_low = {"u_brightness_low", *this}; - Uniform u_brightness_high = {"u_brightness_high", *this}; - Uniform u_saturation_factor = {"u_saturation_factor", *this}; - Uniform u_contrast_factor = {"u_contrast_factor", *this}; - Uniform> u_spin_weights = {"u_spin_weights", *this}; -}; - -} // namespace mbgl - -#endif diff --git a/sdf_shader.cpp b/sdf_shader.cpp deleted file mode 100644 index a972849d3d9..00000000000 --- a/sdf_shader.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include - -#include - -using namespace mbgl; - -SDFShader::SDFShader(gl::GLObjectStore& glObjectStore) - : Shader("sdf", shaders::sdf::vertex, shaders::sdf::fragment, glObjectStore) { - a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")); - a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")); - a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2")); -} - -void SDFGlyphShader::bind(GLbyte* offset) { - const int stride = 16; - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); -} - -void SDFIconShader::bind(GLbyte* offset) { - const int stride = 16; - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8)); - - MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12)); -} diff --git a/sdf_shader.hpp b/sdf_shader.hpp deleted file mode 100644 index 5fe6a443709..00000000000 --- a/sdf_shader.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef MBGL_SHADER_SDF_SHADER -#define MBGL_SHADER_SDF_SHADER - -#include -#include - -namespace mbgl { - -class SDFShader : public Shader { -public: - SDFShader(gl::GLObjectStore&); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_texsize = {"u_texsize", *this}; - Uniform u_buffer = {"u_buffer", *this}; - Uniform u_gamma = {"u_gamma", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_skewed = {"u_skewed", *this}; - Uniform u_texture = {"u_texture", *this}; - Uniform u_fadetexture = {"u_fadetexture", *this}; - -protected: - GLint a_offset = -1; - GLint a_data1 = -1; - GLint a_data2 = -1; -}; - -class SDFGlyphShader : public SDFShader { -public: - SDFGlyphShader(gl::GLObjectStore& glObjectStore) : SDFShader(glObjectStore) {} - void bind(GLbyte *offset) final; -}; - -class SDFIconShader : public SDFShader { -public: - SDFIconShader(gl::GLObjectStore& glObjectStore) : SDFShader(glObjectStore) {} - void bind(GLbyte *offset) final; -}; - -} // namespace mbgl - -#endif diff --git a/shader.cpp b/shader.cpp deleted file mode 100644 index 8216de5b4d9..00000000000 --- a/shader.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace mbgl { - -Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSource, gl::GLObjectStore& glObjectStore) - : name(name_) -{ - util::stopwatch stopwatch("shader compilation", Event::Shader); - - program.create(glObjectStore); - vertexShader.create(glObjectStore); - if (!compileShader(vertexShader, &vertSource)) { - Log::Error(Event::Shader, "Vertex shader %s failed to compile: %s", name, vertSource); - throw util::ShaderException(std::string { "Vertex shader " } + name + " failed to compile"); - } - - fragmentShader.create(glObjectStore); - if (!compileShader(fragmentShader, &fragSource)) { - Log::Error(Event::Shader, "Fragment shader %s failed to compile: %s", name, fragSource); - throw util::ShaderException(std::string { "Fragment shader " } + name + " failed to compile"); - } - - // Attach shaders - MBGL_CHECK_ERROR(glAttachShader(program.getID(), vertexShader.getID())); - MBGL_CHECK_ERROR(glAttachShader(program.getID(), fragmentShader.getID())); - - { - // Link program - GLint status; - MBGL_CHECK_ERROR(glLinkProgram(program.getID())); - - MBGL_CHECK_ERROR(glGetProgramiv(program.getID(), GL_LINK_STATUS, &status)); - if (status == 0) { - GLint logLength; - MBGL_CHECK_ERROR(glGetProgramiv(program.getID(), GL_INFO_LOG_LENGTH, &logLength)); - const auto log = std::make_unique(logLength); - if (logLength > 0) { - MBGL_CHECK_ERROR(glGetProgramInfoLog(program.getID(), logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Program failed to link: %s", log.get()); - } - throw util::ShaderException(std::string { "Program " } + name + " failed to link: " + log.get()); - } - } - - a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program.getID(), "a_pos")); -} - -bool Shader::compileShader(gl::ShaderHolder& shader, const GLchar *source[]) { - GLint status = 0; - - const GLsizei lengths = static_cast(std::strlen(*source)); - MBGL_CHECK_ERROR(glShaderSource(shader.getID(), 1, source, &lengths)); - - MBGL_CHECK_ERROR(glCompileShader(shader.getID())); - - MBGL_CHECK_ERROR(glGetShaderiv(shader.getID(), GL_COMPILE_STATUS, &status)); - if (status == 0) { - GLint logLength; - MBGL_CHECK_ERROR(glGetShaderiv(shader.getID(), GL_INFO_LOG_LENGTH, &logLength)); - if (logLength > 0) { - const auto log = std::make_unique(logLength); - MBGL_CHECK_ERROR(glGetShaderInfoLog(shader.getID(), logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); - } - return false; - } - - MBGL_CHECK_ERROR(glGetShaderiv(shader.getID(), GL_COMPILE_STATUS, &status)); - if (status == GL_FALSE) { - Log::Error(Event::Shader, "Shader %s failed to compile.", name); - return false; - } - - return true; -} - -Shader::~Shader() { - if (program) { - MBGL_CHECK_ERROR(glDetachShader(program.getID(), vertexShader.getID())); - MBGL_CHECK_ERROR(glDetachShader(program.getID(), fragmentShader.getID())); - } -} - -} // namespace mbgl diff --git a/shader.hpp b/shader.hpp deleted file mode 100644 index b543f73a6f7..00000000000 --- a/shader.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MBGL_RENDERER_SHADER -#define MBGL_RENDERER_SHADER - -#include -#include -#include - -namespace mbgl { - -class Shader : private util::noncopyable { -public: - Shader(const GLchar *name, const GLchar *vertex, const GLchar *fragment, gl::GLObjectStore&); - - ~Shader(); - const GLchar *name; - - GLuint getID() const { - return program.getID(); - } - - virtual void bind(GLbyte *offset) = 0; - -protected: - GLint a_pos = -1; - -private: - bool compileShader(gl::ShaderHolder&, const GLchar *source[]); - - gl::ProgramHolder program; - gl::ShaderHolder vertexShader = { GL_VERTEX_SHADER }; - gl::ShaderHolder fragmentShader = { GL_FRAGMENT_SHADER }; -}; - -} // namespace mbgl - -#endif diff --git a/circle.fragment.glsl b/src/circle.fragment.glsl similarity index 100% rename from circle.fragment.glsl rename to src/circle.fragment.glsl diff --git a/circle.vertex.glsl b/src/circle.vertex.glsl similarity index 100% rename from circle.vertex.glsl rename to src/circle.vertex.glsl diff --git a/box.fragment.glsl b/src/collisionbox.fragment.glsl similarity index 100% rename from box.fragment.glsl rename to src/collisionbox.fragment.glsl diff --git a/box.vertex.glsl b/src/collisionbox.vertex.glsl similarity index 100% rename from box.vertex.glsl rename to src/collisionbox.vertex.glsl diff --git a/dot.fragment.glsl b/src/debug.fragment.glsl similarity index 100% rename from dot.fragment.glsl rename to src/debug.fragment.glsl diff --git a/dot.vertex.glsl b/src/debug.vertex.glsl similarity index 100% rename from dot.vertex.glsl rename to src/debug.vertex.glsl diff --git a/plain.fragment.glsl b/src/fill.fragment.glsl similarity index 100% rename from plain.fragment.glsl rename to src/fill.fragment.glsl diff --git a/plain.vertex.glsl b/src/fill.vertex.glsl similarity index 100% rename from plain.vertex.glsl rename to src/fill.vertex.glsl diff --git a/icon.fragment.glsl b/src/icon.fragment.glsl similarity index 100% rename from icon.fragment.glsl rename to src/icon.fragment.glsl diff --git a/icon.vertex.glsl b/src/icon.vertex.glsl similarity index 100% rename from icon.vertex.glsl rename to src/icon.vertex.glsl diff --git a/line.fragment.glsl b/src/line.fragment.glsl similarity index 100% rename from line.fragment.glsl rename to src/line.fragment.glsl diff --git a/line.vertex.glsl b/src/line.vertex.glsl similarity index 100% rename from line.vertex.glsl rename to src/line.vertex.glsl diff --git a/linepattern.fragment.glsl b/src/linepattern.fragment.glsl similarity index 100% rename from linepattern.fragment.glsl rename to src/linepattern.fragment.glsl diff --git a/linepattern.vertex.glsl b/src/linepattern.vertex.glsl similarity index 100% rename from linepattern.vertex.glsl rename to src/linepattern.vertex.glsl diff --git a/linesdf.fragment.glsl b/src/linesdfpattern.fragment.glsl similarity index 100% rename from linesdf.fragment.glsl rename to src/linesdfpattern.fragment.glsl diff --git a/linesdf.vertex.glsl b/src/linesdfpattern.vertex.glsl similarity index 100% rename from linesdf.vertex.glsl rename to src/linesdfpattern.vertex.glsl diff --git a/outline.fragment.glsl b/src/outline.fragment.glsl similarity index 100% rename from outline.fragment.glsl rename to src/outline.fragment.glsl diff --git a/outline.vertex.glsl b/src/outline.vertex.glsl similarity index 100% rename from outline.vertex.glsl rename to src/outline.vertex.glsl diff --git a/outlinepattern.fragment.glsl b/src/outlinepattern.fragment.glsl similarity index 100% rename from outlinepattern.fragment.glsl rename to src/outlinepattern.fragment.glsl diff --git a/outlinepattern.vertex.glsl b/src/outlinepattern.vertex.glsl similarity index 100% rename from outlinepattern.vertex.glsl rename to src/outlinepattern.vertex.glsl diff --git a/pattern.fragment.glsl b/src/pattern.fragment.glsl similarity index 100% rename from pattern.fragment.glsl rename to src/pattern.fragment.glsl diff --git a/pattern.vertex.glsl b/src/pattern.vertex.glsl similarity index 100% rename from pattern.vertex.glsl rename to src/pattern.vertex.glsl diff --git a/raster.fragment.glsl b/src/raster.fragment.glsl similarity index 100% rename from raster.fragment.glsl rename to src/raster.fragment.glsl diff --git a/raster.vertex.glsl b/src/raster.vertex.glsl similarity index 100% rename from raster.vertex.glsl rename to src/raster.vertex.glsl diff --git a/sdf.fragment.glsl b/src/sdf.fragment.glsl similarity index 100% rename from sdf.fragment.glsl rename to src/sdf.fragment.glsl diff --git a/sdf.vertex.glsl b/src/sdf.vertex.glsl similarity index 100% rename from sdf.vertex.glsl rename to src/sdf.vertex.glsl diff --git a/uniform.cpp b/uniform.cpp deleted file mode 100644 index d43dd20016f..00000000000 --- a/uniform.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include - -namespace mbgl { - -template <> -void Uniform::bind(const GLfloat& t) { - MBGL_CHECK_ERROR(glUniform1f(location, t)); -} - -template <> -void Uniform::bind(const GLint& t) { - MBGL_CHECK_ERROR(glUniform1i(location, t)); -} - -template <> -void Uniform>::bind(const std::array& t) { - MBGL_CHECK_ERROR(glUniform2fv(location, 1, t.data())); -} - -template <> -void Uniform>::bind(const std::array& t) { - MBGL_CHECK_ERROR(glUniform3fv(location, 1, t.data())); -} - -template <> -void Uniform>::bind(const std::array& t) { - MBGL_CHECK_ERROR(glUniform4fv(location, 1, t.data())); -} - -template <> -void UniformMatrix<2>::bind(const std::array& t) { - MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data())); -} - -template <> -void UniformMatrix<3>::bind(const std::array& t) { - MBGL_CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, t.data())); -} - -template <> -void UniformMatrix<4>::bind(const std::array& t) { - MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, t.data())); -} - -// Add more as needed. - -} // namespace mbgl diff --git a/uniform.hpp b/uniform.hpp deleted file mode 100644 index 5c4a2b14c4f..00000000000 --- a/uniform.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef MBGL_SHADER_UNIFORM -#define MBGL_SHADER_UNIFORM - -#include -#include - -#include - -namespace mbgl { - -template -class Uniform { -public: - Uniform(const GLchar* name, const Shader& shader) : current() { - location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name)); - } - - void operator=(const T& t) { - if (current != t) { - current = t; - bind(t); - } - } - -private: - void bind(const T&); - - T current; - GLint location; -}; - -template -class UniformMatrix { -public: - typedef std::array T; - - UniformMatrix(const GLchar* name, const Shader& shader) : current() { - location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name)); - } - - void operator=(const std::array& t) { - bool dirty = false; - for (unsigned int i = 0; i < C*R; i++) { - if (current[i] != t[i]) { - current[i] = t[i]; - dirty = true; - } - } - if (dirty) { - bind(current); - } - } - -private: - void bind(const T&); - - T current; - GLint location; -}; - -} // namespace mbgl - -#endif From 7d3da8f1914954fd96f305b7116cfd127a616551 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 23 May 2016 13:08:09 -0700 Subject: [PATCH 212/259] Reduce shader boilerplate, refactor "Bucket" (#2585) * Rename macros to defines * Rename addPaintAttributes to populatePaintArrays * Add support for pragmas in useProgram * Replace shader boilerplate with pragmas * Inject shader functions at compiletime * Move shader utility functions into a glsl file * Support arguments in shader pragmas, remove precision from bucket definition --- circle.fragment.glsl | 7 ++++-- circle.vertex.glsl | 60 +++----------------------------------------- util.vertex.glsl | 18 +++++++++++++ 3 files changed, 27 insertions(+), 58 deletions(-) create mode 100644 util.vertex.glsl diff --git a/circle.fragment.glsl b/circle.fragment.glsl index 204ce85f52f..ccc878b7b90 100644 --- a/circle.fragment.glsl +++ b/circle.fragment.glsl @@ -3,13 +3,16 @@ precision mediump float; uniform lowp float u_blur; uniform lowp float u_opacity; -varying lowp vec4 v_color; varying vec2 v_extrude; varying lowp float v_antialiasblur; +#pragma mapbox: define color lowp + void main() { + #pragma mapbox: initialize color + float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); - gl_FragColor = v_color * (1.0 - t) * u_opacity; + gl_FragColor = color * (1.0 - t) * u_opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/circle.vertex.glsl b/circle.vertex.glsl index eda02b993aa..efb1ba52abf 100644 --- a/circle.vertex.glsl +++ b/circle.vertex.glsl @@ -6,60 +6,16 @@ uniform float u_devicepixelratio; attribute vec2 a_pos; -#ifdef ATTRIBUTE_A_COLOR -attribute lowp vec4 a_color; -#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_COLOR0 -uniform lowp float u_color_t; -attribute lowp vec4 a_color0; -attribute lowp vec4 a_color1; -attribute lowp vec4 a_color2; -attribute lowp vec4 a_color3; -#else -uniform lowp vec4 a_color; -#endif - -#ifdef ATTRIBUTE_A_RADIUS -attribute mediump float a_radius; -#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_RADIUS -uniform lowp float u_radius_t; -attribute mediump vec4 a_radius; -#else -uniform mediump float a_radius; -#endif +#pragma mapbox: define color lowp +#pragma mapbox: define radius mediump varying vec2 v_extrude; -varying lowp vec4 v_color; varying lowp float v_antialiasblur; -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} - -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - void main(void) { -#ifdef ATTRIBUTE_A_RADIUS - mediump float radius = a_radius / 10.0; -#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_RADIUS - mediump float radius = evaluate_zoom_function_1(a_radius, u_radius_t) / 10.0; -#else - mediump float radius = a_radius; -#endif + #pragma mapbox: initialize color + #pragma mapbox: initialize radius // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); @@ -71,14 +27,6 @@ void main(void) { gl_Position.xy += extrude; -#ifdef ATTRIBUTE_A_COLOR - v_color = a_color / 255.0; -#elif defined ATTRIBUTE_ZOOM_FUNCTION_A_COLOR0 - v_color = evaluate_zoom_function_4(a_color0, a_color1, a_color2, a_color3, u_color_t) / 255.0; -#else - v_color = a_color; -#endif - // 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. diff --git a/util.vertex.glsl b/util.vertex.glsl new file mode 100644 index 00000000000..61ae80755bf --- /dev/null +++ b/util.vertex.glsl @@ -0,0 +1,18 @@ +float evaluate_zoom_function_1(const vec4 values, const float t) { + if (t < 1.0) { + return mix(values[0], values[1], t); + } else if (t < 2.0) { + return mix(values[1], values[2], t - 1.0); + } else { + return mix(values[2], values[3], t - 2.0); + } +} +vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { + if (t < 1.0) { + return mix(value0, value1, t); + } else if (t < 2.0) { + return mix(value1, value2, t - 1.0); + } else { + return mix(value2, value3, t - 2.0); + } +} From 303404bf922ab274db5649d9b0cccf8d3d6d1031 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 May 2016 13:31:44 -0700 Subject: [PATCH 213/259] Port https://github.com/mapbox/mapbox-gl-native/commit/2700ea87a4e6abb9c8ea8520fe92b067be022935 (#2598) --- sdf.vertex.glsl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sdf.vertex.glsl b/sdf.vertex.glsl index 58f26ccf22d..2bf080917ee 100644 --- a/sdf.vertex.glsl +++ b/sdf.vertex.glsl @@ -12,7 +12,6 @@ uniform mat4 u_matrix; uniform mediump float u_zoom; uniform bool u_skewed; -uniform float u_extra; uniform vec2 u_extrude_scale; uniform vec2 u_texsize; @@ -39,11 +38,7 @@ void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); } - // position of y on the screen - float y = gl_Position.y / gl_Position.w; - // how much features are squished in all directions by the perspectiveness - float perspective_scale = 1.0 / (1.0 - y * u_extra); - v_gamma_scale = perspective_scale; + v_gamma_scale = (gl_Position.w - 0.5); v_tex = a_tex / u_texsize; v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0); From 57576d602b2239fa4854f69f2edc72b1267c3e1a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 20 May 2016 17:53:31 -0700 Subject: [PATCH 214/259] Organize as node package --- index.js | 60 +++++++++++++++++++ package.json | 27 +++++++++ .../circle.fragment.glsl | 0 circle.vertex.glsl => src/circle.vertex.glsl | 0 .../collisionbox.fragment.glsl | 0 .../collisionbox.vertex.glsl | 0 .../debug.fragment.glsl | 0 debug.vertex.glsl => src/debug.vertex.glsl | 0 fill.fragment.glsl => src/fill.fragment.glsl | 0 fill.vertex.glsl => src/fill.vertex.glsl | 0 icon.fragment.glsl => src/icon.fragment.glsl | 0 icon.vertex.glsl => src/icon.vertex.glsl | 0 line.fragment.glsl => src/line.fragment.glsl | 0 line.vertex.glsl => src/line.vertex.glsl | 0 .../linepattern.fragment.glsl | 0 .../linepattern.vertex.glsl | 0 .../linesdfpattern.fragment.glsl | 0 .../linesdfpattern.vertex.glsl | 0 .../outline.fragment.glsl | 0 .../outline.vertex.glsl | 0 .../outlinepattern.fragment.glsl | 0 .../outlinepattern.vertex.glsl | 0 .../pattern.fragment.glsl | 0 .../pattern.vertex.glsl | 0 .../raster.fragment.glsl | 0 raster.vertex.glsl => src/raster.vertex.glsl | 0 sdf.fragment.glsl => src/sdf.fragment.glsl | 0 sdf.vertex.glsl => src/sdf.vertex.glsl | 0 28 files changed, 87 insertions(+) create mode 100644 index.js create mode 100644 package.json rename circle.fragment.glsl => src/circle.fragment.glsl (100%) rename circle.vertex.glsl => src/circle.vertex.glsl (100%) rename collisionbox.fragment.glsl => src/collisionbox.fragment.glsl (100%) rename collisionbox.vertex.glsl => src/collisionbox.vertex.glsl (100%) rename debug.fragment.glsl => src/debug.fragment.glsl (100%) rename debug.vertex.glsl => src/debug.vertex.glsl (100%) rename fill.fragment.glsl => src/fill.fragment.glsl (100%) rename fill.vertex.glsl => src/fill.vertex.glsl (100%) rename icon.fragment.glsl => src/icon.fragment.glsl (100%) rename icon.vertex.glsl => src/icon.vertex.glsl (100%) rename line.fragment.glsl => src/line.fragment.glsl (100%) rename line.vertex.glsl => src/line.vertex.glsl (100%) rename linepattern.fragment.glsl => src/linepattern.fragment.glsl (100%) rename linepattern.vertex.glsl => src/linepattern.vertex.glsl (100%) rename linesdfpattern.fragment.glsl => src/linesdfpattern.fragment.glsl (100%) rename linesdfpattern.vertex.glsl => src/linesdfpattern.vertex.glsl (100%) rename outline.fragment.glsl => src/outline.fragment.glsl (100%) rename outline.vertex.glsl => src/outline.vertex.glsl (100%) rename outlinepattern.fragment.glsl => src/outlinepattern.fragment.glsl (100%) rename outlinepattern.vertex.glsl => src/outlinepattern.vertex.glsl (100%) rename pattern.fragment.glsl => src/pattern.fragment.glsl (100%) rename pattern.vertex.glsl => src/pattern.vertex.glsl (100%) rename raster.fragment.glsl => src/raster.fragment.glsl (100%) rename raster.vertex.glsl => src/raster.vertex.glsl (100%) rename sdf.fragment.glsl => src/sdf.fragment.glsl (100%) rename sdf.vertex.glsl => src/sdf.vertex.glsl (100%) diff --git a/index.js b/index.js new file mode 100644 index 00000000000..edc7ccf6f9b --- /dev/null +++ b/index.js @@ -0,0 +1,60 @@ +var fs = require('fs'); +var path = require('path'); + +// readFileSync calls must be written out long-form for brfs. +module.exports = { + debug: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/debug.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/debug.vertex.glsl'), 'utf8') + }, + fill: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill.vertex.glsl'), 'utf8') + }, + circle: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/circle.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/circle.vertex.glsl'), 'utf8') + }, + line: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/line.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/line.vertex.glsl'), 'utf8') + }, + linepattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/linepattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/linepattern.vertex.glsl'), 'utf8') + }, + linesdfpattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/linesdfpattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/linesdfpattern.vertex.glsl'), 'utf8') + }, + outline: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/outline.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/outline.vertex.glsl'), 'utf8') + }, + outlinepattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/outlinepattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/outlinepattern.vertex.glsl'), 'utf8') + }, + pattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/pattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/pattern.vertex.glsl'), 'utf8') + }, + raster: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/raster.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/raster.vertex.glsl'), 'utf8') + }, + icon: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/icon.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/icon.vertex.glsl'), 'utf8') + }, + sdf: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/sdf.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/sdf.vertex.glsl'), 'utf8') + }, + collisionbox: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/collisionbox.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/collisionbox.vertex.glsl'), 'utf8') + } +}; + +module.exports.util = fs.readFileSync(path.join(__dirname, 'util.vertex.glsl'), 'utf8'); diff --git a/package.json b/package.json new file mode 100644 index 00000000000..27fbf9d037b --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "mapbox-gl-shaders", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mapbox/mapbox-gl-shaders.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/mapbox/mapbox-gl-shaders/issues" + }, + "homepage": "https://github.com/mapbox/mapbox-gl-shaders#readme", + "dependencies": { + "brfs": "^1.4.0" + }, + "browserify": { + "transform": [ + "brfs" + ] + } +} diff --git a/circle.fragment.glsl b/src/circle.fragment.glsl similarity index 100% rename from circle.fragment.glsl rename to src/circle.fragment.glsl diff --git a/circle.vertex.glsl b/src/circle.vertex.glsl similarity index 100% rename from circle.vertex.glsl rename to src/circle.vertex.glsl diff --git a/collisionbox.fragment.glsl b/src/collisionbox.fragment.glsl similarity index 100% rename from collisionbox.fragment.glsl rename to src/collisionbox.fragment.glsl diff --git a/collisionbox.vertex.glsl b/src/collisionbox.vertex.glsl similarity index 100% rename from collisionbox.vertex.glsl rename to src/collisionbox.vertex.glsl diff --git a/debug.fragment.glsl b/src/debug.fragment.glsl similarity index 100% rename from debug.fragment.glsl rename to src/debug.fragment.glsl diff --git a/debug.vertex.glsl b/src/debug.vertex.glsl similarity index 100% rename from debug.vertex.glsl rename to src/debug.vertex.glsl diff --git a/fill.fragment.glsl b/src/fill.fragment.glsl similarity index 100% rename from fill.fragment.glsl rename to src/fill.fragment.glsl diff --git a/fill.vertex.glsl b/src/fill.vertex.glsl similarity index 100% rename from fill.vertex.glsl rename to src/fill.vertex.glsl diff --git a/icon.fragment.glsl b/src/icon.fragment.glsl similarity index 100% rename from icon.fragment.glsl rename to src/icon.fragment.glsl diff --git a/icon.vertex.glsl b/src/icon.vertex.glsl similarity index 100% rename from icon.vertex.glsl rename to src/icon.vertex.glsl diff --git a/line.fragment.glsl b/src/line.fragment.glsl similarity index 100% rename from line.fragment.glsl rename to src/line.fragment.glsl diff --git a/line.vertex.glsl b/src/line.vertex.glsl similarity index 100% rename from line.vertex.glsl rename to src/line.vertex.glsl diff --git a/linepattern.fragment.glsl b/src/linepattern.fragment.glsl similarity index 100% rename from linepattern.fragment.glsl rename to src/linepattern.fragment.glsl diff --git a/linepattern.vertex.glsl b/src/linepattern.vertex.glsl similarity index 100% rename from linepattern.vertex.glsl rename to src/linepattern.vertex.glsl diff --git a/linesdfpattern.fragment.glsl b/src/linesdfpattern.fragment.glsl similarity index 100% rename from linesdfpattern.fragment.glsl rename to src/linesdfpattern.fragment.glsl diff --git a/linesdfpattern.vertex.glsl b/src/linesdfpattern.vertex.glsl similarity index 100% rename from linesdfpattern.vertex.glsl rename to src/linesdfpattern.vertex.glsl diff --git a/outline.fragment.glsl b/src/outline.fragment.glsl similarity index 100% rename from outline.fragment.glsl rename to src/outline.fragment.glsl diff --git a/outline.vertex.glsl b/src/outline.vertex.glsl similarity index 100% rename from outline.vertex.glsl rename to src/outline.vertex.glsl diff --git a/outlinepattern.fragment.glsl b/src/outlinepattern.fragment.glsl similarity index 100% rename from outlinepattern.fragment.glsl rename to src/outlinepattern.fragment.glsl diff --git a/outlinepattern.vertex.glsl b/src/outlinepattern.vertex.glsl similarity index 100% rename from outlinepattern.vertex.glsl rename to src/outlinepattern.vertex.glsl diff --git a/pattern.fragment.glsl b/src/pattern.fragment.glsl similarity index 100% rename from pattern.fragment.glsl rename to src/pattern.fragment.glsl diff --git a/pattern.vertex.glsl b/src/pattern.vertex.glsl similarity index 100% rename from pattern.vertex.glsl rename to src/pattern.vertex.glsl diff --git a/raster.fragment.glsl b/src/raster.fragment.glsl similarity index 100% rename from raster.fragment.glsl rename to src/raster.fragment.glsl diff --git a/raster.vertex.glsl b/src/raster.vertex.glsl similarity index 100% rename from raster.vertex.glsl rename to src/raster.vertex.glsl diff --git a/sdf.fragment.glsl b/src/sdf.fragment.glsl similarity index 100% rename from sdf.fragment.glsl rename to src/sdf.fragment.glsl diff --git a/sdf.vertex.glsl b/src/sdf.vertex.glsl similarity index 100% rename from sdf.vertex.glsl rename to src/sdf.vertex.glsl From 93e3a7b62ee252b7843515c01d16af7958d39580 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 May 2016 12:09:10 -0700 Subject: [PATCH 215/259] Add common preamble for GL ES precision --- src/circle.fragment.glsl | 10 ++++++++-- src/circle.vertex.glsl | 10 ++++++++-- src/collisionbox.fragment.glsl | 8 ++++++-- src/collisionbox.vertex.glsl | 8 ++++++-- src/debug.fragment.glsl | 10 ++++++++-- src/debug.vertex.glsl | 10 ++++++++-- src/fill.fragment.glsl | 10 ++++++++-- src/fill.vertex.glsl | 10 ++++++++-- src/icon.fragment.glsl | 8 ++++++-- src/icon.vertex.glsl | 8 ++++++-- src/line.fragment.glsl | 10 ++++++++-- src/line.vertex.glsl | 8 ++++++-- src/linepattern.fragment.glsl | 10 ++++++++-- src/linepattern.vertex.glsl | 8 ++++++-- src/linesdfpattern.fragment.glsl | 10 ++++++++-- src/linesdfpattern.vertex.glsl | 8 ++++++-- src/outline.fragment.glsl | 10 ++++++++-- src/outline.vertex.glsl | 8 ++++++-- src/outlinepattern.fragment.glsl | 8 ++++++-- src/outlinepattern.vertex.glsl | 10 ++++++++-- src/pattern.fragment.glsl | 8 ++++++-- src/pattern.vertex.glsl | 10 ++++++++-- src/raster.fragment.glsl | 10 ++++++++-- src/raster.vertex.glsl | 8 ++++++-- src/sdf.fragment.glsl | 8 ++++++-- src/sdf.vertex.glsl | 8 ++++++-- 26 files changed, 182 insertions(+), 52 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index f32ae2b8d0c..5ed7d36df97 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -1,10 +1,16 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec4 u_color; uniform float u_blur; uniform float u_size; #else -precision mediump float; - uniform lowp float u_blur; uniform lowp float u_opacity; #endif diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index 3077b2800af..b90dbdb0c31 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -1,9 +1,15 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS // set by gl_util uniform float u_size; #else -precision highp float; - uniform mat4 u_matrix; uniform vec2 u_extrude_scale; uniform float u_devicepixelratio; diff --git a/src/collisionbox.fragment.glsl b/src/collisionbox.fragment.glsl index 0dfb6aedd2e..5b8be6c824b 100644 --- a/src/collisionbox.fragment.glsl +++ b/src/collisionbox.fragment.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision mediump float; - +#else +#define lowp +#define mediump +#define highp #endif + uniform float u_zoom; uniform float u_maxzoom; diff --git a/src/collisionbox.vertex.glsl b/src/collisionbox.vertex.glsl index c743de8fab0..d56579279b9 100644 --- a/src/collisionbox.vertex.glsl +++ b/src/collisionbox.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + attribute vec2 a_pos; attribute vec2 a_extrude; attribute vec2 a_data; diff --git a/src/debug.fragment.glsl b/src/debug.fragment.glsl index 22c486d6107..18506c6060a 100644 --- a/src/debug.fragment.glsl +++ b/src/debug.fragment.glsl @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec4 u_color; uniform float u_blur; -#else -precision mediump float; #endif #ifndef MAPBOX_GL_JS diff --git a/src/debug.vertex.glsl b/src/debug.vertex.glsl index 716966a1384..b34649f1591 100644 --- a/src/debug.vertex.glsl +++ b/src/debug.vertex.glsl @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform mat4 u_matrix; uniform float u_size; -#else -precision highp float; #endif attribute vec2 a_pos; diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index bed6114d577..1ab030115b2 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec4 u_color; #else -precision mediump float; - uniform lowp vec4 u_color; uniform lowp float u_opacity; #endif diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index d54ac7e4767..e07aea4d5ec 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -1,7 +1,13 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS attribute vec2 a_pos; -#else -precision highp float; #endif #ifdef MAPBOX_GL_JS diff --git a/src/icon.fragment.glsl b/src/icon.fragment.glsl index 0d9c716027e..f9100ca2f6c 100644 --- a/src/icon.fragment.glsl +++ b/src/icon.fragment.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision mediump float; - +#else +#define lowp +#define mediump +#define highp #endif + uniform sampler2D u_texture; uniform sampler2D u_fadetexture; #ifndef MAPBOX_GL_JS diff --git a/src/icon.vertex.glsl b/src/icon.vertex.glsl index 49819896c8d..f8c787971c7 100644 --- a/src/icon.vertex.glsl +++ b/src/icon.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index 5a66756bd4c..49432d6df25 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -1,9 +1,15 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec2 u_linewidth; uniform vec4 u_color; #else -precision mediump float; - uniform lowp vec4 u_color; uniform lowp float u_opacity; #endif diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index 18e2c3f91a4..6e9c289c642 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/src/linepattern.fragment.glsl b/src/linepattern.fragment.glsl index 97eaef80e2c..138d8784cfe 100644 --- a/src/linepattern.fragment.glsl +++ b/src/linepattern.fragment.glsl @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec2 u_linewidth; #else -precision mediump float; - uniform float u_point; #endif uniform float u_blur; diff --git a/src/linepattern.vertex.glsl b/src/linepattern.vertex.glsl index 37ef8c57a02..c3066e7a202 100644 --- a/src/linepattern.vertex.glsl +++ b/src/linepattern.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/src/linesdfpattern.fragment.glsl b/src/linesdfpattern.fragment.glsl index f62e1e1be83..f9fb15467f4 100644 --- a/src/linesdfpattern.fragment.glsl +++ b/src/linesdfpattern.fragment.glsl @@ -1,9 +1,15 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec2 u_linewidth; uniform vec4 u_color; #else -precision mediump float; - uniform lowp vec4 u_color; uniform lowp float u_opacity; #endif diff --git a/src/linesdfpattern.vertex.glsl b/src/linesdfpattern.vertex.glsl index 269a46beeef..eb7d0bd23ed 100644 --- a/src/linesdfpattern.vertex.glsl +++ b/src/linesdfpattern.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 285aca1fb0e..5f47553cc2e 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec4 u_color; #else -precision mediump float; - uniform lowp vec4 u_color; uniform lowp float u_opacity; #endif diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index ae8dc8d19fc..8009acdafad 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + attribute vec2 a_pos; #ifdef MAPBOX_GL_JS diff --git a/src/outlinepattern.fragment.glsl b/src/outlinepattern.fragment.glsl index 977c954090d..fc52da40ebd 100644 --- a/src/outlinepattern.fragment.glsl +++ b/src/outlinepattern.fragment.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision mediump float; - +#else +#define lowp +#define mediump +#define highp #endif + uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; diff --git a/src/outlinepattern.vertex.glsl b/src/outlinepattern.vertex.glsl index bc1304997d2..633100580b2 100644 --- a/src/outlinepattern.vertex.glsl +++ b/src/outlinepattern.vertex.glsl @@ -1,11 +1,17 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform vec2 u_patternscale_a; uniform vec2 u_patternscale_b; uniform vec2 u_offset_a; uniform vec2 u_offset_b; #else -precision highp float; - uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; uniform vec2 u_pixel_coord_upper; diff --git a/src/pattern.fragment.glsl b/src/pattern.fragment.glsl index 7ff509d463c..5321e902b69 100644 --- a/src/pattern.fragment.glsl +++ b/src/pattern.fragment.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision mediump float; - +#else +#define lowp +#define mediump +#define highp #endif + uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; diff --git a/src/pattern.vertex.glsl b/src/pattern.vertex.glsl index 9a43fed5861..1bea440ae3b 100644 --- a/src/pattern.vertex.glsl +++ b/src/pattern.vertex.glsl @@ -1,9 +1,15 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform mat4 u_matrix; uniform vec2 u_patternscale_a; uniform vec2 u_patternscale_b; -#else -precision highp float; #endif #ifndef MAPBOX_GL_JS diff --git a/src/raster.fragment.glsl b/src/raster.fragment.glsl index 6c5fa6230a3..4fe478b8d58 100644 --- a/src/raster.fragment.glsl +++ b/src/raster.fragment.glsl @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + #ifndef MAPBOX_GL_JS uniform sampler2D u_image; uniform float u_opacity; -#else -precision mediump float; #endif #ifndef MAPBOX_GL_JS diff --git a/src/raster.vertex.glsl b/src/raster.vertex.glsl index 285519685a1..3f506843d6b 100644 --- a/src/raster.vertex.glsl +++ b/src/raster.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + uniform mat4 u_matrix; #ifndef MAPBOX_GL_JS uniform float u_buffer; diff --git a/src/sdf.fragment.glsl b/src/sdf.fragment.glsl index c60fbf37416..5cfb56cc648 100644 --- a/src/sdf.fragment.glsl +++ b/src/sdf.fragment.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision mediump float; - +#else +#define lowp +#define mediump +#define highp #endif + uniform sampler2D u_texture; uniform sampler2D u_fadetexture; #ifndef MAPBOX_GL_JS diff --git a/src/sdf.vertex.glsl b/src/sdf.vertex.glsl index 3f21dd579b8..23aef525fe9 100644 --- a/src/sdf.vertex.glsl +++ b/src/sdf.vertex.glsl @@ -1,7 +1,11 @@ -#ifdef MAPBOX_GL_JS +#ifdef GL_ES precision highp float; - +#else +#define lowp +#define mediump +#define highp #endif + attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; From 99bcded79e7d558334bbf8ce863f85c2cf44e79e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 May 2016 12:13:44 -0700 Subject: [PATCH 216/259] Eliminate redundant #ifdef wrapping for OVERDRAW_INSPECTOR --- src/circle.fragment.glsl | 2 +- src/fill.fragment.glsl | 2 +- src/icon.fragment.glsl | 2 -- src/line.fragment.glsl | 4 ++-- src/linepattern.fragment.glsl | 2 -- src/linesdfpattern.fragment.glsl | 2 +- src/outline.fragment.glsl | 2 +- src/outlinepattern.fragment.glsl | 5 ----- src/pattern.fragment.glsl | 2 -- src/raster.fragment.glsl | 2 -- src/sdf.fragment.glsl | 2 +- 11 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 5ed7d36df97..6e0f8f51ff4 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -31,9 +31,9 @@ void main() { float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = color * (1.0 - t) * u_opacity; +#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index 1ab030115b2..90d718915c8 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -18,9 +18,9 @@ void main() { gl_FragColor = u_color; #else gl_FragColor = u_color * u_opacity; +#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/icon.fragment.glsl b/src/icon.fragment.glsl index f9100ca2f6c..65248c4161b 100644 --- a/src/icon.fragment.glsl +++ b/src/icon.fragment.glsl @@ -24,10 +24,8 @@ void main() { lowp float alpha = texture2D(u_fadetexture, v_fade_tex).a * u_opacity; #endif gl_FragColor = texture2D(u_texture, v_tex) * alpha; -#ifdef MAPBOX_GL_JS #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index 49432d6df25..590fc059d47 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -43,9 +43,9 @@ void main() { #ifndef MAPBOX_GL_JS gl_FragColor = u_color * alpha; -#else +#endif + #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/linepattern.fragment.glsl b/src/linepattern.fragment.glsl index 138d8784cfe..92379eaf2ae 100644 --- a/src/linepattern.fragment.glsl +++ b/src/linepattern.fragment.glsl @@ -79,10 +79,8 @@ void main() { alpha *= u_opacity; gl_FragColor = color * alpha; -#ifdef MAPBOX_GL_JS #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/linesdfpattern.fragment.glsl b/src/linesdfpattern.fragment.glsl index f9fb15467f4..3cdb1f0db2c 100644 --- a/src/linesdfpattern.fragment.glsl +++ b/src/linesdfpattern.fragment.glsl @@ -53,9 +53,9 @@ void main() { gl_FragColor = u_color * alpha; #else gl_FragColor = u_color * (alpha * u_opacity); +#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 5f47553cc2e..4555d6b751e 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -22,9 +22,9 @@ void main() { gl_FragColor = u_color * alpha; #else gl_FragColor = u_color * (alpha * u_opacity); +#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/outlinepattern.fragment.glsl b/src/outlinepattern.fragment.glsl index fc52da40ebd..a7624597029 100644 --- a/src/outlinepattern.fragment.glsl +++ b/src/outlinepattern.fragment.glsl @@ -35,13 +35,8 @@ void main() { gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; -#ifndef MAPBOX_GL_JS -} -#else - #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif } -#endif diff --git a/src/pattern.fragment.glsl b/src/pattern.fragment.glsl index 5321e902b69..bb1c7187bd5 100644 --- a/src/pattern.fragment.glsl +++ b/src/pattern.fragment.glsl @@ -29,10 +29,8 @@ void main() { vec4 color2 = texture2D(u_image, pos2); gl_FragColor = mix(color1, color2, u_mix) * u_opacity; -#ifdef MAPBOX_GL_JS #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/raster.fragment.glsl b/src/raster.fragment.glsl index 4fe478b8d58..7b23f9a8487 100644 --- a/src/raster.fragment.glsl +++ b/src/raster.fragment.glsl @@ -59,10 +59,8 @@ void main() { vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high); gl_FragColor = vec4(mix(u_high_vec, u_low_vec, rgb), color.a); -#ifdef MAPBOX_GL_JS #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } diff --git a/src/sdf.fragment.glsl b/src/sdf.fragment.glsl index 5cfb56cc648..19737e0905c 100644 --- a/src/sdf.fragment.glsl +++ b/src/sdf.fragment.glsl @@ -36,9 +36,9 @@ void main() { lowp float gamma = u_gamma * v_gamma_scale; lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; gl_FragColor = u_color * (alpha * u_opacity); +#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); #endif -#endif } From f5851e885ef46178908892d920ba427f5f948652 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 May 2016 12:16:38 -0700 Subject: [PATCH 217/259] Eliminate whitespace only differences --- src/collisionbox.vertex.glsl | 9 --------- src/fill.vertex.glsl | 5 ----- src/linesdfpattern.vertex.glsl | 3 --- src/outline.vertex.glsl | 6 ------ src/pattern.vertex.glsl | 3 --- 5 files changed, 26 deletions(-) diff --git a/src/collisionbox.vertex.glsl b/src/collisionbox.vertex.glsl index d56579279b9..33eaf2dd48d 100644 --- a/src/collisionbox.vertex.glsl +++ b/src/collisionbox.vertex.glsl @@ -17,17 +17,8 @@ varying float v_max_zoom; varying float v_placement_zoom; void main() { -#ifndef MAPBOX_GL_JS gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0); -#else - gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0); -#endif -#ifndef MAPBOX_GL_JS v_max_zoom = a_data.x; v_placement_zoom = a_data.y; -#else - v_max_zoom = a_data.x; - v_placement_zoom = a_data.y; -#endif } diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index e07aea4d5ec..b0a6e124535 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -6,13 +6,8 @@ precision highp float; #define highp #endif -#ifndef MAPBOX_GL_JS attribute vec2 a_pos; -#endif -#ifdef MAPBOX_GL_JS -attribute vec2 a_pos; -#endif uniform mat4 u_matrix; void main() { diff --git a/src/linesdfpattern.vertex.glsl b/src/linesdfpattern.vertex.glsl index eb7d0bd23ed..211c40860a7 100644 --- a/src/linesdfpattern.vertex.glsl +++ b/src/linesdfpattern.vertex.glsl @@ -43,9 +43,6 @@ uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; -#ifndef MAPBOX_GL_JS - -#endif uniform float u_extra; uniform mat2 u_antialiasingmatrix; #ifdef MAPBOX_GL_JS diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index 8009acdafad..df5ae343c00 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -7,9 +7,7 @@ precision highp float; #endif attribute vec2 a_pos; -#ifdef MAPBOX_GL_JS -#endif uniform mat4 u_matrix; uniform vec2 u_world; @@ -17,9 +15,5 @@ varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); -#ifndef MAPBOX_GL_JS v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; -#else - v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; -#endif } diff --git a/src/pattern.vertex.glsl b/src/pattern.vertex.glsl index 1bea440ae3b..eb801ec76e0 100644 --- a/src/pattern.vertex.glsl +++ b/src/pattern.vertex.glsl @@ -10,9 +10,6 @@ precision highp float; uniform mat4 u_matrix; uniform vec2 u_patternscale_a; uniform vec2 u_patternscale_b; -#endif - -#ifndef MAPBOX_GL_JS uniform vec2 u_offset_a; uniform vec2 u_offset_b; #else From ba03d7de1340a7005ef477e7d30a0642df154624 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 May 2016 14:54:15 -0700 Subject: [PATCH 218/259] Resolve diffs resulting from precision specifiers --- src/icon.fragment.glsl | 8 -------- src/icon.vertex.glsl | 16 +--------------- src/line.vertex.glsl | 14 -------------- src/linepattern.vertex.glsl | 6 ------ src/linesdfpattern.vertex.glsl | 10 ---------- src/outline.fragment.glsl | 4 +--- src/sdf.fragment.glsl | 19 ++++++------------- src/sdf.vertex.glsl | 12 +----------- 8 files changed, 9 insertions(+), 80 deletions(-) diff --git a/src/icon.fragment.glsl b/src/icon.fragment.glsl index 65248c4161b..3a30054b425 100644 --- a/src/icon.fragment.glsl +++ b/src/icon.fragment.glsl @@ -8,21 +8,13 @@ precision mediump float; uniform sampler2D u_texture; uniform sampler2D u_fadetexture; -#ifndef MAPBOX_GL_JS -uniform float u_opacity; -#else uniform lowp float u_opacity; -#endif varying vec2 v_tex; varying vec2 v_fade_tex; void main() { -#ifndef MAPBOX_GL_JS - float alpha = texture2D(u_fadetexture, v_fade_tex).a * u_opacity; -#else lowp float alpha = texture2D(u_fadetexture, v_fade_tex).a * u_opacity; -#endif gl_FragColor = texture2D(u_texture, v_tex) * alpha; #ifdef OVERDRAW_INSPECTOR diff --git a/src/icon.vertex.glsl b/src/icon.vertex.glsl index f8c787971c7..dce4f183e46 100644 --- a/src/icon.vertex.glsl +++ b/src/icon.vertex.glsl @@ -17,11 +17,9 @@ attribute vec4 a_data2; uniform mat4 u_matrix; #ifndef MAPBOX_GL_JS uniform mat4 u_exmatrix; -uniform float u_zoom; -#else +#endif uniform mediump float u_zoom; -#endif uniform bool u_skewed; uniform float u_extra; #ifdef MAPBOX_GL_JS @@ -35,25 +33,13 @@ varying vec2 v_fade_tex; void main() { vec2 a_tex = a_data1.xy; -#ifndef MAPBOX_GL_JS - float a_labelminzoom = a_data1[2]; - float a_angle = a_data1[3]; - vec2 a_zoom = a_data2.st; - float a_minzoom = a_zoom[0]; - float a_maxzoom = a_zoom[1]; -#else mediump float a_labelminzoom = a_data1[2]; mediump vec2 a_zoom = a_data2.st; mediump float a_minzoom = a_zoom[0]; mediump float a_maxzoom = a_zoom[1]; -#endif // u_zoom is the current zoom level adjusted for the change in font size -#ifndef MAPBOX_GL_JS - float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); -#else mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); -#endif #ifdef MAPBOX_GL_JS vec2 extrude = u_extrude_scale * (a_offset / 64.0); diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index 6e9c289c642..52be63d93ba 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -53,11 +53,7 @@ void main() { // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down -#ifndef MAPBOX_GL_JS - vec2 normal = mod(a_pos, 2.0); -#else mediump vec2 normal = mod(a_pos, 2.0); -#endif normal.y = sign(normal.y - 0.5); v_normal = normal; @@ -78,15 +74,9 @@ void main() { // We do this by creating a vector that points towards the extrude, but rotate // it when we're drawing round end points (a_direction = -1 or 1) since their // extrude vector points in another direction. -#ifndef MAPBOX_GL_JS - float u = 0.5 * a_direction; - float t = 1.0 - abs(u); - vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); -#else mediump float u = 0.5 * a_direction; mediump float t = 1.0 - abs(u); mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); -#endif // Remove the texture normal bit of the position before scaling it with the #ifndef MAPBOX_GL_JS @@ -106,11 +96,7 @@ void main() { float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); // how much features are squished in all directions by the perspectiveness -#ifndef MAPBOX_GL_JS - float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.90)); -#else float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); -#endif #ifdef MAPBOX_GL_JS v_linewidth = vec2(outset, inset); diff --git a/src/linepattern.vertex.glsl b/src/linepattern.vertex.glsl index c3066e7a202..cac84a94b97 100644 --- a/src/linepattern.vertex.glsl +++ b/src/linepattern.vertex.glsl @@ -90,15 +90,9 @@ void main() { // We do this by creating a vector that points towards the extrude, but rotate // it when we're drawing round end points (a_direction = -1 or 1) since their // extrude vector points in another direction. -#ifndef MAPBOX_GL_JS - float u = 0.5 * a_direction; - float t = 1.0 - abs(u); - vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); -#else mediump float u = 0.5 * a_direction; mediump float t = 1.0 - abs(u); mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); -#endif // Remove the texture normal bit of the position before scaling it with the #ifndef MAPBOX_GL_JS diff --git a/src/linesdfpattern.vertex.glsl b/src/linesdfpattern.vertex.glsl index 211c40860a7..51e4a24541f 100644 --- a/src/linesdfpattern.vertex.glsl +++ b/src/linesdfpattern.vertex.glsl @@ -66,11 +66,7 @@ void main() { // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down -#ifndef MAPBOX_GL_JS - vec2 normal = mod(a_pos, 2.0); -#else mediump vec2 normal = mod(a_pos, 2.0); -#endif normal.y = sign(normal.y - 0.5); v_normal = normal; @@ -91,15 +87,9 @@ void main() { // We do this by creating a vector that points towards the extrude, but rotate // it when we're drawing round end points (a_direction = -1 or 1) since their // extrude vector points in another direction. -#ifndef MAPBOX_GL_JS - float u = 0.5 * a_direction; - float t = 1.0 - abs(u); - vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); -#else mediump float u = 0.5 * a_direction; mediump float t = 1.0 - abs(u); mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); -#endif // Remove the texture normal bit of the position before scaling it with the #ifndef MAPBOX_GL_JS diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 4555d6b751e..401aaf5b957 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -6,10 +6,8 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec4 u_color; -#else uniform lowp vec4 u_color; +#ifdef MAPBOX_GL_JS uniform lowp float u_opacity; #endif diff --git a/src/sdf.fragment.glsl b/src/sdf.fragment.glsl index 19737e0905c..d34d08f23be 100644 --- a/src/sdf.fragment.glsl +++ b/src/sdf.fragment.glsl @@ -8,33 +8,26 @@ precision mediump float; uniform sampler2D u_texture; uniform sampler2D u_fadetexture; -#ifndef MAPBOX_GL_JS -uniform vec4 u_color; -uniform float u_buffer; -uniform float u_gamma; -#else uniform lowp vec4 u_color; +#ifdef MAPBOX_GL_JS uniform lowp float u_opacity; +#endif uniform lowp float u_buffer; uniform lowp float u_gamma; -#endif varying vec2 v_tex; varying vec2 v_fade_tex; varying float v_gamma_scale; void main() { -#ifndef MAPBOX_GL_JS - float dist = texture2D(u_texture, v_tex).a; - float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a; - float gamma = u_gamma * v_gamma_scale; - float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; - gl_FragColor = u_color * alpha; -#else lowp float dist = texture2D(u_texture, v_tex).a; lowp float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a; lowp float gamma = u_gamma * v_gamma_scale; lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; + +#ifndef MAPBOX_GL_JS + gl_FragColor = u_color * alpha; +#else gl_FragColor = u_color * (alpha * u_opacity); #endif diff --git a/src/sdf.vertex.glsl b/src/sdf.vertex.glsl index 23aef525fe9..77310ea6150 100644 --- a/src/sdf.vertex.glsl +++ b/src/sdf.vertex.glsl @@ -17,11 +17,9 @@ attribute vec4 a_data2; uniform mat4 u_matrix; #ifndef MAPBOX_GL_JS uniform mat4 u_exmatrix; -uniform float u_zoom; -#else +#endif uniform mediump float u_zoom; -#endif uniform bool u_skewed; #ifdef MAPBOX_GL_JS uniform vec2 u_extrude_scale; @@ -35,18 +33,10 @@ varying float v_gamma_scale; void main() { vec2 a_tex = a_data1.xy; -#ifndef MAPBOX_GL_JS - float a_labelminzoom = a_data1[2]; - float a_angle = a_data1[3]; - vec2 a_zoom = a_data2.st; - float a_minzoom = a_zoom[0]; - float a_maxzoom = a_zoom[1]; -#else mediump float a_labelminzoom = a_data1[2]; mediump vec2 a_zoom = a_data2.st; mediump float a_minzoom = a_zoom[0]; mediump float a_maxzoom = a_zoom[1]; -#endif // u_zoom is the current zoom level adjusted for the change in font size #ifndef MAPBOX_GL_JS From 121e4d6e16c02080274b1369037ae85e06798e2f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 24 May 2016 12:53:28 -0700 Subject: [PATCH 219/259] Eliminate conditions from debug shader; not currently used by native --- src/debug.fragment.glsl | 15 --------------- src/debug.vertex.glsl | 11 ----------- 2 files changed, 26 deletions(-) diff --git a/src/debug.fragment.glsl b/src/debug.fragment.glsl index 18506c6060a..fbe40df76e4 100644 --- a/src/debug.fragment.glsl +++ b/src/debug.fragment.glsl @@ -6,23 +6,8 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec4 u_color; -uniform float u_blur; -#endif - -#ifndef MAPBOX_GL_JS -void main() { - float dist = length(gl_PointCoord - 0.5); - float t = smoothstep(0.5, 0.5 - u_blur, dist); -#else uniform lowp vec4 u_color; -#endif -#ifndef MAPBOX_GL_JS - gl_FragColor = u_color * t; -#else void main() { gl_FragColor = u_color; -#endif } diff --git a/src/debug.vertex.glsl b/src/debug.vertex.glsl index b34649f1591..cd0974cb552 100644 --- a/src/debug.vertex.glsl +++ b/src/debug.vertex.glsl @@ -6,21 +6,10 @@ precision highp float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform mat4 u_matrix; -uniform float u_size; -#endif - attribute vec2 a_pos; -#ifndef MAPBOX_GL_JS -void main(void) { - gl_Position = u_matrix * vec4(a_pos, 0, 1); - gl_PointSize = u_size; -#else uniform mat4 u_matrix; void main() { gl_Position = u_matrix * vec4(a_pos, step(32767.0, a_pos.x), 1); -#endif } From 0eda4509d2893adb3aaf92ac68301cdc7722e7b1 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 24 May 2016 13:22:52 -0700 Subject: [PATCH 220/259] Eliminate spurious differences in linepattern shader --- src/linepattern.fragment.glsl | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/linepattern.fragment.glsl b/src/linepattern.fragment.glsl index 92379eaf2ae..4d74600bbe7 100644 --- a/src/linepattern.fragment.glsl +++ b/src/linepattern.fragment.glsl @@ -8,20 +8,13 @@ precision mediump float; #ifndef MAPBOX_GL_JS uniform vec2 u_linewidth; -#else -uniform float u_point; #endif uniform float u_blur; uniform vec2 u_pattern_size_a; -#ifdef MAPBOX_GL_JS uniform vec2 u_pattern_size_b; -#endif uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; -#ifndef MAPBOX_GL_JS -uniform vec2 u_pattern_size_b; -#endif uniform vec2 u_pattern_tl_b; uniform vec2 u_pattern_br_b; uniform float u_fade; @@ -55,26 +48,20 @@ void main() { #endif float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); -#ifndef MAPBOX_GL_JS - float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); - vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); -#endif float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); #ifndef MAPBOX_GL_JS + float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); + vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); #else float y_a = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_a.y); float y_b = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_b.y); - vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); - vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); + vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); + vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); #endif -#ifndef MAPBOX_GL_JS vec4 color = mix(texture2D(u_image, pos_a), texture2D(u_image, pos_b), u_fade); -#else - vec4 color = mix(texture2D(u_image, pos), texture2D(u_image, pos2), u_fade); -#endif alpha *= u_opacity; From d3cdb7f427c7f36ad234b45732b9c77c73440dad Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 24 May 2016 16:43:43 -0700 Subject: [PATCH 221/259] [native] Port "separate u_opacity from u_color" https://github.com/mapbox/mapbox-gl-shaders/commit/0d3412519618a3a1672db9fa21f96f90070cf84c https://github.com/mapbox/mapbox-gl-js/commit/1f5afa7db08a2bdcc492a46e500ff5d020e6f4a2 --- src/circle.fragment.glsl | 16 ++++++---------- src/fill.fragment.glsl | 8 -------- src/line.fragment.glsl | 18 ++++++------------ src/linesdfpattern.fragment.glsl | 17 ++++++----------- src/outline.fragment.glsl | 6 ------ src/sdf.fragment.glsl | 6 ------ 6 files changed, 18 insertions(+), 53 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 6e0f8f51ff4..b4084c9908f 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -6,26 +6,22 @@ precision mediump float; #define highp #endif +uniform lowp float u_blur; +uniform lowp float u_opacity; + #ifndef MAPBOX_GL_JS uniform vec4 u_color; -uniform float u_blur; -uniform float u_size; #else -uniform lowp float u_blur; -uniform lowp float u_opacity; +#pragma mapbox: define color lowp +varying lowp float v_antialiasblur; #endif varying vec2 v_extrude; -#ifdef MAPBOX_GL_JS -varying lowp float v_antialiasblur; - -#pragma mapbox: define color lowp -#endif void main() { #ifndef MAPBOX_GL_JS float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude)); - gl_FragColor = u_color * (1.0 - t); + gl_FragColor = u_color * (1.0 - t) * u_opacity; #else #pragma mapbox: initialize color diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index 90d718915c8..92e7e86c053 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -6,19 +6,11 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec4 u_color; -#else uniform lowp vec4 u_color; uniform lowp float u_opacity; -#endif void main() { -#ifndef MAPBOX_GL_JS - gl_FragColor = u_color; -#else gl_FragColor = u_color * u_opacity; -#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index 590fc059d47..397d2ba5af1 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -6,19 +6,17 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec2 u_linewidth; -uniform vec4 u_color; -#else uniform lowp vec4 u_color; uniform lowp float u_opacity; -#endif uniform float u_blur; -varying vec2 v_normal; -#ifdef MAPBOX_GL_JS +#ifndef MAPBOX_GL_JS +uniform vec2 u_linewidth; +#else varying vec2 v_linewidth; #endif + +varying vec2 v_normal; varying float v_gamma_scale; void main() { @@ -37,13 +35,9 @@ void main() { float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); #else float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); - - gl_FragColor = u_color * (alpha * u_opacity); #endif -#ifndef MAPBOX_GL_JS - gl_FragColor = u_color * alpha; -#endif + gl_FragColor = u_color * (alpha * u_opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/linesdfpattern.fragment.glsl b/src/linesdfpattern.fragment.glsl index 3cdb1f0db2c..ef0d6357254 100644 --- a/src/linesdfpattern.fragment.glsl +++ b/src/linesdfpattern.fragment.glsl @@ -6,22 +6,21 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec2 u_linewidth; -uniform vec4 u_color; -#else uniform lowp vec4 u_color; uniform lowp float u_opacity; -#endif + uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; -varying vec2 v_normal; -#ifdef MAPBOX_GL_JS +#ifndef MAPBOX_GL_JS +uniform vec2 u_linewidth; +#else varying vec2 v_linewidth; #endif + +varying vec2 v_normal; varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; @@ -49,11 +48,7 @@ void main() { float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); -#ifndef MAPBOX_GL_JS - gl_FragColor = u_color * alpha; -#else gl_FragColor = u_color * (alpha * u_opacity); -#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 401aaf5b957..3ef265ae9c2 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -7,20 +7,14 @@ precision mediump float; #endif uniform lowp vec4 u_color; -#ifdef MAPBOX_GL_JS uniform lowp float u_opacity; -#endif varying vec2 v_pos; void main() { float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); -#ifndef MAPBOX_GL_JS - gl_FragColor = u_color * alpha; -#else gl_FragColor = u_color * (alpha * u_opacity); -#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/sdf.fragment.glsl b/src/sdf.fragment.glsl index d34d08f23be..490fc323c76 100644 --- a/src/sdf.fragment.glsl +++ b/src/sdf.fragment.glsl @@ -9,9 +9,7 @@ precision mediump float; uniform sampler2D u_texture; uniform sampler2D u_fadetexture; uniform lowp vec4 u_color; -#ifdef MAPBOX_GL_JS uniform lowp float u_opacity; -#endif uniform lowp float u_buffer; uniform lowp float u_gamma; @@ -25,11 +23,7 @@ void main() { lowp float gamma = u_gamma * v_gamma_scale; lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha; -#ifndef MAPBOX_GL_JS - gl_FragColor = u_color * alpha; -#else gl_FragColor = u_color * (alpha * u_opacity); -#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); From 4a567b438be303fbbf13e5ddf49d72d8debd811d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 24 May 2016 18:28:05 -0700 Subject: [PATCH 222/259] [native] Port "combine line-width and line-gap-width in shader" https://github.com/mapbox/mapbox-gl-shaders/commit/a9559e911b11a155135888f733a96e5110f8cef6 https://github.com/mapbox/mapbox-gl-js/commit/fcb9bcebae6e00f24ebfde8d7ec09adb95f6b1a3 --- src/line.fragment.glsl | 13 ---------- src/line.vertex.glsl | 33 ++---------------------- src/linepattern.fragment.glsl | 20 --------------- src/linepattern.vertex.glsl | 44 ++------------------------------ src/linesdfpattern.fragment.glsl | 15 +---------- src/linesdfpattern.vertex.glsl | 36 ++------------------------ 6 files changed, 7 insertions(+), 154 deletions(-) diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index 397d2ba5af1..ed7a14f7091 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -10,32 +10,19 @@ uniform lowp vec4 u_color; uniform lowp float u_opacity; uniform float u_blur; -#ifndef MAPBOX_GL_JS -uniform vec2 u_linewidth; -#else varying vec2 v_linewidth; -#endif - varying vec2 v_normal; varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. -#ifndef MAPBOX_GL_JS - float dist = length(v_normal) * u_linewidth.s; -#else float dist = length(v_normal) * v_linewidth.s; -#endif // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * v_gamma_scale; -#ifndef MAPBOX_GL_JS - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); -#else float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); -#endif gl_FragColor = u_color * (alpha * u_opacity); diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index 52be63d93ba..87a2e978a38 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -18,31 +18,17 @@ attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; -#ifndef MAPBOX_GL_JS - -// shared -uniform float u_ratio; -uniform vec2 u_linewidth; -uniform float u_offset; - -uniform float u_extra; -#else uniform mediump float u_ratio; uniform mediump float u_linewidth; uniform mediump float u_gapwidth; uniform mediump float u_antialiasing; uniform mediump float u_extra; -#endif uniform mat2 u_antialiasingmatrix; -#ifdef MAPBOX_GL_JS uniform mediump float u_offset; uniform mediump float u_blur; -#endif varying vec2 v_normal; -#ifdef MAPBOX_GL_JS varying vec2 v_linewidth; -#endif varying float v_gamma_scale; void main() { @@ -57,18 +43,12 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; -#ifdef MAPBOX_GL_JS float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; -#endif // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. -#ifndef MAPBOX_GL_JS - vec2 dist = u_linewidth.s * a_extrude * scale; -#else - mediump vec4 dist = vec4(outset * a_extrude * scale, 0.0, 0.0); -#endif + mediump vec2 dist = outset * a_extrude * scale; // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -79,15 +59,8 @@ void main() { mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the -#ifndef MAPBOX_GL_JS - // model/view matrix. Add the extrusion vector *after* the model/view matrix - // because we're extruding the line in pixel space, regardless of the current - // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); -#else // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist.xy) / u_ratio, 0.0, 1.0); -#endif + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); // position of y on the screen float y = gl_Position.y / gl_Position.w; @@ -98,8 +71,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); -#ifdef MAPBOX_GL_JS v_linewidth = vec2(outset, inset); -#endif v_gamma_scale = perspective_scale * squish_scale; } diff --git a/src/linepattern.fragment.glsl b/src/linepattern.fragment.glsl index 4d74600bbe7..4f1815f8548 100644 --- a/src/linepattern.fragment.glsl +++ b/src/linepattern.fragment.glsl @@ -6,9 +6,6 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec2 u_linewidth; -#endif uniform float u_blur; uniform vec2 u_pattern_size_a; @@ -23,43 +20,26 @@ uniform float u_opacity; uniform sampler2D u_image; varying vec2 v_normal; -#ifdef MAPBOX_GL_JS varying vec2 v_linewidth; -#endif varying float v_linesofar; varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. -#ifndef MAPBOX_GL_JS - float dist = length(v_normal) * u_linewidth.s; -#else float dist = length(v_normal) * v_linewidth.s; -#endif // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * v_gamma_scale; -#ifndef MAPBOX_GL_JS - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); -#else float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); -#endif float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); -#ifndef MAPBOX_GL_JS - float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); - float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); - vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); - vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); -#else float y_a = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_a.y); float y_b = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_b.y); vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); -#endif vec4 color = mix(texture2D(u_image, pos_a), texture2D(u_image, pos_b), u_fade); diff --git a/src/linepattern.vertex.glsl b/src/linepattern.vertex.glsl index cac84a94b97..720de53b7f8 100644 --- a/src/linepattern.vertex.glsl +++ b/src/linepattern.vertex.glsl @@ -21,37 +21,17 @@ precision highp float; attribute vec2 a_pos; attribute vec4 a_data; -#ifndef MAPBOX_GL_JS -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. -#endif uniform mat4 u_matrix; -#ifndef MAPBOX_GL_JS -uniform mat4 u_exmatrix; - -// shared -uniform float u_ratio; -uniform vec2 u_linewidth; -uniform float u_offset; -uniform vec4 u_color; - -uniform float u_extra; -#else uniform mediump float u_ratio; uniform mediump float u_linewidth; uniform mediump float u_gapwidth; uniform mediump float u_antialiasing; uniform mediump float u_extra; -#endif uniform mat2 u_antialiasingmatrix; -#ifdef MAPBOX_GL_JS uniform mediump float u_offset; -#endif varying vec2 v_normal; -#ifdef MAPBOX_GL_JS varying vec2 v_linewidth; -#endif varying float v_linesofar; varying float v_gamma_scale; @@ -64,27 +44,16 @@ void main() { // transform y so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down -#ifndef MAPBOX_GL_JS - vec2 normal = mod(a_pos, 2.0); -#else mediump vec2 normal = mod(a_pos, 2.0); -#endif normal.y = sign(normal.y - 0.5); v_normal = normal; -#ifdef MAPBOX_GL_JS float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; -#endif // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. -#ifndef MAPBOX_GL_JS - vec2 dist = u_linewidth.s * a_extrude * scale; -#else - mediump vec2 extrude = a_extrude * scale; - mediump vec2 dist = outset * extrude; -#endif + mediump vec2 dist = outset * a_extrude * scale; // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -95,15 +64,8 @@ void main() { mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the -#ifndef MAPBOX_GL_JS - // model/view matrix. Add the extrusion vector *after* the model/view matrix - // because we're extruding the line in pixel space, regardless of the current - // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + (offset + dist) / u_ratio, 0.0, 1.0); -#else // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist.xy) / u_ratio, 0.0, 1.0); -#endif + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar; // position of y on the screen @@ -119,8 +81,6 @@ void main() { float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); #endif -#ifdef MAPBOX_GL_JS v_linewidth = vec2(outset, inset); -#endif v_gamma_scale = perspective_scale * squish_scale; } diff --git a/src/linesdfpattern.fragment.glsl b/src/linesdfpattern.fragment.glsl index ef0d6357254..246547a91c9 100644 --- a/src/linesdfpattern.fragment.glsl +++ b/src/linesdfpattern.fragment.glsl @@ -14,34 +14,21 @@ uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; -#ifndef MAPBOX_GL_JS -uniform vec2 u_linewidth; -#else -varying vec2 v_linewidth; -#endif - varying vec2 v_normal; +varying vec2 v_linewidth; varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; void main() { // Calculate the distance of the pixel from the line in pixels. -#ifndef MAPBOX_GL_JS - float dist = length(v_normal) * u_linewidth.s; -#else float dist = length(v_normal) * v_linewidth.s; -#endif // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) float blur = u_blur * v_gamma_scale; -#ifndef MAPBOX_GL_JS - float alpha = clamp(min(dist - (u_linewidth.t - blur), u_linewidth.s - dist) / blur, 0.0, 1.0); -#else float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); -#endif float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; diff --git a/src/linesdfpattern.vertex.glsl b/src/linesdfpattern.vertex.glsl index 51e4a24541f..2db91eb24bc 100644 --- a/src/linesdfpattern.vertex.glsl +++ b/src/linesdfpattern.vertex.glsl @@ -21,38 +21,21 @@ precision highp float; attribute vec2 a_pos; attribute vec4 a_data; -#ifndef MAPBOX_GL_JS -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. -#endif uniform mat4 u_matrix; -#ifndef MAPBOX_GL_JS -uniform mat4 u_exmatrix; - -// shared -uniform float u_ratio; -uniform vec2 u_linewidth; -uniform float u_offset; -#else uniform mediump float u_ratio; uniform mediump float u_linewidth; uniform mediump float u_gapwidth; uniform mediump float u_antialiasing; -#endif uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; uniform float u_extra; uniform mat2 u_antialiasingmatrix; -#ifdef MAPBOX_GL_JS uniform mediump float u_offset; -#endif varying vec2 v_normal; -#ifdef MAPBOX_GL_JS varying vec2 v_linewidth; -#endif varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; @@ -70,18 +53,12 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; -#ifdef MAPBOX_GL_JS float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; -#endif // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. -#ifndef MAPBOX_GL_JS - vec2 dist = u_linewidth.s * a_extrude * scale; -#else - mediump vec4 dist = vec4(outset * a_extrude * scale, 0.0, 0.0); -#endif + mediump vec2 dist = outset * a_extrude * scale; // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -92,15 +69,8 @@ void main() { mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the -#ifndef MAPBOX_GL_JS - // model/view matrix. Add the extrusion vector *after* the model/view matrix - // because we're extruding the line in pixel space, regardless of the current - // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); -#else // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist.xy) / u_ratio, 0.0, 1.0); -#endif + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); @@ -114,8 +84,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); -#ifdef MAPBOX_GL_JS v_linewidth = vec2(outset, inset); -#endif v_gamma_scale = perspective_scale * squish_scale; } From 556b3ec8ea48c2135d7111ae650dc09bcbd720ef Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 26 May 2016 16:26:01 -0700 Subject: [PATCH 223/259] Use pragmas for fill-color and fill-outline-color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE FOR GL_NATIVE: The outline shaders’ color attribute has been renamed from “color” to “outline_color” --- src/circle.fragment.glsl | 2 +- src/circle.vertex.glsl | 4 ++-- src/fill.fragment.glsl | 6 ++++-- src/fill.vertex.glsl | 3 +++ src/outline.fragment.glsl | 7 +++++-- src/outline.vertex.glsl | 4 ++++ 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index b4084c9908f..75289a4035a 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -23,7 +23,7 @@ void main() { float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude)); gl_FragColor = u_color * (1.0 - t) * u_opacity; #else - #pragma mapbox: initialize color + #pragma mapbox: initialize color lowp float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = color * (1.0 - t) * u_opacity; diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index b90dbdb0c31..1cab555b9b9 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -33,8 +33,8 @@ varying lowp float v_antialiasblur; void main(void) { #ifdef MAPBOX_GL_JS - #pragma mapbox: initialize color - #pragma mapbox: initialize radius + #pragma mapbox: initialize color lowp + #pragma mapbox: initialize radius mediump #endif // unencode the extrusion vector that we snuck into the a_pos vector diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index 92e7e86c053..bb92dec7bbd 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -6,11 +6,13 @@ precision mediump float; #define highp #endif -uniform lowp vec4 u_color; uniform lowp float u_opacity; +#pragma mapbox: define color lowp void main() { - gl_FragColor = u_color * u_opacity; + #pragma mapbox: initialize color lowp + + gl_FragColor = color * u_opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index b0a6e124535..2cfa5322428 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -10,6 +10,9 @@ attribute vec2 a_pos; uniform mat4 u_matrix; +#pragma mapbox: define color lowp + void main() { + #pragma mapbox: initialize color lowp gl_Position = u_matrix * vec4(a_pos, 0, 1); } diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 3ef265ae9c2..93ffecbc5b5 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -6,15 +6,18 @@ precision mediump float; #define highp #endif -uniform lowp vec4 u_color; uniform lowp float u_opacity; varying vec2 v_pos; +#pragma mapbox: define outline_color lowp + void main() { + #pragma mapbox: initialize outline_color lowp + float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); - gl_FragColor = u_color * (alpha * u_opacity); + gl_FragColor = outline_color * (alpha * u_opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index df5ae343c00..ec5d8ce2d09 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -13,7 +13,11 @@ uniform vec2 u_world; varying vec2 v_pos; +#pragma mapbox: define outline_color lowp + void main() { + #pragma mapbox: initialize outline_color lowp + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } From e4737bb136d718f9c5fe8d943380f05db6249b57 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 27 May 2016 12:15:56 -0700 Subject: [PATCH 224/259] Use ifdef statements to guard GL-JS-specific code --- src/fill.fragment.glsl | 12 +++++++++++- src/fill.vertex.glsl | 6 ++++++ src/outline.fragment.glsl | 13 +++++++++++-- src/outline.vertex.glsl | 5 +++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index bb92dec7bbd..d0fc0cc7990 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -6,11 +6,21 @@ precision mediump float; #define highp #endif -uniform lowp float u_opacity; +#ifdef MAPBOX_GL_JS #pragma mapbox: define color lowp +#else +uniform lowp vec4 u_color; +#endif + +uniform lowp float u_opacity; void main() { + +#ifdef MAPBOX_GL_JS #pragma mapbox: initialize color lowp +#else + lowp vec4 color = u_color; +#endif gl_FragColor = color * u_opacity; diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index 2cfa5322428..fd4ba7f10bd 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -10,9 +10,15 @@ attribute vec2 a_pos; uniform mat4 u_matrix; +#ifdef MAPBOX_GL_JS #pragma mapbox: define color lowp +#endif void main() { + +#ifdef MAPBOX_GL_JS #pragma mapbox: initialize color lowp +#endif + gl_Position = u_matrix * vec4(a_pos, 0, 1); } diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 93ffecbc5b5..753d642528b 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -6,14 +6,23 @@ precision mediump float; #define highp #endif +#ifdef MAPBOX_GL_JS +#pragma mapbox: define outline_color lowp +#else +uniform lowp vec4 u_color; +#endif + uniform lowp float u_opacity; varying vec2 v_pos; -#pragma mapbox: define outline_color lowp - void main() { + +#ifdef MAPBOX_GL_JS #pragma mapbox: initialize outline_color lowp +#else + lowp vec4 outline_color = u_color; +#endif float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index ec5d8ce2d09..d80431a1b6f 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -13,10 +13,15 @@ uniform vec2 u_world; varying vec2 v_pos; +#ifdef MAPBOX_GL_JS #pragma mapbox: define outline_color lowp +#endif + void main() { +#ifdef MAPBOX_GL_JS #pragma mapbox: initialize outline_color lowp +#endif gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; From 13aad76282c1b6c4d38fd46f373325dfec69ab01 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 31 May 2016 15:48:36 +0300 Subject: [PATCH 225/259] Update circle shader code for Mapbox GL native Ported the following patches: - [convert mat4 exMatrix to a vec2 extrudeScale](https://github.com/mapbox/mapbox-gl-shaders/commit/a8d549b7a41540d3a99767975ff1b7b18a6010e9) - [Enabled data-driven styling for circle-radius](https://github.com/mapbox/mapbox-gl-shaders/commit/4356e41fa657837904d189e604468617ee601ddb) - [Reduce shader boilerplate, refactor "Bucket"](https://github.com/mapbox/mapbox-gl-shaders/commit/7d3da8f1914954fd96f305b7116cfd127a616551) --- src/circle.fragment.glsl | 7 +++---- src/circle.vertex.glsl | 28 ++++------------------------ 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 75289a4035a..9339ccc4fd4 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -13,21 +13,20 @@ uniform lowp float u_opacity; uniform vec4 u_color; #else #pragma mapbox: define color lowp -varying lowp float v_antialiasblur; #endif +varying lowp float v_antialiasblur; varying vec2 v_extrude; void main() { #ifndef MAPBOX_GL_JS - float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude)); - gl_FragColor = u_color * (1.0 - t) * u_opacity; + vec4 color = u_color; #else #pragma mapbox: initialize color lowp +#endif float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = color * (1.0 - t) * u_opacity; -#endif #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index 1cab555b9b9..c7a475fdf41 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -6,59 +6,39 @@ precision highp float; #define highp #endif -#ifndef MAPBOX_GL_JS -// set by gl_util -uniform float u_size; -#else uniform mat4 u_matrix; uniform vec2 u_extrude_scale; uniform float u_devicepixelratio; -#endif attribute vec2 a_pos; #ifndef MAPBOX_GL_JS -uniform mat4 u_matrix; -uniform mat4 u_exmatrix; +uniform float u_radius; #else -#pragma mapbox: define color lowp #pragma mapbox: define radius mediump #endif varying vec2 v_extrude; -#ifdef MAPBOX_GL_JS varying lowp float v_antialiasblur; -#endif void main(void) { -#ifdef MAPBOX_GL_JS - - #pragma mapbox: initialize color lowp +#ifndef MAPBOX_GL_JS + float radius = u_radius; +#else #pragma mapbox: initialize radius mediump - #endif // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); -#ifndef MAPBOX_GL_JS - vec4 extrude = u_exmatrix * vec4(v_extrude * u_size, 0, 0); -#else vec2 extrude = v_extrude * radius * u_extrude_scale; -#endif // multiply a_pos by 0.5, since we had it * 2 in order to sneak // in extrusion data gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0, 1); -#ifndef MAPBOX_GL_JS - // 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; -#else gl_Position.xy += extrude; // 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. v_antialiasblur = 1.0 / u_devicepixelratio / radius; -#endif } From 49022d5b92c067b8659f5700a04f376d75f2950e Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 31 May 2016 18:50:00 +0300 Subject: [PATCH 226/259] Update icon shader code for Mapbox GL native Ported the following patch: - [convert mat4 exMatrix to a vec2 extrudeScale](https://github.com/mapbox/mapbox-gl-shaders/commit/a8d549b7a41540d3a99767975ff1b7b18a6010e9) --- src/icon.vertex.glsl | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/icon.vertex.glsl b/src/icon.vertex.glsl index dce4f183e46..bae818c211b 100644 --- a/src/icon.vertex.glsl +++ b/src/icon.vertex.glsl @@ -12,19 +12,12 @@ attribute vec4 a_data1; attribute vec4 a_data2; -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. +// matrix is for the vertex position. uniform mat4 u_matrix; -#ifndef MAPBOX_GL_JS -uniform mat4 u_exmatrix; -#endif uniform mediump float u_zoom; uniform bool u_skewed; -uniform float u_extra; -#ifdef MAPBOX_GL_JS uniform vec2 u_extrude_scale; -#endif uniform vec2 u_texsize; @@ -41,24 +34,12 @@ void main() { // u_zoom is the current zoom level adjusted for the change in font size mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); -#ifdef MAPBOX_GL_JS vec2 extrude = u_extrude_scale * (a_offset / 64.0); -#endif if (u_skewed) { -#ifndef MAPBOX_GL_JS - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0); - gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); -#else gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1); -#endif gl_Position.z += z * gl_Position.w; } else { -#ifndef MAPBOX_GL_JS - vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; -#else gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); -#endif } v_tex = a_tex / u_texsize; From 36278b864e60e1dba937a6863064c03d69526854 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 1 Jun 2016 10:41:42 +0300 Subject: [PATCH 227/259] Update sdf shader code for Mapbox GL native Ported the following patch: - [convert mat4 exMatrix to a vec2 extrudeScale](https://github.com/mapbox/mapbox-gl-shaders/commit/a8d549b7a41540d3a99767975ff1b7b18a6010e9) --- src/sdf.vertex.glsl | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/sdf.vertex.glsl b/src/sdf.vertex.glsl index 77310ea6150..b342cf27477 100644 --- a/src/sdf.vertex.glsl +++ b/src/sdf.vertex.glsl @@ -12,18 +12,12 @@ attribute vec4 a_data1; attribute vec4 a_data2; -// matrix is for the vertex position, exmatrix is for rotating and projecting -// the extrusion vector. +// matrix is for the vertex position. uniform mat4 u_matrix; -#ifndef MAPBOX_GL_JS -uniform mat4 u_exmatrix; -#endif uniform mediump float u_zoom; uniform bool u_skewed; -#ifdef MAPBOX_GL_JS uniform vec2 u_extrude_scale; -#endif uniform vec2 u_texsize; @@ -39,30 +33,14 @@ void main() { mediump float a_maxzoom = a_zoom[1]; // u_zoom is the current zoom level adjusted for the change in font size -#ifndef MAPBOX_GL_JS - float show = step(a_minzoom, u_zoom) * (1.0 - step(a_maxzoom, u_zoom)); -#else mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); -#endif -#ifdef MAPBOX_GL_JS vec2 extrude = u_extrude_scale * (a_offset / 64.0); -#endif if (u_skewed) { -#ifndef MAPBOX_GL_JS - vec4 extrude = u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); - gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1); -#else gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1); gl_Position.z += z * gl_Position.w; -#endif } else { -#ifndef MAPBOX_GL_JS - vec4 extrude = u_exmatrix * vec4(a_offset * show / 64.0, 0, 0); - gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude; -#else gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); -#endif } v_gamma_scale = (gl_Position.w - 0.5); From e032997109c0ead5394ff64f2f0ea6b0f8efdc3f Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 2 Jun 2016 13:29:29 +0300 Subject: [PATCH 228/259] Use "#pragma mapbox:" commands in Mapbox GL Native Part of https://github.com/mapbox/mapbox-gl-native/issues/5174. Fixes #1. --- src/circle.fragment.glsl | 8 -------- src/circle.vertex.glsl | 8 -------- src/fill.fragment.glsl | 10 ---------- src/fill.vertex.glsl | 9 --------- src/outline.fragment.glsl | 9 --------- src/outline.vertex.glsl | 9 --------- 6 files changed, 53 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 9339ccc4fd4..5497ba83486 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -9,21 +9,13 @@ precision mediump float; uniform lowp float u_blur; uniform lowp float u_opacity; -#ifndef MAPBOX_GL_JS -uniform vec4 u_color; -#else #pragma mapbox: define color lowp -#endif varying lowp float v_antialiasblur; varying vec2 v_extrude; void main() { -#ifndef MAPBOX_GL_JS - vec4 color = u_color; -#else #pragma mapbox: initialize color lowp -#endif float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = color * (1.0 - t) * u_opacity; diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index c7a475fdf41..09f8aed2fe4 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -12,21 +12,13 @@ uniform float u_devicepixelratio; attribute vec2 a_pos; -#ifndef MAPBOX_GL_JS -uniform float u_radius; -#else #pragma mapbox: define radius mediump -#endif varying vec2 v_extrude; varying lowp float v_antialiasblur; void main(void) { -#ifndef MAPBOX_GL_JS - float radius = u_radius; -#else #pragma mapbox: initialize radius mediump -#endif // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index d0fc0cc7990..7444c0876b9 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -6,21 +6,11 @@ precision mediump float; #define highp #endif -#ifdef MAPBOX_GL_JS #pragma mapbox: define color lowp -#else -uniform lowp vec4 u_color; -#endif - uniform lowp float u_opacity; void main() { - -#ifdef MAPBOX_GL_JS #pragma mapbox: initialize color lowp -#else - lowp vec4 color = u_color; -#endif gl_FragColor = color * u_opacity; diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index fd4ba7f10bd..b0a6e124535 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -10,15 +10,6 @@ attribute vec2 a_pos; uniform mat4 u_matrix; -#ifdef MAPBOX_GL_JS -#pragma mapbox: define color lowp -#endif - void main() { - -#ifdef MAPBOX_GL_JS - #pragma mapbox: initialize color lowp -#endif - gl_Position = u_matrix * vec4(a_pos, 0, 1); } diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 753d642528b..315a6c1cb14 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -6,23 +6,14 @@ precision mediump float; #define highp #endif -#ifdef MAPBOX_GL_JS #pragma mapbox: define outline_color lowp -#else -uniform lowp vec4 u_color; -#endif uniform lowp float u_opacity; varying vec2 v_pos; void main() { - -#ifdef MAPBOX_GL_JS #pragma mapbox: initialize outline_color lowp -#else - lowp vec4 outline_color = u_color; -#endif float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index d80431a1b6f..df5ae343c00 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -13,16 +13,7 @@ uniform vec2 u_world; varying vec2 v_pos; -#ifdef MAPBOX_GL_JS -#pragma mapbox: define outline_color lowp -#endif - - void main() { -#ifdef MAPBOX_GL_JS - #pragma mapbox: initialize outline_color lowp -#endif - gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } From 996af61d9278693e7af13c12df83b4073ad880e7 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Fri, 3 Jun 2016 20:12:11 +0300 Subject: [PATCH 229/259] Added README.md --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000000..6413c8bd855 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Mapbox GL Shaders + +Shared GL shaders between [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js) +and [Mapbox GL Native](https://github.com/mapbox/mapbox-gl-native). + +## Uniform pragmas + +We use custom pragmas in shader code to define and initialize uniform variables. +These conveniently abstracts away the _Data-Driven Styling_-specific code. These +commands are parsed and generates code readable by the shader compiler. + +Syntax for uniform pragmas is: + +``` +#pragma mapbox: (define|initialize) (lowp|mediump|highp) {type} {name} +``` + +Where: +- {type} is the variable type e.g. `float` or `vec2`. +- {name} is the variable name used inside `main()`. + +Example usage: + +``` +#pragma mapbox: define lowp vec4 color + +void main(void) { + #pragma mapbox: initialize lowp vec4 color + ... + gl_FragColor = color; +} +``` From d151d7774ab5b10a3c6d1d9c69e0e92dd67aaa42 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 3 Jun 2016 11:22:51 -0700 Subject: [PATCH 230/259] Improve README --- README.md | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6413c8bd855..a3c71e78554 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,38 @@ # Mapbox GL Shaders -Shared GL shaders between [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js) -and [Mapbox GL Native](https://github.com/mapbox/mapbox-gl-native). +This repository contains GL shaders which are shared by [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js) and [Mapbox GL Native](https://github.com/mapbox/mapbox-gl-native). -## Uniform pragmas +## Pragmas -We use custom pragmas in shader code to define and initialize uniform variables. -These conveniently abstracts away the _Data-Driven Styling_-specific code. These -commands are parsed and generates code readable by the shader compiler. +Some variables change type depending on their context: -Syntax for uniform pragmas is: + - if the variable is the same for all features, we declare it as a `uniform` + - if the variable is different for each feature, we declare it as an `attribute` + - if the variable is different for each feature and a function of zoom, we declare several `attributes` and `uniforms` then calculate the value using interpolation -``` -#pragma mapbox: (define|initialize) (lowp|mediump|highp) {type} {name} -``` - -Where: -- {type} is the variable type e.g. `float` or `vec2`. -- {name} is the variable name used inside `main()`. +We abstract over this functionality using pragmas. -Example usage: - -``` +```glsl #pragma mapbox: define lowp vec4 color -void main(void) { +main() { #pragma mapbox: initialize lowp vec4 color ... gl_FragColor = color; } ``` + +This program defines a variable within `main` called `color`, initialize the value of `color`, then sets `gl_FragColor` to the value of `color`. + +In general, pragmas take the form defined below. + +```glsl +#pragma mapbox: (define|initialize) (lowp|mediump|highp) (float|vec2|vec3|vec4) {name} +``` + +When using pragmas, the following requirements apply. + + - all pragma-defined variables must have both `define` and `initialize` `#pragmas` + - `define` pragmas must be in file scope + - `initialize` pragmas must be in function scope + - all pragma-defined variables defined and initialized in the fragment shader must also be defined and initialized in the vertex shader because `attribute`s are not accessible from the fragment shader From 6d771686f163c496b01fa6da3f4a8c9d59800136 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 3 Jun 2016 11:32:37 -0700 Subject: [PATCH 231/259] Mention util.glsl in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a3c71e78554..8a7853d1adc 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,7 @@ When using pragmas, the following requirements apply. - `define` pragmas must be in file scope - `initialize` pragmas must be in function scope - all pragma-defined variables defined and initialized in the fragment shader must also be defined and initialized in the vertex shader because `attribute`s are not accessible from the fragment shader + +## Util + +The `util.glsl` file is automatically included in all shaders by the compiler. From 3176002b7e5e04f51c9a64a1263e59d4bd5e37f6 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 3 Jun 2016 14:51:32 -0700 Subject: [PATCH 232/259] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a7853d1adc..c7806bba506 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ main() { This program defines a variable within `main` called `color`, initialize the value of `color`, then sets `gl_FragColor` to the value of `color`. -In general, pragmas take the form defined below. +Pragmas take the following form. ```glsl #pragma mapbox: (define|initialize) (lowp|mediump|highp) (float|vec2|vec3|vec4) {name} @@ -32,7 +32,7 @@ In general, pragmas take the form defined below. When using pragmas, the following requirements apply. - - all pragma-defined variables must have both `define` and `initialize` `#pragmas` + - all pragma-defined variables must have both `define` and `initialize` pragmas - `define` pragmas must be in file scope - `initialize` pragmas must be in function scope - all pragma-defined variables defined and initialized in the fragment shader must also be defined and initialized in the vertex shader because `attribute`s are not accessible from the fragment shader From c48d71ed9d470688d840d7716dfe189056e61196 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 3 Jun 2016 14:52:31 -0700 Subject: [PATCH 233/259] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c7806bba506..6e50e8e0066 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This repository contains GL shaders which are shared by [Mapbox GL JS](https://g ## Pragmas +_This section is written as if we have already completed [#8](https://github.com/mapbox/mapbox-gl-shaders/issues/8)_ + Some variables change type depending on their context: - if the variable is the same for all features, we declare it as a `uniform` From be09fce1d01e63de69f019e953261832d16ec88c Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Mon, 6 Jun 2016 13:22:39 -0400 Subject: [PATCH 234/259] Revert changes to shaders that broke gl js --- src/circle.vertex.glsl | 2 ++ src/fill.vertex.glsl | 3 +++ src/outline.vertex.glsl | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index 09f8aed2fe4..2d860360424 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -12,12 +12,14 @@ uniform float u_devicepixelratio; attribute vec2 a_pos; +#pragma mapbox: define color lowp #pragma mapbox: define radius mediump varying vec2 v_extrude; varying lowp float v_antialiasblur; void main(void) { + #pragma mapbox: initialize color lowp #pragma mapbox: initialize radius mediump // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index b0a6e124535..2cfa5322428 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -10,6 +10,9 @@ attribute vec2 a_pos; uniform mat4 u_matrix; +#pragma mapbox: define color lowp + void main() { + #pragma mapbox: initialize color lowp gl_Position = u_matrix * vec4(a_pos, 0, 1); } diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index df5ae343c00..ec5d8ce2d09 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -13,7 +13,11 @@ uniform vec2 u_world; varying vec2 v_pos; +#pragma mapbox: define outline_color lowp + void main() { + #pragma mapbox: initialize outline_color lowp + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } From 8dfd9653e6659cb2837a4b98f3e8e1d559b29a09 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 6 Jun 2016 17:02:59 -0700 Subject: [PATCH 235/259] Include type in #pragmas fixes #8 --- src/circle.fragment.glsl | 4 ++-- src/circle.vertex.glsl | 9 +++++---- src/fill.fragment.glsl | 4 ++-- src/fill.vertex.glsl | 5 +++-- src/outline.fragment.glsl | 4 ++-- src/outline.vertex.glsl | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 5497ba83486..d6d44c2d741 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -9,13 +9,13 @@ precision mediump float; uniform lowp float u_blur; uniform lowp float u_opacity; -#pragma mapbox: define color lowp +#pragma mapbox: define lowp vec4 color varying lowp float v_antialiasblur; varying vec2 v_extrude; void main() { - #pragma mapbox: initialize color lowp + #pragma mapbox: initialize lowp vec4 color float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = color * (1.0 - t) * u_opacity; diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index 2d860360424..e85f53e4fce 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -12,15 +12,16 @@ uniform float u_devicepixelratio; attribute vec2 a_pos; -#pragma mapbox: define color lowp -#pragma mapbox: define radius mediump +#pragma mapbox: define lowp vec4 color +#pragma mapbox: define mediump float radius varying vec2 v_extrude; varying lowp float v_antialiasblur; void main(void) { - #pragma mapbox: initialize color lowp - #pragma mapbox: initialize radius mediump + #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize mediump float radius + // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index 7444c0876b9..12075ec2903 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -6,11 +6,11 @@ precision mediump float; #define highp #endif -#pragma mapbox: define color lowp +#pragma mapbox: define lowp vec4 color uniform lowp float u_opacity; void main() { - #pragma mapbox: initialize color lowp + #pragma mapbox: initialize lowp vec4 color gl_FragColor = color * u_opacity; diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index 2cfa5322428..4a6f15579a6 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -10,9 +10,10 @@ attribute vec2 a_pos; uniform mat4 u_matrix; -#pragma mapbox: define color lowp +#pragma mapbox: define lowp vec4 color void main() { - #pragma mapbox: initialize color lowp + #pragma mapbox: initialize lowp vec4 color + gl_Position = u_matrix * vec4(a_pos, 0, 1); } diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 315a6c1cb14..68f2f1d10df 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -6,14 +6,14 @@ precision mediump float; #define highp #endif -#pragma mapbox: define outline_color lowp +#pragma mapbox: define lowp vec4 outline_color uniform lowp float u_opacity; varying vec2 v_pos; void main() { - #pragma mapbox: initialize outline_color lowp + #pragma mapbox: initialize lowp vec4 outline_color float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index ec5d8ce2d09..312ddfe58e5 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -13,10 +13,10 @@ uniform vec2 u_world; varying vec2 v_pos; -#pragma mapbox: define outline_color lowp +#pragma mapbox: define lowp vec4 outline_color void main() { - #pragma mapbox: initialize outline_color lowp + #pragma mapbox: initialize lowp vec4 outline_color gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; From 895c46d392c1cc1797fd7d776976d3138414afd7 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 7 Jun 2016 15:09:02 +0300 Subject: [PATCH 236/259] Remove README.md notice --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 6e50e8e0066..c7806bba506 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ This repository contains GL shaders which are shared by [Mapbox GL JS](https://g ## Pragmas -_This section is written as if we have already completed [#8](https://github.com/mapbox/mapbox-gl-shaders/issues/8)_ - Some variables change type depending on their context: - if the variable is the same for all features, we declare it as a `uniform` From 9af2892c56c74c4d2d7e5cc59b6e5e4fe3837c6f Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 8 Jun 2016 09:21:58 -0700 Subject: [PATCH 237/259] Add property functions for circle-opacity and circle-blur --- src/circle.fragment.glsl | 13 +++++++------ src/circle.vertex.glsl | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index d6d44c2d741..77863a0d668 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -6,19 +6,20 @@ precision mediump float; #define highp #endif -uniform lowp float u_blur; -uniform lowp float u_opacity; - #pragma mapbox: define lowp vec4 color -varying lowp float v_antialiasblur; +#pragma mapbox: define lowp vec4 blur +#pragma mapbox: define lowp vec4 opacity varying vec2 v_extrude; +varying lowp float v_antialiasblur; void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp vec4 blur + #pragma mapbox: initialize lowp vec4 opacity - float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude)); - gl_FragColor = color * (1.0 - t) * u_opacity; + float t = smoothstep(1.0 - max(blur, v_antialiasblur), 1.0, length(v_extrude)); + gl_FragColor = color * (1.0 - t) * opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index e85f53e4fce..db6a313ac66 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -14,6 +14,8 @@ attribute vec2 a_pos; #pragma mapbox: define lowp vec4 color #pragma mapbox: define mediump float radius +#pragma mapbox: define lowp vec4 blur +#pragma mapbox: define lowp vec4 opacity varying vec2 v_extrude; varying lowp float v_antialiasblur; @@ -21,6 +23,8 @@ varying lowp float v_antialiasblur; void main(void) { #pragma mapbox: initialize lowp vec4 color #pragma mapbox: initialize mediump float radius + #pragma mapbox: initialize lowp vec4 blur + #pragma mapbox: initialize lowp vec4 opacity // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); From f0b94dcc5f782958e9aade61d592a207d8a46e0f Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Fri, 10 Jun 2016 14:25:29 -0400 Subject: [PATCH 238/259] vec4 => float for blur/opacity in circle shader --- src/circle.fragment.glsl | 8 ++++---- src/circle.vertex.glsl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 77863a0d668..82b7be431b0 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -7,16 +7,16 @@ precision mediump float; #endif #pragma mapbox: define lowp vec4 color -#pragma mapbox: define lowp vec4 blur -#pragma mapbox: define lowp vec4 opacity +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity varying vec2 v_extrude; varying lowp float v_antialiasblur; void main() { #pragma mapbox: initialize lowp vec4 color - #pragma mapbox: initialize lowp vec4 blur - #pragma mapbox: initialize lowp vec4 opacity + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity float t = smoothstep(1.0 - max(blur, v_antialiasblur), 1.0, length(v_extrude)); gl_FragColor = color * (1.0 - t) * opacity; diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index db6a313ac66..b35fc1166ae 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -14,8 +14,8 @@ attribute vec2 a_pos; #pragma mapbox: define lowp vec4 color #pragma mapbox: define mediump float radius -#pragma mapbox: define lowp vec4 blur -#pragma mapbox: define lowp vec4 opacity +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity varying vec2 v_extrude; varying lowp float v_antialiasblur; @@ -23,8 +23,8 @@ varying lowp float v_antialiasblur; void main(void) { #pragma mapbox: initialize lowp vec4 color #pragma mapbox: initialize mediump float radius - #pragma mapbox: initialize lowp vec4 blur - #pragma mapbox: initialize lowp vec4 opacity + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); From 30caf388dbddd02cfc4f967ffc94c1338c30fbf8 Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Sat, 4 Jun 2016 12:23:45 -0400 Subject: [PATCH 239/259] Refactor to support text-pitch-alignment + text-rotation-alignment --- src/icon.vertex.glsl | 4 ++-- src/sdf.vertex.glsl | 46 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/icon.vertex.glsl b/src/icon.vertex.glsl index bae818c211b..1689f2af2ac 100644 --- a/src/icon.vertex.glsl +++ b/src/icon.vertex.glsl @@ -16,7 +16,7 @@ attribute vec4 a_data2; uniform mat4 u_matrix; uniform mediump float u_zoom; -uniform bool u_skewed; +uniform bool u_rotate_with_map; uniform vec2 u_extrude_scale; uniform vec2 u_texsize; @@ -35,7 +35,7 @@ void main() { mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); vec2 extrude = u_extrude_scale * (a_offset / 64.0); - if (u_skewed) { + if (u_rotate_with_map) { gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1); gl_Position.z += z * gl_Position.w; } else { diff --git a/src/sdf.vertex.glsl b/src/sdf.vertex.glsl index b342cf27477..41cd611af2f 100644 --- a/src/sdf.vertex.glsl +++ b/src/sdf.vertex.glsl @@ -6,6 +6,8 @@ precision highp float; #define highp #endif +const float PI = 3.141592653589793; + attribute vec2 a_pos; attribute vec2 a_offset; attribute vec4 a_data1; @@ -16,7 +18,11 @@ attribute vec4 a_data2; uniform mat4 u_matrix; uniform mediump float u_zoom; -uniform bool u_skewed; +uniform bool u_rotate_with_map; +uniform bool u_pitch_with_map; +uniform mediump float u_pitch; +uniform mediump float u_bearing; +uniform mediump float u_aspect_ratio; uniform vec2 u_extrude_scale; uniform vec2 u_texsize; @@ -35,11 +41,45 @@ void main() { // u_zoom is the current zoom level adjusted for the change in font size mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)); - vec2 extrude = u_extrude_scale * (a_offset / 64.0); - if (u_skewed) { + // pitch-alignment: map + // rotation-alignment: map | viewport + if (u_pitch_with_map) { + lowp float angle = u_rotate_with_map ? (a_data1[3] / 256.0 * 2.0 * PI) : u_bearing; + lowp float asin = sin(angle); + lowp float acos = cos(angle); + mat2 RotationMatrix = mat2(acos, asin, -1.0 * asin, acos); + vec2 offset = RotationMatrix * a_offset; + vec2 extrude = u_extrude_scale * (offset / 64.0); gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1); gl_Position.z += z * gl_Position.w; + // pitch-alignment: viewport + // rotation-alignment: map + } else if (u_rotate_with_map) { + // foreshortening factor to apply on pitched maps + // as a label goes from horizontal <=> vertical in angle + // it goes from 0% foreshortening to up to around 70% foreshortening + lowp float pitchfactor = 1.0 - cos(u_pitch * sin(u_pitch * 0.75)); + + lowp float lineangle = a_data1[3] / 256.0 * 2.0 * PI; + + // use the lineangle to position points a,b along the line + // project the points and calculate the label angle in projected space + // this calculation allows labels to be rendered unskewed on pitched maps + vec4 a = u_matrix * vec4(a_pos, 0, 1); + vec4 b = u_matrix * vec4(a_pos + vec2(cos(lineangle),sin(lineangle)), 0, 1); + lowp float angle = atan((b[1]/b[3] - a[1]/a[3])/u_aspect_ratio, b[0]/b[3] - a[0]/a[3]); + lowp float asin = sin(angle); + lowp float acos = cos(angle); + mat2 RotationMatrix = mat2(acos, -1.0 * asin, asin, acos); + + vec2 offset = RotationMatrix * (vec2((1.0-pitchfactor)+(pitchfactor*cos(angle*2.0)), 1.0) * a_offset); + vec2 extrude = u_extrude_scale * (offset / 64.0); + gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); + gl_Position.z += z * gl_Position.w; + // pitch-alignment: viewport + // rotation-alignment: viewport } else { + vec2 extrude = u_extrude_scale * (a_offset / 64.0); gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); } From 09ee512cd59a8fb1a241c78833b7c8022bf4f263 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 13 Jun 2016 09:39:51 +0300 Subject: [PATCH 240/259] Cleaned line-pattern diff in JS/Native Added line-pattern/pitch render-test to verify. --- src/linepattern.vertex.glsl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/linepattern.vertex.glsl b/src/linepattern.vertex.glsl index 720de53b7f8..a1b812ba0eb 100644 --- a/src/linepattern.vertex.glsl +++ b/src/linepattern.vertex.glsl @@ -75,11 +75,7 @@ void main() { float squish_scale = length(a_extrude) / length(u_antialiasingmatrix * a_extrude); // how much features are squished in all directions by the perspectiveness -#ifndef MAPBOX_GL_JS - float perspective_scale = 1.0 / (1.0 - y * u_extra); -#else float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); -#endif v_linewidth = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; From bc5bfee8891d891b85c83bf9cacc761ebe16846c Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 14 Jun 2016 17:55:24 +0300 Subject: [PATCH 241/259] Added .gitignore --- .gitinore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitinore diff --git a/.gitinore b/.gitinore new file mode 100644 index 00000000000..07e6e472cc7 --- /dev/null +++ b/.gitinore @@ -0,0 +1 @@ +/node_modules From 59e998295d548f208ee3ec10cdd21ff2630e2079 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 14 Jun 2016 18:11:06 +0300 Subject: [PATCH 242/259] [native] Separate pattern size from draw-time variables --- src/outlinepattern.vertex.glsl | 16 +--------------- src/pattern.vertex.glsl | 15 +-------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/outlinepattern.vertex.glsl b/src/outlinepattern.vertex.glsl index 633100580b2..dc02bbb23cc 100644 --- a/src/outlinepattern.vertex.glsl +++ b/src/outlinepattern.vertex.glsl @@ -6,12 +6,6 @@ precision highp float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform vec2 u_patternscale_a; -uniform vec2 u_patternscale_b; -uniform vec2 u_offset_a; -uniform vec2 u_offset_b; -#else uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; uniform vec2 u_pixel_coord_upper; @@ -19,7 +13,6 @@ uniform vec2 u_pixel_coord_lower; uniform float u_scale_a; uniform float u_scale_b; uniform float u_tile_units_to_pixels; -#endif attribute vec2 a_pos; @@ -30,19 +23,13 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec2 v_pos; - void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); -#ifndef MAPBOX_GL_JS - v_pos_a = u_patternscale_a * a_pos + u_offset_a; - v_pos_b = u_patternscale_b * a_pos + u_offset_b; - v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; -#else vec2 scaled_size_a = u_scale_a * u_pattern_size_a; vec2 scaled_size_b = u_scale_b * u_pattern_size_b; // the correct offset needs to be calculated. - // + // // The offset depends on how many pixels are between the world origin and // the edge of the tile: // vec2 offset = mod(pixel_coord, size) @@ -63,5 +50,4 @@ void main() { v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; -#endif } diff --git a/src/pattern.vertex.glsl b/src/pattern.vertex.glsl index eb801ec76e0..d949a2fe0aa 100644 --- a/src/pattern.vertex.glsl +++ b/src/pattern.vertex.glsl @@ -6,13 +6,6 @@ precision highp float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform mat4 u_matrix; -uniform vec2 u_patternscale_a; -uniform vec2 u_patternscale_b; -uniform vec2 u_offset_a; -uniform vec2 u_offset_b; -#else uniform mat4 u_matrix; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; @@ -21,7 +14,6 @@ uniform vec2 u_pixel_coord_lower; uniform float u_scale_a; uniform float u_scale_b; uniform float u_tile_units_to_pixels; -#endif attribute vec2 a_pos; @@ -30,15 +22,11 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); -#ifndef MAPBOX_GL_JS - v_pos_a = u_patternscale_a * a_pos + u_offset_a; - v_pos_b = u_patternscale_b * a_pos + u_offset_b; -#else vec2 scaled_size_a = u_scale_a * u_pattern_size_a; vec2 scaled_size_b = u_scale_b * u_pattern_size_b; // the correct offset needs to be calculated. - // + // // The offset depends on how many pixels are between the world origin and // the edge of the tile: // vec2 offset = mod(pixel_coord, size) @@ -57,5 +45,4 @@ void main() { v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; -#endif } From 03f799b19d27efd40eafafc857077ac6eb34b307 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 13 Jun 2016 17:15:07 -0700 Subject: [PATCH 243/259] Use pragmas for fill & fill-outline opacity --- src/fill.fragment.glsl | 5 +++-- src/fill.vertex.glsl | 2 ++ src/outline.fragment.glsl | 6 +++--- src/outline.vertex.glsl | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index 12075ec2903..8598263fc82 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -7,12 +7,13 @@ precision mediump float; #endif #pragma mapbox: define lowp vec4 color -uniform lowp float u_opacity; +#pragma mapbox: define lowp float opacity void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float opacity - gl_FragColor = color * u_opacity; + gl_FragColor = color * opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index 4a6f15579a6..59285163627 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -11,9 +11,11 @@ attribute vec2 a_pos; uniform mat4 u_matrix; #pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float opacity void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float opacity gl_Position = u_matrix * vec4(a_pos, 0, 1); } diff --git a/src/outline.fragment.glsl b/src/outline.fragment.glsl index 68f2f1d10df..864c1524dd9 100644 --- a/src/outline.fragment.glsl +++ b/src/outline.fragment.glsl @@ -7,17 +7,17 @@ precision mediump float; #endif #pragma mapbox: define lowp vec4 outline_color - -uniform lowp float u_opacity; +#pragma mapbox: define lowp float opacity varying vec2 v_pos; void main() { #pragma mapbox: initialize lowp vec4 outline_color + #pragma mapbox: initialize lowp float opacity float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); - gl_FragColor = outline_color * (alpha * u_opacity); + gl_FragColor = outline_color * (alpha * opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/outline.vertex.glsl b/src/outline.vertex.glsl index 312ddfe58e5..f5c92d8373d 100644 --- a/src/outline.vertex.glsl +++ b/src/outline.vertex.glsl @@ -14,9 +14,11 @@ uniform vec2 u_world; varying vec2 v_pos; #pragma mapbox: define lowp vec4 outline_color +#pragma mapbox: define lowp float opacity void main() { #pragma mapbox: initialize lowp vec4 outline_color + #pragma mapbox: initialize lowp float opacity gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; From d3a10d1a46b99d3da264cf2d1903cbde6fea3185 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 15 Jun 2016 20:09:56 +0300 Subject: [PATCH 244/259] [native] Cross-fade raster tiles Ref: https://github.com/mapbox/mapbox-gl-shaders/issues/1 --- src/raster.fragment.glsl | 13 ------------- src/raster.vertex.glsl | 16 ---------------- 2 files changed, 29 deletions(-) diff --git a/src/raster.fragment.glsl b/src/raster.fragment.glsl index 7b23f9a8487..d05c54fbbf4 100644 --- a/src/raster.fragment.glsl +++ b/src/raster.fragment.glsl @@ -6,21 +6,12 @@ precision mediump float; #define highp #endif -#ifndef MAPBOX_GL_JS -uniform sampler2D u_image; -uniform float u_opacity; -#endif - -#ifndef MAPBOX_GL_JS -varying vec2 v_pos; -#else uniform float u_opacity0; uniform float u_opacity1; uniform sampler2D u_image0; uniform sampler2D u_image1; varying vec2 v_pos0; varying vec2 v_pos1; -#endif uniform float u_brightness_low; uniform float u_brightness_high; @@ -31,14 +22,10 @@ uniform vec3 u_spin_weights; void main() { -#ifndef MAPBOX_GL_JS - vec4 color = texture2D(u_image, v_pos) * u_opacity; -#else // read and cross-fade colors from the main and parent tiles vec4 color0 = texture2D(u_image0, v_pos0); vec4 color1 = texture2D(u_image1, v_pos1); vec4 color = color0 * u_opacity0 + color1 * u_opacity1; -#endif vec3 rgb = color.rgb; // spin diff --git a/src/raster.vertex.glsl b/src/raster.vertex.glsl index 3f506843d6b..70f68446ec8 100644 --- a/src/raster.vertex.glsl +++ b/src/raster.vertex.glsl @@ -7,34 +7,18 @@ precision highp float; #endif uniform mat4 u_matrix; -#ifndef MAPBOX_GL_JS -uniform float u_buffer; -#else uniform vec2 u_tl_parent; uniform float u_scale_parent; uniform float u_buffer_scale; -#endif attribute vec2 a_pos; -#ifdef MAPBOX_GL_JS attribute vec2 a_texture_pos; -#endif - -#ifndef MAPBOX_GL_JS -varying vec2 v_pos; -#else varying vec2 v_pos0; varying vec2 v_pos1; -#endif void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); -#ifndef MAPBOX_GL_JS - float dimension = (8192.0 + 2.0 * u_buffer); - v_pos = (a_pos / dimension) + (u_buffer / dimension); -#else v_pos0 = (((a_texture_pos / 32767.0) - 0.5) / u_buffer_scale ) + 0.5; v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; -#endif } From 4d1f89514bf03536c8e682439df165c33a37122a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 5 Jul 2016 10:51:55 -0700 Subject: [PATCH 245/259] Add support for circle-pitch-scale property --- src/circle.vertex.glsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index b35fc1166ae..d96cce41762 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -7,6 +7,7 @@ precision highp float; #endif uniform mat4 u_matrix; +uniform bool u_scale_with_map; uniform vec2 u_extrude_scale; uniform float u_devicepixelratio; @@ -34,7 +35,11 @@ void main(void) { // in extrusion data gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0, 1); - gl_Position.xy += extrude; + if (u_scale_with_map) { + gl_Position.xy += extrude; + } else { + gl_Position.xy += extrude * gl_Position.w; + } // 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 From de2ab007455aa2587c552694c68583f94c9f2747 Mon Sep 17 00:00:00 2001 From: xrwang Date: Thu, 4 Aug 2016 17:04:38 -0700 Subject: [PATCH 246/259] Rearrange icon and sdf attributes to allow larger texture --- src/icon.vertex.glsl | 10 +++++----- src/sdf.vertex.glsl | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/icon.vertex.glsl b/src/icon.vertex.glsl index 1689f2af2ac..8e5888d3ea3 100644 --- a/src/icon.vertex.glsl +++ b/src/icon.vertex.glsl @@ -8,8 +8,8 @@ precision highp float; attribute vec2 a_pos; attribute vec2 a_offset; -attribute vec4 a_data1; -attribute vec4 a_data2; +attribute vec2 a_texture_pos; +attribute vec4 a_data; // matrix is for the vertex position. @@ -25,9 +25,9 @@ varying vec2 v_tex; varying vec2 v_fade_tex; void main() { - vec2 a_tex = a_data1.xy; - mediump float a_labelminzoom = a_data1[2]; - mediump vec2 a_zoom = a_data2.st; + vec2 a_tex = a_texture_pos.xy; + mediump float a_labelminzoom = a_data[0]; + mediump vec2 a_zoom = a_data.pq; mediump float a_minzoom = a_zoom[0]; mediump float a_maxzoom = a_zoom[1]; diff --git a/src/sdf.vertex.glsl b/src/sdf.vertex.glsl index 41cd611af2f..771eb0e6843 100644 --- a/src/sdf.vertex.glsl +++ b/src/sdf.vertex.glsl @@ -10,8 +10,8 @@ const float PI = 3.141592653589793; attribute vec2 a_pos; attribute vec2 a_offset; -attribute vec4 a_data1; -attribute vec4 a_data2; +attribute vec2 a_texture_pos; +attribute vec4 a_data; // matrix is for the vertex position. @@ -32,9 +32,9 @@ varying vec2 v_fade_tex; varying float v_gamma_scale; void main() { - vec2 a_tex = a_data1.xy; - mediump float a_labelminzoom = a_data1[2]; - mediump vec2 a_zoom = a_data2.st; + vec2 a_tex = a_texture_pos.xy; + mediump float a_labelminzoom = a_data[0]; + mediump vec2 a_zoom = a_data.pq; mediump float a_minzoom = a_zoom[0]; mediump float a_maxzoom = a_zoom[1]; @@ -44,7 +44,7 @@ void main() { // pitch-alignment: map // rotation-alignment: map | viewport if (u_pitch_with_map) { - lowp float angle = u_rotate_with_map ? (a_data1[3] / 256.0 * 2.0 * PI) : u_bearing; + lowp float angle = u_rotate_with_map ? (a_data[1] / 256.0 * 2.0 * PI) : u_bearing; lowp float asin = sin(angle); lowp float acos = cos(angle); mat2 RotationMatrix = mat2(acos, asin, -1.0 * asin, acos); @@ -60,7 +60,7 @@ void main() { // it goes from 0% foreshortening to up to around 70% foreshortening lowp float pitchfactor = 1.0 - cos(u_pitch * sin(u_pitch * 0.75)); - lowp float lineangle = a_data1[3] / 256.0 * 2.0 * PI; + lowp float lineangle = a_data[1] / 256.0 * 2.0 * PI; // use the lineangle to position points a,b along the line // project the points and calculate the label angle in projected space From df162476980d9ee2ab6f8d0cf5a06e27aac60472 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 3 Aug 2016 16:19:38 -0700 Subject: [PATCH 247/259] Add support for property functions in line-color --- src/line.fragment.glsl | 7 +++++-- src/line.vertex.glsl | 4 ++++ src/linesdfpattern.fragment.glsl | 7 +++++-- src/linesdfpattern.vertex.glsl | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index ed7a14f7091..611f3be42ed 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -6,15 +6,18 @@ precision mediump float; #define highp #endif -uniform lowp vec4 u_color; uniform lowp float u_opacity; uniform float u_blur; +#pragma mapbox: define lowp vec4 color + varying vec2 v_linewidth; varying vec2 v_normal; varying float v_gamma_scale; void main() { + #pragma mapbox: initialize lowp vec4 color + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_linewidth.s; @@ -24,7 +27,7 @@ void main() { float blur = u_blur * v_gamma_scale; float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); - gl_FragColor = u_color * (alpha * u_opacity); + gl_FragColor = color * (alpha * u_opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index 87a2e978a38..5ad58b2e6d3 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -31,7 +31,11 @@ varying vec2 v_normal; varying vec2 v_linewidth; varying float v_gamma_scale; +#pragma mapbox: define lowp vec4 color + void main() { + #pragma mapbox: initialize lowp vec4 color + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; diff --git a/src/linesdfpattern.fragment.glsl b/src/linesdfpattern.fragment.glsl index 246547a91c9..714f3e94967 100644 --- a/src/linesdfpattern.fragment.glsl +++ b/src/linesdfpattern.fragment.glsl @@ -6,7 +6,6 @@ precision mediump float; #define highp #endif -uniform lowp vec4 u_color; uniform lowp float u_opacity; uniform float u_blur; @@ -20,7 +19,11 @@ varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; +#pragma mapbox: define lowp vec4 color + void main() { + #pragma mapbox: initialize lowp vec4 color + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_linewidth.s; @@ -35,7 +38,7 @@ void main() { float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); - gl_FragColor = u_color * (alpha * u_opacity); + gl_FragColor = color * (alpha * u_opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/linesdfpattern.vertex.glsl b/src/linesdfpattern.vertex.glsl index 2db91eb24bc..5d70d12d4c6 100644 --- a/src/linesdfpattern.vertex.glsl +++ b/src/linesdfpattern.vertex.glsl @@ -40,7 +40,11 @@ varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; +#pragma mapbox: define lowp vec4 color + void main() { + #pragma mapbox: initialize lowp vec4 color + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; From 98a56d538b11fb331aa67a6d632d6ecd6821b007 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 6 Oct 2016 17:21:57 -0700 Subject: [PATCH 248/259] Rationalize names Fixes #26 --- index.js | 62 +++++++++---------- ...gment.glsl => collision_box.fragment.glsl} | 0 ....vertex.glsl => collision_box.vertex.glsl} | 0 ...agment.glsl => fill_outline.fragment.glsl} | 0 ...e.vertex.glsl => fill_outline.vertex.glsl} | 0 ...lsl => fill_outline_pattern.fragment.glsl} | 0 ....glsl => fill_outline_pattern.vertex.glsl} | 0 ...agment.glsl => fill_pattern.fragment.glsl} | 0 ...n.vertex.glsl => fill_pattern.vertex.glsl} | 0 ...agment.glsl => line_pattern.fragment.glsl} | 0 ...n.vertex.glsl => line_pattern.vertex.glsl} | 0 ...n.fragment.glsl => line_sdf.fragment.glsl} | 0 ...ttern.vertex.glsl => line_sdf.vertex.glsl} | 0 ...ragment.glsl => symbol_icon.fragment.glsl} | 0 ...on.vertex.glsl => symbol_icon.vertex.glsl} | 0 ...fragment.glsl => symbol_sdf.fragment.glsl} | 0 ...sdf.vertex.glsl => symbol_sdf.vertex.glsl} | 0 17 files changed, 31 insertions(+), 31 deletions(-) rename src/{collisionbox.fragment.glsl => collision_box.fragment.glsl} (100%) rename src/{collisionbox.vertex.glsl => collision_box.vertex.glsl} (100%) rename src/{outline.fragment.glsl => fill_outline.fragment.glsl} (100%) rename src/{outline.vertex.glsl => fill_outline.vertex.glsl} (100%) rename src/{outlinepattern.fragment.glsl => fill_outline_pattern.fragment.glsl} (100%) rename src/{outlinepattern.vertex.glsl => fill_outline_pattern.vertex.glsl} (100%) rename src/{pattern.fragment.glsl => fill_pattern.fragment.glsl} (100%) rename src/{pattern.vertex.glsl => fill_pattern.vertex.glsl} (100%) rename src/{linepattern.fragment.glsl => line_pattern.fragment.glsl} (100%) rename src/{linepattern.vertex.glsl => line_pattern.vertex.glsl} (100%) rename src/{linesdfpattern.fragment.glsl => line_sdf.fragment.glsl} (100%) rename src/{linesdfpattern.vertex.glsl => line_sdf.vertex.glsl} (100%) rename src/{icon.fragment.glsl => symbol_icon.fragment.glsl} (100%) rename src/{icon.vertex.glsl => symbol_icon.vertex.glsl} (100%) rename src/{sdf.fragment.glsl => symbol_sdf.fragment.glsl} (100%) rename src/{sdf.vertex.glsl => symbol_sdf.vertex.glsl} (100%) diff --git a/index.js b/index.js index edc7ccf6f9b..24428c16e32 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,14 @@ var path = require('path'); // readFileSync calls must be written out long-form for brfs. module.exports = { + circle: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/circle.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/circle.vertex.glsl'), 'utf8') + }, + collisionBox: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/collision_box.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/collision_box.vertex.glsl'), 'utf8') + }, debug: { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/debug.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/debug.vertex.glsl'), 'utf8') @@ -11,49 +19,41 @@ module.exports = { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill.vertex.glsl'), 'utf8') }, - circle: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/circle.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/circle.vertex.glsl'), 'utf8') + fillOutline: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_outline.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_outline.vertex.glsl'), 'utf8') + }, + fillOutlinePattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_outline_pattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_outline_pattern.vertex.glsl'), 'utf8') + }, + fillPattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_pattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_pattern.vertex.glsl'), 'utf8') }, line: { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/line.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/line.vertex.glsl'), 'utf8') }, - linepattern: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/linepattern.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/linepattern.vertex.glsl'), 'utf8') - }, - linesdfpattern: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/linesdfpattern.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/linesdfpattern.vertex.glsl'), 'utf8') + linePattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/line_pattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/line_pattern.vertex.glsl'), 'utf8') }, - outline: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/outline.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/outline.vertex.glsl'), 'utf8') - }, - outlinepattern: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/outlinepattern.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/outlinepattern.vertex.glsl'), 'utf8') - }, - pattern: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/pattern.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/pattern.vertex.glsl'), 'utf8') + lineSDF: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/line_sdf.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/line_sdf.vertex.glsl'), 'utf8') }, raster: { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/raster.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/raster.vertex.glsl'), 'utf8') }, - icon: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/icon.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/icon.vertex.glsl'), 'utf8') - }, - sdf: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/sdf.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/sdf.vertex.glsl'), 'utf8') + symbolIcon: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/symbol_icon.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/symbol_icon.vertex.glsl'), 'utf8') }, - collisionbox: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/collisionbox.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/collisionbox.vertex.glsl'), 'utf8') + symbolSDF: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/symbol_sdf.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/symbol_sdf.vertex.glsl'), 'utf8') } }; diff --git a/src/collisionbox.fragment.glsl b/src/collision_box.fragment.glsl similarity index 100% rename from src/collisionbox.fragment.glsl rename to src/collision_box.fragment.glsl diff --git a/src/collisionbox.vertex.glsl b/src/collision_box.vertex.glsl similarity index 100% rename from src/collisionbox.vertex.glsl rename to src/collision_box.vertex.glsl diff --git a/src/outline.fragment.glsl b/src/fill_outline.fragment.glsl similarity index 100% rename from src/outline.fragment.glsl rename to src/fill_outline.fragment.glsl diff --git a/src/outline.vertex.glsl b/src/fill_outline.vertex.glsl similarity index 100% rename from src/outline.vertex.glsl rename to src/fill_outline.vertex.glsl diff --git a/src/outlinepattern.fragment.glsl b/src/fill_outline_pattern.fragment.glsl similarity index 100% rename from src/outlinepattern.fragment.glsl rename to src/fill_outline_pattern.fragment.glsl diff --git a/src/outlinepattern.vertex.glsl b/src/fill_outline_pattern.vertex.glsl similarity index 100% rename from src/outlinepattern.vertex.glsl rename to src/fill_outline_pattern.vertex.glsl diff --git a/src/pattern.fragment.glsl b/src/fill_pattern.fragment.glsl similarity index 100% rename from src/pattern.fragment.glsl rename to src/fill_pattern.fragment.glsl diff --git a/src/pattern.vertex.glsl b/src/fill_pattern.vertex.glsl similarity index 100% rename from src/pattern.vertex.glsl rename to src/fill_pattern.vertex.glsl diff --git a/src/linepattern.fragment.glsl b/src/line_pattern.fragment.glsl similarity index 100% rename from src/linepattern.fragment.glsl rename to src/line_pattern.fragment.glsl diff --git a/src/linepattern.vertex.glsl b/src/line_pattern.vertex.glsl similarity index 100% rename from src/linepattern.vertex.glsl rename to src/line_pattern.vertex.glsl diff --git a/src/linesdfpattern.fragment.glsl b/src/line_sdf.fragment.glsl similarity index 100% rename from src/linesdfpattern.fragment.glsl rename to src/line_sdf.fragment.glsl diff --git a/src/linesdfpattern.vertex.glsl b/src/line_sdf.vertex.glsl similarity index 100% rename from src/linesdfpattern.vertex.glsl rename to src/line_sdf.vertex.glsl diff --git a/src/icon.fragment.glsl b/src/symbol_icon.fragment.glsl similarity index 100% rename from src/icon.fragment.glsl rename to src/symbol_icon.fragment.glsl diff --git a/src/icon.vertex.glsl b/src/symbol_icon.vertex.glsl similarity index 100% rename from src/icon.vertex.glsl rename to src/symbol_icon.vertex.glsl diff --git a/src/sdf.fragment.glsl b/src/symbol_sdf.fragment.glsl similarity index 100% rename from src/sdf.fragment.glsl rename to src/symbol_sdf.fragment.glsl diff --git a/src/sdf.vertex.glsl b/src/symbol_sdf.vertex.glsl similarity index 100% rename from src/sdf.vertex.glsl rename to src/symbol_sdf.vertex.glsl From 44b65f8090a74cbb0319664d010b8d8a8a1512b0 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 7 Oct 2016 16:59:27 -0700 Subject: [PATCH 249/259] Extrusion shaders (#25) --- index.js | 12 ++++ src/fill_extrude.fragment.glsl | 24 ++++++++ src/fill_extrude.vertex.glsl | 76 ++++++++++++++++++++++++ src/fill_extrude_pattern.fragment.glsl | 49 +++++++++++++++ src/fill_extrude_pattern.vertex.glsl | 82 ++++++++++++++++++++++++++ src/fill_extrude_texture.fragment.glsl | 16 +++++ src/fill_extrude_texture.vertex.glsl | 20 +++++++ 7 files changed, 279 insertions(+) create mode 100644 src/fill_extrude.fragment.glsl create mode 100644 src/fill_extrude.vertex.glsl create mode 100644 src/fill_extrude_pattern.fragment.glsl create mode 100644 src/fill_extrude_pattern.vertex.glsl create mode 100644 src/fill_extrude_texture.fragment.glsl create mode 100644 src/fill_extrude_texture.vertex.glsl diff --git a/index.js b/index.js index 24428c16e32..22ac7ea58c6 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,18 @@ module.exports = { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_pattern.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_pattern.vertex.glsl'), 'utf8') }, + fillExtrude: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude.vertex.glsl'), 'utf8') + }, + fillExtrudePattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_pattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_pattern.vertex.glsl'), 'utf8') + }, + fillExtrudeTexture: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_texture.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_texture.vertex.glsl'), 'utf8') + }, line: { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/line.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/line.vertex.glsl'), 'utf8') diff --git a/src/fill_extrude.fragment.glsl b/src/fill_extrude.fragment.glsl new file mode 100644 index 00000000000..d327707b67e --- /dev/null +++ b/src/fill_extrude.fragment.glsl @@ -0,0 +1,24 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + +varying vec4 v_color; +#ifdef MAPBOX_GL_JS +#pragma mapbox: define lowp float minH +#pragma mapbox: define lowp float maxH +#endif +#pragma mapbox: define lowp vec4 color + +void main() { +#ifdef MAPBOX_GL_JS + #pragma mapbox: initialize lowp float minH + #pragma mapbox: initialize lowp float maxH +#endif + #pragma mapbox: initialize lowp vec4 color + + gl_FragColor = v_color; +} diff --git a/src/fill_extrude.vertex.glsl b/src/fill_extrude.vertex.glsl new file mode 100644 index 00000000000..ed22459a810 --- /dev/null +++ b/src/fill_extrude.vertex.glsl @@ -0,0 +1,76 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + +uniform mat4 u_matrix; +uniform vec3 u_lightcolor; +uniform lowp vec3 u_lightpos; +uniform lowp float u_lightintensity; +uniform lowp vec4 u_outline_color; + +attribute vec2 a_pos; +attribute vec3 a_normal; +attribute float a_edgedistance; + +varying vec4 v_color; + +#ifndef MAPBOX_GL_JS +attribute float minH; +attribute float maxH; +#else +#pragma mapbox: define lowp float minH +#pragma mapbox: define lowp float maxH +#endif + +#pragma mapbox: define lowp vec4 color + +void main() { +#ifdef MAPBOX_GL_JS + #pragma mapbox: initialize lowp float minH + #pragma mapbox: initialize lowp float maxH +#endif + #pragma mapbox: initialize lowp vec4 color + + float ed = a_edgedistance; // use each attrib in order to not trip a VAO assert + float t = mod(a_normal.x, 2.0); + + gl_Position = u_matrix * vec4(a_pos, t > 0.0 ? maxH : minH, 1); + +#ifdef OUTLINE + color = u_outline_color; +#endif + + // Relative luminance (how dark/bright is the surface color?) + float colorvalue = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722; + + v_color = vec4(0.0, 0.0, 0.0, 1.0); + + // Add slight ambient lighting so no extrusions are totally black + vec4 ambientlight = vec4(0.03, 0.03, 0.03, 1.0); + color += ambientlight; + + // Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray + float directional = clamp(dot(a_normal / 16384.0, u_lightpos), 0.0, 1.0); + + // Adjust directional so that + // the range of values for highlight/shading is narrower + // with lower light intensity + // and with lighter/brighter surface colors + directional = mix((1.0 - u_lightintensity), max((1.0 - colorvalue + u_lightintensity), 1.0), directional); + + // Add gradient along z axis of side surfaces + if (a_normal.y != 0.0) { + directional *= clamp((t + minH) * pow(maxH / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); + } + + // Assign final color based on surface + ambient light color, diffuse light directional, and light color + // with lower bounds adjusted to hue of light + // so that shading is tinted with the complementary (opposite) color to the light color + v_color.r += clamp(color.r * directional * u_lightcolor.r, mix(0.0, 0.3, 1.0 - u_lightcolor.r), 1.0); + v_color.g += clamp(color.g * directional * u_lightcolor.g, mix(0.0, 0.3, 1.0 - u_lightcolor.g), 1.0); + v_color.b += clamp(color.b * directional * u_lightcolor.b, mix(0.0, 0.3, 1.0 - u_lightcolor.b), 1.0); +} diff --git a/src/fill_extrude_pattern.fragment.glsl b/src/fill_extrude_pattern.fragment.glsl new file mode 100644 index 00000000000..368c0c4a2ec --- /dev/null +++ b/src/fill_extrude_pattern.fragment.glsl @@ -0,0 +1,49 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; +uniform float u_mix; + +uniform sampler2D u_image; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec4 v_lighting; + +#ifdef MAPBOX_GL_JS +#pragma mapbox: define lowp float minH +#pragma mapbox: define lowp float maxH +#endif +#pragma mapbox: define lowp vec4 color + +void main() { +#ifdef MAPBOX_GL_JS + #pragma mapbox: initialize lowp float minH + #pragma mapbox: initialize lowp float maxH +#endif + #pragma mapbox: initialize lowp vec4 color + + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); + vec4 color1 = texture2D(u_image, pos); + + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); + vec4 color2 = texture2D(u_image, pos2); + + vec4 mixedColor = mix(color1, color2, u_mix); + + gl_FragColor = mixedColor * v_lighting; + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif +} diff --git a/src/fill_extrude_pattern.vertex.glsl b/src/fill_extrude_pattern.vertex.glsl new file mode 100644 index 00000000000..0143e28de32 --- /dev/null +++ b/src/fill_extrude_pattern.vertex.glsl @@ -0,0 +1,82 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + +uniform mat4 u_matrix; +uniform vec2 u_pattern_size_a; +uniform vec2 u_pattern_size_b; +uniform vec2 u_pixel_coord_upper; +uniform vec2 u_pixel_coord_lower; +uniform float u_scale_a; +uniform float u_scale_b; +uniform float u_tile_units_to_pixels; +uniform float u_height_factor; + +uniform vec3 u_lightcolor; +uniform lowp vec3 u_lightpos; +uniform lowp float u_lightintensity; + +attribute vec2 a_pos; +attribute vec3 a_normal; +attribute float a_edgedistance; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec4 v_lighting; +varying float v_directional; + +#ifndef MAPBOX_GL_JS +attribute float minH; +attribute float maxH; +#else +#pragma mapbox: define lowp float minH +#pragma mapbox: define lowp float maxH +#endif + +#pragma mapbox: define lowp vec4 color + +void main() { +#ifdef MAPBOX_GL_JS + #pragma mapbox: initialize lowp float minH + #pragma mapbox: initialize lowp float maxH +#endif + #pragma mapbox: initialize lowp vec4 color + + float t = mod(a_normal.x, 2.0); + float z = t > 0.0 ? maxH : minH; + + gl_Position = u_matrix * vec4(a_pos, z, 1); + + vec2 scaled_size_a = u_scale_a * u_pattern_size_a; + vec2 scaled_size_b = u_scale_b * u_pattern_size_b; + + // the following offset calculation is duplicated from the regular pattern shader: + vec2 offset_a = mod(mod(mod(u_pixel_coord_upper, scaled_size_a) * 256.0, scaled_size_a) * 256.0 + u_pixel_coord_lower, scaled_size_a); + vec2 offset_b = mod(mod(mod(u_pixel_coord_upper, scaled_size_b) * 256.0, scaled_size_b) * 256.0 + u_pixel_coord_lower, scaled_size_b); + + if (a_normal.x == 1.0 && a_normal.y == 0.0 && a_normal.z == 16384.0) { + // extrusion top + v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; + v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; + } else { + // extrusion side + float hf = z * u_height_factor; + + v_pos_a = (u_tile_units_to_pixels * vec2(a_edgedistance, hf) + offset_a) / scaled_size_a; + v_pos_b = (u_tile_units_to_pixels * vec2(a_edgedistance, hf) + offset_b) / scaled_size_b; + } + + v_lighting = vec4(0.0, 0.0, 0.0, 1.0); + float directional = clamp(dot(a_normal / 16383.0, u_lightpos), 0.0, 1.0); + directional = mix((1.0 - u_lightintensity), max((0.5 + u_lightintensity), 1.0), directional); + + if (a_normal.y != 0.0) { + directional *= clamp((t + minH) * pow(maxH / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); + } + + v_lighting.rgb += clamp(directional * u_lightcolor, mix(vec3(0.0), vec3(0.3), 1.0 - u_lightcolor), vec3(1.0)); +} diff --git a/src/fill_extrude_texture.fragment.glsl b/src/fill_extrude_texture.fragment.glsl new file mode 100644 index 00000000000..6eac6fede50 --- /dev/null +++ b/src/fill_extrude_texture.fragment.glsl @@ -0,0 +1,16 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif + +uniform sampler2D u_texture; +uniform float u_opacity; + +varying vec2 v_pos; + +void main() { + gl_FragColor = texture2D(u_texture, v_pos) * u_opacity; +} diff --git a/src/fill_extrude_texture.vertex.glsl b/src/fill_extrude_texture.vertex.glsl new file mode 100644 index 00000000000..506c265fdcf --- /dev/null +++ b/src/fill_extrude_texture.vertex.glsl @@ -0,0 +1,20 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + +uniform mat4 u_matrix; +uniform int u_xdim; +uniform int u_ydim; +attribute vec2 a_pos; +varying vec2 v_pos; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + + v_pos.x = a_pos.x / float(u_xdim); + v_pos.y = 1.0 - a_pos.y / float(u_ydim); +} From 830540b26078141f4e38a62dcce1353a2538b1df Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Tue, 1 Nov 2016 17:46:55 -0700 Subject: [PATCH 250/259] Rename extrusion shaders to align more closely with fill-extrusion type name (#29) --- index.js | 18 +++++++++--------- ...nt.glsl => extrusion_texture.fragment.glsl} | 0 ...rtex.glsl => extrusion_texture.vertex.glsl} | 0 ...gment.glsl => fill_extrusion.fragment.glsl} | 0 ....vertex.glsl => fill_extrusion.vertex.glsl} | 0 ...sl => fill_extrusion_pattern.fragment.glsl} | 0 ...glsl => fill_extrusion_pattern.vertex.glsl} | 0 7 files changed, 9 insertions(+), 9 deletions(-) rename src/{fill_extrude_texture.fragment.glsl => extrusion_texture.fragment.glsl} (100%) rename src/{fill_extrude_texture.vertex.glsl => extrusion_texture.vertex.glsl} (100%) rename src/{fill_extrude.fragment.glsl => fill_extrusion.fragment.glsl} (100%) rename src/{fill_extrude.vertex.glsl => fill_extrusion.vertex.glsl} (100%) rename src/{fill_extrude_pattern.fragment.glsl => fill_extrusion_pattern.fragment.glsl} (100%) rename src/{fill_extrude_pattern.vertex.glsl => fill_extrusion_pattern.vertex.glsl} (100%) diff --git a/index.js b/index.js index 22ac7ea58c6..e1938391f24 100644 --- a/index.js +++ b/index.js @@ -31,17 +31,17 @@ module.exports = { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_pattern.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_pattern.vertex.glsl'), 'utf8') }, - fillExtrude: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude.vertex.glsl'), 'utf8') + fillExtrusion: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrusion.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrusion.vertex.glsl'), 'utf8') }, - fillExtrudePattern: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_pattern.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_pattern.vertex.glsl'), 'utf8') + fillExtrusionPattern: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrusion_pattern.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrusion_pattern.vertex.glsl'), 'utf8') }, - fillExtrudeTexture: { - fragmentSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_texture.fragment.glsl'), 'utf8'), - vertexSource: fs.readFileSync(path.join(__dirname, 'src/fill_extrude_texture.vertex.glsl'), 'utf8') + extrusionTexture: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/extrusion_texture.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/extrusion_texture.vertex.glsl'), 'utf8') }, line: { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/line.fragment.glsl'), 'utf8'), diff --git a/src/fill_extrude_texture.fragment.glsl b/src/extrusion_texture.fragment.glsl similarity index 100% rename from src/fill_extrude_texture.fragment.glsl rename to src/extrusion_texture.fragment.glsl diff --git a/src/fill_extrude_texture.vertex.glsl b/src/extrusion_texture.vertex.glsl similarity index 100% rename from src/fill_extrude_texture.vertex.glsl rename to src/extrusion_texture.vertex.glsl diff --git a/src/fill_extrude.fragment.glsl b/src/fill_extrusion.fragment.glsl similarity index 100% rename from src/fill_extrude.fragment.glsl rename to src/fill_extrusion.fragment.glsl diff --git a/src/fill_extrude.vertex.glsl b/src/fill_extrusion.vertex.glsl similarity index 100% rename from src/fill_extrude.vertex.glsl rename to src/fill_extrusion.vertex.glsl diff --git a/src/fill_extrude_pattern.fragment.glsl b/src/fill_extrusion_pattern.fragment.glsl similarity index 100% rename from src/fill_extrude_pattern.fragment.glsl rename to src/fill_extrusion_pattern.fragment.glsl diff --git a/src/fill_extrude_pattern.vertex.glsl b/src/fill_extrusion_pattern.vertex.glsl similarity index 100% rename from src/fill_extrude_pattern.vertex.glsl rename to src/fill_extrusion_pattern.vertex.glsl From abd16b9e8b5da8efbbcad7a83f08491db4777c11 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Wed, 2 Nov 2016 18:09:08 -0700 Subject: [PATCH 251/259] Extrusion shader cleanup: * Remove unnecessary IFDEFS * Rename a_minH to a_base and a_maxH to a_height for naming consistency * Remove unused color attributes from fill_extrusion_pattern shaders --- src/fill_extrusion.fragment.glsl | 12 ++++-------- src/fill_extrusion.vertex.glsl | 19 ++++++------------- src/fill_extrusion_pattern.fragment.glsl | 14 ++++---------- src/fill_extrusion_pattern.vertex.glsl | 22 ++++++---------------- 4 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/fill_extrusion.fragment.glsl b/src/fill_extrusion.fragment.glsl index d327707b67e..661aecc801f 100644 --- a/src/fill_extrusion.fragment.glsl +++ b/src/fill_extrusion.fragment.glsl @@ -7,17 +7,13 @@ precision mediump float; #endif varying vec4 v_color; -#ifdef MAPBOX_GL_JS -#pragma mapbox: define lowp float minH -#pragma mapbox: define lowp float maxH -#endif +#pragma mapbox: define lowp float base +#pragma mapbox: define lowp float height #pragma mapbox: define lowp vec4 color void main() { -#ifdef MAPBOX_GL_JS - #pragma mapbox: initialize lowp float minH - #pragma mapbox: initialize lowp float maxH -#endif + #pragma mapbox: initialize lowp float base + #pragma mapbox: initialize lowp float height #pragma mapbox: initialize lowp vec4 color gl_FragColor = v_color; diff --git a/src/fill_extrusion.vertex.glsl b/src/fill_extrusion.vertex.glsl index ed22459a810..c4a3ab147ba 100644 --- a/src/fill_extrusion.vertex.glsl +++ b/src/fill_extrusion.vertex.glsl @@ -18,27 +18,20 @@ attribute float a_edgedistance; varying vec4 v_color; -#ifndef MAPBOX_GL_JS -attribute float minH; -attribute float maxH; -#else -#pragma mapbox: define lowp float minH -#pragma mapbox: define lowp float maxH -#endif +#pragma mapbox: define lowp float base +#pragma mapbox: define lowp float height #pragma mapbox: define lowp vec4 color void main() { -#ifdef MAPBOX_GL_JS - #pragma mapbox: initialize lowp float minH - #pragma mapbox: initialize lowp float maxH -#endif + #pragma mapbox: initialize lowp float base + #pragma mapbox: initialize lowp float height #pragma mapbox: initialize lowp vec4 color float ed = a_edgedistance; // use each attrib in order to not trip a VAO assert float t = mod(a_normal.x, 2.0); - gl_Position = u_matrix * vec4(a_pos, t > 0.0 ? maxH : minH, 1); + gl_Position = u_matrix * vec4(a_pos, t > 0.0 ? height : base, 1); #ifdef OUTLINE color = u_outline_color; @@ -64,7 +57,7 @@ void main() { // Add gradient along z axis of side surfaces if (a_normal.y != 0.0) { - directional *= clamp((t + minH) * pow(maxH / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); + directional *= clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); } // Assign final color based on surface + ambient light color, diffuse light directional, and light color diff --git a/src/fill_extrusion_pattern.fragment.glsl b/src/fill_extrusion_pattern.fragment.glsl index 368c0c4a2ec..883345486d4 100644 --- a/src/fill_extrusion_pattern.fragment.glsl +++ b/src/fill_extrusion_pattern.fragment.glsl @@ -18,18 +18,12 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec4 v_lighting; -#ifdef MAPBOX_GL_JS -#pragma mapbox: define lowp float minH -#pragma mapbox: define lowp float maxH -#endif -#pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float base +#pragma mapbox: define lowp float height void main() { -#ifdef MAPBOX_GL_JS - #pragma mapbox: initialize lowp float minH - #pragma mapbox: initialize lowp float maxH -#endif - #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float base + #pragma mapbox: initialize lowp float height vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); diff --git a/src/fill_extrusion_pattern.vertex.glsl b/src/fill_extrusion_pattern.vertex.glsl index 0143e28de32..423f555b643 100644 --- a/src/fill_extrusion_pattern.vertex.glsl +++ b/src/fill_extrusion_pattern.vertex.glsl @@ -29,25 +29,15 @@ varying vec2 v_pos_b; varying vec4 v_lighting; varying float v_directional; -#ifndef MAPBOX_GL_JS -attribute float minH; -attribute float maxH; -#else -#pragma mapbox: define lowp float minH -#pragma mapbox: define lowp float maxH -#endif - -#pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float base +#pragma mapbox: define lowp float height void main() { -#ifdef MAPBOX_GL_JS - #pragma mapbox: initialize lowp float minH - #pragma mapbox: initialize lowp float maxH -#endif - #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float base + #pragma mapbox: initialize lowp float height float t = mod(a_normal.x, 2.0); - float z = t > 0.0 ? maxH : minH; + float z = t > 0.0 ? height : base; gl_Position = u_matrix * vec4(a_pos, z, 1); @@ -75,7 +65,7 @@ void main() { directional = mix((1.0 - u_lightintensity), max((0.5 + u_lightintensity), 1.0), directional); if (a_normal.y != 0.0) { - directional *= clamp((t + minH) * pow(maxH / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); + directional *= clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0); } v_lighting.rgb += clamp(directional * u_lightcolor, mix(vec3(0.0), vec3(0.3), 1.0 - u_lightcolor), vec3(1.0)); From 7f1c3bef3692f1d044035a22e65c8758b7630333 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Sun, 6 Nov 2016 12:40:48 -0800 Subject: [PATCH 252/259] introduce fragment/vertex prelude for shared code --- index.js | 6 ++++-- src/_prelude.fragment.glsl | 7 +++++++ util.vertex.glsl => src/_prelude.vertex.glsl | 8 ++++++++ src/circle.fragment.glsl | 8 -------- src/circle.vertex.glsl | 8 -------- src/collision_box.fragment.glsl | 8 -------- src/collision_box.vertex.glsl | 8 -------- src/debug.fragment.glsl | 8 -------- src/debug.vertex.glsl | 8 -------- src/extrusion_texture.fragment.glsl | 8 -------- src/extrusion_texture.vertex.glsl | 8 -------- src/fill.fragment.glsl | 8 -------- src/fill.vertex.glsl | 8 -------- src/fill_extrusion.fragment.glsl | 8 -------- src/fill_extrusion.vertex.glsl | 8 -------- src/fill_extrusion_pattern.fragment.glsl | 8 -------- src/fill_extrusion_pattern.vertex.glsl | 8 -------- src/fill_outline.fragment.glsl | 8 -------- src/fill_outline.vertex.glsl | 8 -------- src/fill_outline_pattern.fragment.glsl | 10 +--------- src/fill_outline_pattern.vertex.glsl | 8 -------- src/fill_pattern.fragment.glsl | 8 -------- src/fill_pattern.vertex.glsl | 8 -------- src/line.fragment.glsl | 8 -------- src/line.vertex.glsl | 8 -------- src/line_pattern.fragment.glsl | 8 -------- src/line_pattern.vertex.glsl | 8 -------- src/line_sdf.fragment.glsl | 8 -------- src/line_sdf.vertex.glsl | 8 -------- src/raster.fragment.glsl | 8 -------- src/raster.vertex.glsl | 8 -------- src/symbol_icon.fragment.glsl | 8 -------- src/symbol_icon.vertex.glsl | 8 -------- src/symbol_sdf.fragment.glsl | 8 -------- src/symbol_sdf.vertex.glsl | 8 -------- 35 files changed, 20 insertions(+), 259 deletions(-) create mode 100644 src/_prelude.fragment.glsl rename util.vertex.glsl => src/_prelude.vertex.glsl (86%) diff --git a/index.js b/index.js index e1938391f24..1abfc76f5eb 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,10 @@ var path = require('path'); // readFileSync calls must be written out long-form for brfs. module.exports = { + prelude: { + fragmentSource: fs.readFileSync(path.join(__dirname, 'src/_prelude.fragment.glsl'), 'utf8'), + vertexSource: fs.readFileSync(path.join(__dirname, 'src/_prelude.vertex.glsl'), 'utf8') + }, circle: { fragmentSource: fs.readFileSync(path.join(__dirname, 'src/circle.fragment.glsl'), 'utf8'), vertexSource: fs.readFileSync(path.join(__dirname, 'src/circle.vertex.glsl'), 'utf8') @@ -68,5 +72,3 @@ module.exports = { vertexSource: fs.readFileSync(path.join(__dirname, 'src/symbol_sdf.vertex.glsl'), 'utf8') } }; - -module.exports.util = fs.readFileSync(path.join(__dirname, 'util.vertex.glsl'), 'utf8'); diff --git a/src/_prelude.fragment.glsl b/src/_prelude.fragment.glsl new file mode 100644 index 00000000000..d332e991da9 --- /dev/null +++ b/src/_prelude.fragment.glsl @@ -0,0 +1,7 @@ +#ifdef GL_ES +precision mediump float; +#else +#define lowp +#define mediump +#define highp +#endif diff --git a/util.vertex.glsl b/src/_prelude.vertex.glsl similarity index 86% rename from util.vertex.glsl rename to src/_prelude.vertex.glsl index 61ae80755bf..52703e2a954 100644 --- a/util.vertex.glsl +++ b/src/_prelude.vertex.glsl @@ -1,3 +1,11 @@ +#ifdef GL_ES +precision highp float; +#else +#define lowp +#define mediump +#define highp +#endif + float evaluate_zoom_function_1(const vec4 values, const float t) { if (t < 1.0) { return mix(values[0], values[1], t); diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 82b7be431b0..19f32615454 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - #pragma mapbox: define lowp vec4 color #pragma mapbox: define lowp float blur #pragma mapbox: define lowp float opacity diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index d96cce41762..445ef958f49 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform mat4 u_matrix; uniform bool u_scale_with_map; uniform vec2 u_extrude_scale; diff --git a/src/collision_box.fragment.glsl b/src/collision_box.fragment.glsl index 5b8be6c824b..030f1219f8e 100644 --- a/src/collision_box.fragment.glsl +++ b/src/collision_box.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform float u_zoom; uniform float u_maxzoom; diff --git a/src/collision_box.vertex.glsl b/src/collision_box.vertex.glsl index 33eaf2dd48d..d141b13873a 100644 --- a/src/collision_box.vertex.glsl +++ b/src/collision_box.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - attribute vec2 a_pos; attribute vec2 a_extrude; attribute vec2 a_data; diff --git a/src/debug.fragment.glsl b/src/debug.fragment.glsl index fbe40df76e4..533b9632e61 100644 --- a/src/debug.fragment.glsl +++ b/src/debug.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform lowp vec4 u_color; void main() { diff --git a/src/debug.vertex.glsl b/src/debug.vertex.glsl index cd0974cb552..71f42b9935f 100644 --- a/src/debug.vertex.glsl +++ b/src/debug.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - attribute vec2 a_pos; uniform mat4 u_matrix; diff --git a/src/extrusion_texture.fragment.glsl b/src/extrusion_texture.fragment.glsl index 6eac6fede50..a9b809df360 100644 --- a/src/extrusion_texture.fragment.glsl +++ b/src/extrusion_texture.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform sampler2D u_texture; uniform float u_opacity; diff --git a/src/extrusion_texture.vertex.glsl b/src/extrusion_texture.vertex.glsl index 506c265fdcf..0ad8fdcbcae 100644 --- a/src/extrusion_texture.vertex.glsl +++ b/src/extrusion_texture.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform mat4 u_matrix; uniform int u_xdim; uniform int u_ydim; diff --git a/src/fill.fragment.glsl b/src/fill.fragment.glsl index 8598263fc82..d52c6205aa1 100644 --- a/src/fill.fragment.glsl +++ b/src/fill.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - #pragma mapbox: define lowp vec4 color #pragma mapbox: define lowp float opacity diff --git a/src/fill.vertex.glsl b/src/fill.vertex.glsl index 59285163627..da61e469653 100644 --- a/src/fill.vertex.glsl +++ b/src/fill.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - attribute vec2 a_pos; uniform mat4 u_matrix; diff --git a/src/fill_extrusion.fragment.glsl b/src/fill_extrusion.fragment.glsl index 661aecc801f..991f23dd42c 100644 --- a/src/fill_extrusion.fragment.glsl +++ b/src/fill_extrusion.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - varying vec4 v_color; #pragma mapbox: define lowp float base #pragma mapbox: define lowp float height diff --git a/src/fill_extrusion.vertex.glsl b/src/fill_extrusion.vertex.glsl index c4a3ab147ba..03e159528d5 100644 --- a/src/fill_extrusion.vertex.glsl +++ b/src/fill_extrusion.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform mat4 u_matrix; uniform vec3 u_lightcolor; uniform lowp vec3 u_lightpos; diff --git a/src/fill_extrusion_pattern.fragment.glsl b/src/fill_extrusion_pattern.fragment.glsl index 883345486d4..d216f3b8a59 100644 --- a/src/fill_extrusion_pattern.fragment.glsl +++ b/src/fill_extrusion_pattern.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; diff --git a/src/fill_extrusion_pattern.vertex.glsl b/src/fill_extrusion_pattern.vertex.glsl index 423f555b643..971e70ae073 100644 --- a/src/fill_extrusion_pattern.vertex.glsl +++ b/src/fill_extrusion_pattern.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform mat4 u_matrix; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; diff --git a/src/fill_outline.fragment.glsl b/src/fill_outline.fragment.glsl index 864c1524dd9..98da5c5d352 100644 --- a/src/fill_outline.fragment.glsl +++ b/src/fill_outline.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - #pragma mapbox: define lowp vec4 outline_color #pragma mapbox: define lowp float opacity diff --git a/src/fill_outline.vertex.glsl b/src/fill_outline.vertex.glsl index f5c92d8373d..2d16aa508e5 100644 --- a/src/fill_outline.vertex.glsl +++ b/src/fill_outline.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - attribute vec2 a_pos; uniform mat4 u_matrix; diff --git a/src/fill_outline_pattern.fragment.glsl b/src/fill_outline_pattern.fragment.glsl index a7624597029..6e66ba2e55e 100644 --- a/src/fill_outline_pattern.fragment.glsl +++ b/src/fill_outline_pattern.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; @@ -32,7 +24,7 @@ void main() { float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); - + gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; diff --git a/src/fill_outline_pattern.vertex.glsl b/src/fill_outline_pattern.vertex.glsl index dc02bbb23cc..891b8a0745b 100644 --- a/src/fill_outline_pattern.vertex.glsl +++ b/src/fill_outline_pattern.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; uniform vec2 u_pixel_coord_upper; diff --git a/src/fill_pattern.fragment.glsl b/src/fill_pattern.fragment.glsl index bb1c7187bd5..b87c3c5330d 100644 --- a/src/fill_pattern.fragment.glsl +++ b/src/fill_pattern.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; diff --git a/src/fill_pattern.vertex.glsl b/src/fill_pattern.vertex.glsl index d949a2fe0aa..87ec48aec83 100644 --- a/src/fill_pattern.vertex.glsl +++ b/src/fill_pattern.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform mat4 u_matrix; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index 611f3be42ed..514d8aa46f4 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform lowp float u_opacity; uniform float u_blur; diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index 5ad58b2e6d3..0372227fb3e 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/src/line_pattern.fragment.glsl b/src/line_pattern.fragment.glsl index 4f1815f8548..96ebae73d7f 100644 --- a/src/line_pattern.fragment.glsl +++ b/src/line_pattern.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform float u_blur; uniform vec2 u_pattern_size_a; diff --git a/src/line_pattern.vertex.glsl b/src/line_pattern.vertex.glsl index a1b812ba0eb..8ed6e5a850a 100644 --- a/src/line_pattern.vertex.glsl +++ b/src/line_pattern.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/src/line_sdf.fragment.glsl b/src/line_sdf.fragment.glsl index 714f3e94967..e9890c0f786 100644 --- a/src/line_sdf.fragment.glsl +++ b/src/line_sdf.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform lowp float u_opacity; uniform float u_blur; diff --git a/src/line_sdf.vertex.glsl b/src/line_sdf.vertex.glsl index 5d70d12d4c6..9f835badc8e 100644 --- a/src/line_sdf.vertex.glsl +++ b/src/line_sdf.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/src/raster.fragment.glsl b/src/raster.fragment.glsl index d05c54fbbf4..25f921abdb3 100644 --- a/src/raster.fragment.glsl +++ b/src/raster.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform float u_opacity0; uniform float u_opacity1; uniform sampler2D u_image0; diff --git a/src/raster.vertex.glsl b/src/raster.vertex.glsl index 70f68446ec8..987212d88ff 100644 --- a/src/raster.vertex.glsl +++ b/src/raster.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; diff --git a/src/symbol_icon.fragment.glsl b/src/symbol_icon.fragment.glsl index 3a30054b425..e5a718f38f6 100644 --- a/src/symbol_icon.fragment.glsl +++ b/src/symbol_icon.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform sampler2D u_texture; uniform sampler2D u_fadetexture; uniform lowp float u_opacity; diff --git a/src/symbol_icon.vertex.glsl b/src/symbol_icon.vertex.glsl index 8e5888d3ea3..ac4af37d088 100644 --- a/src/symbol_icon.vertex.glsl +++ b/src/symbol_icon.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - attribute vec2 a_pos; attribute vec2 a_offset; attribute vec2 a_texture_pos; diff --git a/src/symbol_sdf.fragment.glsl b/src/symbol_sdf.fragment.glsl index 490fc323c76..9662bd17c1a 100644 --- a/src/symbol_sdf.fragment.glsl +++ b/src/symbol_sdf.fragment.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision mediump float; -#else -#define lowp -#define mediump -#define highp -#endif - uniform sampler2D u_texture; uniform sampler2D u_fadetexture; uniform lowp vec4 u_color; diff --git a/src/symbol_sdf.vertex.glsl b/src/symbol_sdf.vertex.glsl index 771eb0e6843..223b79161fc 100644 --- a/src/symbol_sdf.vertex.glsl +++ b/src/symbol_sdf.vertex.glsl @@ -1,11 +1,3 @@ -#ifdef GL_ES -precision highp float; -#else -#define lowp -#define mediump -#define highp -#endif - const float PI = 3.141592653589793; attribute vec2 a_pos; From 749859b165cd0d96cf52d200e20e3ef7a66e0001 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Sun, 6 Nov 2016 13:25:14 -0800 Subject: [PATCH 253/259] extract common pattern code to the vertex prelude --- src/_prelude.vertex.glsl | 18 ++++++++++++++++ src/fill_extrusion_pattern.vertex.glsl | 22 +++++-------------- src/fill_outline_pattern.vertex.glsl | 29 ++++---------------------- src/fill_pattern.vertex.glsl | 24 ++------------------- 4 files changed, 29 insertions(+), 64 deletions(-) diff --git a/src/_prelude.vertex.glsl b/src/_prelude.vertex.glsl index 52703e2a954..d689f2784f0 100644 --- a/src/_prelude.vertex.glsl +++ b/src/_prelude.vertex.glsl @@ -24,3 +24,21 @@ vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 v return mix(value2, value3, t - 2.0); } } + +// The offset depends on how many pixels are between the world origin and the edge of the tile: +// vec2 offset = mod(pixel_coord, size) +// +// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. +// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. +// +// The pixel_coord is passed in as two 16 bit values: +// pixel_coord_upper = floor(pixel_coord / 2^16) +// pixel_coord_lower = mod(pixel_coord, 2^16) +// +// The offset is calculated in a series of steps that should preserve this precision: +vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, + const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { + + vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); + return (tile_units_to_pixels * pos + offset) / pattern_size; +} diff --git a/src/fill_extrusion_pattern.vertex.glsl b/src/fill_extrusion_pattern.vertex.glsl index 971e70ae073..6e3af021e8f 100644 --- a/src/fill_extrusion_pattern.vertex.glsl +++ b/src/fill_extrusion_pattern.vertex.glsl @@ -33,24 +33,12 @@ void main() { gl_Position = u_matrix * vec4(a_pos, z, 1); - vec2 scaled_size_a = u_scale_a * u_pattern_size_a; - vec2 scaled_size_b = u_scale_b * u_pattern_size_b; + vec2 pos = a_normal.x == 1.0 && a_normal.y == 0.0 && a_normal.z == 16384.0 + ? a_pos // extrusion top + : vec2(a_edgedistance, z * u_height_factor); // extrusion side - // the following offset calculation is duplicated from the regular pattern shader: - vec2 offset_a = mod(mod(mod(u_pixel_coord_upper, scaled_size_a) * 256.0, scaled_size_a) * 256.0 + u_pixel_coord_lower, scaled_size_a); - vec2 offset_b = mod(mod(mod(u_pixel_coord_upper, scaled_size_b) * 256.0, scaled_size_b) * 256.0 + u_pixel_coord_lower, scaled_size_b); - - if (a_normal.x == 1.0 && a_normal.y == 0.0 && a_normal.z == 16384.0) { - // extrusion top - v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; - v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; - } else { - // extrusion side - float hf = z * u_height_factor; - - v_pos_a = (u_tile_units_to_pixels * vec2(a_edgedistance, hf) + offset_a) / scaled_size_a; - v_pos_b = (u_tile_units_to_pixels * vec2(a_edgedistance, hf) + offset_b) / scaled_size_b; - } + v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, pos); + v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, pos); v_lighting = vec4(0.0, 0.0, 0.0, 1.0); float directional = clamp(dot(a_normal / 16383.0, u_lightpos), 0.0, 1.0); diff --git a/src/fill_outline_pattern.vertex.glsl b/src/fill_outline_pattern.vertex.glsl index 891b8a0745b..04a6633cb48 100644 --- a/src/fill_outline_pattern.vertex.glsl +++ b/src/fill_outline_pattern.vertex.glsl @@ -1,3 +1,5 @@ +uniform mat4 u_matrix; +uniform vec2 u_world; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; uniform vec2 u_pixel_coord_upper; @@ -8,38 +10,15 @@ uniform float u_tile_units_to_pixels; attribute vec2 a_pos; -uniform mat4 u_matrix; -uniform vec2 u_world; - varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec2 v_pos; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - vec2 scaled_size_a = u_scale_a * u_pattern_size_a; - vec2 scaled_size_b = u_scale_b * u_pattern_size_b; - - // the correct offset needs to be calculated. - // - // The offset depends on how many pixels are between the world origin and - // the edge of the tile: - // vec2 offset = mod(pixel_coord, size) - // - // At high zoom levels there are a ton of pixels between the world origin - // and the edge of the tile. The glsl spec only guarantees 16 bits of - // precision for highp floats. We need more than that. - // - // The pixel_coord is passed in as two 16 bit values: - // pixel_coord_upper = floor(pixel_coord / 2^16) - // pixel_coord_lower = mod(pixel_coord, 2^16) - // - // The offset is calculated in a series of steps that should preserve this precision: - vec2 offset_a = mod(mod(mod(u_pixel_coord_upper, scaled_size_a) * 256.0, scaled_size_a) * 256.0 + u_pixel_coord_lower, scaled_size_a); - vec2 offset_b = mod(mod(mod(u_pixel_coord_upper, scaled_size_b) * 256.0, scaled_size_b) * 256.0 + u_pixel_coord_lower, scaled_size_b); - v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; - v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; + v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos); + v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, a_pos); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } diff --git a/src/fill_pattern.vertex.glsl b/src/fill_pattern.vertex.glsl index 87ec48aec83..e8935a06270 100644 --- a/src/fill_pattern.vertex.glsl +++ b/src/fill_pattern.vertex.glsl @@ -14,27 +14,7 @@ varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - vec2 scaled_size_a = u_scale_a * u_pattern_size_a; - vec2 scaled_size_b = u_scale_b * u_pattern_size_b; - // the correct offset needs to be calculated. - // - // The offset depends on how many pixels are between the world origin and - // the edge of the tile: - // vec2 offset = mod(pixel_coord, size) - // - // At high zoom levels there are a ton of pixels between the world origin - // and the edge of the tile. The glsl spec only guarantees 16 bits of - // precision for highp floats. We need more than that. - // - // The pixel_coord is passed in as two 16 bit values: - // pixel_coord_upper = floor(pixel_coord / 2^16) - // pixel_coord_lower = mod(pixel_coord, 2^16) - // - // The offset is calculated in a series of steps that should preserve this precision: - vec2 offset_a = mod(mod(mod(u_pixel_coord_upper, scaled_size_a) * 256.0, scaled_size_a) * 256.0 + u_pixel_coord_lower, scaled_size_a); - vec2 offset_b = mod(mod(mod(u_pixel_coord_upper, scaled_size_b) * 256.0, scaled_size_b) * 256.0 + u_pixel_coord_lower, scaled_size_b); - - v_pos_a = (u_tile_units_to_pixels * a_pos + offset_a) / scaled_size_a; - v_pos_b = (u_tile_units_to_pixels * a_pos + offset_b) / scaled_size_b; + v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos); + v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, a_pos); } From 5d7b99a4fd286e8b58a219a4247ca446746a462b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 11 Nov 2016 13:50:48 -0800 Subject: [PATCH 254/259] Support fill-pattern + data-driven fill-opacity --- src/fill_outline_pattern.fragment.glsl | 7 +++++-- src/fill_outline_pattern.vertex.glsl | 4 ++++ src/fill_pattern.fragment.glsl | 6 ++++-- src/fill_pattern.vertex.glsl | 4 ++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/fill_outline_pattern.fragment.glsl b/src/fill_outline_pattern.fragment.glsl index 6e66ba2e55e..12c6bd3c27a 100644 --- a/src/fill_outline_pattern.fragment.glsl +++ b/src/fill_outline_pattern.fragment.glsl @@ -1,4 +1,3 @@ -uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; @@ -11,7 +10,11 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec2 v_pos; +#pragma mapbox: define lowp float opacity + void main() { + #pragma mapbox: initialize lowp float opacity + vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); vec4 color1 = texture2D(u_image, pos); @@ -26,7 +29,7 @@ void main() { float alpha = smoothstep(1.0, 0.0, dist); - gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; + gl_FragColor = mix(color1, color2, u_mix) * alpha * opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/fill_outline_pattern.vertex.glsl b/src/fill_outline_pattern.vertex.glsl index 04a6633cb48..43f6916001c 100644 --- a/src/fill_outline_pattern.vertex.glsl +++ b/src/fill_outline_pattern.vertex.glsl @@ -14,7 +14,11 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec2 v_pos; +#pragma mapbox: define lowp float opacity + void main() { + #pragma mapbox: initialize lowp float opacity + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos); diff --git a/src/fill_pattern.fragment.glsl b/src/fill_pattern.fragment.glsl index b87c3c5330d..18527cb492e 100644 --- a/src/fill_pattern.fragment.glsl +++ b/src/fill_pattern.fragment.glsl @@ -1,4 +1,3 @@ -uniform float u_opacity; uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; @@ -10,7 +9,10 @@ uniform sampler2D u_image; varying vec2 v_pos_a; varying vec2 v_pos_b; +#pragma mapbox: define lowp float opacity + void main() { + #pragma mapbox: initialize lowp float opacity vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); @@ -20,7 +22,7 @@ void main() { vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); vec4 color2 = texture2D(u_image, pos2); - gl_FragColor = mix(color1, color2, u_mix) * u_opacity; + gl_FragColor = mix(color1, color2, u_mix) * opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/fill_pattern.vertex.glsl b/src/fill_pattern.vertex.glsl index e8935a06270..8672a7cffc6 100644 --- a/src/fill_pattern.vertex.glsl +++ b/src/fill_pattern.vertex.glsl @@ -12,7 +12,11 @@ attribute vec2 a_pos; varying vec2 v_pos_a; varying vec2 v_pos_b; +#pragma mapbox: define lowp float opacity + void main() { + #pragma mapbox: initialize lowp float opacity + gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos); From ec891ce5360e488d81f60991f95d2038b83c4e3c Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 14 Nov 2016 14:02:23 +0100 Subject: [PATCH 255/259] Avoid redefining precision macros --- src/_prelude.fragment.glsl | 10 ++++++++++ src/_prelude.vertex.glsl | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/_prelude.fragment.glsl b/src/_prelude.fragment.glsl index d332e991da9..e98fb22d587 100644 --- a/src/_prelude.fragment.glsl +++ b/src/_prelude.fragment.glsl @@ -1,7 +1,17 @@ #ifdef GL_ES precision mediump float; #else + +#if !defined(lowp) #define lowp +#endif + +#if !defined(mediump) #define mediump +#endif + +#if !defined(highp) #define highp #endif + +#endif diff --git a/src/_prelude.vertex.glsl b/src/_prelude.vertex.glsl index d689f2784f0..a5a972818eb 100644 --- a/src/_prelude.vertex.glsl +++ b/src/_prelude.vertex.glsl @@ -1,11 +1,21 @@ #ifdef GL_ES precision highp float; #else + +#if !defined(lowp) #define lowp +#endif + +#if !defined(mediump) #define mediump +#endif + +#if !defined(highp) #define highp #endif +#endif + float evaluate_zoom_function_1(const vec4 values, const float t) { if (t < 1.0) { return mix(values[0], values[1], t); From 8b5651ac83e175fb340e5dc0146e0c7bf11cc604 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Wed, 16 Nov 2016 20:33:14 -0500 Subject: [PATCH 256/259] Add support for line paint property functions (#24) * Add support for line-blur property functions * Add support for line-opacity property functions * Remove "u_antialiasing" * Add support for misc line property functions * remove u_blur and u_opacity from line_sdf * remove u_devicepixelratio in favor of DEVICE_PIXEL_RATIO * move line transformation logic to shaders * DRY-ify line transformation math * remove unused var from line fragment shader --- src/circle.vertex.glsl | 3 +-- src/line.fragment.glsl | 21 +++++++++--------- src/line.vertex.glsl | 40 ++++++++++++++++++++++++---------- src/line_pattern.fragment.glsl | 29 ++++++++++++------------ src/line_pattern.vertex.glsl | 38 +++++++++++++++++++++++--------- src/line_sdf.fragment.glsl | 20 +++++++++-------- src/line_sdf.vertex.glsl | 36 ++++++++++++++++++++---------- 7 files changed, 120 insertions(+), 67 deletions(-) diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index 445ef958f49..601c161479e 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -1,7 +1,6 @@ uniform mat4 u_matrix; uniform bool u_scale_with_map; uniform vec2 u_extrude_scale; -uniform float u_devicepixelratio; attribute vec2 a_pos; @@ -36,5 +35,5 @@ void main(void) { // 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. - v_antialiasblur = 1.0 / u_devicepixelratio / radius; + v_antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / radius; } diff --git a/src/line.fragment.glsl b/src/line.fragment.glsl index 514d8aa46f4..d422489b112 100644 --- a/src/line.fragment.glsl +++ b/src/line.fragment.glsl @@ -1,25 +1,26 @@ -uniform lowp float u_opacity; -uniform float u_blur; - #pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity -varying vec2 v_linewidth; +varying vec2 v_width2; varying vec2 v_normal; varying float v_gamma_scale; void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * v_linewidth.s; + float dist = length(v_normal) * v_width2.s; // Calculate the antialiasing fade factor. This is either when fading in - // the line in case of an offset line (v_linewidth.t) or when fading out - // (v_linewidth.s) - float blur = u_blur * v_gamma_scale; - float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); + // the line in case of an offset line (v_width2.t) or when fading out + // (v_width2.s) + float blur2 = (blur + 1.0 / DEVICE_PIXEL_RATIO) * v_gamma_scale; + float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0); - gl_FragColor = color * (alpha * u_opacity); + gl_FragColor = color * (alpha * opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index 0372227fb3e..a820b105ee4 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -1,3 +1,9 @@ + + +// the distance over which the line edge fades out. +// Retina devices need a smaller distance to avoid aliasing. +#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 + // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but @@ -11,22 +17,27 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; -uniform mediump float u_linewidth; -uniform mediump float u_gapwidth; -uniform mediump float u_antialiasing; uniform mediump float u_extra; uniform mat2 u_antialiasingmatrix; -uniform mediump float u_offset; -uniform mediump float u_blur; varying vec2 v_normal; -varying vec2 v_linewidth; +varying vec2 v_width2; varying float v_gamma_scale; #pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity +#pragma mapbox: define lowp float width +#pragma mapbox: define mediump float gapwidth +#pragma mapbox: define lowp float offset void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity + #pragma mapbox: initialize lowp float width + #pragma mapbox: initialize mediump float gapwidth + #pragma mapbox: initialize lowp float offset vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -39,8 +50,15 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; - float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); - float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; + + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. + gapwidth = gapwidth / 2.0; + width = width / 2.0; + offset = -1.0 * offset; + + float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); + float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. @@ -52,11 +70,11 @@ void main() { // extrude vector points in another direction. mediump float u = 0.5 * a_direction; mediump float t = 1.0 - abs(u); - mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset2 + dist) / u_ratio, 0.0, 1.0); // position of y on the screen float y = gl_Position.y / gl_Position.w; @@ -67,6 +85,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); - v_linewidth = vec2(outset, inset); + v_width2 = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; } diff --git a/src/line_pattern.fragment.glsl b/src/line_pattern.fragment.glsl index 96ebae73d7f..33003a77442 100644 --- a/src/line_pattern.fragment.glsl +++ b/src/line_pattern.fragment.glsl @@ -1,5 +1,3 @@ -uniform float u_blur; - uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; uniform vec2 u_pattern_tl_a; @@ -7,37 +5,40 @@ uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; uniform vec2 u_pattern_br_b; uniform float u_fade; -uniform float u_opacity; uniform sampler2D u_image; varying vec2 v_normal; -varying vec2 v_linewidth; +varying vec2 v_width2; varying float v_linesofar; varying float v_gamma_scale; +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity + void main() { + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity + // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * v_linewidth.s; + float dist = length(v_normal) * v_width2.s; // Calculate the antialiasing fade factor. This is either when fading in - // the line in case of an offset line (v_linewidth.t) or when fading out - // (v_linewidth.s) - float blur = u_blur * v_gamma_scale; - float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); + // the line in case of an offset line (v_width2.t) or when fading out + // (v_width2.s) + float blur2 = (blur + 1.0 / DEVICE_PIXEL_RATIO) * v_gamma_scale; + float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0); float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); - float y_a = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_a.y); - float y_b = 0.5 + (v_normal.y * v_linewidth.s / u_pattern_size_b.y); + float y_a = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_a.y); + float y_b = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_b.y); vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); vec4 color = mix(texture2D(u_image, pos_a), texture2D(u_image, pos_b), u_fade); - alpha *= u_opacity; - - gl_FragColor = color * alpha; + gl_FragColor = color * alpha * opacity; #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/line_pattern.vertex.glsl b/src/line_pattern.vertex.glsl index 8ed6e5a850a..86e19a43025 100644 --- a/src/line_pattern.vertex.glsl +++ b/src/line_pattern.vertex.glsl @@ -10,24 +10,36 @@ // long distances for long segments. Use this value to unscale the distance. #define LINE_DISTANCE_SCALE 2.0 +// the distance over which the line edge fades out. +// Retina devices need a smaller distance to avoid aliasing. +#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 + attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; -uniform mediump float u_linewidth; -uniform mediump float u_gapwidth; -uniform mediump float u_antialiasing; uniform mediump float u_extra; uniform mat2 u_antialiasingmatrix; -uniform mediump float u_offset; varying vec2 v_normal; -varying vec2 v_linewidth; +varying vec2 v_width2; varying float v_linesofar; varying float v_gamma_scale; +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity +#pragma mapbox: define lowp float width +#pragma mapbox: define lowp float offset +#pragma mapbox: define mediump float gapwidth + void main() { + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity + #pragma mapbox: initialize lowp float width + #pragma mapbox: initialize lowp float offset + #pragma mapbox: initialize mediump float gapwidth + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; @@ -40,8 +52,14 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; - float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); - float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. + gapwidth = gapwidth / 2.0; + width = width / 2.0; + offset = -1.0 * offset; + + float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); + float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. @@ -53,11 +71,11 @@ void main() { // extrude vector points in another direction. mediump float u = 0.5 * a_direction; mediump float t = 1.0 - abs(u); - mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset2 + dist) / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar; // position of y on the screen @@ -69,6 +87,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); - v_linewidth = vec2(outset, inset); + v_width2 = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; } diff --git a/src/line_sdf.fragment.glsl b/src/line_sdf.fragment.glsl index e9890c0f786..ec6aa7be71f 100644 --- a/src/line_sdf.fragment.glsl +++ b/src/line_sdf.fragment.glsl @@ -1,36 +1,38 @@ -uniform lowp float u_opacity; -uniform float u_blur; uniform sampler2D u_image; uniform float u_sdfgamma; uniform float u_mix; varying vec2 v_normal; -varying vec2 v_linewidth; +varying vec2 v_width2; varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; #pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float opacity void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float opacity // Calculate the distance of the pixel from the line in pixels. - float dist = length(v_normal) * v_linewidth.s; + float dist = length(v_normal) * v_width2.s; // Calculate the antialiasing fade factor. This is either when fading in - // the line in case of an offset line (v_linewidth.t) or when fading out - // (v_linewidth.s) - float blur = u_blur * v_gamma_scale; - float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0); + // the line in case of an offset line (v_width2.t) or when fading out + // (v_width2.s) + float blur2 = (blur + 1.0 / DEVICE_PIXEL_RATIO) * v_gamma_scale; + float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0); float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); - gl_FragColor = color * (alpha * u_opacity); + gl_FragColor = color * (alpha * opacity); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/line_sdf.vertex.glsl b/src/line_sdf.vertex.glsl index 9f835badc8e..2ace5e30523 100644 --- a/src/line_sdf.vertex.glsl +++ b/src/line_sdf.vertex.glsl @@ -10,32 +10,40 @@ // long distances for long segments. Use this value to unscale the distance. #define LINE_DISTANCE_SCALE 2.0 +// the distance over which the line edge fades out. +// Retina devices need a smaller distance to avoid aliasing. +#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 + attribute vec2 a_pos; attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; -uniform mediump float u_linewidth; -uniform mediump float u_gapwidth; -uniform mediump float u_antialiasing; uniform vec2 u_patternscale_a; uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; uniform float u_extra; uniform mat2 u_antialiasingmatrix; -uniform mediump float u_offset; varying vec2 v_normal; -varying vec2 v_linewidth; +varying vec2 v_width2; varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; #pragma mapbox: define lowp vec4 color +#pragma mapbox: define lowp float blur +#pragma mapbox: define lowp float width +#pragma mapbox: define mediump float gapwidth +#pragma mapbox: define lowp float offset void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize lowp float blur + #pragma mapbox: initialize lowp float width + #pragma mapbox: initialize mediump float gapwidth + #pragma mapbox: initialize lowp float offset vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -49,12 +57,18 @@ void main() { normal.y = sign(normal.y - 0.5); v_normal = normal; - float inset = u_gapwidth + (u_gapwidth > 0.0 ? u_antialiasing : 0.0); - float outset = u_gapwidth + u_linewidth * (u_gapwidth > 0.0 ? 2.0 : 1.0) + u_antialiasing; + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. + gapwidth = gapwidth / 2.0; + width = width / 2.0; + offset = -1.0 * offset; + + float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); + float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. - mediump vec2 dist = outset * a_extrude * scale; + mediump vec2 dist =outset * a_extrude * scale; // Calculate the offset when drawing a line that is to the side of the actual line. // We do this by creating a vector that points towards the extrude, but rotate @@ -62,11 +76,11 @@ void main() { // extrude vector points in another direction. mediump float u = 0.5 * a_direction; mediump float t = 1.0 - abs(u); - mediump vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); // Remove the texture normal bit of the position before scaling it with the // model/view matrix. - gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset + dist) / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos * 0.5) + (offset2 + dist) / u_ratio, 0.0, 1.0); v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); @@ -80,6 +94,6 @@ void main() { // how much features are squished in all directions by the perspectiveness float perspective_scale = 1.0 / (1.0 - min(y * u_extra, 0.9)); - v_linewidth = vec2(outset, inset); + v_width2 = vec2(outset, inset); v_gamma_scale = perspective_scale * squish_scale; } From bc72d7b0def94cb8388ab4add183b52c84d5128e Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Tue, 22 Nov 2016 10:55:40 -0500 Subject: [PATCH 257/259] add opacity to line_sdf.vertex to support dds opacity for dasharray lines (#38) --- src/line_sdf.vertex.glsl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/line_sdf.vertex.glsl b/src/line_sdf.vertex.glsl index 2ace5e30523..9c9b432088b 100644 --- a/src/line_sdf.vertex.glsl +++ b/src/line_sdf.vertex.glsl @@ -35,6 +35,7 @@ varying float v_gamma_scale; #pragma mapbox: define lowp vec4 color #pragma mapbox: define lowp float blur #pragma mapbox: define lowp float width +#pragma mapbox: define lowp float opacity #pragma mapbox: define mediump float gapwidth #pragma mapbox: define lowp float offset @@ -42,6 +43,7 @@ void main() { #pragma mapbox: initialize lowp vec4 color #pragma mapbox: initialize lowp float blur #pragma mapbox: initialize lowp float width + #pragma mapbox: initialize lowp float opacity #pragma mapbox: initialize mediump float gapwidth #pragma mapbox: initialize lowp float offset From 26733535ba2f1b164dd6a231d4d1868c3218eafd Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 29 Nov 2016 13:16:13 -0800 Subject: [PATCH 258/259] Add support for circle-stroke-* properties (#39) * Add support for circle-stroke-* properties * Fix merge artifacts * Eliminate common subexpressions, adjust formatting per PR review --- src/circle.fragment.glsl | 22 ++++++++++++++++++++-- src/circle.vertex.glsl | 10 ++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/circle.fragment.glsl b/src/circle.fragment.glsl index 19f32615454..5860c5e7296 100644 --- a/src/circle.fragment.glsl +++ b/src/circle.fragment.glsl @@ -1,17 +1,35 @@ #pragma mapbox: define lowp vec4 color +#pragma mapbox: define mediump float radius #pragma mapbox: define lowp float blur #pragma mapbox: define lowp float opacity +#pragma mapbox: define lowp vec4 stroke_color +#pragma mapbox: define mediump float stroke_width +#pragma mapbox: define lowp float stroke_opacity varying vec2 v_extrude; varying lowp float v_antialiasblur; void main() { #pragma mapbox: initialize lowp vec4 color + #pragma mapbox: initialize mediump float radius #pragma mapbox: initialize lowp float blur #pragma mapbox: initialize lowp float opacity + #pragma mapbox: initialize lowp vec4 stroke_color + #pragma mapbox: initialize mediump float stroke_width + #pragma mapbox: initialize lowp float stroke_opacity - float t = smoothstep(1.0 - max(blur, v_antialiasblur), 1.0, length(v_extrude)); - gl_FragColor = color * (1.0 - t) * opacity; + float extrude_length = length(v_extrude); + float antialiased_blur = -max(blur, v_antialiasblur); + + float opacity_t = smoothstep(0.0, antialiased_blur, extrude_length - 1.0); + + float color_t = stroke_width < 0.01 ? 0.0 : smoothstep( + antialiased_blur, + 0.0, + extrude_length - radius / (radius + stroke_width) + ); + + gl_FragColor = opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t); #ifdef OVERDRAW_INSPECTOR gl_FragColor = vec4(1.0); diff --git a/src/circle.vertex.glsl b/src/circle.vertex.glsl index 601c161479e..ee083278a96 100644 --- a/src/circle.vertex.glsl +++ b/src/circle.vertex.glsl @@ -8,6 +8,9 @@ attribute vec2 a_pos; #pragma mapbox: define mediump float radius #pragma mapbox: define lowp float blur #pragma mapbox: define lowp float opacity +#pragma mapbox: define lowp vec4 stroke_color +#pragma mapbox: define mediump float stroke_width +#pragma mapbox: define lowp float stroke_opacity varying vec2 v_extrude; varying lowp float v_antialiasblur; @@ -17,11 +20,14 @@ void main(void) { #pragma mapbox: initialize mediump float radius #pragma mapbox: initialize lowp float blur #pragma mapbox: initialize lowp float opacity + #pragma mapbox: initialize lowp vec4 stroke_color + #pragma mapbox: initialize mediump float stroke_width + #pragma mapbox: initialize lowp float stroke_opacity // unencode the extrusion vector that we snuck into the a_pos vector v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); - vec2 extrude = v_extrude * radius * u_extrude_scale; + vec2 extrude = v_extrude * (radius + stroke_width) * u_extrude_scale; // multiply a_pos by 0.5, since we had it * 2 in order to sneak // in extrusion data gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0, 1); @@ -35,5 +41,5 @@ void main(void) { // 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. - v_antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / radius; + v_antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / (radius + stroke_width); } From b51b85ffb8c512e228c36c5405293ce51d123519 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Fri, 2 Dec 2016 18:01:27 -0800 Subject: [PATCH 259/259] roll back property function support for line-width + line-dasharray (#40) --- src/line.vertex.glsl | 5 ++--- src/line_pattern.vertex.glsl | 5 ++--- src/line_sdf.vertex.glsl | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/line.vertex.glsl b/src/line.vertex.glsl index a820b105ee4..263c57759e5 100644 --- a/src/line.vertex.glsl +++ b/src/line.vertex.glsl @@ -19,6 +19,7 @@ uniform mat4 u_matrix; uniform mediump float u_ratio; uniform mediump float u_extra; uniform mat2 u_antialiasingmatrix; +uniform mediump float u_width; varying vec2 v_normal; varying vec2 v_width2; @@ -27,7 +28,6 @@ varying float v_gamma_scale; #pragma mapbox: define lowp vec4 color #pragma mapbox: define lowp float blur #pragma mapbox: define lowp float opacity -#pragma mapbox: define lowp float width #pragma mapbox: define mediump float gapwidth #pragma mapbox: define lowp float offset @@ -35,7 +35,6 @@ void main() { #pragma mapbox: initialize lowp vec4 color #pragma mapbox: initialize lowp float blur #pragma mapbox: initialize lowp float opacity - #pragma mapbox: initialize lowp float width #pragma mapbox: initialize mediump float gapwidth #pragma mapbox: initialize lowp float offset @@ -54,7 +53,7 @@ void main() { // these transformations used to be applied in the JS and native code bases. // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; - width = width / 2.0; + float width = u_width / 2.0; offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); diff --git a/src/line_pattern.vertex.glsl b/src/line_pattern.vertex.glsl index 86e19a43025..e0429ce83b3 100644 --- a/src/line_pattern.vertex.glsl +++ b/src/line_pattern.vertex.glsl @@ -19,6 +19,7 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; +uniform mediump float u_width; uniform mediump float u_extra; uniform mat2 u_antialiasingmatrix; @@ -29,14 +30,12 @@ varying float v_gamma_scale; #pragma mapbox: define lowp float blur #pragma mapbox: define lowp float opacity -#pragma mapbox: define lowp float width #pragma mapbox: define lowp float offset #pragma mapbox: define mediump float gapwidth void main() { #pragma mapbox: initialize lowp float blur #pragma mapbox: initialize lowp float opacity - #pragma mapbox: initialize lowp float width #pragma mapbox: initialize lowp float offset #pragma mapbox: initialize mediump float gapwidth @@ -55,7 +54,7 @@ void main() { // these transformations used to be applied in the JS and native code bases. // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; - width = width / 2.0; + float width = u_width / 2.0; offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); diff --git a/src/line_sdf.vertex.glsl b/src/line_sdf.vertex.glsl index 9c9b432088b..8f64174cc7f 100644 --- a/src/line_sdf.vertex.glsl +++ b/src/line_sdf.vertex.glsl @@ -25,6 +25,7 @@ uniform vec2 u_patternscale_b; uniform float u_tex_y_b; uniform float u_extra; uniform mat2 u_antialiasingmatrix; +uniform mediump float u_width; varying vec2 v_normal; varying vec2 v_width2; @@ -34,7 +35,6 @@ varying float v_gamma_scale; #pragma mapbox: define lowp vec4 color #pragma mapbox: define lowp float blur -#pragma mapbox: define lowp float width #pragma mapbox: define lowp float opacity #pragma mapbox: define mediump float gapwidth #pragma mapbox: define lowp float offset @@ -42,7 +42,6 @@ varying float v_gamma_scale; void main() { #pragma mapbox: initialize lowp vec4 color #pragma mapbox: initialize lowp float blur - #pragma mapbox: initialize lowp float width #pragma mapbox: initialize lowp float opacity #pragma mapbox: initialize mediump float gapwidth #pragma mapbox: initialize lowp float offset @@ -62,7 +61,7 @@ void main() { // these transformations used to be applied in the JS and native code bases. // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; - width = width / 2.0; + float width = u_width / 2.0; offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);