chickadee » hypergiant » add-node

(add-node PARENT PIPELINE [mesh: MESH] [vao: VAO] [mode: MODE] [n-elements: N-ELEMENTS] [element-type: ELEMENT-TYPE] [offset: OFFSET] [usage: USAGE] [draw-arrays?: DRAW-ARRAYS?] [position: POSITION] [radius: RADIUS] [data: DATA] [delete: DELETE] . UNIFORM-ARGS)procedure

This extension of the Hyperscene function of the same name (along with Hypergiant’s extension of define-pipline) is where the majority of the magic of Hypergiant happens. Unlike its cousin, Hypergiant’s add-node’s PIPELINE argument accepts the special render-pipeline object defined by Hypergiant’s define-pipeline rather than a Hyperscene pipeline. Because of this, Hyperscene pipelines never need to be manually created. When a non-render-pipeline (i.e. a Hyperscene pipeline) is passed to add-node, it acts identically to the Hyperscene version, except with the addition of the POSITION and RADIUS keywords, and DATA and DELETE are keyword arguments.

POSITION expects a gl-math point. When POSITION is provided, set-node-position! is called with POSITION after the node is created. RADIUS expects a float. When RADIUS is provided, set-node-bounding-sphere! is called with RADIUS after the node is created.

When PIPELINE is a render-pipeline the node data that is created is a glls renderable object. MESH, VAO, MODE, N-ELEMENTS, ELEMENT-TYPE, and OFFSET all function as they do when making a renderable. Additionally, MESH may be passed to add-node when its VAO has not yet been created (i.e. with mesh-make-vao!), and mesh-make-vao! will be called automatically, influenced by the optional USAGE keyword (defaulting to #:static). DRAW-ARRAYS? is a boolean that indicates whether or not the renderable’s array rendering function should be used (i.e. draw-arrays is used instead of draw-elements). DRAW-ARRAYS? defaults to #t if MESH has no index data, and #f otherwise. add-node accepts other keyword UNIFORM-ARGS, which are used to set the value for each uniform in the pipeline, as required by glls renderable makers.

add-node appends a number of Hyperscene values to its renderable creation call, for convenience. The following keys and values are added, which must correspond to the names of uniforms in the renderable’s pipeline if they are to be used:

  • mvp: (current-camera-model-view-projection)
  • view: (current-camera-view)
  • projection: (current-camera-projection)
  • view-projection: (current-camera-view-projection)
  • camera-position: (current-camera-position)
  • inverse-transpose-model: (current-inverse-transpose-model)
  • n-lights: (n-current-lights)
  • light-positions: (current-light-positions)
  • light-colors: (current-light-colors)
  • light-intensities: (current-light-intensities)
  • light-directions: (current-light-directions)
  • ambient: (current-ambient-light)

It’s worth noting that when add-node is called with a mesh, no references to that node are kept. Make sure you keep your meshes live, lest they become garbage.

add-node, along with define-pipeline does some magic so that things keep working when the program is evaluated (as opposed to compiled), but the end result is that it should Just Work.