diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | bin/build-shaders.js | 6 | ||||
-rw-r--r-- | src/geometry/debug_font.cpp | 199 | ||||
-rw-r--r-- | src/shader/shaders.cpp | 30 |
4 files changed, 121 insertions, 116 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 658615986c..77c3babce8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(VERSION_MINOR "0") set(VERSION_PATCH "1") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -stdlib=libc++") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -stdlib=libc++ -pedantic") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") add_subdirectory(src) diff --git a/bin/build-shaders.js b/bin/build-shaders.js index 3578fe7e86..531c2f7a93 100755 --- a/bin/build-shaders.js +++ b/bin/build-shaders.js @@ -28,9 +28,9 @@ module.exports = function() { consts.push(name.toUpperCase() + '_SHADER'); var line = ''; - line += ' [' + name.toUpperCase() + '_SHADER] = {\n'; - line += ' .vertex = ' + JSON.stringify(shaders[name].vertex) + ',\n'; - line += ' .fragment = ' + JSON.stringify(shaders[name].fragment) + ',\n'; + line += ' {\n'; + line += ' ' + JSON.stringify(shaders[name].vertex) + ',\n'; + line += ' ' + JSON.stringify(shaders[name].fragment) + ',\n'; line += ' }'; lines.push(line); } diff --git a/src/geometry/debug_font.cpp b/src/geometry/debug_font.cpp index 3920bd9476..5682d5118b 100644 --- a/src/geometry/debug_font.cpp +++ b/src/geometry/debug_font.cpp @@ -1,6 +1,6 @@ #include <cstdint> +#include <map> -int8_t simplex_0[] = { }; int8_t simplex_1[] = { 5, 21, 5, 7, -1, -1, 5, 2, 4, 1, 5, 0, 6, 1, 5, 2 }; int8_t simplex_2[] = { 4, 21, 4, 14, -1, -1, 12, 21, 12, 14 }; int8_t simplex_3[] = { 11, 25, 4, -7, -1, -1, 17, 25, 10, -7, -1, -1, 4, 12, 18, 12, -1, -1, 3, 6, 17, 6 }; @@ -97,6 +97,11 @@ int8_t simplex_93[] = { 5, 25, 7, 24, 8, 23, 9, 21, 9, 19, 8, 17, 7, 16, 6, 14, int8_t simplex_94[] = { 3, 6, 3, 8, 4, 11, 6, 12, 8, 12, 10, 11, 14, 8, 16, 7, 18, 7, 20, 8, 21, 10, -1, -1, 3, 8, 4, 10, 6, 11, 8, 11, 10, 10, 14, 7, 16, 6, 18, 6, 20, 7, 21, 10, 21, 12 }; struct glyph { + glyph() : width(0), length(0), data(NULL) { } + glyph(uint8_t width, uint8_t length, int8_t *data) + : width(width), + length(length), + data(data) {} uint8_t width; uint8_t length; int8_t *data; @@ -104,100 +109,100 @@ struct glyph { // Font data From Hershey Simplex Font // http://paulbourke.net/dataformats/hershey/ -glyph simplex[127] = { - [' '] = { .width = 16, .length = sizeof(simplex_0), .data = simplex_0 }, - ['!'] = { .width = 10, .length = sizeof(simplex_1), .data = simplex_1 }, - ['"'] = { .width = 16, .length = sizeof(simplex_2), .data = simplex_2 }, - ['#'] = { .width = 21, .length = sizeof(simplex_3), .data = simplex_3 }, - ['$'] = { .width = 20, .length = sizeof(simplex_4), .data = simplex_4 }, - ['%'] = { .width = 24, .length = sizeof(simplex_5), .data = simplex_5 }, - ['&'] = { .width = 26, .length = sizeof(simplex_6), .data = simplex_6 }, - ['\''] = { .width = 10, .length = sizeof(simplex_7), .data = simplex_7 }, - ['('] = { .width = 14, .length = sizeof(simplex_8), .data = simplex_8 }, - [')'] = { .width = 14, .length = sizeof(simplex_9), .data = simplex_9 }, - ['*'] = { .width = 16, .length = sizeof(simplex_10), .data = simplex_10 }, - ['+'] = { .width = 26, .length = sizeof(simplex_11), .data = simplex_11 }, - [','] = { .width = 10, .length = sizeof(simplex_12), .data = simplex_12 }, - ['-'] = { .width = 26, .length = sizeof(simplex_13), .data = simplex_13 }, - ['.'] = { .width = 10, .length = sizeof(simplex_14), .data = simplex_14 }, - ['/'] = { .width = 22, .length = sizeof(simplex_15), .data = simplex_15 }, - ['0'] = { .width = 20, .length = sizeof(simplex_16), .data = simplex_16 }, - ['1'] = { .width = 20, .length = sizeof(simplex_17), .data = simplex_17 }, - ['2'] = { .width = 20, .length = sizeof(simplex_18), .data = simplex_18 }, - ['3'] = { .width = 20, .length = sizeof(simplex_19), .data = simplex_19 }, - ['4'] = { .width = 20, .length = sizeof(simplex_20), .data = simplex_20 }, - ['5'] = { .width = 20, .length = sizeof(simplex_21), .data = simplex_21 }, - ['6'] = { .width = 20, .length = sizeof(simplex_22), .data = simplex_22 }, - ['7'] = { .width = 20, .length = sizeof(simplex_23), .data = simplex_23 }, - ['8'] = { .width = 20, .length = sizeof(simplex_24), .data = simplex_24 }, - ['9'] = { .width = 20, .length = sizeof(simplex_25), .data = simplex_25 }, - [':'] = { .width = 10, .length = sizeof(simplex_26), .data = simplex_26 }, - [';'] = { .width = 10, .length = sizeof(simplex_27), .data = simplex_27 }, - ['<'] = { .width = 24, .length = sizeof(simplex_28), .data = simplex_28 }, - ['='] = { .width = 26, .length = sizeof(simplex_29), .data = simplex_29 }, - ['>'] = { .width = 24, .length = sizeof(simplex_30), .data = simplex_30 }, - ['?'] = { .width = 18, .length = sizeof(simplex_31), .data = simplex_31 }, - ['@'] = { .width = 27, .length = sizeof(simplex_32), .data = simplex_32 }, - ['A'] = { .width = 18, .length = sizeof(simplex_33), .data = simplex_33 }, - ['B'] = { .width = 21, .length = sizeof(simplex_34), .data = simplex_34 }, - ['C'] = { .width = 21, .length = sizeof(simplex_35), .data = simplex_35 }, - ['D'] = { .width = 21, .length = sizeof(simplex_36), .data = simplex_36 }, - ['E'] = { .width = 19, .length = sizeof(simplex_37), .data = simplex_37 }, - ['F'] = { .width = 18, .length = sizeof(simplex_38), .data = simplex_38 }, - ['G'] = { .width = 21, .length = sizeof(simplex_39), .data = simplex_39 }, - ['H'] = { .width = 22, .length = sizeof(simplex_40), .data = simplex_40 }, - ['I'] = { .width = 8, .length = sizeof(simplex_41), .data = simplex_41 }, - ['J'] = { .width = 16, .length = sizeof(simplex_42), .data = simplex_42 }, - ['K'] = { .width = 21, .length = sizeof(simplex_43), .data = simplex_43 }, - ['L'] = { .width = 17, .length = sizeof(simplex_44), .data = simplex_44 }, - ['M'] = { .width = 24, .length = sizeof(simplex_45), .data = simplex_45 }, - ['N'] = { .width = 22, .length = sizeof(simplex_46), .data = simplex_46 }, - ['O'] = { .width = 22, .length = sizeof(simplex_47), .data = simplex_47 }, - ['P'] = { .width = 21, .length = sizeof(simplex_48), .data = simplex_48 }, - ['Q'] = { .width = 22, .length = sizeof(simplex_49), .data = simplex_49 }, - ['R'] = { .width = 21, .length = sizeof(simplex_50), .data = simplex_50 }, - ['S'] = { .width = 20, .length = sizeof(simplex_51), .data = simplex_51 }, - ['T'] = { .width = 16, .length = sizeof(simplex_52), .data = simplex_52 }, - ['U'] = { .width = 22, .length = sizeof(simplex_53), .data = simplex_53 }, - ['V'] = { .width = 18, .length = sizeof(simplex_54), .data = simplex_54 }, - ['W'] = { .width = 24, .length = sizeof(simplex_55), .data = simplex_55 }, - ['X'] = { .width = 20, .length = sizeof(simplex_56), .data = simplex_56 }, - ['Y'] = { .width = 18, .length = sizeof(simplex_57), .data = simplex_57 }, - ['Z'] = { .width = 20, .length = sizeof(simplex_58), .data = simplex_58 }, - ['['] = { .width = 14, .length = sizeof(simplex_59), .data = simplex_59 }, - ['\\'] = { .width = 14, .length = sizeof(simplex_60), .data = simplex_60 }, - [']'] = { .width = 14, .length = sizeof(simplex_61), .data = simplex_61 }, - ['^'] = { .width = 16, .length = sizeof(simplex_62), .data = simplex_62 }, - ['_'] = { .width = 16, .length = sizeof(simplex_63), .data = simplex_63 }, - ['`'] = { .width = 10, .length = sizeof(simplex_64), .data = simplex_64 }, - ['a'] = { .width = 19, .length = sizeof(simplex_65), .data = simplex_65 }, - ['b'] = { .width = 19, .length = sizeof(simplex_66), .data = simplex_66 }, - ['c'] = { .width = 18, .length = sizeof(simplex_67), .data = simplex_67 }, - ['d'] = { .width = 19, .length = sizeof(simplex_68), .data = simplex_68 }, - ['e'] = { .width = 18, .length = sizeof(simplex_69), .data = simplex_69 }, - ['f'] = { .width = 12, .length = sizeof(simplex_70), .data = simplex_70 }, - ['g'] = { .width = 19, .length = sizeof(simplex_71), .data = simplex_71 }, - ['h'] = { .width = 19, .length = sizeof(simplex_72), .data = simplex_72 }, - ['i'] = { .width = 8, .length = sizeof(simplex_73), .data = simplex_73 }, - ['j'] = { .width = 10, .length = sizeof(simplex_74), .data = simplex_74 }, - ['k'] = { .width = 17, .length = sizeof(simplex_75), .data = simplex_75 }, - ['l'] = { .width = 8, .length = sizeof(simplex_76), .data = simplex_76 }, - ['m'] = { .width = 30, .length = sizeof(simplex_77), .data = simplex_77 }, - ['n'] = { .width = 19, .length = sizeof(simplex_78), .data = simplex_78 }, - ['o'] = { .width = 19, .length = sizeof(simplex_79), .data = simplex_79 }, - ['p'] = { .width = 19, .length = sizeof(simplex_80), .data = simplex_80 }, - ['q'] = { .width = 19, .length = sizeof(simplex_81), .data = simplex_81 }, - ['r'] = { .width = 13, .length = sizeof(simplex_82), .data = simplex_82 }, - ['s'] = { .width = 17, .length = sizeof(simplex_83), .data = simplex_83 }, - ['t'] = { .width = 12, .length = sizeof(simplex_84), .data = simplex_84 }, - ['u'] = { .width = 19, .length = sizeof(simplex_85), .data = simplex_85 }, - ['v'] = { .width = 16, .length = sizeof(simplex_86), .data = simplex_86 }, - ['w'] = { .width = 22, .length = sizeof(simplex_87), .data = simplex_87 }, - ['x'] = { .width = 17, .length = sizeof(simplex_88), .data = simplex_88 }, - ['y'] = { .width = 16, .length = sizeof(simplex_89), .data = simplex_89 }, - ['z'] = { .width = 17, .length = sizeof(simplex_90), .data = simplex_90 }, - ['{'] = { .width = 14, .length = sizeof(simplex_91), .data = simplex_91 }, - ['|'] = { .width = 8, .length = sizeof(simplex_92), .data = simplex_92 }, - ['}'] = { .width = 14, .length = sizeof(simplex_93), .data = simplex_93 }, - ['~'] = { .width = 24, .length = sizeof(simplex_94), .data = simplex_94 } +std::map<char, glyph> simplex = { + { ' ', { 16, 0, NULL } }, + { '!', { 10, sizeof(simplex_1), simplex_1 } }, + { '"', { 16, sizeof(simplex_2), simplex_2 } }, + { '#', { 21, sizeof(simplex_3), simplex_3 } }, + { '$', { 20, sizeof(simplex_4), simplex_4 } }, + { '%', { 24, sizeof(simplex_5), simplex_5 } }, + { '&', { 26, sizeof(simplex_6), simplex_6 } }, + { '\'', { 10, sizeof(simplex_7), simplex_7 } }, + { '(', { 14, sizeof(simplex_8), simplex_8 } }, + { ')', { 14, sizeof(simplex_9), simplex_9 } }, + { '*', { 16, sizeof(simplex_10), simplex_10 } }, + { '+', { 26, sizeof(simplex_11), simplex_11 } }, + { ',', { 10, sizeof(simplex_12), simplex_12 } }, + { '-', { 26, sizeof(simplex_13), simplex_13 } }, + { '.', { 10, sizeof(simplex_14), simplex_14 } }, + { '/', { 22, sizeof(simplex_15), simplex_15 } }, + { '0', { 20, sizeof(simplex_16), simplex_16 } }, + { '1', { 20, sizeof(simplex_17), simplex_17 } }, + { '2', { 20, sizeof(simplex_18), simplex_18 } }, + { '3', { 20, sizeof(simplex_19), simplex_19 } }, + { '4', { 20, sizeof(simplex_20), simplex_20 } }, + { '5', { 20, sizeof(simplex_21), simplex_21 } }, + { '6', { 20, sizeof(simplex_22), simplex_22 } }, + { '7', { 20, sizeof(simplex_23), simplex_23 } }, + { '8', { 20, sizeof(simplex_24), simplex_24 } }, + { '9', { 20, sizeof(simplex_25), simplex_25 } }, + { ':', { 10, sizeof(simplex_26), simplex_26 } }, + { ';', { 10, sizeof(simplex_27), simplex_27 } }, + { '<', { 24, sizeof(simplex_28), simplex_28 } }, + { '=', { 26, sizeof(simplex_29), simplex_29 } }, + { '>', { 24, sizeof(simplex_30), simplex_30 } }, + { '?', { 18, sizeof(simplex_31), simplex_31 } }, + { '@', { 27, sizeof(simplex_32), simplex_32 } }, + { 'A', { 18, sizeof(simplex_33), simplex_33 } }, + { 'B', { 21, sizeof(simplex_34), simplex_34 } }, + { 'C', { 21, sizeof(simplex_35), simplex_35 } }, + { 'D', { 21, sizeof(simplex_36), simplex_36 } }, + { 'E', { 19, sizeof(simplex_37), simplex_37 } }, + { 'F', { 18, sizeof(simplex_38), simplex_38 } }, + { 'G', { 21, sizeof(simplex_39), simplex_39 } }, + { 'H', { 22, sizeof(simplex_40), simplex_40 } }, + { 'I', { 8, sizeof(simplex_41), simplex_41 } }, + { 'J', { 16, sizeof(simplex_42), simplex_42 } }, + { 'K', { 21, sizeof(simplex_43), simplex_43 } }, + { 'L', { 17, sizeof(simplex_44), simplex_44 } }, + { 'M', { 24, sizeof(simplex_45), simplex_45 } }, + { 'N', { 22, sizeof(simplex_46), simplex_46 } }, + { 'O', { 22, sizeof(simplex_47), simplex_47 } }, + { 'P', { 21, sizeof(simplex_48), simplex_48 } }, + { 'Q', { 22, sizeof(simplex_49), simplex_49 } }, + { 'R', { 21, sizeof(simplex_50), simplex_50 } }, + { 'S', { 20, sizeof(simplex_51), simplex_51 } }, + { 'T', { 16, sizeof(simplex_52), simplex_52 } }, + { 'U', { 22, sizeof(simplex_53), simplex_53 } }, + { 'V', { 18, sizeof(simplex_54), simplex_54 } }, + { 'W', { 24, sizeof(simplex_55), simplex_55 } }, + { 'X', { 20, sizeof(simplex_56), simplex_56 } }, + { 'Y', { 18, sizeof(simplex_57), simplex_57 } }, + { 'Z', { 20, sizeof(simplex_58), simplex_58 } }, + { '[', { 14, sizeof(simplex_59), simplex_59 } }, + { '\\', { 14, sizeof(simplex_60), simplex_60 } }, + { ']', { 14, sizeof(simplex_61), simplex_61 } }, + { '^', { 16, sizeof(simplex_62), simplex_62 } }, + { '_', { 16, sizeof(simplex_63), simplex_63 } }, + { '`', { 10, sizeof(simplex_64), simplex_64 } }, + { 'a', { 19, sizeof(simplex_65), simplex_65 } }, + { 'b', { 19, sizeof(simplex_66), simplex_66 } }, + { 'c', { 18, sizeof(simplex_67), simplex_67 } }, + { 'd', { 19, sizeof(simplex_68), simplex_68 } }, + { 'e', { 18, sizeof(simplex_69), simplex_69 } }, + { 'f', { 12, sizeof(simplex_70), simplex_70 } }, + { 'g', { 19, sizeof(simplex_71), simplex_71 } }, + { 'h', { 19, sizeof(simplex_72), simplex_72 } }, + { 'i', { 8, sizeof(simplex_73), simplex_73 } }, + { 'j', { 10, sizeof(simplex_74), simplex_74 } }, + { 'k', { 17, sizeof(simplex_75), simplex_75 } }, + { 'l', { 8, sizeof(simplex_76), simplex_76 } }, + { 'm', { 30, sizeof(simplex_77), simplex_77 } }, + { 'n', { 19, sizeof(simplex_78), simplex_78 } }, + { 'o', { 19, sizeof(simplex_79), simplex_79 } }, + { 'p', { 19, sizeof(simplex_80), simplex_80 } }, + { 'q', { 19, sizeof(simplex_81), simplex_81 } }, + { 'r', { 13, sizeof(simplex_82), simplex_82 } }, + { 's', { 17, sizeof(simplex_83), simplex_83 } }, + { 't', { 12, sizeof(simplex_84), simplex_84 } }, + { 'u', { 19, sizeof(simplex_85), simplex_85 } }, + { 'v', { 16, sizeof(simplex_86), simplex_86 } }, + { 'w', { 22, sizeof(simplex_87), simplex_87 } }, + { 'x', { 17, sizeof(simplex_88), simplex_88 } }, + { 'y', { 16, sizeof(simplex_89), simplex_89 } }, + { 'z', { 17, sizeof(simplex_90), simplex_90 } }, + { '{', { 14, sizeof(simplex_91), simplex_91 } }, + { '|', { 8, sizeof(simplex_92), simplex_92 } }, + { '}', { 14, sizeof(simplex_93), simplex_93 } }, + { '~', { 24, sizeof(simplex_94), simplex_94 } } }; diff --git a/src/shader/shaders.cpp b/src/shader/shaders.cpp index cd7222b3e1..e98386a6ef 100644 --- a/src/shader/shaders.cpp +++ b/src/shader/shaders.cpp @@ -4,24 +4,24 @@ using namespace llmr; const shader_source llmr::shaders[SHADER_COUNT] = { - [FILL_SHADER] = { - .vertex = "attribute vec2 a_pos;\n\nuniform mat4 u_matrix;\n\nvoid main() {\n gl_Position = u_matrix * vec4(a_pos, 0, 1);\n}\n", - .fragment = "uniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}\n", + { + "attribute vec2 a_pos;\n\nuniform mat4 u_matrix;\n\nvoid main() {\n gl_Position = u_matrix * vec4(a_pos, 0, 1);\n}\n", + "uniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}\n", }, - [LINE_SHADER] = { - .vertex = "// these are the shaders for rendering antialiased lines\n\n// floor(127 / 2) == 63.0\n// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is\n// stored in a byte (-128..127). we scale regular normals up to length 63, but\n// there are also \"special\" normals that have a bigger length (of up to 126 in\n// this case).\n#define scale 63.0\n\nattribute vec2 a_pos;\nattribute vec2 a_extrude;\nattribute float a_linesofar;\n\n// matrix is for the vertex position, exmatrix is for rotating and projecting\n// the extrusion vector.\nuniform mat4 u_matrix;\nuniform mat4 u_exmatrix;\n\n\nuniform float u_debug;\n\n// shared\nuniform float u_ratio;\nuniform vec2 u_linewidth;\nuniform vec4 u_color;\nuniform float u_point;\n\nvarying vec2 v_normal;\nvarying float v_linesofar;\n\nvoid main() {\n // We store the texture normals in the most insignificant bit\n // transform y so that 0 => -1 and 1 => 1\n // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap\n // y is 1 if the normal points up, and -1 if it points down\n vec2 normal = mod(a_pos, 2.0);\n normal.y = sign(normal.y - 0.5);\n v_normal = normal;\n\n // Scale the extrusion vector down to a normal and then up by the line width\n // of this vertex.\n vec2 extrude = a_extrude / scale;\n vec2 dist = u_linewidth.s * extrude * (1.0 - u_point);\n\n // If the x coordinate is the maximum integer, we move the z coordinates out\n // of the view plane so that the triangle gets clipped. This makes it easier\n // for us to create degenerate triangle strips.\n float z = step(32767.0, a_pos.x);\n\n // When drawing points, skip every other vertex\n z += u_point * step(1.0, v_normal.y);\n\n // Remove the texture normal bit of the position before scaling it with the\n // model/view matrix. Add the extrusion vector *after* the model/view matrix\n // because we're extruding the line in pixel space, regardless of the current\n // tile's zoom level.\n gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0);\n v_linesofar = a_linesofar * u_ratio;\n\n\n gl_PointSize = 2.0 * u_linewidth.s - 1.0;\n}\n", - .fragment = "#version 120\n\n// shared\nuniform float u_debug;\nuniform vec2 u_linewidth;\nuniform vec4 u_color;\nuniform float u_point;\nuniform float u_gamma;\n\nuniform vec2 u_dasharray;\n\nvarying vec2 v_normal;\nvarying float v_linesofar;\n\nvoid main() {\n // Calculate the distance of the pixel from the line in pixels.\n float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0);\n\n dist *= u_linewidth.s;\n\n // Calculate the antialiasing fade factor. This is either when fading in\n // the line in case of an offset line (v_linewidth.t) or when fading out\n // (v_linewidth.s)\n float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist) * u_gamma, 0.0, 1.0);\n\n // Calculate the antialiasing fade factor based on distance to the dash.\n // Only affects alpha when line is dashed\n float pos = mod(v_linesofar, u_dasharray.x + u_dasharray.y);\n alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0));\n\n gl_FragColor = u_color * alpha;\n\n if (u_debug > 0.0) {\n gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n }\n}\n", + { + "// these are the shaders for rendering antialiased lines\n\n// floor(127 / 2) == 63.0\n// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is\n// stored in a byte (-128..127). we scale regular normals up to length 63, but\n// there are also \"special\" normals that have a bigger length (of up to 126 in\n// this case).\n#define scale 63.0\n\nattribute vec2 a_pos;\nattribute vec2 a_extrude;\nattribute float a_linesofar;\n\n// matrix is for the vertex position, exmatrix is for rotating and projecting\n// the extrusion vector.\nuniform mat4 u_matrix;\nuniform mat4 u_exmatrix;\n\n\nuniform float u_debug;\n\n// shared\nuniform float u_ratio;\nuniform vec2 u_linewidth;\nuniform vec4 u_color;\nuniform float u_point;\n\nvarying vec2 v_normal;\nvarying float v_linesofar;\n\nvoid main() {\n // We store the texture normals in the most insignificant bit\n // transform y so that 0 => -1 and 1 => 1\n // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap\n // y is 1 if the normal points up, and -1 if it points down\n vec2 normal = mod(a_pos, 2.0);\n normal.y = sign(normal.y - 0.5);\n v_normal = normal;\n\n // Scale the extrusion vector down to a normal and then up by the line width\n // of this vertex.\n vec2 extrude = a_extrude / scale;\n vec2 dist = u_linewidth.s * extrude * (1.0 - u_point);\n\n // If the x coordinate is the maximum integer, we move the z coordinates out\n // of the view plane so that the triangle gets clipped. This makes it easier\n // for us to create degenerate triangle strips.\n float z = step(32767.0, a_pos.x);\n\n // When drawing points, skip every other vertex\n z += u_point * step(1.0, v_normal.y);\n\n // Remove the texture normal bit of the position before scaling it with the\n // model/view matrix. Add the extrusion vector *after* the model/view matrix\n // because we're extruding the line in pixel space, regardless of the current\n // tile's zoom level.\n gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0);\n v_linesofar = a_linesofar * u_ratio;\n\n\n gl_PointSize = 2.0 * u_linewidth.s - 1.0;\n}\n", + "#version 120\n\n// shared\nuniform float u_debug;\nuniform vec2 u_linewidth;\nuniform vec4 u_color;\nuniform float u_point;\nuniform float u_gamma;\n\nuniform vec2 u_dasharray;\n\nvarying vec2 v_normal;\nvarying float v_linesofar;\n\nvoid main() {\n // Calculate the distance of the pixel from the line in pixels.\n float dist = length(v_normal) * (1.0 - u_point) + u_point * length(gl_PointCoord * 2.0 - 1.0);\n\n dist *= u_linewidth.s;\n\n // Calculate the antialiasing fade factor. This is either when fading in\n // the line in case of an offset line (v_linewidth.t) or when fading out\n // (v_linewidth.s)\n float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist) * u_gamma, 0.0, 1.0);\n\n // Calculate the antialiasing fade factor based on distance to the dash.\n // Only affects alpha when line is dashed\n float pos = mod(v_linesofar, u_dasharray.x + u_dasharray.y);\n alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0));\n\n gl_FragColor = u_color * alpha;\n\n if (u_debug > 0.0) {\n gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n }\n}\n", }, - [OUTLINE_SHADER] = { - .vertex = "attribute vec2 a_pos;\nuniform mat4 u_matrix;\nuniform vec2 u_world;\n\nvarying vec2 v_pos;\n\nvoid main() {\n // If the x coordinate is the maximum integer, we move the z coordinates out\n // of the view plane so that the triangle gets clipped. This makes it easier\n // for us to create degenerate triangle strips.\n float z = step(32767.0, a_pos.x) * 2.0;\n gl_Position = u_matrix * vec4(a_pos, z, 1);\n\n v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world;\n}\n", - .fragment = "uniform vec4 u_color;\n\nvarying vec2 v_pos;\n\nvoid main() {\n float dist = length(v_pos - gl_FragCoord.xy);\n float alpha = smoothstep(1.0, 0.0, dist);\n gl_FragColor = u_color * alpha;\n}\n", + { + "attribute vec2 a_pos;\nuniform mat4 u_matrix;\nuniform vec2 u_world;\n\nvarying vec2 v_pos;\n\nvoid main() {\n // If the x coordinate is the maximum integer, we move the z coordinates out\n // of the view plane so that the triangle gets clipped. This makes it easier\n // for us to create degenerate triangle strips.\n float z = step(32767.0, a_pos.x) * 2.0;\n gl_Position = u_matrix * vec4(a_pos, z, 1);\n\n v_pos = (gl_Position.xy + 1.0) / 2.0 * u_world;\n}\n", + "uniform vec4 u_color;\n\nvarying vec2 v_pos;\n\nvoid main() {\n float dist = length(v_pos - gl_FragCoord.xy);\n float alpha = smoothstep(1.0, 0.0, dist);\n gl_FragColor = u_color * alpha;\n}\n", }, - [PATTERN_SHADER] = { - .vertex = "uniform mat4 u_matrix;\n\nattribute vec2 a_pos;\n\nvarying vec2 v_pos;\n\nvoid main() {\n v_pos = a_pos;\n gl_Position = u_matrix * vec4(a_pos, 0, 1);\n}\n", - .fragment = "uniform vec4 u_color;\n\nuniform vec2 u_offset;\nuniform vec2 u_pattern_size;\nuniform vec2 u_pattern_tl;\nuniform vec2 u_pattern_br;\nuniform float u_mix;\n\n\nuniform sampler2D u_image;\n\nvarying vec2 v_pos;\n\nvoid main() {\n\n vec2 imagecoord = mod((v_pos + u_offset) / u_pattern_size, 1.0);\n vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord);\n vec4 color1 = texture2D(u_image, pos);\n\n vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0);\n vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2);\n vec4 color2 = texture2D(u_image, pos2);\n\n vec4 color = mix(color1, color2, u_mix);\n gl_FragColor = color + u_color * (1.0 - color.a);\n}\n", + { + "uniform mat4 u_matrix;\n\nattribute vec2 a_pos;\n\nvarying vec2 v_pos;\n\nvoid main() {\n v_pos = a_pos;\n gl_Position = u_matrix * vec4(a_pos, 0, 1);\n}\n", + "uniform vec4 u_color;\n\nuniform vec2 u_offset;\nuniform vec2 u_pattern_size;\nuniform vec2 u_pattern_tl;\nuniform vec2 u_pattern_br;\nuniform float u_mix;\n\n\nuniform sampler2D u_image;\n\nvarying vec2 v_pos;\n\nvoid main() {\n\n vec2 imagecoord = mod((v_pos + u_offset) / u_pattern_size, 1.0);\n vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord);\n vec4 color1 = texture2D(u_image, pos);\n\n vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0);\n vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2);\n vec4 color2 = texture2D(u_image, pos2);\n\n vec4 color = mix(color1, color2, u_mix);\n gl_FragColor = color + u_color * (1.0 - color.a);\n}\n", }, - [PLAIN_SHADER] = { - .vertex = "attribute vec2 a_pos;\n\nuniform mat4 u_matrix;\n\nvoid main() {\n float z = step(32767.0, a_pos.x) * 2.0;\n gl_Position = u_matrix * vec4(a_pos, z, 1);\n}\n", - .fragment = "uniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}\n", + { + "attribute vec2 a_pos;\n\nuniform mat4 u_matrix;\n\nvoid main() {\n float z = step(32767.0, a_pos.x) * 2.0;\n gl_Position = u_matrix * vec4(a_pos, z, 1);\n}\n", + "uniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}\n", } }; |