Aeva / m.grl

Midnight Graphics & Recreation Library
http://mgrl.midnightsisters.org
GNU Lesser General Public License v3.0
44 stars 3 forks source link

standard components api #230

Closed Aeva closed 7 years ago

Aeva commented 8 years ago

The standard components API bulids on top of both the shader program creation api, the compositing system, and the scene graph; and largely aims to either provide a simplified access to all three or replace entirely for the end user.

This would be a backwards compatible implementation, so code that doesn't use it would still work.

The main need for this is to provide a nice interface for creating custom renderers (see issue #226), and also to guarantee that objects being instanced have the correct bindings.

The API might look something like so:

renderer = please.create_renderer("simple_lighting", [extra_sources], {options});
renderer.attach("scene.jta", {defaults}, {options});
renderer.attach("camera", {defaults}, {options});

Eg:

// shorthand for creating deferred rendering compositing node and 
// a shader program for it with the following sources:
//  - deferred_renderer/main.vert
//  - deferred_renderer/main.frag
//  - deferred_renderer/simple_brdf.glsl
//  - my_procedural_texture.glsl
renderer = please.create_renderer("simple_lighting", ["my_procedural_texture.glsl"]);

// shorthand for:
// renderer.graph.add(please.access("scene.jta").instance());
renderer.attach("scene.jta");

// shorthand for:
// var handle = new please.GraphNode();
// renderer.graph.add(handle);
var handle = renderer.attach("empty");

// shorthand for:
// var camera = new please.CameraNode();
// camera.location = [-10.0, 0.0, 5.0];
// handle.add(camera);
var camera = handle.attach("camera", {location:[-10.0, 0.0, 5.0]});
camera.activate();

please.set_viewport(renderer);

In this api, please.create_renderer returns a compositing node, and the various .attach functions return graph nodes. Rather than instancing these directly from their classes, instead a string is used to look up the class from a manifest.

Custom constructors could be exposed like so:

please.register_renderer("handy_name", HandyRenderer);
please.register_fixture("stereo_camera", please.StereoCamera);

Standard components would use the "custom constructors" API internally to add things to the manifest.

Aeva commented 8 years ago

232 introduces some changes that makes the graph much more decoupled from the shader, by moving all of the drawing functionality onto the RenderNode.

The problem that this issue is meant to solve might not exist anymore, so maybe I should close this out.