PAIR-code / megaplot

Apache License 2.0
19 stars 5 forks source link

Use string property names on objects passed to regl #32

Closed jimbojw closed 2 years ago

jimbojw commented 2 years ago

Megaplot uses regl for a WebGL abstraction layer. When calling regl functions to setup draw commands, it's customary to provide objects whose keys contain configuration information.

Currently, the objects passed use short-hand notation like this:

regl({
  frag: `...fragment shader program...`,
  vert: `...vertex shader progam...`,
  attributes: {
    someAttribute: [[...values]],
  },
  ...

A consequence of this is that JavaScript minimizers may rename these properties. If so, this can cause errors in regl, which expects these properties not to change, and relies on them for dynamic code compilation (using the Function constructor).

Instead, Megaplot should pass string versions of properties instead:

regl({
  'frag': `...fragment shader program...`,
  'vert': `...vertex shader progam...`,
  'attributes': {
    'someAttribute': [[...values]],
  },
  ...

This will ensure that aggressive minimizers will not alter the property names.