Improve GPU memory usage for polygons and lines styles with some vertex attribute VBO re-arrangement.
For polygons:
Features that aren't extruded don't need per-vertex surface normals, because they're always flat and facing up. We can make the a_normal attribute have a static value of [0, 0, 1] in these cases. Extruded features like buildings keep the full per-vertex a_normal in the VBO.
For lines:
This one is a bit trickier. Both the z position of the feature (e.g. the z parameter in a draw block, which moves the entire line up and down in space) and line offset are optional.
While the a_offset attribute (different from the line's a_extrude, which diverges from the line normal at caps and joins) was already an optional attribute with a static value of [0, 0], the offset scaling factor (used to interpolate the offset between zooms) always had space allocated as the second element of the a_scaling attribute (the first element being the line's width scaling factor). Width scaling is required for all lines, but offset scaling only for few.
Therefore, to better organize attributes according to their required/optional status:
Move the required width scaling factor into a_position.z (a required vec4).
Move the optional style z and offset scaling factor into a new a_z_and_offset_scale attribute (an optional vec2). The parameters are grouped into one attribute because they are both 2-byte SHORT values, and attributes must be aligned on 4-byte boundaries.
The previous a_scalingvec2 attribute is removed.
Reviewing Bubble Wrap and the Tangram demo style at a variety of zooms and locations, these changes typically reduce geometry/GPU memory usage by 15-17%.
Improve GPU memory usage for
polygons
andlines
styles with some vertex attribute VBO re-arrangement.polygons
:a_normal
attribute have a static value of[0, 0, 1]
in these cases. Extruded features like buildings keep the full per-vertexa_normal
in the VBO.lines
:z
parameter in adraw
block, which moves the entire line up and down in space) and lineoffset
are optional.a_offset
attribute (different from the line'sa_extrude
, which diverges from the line normal at caps and joins) was already an optional attribute with a static value of[0, 0]
, the offset scaling factor (used to interpolate the offset between zooms) always had space allocated as the second element of thea_scaling
attribute (the first element being the line's width scaling factor). Width scaling is required for all lines, but offset scaling only for few.a_position.z
(a requiredvec4
).a_z_and_offset_scale
attribute (an optionalvec2
). The parameters are grouped into one attribute because they are both 2-byteSHORT
values, and attributes must be aligned on 4-byte boundaries.a_scaling
vec2
attribute is removed.Reviewing Bubble Wrap and the Tangram demo style at a variety of zooms and locations, these changes typically reduce geometry/GPU memory usage by 15-17%.