Skip to main content

Module gl

Module gl 

Source
Expand description

A software model of the parts of MapLibre GL JS’s WebGL pipeline used to draw fills, lines and circles, so CPU renders match it pixel-for-pixel.

  • Primitives are sampled at pixel centres with the top-left rule, like a GPU rasteriser; there is no other antialiasing.
  • The framebuffer is 8-bit premultiplied RGBA; every fragment is blended with src + dst * (1 - src.a) and rounded to 8 bits, like WebGL.
  • Line geometry is a port of LineBucket.addLine and the line / line-SDF shaders; fill outlines model gl.LINES with the fill_outline shader; dashes use a port of LineAtlas.

References are to maplibre-gl-js src/data/bucket/line_bucket.ts, src/render/line_atlas.ts, src/render/draw_fill.ts and src/shaders/*.

Structs§

Clip
Per-tile stencil clip: a pixel belongs to the tile if its centre is in [x0, x1) × [y0, y1) (top-left rule on the tile quad).
Dash
Framebuffer
LineBuilder
LineVertex
One line vertex as the line shaders see it after attribute decoding.
Vert

Enums§

Cap
Join

Constants§

ATLAS_W
EXTENT
MapLibre loads all tile geometry into an 8192-unit extent.

Functions§

raster_gl_line
Fragments of a 1 px aliased gl.LINES segment (diamond-exit style: start inclusive, end exclusive along the major axis), with the perpendicular distance from each pixel centre to the line, which is what the fill_outline shader’s length(v_pos - gl_FragCoord.xy) evaluates to.
raster_polygon
Pixel-centre coverage of one polygon (exterior + holes, even-odd), the same pixels earcut triangles cover under the top-left rule.
raster_triangle
Rasterise a triangle, calling frag(x, y, varyings) for each covered pixel centre inside clip. Varyings are interpolated linearly (no perspective).
smoothstep