tmp-demo / tde.js

JS demo engine.
2 stars 0 forks source link

Generate the render loop #10

Open nical opened 9 years ago

nical commented 9 years ago

We have a level of indirection in the engine that isn't necessary and eats up a small but certain amount of space.

Instead of having a loop that calls render_pass with a pass descriptor, we could have the unrolled logic directly:

{
  render_to: textures.foo,
  clear: [0.0, 0.0, 0.8, 0.0],
  program: "effect",
  texture_inputs: [textures.bar],
  scene: [{ geometry:  "quad" }],
}

would turn into:

render_to(textures.foo);
clear([0.0, 0.0, 0.8, 0.0]);
program(programs.blur_h, [textures.bar]);
draw_scene([{ geometry: geometries.quad }]);

This would let us avoid setting states that don't need to be set several times like the render target or the program. This would also let us remove branches that check whether properties of the descriptor exist.

This would also let us easily hand-write the render-loop and add some specific logic like "if t is in this range, use this texture, otherwise this one", etc.

We can still use the json representation for editing and generate the render loop from it (or even choose at build time whether or not to generate it).

I am certain that this will make the things strictly smaller. On some demos the difference may not be big but it will at least make it possible to express some things that are hard to express in the current setup (at the expense of extra logic in the exporter).

nical commented 9 years ago

The render loop is not yet generated, but now the render graph is optional. If demo.rg is not in the data, an asset (such as a script) must set the engine.render callback (which is render_rg(time) if the render graph is present). So we can easily hand-write the rendering code when we have specific needs, now.