diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-08 08:55:55 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-08 13:49:24 -0800 |
commit | b83b14feb0b99d669fb84a52ab356051368de637 (patch) | |
tree | adc86e0e415db7d7f0371471e1d3fe4b95146968 | |
parent | 84aac92b4eaf264de66c07b98e267364e34e14f0 (diff) | |
download | qtlocation-mapboxgl-b83b14feb0b99d669fb84a52ab356051368de637.tar.gz |
[core] De-duplicate shader prelude source
-rw-r--r-- | cmake/core-files.cmake | 2 | ||||
-rwxr-xr-x | scripts/generate-shaders.js | 41 | ||||
-rw-r--r-- | src/mbgl/programs/program.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/shaders/circle.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/collision_box.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/debug.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/fill.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_outline.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_outline_pattern.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/fill_pattern.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/line.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/line_pattern.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/line_sdf.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/preludes.cpp | 87 | ||||
-rw-r--r-- | src/mbgl/shaders/preludes.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/shaders/raster.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/symbol_icon.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/shaders/symbol_sdf.cpp | 71 |
18 files changed, 141 insertions, 929 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index a9fe077db9..b5baff264c 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -205,6 +205,8 @@ set(MBGL_CORE_FILES src/mbgl/shaders/line_pattern.hpp src/mbgl/shaders/line_sdf.cpp src/mbgl/shaders/line_sdf.hpp + src/mbgl/shaders/preludes.cpp + src/mbgl/shaders/preludes.hpp src/mbgl/shaders/raster.cpp src/mbgl/shaders/raster.hpp src/mbgl/shaders/symbol_icon.cpp diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js index 2949ebd007..892620cf21 100755 --- a/scripts/generate-shaders.js +++ b/scripts/generate-shaders.js @@ -8,6 +8,41 @@ const outputPath = 'src/mbgl/shaders'; require('./style-code'); +const vertexPrelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl')); +const fragmentPrelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl')); + +writeIfModified(path.join(outputPath, 'preludes.hpp'), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. + +#pragma once + +namespace mbgl { +namespace shaders { + +extern const char* vertexPrelude; +extern const char* fragmentPrelude; + +} // namespace shaders +} // namespace mbgl +`); + +writeIfModified(path.join(outputPath, 'preludes.cpp'), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. + +#include <mbgl/shaders/preludes.hpp> + +namespace mbgl { +namespace shaders { + +const char* vertexPrelude = R"MBGL_SHADER( +${vertexPrelude} +)MBGL_SHADER"; +const char* fragmentPrelude = R"MBGL_SHADER( +${fragmentPrelude} +)MBGL_SHADER"; + +} // namespace shaders +} // namespace mbgl +`); + [ 'circle', 'collision_box', @@ -34,9 +69,8 @@ require('./style-code'); } function vertexSource() { - const prelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl')); const source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8'); - return prelude + applyPragmas(source, { + return applyPragmas(source, { define: [ "uniform lowp float a_{name}_t;", "attribute {precision} {type} a_{name}_min;", @@ -50,9 +84,8 @@ require('./style-code'); } function fragmentSource() { - const prelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl')); const source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8'); - return prelude + applyPragmas(source, { + return applyPragmas(source, { define: [ "varying {precision} {type} {name};" ], diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index e75dbebf18..ffad767c3a 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -4,6 +4,7 @@ #include <mbgl/programs/program_parameters.hpp> #include <mbgl/programs/attributes.hpp> #include <mbgl/style/paint_property.hpp> +#include <mbgl/shaders/preludes.hpp> #include <sstream> #include <cassert> @@ -45,7 +46,7 @@ public: } static std::string fragmentSource(const ProgramParameters& parameters) { - std::string source = pixelRatioDefine(parameters) + Shaders::fragmentSource; + std::string source = pixelRatioDefine(parameters) + shaders::fragmentPrelude + Shaders::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"); @@ -54,7 +55,7 @@ public: } static std::string vertexSource(const ProgramParameters& parameters) { - return pixelRatioDefine(parameters) + Shaders::vertexSource; + return pixelRatioDefine(parameters) + shaders::vertexPrelude + Shaders::vertexSource; } template <class DrawMode> diff --git a/src/mbgl/shaders/circle.cpp b/src/mbgl/shaders/circle.cpp index 592a883fb3..4b2bb7cecf 100644 --- a/src/mbgl/shaders/circle.cpp +++ b/src/mbgl/shaders/circle.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* circle::name = "circle"; const char* circle::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} uniform mat4 u_matrix; uniform bool u_scale_with_map; uniform vec2 u_extrude_scale; @@ -130,23 +76,6 @@ void main(void) { )MBGL_SHADER"; const char* circle::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif varying lowp vec4 color; varying mediump float radius; varying lowp float blur; diff --git a/src/mbgl/shaders/collision_box.cpp b/src/mbgl/shaders/collision_box.cpp index 6f2b9f3824..5f733c6a1e 100644 --- a/src/mbgl/shaders/collision_box.cpp +++ b/src/mbgl/shaders/collision_box.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* collision_box::name = "collision_box"; const char* collision_box::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} attribute vec2 a_pos; attribute vec2 a_extrude; attribute vec2 a_data; @@ -80,23 +26,6 @@ void main() { )MBGL_SHADER"; const char* collision_box::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform float u_zoom; uniform float u_maxzoom; diff --git a/src/mbgl/shaders/debug.cpp b/src/mbgl/shaders/debug.cpp index 2659b2ca79..27a15698d4 100644 --- a/src/mbgl/shaders/debug.cpp +++ b/src/mbgl/shaders/debug.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* debug::name = "debug"; const char* debug::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} attribute vec2 a_pos; uniform mat4 u_matrix; @@ -71,23 +17,6 @@ void main() { )MBGL_SHADER"; const char* debug::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform lowp vec4 u_color; void main() { diff --git a/src/mbgl/shaders/fill.cpp b/src/mbgl/shaders/fill.cpp index 066adee447..d0fc3a7033 100644 --- a/src/mbgl/shaders/fill.cpp +++ b/src/mbgl/shaders/fill.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* fill::name = "fill"; const char* fill::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} attribute vec2 a_pos; uniform mat4 u_matrix; @@ -83,23 +29,6 @@ void main() { )MBGL_SHADER"; const char* fill::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif varying lowp vec4 color; varying lowp float opacity; diff --git a/src/mbgl/shaders/fill_outline.cpp b/src/mbgl/shaders/fill_outline.cpp index 0f0f3806a9..d6f8d63715 100644 --- a/src/mbgl/shaders/fill_outline.cpp +++ b/src/mbgl/shaders/fill_outline.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* fill_outline::name = "fill_outline"; const char* fill_outline::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} attribute vec2 a_pos; uniform mat4 u_matrix; @@ -87,23 +33,6 @@ void main() { )MBGL_SHADER"; const char* fill_outline::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif varying lowp vec4 outline_color; varying lowp float opacity; diff --git a/src/mbgl/shaders/fill_outline_pattern.cpp b/src/mbgl/shaders/fill_outline_pattern.cpp index 3921a83e6b..6e9d6ad9a1 100644 --- a/src/mbgl/shaders/fill_outline_pattern.cpp +++ b/src/mbgl/shaders/fill_outline_pattern.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* fill_outline_pattern::name = "fill_outline_pattern"; const char* fill_outline_pattern::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} uniform mat4 u_matrix; uniform vec2 u_world; uniform vec2 u_pattern_size_a; @@ -95,23 +41,6 @@ void main() { )MBGL_SHADER"; const char* fill_outline_pattern::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; diff --git a/src/mbgl/shaders/fill_pattern.cpp b/src/mbgl/shaders/fill_pattern.cpp index 822a0f7b8f..329a292eed 100644 --- a/src/mbgl/shaders/fill_pattern.cpp +++ b/src/mbgl/shaders/fill_pattern.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* fill_pattern::name = "fill_pattern"; const char* fill_pattern::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} uniform mat4 u_matrix; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; @@ -91,23 +37,6 @@ void main() { )MBGL_SHADER"; const char* fill_pattern::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform vec2 u_pattern_tl_a; uniform vec2 u_pattern_br_a; uniform vec2 u_pattern_tl_b; diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index 59fa9f0cf2..bd3256ad3b 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* line::name = "line"; const char* line::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} // the distance over which the line edge fades out. @@ -164,23 +110,6 @@ void main() { )MBGL_SHADER"; const char* line::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif varying lowp vec4 color; varying lowp float blur; varying lowp float opacity; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index 7f2a31ee44..2be98deab3 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* line_pattern::name = "line_pattern"; const char* line_pattern::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but @@ -163,23 +109,6 @@ void main() { )MBGL_SHADER"; const char* line_pattern::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; uniform vec2 u_pattern_tl_a; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index 011c1c3738..5f01cf00c0 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* line_sdf::name = "line_sdf"; const char* line_sdf::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} // floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but @@ -175,23 +121,6 @@ void main() { )MBGL_SHADER"; const char* line_sdf::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform sampler2D u_image; uniform float u_sdfgamma; diff --git a/src/mbgl/shaders/preludes.cpp b/src/mbgl/shaders/preludes.cpp new file mode 100644 index 0000000000..a0e9414ceb --- /dev/null +++ b/src/mbgl/shaders/preludes.cpp @@ -0,0 +1,87 @@ +// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. + +#include <mbgl/shaders/preludes.hpp> + +namespace mbgl { +namespace shaders { + +const char* vertexPrelude = R"MBGL_SHADER( +#ifdef GL_ES +precision highp float; +#else + +#if !defined(lowp) +#define lowp +#endif + +#if !defined(mediump) +#define mediump +#endif + +#if !defined(highp) +#define highp +#endif + +#endif + +float evaluate_zoom_function_1(const vec4 values, const float t) { + if (t < 1.0) { + return mix(values[0], values[1], t); + } else if (t < 2.0) { + return mix(values[1], values[2], t - 1.0); + } else { + return mix(values[2], values[3], t - 2.0); + } +} +vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { + if (t < 1.0) { + return mix(value0, value1, t); + } else if (t < 2.0) { + return mix(value1, value2, t - 1.0); + } else { + return mix(value2, value3, t - 2.0); + } +} + +// The offset depends on how many pixels are between the world origin and the edge of the tile: +// vec2 offset = mod(pixel_coord, size) +// +// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. +// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. +// +// The pixel_coord is passed in as two 16 bit values: +// pixel_coord_upper = floor(pixel_coord / 2^16) +// pixel_coord_lower = mod(pixel_coord, 2^16) +// +// The offset is calculated in a series of steps that should preserve this precision: +vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, + const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { + + vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); + return (tile_units_to_pixels * pos + offset) / pattern_size; +} + +)MBGL_SHADER"; +const char* fragmentPrelude = R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#else + +#if !defined(lowp) +#define lowp +#endif + +#if !defined(mediump) +#define mediump +#endif + +#if !defined(highp) +#define highp +#endif + +#endif + +)MBGL_SHADER"; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/preludes.hpp b/src/mbgl/shaders/preludes.hpp new file mode 100644 index 0000000000..a3abc9001f --- /dev/null +++ b/src/mbgl/shaders/preludes.hpp @@ -0,0 +1,12 @@ +// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. + +#pragma once + +namespace mbgl { +namespace shaders { + +extern const char* vertexPrelude; +extern const char* fragmentPrelude; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/raster.cpp b/src/mbgl/shaders/raster.cpp index ba0aa5cd05..eb7a2db240 100644 --- a/src/mbgl/shaders/raster.cpp +++ b/src/mbgl/shaders/raster.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* raster::name = "raster"; const char* raster::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} uniform mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; @@ -80,23 +26,6 @@ void main() { )MBGL_SHADER"; const char* raster::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform float u_fade_t; uniform float u_opacity; uniform sampler2D u_image0; diff --git a/src/mbgl/shaders/symbol_icon.cpp b/src/mbgl/shaders/symbol_icon.cpp index e6728e15de..5945f1f3b1 100644 --- a/src/mbgl/shaders/symbol_icon.cpp +++ b/src/mbgl/shaders/symbol_icon.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* symbol_icon::name = "symbol_icon"; const char* symbol_icon::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} attribute vec2 a_pos; attribute vec2 a_offset; attribute vec2 a_texture_pos; @@ -109,23 +55,6 @@ void main() { )MBGL_SHADER"; const char* symbol_icon::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif uniform sampler2D u_texture; uniform sampler2D u_fadetexture; diff --git a/src/mbgl/shaders/symbol_sdf.cpp b/src/mbgl/shaders/symbol_sdf.cpp index e087242bf8..ccb4b9cee6 100644 --- a/src/mbgl/shaders/symbol_sdf.cpp +++ b/src/mbgl/shaders/symbol_sdf.cpp @@ -7,60 +7,6 @@ namespace shaders { const char* symbol_sdf::name = "symbol_sdf"; const char* symbol_sdf::vertexSource = R"MBGL_SHADER( -#ifdef GL_ES -precision highp float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif - -float evaluate_zoom_function_1(const vec4 values, const float t) { - if (t < 1.0) { - return mix(values[0], values[1], t); - } else if (t < 2.0) { - return mix(values[1], values[2], t - 1.0); - } else { - return mix(values[2], values[3], t - 2.0); - } -} -vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) { - if (t < 1.0) { - return mix(value0, value1, t); - } else if (t < 2.0) { - return mix(value1, value2, t - 1.0); - } else { - return mix(value2, value3, t - 2.0); - } -} - -// The offset depends on how many pixels are between the world origin and the edge of the tile: -// vec2 offset = mod(pixel_coord, size) -// -// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile. -// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that. -// -// The pixel_coord is passed in as two 16 bit values: -// pixel_coord_upper = floor(pixel_coord / 2^16) -// pixel_coord_lower = mod(pixel_coord, 2^16) -// -// The offset is calculated in a series of steps that should preserve this precision: -vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, - const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) { - - vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} const float PI = 3.141592653589793; attribute vec2 a_pos; @@ -172,23 +118,6 @@ void main() { )MBGL_SHADER"; const char* symbol_sdf::fragmentSource = R"MBGL_SHADER( -#ifdef GL_ES -precision mediump float; -#else - -#if !defined(lowp) -#define lowp -#endif - -#if !defined(mediump) -#define mediump -#endif - -#if !defined(highp) -#define highp -#endif - -#endif #define SDF_PX 8.0 #define EDGE_GAMMA 0.105/DEVICE_PIXEL_RATIO |