From 7bfcce02662a9c429c3ac715728de63e2850231e Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 14 Jun 2017 14:34:03 +0200 Subject: [PATCH 01/12] Cherry pick release (#9263) * [core] - bump earcut version dependency to handle unused lamba warning (#9242) * [android] - snapshot bitmap contains view based content (#9252) --- CMakeLists.txt | 2 +- .../mapbox/mapboxsdk/maps/NativeMapView.java | 16 ++++++--- .../mapbox/mapboxsdk/utils/BitmapUtils.java | 33 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c7a2ac572..8144d880ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ mason_use(boost VERSION 1.62.0 HEADER_ONLY) mason_use(geojsonvt VERSION 6.2.0 HEADER_ONLY) mason_use(supercluster VERSION 0.2.0-1 HEADER_ONLY) mason_use(kdbush VERSION 0.1.1-1 HEADER_ONLY) -mason_use(earcut VERSION 0.12.1 HEADER_ONLY) +mason_use(earcut VERSION 0.12.3 HEADER_ONLY) mason_use(protozero VERSION 1.4.2 HEADER_ONLY) mason_use(pixelmatch VERSION 0.10.0 HEADER_ONLY) mason_use(geojson VERSION 0.4.0 HEADER_ONLY) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index a31babc1c54..af3b57151d6 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -29,6 +29,7 @@ import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; import com.mapbox.mapboxsdk.style.sources.Source; +import com.mapbox.mapboxsdk.utils.BitmapUtils; import com.mapbox.services.commons.geojson.Feature; import java.nio.ByteBuffer; @@ -39,7 +40,6 @@ import timber.log.Timber; - // Class that wraps the native methods for convenience final class NativeMapView { @@ -920,12 +920,20 @@ protected void onMapChanged(int rawChange) { } protected void onFpsChanged(double fps) { + if (isDestroyedOn("OnFpsChanged")) { + return; + } mapView.onFpsChanged(fps); } - protected void onSnapshotReady(Bitmap bitmap) { - if (snapshotReadyCallback != null && bitmap != null) { - snapshotReadyCallback.onSnapshotReady(bitmap); + protected void onSnapshotReady(Bitmap mapContent) { + if (isDestroyedOn("OnSnapshotReady")) { + return; + } + + Bitmap viewContent = BitmapUtils.createBitmapFromView(mapView); + if (snapshotReadyCallback != null && mapContent != null && viewContent != null) { + snapshotReadyCallback.onSnapshotReady(BitmapUtils.mergeBitmap(mapContent, viewContent)); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java new file mode 100644 index 00000000000..e3fc7657342 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java @@ -0,0 +1,33 @@ +package com.mapbox.mapboxsdk.utils; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.support.annotation.NonNull; +import android.view.View; + +public class BitmapUtils { + + public static Bitmap createBitmapFromView(@NonNull View view) { + view.setDrawingCacheEnabled(true); + view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); + view.buildDrawingCache(); + + if (view.getDrawingCache() == null) { + return null; + } + + Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); + view.setDrawingCacheEnabled(false); + view.destroyDrawingCache(); + return snapshot; + } + + public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) { + Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig()); + Canvas canvas = new Canvas(result); + canvas.drawBitmap(background, 0f, 0f, null); + canvas.drawBitmap(foreground, 10, 10, null); + return result; + } + +} From 441b80d574783e959bf18c01bdb8cfee740424c5 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 12 Jun 2017 16:39:59 -0700 Subject: [PATCH 02/12] [core] Reduce number of varyings to 8 or less For #pragmas, don't generate varyings for attributes that aren't used by the fragment shader. Pack other varyings more tightly. --- scripts/generate-shaders.js | 65 +++++++++++++------------------ src/mbgl/shaders/circle.cpp | 24 ++++++------ src/mbgl/shaders/line.cpp | 6 +-- src/mbgl/shaders/line_pattern.cpp | 6 +-- src/mbgl/shaders/line_sdf.cpp | 6 +-- src/mbgl/shaders/symbol_sdf.cpp | 49 ++++++++++++----------- 6 files changed, 73 insertions(+), 83 deletions(-) diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js index 2f1f4c2f9c5..2813d273652 100755 --- a/scripts/generate-shaders.js +++ b/scripts/generate-shaders.js @@ -61,42 +61,31 @@ ${fragmentPrelude} 'symbol_icon', 'symbol_sdf' ].forEach(function (shaderName) { - function applyPragmas(source, pragmas) { - return source.replace(/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g, (match, operation, precision, type, name) => { - const a_type = type === "float" ? "vec2" : "vec4"; - return pragmas[operation] - .join("\n") - .replace(/\{type\}/g, type) - .replace(/\{a_type}/g, a_type) - .replace(/\{precision\}/g, precision) - .replace(/\{name\}/g, name); - }); - } - - function vertexSource() { - const source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8'); - return applyPragmas(source, { - define: [ - "uniform lowp float a_{name}_t;", - "attribute {precision} {a_type} a_{name};", - "varying {precision} {type} {name};" - ], - initialize: [ - "{name} = unpack_mix_{a_type}(a_{name}, a_{name}_t);" - ] - }); - } - - function fragmentSource() { - const source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8'); - return applyPragmas(source, { - define: [ - "varying {precision} {type} {name};" - ], - initialize: [ - ] - }); - } + const re = /#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g; + const fragmentPragmas = new Set(); + + let fragmentSource = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8'); + let vertexSource = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8'); + + fragmentSource = fragmentSource.replace(re, (match, operation, precision, type, name) => { + fragmentPragmas.add(name); + return operation === "define" ? + `varying ${precision} ${type} ${name};` : + ``; + }); + + vertexSource = vertexSource.replace(re, (match, operation, precision, type, name) => { + const a_type = type === "float" ? "vec2" : "vec4"; + if (fragmentPragmas.has(name)) { + return operation === "define" ? + `uniform lowp float a_${name}_t;\nattribute ${precision} ${a_type} a_${name};\nvarying ${precision} ${type} ${name};` : + `${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t);`; + } else { + return operation === "define" ? + `uniform lowp float a_${name}_t;\nattribute ${precision} ${a_type} a_${name};` : + `${precision} ${type} ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t);`; + } + }); writeIfModified(path.join(outputPath, `${shaderName}.hpp`), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. @@ -125,10 +114,10 @@ namespace shaders { const char* ${shaderName}::name = "${shaderName}"; const char* ${shaderName}::vertexSource = R"MBGL_SHADER( -${vertexSource()} +${vertexSource} )MBGL_SHADER"; const char* ${shaderName}::fragmentSource = R"MBGL_SHADER( -${fragmentSource()} +${fragmentSource} )MBGL_SHADER"; } // namespace shaders diff --git a/src/mbgl/shaders/circle.cpp b/src/mbgl/shaders/circle.cpp index 1c977d2bce0..2ecceeca708 100644 --- a/src/mbgl/shaders/circle.cpp +++ b/src/mbgl/shaders/circle.cpp @@ -35,8 +35,7 @@ uniform lowp float a_stroke_opacity_t; attribute lowp vec2 a_stroke_opacity; varying lowp float stroke_opacity; -varying vec2 v_extrude; -varying lowp float v_antialiasblur; +varying vec3 v_data; void main(void) { color = unpack_mix_vec4(a_color, a_color_t); @@ -48,23 +47,24 @@ void main(void) { stroke_opacity = unpack_mix_vec2(a_stroke_opacity, a_stroke_opacity_t); // 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 = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); - 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); if (u_scale_with_map) { - gl_Position.xy += extrude; + gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale; } else { - gl_Position.xy += extrude * gl_Position.w; + gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale * 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 // to keep the blur at roughly 1px, the two are inversely related. - v_antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / (radius + stroke_width); + lowp float antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / (radius + stroke_width); + + v_data = vec3(extrude.x, extrude.y, antialiasblur); } )MBGL_SHADER"; @@ -77,8 +77,7 @@ varying highp vec4 stroke_color; varying mediump float stroke_width; varying lowp float stroke_opacity; -varying vec2 v_extrude; -varying lowp float v_antialiasblur; +varying vec3 v_data; void main() { @@ -89,8 +88,11 @@ void main() { - float extrude_length = length(v_extrude); - float antialiased_blur = -max(blur, v_antialiasblur); + vec2 extrude = v_data.xy; + float extrude_length = length(extrude); + + lowp float antialiasblur = v_data.z; + float antialiased_blur = -max(blur, antialiasblur); float opacity_t = smoothstep(0.0, antialiased_blur, extrude_length - 1.0); diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index 4392bd051f8..e101cf6ee15 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -44,17 +44,15 @@ attribute lowp vec2 a_opacity; varying lowp float opacity; uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; -varying mediump float gapwidth; uniform lowp float a_offset_t; attribute lowp vec2 a_offset; -varying lowp float offset; void main() { color = unpack_mix_vec4(a_color, a_color_t); blur = unpack_mix_vec2(a_blur, a_blur_t); opacity = unpack_mix_vec2(a_opacity, a_opacity_t); - gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); - offset = unpack_mix_vec2(a_offset, a_offset_t); + mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); + lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index f52a8e2157f..79433b53a0a 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -44,16 +44,14 @@ attribute lowp vec2 a_opacity; varying lowp float opacity; uniform lowp float a_offset_t; attribute lowp vec2 a_offset; -varying lowp float offset; uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; -varying mediump float gapwidth; void main() { blur = unpack_mix_vec2(a_blur, a_blur_t); opacity = unpack_mix_vec2(a_opacity, a_opacity_t); - offset = unpack_mix_vec2(a_offset, a_offset_t); - gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); + lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); + mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index 17a6a197395..4f6cf814f9f 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -52,17 +52,15 @@ attribute lowp vec2 a_opacity; varying lowp float opacity; uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; -varying mediump float gapwidth; uniform lowp float a_offset_t; attribute lowp vec2 a_offset; -varying lowp float offset; void main() { color = unpack_mix_vec4(a_color, a_color_t); blur = unpack_mix_vec2(a_blur, a_blur_t); opacity = unpack_mix_vec2(a_opacity, a_opacity_t); - gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); - offset = unpack_mix_vec2(a_offset, a_offset_t); + mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); + lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; diff --git a/src/mbgl/shaders/symbol_sdf.cpp b/src/mbgl/shaders/symbol_sdf.cpp index 194e6240368..0c39c5f4acc 100644 --- a/src/mbgl/shaders/symbol_sdf.cpp +++ b/src/mbgl/shaders/symbol_sdf.cpp @@ -57,10 +57,8 @@ uniform vec2 u_extrude_scale; uniform vec2 u_texsize; -varying vec2 v_tex; -varying vec2 v_fade_tex; -varying float v_gamma_scale; -varying float v_size; +varying vec4 v_data0; +varying vec2 v_data1; void main() { fill_color = unpack_mix_vec4(a_fill_color, a_fill_color_t); @@ -81,6 +79,7 @@ void main() { mediump vec2 a_zoom = unpack_float(a_data[3]); mediump float a_minzoom = a_zoom[0]; mediump float a_maxzoom = a_zoom[1]; + float size; // In order to accommodate placing labels around corners in // symbol-placement: line, each glyph in a label could have multiple @@ -92,22 +91,22 @@ void main() { // based on the scale of rendered text size relative to layout text size. mediump float layoutSize; if (!u_is_size_zoom_constant && !u_is_size_feature_constant) { - v_size = mix(a_size[0], a_size[1], u_size_t) / 10.0; + size = mix(a_size[0], a_size[1], u_size_t) / 10.0; layoutSize = a_size[2] / 10.0; } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) { - v_size = a_size[0] / 10.0; - layoutSize = v_size; + size = a_size[0] / 10.0; + layoutSize = size; } else if (!u_is_size_zoom_constant && u_is_size_feature_constant) { - v_size = u_size; + size = u_size; layoutSize = u_layout_size; } else { - v_size = u_size; + size = u_size; layoutSize = u_size; } - float fontScale = u_is_text ? v_size / 24.0 : v_size; + float fontScale = u_is_text ? size / 24.0 : size; - mediump float zoomAdjust = log2(v_size / layoutSize); + mediump float zoomAdjust = log2(size / layoutSize); mediump float adjustedZoom = (u_zoom - zoomAdjust) * 10.0; // result: z = 0 if a_minzoom <= adjustedZoom < a_maxzoom, and 1 otherwise // Used below to move the vertex out of the clip space for when the current @@ -156,10 +155,13 @@ void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0); } - v_gamma_scale = gl_Position.w; + float gamma_scale = gl_Position.w; - v_tex = a_tex / u_texsize; - v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0); + vec2 tex = a_tex / u_texsize; + vec2 fade_tex = vec2(a_labelminzoom / 255.0, 0.0); + + v_data0 = vec4(tex.x, tex.y, fade_tex.x, fade_tex.y); + v_data1 = vec2(gamma_scale, size); } )MBGL_SHADER"; @@ -179,10 +181,8 @@ uniform sampler2D u_fadetexture; uniform highp float u_gamma_scale; uniform bool u_is_text; -varying vec2 v_tex; -varying vec2 v_fade_tex; -varying float v_gamma_scale; -varying float v_size; +varying vec4 v_data0; +varying vec2 v_data1; void main() { @@ -191,7 +191,12 @@ void main() { - float fontScale = u_is_text ? v_size / 24.0 : v_size; + vec2 tex = v_data0.xy; + vec2 fade_tex = v_data0.zw; + float gamma_scale = v_data1.x; + float size = v_data1.y; + + float fontScale = u_is_text ? size / 24.0 : size; lowp vec4 color = fill_color; highp float gamma = EDGE_GAMMA / (fontScale * u_gamma_scale); @@ -202,9 +207,9 @@ void main() { buff = (6.0 - halo_width / fontScale) / SDF_PX; } - lowp float dist = texture2D(u_texture, v_tex).a; - lowp float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a; - highp float gamma_scaled = gamma * v_gamma_scale; + lowp float dist = texture2D(u_texture, tex).a; + lowp float fade_alpha = texture2D(u_fadetexture, fade_tex).a; + highp float gamma_scaled = gamma * gamma_scale; highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist) * fade_alpha; gl_FragColor = color * (alpha * opacity); From 951f5997065d39597e2aad1e4586a11053d6fe1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Sun, 4 Jun 2017 02:47:20 +0200 Subject: [PATCH 03/12] [core] store vertex attribute binding to prevent duplicate binds We have an "oldBinding" value that we use for checking whether the vertex attribute was already bound to the current VAO, but we never set the state. Additionally, we're also checking whether the previous state was already any binding (optional is set), and don't re-enable the vertex attribute array. Additionally, we now only disable the vertex attribute array when the previous state was in fact an array attribute. We still don't deduplicate constant glVertexAttrib* calls, but that's a little trickier. --- src/mbgl/gl/attribute.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index eacaa37457b..8c52121f6ec 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -29,6 +29,7 @@ void VariableAttributeBinding::bind(Context& context, } context.vertexBuffer = vertexBuffer; MBGL_CHECK_ERROR(glEnableVertexAttribArray(location)); + oldBinding = *this; MBGL_CHECK_ERROR(glVertexAttribPointer( location, static_cast(attributeSize), From eaa8f236729814b5edd47a03d5b7e4a25092f044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Sun, 4 Jun 2017 15:45:03 +0200 Subject: [PATCH 04/12] [core] only bind uniforms that exist in the program --- src/mbgl/gl/uniform.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp index 34a32aeee91..bb3453b2d83 100644 --- a/src/mbgl/gl/uniform.hpp +++ b/src/mbgl/gl/uniform.hpp @@ -30,7 +30,7 @@ class Uniform { class State { public: void operator=(const Value& value) { - if (!current || *current != value.t) { + if (location >= 0 && (!current || *current != value.t)) { current = value.t; bindUniform(location, value.t); } From b141707b8d17fb72276010075fdc75297de8675e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Sun, 4 Jun 2017 15:43:27 +0200 Subject: [PATCH 05/12] [core] add shader defines for enabling/disabling attributes/uniforms for DDS --- scripts/generate-shaders.js | 49 +++++-- src/mbgl/shaders/circle.cpp | 140 +++++++++++++++++++- src/mbgl/shaders/fill.cpp | 40 +++++- src/mbgl/shaders/fill_extrusion.cpp | 60 ++++++++- src/mbgl/shaders/fill_extrusion_pattern.cpp | 40 +++++- src/mbgl/shaders/fill_outline.cpp | 40 +++++- src/mbgl/shaders/fill_outline_pattern.cpp | 20 ++- src/mbgl/shaders/fill_pattern.cpp | 20 ++- src/mbgl/shaders/line.cpp | 80 ++++++++++- src/mbgl/shaders/line_pattern.cpp | 60 ++++++++- src/mbgl/shaders/line_sdf.cpp | 80 ++++++++++- src/mbgl/shaders/symbol_icon.cpp | 20 ++- src/mbgl/shaders/symbol_sdf.cpp | 100 +++++++++++++- 13 files changed, 708 insertions(+), 41 deletions(-) diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js index 2813d273652..159817f62f8 100755 --- a/scripts/generate-shaders.js +++ b/scripts/generate-shaders.js @@ -69,21 +69,52 @@ ${fragmentPrelude} fragmentSource = fragmentSource.replace(re, (match, operation, precision, type, name) => { fragmentPragmas.add(name); - return operation === "define" ? - `varying ${precision} ${type} ${name};` : - ``; + return operation === "define" ? ` +#ifndef HAS_UNIFORM_u_${name} +varying ${precision} ${type} ${name}; +#else +uniform ${precision} ${type} u_${name}; +#endif +` : ` +#ifdef HAS_UNIFORM_u_${name} + ${precision} ${type} ${name} = u_${name}; +#endif +`; }); vertexSource = vertexSource.replace(re, (match, operation, precision, type, name) => { const a_type = type === "float" ? "vec2" : "vec4"; if (fragmentPragmas.has(name)) { - return operation === "define" ? - `uniform lowp float a_${name}_t;\nattribute ${precision} ${a_type} a_${name};\nvarying ${precision} ${type} ${name};` : - `${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t);`; + return operation === "define" ? ` +#ifdef HAS_UNIFORM_u_${name} +uniform lowp float a_${name}_t; +attribute ${precision} ${a_type} a_${name}; +varying ${precision} ${type} ${name}; +#else +uniform ${precision} ${type} u_${name}; +#endif +` : ` +#ifndef HAS_UNIFORM_u_${name} + ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t); +#else + ${precision} ${type} ${name} = u_${name}; +#endif +`; } else { - return operation === "define" ? - `uniform lowp float a_${name}_t;\nattribute ${precision} ${a_type} a_${name};` : - `${precision} ${type} ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t);`; + return operation === "define" ? ` +#ifdef HAS_UNIFORM_u_${name} +uniform lowp float a_${name}_t; +attribute ${precision} ${a_type} a_${name}; +#else +uniform ${precision} ${type} u_${name}; +#endif +` : ` +#ifndef HAS_UNIFORM_u_${name} + ${precision} ${type} ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t); +#else + ${precision} ${type} ${name} = u_${name}; +#endif +`; } }); diff --git a/src/mbgl/shaders/circle.cpp b/src/mbgl/shaders/circle.cpp index 2ecceeca708..2e0c76122ce 100644 --- a/src/mbgl/shaders/circle.cpp +++ b/src/mbgl/shaders/circle.cpp @@ -13,38 +13,108 @@ uniform vec2 u_extrude_scale; attribute vec2 a_pos; + +#ifndef HAS_UNIFORM_u_color uniform lowp float a_color_t; attribute highp vec4 a_color; varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_radius uniform lowp float a_radius_t; attribute mediump vec2 a_radius; varying mediump float radius; +#else +uniform mediump float u_radius; +#endif + +#ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_stroke_color uniform lowp float a_stroke_color_t; attribute highp vec4 a_stroke_color; varying highp vec4 stroke_color; +#else +uniform highp vec4 u_stroke_color; +#endif + +#ifndef HAS_UNIFORM_u_stroke_width uniform lowp float a_stroke_width_t; attribute mediump vec2 a_stroke_width; varying mediump float stroke_width; +#else +uniform mediump float u_stroke_width; +#endif + +#ifndef HAS_UNIFORM_u_stroke_opacity uniform lowp float a_stroke_opacity_t; attribute lowp vec2 a_stroke_opacity; varying lowp float stroke_opacity; +#else +uniform lowp float u_stroke_opacity; +#endif varying vec3 v_data; void main(void) { + +#ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); +#else + highp vec4 color = u_color; +#endif + +#ifndef HAS_UNIFORM_u_radius radius = unpack_mix_vec2(a_radius, a_radius_t); +#else + mediump float radius = u_radius; +#endif + +#ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); +#else + lowp float blur = u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_stroke_color stroke_color = unpack_mix_vec4(a_stroke_color, a_stroke_color_t); +#else + highp vec4 stroke_color = u_stroke_color; +#endif + +#ifndef HAS_UNIFORM_u_stroke_width stroke_width = unpack_mix_vec2(a_stroke_width, a_stroke_width_t); +#else + mediump float stroke_width = u_stroke_width; +#endif + +#ifndef HAS_UNIFORM_u_stroke_opacity stroke_opacity = unpack_mix_vec2(a_stroke_opacity, a_stroke_opacity_t); +#else + lowp float stroke_opacity = u_stroke_opacity; +#endif // unencode the extrusion vector that we snuck into the a_pos vector vec2 extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); @@ -69,24 +139,80 @@ void main(void) { )MBGL_SHADER"; const char* circle::fragmentSource = R"MBGL_SHADER( + +#ifndef HAS_UNIFORM_u_color varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_radius varying mediump float radius; +#else +uniform mediump float u_radius; +#endif + +#ifndef HAS_UNIFORM_u_blur varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_stroke_color varying highp vec4 stroke_color; +#else +uniform highp vec4 u_stroke_color; +#endif + +#ifndef HAS_UNIFORM_u_stroke_width varying mediump float stroke_width; +#else +uniform mediump float u_stroke_width; +#endif + +#ifndef HAS_UNIFORM_u_stroke_opacity varying lowp float stroke_opacity; +#else +uniform lowp float u_stroke_opacity; +#endif varying vec3 v_data; void main() { - - - - - - - + +#ifdef HAS_UNIFORM_u_color + highp vec4 color = u_color; +#endif + +#ifdef HAS_UNIFORM_u_radius + mediump float radius = u_radius; +#endif + +#ifdef HAS_UNIFORM_u_blur + lowp float blur = u_blur; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif + +#ifdef HAS_UNIFORM_u_stroke_color + highp vec4 stroke_color = u_stroke_color; +#endif + +#ifdef HAS_UNIFORM_u_stroke_width + mediump float stroke_width = u_stroke_width; +#endif + +#ifdef HAS_UNIFORM_u_stroke_opacity + lowp float stroke_opacity = u_stroke_opacity; +#endif vec2 extrude = v_data.xy; float extrude_length = length(extrude); diff --git a/src/mbgl/shaders/fill.cpp b/src/mbgl/shaders/fill.cpp index 0b775273d23..8f5f3040142 100644 --- a/src/mbgl/shaders/fill.cpp +++ b/src/mbgl/shaders/fill.cpp @@ -11,28 +11,64 @@ attribute vec2 a_pos; uniform mat4 u_matrix; + +#ifndef HAS_UNIFORM_u_color uniform lowp float a_color_t; attribute highp vec4 a_color; varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { + +#ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); +#else + highp vec4 color = u_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif gl_Position = u_matrix * vec4(a_pos, 0, 1); } )MBGL_SHADER"; const char* fill::fragmentSource = R"MBGL_SHADER( + +#ifndef HAS_UNIFORM_u_color varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { - - + +#ifdef HAS_UNIFORM_u_color + highp vec4 color = u_color; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif gl_FragColor = color * opacity; diff --git a/src/mbgl/shaders/fill_extrusion.cpp b/src/mbgl/shaders/fill_extrusion.cpp index ea1c80545ef..ad14e4f32eb 100644 --- a/src/mbgl/shaders/fill_extrusion.cpp +++ b/src/mbgl/shaders/fill_extrusion.cpp @@ -18,21 +18,51 @@ attribute float a_edgedistance; varying vec4 v_color; + +#ifndef HAS_UNIFORM_u_base uniform lowp float a_base_t; attribute lowp vec2 a_base; varying lowp float base; +#else +uniform lowp float u_base; +#endif + +#ifndef HAS_UNIFORM_u_height uniform lowp float a_height_t; attribute lowp vec2 a_height; varying lowp float height; +#else +uniform lowp float u_height; +#endif + +#ifndef HAS_UNIFORM_u_color uniform lowp float a_color_t; attribute highp vec4 a_color; varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif void main() { + +#ifndef HAS_UNIFORM_u_base base = unpack_mix_vec2(a_base, a_base_t); +#else + lowp float base = u_base; +#endif + +#ifndef HAS_UNIFORM_u_height height = unpack_mix_vec2(a_height, a_height_t); +#else + lowp float height = u_height; +#endif + +#ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); +#else + highp vec4 color = u_color; +#endif base = max(0.0, base); height = max(0.0, height); @@ -76,14 +106,38 @@ void main() { )MBGL_SHADER"; const char* fill_extrusion::fragmentSource = R"MBGL_SHADER( varying vec4 v_color; + +#ifndef HAS_UNIFORM_u_base varying lowp float base; +#else +uniform lowp float u_base; +#endif + +#ifndef HAS_UNIFORM_u_height varying lowp float height; +#else +uniform lowp float u_height; +#endif + +#ifndef HAS_UNIFORM_u_color varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif void main() { - - - + +#ifdef HAS_UNIFORM_u_base + lowp float base = u_base; +#endif + +#ifdef HAS_UNIFORM_u_height + lowp float height = u_height; +#endif + +#ifdef HAS_UNIFORM_u_color + highp vec4 color = u_color; +#endif gl_FragColor = v_color; diff --git a/src/mbgl/shaders/fill_extrusion_pattern.cpp b/src/mbgl/shaders/fill_extrusion_pattern.cpp index e2de5c20b26..66c24b1bb0e 100644 --- a/src/mbgl/shaders/fill_extrusion_pattern.cpp +++ b/src/mbgl/shaders/fill_extrusion_pattern.cpp @@ -30,16 +30,36 @@ varying vec2 v_pos_b; varying vec4 v_lighting; varying float v_directional; + +#ifndef HAS_UNIFORM_u_base uniform lowp float a_base_t; attribute lowp vec2 a_base; varying lowp float base; +#else +uniform lowp float u_base; +#endif + +#ifndef HAS_UNIFORM_u_height uniform lowp float a_height_t; attribute lowp vec2 a_height; varying lowp float height; +#else +uniform lowp float u_height; +#endif void main() { + +#ifndef HAS_UNIFORM_u_base base = unpack_mix_vec2(a_base, a_base_t); +#else + lowp float base = u_base; +#endif + +#ifndef HAS_UNIFORM_u_height height = unpack_mix_vec2(a_height, a_height_t); +#else + lowp float height = u_height; +#endif base = max(0.0, base); height = max(0.0, height); @@ -81,12 +101,28 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec4 v_lighting; + +#ifndef HAS_UNIFORM_u_base varying lowp float base; +#else +uniform lowp float u_base; +#endif + +#ifndef HAS_UNIFORM_u_height varying lowp float height; +#else +uniform lowp float u_height; +#endif void main() { - - + +#ifdef HAS_UNIFORM_u_base + lowp float base = u_base; +#endif + +#ifdef HAS_UNIFORM_u_height + lowp float height = u_height; +#endif vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); diff --git a/src/mbgl/shaders/fill_outline.cpp b/src/mbgl/shaders/fill_outline.cpp index 3e160ac6c27..45bc716be37 100644 --- a/src/mbgl/shaders/fill_outline.cpp +++ b/src/mbgl/shaders/fill_outline.cpp @@ -14,16 +14,36 @@ uniform vec2 u_world; varying vec2 v_pos; + +#ifndef HAS_UNIFORM_u_outline_color uniform lowp float a_outline_color_t; attribute highp vec4 a_outline_color; varying highp vec4 outline_color; +#else +uniform highp vec4 u_outline_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { + +#ifndef HAS_UNIFORM_u_outline_color outline_color = unpack_mix_vec4(a_outline_color, a_outline_color_t); +#else + highp vec4 outline_color = u_outline_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif gl_Position = u_matrix * vec4(a_pos, 0, 1); v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; @@ -31,14 +51,30 @@ void main() { )MBGL_SHADER"; const char* fill_outline::fragmentSource = R"MBGL_SHADER( + +#ifndef HAS_UNIFORM_u_outline_color varying highp vec4 outline_color; +#else +uniform highp vec4 u_outline_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif varying vec2 v_pos; void main() { - - + +#ifdef HAS_UNIFORM_u_outline_color + highp vec4 outline_color = u_outline_color; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif float dist = length(v_pos - gl_FragCoord.xy); float alpha = smoothstep(1.0, 0.0, dist); diff --git a/src/mbgl/shaders/fill_outline_pattern.cpp b/src/mbgl/shaders/fill_outline_pattern.cpp index 5e380233827..5315709e3a2 100644 --- a/src/mbgl/shaders/fill_outline_pattern.cpp +++ b/src/mbgl/shaders/fill_outline_pattern.cpp @@ -23,12 +23,22 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec2 v_pos; + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif gl_Position = u_matrix * vec4(a_pos, 0, 1); @@ -52,10 +62,18 @@ varying vec2 v_pos_a; varying vec2 v_pos_b; varying vec2 v_pos; + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { - + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); diff --git a/src/mbgl/shaders/fill_pattern.cpp b/src/mbgl/shaders/fill_pattern.cpp index 0357fed40ec..dd99e4efff2 100644 --- a/src/mbgl/shaders/fill_pattern.cpp +++ b/src/mbgl/shaders/fill_pattern.cpp @@ -21,12 +21,22 @@ attribute vec2 a_pos; varying vec2 v_pos_a; varying vec2 v_pos_b; + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif gl_Position = u_matrix * vec4(a_pos, 0, 1); @@ -47,10 +57,18 @@ uniform sampler2D u_image; varying vec2 v_pos_a; varying vec2 v_pos_b; + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { - + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif vec2 imagecoord = mod(v_pos_a, 1.0); vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index e101cf6ee15..dce6046257f 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -33,26 +33,76 @@ varying vec2 v_normal; varying vec2 v_width2; varying float v_gamma_scale; + +#ifndef HAS_UNIFORM_u_color uniform lowp float a_color_t; attribute highp vec4 a_color; varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_gapwidth uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; +#else +uniform mediump float u_gapwidth; +#endif + +#ifndef HAS_UNIFORM_u_offset uniform lowp float a_offset_t; attribute lowp vec2 a_offset; +#else +uniform lowp float u_offset; +#endif void main() { + +#ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); +#else + highp vec4 color = u_color; +#endif + +#ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); +#else + lowp float blur = u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_gapwidth mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); +#else + mediump float gapwidth = u_gapwidth; +#endif + +#ifndef HAS_UNIFORM_u_offset lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); +#else + lowp float offset = u_offset; +#endif vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -103,18 +153,42 @@ void main() { )MBGL_SHADER"; const char* line::fragmentSource = R"MBGL_SHADER( + +#ifndef HAS_UNIFORM_u_color varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_blur varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif varying vec2 v_width2; varying vec2 v_normal; varying float v_gamma_scale; void main() { - - - + +#ifdef HAS_UNIFORM_u_color + highp vec4 color = u_color; +#endif + +#ifdef HAS_UNIFORM_u_blur + lowp float blur = u_blur; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index 79433b53a0a..1c07b4f5153 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -36,22 +36,62 @@ varying vec2 v_width2; varying float v_linesofar; varying float v_gamma_scale; + +#ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_offset uniform lowp float a_offset_t; attribute lowp vec2 a_offset; +#else +uniform lowp float u_offset; +#endif + +#ifndef HAS_UNIFORM_u_gapwidth uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; +#else +uniform mediump float u_gapwidth; +#endif void main() { + +#ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); +#else + lowp float blur = u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_offset lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); +#else + lowp float offset = u_offset; +#endif + +#ifndef HAS_UNIFORM_u_gapwidth mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); +#else + mediump float gapwidth = u_gapwidth; +#endif vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -118,12 +158,28 @@ varying vec2 v_width2; varying float v_linesofar; varying float v_gamma_scale; + +#ifndef HAS_UNIFORM_u_blur varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { - - + +#ifdef HAS_UNIFORM_u_blur + lowp float blur = u_blur; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index 4f6cf814f9f..b37bf688d45 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -41,26 +41,76 @@ varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; + +#ifndef HAS_UNIFORM_u_color uniform lowp float a_color_t; attribute highp vec4 a_color; varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_blur uniform lowp float a_blur_t; attribute lowp vec2 a_blur; varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_gapwidth uniform lowp float a_gapwidth_t; attribute mediump vec2 a_gapwidth; +#else +uniform mediump float u_gapwidth; +#endif + +#ifndef HAS_UNIFORM_u_offset uniform lowp float a_offset_t; attribute lowp vec2 a_offset; +#else +uniform lowp float u_offset; +#endif void main() { + +#ifndef HAS_UNIFORM_u_color color = unpack_mix_vec4(a_color, a_color_t); +#else + highp vec4 color = u_color; +#endif + +#ifndef HAS_UNIFORM_u_blur blur = unpack_mix_vec2(a_blur, a_blur_t); +#else + lowp float blur = u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_gapwidth mediump float gapwidth = unpack_mix_vec2(a_gapwidth, a_gapwidth_t); +#else + mediump float gapwidth = u_gapwidth; +#endif + +#ifndef HAS_UNIFORM_u_offset lowp float offset = unpack_mix_vec2(a_offset, a_offset_t); +#else + lowp float offset = u_offset; +#endif vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -125,14 +175,38 @@ varying vec2 v_tex_a; varying vec2 v_tex_b; varying float v_gamma_scale; + +#ifndef HAS_UNIFORM_u_color varying highp vec4 color; +#else +uniform highp vec4 u_color; +#endif + +#ifndef HAS_UNIFORM_u_blur varying lowp float blur; +#else +uniform lowp float u_blur; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif void main() { - - - + +#ifdef HAS_UNIFORM_u_color + highp vec4 color = u_color; +#endif + +#ifdef HAS_UNIFORM_u_blur + lowp float blur = u_blur; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; diff --git a/src/mbgl/shaders/symbol_icon.cpp b/src/mbgl/shaders/symbol_icon.cpp index b6fbed428e8..bc570cf361c 100644 --- a/src/mbgl/shaders/symbol_icon.cpp +++ b/src/mbgl/shaders/symbol_icon.cpp @@ -19,9 +19,14 @@ uniform mediump float u_size_t; // used to interpolate between zoom stops when s uniform mediump float u_size; // used when size is both zoom and feature constant uniform mediump float u_layout_size; // used when size is feature constant + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif // matrix is for the vertex position. uniform mat4 u_matrix; @@ -37,7 +42,12 @@ varying vec2 v_tex; varying vec2 v_fade_tex; void main() { + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif vec2 a_pos = a_pos_offset.xy; vec2 a_offset = a_pos_offset.zw; @@ -97,13 +107,21 @@ const char* symbol_icon::fragmentSource = R"MBGL_SHADER( uniform sampler2D u_texture; uniform sampler2D u_fadetexture; + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif varying vec2 v_tex; varying vec2 v_fade_tex; void main() { - + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif lowp float alpha = texture2D(u_fadetexture, v_fade_tex).a * opacity; gl_FragColor = texture2D(u_texture, v_tex) * alpha; diff --git a/src/mbgl/shaders/symbol_sdf.cpp b/src/mbgl/shaders/symbol_sdf.cpp index 0c39c5f4acc..cce6b769a67 100644 --- a/src/mbgl/shaders/symbol_sdf.cpp +++ b/src/mbgl/shaders/symbol_sdf.cpp @@ -27,21 +27,46 @@ uniform mediump float u_size_t; // used to interpolate between zoom stops when s uniform mediump float u_size; // used when size is both zoom and feature constant uniform mediump float u_layout_size; // used when size is feature constant + +#ifndef HAS_UNIFORM_u_fill_color uniform lowp float a_fill_color_t; attribute highp vec4 a_fill_color; varying highp vec4 fill_color; +#else +uniform highp vec4 u_fill_color; +#endif + +#ifndef HAS_UNIFORM_u_halo_color uniform lowp float a_halo_color_t; attribute highp vec4 a_halo_color; varying highp vec4 halo_color; +#else +uniform highp vec4 u_halo_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity uniform lowp float a_opacity_t; attribute lowp vec2 a_opacity; varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_halo_width uniform lowp float a_halo_width_t; attribute lowp vec2 a_halo_width; varying lowp float halo_width; +#else +uniform lowp float u_halo_width; +#endif + +#ifndef HAS_UNIFORM_u_halo_blur uniform lowp float a_halo_blur_t; attribute lowp vec2 a_halo_blur; varying lowp float halo_blur; +#else +uniform lowp float u_halo_blur; +#endif // matrix is for the vertex position. uniform mat4 u_matrix; @@ -61,11 +86,36 @@ varying vec4 v_data0; varying vec2 v_data1; void main() { + +#ifndef HAS_UNIFORM_u_fill_color fill_color = unpack_mix_vec4(a_fill_color, a_fill_color_t); +#else + highp vec4 fill_color = u_fill_color; +#endif + +#ifndef HAS_UNIFORM_u_halo_color halo_color = unpack_mix_vec4(a_halo_color, a_halo_color_t); +#else + highp vec4 halo_color = u_halo_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, a_opacity_t); +#else + lowp float opacity = u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_halo_width halo_width = unpack_mix_vec2(a_halo_width, a_halo_width_t); +#else + lowp float halo_width = u_halo_width; +#endif + +#ifndef HAS_UNIFORM_u_halo_blur halo_blur = unpack_mix_vec2(a_halo_blur, a_halo_blur_t); +#else + lowp float halo_blur = u_halo_blur; +#endif vec2 a_pos = a_pos_offset.xy; vec2 a_offset = a_pos_offset.zw; @@ -170,11 +220,36 @@ const char* symbol_sdf::fragmentSource = R"MBGL_SHADER( #define EDGE_GAMMA 0.105/DEVICE_PIXEL_RATIO uniform bool u_is_halo; + +#ifndef HAS_UNIFORM_u_fill_color varying highp vec4 fill_color; +#else +uniform highp vec4 u_fill_color; +#endif + +#ifndef HAS_UNIFORM_u_halo_color varying highp vec4 halo_color; +#else +uniform highp vec4 u_halo_color; +#endif + +#ifndef HAS_UNIFORM_u_opacity varying lowp float opacity; +#else +uniform lowp float u_opacity; +#endif + +#ifndef HAS_UNIFORM_u_halo_width varying lowp float halo_width; +#else +uniform lowp float u_halo_width; +#endif + +#ifndef HAS_UNIFORM_u_halo_blur varying lowp float halo_blur; +#else +uniform lowp float u_halo_blur; +#endif uniform sampler2D u_texture; uniform sampler2D u_fadetexture; @@ -185,11 +260,26 @@ varying vec4 v_data0; varying vec2 v_data1; void main() { - - - - - + +#ifdef HAS_UNIFORM_u_fill_color + highp vec4 fill_color = u_fill_color; +#endif + +#ifdef HAS_UNIFORM_u_halo_color + highp vec4 halo_color = u_halo_color; +#endif + +#ifdef HAS_UNIFORM_u_opacity + lowp float opacity = u_opacity; +#endif + +#ifdef HAS_UNIFORM_u_halo_width + lowp float halo_width = u_halo_width; +#endif + +#ifdef HAS_UNIFORM_u_halo_blur + lowp float halo_blur = u_halo_blur; +#endif vec2 tex = v_data0.xy; vec2 fade_tex = v_data0.zw; From cf85873f365e5baee73de0fb33113cd7bb134a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Sun, 4 Jun 2017 23:17:59 +0200 Subject: [PATCH 06/12] [core] add uniforms to DataDrivenPaintPropertys --- src/mbgl/programs/uniforms.hpp | 14 ++++++++++++- .../style/layers/circle_layer_properties.hpp | 15 ++++++------- .../fill_extrusion_layer_properties.hpp | 7 ++++--- .../style/layers/fill_layer_properties.hpp | 7 ++++--- .../style/layers/line_layer_properties.hpp | 11 +++++----- .../style/layers/symbol_layer_properties.hpp | 21 ++++++++++--------- src/mbgl/style/paint_property.hpp | 3 ++- 7 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/mbgl/programs/uniforms.hpp b/src/mbgl/programs/uniforms.hpp index 972405d5a9b..60a50a7cb23 100644 --- a/src/mbgl/programs/uniforms.hpp +++ b/src/mbgl/programs/uniforms.hpp @@ -16,7 +16,19 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_blur); MBGL_DEFINE_UNIFORM_SCALAR(float, u_zoom); MBGL_DEFINE_UNIFORM_SCALAR(float, u_pitch); MBGL_DEFINE_UNIFORM_SCALAR(float, u_bearing); - +MBGL_DEFINE_UNIFORM_SCALAR(float, u_radius); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_stroke_width); +MBGL_DEFINE_UNIFORM_SCALAR(Color, u_stroke_color); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_stroke_opacity); +MBGL_DEFINE_UNIFORM_SCALAR(Color, u_fill_color); +MBGL_DEFINE_UNIFORM_SCALAR(Color, u_halo_color); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_halo_width); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_halo_blur); +MBGL_DEFINE_UNIFORM_SCALAR(Color, u_outline_color); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_height); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_base); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_gap_width); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_offset); MBGL_DEFINE_UNIFORM_SCALAR(Size, u_world); MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_extrude_scale); diff --git a/src/mbgl/style/layers/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp index 1cb4f5a635a..58206c61dac 100644 --- a/src/mbgl/style/layers/circle_layer_properties.hpp +++ b/src/mbgl/style/layers/circle_layer_properties.hpp @@ -6,23 +6,24 @@ #include #include #include +#include namespace mbgl { namespace style { -struct CircleRadius : DataDrivenPaintProperty { +struct CircleRadius : DataDrivenPaintProperty { static float defaultValue() { return 5; } }; -struct CircleColor : DataDrivenPaintProperty { +struct CircleColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; -struct CircleBlur : DataDrivenPaintProperty { +struct CircleBlur : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -struct CircleOpacity : DataDrivenPaintProperty { +struct CircleOpacity : DataDrivenPaintProperty { static float defaultValue() { return 1; } }; @@ -38,15 +39,15 @@ struct CirclePitchScale : PaintProperty { static CirclePitchScaleType defaultValue() { return CirclePitchScaleType::Map; } }; -struct CircleStrokeWidth : DataDrivenPaintProperty { +struct CircleStrokeWidth : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -struct CircleStrokeColor : DataDrivenPaintProperty { +struct CircleStrokeColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; -struct CircleStrokeOpacity : DataDrivenPaintProperty { +struct CircleStrokeOpacity : DataDrivenPaintProperty { static float defaultValue() { return 1; } }; diff --git a/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp b/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp index c1dd3b079de..f41ce68b94a 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -14,7 +15,7 @@ struct FillExtrusionOpacity : PaintProperty { static float defaultValue() { return 1; } }; -struct FillExtrusionColor : DataDrivenPaintProperty { +struct FillExtrusionColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; @@ -30,11 +31,11 @@ struct FillExtrusionPattern : CrossFadedPaintProperty { static std::string defaultValue() { return ""; } }; -struct FillExtrusionHeight : DataDrivenPaintProperty { +struct FillExtrusionHeight : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -struct FillExtrusionBase : DataDrivenPaintProperty { +struct FillExtrusionBase : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp index f44a18d0e03..ee1e5158cec 100644 --- a/src/mbgl/style/layers/fill_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_layer_properties.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -14,15 +15,15 @@ struct FillAntialias : PaintProperty { static bool defaultValue() { return true; } }; -struct FillOpacity : DataDrivenPaintProperty { +struct FillOpacity : DataDrivenPaintProperty { static float defaultValue() { return 1; } }; -struct FillColor : DataDrivenPaintProperty { +struct FillColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; -struct FillOutlineColor : DataDrivenPaintProperty { +struct FillOutlineColor : DataDrivenPaintProperty { static Color defaultValue() { return {}; } }; diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index 724026e3a64..0b234921ad3 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -30,11 +31,11 @@ struct LineRoundLimit : LayoutProperty { static float defaultValue() { return 1; } }; -struct LineOpacity : DataDrivenPaintProperty { +struct LineOpacity : DataDrivenPaintProperty { static float defaultValue() { return 1; } }; -struct LineColor : DataDrivenPaintProperty { +struct LineColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; @@ -50,15 +51,15 @@ struct LineWidth : PaintProperty { static float defaultValue() { return 1; } }; -struct LineGapWidth : DataDrivenPaintProperty { +struct LineGapWidth : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -struct LineOffset : DataDrivenPaintProperty> { +struct LineOffset : DataDrivenPaintProperty, uniforms::u_offset> { static float defaultValue() { return 0; } }; -struct LineBlur : DataDrivenPaintProperty { +struct LineBlur : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 42f593890b9..5b571757853 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -180,23 +181,23 @@ struct TextOptional : LayoutProperty { static bool defaultValue() { return false; } }; -struct IconOpacity : DataDrivenPaintProperty { +struct IconOpacity : DataDrivenPaintProperty { static float defaultValue() { return 1; } }; -struct IconColor : DataDrivenPaintProperty { +struct IconColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; -struct IconHaloColor : DataDrivenPaintProperty { +struct IconHaloColor : DataDrivenPaintProperty { static Color defaultValue() { return {}; } }; -struct IconHaloWidth : DataDrivenPaintProperty { +struct IconHaloWidth : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -struct IconHaloBlur : DataDrivenPaintProperty { +struct IconHaloBlur : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; @@ -208,23 +209,23 @@ struct IconTranslateAnchor : PaintProperty { static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } }; -struct TextOpacity : DataDrivenPaintProperty { +struct TextOpacity : DataDrivenPaintProperty { static float defaultValue() { return 1; } }; -struct TextColor : DataDrivenPaintProperty { +struct TextColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; -struct TextHaloColor : DataDrivenPaintProperty { +struct TextHaloColor : DataDrivenPaintProperty { static Color defaultValue() { return {}; } }; -struct TextHaloWidth : DataDrivenPaintProperty { +struct TextHaloWidth : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -struct TextHaloBlur : DataDrivenPaintProperty { +struct TextHaloBlur : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index f1752e69d9e..c203083c498 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -92,7 +92,7 @@ class PaintProperty { static constexpr bool IsDataDriven = false; }; -template +template class DataDrivenPaintProperty { public: using ValueType = DataDrivenPropertyValue; @@ -104,6 +104,7 @@ class DataDrivenPaintProperty { using Type = T; using Attribute = A; + using Uniform = U; }; template From a64828218a3934c036f7fb256b6799723c30830a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Sun, 4 Jun 2017 23:58:02 +0200 Subject: [PATCH 07/12] [core] add constant DDS values as uniforms --- src/mbgl/programs/program.hpp | 2 +- src/mbgl/programs/symbol_program.hpp | 2 +- src/mbgl/renderer/paint_property_binder.hpp | 23 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 7eec15e7552..420d2e1397a 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -62,7 +62,7 @@ class Program { std::move(stencilMode), std::move(colorMode), uniformValues - .concat(paintPropertyBinders.uniformValues(currentZoom)), + .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), LayoutAttributes::allVariableBindings(layoutVertexBuffer) .concat(paintPropertyBinders.attributeBindings(currentProperties)), indexBuffer, diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 46f532e5c4b..1b7232c9e44 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -377,7 +377,7 @@ class SymbolProgram { std::move(colorMode), uniformValues .concat(symbolSizeBinder.uniformValues(currentZoom)) - .concat(paintPropertyBinders.uniformValues(currentZoom)), + .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), LayoutAttributes::allVariableBindings(layoutVertexBuffer) .concat(symbolSizeBinder.attributeBindings(currentSizeValue)) .concat(paintPropertyBinders.attributeBindings(currentProperties)), diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 3e53bcc8846..a4bea24bbf1 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -88,6 +88,7 @@ class PaintPropertyBinder { virtual void upload(gl::Context& context) = 0; virtual AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; virtual float interpolationFactor(float currentZoom) const = 0; + virtual T uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; static std::unique_ptr create(const PossiblyEvaluatedPropertyValue& value, float zoom, T defaultValue); @@ -118,6 +119,10 @@ class ConstantPaintPropertyBinder : public PaintPropertyBinder { return 0.0f; } + T uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const override { + return currentValue.constantOr(constant); + } + private: T constant; }; @@ -165,6 +170,11 @@ class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder { return 0.0f; } + T uniformValue(const PossiblyEvaluatedPropertyValue&) const override { + // Uniform values for vertex attribute arrays are unused. + return {}; + } + private: style::SourceFunction function; T defaultValue; @@ -220,6 +230,11 @@ class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder { return util::interpolationFactor(1.0f, std::get<0>(coveringRanges), currentZoom); } + T uniformValue(const PossiblyEvaluatedPropertyValue&) const override { + // Uniform values for vertex attribute arrays are unused. + return {}; + } + private: using InnerStops = typename style::CompositeFunction::InnerStops; style::CompositeFunction function; @@ -306,14 +321,18 @@ class PaintPropertyBinders> { }; } - using Uniforms = gl::Uniforms...>; + using Uniforms = gl::Uniforms..., typename Ps::Uniform...>; using UniformValues = typename Uniforms::Values; - UniformValues uniformValues(float currentZoom) const { + template + UniformValues uniformValues(float currentZoom, const EvaluatedProperties& currentProperties) const { (void)currentZoom; // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 return UniformValues { typename InterpolationUniform::Value { binders.template get()->interpolationFactor(currentZoom) + }..., + typename Ps::Uniform::Value { + binders.template get()->uniformValue(currentProperties.template get()) }... }; } From 212ae5273dc3930a035b51c603c540b4f02fa777 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 13 Jun 2017 11:47:39 -0700 Subject: [PATCH 08/12] [core] cleanup ProgramParameters --- cmake/core-files.cmake | 1 + src/mbgl/gl/program.hpp | 4 +-- src/mbgl/programs/program_parameters.cpp | 32 ++++++++++++++++++++++++ src/mbgl/programs/program_parameters.hpp | 15 ++++++----- src/mbgl/programs/programs.hpp | 4 +-- src/mbgl/shaders/shaders.cpp | 22 ++-------------- src/mbgl/shaders/shaders.hpp | 1 - 7 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 src/mbgl/programs/program_parameters.cpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 4779abba865..069b6cb4c9a 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -150,6 +150,7 @@ set(MBGL_CORE_FILES src/mbgl/programs/line_program.cpp src/mbgl/programs/line_program.hpp src/mbgl/programs/program.hpp + src/mbgl/programs/program_parameters.cpp src/mbgl/programs/program_parameters.hpp src/mbgl/programs/programs.hpp src/mbgl/programs/raster_program.cpp diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 1b23abe2b10..c36543839cf 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -55,11 +55,11 @@ class Program { shaders::vertexSource(programParameters, vertexSource_); const std::string fragmentSource = shaders::fragmentSource(programParameters, fragmentSource_); - const std::string cachePath = - shaders::programCachePath(programParameters, name); const std::string identifier = shaders::programIdentifier(vertexSource, fragmentSource_); + const std::string cachePath = programParameters.cachePath(name); + try { if (auto cachedBinaryProgram = util::readFile(cachePath)) { const BinaryProgram binaryProgram(std::move(*cachedBinaryProgram)); diff --git a/src/mbgl/programs/program_parameters.cpp b/src/mbgl/programs/program_parameters.cpp new file mode 100644 index 00000000000..f9f680ac1ea --- /dev/null +++ b/src/mbgl/programs/program_parameters.cpp @@ -0,0 +1,32 @@ +#include + +#include +#include + +namespace mbgl { + +ProgramParameters::ProgramParameters(const float pixelRatio, + const bool overdraw, + std::string cacheDir_) + : defines([&] { + std::ostringstream ss; + ss.imbue(std::locale("C")); + ss.setf(std::ios_base::showpoint); + ss << "#define DEVICE_PIXEL_RATIO " << pixelRatio << std::endl; + if (overdraw) { + ss << "#define OVERDRAW_INSPECTOR" << std::endl; + } + return ss.str(); + }()), + hash(std::hash()(defines)), + cacheDir(std::move(cacheDir_)) { +} + +std::string ProgramParameters::cachePath(const char* name) const { + std::ostringstream ss; + ss << cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0') + << std::setw(sizeof(size_t) * 2) << std::hex << hash << ".pbf"; + return ss.str(); +} + +} // namespace mbgl diff --git a/src/mbgl/programs/program_parameters.hpp b/src/mbgl/programs/program_parameters.hpp index b91b41f3589..420658d089e 100644 --- a/src/mbgl/programs/program_parameters.hpp +++ b/src/mbgl/programs/program_parameters.hpp @@ -6,16 +6,15 @@ namespace mbgl { class ProgramParameters { public: - ProgramParameters(float pixelRatio_ = 1.0, - bool overdraw_ = false, - const std::string& cacheDir_ = "") - : pixelRatio(pixelRatio_), overdraw(overdraw_), cacheDir(cacheDir_) { - } + ProgramParameters(float pixelRatio, bool overdraw, std::string cacheDir); - const float pixelRatio; - const bool overdraw; + const std::string defines; + + std::string cachePath(const char* name) const; + +private: + const std::size_t hash; const std::string cacheDir; }; } // namespace mbgl - diff --git a/src/mbgl/programs/programs.hpp b/src/mbgl/programs/programs.hpp index ff6b1cd505d..b58d2e3beee 100644 --- a/src/mbgl/programs/programs.hpp +++ b/src/mbgl/programs/programs.hpp @@ -31,8 +31,8 @@ class Programs { symbolIcon(context, programParameters), symbolIconSDF(context, programParameters), symbolGlyph(context, programParameters), - debug(context, ProgramParameters(programParameters.pixelRatio, false, programParameters.cacheDir)), - collisionBox(context, ProgramParameters(programParameters.pixelRatio, false, programParameters.cacheDir)) { + debug(context, programParameters), + collisionBox(context, programParameters) { } CircleProgram circle; diff --git a/src/mbgl/shaders/shaders.cpp b/src/mbgl/shaders/shaders.cpp index 03d796edbae..93e273f9852 100644 --- a/src/mbgl/shaders/shaders.cpp +++ b/src/mbgl/shaders/shaders.cpp @@ -9,30 +9,12 @@ namespace mbgl { namespace shaders { -static std::string pixelRatioDefine(const ProgramParameters& parameters) { - std::ostringstream pixelRatioSS; - pixelRatioSS.imbue(std::locale("C")); - pixelRatioSS.setf(std::ios_base::showpoint); - pixelRatioSS << parameters.pixelRatio; - return std::string("#define DEVICE_PIXEL_RATIO ") + pixelRatioSS.str() + "\n"; -} - std::string fragmentSource(const ProgramParameters& parameters, const char* fragmentSource) { - std::string source = pixelRatioDefine(parameters) + fragmentPrelude + fragmentSource; - if (parameters.overdraw) { - assert(source.find("#ifdef OVERDRAW_INSPECTOR") != std::string::npos); - source.replace(source.find_first_of('\n'), 1, "\n#define OVERDRAW_INSPECTOR\n"); - } - return source; + return parameters.defines + fragmentPrelude + fragmentSource; } std::string vertexSource(const ProgramParameters& parameters, const char* vertexSource) { - return pixelRatioDefine(parameters) + vertexPrelude + vertexSource; -} - -std::string programCachePath(const ProgramParameters& parameters, const char* name) { - return parameters.cacheDir + "/com.mapbox.gl.shader." + name + - (parameters.overdraw ? ".overdraw.pbf" : ".pbf"); + return parameters.defines + vertexPrelude + vertexSource; } std::string programIdentifier(const std::string& vertexSource, const std::string& fragmentSource) { diff --git a/src/mbgl/shaders/shaders.hpp b/src/mbgl/shaders/shaders.hpp index 126c64bb9e6..513d37fa6f1 100644 --- a/src/mbgl/shaders/shaders.hpp +++ b/src/mbgl/shaders/shaders.hpp @@ -10,7 +10,6 @@ namespace shaders { std::string fragmentSource(const ProgramParameters&, const char* fragmentSource); std::string vertexSource(const ProgramParameters&, const char* vertexSource); -std::string programCachePath(const ProgramParameters&, const char* name); std::string programIdentifier(const std::string& vertexSource, const std::string& fragmentSource); } // namespace shaders From d618d4a274023257988a91e96ecf794338189bf8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 5 Jun 2017 12:15:27 -0700 Subject: [PATCH 09/12] [core] Dynamic program compilation for data-driven properties --- include/mbgl/map/map.hpp | 2 +- src/mbgl/gl/program.hpp | 11 ++-- src/mbgl/map/map.cpp | 8 +-- src/mbgl/programs/program.hpp | 35 +++++++++++- src/mbgl/programs/program_parameters.cpp | 30 +++++++--- src/mbgl/programs/program_parameters.hpp | 14 +++-- src/mbgl/programs/programs.hpp | 26 ++++----- src/mbgl/programs/symbol_program.hpp | 3 +- src/mbgl/renderer/paint_property_binder.hpp | 60 ++++++++++++++------ src/mbgl/renderer/painter.cpp | 2 +- src/mbgl/renderer/painter.hpp | 2 +- src/mbgl/renderer/painter_background.cpp | 4 +- src/mbgl/renderer/painter_circle.cpp | 2 +- src/mbgl/renderer/painter_clipping.cpp | 2 +- src/mbgl/renderer/painter_fill.cpp | 4 +- src/mbgl/renderer/painter_fill_extrusion.cpp | 4 +- src/mbgl/renderer/painter_line.cpp | 2 +- src/mbgl/renderer/painter_symbol.cpp | 2 +- src/mbgl/shaders/shaders.cpp | 4 +- 19 files changed, 148 insertions(+), 69 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 8072eda7ddd..bbeeeac6cc2 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -44,7 +44,7 @@ class Map : private util::noncopyable { GLContextMode contextMode = GLContextMode::Unique, ConstrainMode constrainMode = ConstrainMode::HeightOnly, ViewportMode viewportMode = ViewportMode::Default, - const std::string& programCacheDir = ""); + const optional& programCacheDir = {}); ~Map(); // Register a callback that will get called (on the render thread) when all resources have diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index c36543839cf..47ad39de7ca 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -50,7 +50,8 @@ class Program { const char* vertexSource_, const char* fragmentSource_) { #if MBGL_HAS_BINARY_PROGRAMS - if (!programParameters.cacheDir.empty() && context.supportsProgramBinaries()) { + optional cachePath = programParameters.cachePath(name); + if (cachePath && context.supportsProgramBinaries()) { const std::string vertexSource = shaders::vertexSource(programParameters, vertexSource_); const std::string fragmentSource = @@ -58,10 +59,8 @@ class Program { const std::string identifier = shaders::programIdentifier(vertexSource, fragmentSource_); - const std::string cachePath = programParameters.cachePath(name); - try { - if (auto cachedBinaryProgram = util::readFile(cachePath)) { + if (auto cachedBinaryProgram = util::readFile(*cachePath)) { const BinaryProgram binaryProgram(std::move(*cachedBinaryProgram)); if (binaryProgram.identifier() == identifier) { return Program { context, binaryProgram }; @@ -82,8 +81,8 @@ class Program { try { if (const auto binaryProgram = result.template get(context, identifier)) { - util::write_file(cachePath, binaryProgram->serialize()); - Log::Warning(Event::OpenGL, "Caching program in: %s", cachePath.c_str()); + util::write_file(*cachePath, binaryProgram->serialize()); + Log::Warning(Event::OpenGL, "Caching program in: %s", (*cachePath).c_str()); } } catch (std::runtime_error& error) { Log::Warning(Event::OpenGL, "Failed to cache program: %s", error.what()); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 181370dc142..35457f3a5b8 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -58,7 +58,7 @@ class Map::Impl : public style::Observer { GLContextMode, ConstrainMode, ViewportMode, - const std::string& programCacheDir); + optional programCacheDir); void onSourceChanged(style::Source&) override; void onUpdate(Update) override; @@ -83,7 +83,7 @@ class Map::Impl : public style::Observer { const MapMode mode; const GLContextMode contextMode; const float pixelRatio; - const std::string programCacheDir; + const optional programCacheDir; MapDebugOptions debugOptions { MapDebugOptions::NoDebug }; @@ -116,7 +116,7 @@ Map::Map(Backend& backend, GLContextMode contextMode, ConstrainMode constrainMode, ViewportMode viewportMode, - const std::string& programCacheDir) + const optional& programCacheDir) : impl(std::make_unique(*this, backend, pixelRatio, @@ -139,7 +139,7 @@ Map::Impl::Impl(Map& map_, GLContextMode contextMode_, ConstrainMode constrainMode_, ViewportMode viewportMode_, - const std::string& programCacheDir_) + optional programCacheDir_) : map(map_), observer(backend_), backend(backend_), diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 420d2e1397a..bbe4885745a 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -9,18 +9,21 @@ #include #include +#include + namespace mbgl { template + class PaintProps> class Program { public: using LayoutAttributes = LayoutAttrs; using LayoutVertex = typename LayoutAttributes::Vertex; + using PaintProperties = PaintProps; using PaintPropertyBinders = typename PaintProperties::Binders; using PaintAttributes = typename PaintPropertyBinders::Attributes; using Attributes = gl::ConcatenateAttributes; @@ -71,4 +74,34 @@ class Program { } }; +template +class ProgramMap { +public: + using PaintProperties = typename Program::PaintProperties; + using PaintPropertyBinders = typename Program::PaintPropertyBinders; + using Bitset = typename PaintPropertyBinders::Bitset; + + ProgramMap(gl::Context& context_, ProgramParameters parameters_) + : context(context_), + parameters(std::move(parameters_)) { + } + + Program& get(const typename PaintProperties::Evaluated& currentProperties) { + Bitset bits = PaintPropertyBinders::constants(currentProperties); + auto it = programs.find(bits); + if (it != programs.end()) { + return it->second; + } + return programs.emplace(std::piecewise_construct, + std::forward_as_tuple(bits), + std::forward_as_tuple(context, + parameters.withAdditionalDefines(PaintPropertyBinders::defines(currentProperties)))).first->second; + } + +private: + gl::Context& context; + ProgramParameters parameters; + std::unordered_map programs; +}; + } // namespace mbgl diff --git a/src/mbgl/programs/program_parameters.cpp b/src/mbgl/programs/program_parameters.cpp index f9f680ac1ea..e76ec4be713 100644 --- a/src/mbgl/programs/program_parameters.cpp +++ b/src/mbgl/programs/program_parameters.cpp @@ -7,7 +7,7 @@ namespace mbgl { ProgramParameters::ProgramParameters(const float pixelRatio, const bool overdraw, - std::string cacheDir_) + optional cacheDir_) : defines([&] { std::ostringstream ss; ss.imbue(std::locale("C")); @@ -18,15 +18,31 @@ ProgramParameters::ProgramParameters(const float pixelRatio, } return ss.str(); }()), - hash(std::hash()(defines)), cacheDir(std::move(cacheDir_)) { } -std::string ProgramParameters::cachePath(const char* name) const { - std::ostringstream ss; - ss << cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0') - << std::setw(sizeof(size_t) * 2) << std::hex << hash << ".pbf"; - return ss.str(); +const std::string& ProgramParameters::getDefines() const { + return defines; +} + +optional ProgramParameters::cachePath(const char* name) const { + if (!cacheDir) { + return {}; + } else { + std::ostringstream ss; + ss << *cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0') + << std::setw(sizeof(size_t) * 2) << std::hex << std::hash()(defines) << ".pbf"; + return ss.str(); + } +} + +ProgramParameters ProgramParameters::withAdditionalDefines(const std::vector& additionalDefines) const { + ProgramParameters result(*this); + for (const auto& define : additionalDefines) { + result.defines += define; + result.defines += "\n"; + } + return result; } } // namespace mbgl diff --git a/src/mbgl/programs/program_parameters.hpp b/src/mbgl/programs/program_parameters.hpp index 420658d089e..e94e61c217a 100644 --- a/src/mbgl/programs/program_parameters.hpp +++ b/src/mbgl/programs/program_parameters.hpp @@ -1,20 +1,24 @@ #pragma once +#include + #include +#include namespace mbgl { class ProgramParameters { public: - ProgramParameters(float pixelRatio, bool overdraw, std::string cacheDir); + ProgramParameters(float pixelRatio, bool overdraw, optional cacheDir); - const std::string defines; + const std::string& getDefines() const; + optional cachePath(const char* name) const; - std::string cachePath(const char* name) const; + ProgramParameters withAdditionalDefines(const std::vector& defines) const; private: - const std::size_t hash; - const std::string cacheDir; + std::string defines; + optional cacheDir; }; } // namespace mbgl diff --git a/src/mbgl/programs/programs.hpp b/src/mbgl/programs/programs.hpp index b58d2e3beee..37ced32745a 100644 --- a/src/mbgl/programs/programs.hpp +++ b/src/mbgl/programs/programs.hpp @@ -35,21 +35,21 @@ class Programs { collisionBox(context, programParameters) { } - CircleProgram circle; + ProgramMap circle; ExtrusionTextureProgram extrusionTexture; - FillProgram fill; - FillExtrusionProgram fillExtrusion; - FillExtrusionPatternProgram fillExtrusionPattern; - FillPatternProgram fillPattern; - FillOutlineProgram fillOutline; - FillOutlinePatternProgram fillOutlinePattern; - LineProgram line; - LineSDFProgram lineSDF; - LinePatternProgram linePattern; + ProgramMap fill; + ProgramMap fillExtrusion; + ProgramMap fillExtrusionPattern; + ProgramMap fillPattern; + ProgramMap fillOutline; + ProgramMap fillOutlinePattern; + ProgramMap line; + ProgramMap lineSDF; + ProgramMap linePattern; RasterProgram raster; - SymbolIconProgram symbolIcon; - SymbolSDFIconProgram symbolIconSDF; - SymbolSDFTextProgram symbolGlyph; + ProgramMap symbolIcon; + ProgramMap symbolIconSDF; + ProgramMap symbolGlyph; DebugProgram debug; CollisionBoxProgram collisionBox; diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 1b7232c9e44..01e95f456d0 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -324,7 +324,7 @@ template + class PaintProps> class SymbolProgram { public: using LayoutAttributes = LayoutAttrs; @@ -332,6 +332,7 @@ class SymbolProgram { using LayoutAndSizeAttributes = gl::ConcatenateAttributes; + using PaintProperties = PaintProps; using PaintPropertyBinders = typename PaintProperties::Binders; using PaintAttributes = typename PaintPropertyBinders::Attributes; using Attributes = gl::ConcatenateAttributes; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index a4bea24bbf1..062b77888e1 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -6,6 +6,8 @@ #include #include +#include + namespace mbgl { /* @@ -54,8 +56,7 @@ std::array zoomInterpolatedAttributeValue(const std::array * For _constant_ properties -- those whose value is a constant, or the constant result of evaluating a camera function at a particular camera position -- we - don't need a vertex buffer, and can instead use a constant attribute binding - via the `glVertexAttrib*` family of functions. + don't need a vertex buffer, and instead use a uniform. * For source functions, we use a vertex buffer with a single attribute value, the evaluated result of the source function for the given feature. * For composite functions, we use a vertex buffer with two attributes: min and @@ -66,15 +67,8 @@ std::array zoomInterpolatedAttributeValue(const std::array between the min and max value at the final displayed zoom level. The use of a uniform allows us to cheaply update the value on every frame. - Note that the shader source is the same regardless of the strategy used to bind - the attribute -- in all cases the attribute is declared as a vec2, in order to - support composite min and max values (color attributes use a vec4 with special - packing). When the constant or source function strategies are used, the - interpolation uniform value is set to zero, and the second attribute element is - unused. This differs from the GL JS implementation, which dynamically generates - shader source based on the strategy used. We found that in WebGL, using - `glVertexAttrib*` was unnacceptably slow. Additionally, in GL Native we have - implemented binary shader caching, which works better if the shaders are constant. + Note that the shader source varies depending on whether we're using a uniform or + attribute. Like GL JS, we dynamically compile shaders at runtime to accomodate this. */ template class PaintPropertyBinder { @@ -170,9 +164,13 @@ class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder { return 0.0f; } - T uniformValue(const PossiblyEvaluatedPropertyValue&) const override { - // Uniform values for vertex attribute arrays are unused. - return {}; + T uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const override { + if (currentValue.isConstant()) { + return *currentValue.constant(); + } else { + // Uniform values for vertex attribute arrays are unused. + return {}; + } } private: @@ -230,9 +228,13 @@ class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder { return util::interpolationFactor(1.0f, std::get<0>(coveringRanges), currentZoom); } - T uniformValue(const PossiblyEvaluatedPropertyValue&) const override { - // Uniform values for vertex attribute arrays are unused. - return {}; + T uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const override { + if (currentValue.isConstant()) { + return *currentValue.constant(); + } else { + // Uniform values for vertex attribute arrays are unused. + return {}; + } } private: @@ -342,6 +344,30 @@ class PaintPropertyBinders> { return binders.template get

()->statistics; } + + using Bitset = std::bitset; + + template + static Bitset constants(const EvaluatedProperties& currentProperties) { + Bitset result; + util::ignore({ + result.set(TypeIndex::value, + currentProperties.template get().isConstant())... + }); + return result; + } + + template + static std::vector defines(const EvaluatedProperties& currentProperties) { + std::vector result; + util::ignore({ + (result.push_back(currentProperties.template get().isConstant() + ? std::string("#define HAS_UNIFORM_") + Ps::Uniform::name() + : std::string()), 0)... + }); + return result; + } + private: Binders binders; }; diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index eed3bfcd8b1..da4903864b4 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -93,7 +93,7 @@ static gl::VertexVector extrusionTextureVertices() Painter::Painter(gl::Context& context_, const TransformState& state_, float pixelRatio, - const std::string& programCacheDir) + const optional& programCacheDir) : context(context_), state(state_), tileVertexBuffer(context.createVertexBuffer(tileVertices())), diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 47b469d9713..4658f0c206c 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -74,7 +74,7 @@ struct FrameData { class Painter : private util::noncopyable { public: - Painter(gl::Context&, const TransformState&, float pixelRatio, const std::string& programCacheDir); + Painter(gl::Context&, const TransformState&, float pixelRatio, const optional& programCacheDir); ~Painter(); void render(const style::Style&, diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index 7cd9cbac5f1..d01696ee3e7 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -33,7 +33,7 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou spriteAtlas->bind(true, context, 0); for (const auto& tileID : util::tileCover(state, state.getIntegerZoom())) { - parameters.programs.fillPattern.draw( + parameters.programs.fillPattern.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), @@ -58,7 +58,7 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou } } else { for (const auto& tileID : util::tileCover(state, state.getIntegerZoom())) { - parameters.programs.fill.draw( + parameters.programs.fill.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 7c9194f6dd1..13acb5f7fe5 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -23,7 +23,7 @@ void Painter::renderCircle(PaintParameters& parameters, const CirclePaintProperties::Evaluated& properties = layer.evaluated; const bool scaleWithMap = properties.get() == CirclePitchScaleType::Map; - parameters.programs.circle.draw( + parameters.programs.circle.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp index 0d3b5f1504b..b3a2d77b1a2 100644 --- a/src/mbgl/renderer/painter_clipping.cpp +++ b/src/mbgl/renderer/painter_clipping.cpp @@ -8,7 +8,7 @@ namespace mbgl { void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& clip) { static const style::FillPaintProperties::Evaluated properties {}; static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); - programs->fill.draw( + programs->fill.get(properties).draw( context, gl::Triangles(), gl::DepthMode::disabled(), diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 622f6386ef3..e1b59d88392 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -38,7 +38,7 @@ void Painter::renderFill(PaintParameters& parameters, const auto& drawMode, const auto& indexBuffer, const auto& segments) { - program.draw( + program.get(properties).draw( context, drawMode, depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), @@ -85,7 +85,7 @@ void Painter::renderFill(PaintParameters& parameters, const auto& drawMode, const auto& indexBuffer, const auto& segments) { - program.draw( + program.get(properties).draw( context, drawMode, depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), diff --git a/src/mbgl/renderer/painter_fill_extrusion.cpp b/src/mbgl/renderer/painter_fill_extrusion.cpp index af98cae5691..95617525c73 100644 --- a/src/mbgl/renderer/painter_fill_extrusion.cpp +++ b/src/mbgl/renderer/painter_fill_extrusion.cpp @@ -36,7 +36,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, spriteAtlas->bind(true, context, 0); - parameters.programs.fillExtrusionPattern.draw( + parameters.programs.fillExtrusionPattern.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadWrite), @@ -62,7 +62,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, state.getZoom()); } else { - parameters.programs.fillExtrusion.draw( + parameters.programs.fillExtrusion.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadWrite), diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 4d7a27d0f66..9152ac8512c 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -24,7 +24,7 @@ void Painter::renderLine(PaintParameters& parameters, const LinePaintProperties::Evaluated& properties = layer.evaluated; auto draw = [&] (auto& program, auto&& uniformValues) { - program.draw( + program.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 5a66d1e62f4..86b2146b9f5 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -41,7 +41,7 @@ void Painter::renderSymbol(PaintParameters& parameters, // We clip symbols to their tile extent in still mode. const bool needsClipping = frame.mapMode == MapMode::Still; - program.draw( + program.get(paintProperties).draw( context, gl::Triangles(), values_.pitchAlignment == AlignmentType::Map diff --git a/src/mbgl/shaders/shaders.cpp b/src/mbgl/shaders/shaders.cpp index 93e273f9852..31ff405f021 100644 --- a/src/mbgl/shaders/shaders.cpp +++ b/src/mbgl/shaders/shaders.cpp @@ -10,11 +10,11 @@ namespace mbgl { namespace shaders { std::string fragmentSource(const ProgramParameters& parameters, const char* fragmentSource) { - return parameters.defines + fragmentPrelude + fragmentSource; + return parameters.getDefines() + fragmentPrelude + fragmentSource; } std::string vertexSource(const ProgramParameters& parameters, const char* vertexSource) { - return parameters.defines + vertexPrelude + vertexSource; + return parameters.getDefines() + vertexPrelude + vertexSource; } std::string programIdentifier(const std::string& vertexSource, const std::string& fragmentSource) { From d27740650bb71469ab5a2ce5528d71d59f23ad8a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 13 Jun 2017 11:28:41 -0700 Subject: [PATCH 10/12] [core] Don't upload the FrameHistory texture in frames where it's not changing --- src/mbgl/renderer/frame_history.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mbgl/renderer/frame_history.cpp b/src/mbgl/renderer/frame_history.cpp index a933a9004aa..35e246f4886 100644 --- a/src/mbgl/renderer/frame_history.cpp +++ b/src/mbgl/renderer/frame_history.cpp @@ -39,15 +39,15 @@ void FrameHistory::record(const TimePoint& now, float zoom, const Duration& dura for (int16_t z = 0; z <= 255; z++) { std::chrono::duration timeDiff = now - changeTimes[z]; int32_t opacityChange = (duration == Milliseconds(0) ? 1 : (timeDiff / duration)) * 255; - if (z <= zoomIndex) { - opacities.data[z] = util::min(255, changeOpacities[z] + opacityChange); - } else { - opacities.data[z] = util::max(0, changeOpacities[z] - opacityChange); + uint8_t opacity = z <= zoomIndex + ? util::min(255, changeOpacities[z] + opacityChange) + : util::max(0, changeOpacities[z] - opacityChange); + if (opacities.data[z] != opacity) { + opacities.data[z] = opacity; + dirty = true; } } - dirty = true; - if (zoomIndex != previousZoomIndex) { previousZoomIndex = zoomIndex; previousTime = now; From df3af9738962d377b0b269347a9d91f2173da7e5 Mon Sep 17 00:00:00 2001 From: Jordan Kiley Date: Wed, 14 Jun 2017 11:26:34 -0700 Subject: [PATCH 11/12] [ios, macos] Revised descriptions for abstract classes (#9095) Addresses https://github.com/mapbox/mapbox-gl-native/issues/8635 --- platform/darwin/src/MGLForegroundStyleLayer.h | 7 ++++--- platform/darwin/src/MGLMultiPoint.h | 5 +++-- platform/darwin/src/MGLShape.h | 10 +++++----- platform/darwin/src/MGLSource.h | 7 ++++--- platform/darwin/src/MGLStyleLayer.h | 8 ++++---- platform/darwin/src/MGLStyleValue.h | 9 ++++----- platform/darwin/src/MGLTileSource.h | 6 +++--- platform/darwin/src/MGLVectorStyleLayer.h | 8 ++++---- platform/ios/src/MGLUserLocation.h | 2 +- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/platform/darwin/src/MGLForegroundStyleLayer.h b/platform/darwin/src/MGLForegroundStyleLayer.h index 16a973630e8..bcd323fb99f 100644 --- a/platform/darwin/src/MGLForegroundStyleLayer.h +++ b/platform/darwin/src/MGLForegroundStyleLayer.h @@ -11,9 +11,10 @@ NS_ASSUME_NONNULL_BEGIN `MGLForegroundStyleLayer` is an abstract superclass for style layers whose content is defined by an `MGLSource` object. - Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, create instances of `MGLRasterStyleLayer` - and the concrete subclasses of `MGLVectorStyleLayer`. + Create instances of `MGLRasterStyleLayer` and the concrete subclasses of + `MGLVectorStyleLayer` in order to use `MGLForegroundStyleLayer`'s methods. + Do not create instances of `MGLForegroundStyleLayer` directly, and do not + create your own subclasses of this class. */ MGL_EXPORT @interface MGLForegroundStyleLayer : MGLStyleLayer diff --git a/platform/darwin/src/MGLMultiPoint.h b/platform/darwin/src/MGLMultiPoint.h index 429bbdb22d7..ee9eb530a47 100644 --- a/platform/darwin/src/MGLMultiPoint.h +++ b/platform/darwin/src/MGLMultiPoint.h @@ -10,8 +10,9 @@ NS_ASSUME_NONNULL_BEGIN The `MGLMultiPoint` class is an abstract superclass used to define shapes composed of multiple vertices. - You do not create instances of this class directly. Instead, you create - instances of the `MGLPolyline` or `MGLPolygon` classes. However, you can use + Create instances of `MGLPolyline` or `MGLPolygon` in order to use + properties of `MGLMultiPoint`. Do not create instances of `MGLMultiPoint` + directly and do not create your own subclasses of this class. You can use the method and properties of this class to access information about the vertices of the line or polygon. diff --git a/platform/darwin/src/MGLShape.h b/platform/darwin/src/MGLShape.h index bd8b6152d2d..e9657105521 100644 --- a/platform/darwin/src/MGLShape.h +++ b/platform/darwin/src/MGLShape.h @@ -10,11 +10,11 @@ NS_ASSUME_NONNULL_BEGIN constitute the content of a map – not only the overlays atop the map, but also the content that forms the base map. - You do not create instances of this class directly or create subclasses of this - class. Instead, you create instances of `MGLPointAnnotation`, - `MGLPointCollection`, `MGLPolyline`, `MGLMultiPolyline`, `MGLPolygon`, - `MGLMultiPolygon`, or `MGLShapeCollection`. The shape classes correspond to the - Geometry object + Create instances of `MGLPointAnnotation`, `MGLPointCollection`, `MGLPolyline`, + `MGLMultiPolyline`, `MGLPolygon`, `MGLMultiPolygon`, or `MGLShapeCollection` in + order to use `MGLShape`'s methods. Do not create instances of `MGLShape` directly, + and do not create your own subclasses of this class. The shape classes correspond + to the Geometry object types in the GeoJSON standard, but some have nonstandard names for backwards compatibility. diff --git a/platform/darwin/src/MGLSource.h b/platform/darwin/src/MGLSource.h index 8bf48907cc0..151363104ec 100644 --- a/platform/darwin/src/MGLSource.h +++ b/platform/darwin/src/MGLSource.h @@ -16,9 +16,10 @@ NS_ASSUME_NONNULL_BEGIN add and remove sources dynamically using methods such as `-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`. - Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, create instances of `MGLShapeSource` and the - concrete subclasses of `MGLTileSource`, `MGLVectorSource` and `MGLRasterSource`. + Create instances of `MGLShapeSource` and the concrete subclasses of + `MGLTileSource`, `MGLVectorSource` and `MGLRasterSource` in order to use + `MGLMultiPoint`'s properties and methods. Do not create instances of `MGLSource` + directly, and do not create your own subclasses of this class. */ MGL_EXPORT @interface MGLSource : NSObject diff --git a/platform/darwin/src/MGLStyleLayer.h b/platform/darwin/src/MGLStyleLayer.h index 7d181667d60..b610a276076 100644 --- a/platform/darwin/src/MGLStyleLayer.h +++ b/platform/darwin/src/MGLStyleLayer.h @@ -14,10 +14,10 @@ NS_ASSUME_NONNULL_BEGIN `MGLStyleLayer` object, which you can use to refine the map’s appearance. You can also add and remove style layers dynamically. - Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, create instances of - `MGLBackgroundStyleLayer` and the concrete subclasses of - `MGLForegroundStyleLayer`. + Create instances of `MGLBackgroundStyleLayer` and the concrete subclasses of + `MGLForegroundStyleLayer` in order to use `MGLStyleLayer`'s properties and methods. + You do not create instances of `MGLStyleLayer` directly, and do not + create your own subclasses of this class. Do not add `MGLStyleLayer` objects to the `style` property of a `MGLMapView` before `-mapView:didFinishLoadingStyle:` is called. diff --git a/platform/darwin/src/MGLStyleValue.h b/platform/darwin/src/MGLStyleValue.h index 2bb3aca4f4a..9c9b1dc4d10 100644 --- a/platform/darwin/src/MGLStyleValue.h +++ b/platform/darwin/src/MGLStyleValue.h @@ -239,11 +239,10 @@ MGL_EXPORT defined by an `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, or `MGLCompositeStyleFunction` object. - Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, use one of the class factory methods in - `MGLStyleValue` to create instances of the following concrete subclasses: - `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, and - `MGLCompositeStyleFunction`. + Create instances of `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, and + `MGLCompositeStyleFunction` in order to use `MGLStyleFunction`'s methods. Do + not create instances of `MGLStyleFunction` directly, and do not create your + own subclasses of this class. The `MGLStyleFunction` class takes a generic parameter `T` that indicates the Foundation class being wrapped by this class. diff --git a/platform/darwin/src/MGLTileSource.h b/platform/darwin/src/MGLTileSource.h index 538b94037ee..caeafcd2f6c 100644 --- a/platform/darwin/src/MGLTileSource.h +++ b/platform/darwin/src/MGLTileSource.h @@ -140,9 +140,9 @@ typedef NS_ENUM(NSUInteger, MGLTileCoordinateSystem) { Mapbox-hosted tile set, view it in Mapbox Studio’s Tilesets editor. - Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, create instances of `MGLRasterSource` and - `MGLVectorSource`. + Create instances of `MGLRasterSource` and `MGLVectorSource` in order to use + `MGLTileSource`'s properties and methods. Do not create instances of `MGLTileSource` + directly, and do not create your own subclasses of this class. */ MGL_EXPORT @interface MGLTileSource : MGLSource diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h index c6193e60463..e54a580aede 100644 --- a/platform/darwin/src/MGLVectorStyleLayer.h +++ b/platform/darwin/src/MGLVectorStyleLayer.h @@ -9,10 +9,10 @@ NS_ASSUME_NONNULL_BEGIN `MGLVectorStyleLayer` is an abstract superclass for style layers whose content is defined by an `MGLShapeSource` or `MGLVectorSource` object. - Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, create instances of the following concrete - subclasses: `MGLCircleStyleLayer`, `MGLFillStyleLayer`, `MGLLineStyleLayer`, - and `MGLSymbolStyleLayer`. + Create instances of `MGLCircleStyleLayer`, `MGLFillStyleLayer`, `MGLLineStyleLayer`, + and `MGLSymbolStyleLayer` in order to use `MGLVectorStyleLayer`'s properties and + methods. Do not create instances of `MGLVectorStyleLayer` directly, and do not + create your own subclasses of this class. */ MGL_EXPORT @interface MGLVectorStyleLayer : MGLForegroundStyleLayer diff --git a/platform/ios/src/MGLUserLocation.h b/platform/ios/src/MGLUserLocation.h index c41c3ee7fd5..30bfc592cab 100644 --- a/platform/ios/src/MGLUserLocation.h +++ b/platform/ios/src/MGLUserLocation.h @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN /** The MGLUserLocation class defines a specific type of annotation that identifies the user’s current location. You do not create instances of this class - directly. Instead, you retrieve an existing MGLUserLocation object from the + directly. Instead, you retrieve an existing `MGLUserLocation` object from the `userLocation` property of the map view displayed in your application. */ @interface MGLUserLocation : NSObject From 6cba15f3a964b39184651dae32cccf32c8d706d0 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Wed, 14 Jun 2017 03:01:02 -0400 Subject: [PATCH 12/12] [ios] Remove old Fabric build infrastructure --- Makefile | 5 --- platform/ios/DEVELOPING.md | 1 - platform/ios/scripts/deploy-packages.sh | 1 - platform/ios/scripts/release-fabric.sh | 37 ------------------- ...abric-zip.sh => validate-framework-zip.sh} | 0 5 files changed, 44 deletions(-) delete mode 100755 platform/ios/scripts/release-fabric.sh rename platform/ios/scripts/{validate-fabric-zip.sh => validate-framework-zip.sh} (100%) diff --git a/Makefile b/Makefile index abccb306a6a..1a635cdd3ce 100644 --- a/Makefile +++ b/Makefile @@ -253,11 +253,6 @@ iframework: $(IOS_PROJ_PATH) FORMAT=dynamic BUILD_DEVICE=$(BUILD_DEVICE) SYMBOLS=$(SYMBOLS) \ ./platform/ios/scripts/package.sh -.PHONY: ifabric -ifabric: $(IOS_PROJ_PATH) - FORMAT=static BUILD_DEVICE=$(BUILD_DEVICE) SYMBOLS=NO SELF_CONTAINED=YES \ - ./platform/ios/scripts/package.sh - .PHONY: ideploy ideploy: caffeinate -i ./platform/ios/scripts/deploy-packages.sh diff --git a/platform/ios/DEVELOPING.md b/platform/ios/DEVELOPING.md index 83064fbbd8f..bcb837c243e 100644 --- a/platform/ios/DEVELOPING.md +++ b/platform/ios/DEVELOPING.md @@ -46,7 +46,6 @@ Build and package the SDK by using one of the following commands: * `make iframework` builds a dynamic framework in the Debug configuration for devices and the iOS Simulator. The CocoaPods pod downloads the output of this target. * `make ipackage-sim` builds a dynamic framework in the Debug configuration for the iOS simulator. This is the fastest target. * `make ipackage-strip` builds both dynamic and static frameworks in the Debug configuration, stripped of debug symbols, for devices and the iOS Simulator. -* `make ifabric` builds a special static framework for compatibility with the Fabric Mac application. You can customize the build output by passing the following arguments into the `make` invocation: diff --git a/platform/ios/scripts/deploy-packages.sh b/platform/ios/scripts/deploy-packages.sh index 4a3c73295af..bdc946497d1 100755 --- a/platform/ios/scripts/deploy-packages.sh +++ b/platform/ios/scripts/deploy-packages.sh @@ -112,6 +112,5 @@ buildPackageStyle "ipackage" "symbols" buildPackageStyle "ipackage-strip" buildPackageStyle "iframework" "symbols-dynamic" buildPackageStyle "iframework SYMBOLS=NO" "dynamic" -buildPackageStyle "ifabric" "fabric" step "Finished deploying ${PUBLISH_VERSION} in $(($SECONDS / 60)) minutes and $(($SECONDS % 60)) seconds" diff --git a/platform/ios/scripts/release-fabric.sh b/platform/ios/scripts/release-fabric.sh deleted file mode 100755 index a523705b7bc..00000000000 --- a/platform/ios/scripts/release-fabric.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail -set -u - -export PUBLISH_VERSION=$1 -export BINARY_DIRECTORY=$2 -export ZIP_OUTPUT=mapbox-ios-sdk-${PUBLISH_VERSION}-fabric -export FILE_NAME=mapbox-ios-sdk-${PUBLISH_VERSION}-fabric.zip -export ZIP_ARCHIVE_PATH=${BINARY_DIRECTORY}/${FILE_NAME} -export BUNDLE_ID="com.mapbox.sdk.ios" - -echo "Downloading ${FILE_NAME}:" -wget -P ${BINARY_DIRECTORY} http://mapbox.s3.amazonaws.com/mapbox-gl-native/ios/builds/${FILE_NAME} - -echo "Extracting ${ZIP_ARCHIVE_PATH} to ${BINARY_DIRECTORY}/${ZIP_OUTPUT}" -unzip -q ${ZIP_ARCHIVE_PATH} -d ${BINARY_DIRECTORY}/${ZIP_OUTPUT} -ditto ${BINARY_DIRECTORY}/${ZIP_OUTPUT}/static/Mapbox.framework ${BINARY_DIRECTORY}/Mapbox.framework - -echo "Zipping framework:" -cd ${BINARY_DIRECTORY} -zip -q -r Mapbox.framework.zip Mapbox.framework -cd $OLDPWD - -echo "Validating framework:" -./validate-fabric-zip.sh ${BINARY_DIRECTORY}/Mapbox.framework.zip - -echo "Uploading ${BINARY_DIRECTORY}/Mapbox.framework.zip to https://kits.fabric.io/manage-api/v1/kit-releases/ios/$BUNDLE_ID/$PUBLISH_VERSION with key ${FABRIC_KIT_API_KEY}" -curl --fail -v -X PUT -H "X-FabricKits-ApiKey: ${FABRIC_KIT_API_KEY}" \ - -F "release_artifact=@${BINARY_DIRECTORY}/Mapbox.framework.zip;type=application/octet-stream" \ - https://kits.fabric.io/manage-api/v1/kit-releases/ios/$BUNDLE_ID/$PUBLISH_VERSION - -echo "Cleaning up" -rm -r #{BINARY_DIRECTORY} - -echo "Done" diff --git a/platform/ios/scripts/validate-fabric-zip.sh b/platform/ios/scripts/validate-framework-zip.sh similarity index 100% rename from platform/ios/scripts/validate-fabric-zip.sh rename to platform/ios/scripts/validate-framework-zip.sh