@mapwhit/tilerenderer 0.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +25 -0
  3. package/build/min/.dir +0 -0
  4. package/build/min/package.json +3 -0
  5. package/build/min/src/shaders/_prelude.fragment.glsl.txt +13 -0
  6. package/build/min/src/shaders/_prelude.vertex.glsl.txt +14 -0
  7. package/build/min/src/shaders/background.fragment.glsl.txt +5 -0
  8. package/build/min/src/shaders/background.vertex.glsl.txt +1 -0
  9. package/build/min/src/shaders/background_pattern.fragment.glsl.txt +5 -0
  10. package/build/min/src/shaders/background_pattern.vertex.glsl.txt +1 -0
  11. package/build/min/src/shaders/circle.fragment.glsl.txt +20 -0
  12. package/build/min/src/shaders/circle.vertex.glsl.txt +17 -0
  13. package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +1 -0
  14. package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +1 -0
  15. package/build/min/src/shaders/collision_box.fragment.glsl.txt +1 -0
  16. package/build/min/src/shaders/collision_box.vertex.glsl.txt +1 -0
  17. package/build/min/src/shaders/collision_circle.fragment.glsl.txt +1 -0
  18. package/build/min/src/shaders/collision_circle.vertex.glsl.txt +1 -0
  19. package/build/min/src/shaders/debug.fragment.glsl.txt +1 -0
  20. package/build/min/src/shaders/debug.vertex.glsl.txt +1 -0
  21. package/build/min/src/shaders/fill.fragment.glsl.txt +10 -0
  22. package/build/min/src/shaders/fill.vertex.glsl.txt +7 -0
  23. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +13 -0
  24. package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +9 -0
  25. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +15 -0
  26. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +11 -0
  27. package/build/min/src/shaders/fill_outline.fragment.glsl.txt +10 -0
  28. package/build/min/src/shaders/fill_outline.vertex.glsl.txt +7 -0
  29. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +13 -0
  30. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +9 -0
  31. package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +13 -0
  32. package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +9 -0
  33. package/build/min/src/shaders/heatmap.fragment.glsl.txt +10 -0
  34. package/build/min/src/shaders/heatmap.vertex.glsl.txt +8 -0
  35. package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +5 -0
  36. package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +1 -0
  37. package/build/min/src/shaders/hillshade.fragment.glsl.txt +7 -0
  38. package/build/min/src/shaders/hillshade.vertex.glsl.txt +1 -0
  39. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +8 -0
  40. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +1 -0
  41. package/build/min/src/shaders/line.fragment.glsl.txt +12 -0
  42. package/build/min/src/shaders/line.vertex.glsl.txt +17 -0
  43. package/build/min/src/shaders/line_gradient.fragment.glsl.txt +10 -0
  44. package/build/min/src/shaders/line_gradient.vertex.glsl.txt +16 -0
  45. package/build/min/src/shaders/line_pattern.fragment.glsl.txt +15 -0
  46. package/build/min/src/shaders/line_pattern.vertex.glsl.txt +20 -0
  47. package/build/min/src/shaders/line_sdf.fragment.glsl.txt +17 -0
  48. package/build/min/src/shaders/line_sdf.vertex.glsl.txt +20 -0
  49. package/build/min/src/shaders/raster.fragment.glsl.txt +5 -0
  50. package/build/min/src/shaders/raster.vertex.glsl.txt +1 -0
  51. package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +9 -0
  52. package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +5 -0
  53. package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +19 -0
  54. package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +13 -0
  55. package/package.json +44 -0
  56. package/src/css/mapbox-gl.css +506 -0
  57. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  58. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  59. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  60. package/src/css/svg/mapboxgl-ctrl-geolocate-background.svg +3 -0
  61. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +3 -0
  62. package/src/css/svg/mapboxgl-ctrl-logo-compact.svg +2 -0
  63. package/src/css/svg/mapboxgl-ctrl-logo.svg +1 -0
  64. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  65. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  66. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  67. package/src/data/array_types.js +1138 -0
  68. package/src/data/bucket/circle_attributes.js +5 -0
  69. package/src/data/bucket/circle_bucket.js +118 -0
  70. package/src/data/bucket/fill_attributes.js +5 -0
  71. package/src/data/bucket/fill_bucket.js +166 -0
  72. package/src/data/bucket/fill_extrusion_attributes.js +11 -0
  73. package/src/data/bucket/fill_extrusion_bucket.js +247 -0
  74. package/src/data/bucket/heatmap_bucket.js +12 -0
  75. package/src/data/bucket/line_attributes.js +11 -0
  76. package/src/data/bucket/line_bucket.js +625 -0
  77. package/src/data/bucket/pattern_attributes.js +9 -0
  78. package/src/data/bucket/pattern_bucket_features.js +44 -0
  79. package/src/data/bucket/symbol_attributes.js +95 -0
  80. package/src/data/bucket/symbol_bucket.js +697 -0
  81. package/src/data/bucket.js +53 -0
  82. package/src/data/dem_data.js +126 -0
  83. package/src/data/extent.js +17 -0
  84. package/src/data/feature_index.js +254 -0
  85. package/src/data/index_array_type.js +14 -0
  86. package/src/data/load_geometry.js +42 -0
  87. package/src/data/pos_attributes.js +3 -0
  88. package/src/data/program_configuration.js +782 -0
  89. package/src/data/raster_bounds_attributes.js +6 -0
  90. package/src/data/segment.js +63 -0
  91. package/src/geo/coordinate.js +78 -0
  92. package/src/geo/lng_lat.js +129 -0
  93. package/src/geo/lng_lat_bounds.js +253 -0
  94. package/src/geo/transform.js +605 -0
  95. package/src/gl/color_mode.js +21 -0
  96. package/src/gl/context.js +193 -0
  97. package/src/gl/cull_face_mode.js +22 -0
  98. package/src/gl/depth_mode.js +18 -0
  99. package/src/gl/framebuffer.js +28 -0
  100. package/src/gl/index_buffer.js +52 -0
  101. package/src/gl/stencil_mode.js +17 -0
  102. package/src/gl/types.js +0 -0
  103. package/src/gl/value.js +676 -0
  104. package/src/gl/vertex_buffer.js +101 -0
  105. package/src/index.js +50 -0
  106. package/src/render/draw_background.js +60 -0
  107. package/src/render/draw_circle.js +55 -0
  108. package/src/render/draw_collision_debug.js +45 -0
  109. package/src/render/draw_debug.js +429 -0
  110. package/src/render/draw_fill.js +143 -0
  111. package/src/render/draw_fill_extrusion.js +101 -0
  112. package/src/render/draw_heatmap.js +159 -0
  113. package/src/render/draw_hillshade.js +144 -0
  114. package/src/render/draw_line.js +99 -0
  115. package/src/render/draw_raster.js +151 -0
  116. package/src/render/draw_symbol.js +231 -0
  117. package/src/render/glyph_atlas.js +55 -0
  118. package/src/render/glyph_manager.js +145 -0
  119. package/src/render/image_atlas.js +97 -0
  120. package/src/render/image_manager.js +183 -0
  121. package/src/render/line_atlas.js +139 -0
  122. package/src/render/painter.js +483 -0
  123. package/src/render/program/background_program.js +46 -0
  124. package/src/render/program/circle_program.js +40 -0
  125. package/src/render/program/clipping_mask_program.js +11 -0
  126. package/src/render/program/collision_program.js +28 -0
  127. package/src/render/program/debug_program.js +13 -0
  128. package/src/render/program/fill_extrusion_program.js +76 -0
  129. package/src/render/program/fill_program.js +60 -0
  130. package/src/render/program/heatmap_program.js +46 -0
  131. package/src/render/program/hillshade_program.js +77 -0
  132. package/src/render/program/line_program.js +119 -0
  133. package/src/render/program/pattern.js +57 -0
  134. package/src/render/program/program_uniforms.js +46 -0
  135. package/src/render/program/raster_program.js +50 -0
  136. package/src/render/program/symbol_program.js +112 -0
  137. package/src/render/program.js +133 -0
  138. package/src/render/texture.js +88 -0
  139. package/src/render/tile_mask.js +108 -0
  140. package/src/render/uniform_binding.js +129 -0
  141. package/src/render/vertex_array_object.js +155 -0
  142. package/src/shaders/README.md +42 -0
  143. package/src/shaders/_prelude.fragment.glsl +17 -0
  144. package/src/shaders/_prelude.vertex.glsl +73 -0
  145. package/src/shaders/background.fragment.glsl +10 -0
  146. package/src/shaders/background.vertex.glsl +7 -0
  147. package/src/shaders/background_pattern.fragment.glsl +28 -0
  148. package/src/shaders/background_pattern.vertex.glsl +20 -0
  149. package/src/shaders/circle.fragment.glsl +39 -0
  150. package/src/shaders/circle.vertex.glsl +63 -0
  151. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  152. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  153. package/src/shaders/collision_box.fragment.glsl +21 -0
  154. package/src/shaders/collision_box.vertex.glsl +26 -0
  155. package/src/shaders/collision_circle.fragment.glsl +34 -0
  156. package/src/shaders/collision_circle.vertex.glsl +36 -0
  157. package/src/shaders/debug.fragment.glsl +5 -0
  158. package/src/shaders/debug.vertex.glsl +7 -0
  159. package/src/shaders/encode_attribute.js +19 -0
  160. package/src/shaders/fill.fragment.glsl +13 -0
  161. package/src/shaders/fill.vertex.glsl +13 -0
  162. package/src/shaders/fill_extrusion.fragment.glsl +16 -0
  163. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  164. package/src/shaders/fill_extrusion_pattern.fragment.glsl +41 -0
  165. package/src/shaders/fill_extrusion_pattern.vertex.glsl +76 -0
  166. package/src/shaders/fill_outline.fragment.glsl +17 -0
  167. package/src/shaders/fill_outline.vertex.glsl +17 -0
  168. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  169. package/src/shaders/fill_outline_pattern.vertex.glsl +41 -0
  170. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  171. package/src/shaders/fill_pattern.vertex.glsl +36 -0
  172. package/src/shaders/heatmap.fragment.glsl +21 -0
  173. package/src/shaders/heatmap.vertex.glsl +53 -0
  174. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  175. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  176. package/src/shaders/hillshade.fragment.glsl +52 -0
  177. package/src/shaders/hillshade.vertex.glsl +11 -0
  178. package/src/shaders/hillshade_prepare.fragment.glsl +72 -0
  179. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  180. package/src/shaders/index.js +194 -0
  181. package/src/shaders/line.fragment.glsl +28 -0
  182. package/src/shaders/line.vertex.glsl +84 -0
  183. package/src/shaders/line_gradient.fragment.glsl +34 -0
  184. package/src/shaders/line_gradient.vertex.glsl +84 -0
  185. package/src/shaders/line_pattern.fragment.glsl +69 -0
  186. package/src/shaders/line_pattern.vertex.glsl +88 -0
  187. package/src/shaders/line_sdf.fragment.glsl +44 -0
  188. package/src/shaders/line_sdf.vertex.glsl +95 -0
  189. package/src/shaders/raster.fragment.glsl +52 -0
  190. package/src/shaders/raster.vertex.glsl +21 -0
  191. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  192. package/src/shaders/symbol_icon.vertex.glsl +91 -0
  193. package/src/shaders/symbol_sdf.fragment.glsl +50 -0
  194. package/src/shaders/symbol_sdf.vertex.glsl +117 -0
  195. package/src/source/geojson_source.js +267 -0
  196. package/src/source/geojson_worker_source.js +210 -0
  197. package/src/source/geojson_wrapper.js +67 -0
  198. package/src/source/image_source.js +213 -0
  199. package/src/source/load_tilejson.js +40 -0
  200. package/src/source/pixels_to_tile_units.js +17 -0
  201. package/src/source/query_features.js +198 -0
  202. package/src/source/raster_dem_tile_source.js +140 -0
  203. package/src/source/raster_dem_tile_worker_source.js +26 -0
  204. package/src/source/raster_tile_source.js +126 -0
  205. package/src/source/rtl_text_plugin.js +63 -0
  206. package/src/source/source.js +75 -0
  207. package/src/source/source_cache.js +794 -0
  208. package/src/source/source_state.js +55 -0
  209. package/src/source/tile.js +332 -0
  210. package/src/source/tile_bounds.js +40 -0
  211. package/src/source/tile_cache.js +122 -0
  212. package/src/source/tile_id.js +150 -0
  213. package/src/source/vector_tile_source.js +144 -0
  214. package/src/source/vector_tile_worker_source.js +126 -0
  215. package/src/source/worker.js +175 -0
  216. package/src/source/worker_source.js +14 -0
  217. package/src/source/worker_tile.js +199 -0
  218. package/src/style/create_style_layer.js +25 -0
  219. package/src/style/evaluation_parameters.js +45 -0
  220. package/src/style/light.js +112 -0
  221. package/src/style/load_glyph_range.js +17 -0
  222. package/src/style/load_sprite.js +26 -0
  223. package/src/style/parse_glyph_pbf.js +45 -0
  224. package/src/style/pauseable_placement.js +88 -0
  225. package/src/style/properties.js +691 -0
  226. package/src/style/query_utils.js +39 -0
  227. package/src/style/style.js +955 -0
  228. package/src/style/style_layer/background_style_layer.js +11 -0
  229. package/src/style/style_layer/background_style_layer_properties.js +25 -0
  230. package/src/style/style_layer/circle_style_layer.js +93 -0
  231. package/src/style/style_layer/circle_style_layer_properties.js +76 -0
  232. package/src/style/style_layer/fill_extrusion_style_layer.js +194 -0
  233. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +56 -0
  234. package/src/style/style_layer/fill_style_layer.js +46 -0
  235. package/src/style/style_layer/fill_style_layer_properties.js +45 -0
  236. package/src/style/style_layer/heatmap_style_layer.js +51 -0
  237. package/src/style/style_layer/heatmap_style_layer_properties.js +52 -0
  238. package/src/style/style_layer/hillshade_style_layer.js +15 -0
  239. package/src/style/style_layer/hillshade_style_layer_properties.js +43 -0
  240. package/src/style/style_layer/line_style_layer.js +129 -0
  241. package/src/style/style_layer/line_style_layer_properties.js +104 -0
  242. package/src/style/style_layer/raster_style_layer.js +11 -0
  243. package/src/style/style_layer/raster_style_layer_properties.js +55 -0
  244. package/src/style/style_layer/symbol_style_layer.js +66 -0
  245. package/src/style/style_layer/symbol_style_layer_properties.js +288 -0
  246. package/src/style/style_layer.js +183 -0
  247. package/src/style/style_layer_index.js +61 -0
  248. package/src/style/zoom_history.js +36 -0
  249. package/src/style-spec/deref.js +51 -0
  250. package/src/style-spec/error/parsing_error.js +8 -0
  251. package/src/style-spec/error/validation_error.js +10 -0
  252. package/src/style-spec/expression/compound_expression.js +118 -0
  253. package/src/style-spec/expression/definitions/array.js +82 -0
  254. package/src/style-spec/expression/definitions/assertion.js +69 -0
  255. package/src/style-spec/expression/definitions/at.js +57 -0
  256. package/src/style-spec/expression/definitions/case.js +73 -0
  257. package/src/style-spec/expression/definitions/coalesce.js +68 -0
  258. package/src/style-spec/expression/definitions/coercion.js +96 -0
  259. package/src/style-spec/expression/definitions/collator.js +102 -0
  260. package/src/style-spec/expression/definitions/equals.js +93 -0
  261. package/src/style-spec/expression/definitions/index.js +407 -0
  262. package/src/style-spec/expression/definitions/interpolate.js +235 -0
  263. package/src/style-spec/expression/definitions/length.js +54 -0
  264. package/src/style-spec/expression/definitions/let.js +60 -0
  265. package/src/style-spec/expression/definitions/literal.js +64 -0
  266. package/src/style-spec/expression/definitions/match.js +142 -0
  267. package/src/style-spec/expression/definitions/step.js +116 -0
  268. package/src/style-spec/expression/definitions/var.js +38 -0
  269. package/src/style-spec/expression/evaluation_context.js +35 -0
  270. package/src/style-spec/expression/index.js +329 -0
  271. package/src/style-spec/expression/is_constant.js +63 -0
  272. package/src/style-spec/expression/parsing_context.js +213 -0
  273. package/src/style-spec/expression/parsing_error.js +9 -0
  274. package/src/style-spec/expression/runtime_error.js +12 -0
  275. package/src/style-spec/expression/scope.js +34 -0
  276. package/src/style-spec/expression/stops.js +37 -0
  277. package/src/style-spec/expression/types.js +77 -0
  278. package/src/style-spec/expression/values.js +126 -0
  279. package/src/style-spec/feature_filter/README.md +55 -0
  280. package/src/style-spec/feature_filter/index.js +158 -0
  281. package/src/style-spec/function/convert.js +256 -0
  282. package/src/style-spec/function/index.js +299 -0
  283. package/src/style-spec/group_by_layout.js +68 -0
  284. package/src/style-spec/reference/v8.json +5356 -0
  285. package/src/style-spec/util/color.js +73 -0
  286. package/src/style-spec/util/color_spaces.js +128 -0
  287. package/src/style-spec/util/eval_support.js +8 -0
  288. package/src/style-spec/util/get_type.js +18 -0
  289. package/src/style-spec/util/interpolate.js +21 -0
  290. package/src/style-spec/util/properties.js +17 -0
  291. package/src/style-spec/util/ref_properties.js +1 -0
  292. package/src/style-spec/util/result.js +19 -0
  293. package/src/symbol/anchor.js +21 -0
  294. package/src/symbol/check_max_angle.js +75 -0
  295. package/src/symbol/clip_line.js +73 -0
  296. package/src/symbol/collision_feature.js +230 -0
  297. package/src/symbol/collision_index.js +379 -0
  298. package/src/symbol/cross_tile_symbol_index.js +270 -0
  299. package/src/symbol/get_anchors.js +177 -0
  300. package/src/symbol/grid_index.js +318 -0
  301. package/src/symbol/mergelines.js +75 -0
  302. package/src/symbol/opacity_state.js +21 -0
  303. package/src/symbol/placement.js +563 -0
  304. package/src/symbol/projection.js +601 -0
  305. package/src/symbol/quads.js +173 -0
  306. package/src/symbol/shaping.js +347 -0
  307. package/src/symbol/symbol_layout.js +519 -0
  308. package/src/symbol/symbol_size.js +110 -0
  309. package/src/symbol/transform_text.js +16 -0
  310. package/src/ui/anchor.js +24 -0
  311. package/src/ui/bind_handlers.js +199 -0
  312. package/src/ui/camera.js +954 -0
  313. package/src/ui/events.js +210 -0
  314. package/src/ui/handler/box_zoom.js +151 -0
  315. package/src/ui/handler/dblclick_zoom.js +91 -0
  316. package/src/ui/handler/drag_pan.js +285 -0
  317. package/src/ui/handler/drag_rotate.js +290 -0
  318. package/src/ui/handler/frame.js +28 -0
  319. package/src/ui/handler/inertia.js +45 -0
  320. package/src/ui/handler/keyboard.js +148 -0
  321. package/src/ui/handler/scroll_zoom.js +284 -0
  322. package/src/ui/handler/touch_zoom_rotate.js +263 -0
  323. package/src/ui/map.js +1645 -0
  324. package/src/util/actor.js +104 -0
  325. package/src/util/async.js +23 -0
  326. package/src/util/browser.js +61 -0
  327. package/src/util/callback.js +26 -0
  328. package/src/util/classify_rings.js +43 -0
  329. package/src/util/color_ramp.js +24 -0
  330. package/src/util/config.js +24 -0
  331. package/src/util/dictionary_coder.js +25 -0
  332. package/src/util/dispatcher.js +68 -0
  333. package/src/util/dom.js +102 -0
  334. package/src/util/evented.js +182 -0
  335. package/src/util/find_pole_of_inaccessibility.js +129 -0
  336. package/src/util/global_worker_pool.js +15 -0
  337. package/src/util/image.js +124 -0
  338. package/src/util/interpolate.js +5 -0
  339. package/src/util/intersection_tests.js +207 -0
  340. package/src/util/is_char_in_unicode_block.js +287 -0
  341. package/src/util/loader/image.js +32 -0
  342. package/src/util/object.js +178 -0
  343. package/src/util/script_detection.js +337 -0
  344. package/src/util/struct_array.js +197 -0
  345. package/src/util/task_queue.js +57 -0
  346. package/src/util/throttle.js +26 -0
  347. package/src/util/tile_cover.js +114 -0
  348. package/src/util/token.js +13 -0
  349. package/src/util/unique_id.js +12 -0
  350. package/src/util/util.js +192 -0
  351. package/src/util/vectortile_to_geojson.js +44 -0
  352. package/src/util/verticalize_punctuation.js +112 -0
  353. package/src/util/warn.js +21 -0
  354. package/src/util/web_worker.js +5 -0
  355. package/src/util/web_worker_transfer.js +228 -0
  356. package/src/util/worker_pool.js +41 -0
@@ -0,0 +1,139 @@
1
+ const warn = require('../util/warn');
2
+
3
+ /**
4
+ * A LineAtlas lets us reuse rendered dashed lines
5
+ * by writing many of them to a texture and then fetching their positions
6
+ * using .getDash.
7
+ *
8
+ * @param {number} width
9
+ * @param {number} height
10
+ * @private
11
+ */
12
+ class LineAtlas {
13
+ constructor(width, height) {
14
+ this.width = width;
15
+ this.height = height;
16
+ this.nextRow = 0;
17
+
18
+ this.bytes = 4;
19
+ this.data = new Uint8Array(this.width * this.height * this.bytes);
20
+
21
+ this.positions = {};
22
+ }
23
+
24
+ /**
25
+ * Get or create a dash line pattern.
26
+ *
27
+ * @param {Array<number>} dasharray
28
+ * @param {boolean} round whether to add circle caps in between dash segments
29
+ * @returns {Object} position of dash texture in { y, height, width }
30
+ * @private
31
+ */
32
+ getDash(dasharray, round) {
33
+ const key = dasharray.join(',') + String(round);
34
+
35
+ if (!this.positions[key]) {
36
+ this.positions[key] = this.addDash(dasharray, round);
37
+ }
38
+ return this.positions[key];
39
+ }
40
+
41
+ addDash(dasharray, round) {
42
+ const n = round ? 7 : 0;
43
+ const height = 2 * n + 1;
44
+ const offset = 128;
45
+
46
+ if (this.nextRow + height > this.height) {
47
+ warn.once('LineAtlas out of space');
48
+ return null;
49
+ }
50
+
51
+ let length = 0;
52
+ for (let i = 0; i < dasharray.length; i++) {
53
+ length += dasharray[i];
54
+ }
55
+
56
+ const stretch = this.width / length;
57
+ const halfWidth = stretch / 2;
58
+
59
+ // If dasharray has an odd length, both the first and last parts
60
+ // are dashes and should be joined seamlessly.
61
+ const oddLength = dasharray.length % 2 === 1;
62
+
63
+ for (let y = -n; y <= n; y++) {
64
+ const row = this.nextRow + n + y;
65
+ const index = this.width * row;
66
+
67
+ let left = oddLength ? -dasharray[dasharray.length - 1] : 0;
68
+ let right = dasharray[0];
69
+ let partIndex = 1;
70
+
71
+ for (let x = 0; x < this.width; x++) {
72
+ while (right < x / stretch) {
73
+ left = right;
74
+ right = right + dasharray[partIndex];
75
+
76
+ if (oddLength && partIndex === dasharray.length - 1) {
77
+ right += dasharray[0];
78
+ }
79
+
80
+ partIndex++;
81
+ }
82
+
83
+ const distLeft = Math.abs(x - left * stretch);
84
+ const distRight = Math.abs(x - right * stretch);
85
+ const dist = Math.min(distLeft, distRight);
86
+ const inside = partIndex % 2 === 1;
87
+ let signedDistance;
88
+
89
+ if (round) {
90
+ // Add circle caps
91
+ const distMiddle = n ? (y / n) * (halfWidth + 1) : 0;
92
+ if (inside) {
93
+ const distEdge = halfWidth - Math.abs(distMiddle);
94
+ signedDistance = Math.sqrt(dist * dist + distEdge * distEdge);
95
+ } else {
96
+ signedDistance = halfWidth - Math.sqrt(dist * dist + distMiddle * distMiddle);
97
+ }
98
+ } else {
99
+ signedDistance = (inside ? 1 : -1) * dist;
100
+ }
101
+
102
+ this.data[3 + (index + x) * 4] = Math.max(0, Math.min(255, signedDistance + offset));
103
+ }
104
+ }
105
+
106
+ const pos = {
107
+ y: (this.nextRow + n + 0.5) / this.height,
108
+ height: (2 * n) / this.height,
109
+ width: length
110
+ };
111
+
112
+ this.nextRow += height;
113
+ this.dirty = true;
114
+
115
+ return pos;
116
+ }
117
+
118
+ bind(context) {
119
+ const gl = context.gl;
120
+ if (!this.texture) {
121
+ this.texture = gl.createTexture();
122
+ gl.bindTexture(gl.TEXTURE_2D, this.texture);
123
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
124
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
125
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
126
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
127
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, this.data);
128
+ } else {
129
+ gl.bindTexture(gl.TEXTURE_2D, this.texture);
130
+
131
+ if (this.dirty) {
132
+ this.dirty = false;
133
+ gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.data);
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ module.exports = LineAtlas;
@@ -0,0 +1,483 @@
1
+ const browser = require('../util/browser');
2
+
3
+ const { mat4 } = require('@mapbox/gl-matrix');
4
+ const SourceCache = require('../source/source_cache');
5
+ const EXTENT = require('../data/extent');
6
+ const pixelsToTileUnits = require('../source/pixels_to_tile_units');
7
+ const SegmentVector = require('../data/segment');
8
+ const { RasterBoundsArray, PosArray, TriangleIndexArray, LineStripIndexArray } = require('../data/array_types');
9
+ const rasterBoundsAttributes = require('../data/raster_bounds_attributes');
10
+ const posAttributes = require('../data/pos_attributes');
11
+ const ProgramConfiguration = require('../data/program_configuration');
12
+ const CrossTileSymbolIndex = require('../symbol/cross_tile_symbol_index');
13
+ const shaders = require('../shaders');
14
+ const Program = require('./program');
15
+ const { programUniforms } = require('./program/program_uniforms');
16
+ const Context = require('../gl/context');
17
+ const DepthMode = require('../gl/depth_mode');
18
+ const StencilMode = require('../gl/stencil_mode');
19
+ const ColorMode = require('../gl/color_mode');
20
+ const CullFaceMode = require('../gl/cull_face_mode');
21
+ const updateTileMasks = require('./tile_mask');
22
+ const { clippingMaskUniformValues } = require('./program/clipping_mask_program');
23
+ const Color = require('../style-spec/util/color');
24
+ const symbol = require('./draw_symbol');
25
+ const circle = require('./draw_circle');
26
+ const heatmap = require('./draw_heatmap');
27
+ const line = require('./draw_line');
28
+ const fill = require('./draw_fill');
29
+ const fillExtrusion = require('./draw_fill_extrusion');
30
+ const hillshade = require('./draw_hillshade');
31
+ const raster = require('./draw_raster');
32
+ const background = require('./draw_background');
33
+ const debug = require('./draw_debug');
34
+
35
+ const draw = {
36
+ symbol,
37
+ circle,
38
+ heatmap,
39
+ line,
40
+ fill,
41
+ 'fill-extrusion': fillExtrusion,
42
+ hillshade,
43
+ raster,
44
+ background,
45
+ debug
46
+ };
47
+
48
+ /**
49
+ * Initialize a new painter object.
50
+ *
51
+ * @param {Canvas} gl an experimental-webgl drawing context
52
+ * @private
53
+ */
54
+ class Painter {
55
+ constructor(gl, transform) {
56
+ this.context = new Context(gl);
57
+ this.transform = transform;
58
+ this._tileTextures = {};
59
+
60
+ this.setup();
61
+
62
+ // Within each layer there are multiple distinct z-planes that can be drawn to.
63
+ // This is implemented using the WebGL depth buffer.
64
+ this.numSublayers = SourceCache.maxUnderzooming + SourceCache.maxOverzooming + 1;
65
+ this.depthEpsilon = 1 / 2 ** 16;
66
+
67
+ this.depthRboNeedsClear = true;
68
+
69
+ this.emptyProgramConfiguration = new ProgramConfiguration();
70
+
71
+ this.crossTileSymbolIndex = new CrossTileSymbolIndex();
72
+ }
73
+
74
+ /*
75
+ * Update the GL viewport, projection matrix, and transforms to compensate
76
+ * for a new width and height value.
77
+ */
78
+ resize(width, height) {
79
+ const gl = this.context.gl;
80
+
81
+ this.width = width * browser.devicePixelRatio;
82
+ this.height = height * browser.devicePixelRatio;
83
+ this.context.viewport.set([0, 0, this.width, this.height]);
84
+
85
+ if (this.style) {
86
+ for (const layerId of this.style._order) {
87
+ this.style._layers[layerId].resize();
88
+ }
89
+ }
90
+
91
+ if (this.depthRbo) {
92
+ gl.deleteRenderbuffer(this.depthRbo);
93
+ this.depthRbo = null;
94
+ }
95
+ }
96
+
97
+ setup() {
98
+ const context = this.context;
99
+
100
+ const tileExtentArray = new PosArray();
101
+ tileExtentArray.emplaceBack(0, 0);
102
+ tileExtentArray.emplaceBack(EXTENT, 0);
103
+ tileExtentArray.emplaceBack(0, EXTENT);
104
+ tileExtentArray.emplaceBack(EXTENT, EXTENT);
105
+ this.tileExtentBuffer = context.createVertexBuffer(tileExtentArray, posAttributes.members);
106
+ this.tileExtentSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
107
+
108
+ const debugArray = new PosArray();
109
+ debugArray.emplaceBack(0, 0);
110
+ debugArray.emplaceBack(EXTENT, 0);
111
+ debugArray.emplaceBack(0, EXTENT);
112
+ debugArray.emplaceBack(EXTENT, EXTENT);
113
+ this.debugBuffer = context.createVertexBuffer(debugArray, posAttributes.members);
114
+ this.debugSegments = SegmentVector.simpleSegment(0, 0, 4, 5);
115
+
116
+ const rasterBoundsArray = new RasterBoundsArray();
117
+ rasterBoundsArray.emplaceBack(0, 0, 0, 0);
118
+ rasterBoundsArray.emplaceBack(EXTENT, 0, EXTENT, 0);
119
+ rasterBoundsArray.emplaceBack(0, EXTENT, 0, EXTENT);
120
+ rasterBoundsArray.emplaceBack(EXTENT, EXTENT, EXTENT, EXTENT);
121
+ this.rasterBoundsBuffer = context.createVertexBuffer(rasterBoundsArray, rasterBoundsAttributes.members);
122
+ this.rasterBoundsSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
123
+
124
+ const viewportArray = new PosArray();
125
+ viewportArray.emplaceBack(0, 0);
126
+ viewportArray.emplaceBack(1, 0);
127
+ viewportArray.emplaceBack(0, 1);
128
+ viewportArray.emplaceBack(1, 1);
129
+ this.viewportBuffer = context.createVertexBuffer(viewportArray, posAttributes.members);
130
+ this.viewportSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
131
+
132
+ const tileLineStripIndices = new LineStripIndexArray();
133
+ tileLineStripIndices.emplaceBack(0);
134
+ tileLineStripIndices.emplaceBack(1);
135
+ tileLineStripIndices.emplaceBack(3);
136
+ tileLineStripIndices.emplaceBack(2);
137
+ tileLineStripIndices.emplaceBack(0);
138
+ this.tileBorderIndexBuffer = context.createIndexBuffer(tileLineStripIndices);
139
+
140
+ const quadTriangleIndices = new TriangleIndexArray();
141
+ quadTriangleIndices.emplaceBack(0, 1, 2);
142
+ quadTriangleIndices.emplaceBack(2, 1, 3);
143
+ this.quadTriangleIndexBuffer = context.createIndexBuffer(quadTriangleIndices);
144
+
145
+ const gl = this.context.gl;
146
+ this.stencilClearMode = new StencilMode({ func: gl.ALWAYS, mask: 0 }, 0x0, 0xff, gl.ZERO, gl.ZERO, gl.ZERO);
147
+ }
148
+
149
+ /*
150
+ * Reset the drawing canvas by clearing the stencil buffer so that we can draw
151
+ * new tiles at the same location, while retaining previously drawn pixels.
152
+ */
153
+ clearStencil() {
154
+ const context = this.context;
155
+ const gl = context.gl;
156
+
157
+ this.nextStencilID = 1;
158
+ this.currentStencilSource = undefined;
159
+
160
+ // As a temporary workaround for https://github.com/mapbox/mapbox-gl-js/issues/5490,
161
+ // pending an upstream fix, we draw a fullscreen stencil=0 clipping mask here,
162
+ // effectively clearing the stencil buffer: once an upstream patch lands, remove
163
+ // this function in favor of context.clear({ stencil: 0x0 })
164
+
165
+ const matrix = mat4.create();
166
+ mat4.ortho(matrix, 0, this.width, this.height, 0, 0, 1);
167
+ mat4.scale(matrix, matrix, [gl.drawingBufferWidth, gl.drawingBufferHeight, 0]);
168
+
169
+ this.useProgram('clippingMask').draw(
170
+ context,
171
+ gl.TRIANGLES,
172
+ DepthMode.disabled,
173
+ this.stencilClearMode,
174
+ ColorMode.disabled,
175
+ CullFaceMode.disabled,
176
+ clippingMaskUniformValues(matrix),
177
+ '$clipping',
178
+ this.viewportBuffer,
179
+ this.quadTriangleIndexBuffer,
180
+ this.viewportSegments
181
+ );
182
+ }
183
+
184
+ _renderTileClippingMasks(layer, tileIDs) {
185
+ if (this.currentStencilSource === layer.source || !layer.isTileClipped() || !tileIDs || !tileIDs.length) return;
186
+
187
+ this.currentStencilSource = layer.source;
188
+
189
+ const context = this.context;
190
+ const gl = context.gl;
191
+
192
+ if (this.nextStencilID + tileIDs.length > 256) {
193
+ // we'll run out of fresh IDs so we need to clear and start from scratch
194
+ this.clearStencil();
195
+ }
196
+
197
+ context.setColorMode(ColorMode.disabled);
198
+ context.setDepthMode(DepthMode.disabled);
199
+
200
+ const program = this.useProgram('clippingMask');
201
+
202
+ this._tileClippingMaskIDs = {};
203
+
204
+ for (const tileID of tileIDs) {
205
+ const id = (this._tileClippingMaskIDs[tileID.key] = this.nextStencilID++);
206
+
207
+ program.draw(
208
+ context,
209
+ gl.TRIANGLES,
210
+ DepthMode.disabled,
211
+ // Tests will always pass, and ref value will be written to stencil buffer.
212
+ new StencilMode({ func: gl.ALWAYS, mask: 0 }, id, 0xff, gl.KEEP, gl.KEEP, gl.REPLACE),
213
+ ColorMode.disabled,
214
+ CullFaceMode.disabled,
215
+ clippingMaskUniformValues(tileID.posMatrix),
216
+ '$clipping',
217
+ this.tileExtentBuffer,
218
+ this.quadTriangleIndexBuffer,
219
+ this.tileExtentSegments
220
+ );
221
+ }
222
+ }
223
+
224
+ stencilModeFor3D() {
225
+ if (this.nextStencilID + 1 > 256) {
226
+ this.clearStencil();
227
+ }
228
+
229
+ const id = this.nextStencilID++;
230
+ const gl = this.context.gl;
231
+ return new StencilMode({ func: gl.NOTEQUAL, mask: 0xff }, id, 0xff, gl.KEEP, gl.KEEP, gl.REPLACE);
232
+ }
233
+
234
+ stencilModeForClipping(tileID) {
235
+ const gl = this.context.gl;
236
+ return new StencilMode(
237
+ { func: gl.EQUAL, mask: 0xff },
238
+ this._tileClippingMaskIDs[tileID.key],
239
+ 0x00,
240
+ gl.KEEP,
241
+ gl.KEEP,
242
+ gl.REPLACE
243
+ );
244
+ }
245
+
246
+ colorModeForRenderPass() {
247
+ const gl = this.context.gl;
248
+ if (this._showOverdrawInspector) {
249
+ const numOverdrawSteps = 8;
250
+ const a = 1 / numOverdrawSteps;
251
+
252
+ return new ColorMode([gl.CONSTANT_COLOR, gl.ONE], new Color(a, a, a, 0), [true, true, true, true]);
253
+ }
254
+ if (this.renderPass === 'opaque') {
255
+ return ColorMode.unblended;
256
+ }
257
+ return ColorMode.alphaBlended;
258
+ }
259
+
260
+ depthModeForSublayer(n, mask, func) {
261
+ if (!this.opaquePassEnabledForLayer()) return DepthMode.disabled;
262
+ const depth = 1 - ((1 + this.currentLayer) * this.numSublayers + n) * this.depthEpsilon;
263
+ return new DepthMode(func || this.context.gl.LEQUAL, mask, [depth, depth]);
264
+ }
265
+
266
+ /*
267
+ * The opaque pass and 3D layers both use the depth buffer.
268
+ * Layers drawn above 3D layers need to be drawn using the
269
+ * painter's algorithm so that they appear above 3D features.
270
+ * This returns true for layers that can be drawn using the
271
+ * opaque pass.
272
+ */
273
+ opaquePassEnabledForLayer() {
274
+ return this.currentLayer < this.opaquePassCutoff;
275
+ }
276
+
277
+ render(style, options) {
278
+ this.style = style;
279
+ this.options = options;
280
+
281
+ this.lineAtlas = style.lineAtlas;
282
+ this.imageManager = style.imageManager;
283
+ this.glyphManager = style.glyphManager;
284
+
285
+ this.symbolFadeChange = style.placement.symbolFadeChange(browser.now());
286
+
287
+ const layerIds = this.style._order;
288
+ const sourceCaches = this.style.sourceCaches;
289
+
290
+ for (const id in sourceCaches) {
291
+ const sourceCache = sourceCaches[id];
292
+ if (sourceCache.used) {
293
+ sourceCache.prepare(this.context);
294
+ }
295
+ }
296
+
297
+ const coordsAscending = {};
298
+ const coordsDescending = {};
299
+ const coordsDescendingSymbol = {};
300
+
301
+ for (const id in sourceCaches) {
302
+ const sourceCache = sourceCaches[id];
303
+ coordsAscending[id] = sourceCache.getVisibleCoordinates();
304
+ coordsDescending[id] = coordsAscending[id].slice().reverse();
305
+ coordsDescendingSymbol[id] = sourceCache.getVisibleCoordinates(true).reverse();
306
+ }
307
+
308
+ for (const id in sourceCaches) {
309
+ const sourceCache = sourceCaches[id];
310
+ const source = sourceCache.getSource();
311
+ if (source.type !== 'raster' && source.type !== 'raster-dem') continue;
312
+ const visibleTiles = [];
313
+ for (const coord of coordsAscending[id]) visibleTiles.push(sourceCache.getTile(coord));
314
+ updateTileMasks(visibleTiles, this.context);
315
+ }
316
+
317
+ this.opaquePassCutoff = Number.POSITIVE_INFINITY;
318
+ for (let i = 0; i < layerIds.length; i++) {
319
+ const layerId = layerIds[i];
320
+ if (this.style._layers[layerId].is3D()) {
321
+ this.opaquePassCutoff = i;
322
+ break;
323
+ }
324
+ }
325
+
326
+ // Offscreen pass ===============================================
327
+ // We first do all rendering that requires rendering to a separate
328
+ // framebuffer, and then save those for rendering back to the map
329
+ // later: in doing this we avoid doing expensive framebuffer restores.
330
+ this.renderPass = 'offscreen';
331
+ this.depthRboNeedsClear = true;
332
+
333
+ for (const layerId of layerIds) {
334
+ const layer = this.style._layers[layerId];
335
+ if (!layer.hasOffscreenPass() || layer.isHidden(this.transform.zoom)) continue;
336
+
337
+ const coords = coordsDescending[layer.source];
338
+ if (!coords.length) continue;
339
+
340
+ this.renderLayer(this, sourceCaches[layer.source], layer, coords);
341
+ }
342
+
343
+ // Rebind the main framebuffer now that all offscreen layers have been rendered:
344
+ this.context.bindFramebuffer.set(null);
345
+
346
+ // Clear buffers in preparation for drawing to the main framebuffer
347
+ this.context.clear({ color: options.showOverdrawInspector ? Color.black : Color.transparent, depth: 1 });
348
+
349
+ this.clearStencil();
350
+
351
+ this._showOverdrawInspector = options.showOverdrawInspector;
352
+ this.depthRangeFor3D = [0, 1 - (style._order.length + 2) * this.numSublayers * this.depthEpsilon];
353
+
354
+ // Opaque pass ===============================================
355
+ // Draw opaque layers top-to-bottom first.
356
+ this.renderPass = 'opaque';
357
+
358
+ for (this.currentLayer = layerIds.length - 1; this.currentLayer >= 0; this.currentLayer--) {
359
+ const layer = this.style._layers[layerIds[this.currentLayer]];
360
+ const sourceCache = sourceCaches[layer.source];
361
+ const coords = coordsAscending[layer.source];
362
+
363
+ this._renderTileClippingMasks(layer, coords);
364
+ this.renderLayer(this, sourceCache, layer, coords);
365
+ }
366
+
367
+ // Translucent pass ===============================================
368
+ // Draw all other layers bottom-to-top.
369
+ this.renderPass = 'translucent';
370
+
371
+ for (this.currentLayer = 0; this.currentLayer < layerIds.length; this.currentLayer++) {
372
+ const layer = this.style._layers[layerIds[this.currentLayer]];
373
+ const sourceCache = sourceCaches[layer.source];
374
+
375
+ // For symbol layers in the translucent pass, we add extra tiles to the renderable set
376
+ // for cross-tile symbol fading. Symbol layers don't use tile clipping, so no need to render
377
+ // separate clipping masks
378
+ const coords = (layer.type === 'symbol' ? coordsDescendingSymbol : coordsDescending)[layer.source];
379
+
380
+ this._renderTileClippingMasks(layer, coordsAscending[layer.source]);
381
+ this.renderLayer(this, sourceCache, layer, coords);
382
+ }
383
+
384
+ if (this.options.showTileBoundaries) {
385
+ for (const id in sourceCaches) {
386
+ draw.debug(this, sourceCaches[id], coordsAscending[id]);
387
+ break;
388
+ }
389
+ }
390
+ }
391
+
392
+ setupOffscreenDepthRenderbuffer() {
393
+ const context = this.context;
394
+ // All of the 3D textures will use the same depth renderbuffer.
395
+ if (!this.depthRbo) {
396
+ this.depthRbo = context.createRenderbuffer(context.gl.DEPTH_COMPONENT16, this.width, this.height);
397
+ }
398
+ }
399
+
400
+ renderLayer(painter, sourceCache, layer, coords) {
401
+ if (layer.isHidden(this.transform.zoom)) return;
402
+ if (layer.type !== 'background' && !coords.length) return;
403
+ this.id = layer.id;
404
+
405
+ draw[layer.type](painter, sourceCache, layer, coords);
406
+ }
407
+
408
+ /**
409
+ * Transform a matrix to incorporate the *-translate and *-translate-anchor properties into it.
410
+ * @param inViewportPixelUnitsUnits True when the units accepted by the matrix are in viewport pixels instead of tile units.
411
+ * @returns {Float32Array} matrix
412
+ */
413
+ translatePosMatrix(matrix, tile, translate, translateAnchor, inViewportPixelUnitsUnits) {
414
+ if (!translate[0] && !translate[1]) return matrix;
415
+
416
+ const angle = inViewportPixelUnitsUnits
417
+ ? translateAnchor === 'map'
418
+ ? this.transform.angle
419
+ : 0
420
+ : translateAnchor === 'viewport'
421
+ ? -this.transform.angle
422
+ : 0;
423
+
424
+ if (angle) {
425
+ const sinA = Math.sin(angle);
426
+ const cosA = Math.cos(angle);
427
+ translate = [translate[0] * cosA - translate[1] * sinA, translate[0] * sinA + translate[1] * cosA];
428
+ }
429
+
430
+ const translation = [
431
+ inViewportPixelUnitsUnits ? translate[0] : pixelsToTileUnits(tile, translate[0], this.transform.zoom),
432
+ inViewportPixelUnitsUnits ? translate[1] : pixelsToTileUnits(tile, translate[1], this.transform.zoom),
433
+ 0
434
+ ];
435
+
436
+ const translatedMatrix = new Float32Array(16);
437
+ mat4.translate(translatedMatrix, matrix, translation);
438
+ return translatedMatrix;
439
+ }
440
+
441
+ saveTileTexture(texture) {
442
+ const textures = this._tileTextures[texture.size[0]];
443
+ if (!textures) {
444
+ this._tileTextures[texture.size[0]] = [texture];
445
+ } else {
446
+ textures.push(texture);
447
+ }
448
+ }
449
+
450
+ getTileTexture(size) {
451
+ const textures = this._tileTextures[size];
452
+ return textures && textures.length > 0 ? textures.pop() : null;
453
+ }
454
+
455
+ /**
456
+ * Checks whether a pattern image is needed, and if it is, whether it is not loaded.
457
+ *
458
+ * @returns true if a needed image is missing and rendering needs to be skipped.
459
+ */
460
+ isPatternMissing(image) {
461
+ if (!image) return false;
462
+ const imagePosA = this.imageManager.getPattern(image.from);
463
+ const imagePosB = this.imageManager.getPattern(image.to);
464
+ return !imagePosA || !imagePosB;
465
+ }
466
+
467
+ useProgram(name, programConfiguration = this.emptyProgramConfiguration) {
468
+ this.cache = this.cache || {};
469
+ const key = `${name}${programConfiguration.cacheKey || ''}${this._showOverdrawInspector ? '/overdraw' : ''}`;
470
+ if (!this.cache[key]) {
471
+ this.cache[key] = new Program(
472
+ this.context,
473
+ shaders[name],
474
+ programConfiguration,
475
+ programUniforms[name],
476
+ this._showOverdrawInspector
477
+ );
478
+ }
479
+ return this.cache[key];
480
+ }
481
+ }
482
+
483
+ module.exports = Painter;
@@ -0,0 +1,46 @@
1
+ const { bgPatternUniformValues } = require('./pattern');
2
+ const { Uniform1i, Uniform1f, Uniform2f, UniformColor, UniformMatrix4f } = require('../uniform_binding');
3
+
4
+ const backgroundUniforms = (context, locations) => ({
5
+ u_matrix: new UniformMatrix4f(context, locations.u_matrix),
6
+ u_opacity: new Uniform1f(context, locations.u_opacity),
7
+ u_color: new UniformColor(context, locations.u_color)
8
+ });
9
+
10
+ const backgroundPatternUniforms = (context, locations) => ({
11
+ u_matrix: new UniformMatrix4f(context, locations.u_matrix),
12
+ u_opacity: new Uniform1f(context, locations.u_opacity),
13
+ u_image: new Uniform1i(context, locations.u_image),
14
+ u_pattern_tl_a: new Uniform2f(context, locations.u_pattern_tl_a),
15
+ u_pattern_br_a: new Uniform2f(context, locations.u_pattern_br_a),
16
+ u_pattern_tl_b: new Uniform2f(context, locations.u_pattern_tl_b),
17
+ u_pattern_br_b: new Uniform2f(context, locations.u_pattern_br_b),
18
+ u_texsize: new Uniform2f(context, locations.u_texsize),
19
+ u_mix: new Uniform1f(context, locations.u_mix),
20
+ u_pattern_size_a: new Uniform2f(context, locations.u_pattern_size_a),
21
+ u_pattern_size_b: new Uniform2f(context, locations.u_pattern_size_b),
22
+ u_scale_a: new Uniform1f(context, locations.u_scale_a),
23
+ u_scale_b: new Uniform1f(context, locations.u_scale_b),
24
+ u_pixel_coord_upper: new Uniform2f(context, locations.u_pixel_coord_upper),
25
+ u_pixel_coord_lower: new Uniform2f(context, locations.u_pixel_coord_lower),
26
+ u_tile_units_to_pixels: new Uniform1f(context, locations.u_tile_units_to_pixels)
27
+ });
28
+
29
+ const backgroundUniformValues = (matrix, opacity, color) => ({
30
+ u_matrix: matrix,
31
+ u_opacity: opacity,
32
+ u_color: color
33
+ });
34
+
35
+ const backgroundPatternUniformValues = (matrix, opacity, painter, image, tile, crossfade) =>
36
+ Object.assign(bgPatternUniformValues(image, crossfade, painter, tile), {
37
+ u_matrix: matrix,
38
+ u_opacity: opacity
39
+ });
40
+
41
+ module.exports = {
42
+ backgroundUniforms,
43
+ backgroundPatternUniforms,
44
+ backgroundUniformValues,
45
+ backgroundPatternUniformValues
46
+ };
@@ -0,0 +1,40 @@
1
+ const { Uniform1i, Uniform1f, Uniform2f, UniformMatrix4f } = require('../uniform_binding');
2
+ const pixelsToTileUnits = require('../../source/pixels_to_tile_units');
3
+
4
+ const circleUniforms = (context, locations) => ({
5
+ u_camera_to_center_distance: new Uniform1f(context, locations.u_camera_to_center_distance),
6
+ u_scale_with_map: new Uniform1i(context, locations.u_scale_with_map),
7
+ u_pitch_with_map: new Uniform1i(context, locations.u_pitch_with_map),
8
+ u_extrude_scale: new Uniform2f(context, locations.u_extrude_scale),
9
+ u_matrix: new UniformMatrix4f(context, locations.u_matrix)
10
+ });
11
+
12
+ const circleUniformValues = (painter, coord, tile, layer) => {
13
+ const transform = painter.transform;
14
+
15
+ let pitchWithMap;
16
+ let extrudeScale;
17
+ if (layer.paint.get('circle-pitch-alignment') === 'map') {
18
+ const pixelRatio = pixelsToTileUnits(tile, 1, transform.zoom);
19
+ pitchWithMap = true;
20
+ extrudeScale = [pixelRatio, pixelRatio];
21
+ } else {
22
+ pitchWithMap = false;
23
+ extrudeScale = transform.pixelsToGLUnits;
24
+ }
25
+
26
+ return {
27
+ u_camera_to_center_distance: transform.cameraToCenterDistance,
28
+ u_scale_with_map: +(layer.paint.get('circle-pitch-scale') === 'map'),
29
+ u_matrix: painter.translatePosMatrix(
30
+ coord.posMatrix,
31
+ tile,
32
+ layer.paint.get('circle-translate'),
33
+ layer.paint.get('circle-translate-anchor')
34
+ ),
35
+ u_pitch_with_map: +pitchWithMap,
36
+ u_extrude_scale: extrudeScale
37
+ };
38
+ };
39
+
40
+ module.exports = { circleUniforms, circleUniformValues };