message: Build and memoize a GLSL prelude
  Saves ~375 ms during startup.
diff: @@ -35,28 +35,15 @@ pub struct Builder {}
  impl Builder {
  /// Returns the final GLSL code. If `pointer_events_enabled` is set to false, the generated
  /// shape will be transparent for pointer events and will pass them trough.
  + #[profile(Detail)]
  pub fn run<S: canvas::Draw>(shape: &S, pointer_events_enabled: bool) -> CodeTemplate {
  - let sdf_defs = primitive::all_shapes_glsl_definitions();
  let mut canvas = Canvas::default();
  let shape_ref = shape.draw(&mut canvas);
  - let defs_header = header("SDF Primitives");
  let shape_header = header("Shape Definition");
  canvas.add_current_function_code_line(iformat!("return {shape_ref.getter()};"));
  canvas.submit_shape_constructor("run");
  - let defs =
  - iformat!("{defs_header}\n\n{sdf_defs}\n\n\n\n{shape_header}\n\n{canvas.to_glsl()}");
  -
  - let redirections = overload::builtin_redirections();
  - let math = overload::allow_overloading(MATH);
  - let color = overload::allow_overloading(COLOR);
  - let debug = overload::allow_overloading(DEBUG);
  - let shape = overload::allow_overloading(SHAPE);
  -
  - let defs = overload::allow_overloading(&defs);
  - let code = format!(
  - "{}\n\n{}\n\n{}\n\n{}\n\n{}\n\n{}",
  - redirections, math, color, debug, shape, defs
  - );
  + let shape_def = overload::allow_overloading(&canvas.to_glsl());
  + let code = [GLSL_PRELUDE.as_str(), "", &shape_header, &shape_def].join("\n\n");
  let main = format!(
  "bool pointer_events_enabled = {};\n{}",
  pointer_events_enabled, FRAGMENT_RUNNER
  @@ -75,3 +62,22 @@ fn header(label: &str) -> String {
  let border = "=".repeat(border_len);
  iformat!("// {border}\n// === {label} ===\n// {border}")
  }
  +
  +
  +// == GLSL_PRELUDE ==
  +
  +lazy_static! {
  + /// A common preamble used to start every shader program.
  + static ref GLSL_PRELUDE: String = make_glsl_prelude();
  +}
  +
  +fn make_glsl_prelude() -> String {
  + let redirections = overload::builtin_redirections();
  + let math = overload::allow_overloading(MATH);
  + let color = overload::allow_overloading(COLOR);
  + let debug = overload::allow_overloading(DEBUG);
  + let shape = overload::allow_overloading(SHAPE);
  + let defs_header = header("SDF Primitives");
  + let sdf_defs = overload::allow_overloading(&primitive::all_shapes_glsl_definitions());
  + [redirections, math, color, debug, shape, defs_header, sdf_defs].join("\n\n")
  +}
  