threeDart/three.dart

Rendering WebGLRenderTargets and the Renderer interface

Closed this issue · 3 comments

tl;dr:

I think we should add a method to WebGLRenderer for rendering WebGLRenderTargets because this will preserve the basic rendering contract shared by all renderers that implement Renderer while exposing the WebGLRenderer's ability to render WebGLRenderTargets This is pertinent because I am currently porting the postprocessing code:

void renderToTarget(Scene scene, Camera camera, WebGLRenderTarget renderTarget,
 [bool forceClear = false]) => _render(scene, camera, renderTarget, forceClear);

Discussion:

In three.js, the WebGLRenderer.render function has the following signature:

render (scene, camera, renderTarget, forceClear);

The rest of the renderers in three.js have the following signature:

render(scene, camera);

Of course, the WebGLRenderer.render method also implicitly supports the other signature, and in JavaScript you can simply exclude last two parameters when not rendering WebGLRenderTargets (which is actually the more typical use case), e.g.:

renderer.render(scene, camera);

In three.dart we have the Renderer abstract class that creates the following render method contract:

void render(Scene scene, Camera camera);

Each of the renderers in three.dart override this method. However, the private _render method in WebGLRenderer does expose (only to the library of course) the parameters for rendering WebGLRenderTargets:

_render (Scene scene, Camera camera, {renderTarget: null, forceClear: false});

I have been working on porting the postprocessing code, and I and anyone who wants to render WebGLRenderTargets will need to be able pass renderTarget and forceClear arguments to the _render method. Keep in mind that there is no method overloading in Dart, and adding the two extra parameters to the public render function of WebGLRenderer will cause it to no longer implement the Renderer interface

It seems to me the best way to approach this is to leave the WebGLRenderer.render method and the Renderer interface unchanged and add another method to WebGLRenderer:

void renderToTarget(Scene scene, Camera camera, WebGLRenderTarget renderTarget,
 [bool forceClear = false]) => _render(scene, camera, renderTarget, forceClear);

This will preserve the basic render contract shared by all renderers while exposing the WebGLRenderer's capability to render WebGLRenderTargets.

Sounds good to me, I would just call it renderToTargetto clearly make it a verb.

Yes, renderToTarget is clearer.

renderToTarget has been added to WebGLRenderer.